Greenie0101

setElementVelocity forwards

Recommended Posts

I need help with this! I want to use setElementVelocity to make a ped go forwards (in the direction it is facing). How can I do this as setElementVelocity works along the x and y axis of the map and not the player.

Share this post


Link to post

nah dont see how that works, i want it so that if im facing north my velocity will be x, y + 0.1, z.

If im facing south it would be x, y - 0.1, z

east would be x + 0.1

west x - 0.1

that part is easy but how can i calculate what it should be for all the stuff in between. For example if i face north east (45 degrees) it will be x + 0.1, y +0.1 z. But if im facing at 10 degrees for example, how can i make the script calculate what the x and y should be?

Share this post


Link to post
function setElementForwardVelocity( elem, vel ) 
    local ang = getElementRotation( elem ); 
    ang = math.rad(90 - ang); 
    local vx = math.cos( ang ) * vel; 
    local vy = math.sin( ang ) * vel; 
    return setElementVelocity( elem, vx, vy, 0 ); 
end 

Haven't tested it but should work.

Share this post


Link to post

ok its been a while but i want to come back to this. I want this so that i can put it in the parachute recource so that i glide more than fall. At the moment i did my parachute resource so that if im not holding controls it sets my velocity as x+1 and y+1 but of curse that just has me shooting off 45 degrees NE. How can i set my velocity to make myself go forward as im falling in parachute script

Share this post


Link to post
function setElementForwardVelocity( elem, vel ) 
    local ang = getElementRotation( elem ); 
    ang = math.rad(90 - ang); 
    local vx = math.cos( ang ) * vel; 
    local vy = math.sin( ang ) * vel; 
    return setElementVelocity( elem, vx, vy, 0 ); 
end 

Haven't tested it but should work.

Added the function to my script but for e.x: setElementForwardVelocity(localPlayer,2) does nothing for me.

Share this post


Link to post
function setElementForwardVelocity( elem, vel ) 
    local ang = getElementRotation( elem ); 
    ang = math.rad(90 - ang); 
    local vx = math.cos( ang ) * vel; 
    local vy = math.sin( ang ) * vel; 
    return setElementVelocity( elem, vx, vy, 0 ); 
end 

Haven't tested it but should work.

What is the math.rad, math.cos and math.sin?

Share this post


Link to post
function setElementForwardVelocity( elem, vel ) 
    local ang = getElementRotation( elem ); 
    ang = math.rad(90 - ang); 
    local vx = math.cos( ang ) * vel; 
    local vy = math.sin( ang ) * vel; 
    return setElementVelocity( elem, vx, vy, 0 ); 
end 

Haven't tested it but should work.

What is the math.rad, math.cos and math.sin?

http://lua-users.org/wiki/MathLibraryTutorial

Share this post


Link to post

Added the function to my script but for e.x: setElementForwardVelocity(localPlayer,2) does nothing for me.

It doesn't work while you stand on the ground, you get stuck. You have to first jump and then use it (alternatively set your position above the ground and then use it, or setElementVelocity upwards and then timer and setElementVelocity forwards, lol).

Share this post


Link to post

Added the function to my script but for e.x: setElementForwardVelocity(localPlayer,2) does nothing for me.

It doesn't work while you stand on the ground, you get stuck. You have to first jump and then use it (alternatively set your position above the ground and then use it, or setElementVelocity upwards and then timer and setElementVelocity forwards, lol).

Just shoots me in the same direction every time

Share this post


Link to post

math.rad(ang); -East

math.rad(90 - ang); -North

math.rad(180 - ang); -West

math.rad(270 - ang); -South

Simple as that.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.