Block breaker paddle movement seems a little stuck

What i’m doing right now with mouse movement is:

void MoveWithMouse()
{
    float mousePosInBlocks = Input.mousePosition.x/Screen.width*16;
    Vector3 paddlePos = new Vector3(0.5f,this.transform.position.y,0f);
    paddlePos.x = Mathf.Clamp(mousePosInBlocks,minX,maxX);
    this.transform.position = paddlePos;
}

Please help me with how to it corretly and smoothing up the paddle movement
and share maybe what you did in mouse-paddle movement.

Thanks

Hello Ori,

Your code looks ok.

Can you provide a little more information, when you say “movement seems a little stuck”, what exactly does this mean?

Is the paddle being moved at all when you move the mouse? Does it not respond at all?


See also;

It’s moving ok - but seems to be a little delay when doing big movements, nothing too serious…
Just wondered maybe other code can make the movement quicker and like I said smoother

1 Like

Tricky to tell without seeing but you could set the script execution order and see if that helps.

Its under Edit / Project Settings / Script Execution Order.

Add the paddle script to the top with a low number and then re-run your project and see if there is any noticeable difference.

Hi, Ori. Maybe you could try something like acceleration, instead of a 1:1 movement.

I haven’t tried it yet in Unity, but in Gamemaker you would use the lerp function. Which gradually increments one value until it reaches a max value.

For example, this would increase the player’s speed by 1 every frame until it reaches a max speed of 10.

acel = 1;
max_spd = 10;
if kb_right {
   spd =  lerp(spd, max_spd, acel);
}

So for block breaker, you would increase or decrease paddle X position until it is equal to mouse X position.

Another thing that would affect the “smoothness” is the framerate and general performance. I don’t know how to check this in Unity yet, but maybe make sure your game is running at 60fps. Increasing the game resolution and sprite sizes will also help as it gives the paddle more pixels inbetween to smooth the movement.

Hope it helps.

Privacy & Terms