Maurize Posted November 26, 2011 Share Posted November 26, 2011 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 Link to comment
12p Posted November 26, 2011 Share Posted November 26, 2011 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? Link to comment
Maurize Posted November 26, 2011 Author Share Posted November 26, 2011 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 ) Link to comment
12p Posted November 26, 2011 Share Posted November 26, 2011 You can use https://wiki.multitheftauto.com/wiki/Get ... ceRotation And basic math to do that. Link to comment
Maurize Posted November 26, 2011 Author Share Posted November 26, 2011 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 Link to comment
Maurize Posted November 26, 2011 Author Share Posted November 26, 2011 anyone? someone? Link to comment
12p Posted November 26, 2011 Share Posted November 26, 2011 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 ) Link to comment
Maurize Posted November 26, 2011 Author Share Posted November 26, 2011 uh ur right, i saw this several minutes ago, but was unable tofix thanks Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now