Block Breaker Question

I am working on block breaker & I have a kinda simple question. How can I make it so that my movement speed increases if I hold a button? Like if I hold X on the controller while moving the paddle would move faster?

…public class MoveLR : MonoBehaviour
{

public float PlayerSpeed = 5;

// Start is called before the first frame update
void Start()
{
}

// Update is called once per frame
void Update()
{
    float amtToMove = Input.GetAxis("Horizontal") * PlayerSpeed * Time.deltaTime;
    transform.Translate(Vector3.right * amtToMove);
}

}…

I have that to move the paddle with the gamepad instead of the mouse.

Hi David,

In the Update method, you could add Time.deltaTime to the value of your speed variable. Since your idea is to make this happen if a key is pressed down, you could wrap the code in an if-statement. If you do not know yet what this is or find this too challenging, I would recommend to complete the next few sections. After you completed the course, you should have learnt enough to implement that feature in your game.

Also please feel free to ask our helpful community of students over on our Discord chat server.

I hope this helped. :slight_smile:


See also:

TY I’ll do that today. I completed the course like 3 years ago but I don’t remember everything. I don’t do much coding I ended up paying someone to do 80% of my codes for the game while I do the building.

…{

public float PlayerSpeed = 5;
bool mofe = false;

// Start is called before the first frame update
void Start()
{
}

// Update is called once per frame
void Update()
{
    float amtToMove = Input.GetAxis("Horizontal") * PlayerSpeed * Time.deltaTime;
    transform.Translate(Vector3.right * amtToMove);
}
private void Mofast()
{
    if (CrossPlatformInputManager.GetButtonDown("Fire1"))
    {
        PlayerSpeed = 20f;
    }
}

}
/* mofe = PlayerSpeed = 20*/…

That’s where I’m at sofar.

So what I’m trying to do is make a bool that’s move faster. I need to serializefield or I can just input & say double speed is 20 because normal speed is 10.
My issue is I can’t seem to get the bool to work.
I’d assume it’s true when the player presses A (for example).
There is no problems detected with the code. I can play the game but what happens is nothing happens when I press A to speed up & the code tells me my code is not being used. I tried some things but that’s where I am basically.

Without knowing your code, it is impossible for other people to tell you what might have gone wrong.

Privacy & Terms