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 :slight_smile:

thnx for ur time Unity Community :slight_smile:

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 :slight_smile:

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!