Jump to content

setElementVelocity forwards


Recommended Posts

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?

Link to comment
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.

Link to comment
  • 4 weeks later...

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

Link to comment
  • 2 years later...
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.

Link to comment
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?

Link to comment
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

Link to comment

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

Link to comment

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

Link to comment
  • 1 year later...

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.
×
×
  • Create New...