I am using a controller in my game but when I move the stick it only moves my character a tiny bit!?
Here is my code.
PlayerControls controls;
Vector2 move;
void Awake()
{
controls = new PlayerControls();
controls.Gameplay.Move.performed += ctx => move = ctx.ReadValue<Vector2>();
controls.Gameplay.Move.canceled += ctx => move = Vector2.zero;
}
void Update()
{
Vector2 m = new Vector2(move.x, move.y = 0.8f) * Time.deltaTime;
transform.Translate(m, Space.World);
}
void OnEnable()
{
controls.Gameplay.Enable();
}
void OnDisable()
{
controls.Gameplay.Disable();
}
I have also attached a video.
Hello :)
Have you tried to debug the code and see what value you have for move.x each time update is called?
When you take move * time.deltatime I guess move.x value wich was for example 1 will be only maybe 0.001
So I guess it will move in x by 0.001 units each update. Try adding a fixed value to move.x and see what value you need it to be for the cube to move faster.
Maybe add time.deltatime * speed
(Where speed will be a value of say 1, 2 or 3. Change that value until the cube moves as fast as you want to)
Try removing * time.deltatime and see if it goes faster.
That way you will know if it is the Time.deltatime that is the problem.
Also just debug the code to see if move.x get a different value depeding on when you move the controller.
Answer by jmhoubre · Oct 05, 2021 at 09:10 PM
Use a speed (like 5.0f) and multiply m by speed. Time.deltaTime is a very tiny float (at 60 FPS , about 1/60 ~ 0,0166667.
@jmhoubre Thank you so much! I did have to change the title of the game to Hoppy Cube from Blocky because the cube kept hopping but I like it more this way.