Jump to content

Ballistic help (camera angle)


Shidony

Recommended Posts

Hi everyone, i'm trying to make a system just for fun but there's a thing i can't do.

I downloaded this script (https://community.multitheftauto.com/index.php?p= ... ils&id=469) but i want to edit it to make the object go in the air with the player camera angle.

I explain better, with this script, the object is throwed at the same z pos of the player, i want to throw the object in the air if i look in the sky or throw it on the ground if i look the ground but i don't know how to get the camera angle.

Can you help me ?

Thanks in advance,

Cordialy.

Link to comment

You can do it with function atan2

Ok it's not easy when you don't know where to start, so here is a little example:

function getAnglesBetweenPoints3D( x1, y1, z1, x2, y2, z2 ) 
  
    x1 = x2 - x1 
    y1 = y2 - y1 
     
    x2 = math.atan2( x1, y1 ) * 57.29578 
    y2 = math.atan2( z2 - z1, math.sqrt( (x1 * x1) + (y1 * y1) ) ) * 57.29578 
     
    return x2, y2 
     
end 
  
  
function displayAngles() 
     
    local x1, y1, z1, x2, y2, z2 = getCameraMatrix( localPlayer ) 
    local a1, a2 = getAnglesBetweenPoints3D( x1, y1, z1, x2, y2, z2 ) 
  
    outputChatBox( string.format( "a1 = %.2f   a2 = %.2f", a1, a2 ) ) 
  
end 
addEventHandler( "onClientRender", root, displayAngles ) 

The angle you asked is a2, but you will need a1 as well isn't it? :)

Edited by Guest
Link to comment

I didn't saw you edited your post, i don't understand why you're using cx1, cy1 etc ... but i found this function:

local function getCameraRotation() 
    local px, py, pz, lx, ly, lz = getCameraMatrix() 
    local rotz = 6.2831853071796 - math.atan2 ( ( lx - px ), ( ly - py ) ) % 6.2831853071796 
    local rotx = math.atan2 ( lz - pz, getDistanceBetweenPoints2D ( lx, ly, px, py ) ) 
    --Convert to degrees 
    rotx = math.deg(rotx) 
    rotz = -math.deg(rotz) 
    return rotx, 180, rotz 
end 

I teste it and it works but know, i need to find the velocity, i allready have the velocity for x and y but fox z a cannot find the calculation to make the object go into the air and then, fall to the ground with a gravity.

EDIT: found the solution, i do not have to convert the rotx into degrees. thanks for your help ;).

Link to comment

There was a function https://wiki.multitheftauto.com/wiki/IsObjectStatic but I'm not sure if it still works with newer MTA. Anyway, if object has some gravity properties then it will react to gravity otherwise you will have to script it yourself. To make smooth movement you'll need to use onClientRender and roughly calculate current frame position based on velocity and use setElementPosition instead of setElementVelocity.

Link to comment

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