# RigidBody2D + velocity slowing down game with input system

Hello,

I’m following this tutorial to create old school super mario bros:

But am adapting the video towards movement with the input system instead of the old hard coded one.

The code I’ve got goes like:

``````using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Security.Cryptography;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UIElements;

public class PlayerMovement : MonoBehaviour
{
private Camera cam;
public Rigidbody2D rb;
private Transform player;
public float speed;
private UnityEngine.Vector2 velocity;
public InputActionReference move;

SideScrolling SideScroll;

private void Awake()
{
cam = Camera.main;
}
private void Update()
{
rb.velocity = new UnityEngine.Vector2(x:velocity.x * speed, y:velocity.y * speed);

}
private void FixedUpdate()
{
UnityEngine.Vector2 position = rb.position;
position += velocity * Time.fixedDeltaTime;
UnityEngine.Vector2 leftEdge= cam.ScreenToWorldPoint(UnityEngine.Vector2.zero);
UnityEngine.Vector2 rightEdge = cam.ScreenToWorldPoint(new UnityEngine.Vector2(Screen.width, Screen.height));
position.x = Mathf.Clamp(position.x, leftEdge.x + 0.5f, rightEdge.x);

rb.MovePosition(position);
}
}
``````

Seems to talk about the same issue. In there they talk about splitting the input and movement systems in 2 to split the processing load which would be causing the slow motion effect. This doesn’t work when I try to limit the player’s movement to not be able to go “out of bounds”. I’m definitely doing something wrong.

Any ideas on how to fix or adapt my code?

It involves moving left, right, up and down. The camera follows the player as he moves forward, but blocks any attempt to go back.

Sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use `Debug.Log(...);` statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Refactoring any code from Old Input to New Input system (oldinput, newinput, inputmanager):

Also applies to adding new sources of input to your game.

1 Like

I forgot to multiply the speed
from:
position += velocity * Time.fixedDeltaTime;

to:
position += speed * velocity * Time.fixedDeltaTime;

it works now.