Sometimes the ball either translates in horizontal motion after hitting the block or slows down after hitting the wall. And also the ball “Sticks” to the wall, either not bouncing off nor retaining the speed.
Can someone please help me?
Sometimes the ball either translates in horizontal motion after hitting the block or slows down after hitting the wall. And also the ball “Sticks” to the wall, either not bouncing off nor retaining the speed.
Can someone please help me?
Hi,
In which lecture are you? Have you already implemented RIck’s tweak for preventing endless loops? Have you tried to set the collision detection mode of your ball’s Rigidbody2D component to “Continuous”?
Yes, I’ve done that but still the above problem remains!
Show us the code to Implement velocityTweak the better way. Help🤔
What do you mean by “better way”? Did you decrease the tweak value? Set it to 0.05 or 0.01.
No need fixed it myself;
Vector2 tweakVelocityOfBoth = new Vector2(Random.Range(0.1f, randomFactor), Random.Range(0.1f, randomFactor));
Vector2 tweakVelocityOfX = new Vector2(Random.Range(0.1f, randomFactor), 0);
Vector2 tweakVelocityOfY= new Vector2(0, Random.Range(0.1f, randomFactor));
myRigidBody2d.velocity = myRigidBody2d.velocity.normalized * ballSpeed;
if (hasStarted && myRigidBody2d.velocity.x >= 0 && myRigidBody2d.velocity.y >= 0)
{
myRigidBody2d.velocity += tweakVelocityOfBoth;
//Debug.Log(myRigidBody2d.velocity);
}
else if (hasStarted && myRigidBody2d.velocity.x <= 0 && myRigidBody2d.velocity.y <= 0)
{
myRigidBody2d.velocity -= tweakVelocityOfBoth;
}else if(hasStarted && myRigidBody2d.velocity.x >= 0 && myRigidBody2d.velocity.y <= 0)
{
myRigidBody2d.velocity += tweakVelocityOfX;
}
else if (hasStarted && myRigidBody2d.velocity.x <= 0 && myRigidBody2d.velocity.y >= 0)
{
myRigidBody2d.velocity += tweakVelocityOfY;
}
Took that much effort (my whole day)
Good job on developing your own solution!
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.