- Home /
2D Joint/Wheel Question
Hi, Im currently working on a 2D game and i need to snap wheels on an object, i tried using various kinds of joints, yet they never seem to stick in place and keep moving a certain distance from the main object. Basically something like a skateboard and 2 wheels.
Is there something else other than joints im supposed to be using rather than joints?
sorry for the noob question :)
thnx for ur time Unity Community :)
Btw i intend to use torque on the wheels for motion, if thats not a great idea and/or should just stick to apply force, your guidance would be appreciated :)
Answer by Fattie · Dec 30, 2012 at 11:35 AM
Just to begin with:
When you attach one object to another.
For example, you have a spaceship and you want to attach a wing. Or you have a truck and you want to attach a container on the back. Or you have a player character and you want to attach a backpack.
Simply - you need to use the parent-child relationship
Note that the parent goes with the "transform".
So in short, you would do something like this:
One -- make a new "wheel unit". Use "Instantiate" to do this. if you do not know about Instantiate read the doco, or ask a new question, or search.
var newWheelUnity:GameObject;
newWheelUnit = Instantiate( myModelWheenUnit );
You now have a beautiful new wheel unit.
So. Now you must make it that your VEHICLE is the PARENT of that new wheel unit. Don't forget, you have to use "transform" for this.
So first set all the other stuff for newWheelUnit ...
newWheelUnit.name = "special name";
newWheelUnit.layer = 13;
etc etc
Now set the parent ..
newWheelUnity.transform.parent = yourCar.transform;
Now you have to set the position of that child. USe localPosition to do that.
newWheelUnity.transform.localPosition = Vector3(0,0,0);
it won't actually be "0,0,0" 0 it will be the actual position of the wheel on the car. Since it works in meters, it might be something like "1.25, -0.835, 0"
First you have to master all this so that you can easily "add parts" to something else
Once you get really good at this, you have to look in to the whole topic of making wheels turn, etc. That is a hugely separate topic and you will need to do a lot of searching and questioning. Good luck!
Thank you, that did solve the problem even though i was attempting a similar approach with parenting objects in the editor, dont know why exactly it just wouldn't work on these, others seem to stick together just fine, probably missing another trick as i am fairly a noob at Unity :)
But there is another issue now hope that you can quickly assist me, since the objects have regular box and sphere colliders and rigid bodies to drop with gravity, while un-parented they just tend to drop and rest upon each other which is expected and just fine... But upon parenting, as the whole rig drops to the ground it now does a bounce, and if i wait till it hits the floor again it does an even bigger bounce no matter how close i place the object to the grond to avoid this...... What's causing this strange bounce? I dont have any materials set to simulate a bounce or rubbery environment.
Thanks once again :)
Your answer
Follow this Question
Related Questions
2d physics car controller 1 Answer
HingeJoint2D.GetReactionForce not working 1 Answer
anti wheel wobble 0 Answers
Mapping movement to a WheelCollider suspension? 2 Answers
in Unity 3.5.7 car starts to shake 0 Answers