1
\$\begingroup\$

So, I have a player who remains in the same X position. the floor moves from right to left underneath the player, and I am using tiles of 1 unit.

Here's my jumping stuff:

if (RB.velocity.y < 0)
{
    RB.velocity += Vector2.up * Physics2D.gravity.y * (FallMultiplier - 1) * Time.deltaTime;
}
else if (RB.velocity.y > 0)
{
    RB.velocity += -Vector2.up * -Physics2D.gravity.y * (JumpMultiplier - 1) * Time.deltaTime;
}
if (/*Input.GetKey(KeyCode.Space) &&*/ IsGrounded && JumpDelay < 0)
{
    RB.velocity = Vector2.up * JumpVelocity;
    JumpDelay = 0.1f;
    Debug.Log("Jumping");
}

And here is what moves the floor:

Vector2 NewPosition = TF.position;
NewPosition.x -= Time.deltaTime * Speed;

TF.position = NewPosition;

So, what I want to happen, is I have a movement speed for the floor, and I want to make it line up such that if I jump where the player is directly in the middle of one floor tile, they will land (say 4 tiles later) directly in the middle of another tile.

I can get close by tweaking the velocities... but this feels the wrong way. I want to know what values I might be able to use, and how to calculate what velocities they should be.

Speed of floor right now is at 5, Jump Multiplier at 1.75 and Fall Multiplier at 7. There of course do not line up as I hope, but it gives example values in case that helps. How would I solve this to say, for example, with the given multipliers, what should the floor speed be to line up perfectly?

\$\endgroup\$
  • 1
    \$\begingroup\$ Try searching on google and youtube for "kinematic equations", you may find useful info. \$\endgroup\$ – Nikaas Jul 13 '17 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.