• What is the right equation to calcule the needed vector velocity to send a player at?
    3 replies, posted
I am trying to find out the needed velocity in vector form to send a player at with only knowing the players position, target position, time, distance, and height. I had something that seemed correct but apparently it is to weak. I tried powering it and it said that it was to fast in console so it would not apply the velocity. Code: [lua] function CalculatePlyrArc(ply) local vec1 = ply:GetPos() //Get Player vector position local vec2 = Vector(0,0,0) //Target Position local grav = ply:GetGravity()*9.81 //Gravity local ang = 45 //Angle local Hgt = math.abs( vec1.z-vec2.z) //Height local dis = vec1:Distance( vec2 ) //Distance between vectors local t = 5 //Time it takes local velx = 0 local vely = 0 //vel = (math.sqrt(grav) * math.sqrt(vec2.x) * math.sqrt((math.tan(ang)*math.tan(ang))+1)) / math.sqrt(2 * math.tan(ang) - (2 * grav * vec2.y) / vec2.x); velx = math.pow((vec2.x-vec1.x)/t, 2) vely = math.pow((vec2.y+.5*grav*t*t-vec1.y)/t, 1) ply:SetVelocity( Vector(0,vely,velx)) end [/lua]
Pretty sure your gravity is wrong. Your equation looks pretty wrong too. [url]https://en.wikipedia.org/wiki/Projectile_motion#The_initial_velocity[/url] target = vec2-vec1 Vel = Vector( target.x / t, target.y / t, target.z / t + gravity * t / 2 )
GetGravity returns a gravity multiplier. Use this against sv_gravity to get the gravity for the player. Also, 9.81 is assuming you're in metres, which you should never do in a game engine. [editline]8th July 2015[/editline] Ninja'd
[QUOTE=code_gs;48154029]GetGravity returns a gravity multiplier. Use this against sv_gravity to get the gravity for the player. Also, 9.81 is assuming you're in metres, which you should never do in a game engine. [editline]8th July 2015[/editline] Ninja'd[/QUOTE] [QUOTE=thegrb93;48154016]Pretty sure your gravity is wrong. Your equation looks pretty wrong too. [url]https://en.wikipedia.org/wiki/Projectile_motion#The_initial_velocity[/url] target = vec2-vec1 Vel = Vector( target.x / t, target.y / t, target.z / t + gravity * t / 2 )[/QUOTE] Thanks I was over-thinking it. I was trying to add in all this unneeded information.
Sorry, you need to Log In to post a reply to this thread.