Best way to move object?

Hallo there,

I am trying to move a object, but I’m not sure how I should do it.

Should I just change the X,Y,Z coordinates of the object, or should I use Force or are there perhaps other ways of doing so?

I know that there are tutorials that got player movement in them, but those usually use already pre-made scripts and I can’t really figure out how those work… So I would prefer to do it myself so that I can also learn something about it…

I tried both force and coordinates and the coordinates seemed to work better for me, because I got my box to move with a permanent, speed… where it would start moving slowly and then start gaining a little bit of speed if I used force…

Force seems to work great, except that I don’t get a constant speed with it, or can I fix that somehow?

Using physics and forces is inherently chaotic. Use them only if you want to run a physics simulation. In that case you’re dealing with accelerations and hardly anything is simply linear movement.

If you want “gamey”, super mario bros style controls, it’s much better to Lerp stuff by hand or use something like iTween. You’ll have predicatability and full control.

The choice should depend on the type of game you’re making.

Funny that you mention Mario, because thats pretty much what I’m trying to make… I mean a sidescroller…

So perhaps you could suggest me some way to stop my box from moving when I’m next to a wall or other obstacle… Because if I’m using the coordinates, then my object will go partially into it until I release the key and then it will jump out of it…

I was thinking of a ray sensor, but I have no idea how those work in Unity… :s
[edit] Thats why I liked force, because my object would immediately stop moving if I ran into something… :slight_smile:

Basic sidescroller movement you want to model by hand. Physics isn’t very good for that. Use physics on some of the objects that your character interacts with.

You can use colliders and triggers to stop your box in many circumstances. Look at the docs for Character Controller and isKinematic. That second setting lets you take advantage of some physics properties but still allows you to transform that character’s x,y,z by hand.

If you’re making a sidescroller, you’ll definitely want to check out the Lerps 2D Platformer tutorial that comes with Unity. You can adapt lots of stuff from there, although that example relies on physics more than I like.

I already looked at it… it uses so much code… :x

Thanks, I will look into those things… :slight_smile: