Adding velocity to an object in a brick breaker game
I am trying to use else if statements to modify the velocity of my ball once it reaches a speed on each axes. I figured that the velocity in this type of game should only change upon collisions so I decided to make the statement based on velocity instead of something on collision. My statements aren't seeming to do anything at the moment, so I'm assuming I've made an error at some point. I put in comments to label anything that seemed important so please lend me some advice on how to fix this =)
Just for clarification, I want the ball to adjust when its moving very slowly on either axes and the force to be distributed in the direction it is moving. For example: its moving 0.01f on the X axes per second and the adjustment would add a positive 10f to its velocity in that direction.
public void FixedUpdate()
{
/* X axis adjustment */
if (rb.velocity.x > 0 && rb.velocity.x < 0.1)
{
rb.velocity = new Vector3(10f, 10f, 0f);
ballIsStuck = true;
}
else if (rb.velocity.x > -0.1 && rb.velocity.x < 0)
{
rb.velocity = new Vector3(-10f, -10f, 0f);
ballIsStuck = true;
}
/* Y axis adjustment */
if (rb.velocity.y > 0 && rb.velocity.y < 0.1)
{
rb.velocity = new Vector3(10f, 10f, 0f);
ballIsStuck = true;
}
else if (rb.velocity.y > -0.1 && rb.velocity.y < 0)
{
rb.velocity = new Vector3(-10f, -10f, 0f);
ballIsStuck = true;
}
}
Your answer
Follow this Question
Related Questions
Climbing code problem (2d physic). 0 Answers
Rigidbody rotate velocity 0 Answers
Trying to add force to an object... is this done correctly? 0 Answers
Addforce for 2d game is not doing anything. 0 Answers
Why/How 2d tower of blocks collapse? 0 Answers