Avenger Posted July 1, 2019 Posted July 1, 2019 Hello all, I've spent some time working with the rotation property of the vehicle object (server side of course) and I've worked out why things are "broken" with it... The setter requires x, y, z angles relative to the vehicle where the x is roll, y is pitch and z is heading. The getter returns the x, y, z angles relative to the world. That is, if the vehicle is facing south (z = 180), the setter and getter values are equal, but at any other heading, the getter object cannot be used as the setter. To solve this, I came up with the following function - I thought it might be helpful to others... const relativeRotation = (rotation) => { const {x, y, z} = rotation; const rx = (360-z) / 180 * Math.PI; const ry = z / 180 * Math.PI; return { x: x * -Math.cos(rx) + y * Math.sin(rx), y: y * -Math.cos(ry) + x * Math.sin(ry), z }; }; Basic usage... // get the rotation of the vehicle relative to the vehicle. let {x, y, z} = relativeRotation(vehicle.rotation); x += 45; // adjust the pitch of the vehicle by 45 degrees // update the vehicle rotation. vehicle.rotation = new mp.Vector3(x, y, z); 1
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