Jump to content

Question to a simple thing :)


Maurize

Recommended Posts

Posted

Hey,

I´m creating a function that allows the player to get a car attached on his arms and able him to throw it.

ONLY PROBLEM:

I use setElementVelocity and now the car is only "flying" in one direction.

Is there a way to calculate the direction in which the car must fly?

Thanks,

Hope u understood me :)

Posted

CapY, there's no need to show the script.

Is there a way to calculate the direction in which the car must fly?

Be more specific! Do you want the car to fly exactly in front of itself?

Posted

yep exactly. it should fly in the direction, the player got.

  
addEvent( "beiPower", true ) 
addEventHandler( "beiPower", getRootElement(), 
function() 
    local px, py, pz = getElementPosition( source ) 
    local rx, ry, rz = getElementRotation( source ) 
    local veh = createVehicle( 542, px, py, pz ) 
    attachElements( veh, source, 0, 0, 1.5, rx, ry, rz ) 
    bindKey( source, "mouse1", "down", 
function( player ) 
    local rx, ry, rz = getElementRotation( player ) 
    unbindKey( player, "mouse1", "down", source ) 
    setPedAnimation( player, "RYDER", "Van_Throw", 2000, false, false, false, false ) 
    detachElements( veh, player ) 
    setElementRotation( veh, 0, 0, pz ) 
    setElementVelocity( veh, 0, math.random( 1, 2 ), 0 ) 
    end ) 
end ) 
  

Posted

benxamix2 this function is irritating me, could u give me more help about this?

  
addEvent( "beiPower", true ) 
addEventHandler( "beiPower", getRootElement(), 
function() 
    local px, py, pz = getElementPosition( source ) 
    local rx, ry, rz = getElementRotation( source ) 
    local veh = createVehicle( 542, px, py, pz ) 
    attachElements( veh, source, 0, 0, 1.5, rx, ry, rz ) 
    bindKey( source, "mouse1", "down", 
function( player ) 
    local px, py, pz = getElementPosition( player ) 
    local rx, ry, rz = getElementRotation( player ) 
    local nx, ny = getPointFromDistanceRotation( px, py, 1, rz ) 
    unbindKey( player, "mouse1", "down", source ) 
    setPedAnimation( player, "RYDER", "Van_Throw", 2000, false, false, false, false ) 
    detachElements( veh, player ) 
    setElementRotation( veh, 0, 0, pz ) 
    setElementVelocity( veh, nx, ny, 0 ) 
    end ) 
end ) 
-- "RIOT", "RIOT_ANGRY" -- 
  
function getPointFromDistanceRotation( x, y, dist, angle ) 
    local a = math.rad( 90 - angle ) 
    local dx = math.cos( a ) * dist 
    local dy = math.sin( a ) * dist 
    return x + dx, y + dy 
end 

Posted

Don't bump!!!

God, that's not very clever from you, Maurize! That will obviously don't work!

getPointFromDistanceRotation returns a 2D POSITION.

function getPointFromDistanceRotation( x, y, dist, angle ) 
    local a = math.rad( 90 - angle ) 
    local dx = math.cos( a ) * dist 
    local dy = math.sin( a ) * dist 
    return x + dx, y + dy 
end 
  
addEvent( "beiPower", true ) 
addEventHandler( "beiPower", getRootElement(), 
function() 
    local px, py, pz = getElementPosition( source ) 
    local rx, ry, rz = getElementRotation( source ) 
    local veh = createVehicle( 542, px, py, pz ) 
    attachElements( veh, source, 0, 0, 1.5, rx, ry, rz ) 
    bindKey( source, "mouse1", "down", 
function( player ) 
    local px, py, pz = getElementPosition( player ) 
    local rx, ry, rz = getElementRotation( player ) 
    local nx, ny = getPointFromDistanceRotation( px, py, 1, rz ) 
    unbindKey( player, "mouse1", "down", source ) 
    setPedAnimation( player, "RYDER", "Van_Throw", 2000, false, false, false, false ) 
    detachElements( veh, player ) 
    setElementRotation( veh, 0, 0, pz ) 
    setElementVelocity( veh, (nx - px)/10, (ny - py)/10, 0 ) --This determines the direction of the movement. You can increase or reduce the division "/10". 
    end ) 
end ) 

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