Suggest a correct way for dealing with character movement

I am about to program a platformer similar to SkyRoads. In my game I want specific number of lanes say 5. The ship will move from one adjacent lane to another and can jump in the same lane or to the adjacent lane.

70032-skyroads.jpg

What will be the correct way for movement control of the ship?

  1. Use rigidbody without gravity and move ship using Transform. OR

  2. Move the rigidbody under gravity using velocity/force.

(I have no clue of how to assign the correct velocity/force so that the ship jumps the fixed distance to land on the adjacent lane)

What do you suggest considering the ship does not move freely as it does in SkyRoads?

I’d suggest writing your own movement, and not relying on unity physics.

Set your rigidbody to IsKinematic. Create a member variable that holds the width of your lanes and lerp between the x-value of the middle of the currentlane and the x-value of the middle of the next lane (which is x - laneWidth or x + laneWidth). (Also create a variable that remembers which lane you are currently in to check if you don’t move outside of the track. )At the same time, for the forward movement, set a speed on your z-axis by incrementing the z of your position each frame. Don’t forget to multiply by Time.deltaTime to get smooth movement. Since I’m currently doing pretty much the same thing, here is my code for calculating the jump (it is a coroutine)

private float m_JumpSpeed = 10f;

    private IEnumerator Jump()
        {

            float gravity = -Physics.gravity.y;
            float jumpVelocity = m_JumpSpeed;
            float initialY = transform.position.y;
    
            while (transform.position.y >= initialY)
            {
                transform.Translate(0f, jumpVelocity * Time.deltaTime, 0f);
                jumpVelocity -= gravity;
                yield return null;
            }
    

            transform.position = new Vector3(transform.position.x, initialY, transform.position.z);
        }

Hope this helps.

@Tyche10 I got your answer. I’ve done that thing in previous projects too, but I have faced issues when dealing with a complex character with so so many moves.

Between, using Coroutines for updating Transform is a bad thing. Unity has Update function for it. If dealing with physics then FixedUpdate