AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved [ H3LP ] Velocity between two points? (https://forums.alliedmods.net/showthread.php?t=299720)

CrazY. 07-23-2017 19:33

[ H3LP ] Velocity between two points?
 
Hello, I tried to find something like Velocity_by_aim, however, both the current position and the final position are attributed to the position of the player and the enemy respectively, i.e. I will get the origin of the player and the enemy, I want to create an entity that moves from where the player is as far as the enemy is. Can someone help me?

fysiks 07-23-2017 19:39

Re: [ H3LP ] Velocity between two points?
 
"velocity by aim" is not possible. The term velocity requires 2 things: speed and direction. "aim" only gives you direction, not speed.

You say you want to make something move from the player to the enemy so exactly what part are you unable to do?

CrazY. 07-23-2017 20:29

Re: [ H3LP ] Velocity between two points?
 
What I do not know is to calculate the axes (x, y, z) of the velocity to apply to the entity.

fysiks 07-23-2017 20:55

Re: [ H3LP ] Velocity between two points?
 
The direction vector between the two players is simply the subtraction of the two positions and dividing by the linear distance. When you do the subtraction, make sure the the order is done correctly:

<direction vector> = (<target position> - <from position>)/distance

This is called a unit vector (a vector with a length of 1). Then, to turn it into a velocity vector, you simply multiply by the speed.

CrazY. 07-23-2017 22:12

Re: [ H3LP ] Velocity between two points?
 
Oh, thanks fysiks, work perfectly!

Here is the solution:
Code:
create_rocket(const Float:origin[3], const Float:end[3]) {     new entity = create_entity("info_target")     entity_set_origin(entity, origin)     entity_set_int(entity, EV_INT_solid, SOLID_TRIGGER)     entity_set_int(entity, EV_INT_movetype, MOVETYPE_FLY)     entity_set_model(entity, ROCKET_MODEL)     new Float:mins[3] = { -1.0, -1.0, -1.0 }     new Float:maxs[3] = { 1.0, 1.0, 1.0 }     entity_set_size(entity, mins, maxs)     new Float:multiplier = 1000.0     new Float:distance = get_distance_f(origin, end)     new Float:vector[3]     vector[0] = ((end[0] - origin[0]) / distance)     vector[1] = ((end[1] - origin[1]) / distance)     vector[2] = ((end[2] - origin[2]) / distance)     new Float:velocity[3]     velocity[0] = vector[0] * multiplier     velocity[1] = vector[1] * multiplier     velocity[2] = vector[2] * multiplier     new Float:angles[3]     vector_to_angle(vector, angles)     entity_set_vector(entity, EV_VEC_velocity, velocity)     entity_set_vector(entity, EV_VEC_angles, angles) }


All times are GMT -4. The time now is 22:54.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.