#Basic character movement

1 messages · Page 1 of 1 (latest)

slate surge
#

If you want to use OnCollisionEnter2D() then yeah, one of the objects involved needs to have a rigidbody (specifically, a Rigidbody2D in your case).

But if you intend to move the character directly instead of doing so through velocities or forces (which your use of transform.Translate() so far implies), there are other options which may be more appropriate and work better for you, as Aethenosity mentioned.

When you directly move objects around by setting their positions or moving their transforms, the objects are essentially teleporting. They go to directly where you tell them to, without the physics engine simulating their movement from point A to point B. As a result, they won't properly react to collisions with other physical objects.

So you'll either need to change the way in which you move your character, or use a different mechanism to detect the ground.

Both approaches have their pros and cons. In short, direct movement gives you all the control in the world, but that means you also need to explicitly write how the object will move and collide and such. Physics-based gives you free collisions and realistic-ish force-driven motion, but it can take a little more work to get things to move in ways which are not directly physics-driven, as well as tweaking the values for masses and forces to get things to move as you'd wish.

It is good to explore both options at some point. They can work together if you're careful, and eventually you may end up writing your character controllers as a mish-mash of both, but that's generally inadvisable when you're starting out - explore one at a time.

indigo cobalt
#

hey, I just wanna say thanks for your help

with your help I actually got the code to work, my char only jumps once and cant jump again till they hit the ground

at first the reason my char was able to keep jumping is because i had a duplicate of my jump code outside of my "isjumping" bracket thing. so once I moved the code into the bracket and deleted the duplicate my code started woorking the way i wanted it to

#

thank you for helping me