Cube Movement (Jumping +1 Forward/Right/Backward/Left)

Hey community,

First of all:

  • I’m new here in the community and hope my post is in the right discussion area.
  • I’m still very new about programming with C# and Unity.

My question:
I’m working on an idea for a Movement of a Cube.
It is planned that the cube will move forward by pressing a key (W-Key). But it shouldn’t just move forward. It should jump forward to the next point. So always plus 1 of its axis into which it should go. Accordingly, it is only intended to go forward, right, down, left. He won’t be able to jump over behind. You should also see that the cube jumps in the respective direction, so it should not teleport itself. :smile:

Does anyone have an idea how I can realize this movement?
I am very much looking forward to your ideas.

(Sorry if my English is not so good, my English not the best. ^^)

best regards
xKarToSx

There are multiple ways implementing such movement (and probably any other). One way is to rely on physics - just add precalculated impulse to the rigidbody and it will jump forward and then stop. You may want to edit rigidbody constraints to exclude inappopriate rotations from jumping.
Another approach uses animation and root motion. Animate your cube and play the jumping clip when it needs to jump. If you add root node motion to the animation, then the cube position in scene will be altered accordingly.
Also feel free to experiment and use your own approach as it might be better for the game you doing and it will be right and correct if the cube moves as desired. Many popular games arose from just original player control scheme.