Jump to content

Look-at rotation


Mr.Loki

Recommended Posts

I use this to make prisoner always face cop:

local copX, copY, copZ = getElementPosition(cop)
local prisonerX, prisonerY, prisonerZ = getElementPosition(prisoner)
local copAngle = ( 360 - math.deg(math.atan2((copX - prisonerX), (copY - prisonerY))) ) % 360

You should be able to use this, copAngle is the Z rotation that you can set on the object so that it faces copX, copY, copZ but if you want it to also look up and down then you can probably clone line 3 from above and play around with copX, prisonerX, copY, prisonerY to get a combination that returns the X and Y rotation for the object.

Link to comment

Then you'll need to add some debug, the video shows on screen XYZ which is a good start, below that you should add the Z rotation so you can see what rotation it's setting on your ped, because the script might be correct but there's a GTA or MTA bug that makes it appear wrong.

Link to comment

Those XYZ values on the screen are the rotations that are being set.

The problem was the z was using the y values so its fixed now.

The main problem I'm getting now is I've set the z rotation to the camera so the player is always facing forward.

When the Z rotation is 180 the X and Y rotations are ok but when the Z is 0 the rotations on X and Y are reversed.

https://streamable.com/0n6sh

In this video I reversed the Y rotation so that the X and Y are correct when the Z rotation is 180.

https://streamable.com/62o0o

 

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