Welcome, Guest! Login | Register
ignoring Y axis during rotation
Info
Report
210 Posts

so, i have this object who moves towards an object while also rotating towards another one, everything works fine but i was wondering if given this script it would be possible to have the object ignore the Y axis when rotating

Vector3 direction = player.position - transform.position;
            Quaternion rotation = Quaternion.LookRotation(direction);
            
            transform.rotation = Quaternion.Lerp(transform.rotation, rotation, speed * Time.deltaTime);
            transform.position = Vector3.MoveTowards(transform.position, moveSpot.position, speed * Time.deltaTime);
Created on: 1 month ago
Info
Report
56 Posts

Hi TSD, I am not sure what your trying to do, which variable you want to change. You can't change a Quaternion values because there not co-ordinates like a vector. But you can change a Vectors values x y z. To lock the Y co-ordinate you just set like this direction.y = 0.0f.  Or you might want to alter the player.position.y = 0.0f

Hope this helps

n_iron
Created on: 1 month ago
Info
Report
210 Posts

thanks niron, it works!
Created on: 1 month ago
Reply
Preview
Post
Or use the advanced reply form here...
Sponsored