-
-
Notifications
You must be signed in to change notification settings - Fork 34
Home
- The ball keeps slowing down
- The AI keeps missing the ball
- There are no functions available to select for the score trigger
- Script variables are not showing up in the editor
This usually is an indication that the ball has drag which causes it to slow down over time. If you want your ball to maintain the same velocity and not slow down, set the Linear Drag
property on the Rigidbody
component to zero.
If the ball slows down when hitting a wall, it is because of the friction between the two objects colliding. To prevent this friction, add a Physics Material
to your ball's collider component with the Friction
value set to zero.
Try changing the Mass
and Linear Drag
on the Rigidbody
component of your AI paddle. Reducing these values allow the paddle to more easily switch directions, which will help it to be in the right place at the right time to hit the ball. Be careful though, because you can create the opposite problem where the paddle never misses. Adjust the numbers to your preference. You can also change the speed
property that we added to the paddle script to make it faster or slower overall.
A common mistake here is dragging the GameManager.cs
file into the field rather than the "Game Manager" object in your scene. After dragging in the scene object, you should see the functions available on each component attached to that object, including the functions made available in our script.
The other common mistake is not marking your functions as public
in your code. Only public functions are available in the menu. If you don't explicitly set them to be public, then they will default to private.
public void PlayerScores()
{
//...
}
There are two ways for a field to show up in the editor. It can be marked public:
public float speed;
Or you can use a special attribute:
[SerializeField] private float speed;
If the variable still does not show up, this might be an indication that you have a compiler error. Your code must successfully compile before any new fields will display in the editor. Check your console for any potential errors.