vehicle.rotation setter/getter

Recommended Posts

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),

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);


  • Like 1

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.