- Home /
Suspension arm
I hate 3dsMax, It screws up the pivots of objects and makes using them really difficult,
This should be easy to do but I can't for the life of me figure it out, Hope someone can help.
My Car has a suspension arm which is attached to the wheel, I want to make the suspension arm travel up and down when the wheel bounces up and down.
I figured the way to do this is to put the pivot in the right place on the suspension arm, and then use a "look at" using the target as the wheel's transform.
However, doing this, when the car goes up or down a slope, the object appears to "twist" - I figure I need to lock one of the axis's of the look at - and here's the question:
When I use LookAt - the object appears to completely disregard it's children status, (it doesn't add the cars heading or tilt to the look at equation.)
Is there another method I should use, I want a subject object suspension arm to move it's pivot up and down based on the height of an attached wheel - but thats it, no fancy rotations or anything like that, just bounce up and down...
Answer by aldonaletto · Aug 27, 2011 at 08:02 PM
You can use LookAt, but you must specify the second parameter, worldUp. It's a vector that defines the up side; if not specified, Unity assumes Vector3.up - that's why the arm stays horizontal even when the vehicle is on a slope.
If the suspension arm is childed to the vehicle's body, you can use this attached to the arm:
var wheel: Transform; // drag the wheel here
function Update(){ transform.LookAt(wheel, transform.parent.transform.up); } If the arm isn't a vehicle child, you can define the vehicle's transform in a variable, like this:
var wheel: Transform; // drag the wheel here var vehicle: Transform; // drag the vehicle's body here
function Update(){ transform.LookAt(wheel, vehicle.up); } For this to work, the arm model Z axis must point to the wheel, and its pivot must be correctly set. If you have problems with this, create an empty game object, rotate it to have Z pointing to the wheel, then set its position at the correct point in the vehicle's body. Attach the script to the game object, and child your arm model to it.
Aha, Brilliant, I knew that there was something I was missing with the world up parameter, just wasn't sure how to use it. Thanks for the answer!
Your answer
Follow this Question
Related Questions
Lock rotation axis? 4 Answers
Incorrect script for slerp rotation 1 Answer
Look at multiple cameras 2 Answers