Raised This Month: $ Target: $400
 0% 

Solved [ H3LP ] Velocity between two points?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-23-2017 , 19:33   [ H3LP ] Velocity between two points?
Reply With Quote #1

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?
__________________









Last edited by CrazY.; 07-23-2017 at 22:14.
CrazY. is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-23-2017 , 19:39   Re: [ H3LP ] Velocity between two points?
Reply With Quote #2

"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?
__________________
fysiks is online now
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-23-2017 , 20:29   Re: [ H3LP ] Velocity between two points?
Reply With Quote #3

What I do not know is to calculate the axes (x, y, z) of the velocity to apply to the entity.
__________________








CrazY. is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-23-2017 , 20:55   Re: [ H3LP ] Velocity between two points?
Reply With Quote #4

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.
__________________

Last edited by fysiks; 07-23-2017 at 20:57.
fysiks is online now
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-23-2017 , 22:12   Re: [ H3LP ] Velocity between two points?
Reply With Quote #5

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) }
__________________









Last edited by CrazY.; 07-23-2017 at 22:13.
CrazY. is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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