- Home /
I Can't Assign Something To Local Space's X Axis
Hellos,
transform.InverseTransformDirection(rigidbody.velocity).x = Mathf.Clamp( (transform.InverseTransformDirection(rigidbody.velocity).x), -3.0f, 3.0f);
I need to write this code for my car but I can't. It give me a warning and it doesn't work. Warning is : "Assignment to temporary."
I can write just this :
this.rigidbody.velocity.x = Mathf.Clamp( this.rigidbody.velocity.x, -3.0f, 3.0f);
but this is not my car's velocity.(not local space) It is world space's velocity. I need assign variable to my car's local space.
In addition, my purpose is that, if my car drift in X axis too much, I want stop it's drifting.
What should I do ?
Thanks for helps :)
I just need assing something to my object's local space's axis. Actually I couldn't contact between my question and your comment.
Answer by robertbu · Aug 05, 2014 at 04:43 PM
Typically I see this in three lines of code:
Vector3 localVelocity = transform.InverseTransformDirection(rigidbody.velocity);
localVelocity.x = Mathf.Clamp(localVelocity.x, -3.0f, 3.0f);
rigidbody.velocity = transform.TransformDirection(localVelocity);
Your answer
Follow this Question
Related Questions
How to find the edge of a sprite in local space. 1 Answer
How can I get an object to orientate behind a plane? 0 Answers
Transform.rotation.y rotating around x and z... 1 Answer
How to build a XZ only rigidbody drag function in local space? 1 Answer
Moving an object in its local X/Z relative to the camera orientation 2 Answers