one other note, i added everything back to FixedUpdate and you can actually watch the ball slide down through the paddle and off the screen. The actual Y vector does not change in the print statements during this movement, but you can see the value has changed when the trigger is fired.
When you say the ball isnt bouncing, do.you mean you cant launch it on the OnClick
event, or that you can, it moves upwards but then doean’t bounce when it hits the paddle?
Ah, I mean that it doesn’t launch from the OnClick event.
In the course I’m sure it used to set a velocity rather than use a force, perhaps consider trying that in the method call for checking the mouse click.
That does seem to fix the issue.
Your explanation of what is happening makes sense, although it doesn’t quite explain why the magic numbers make a difference or why it doesn’t just bounce when it hits the paddle collider. But, it works, and for that I’m happy! Perhaps as i learn more it will all be more clear. Thanks for all your help on this Rob!
Cheers,
James
Hi James,
At the end of the end of the day I do believe this will simoly be down to timings and the way the physics are calculated.
The fact that the ball can effectively slip through the paddle, where visible or not, indicates a significant issue, this can often be seen in collision detection when one object is moving very fast and hits another. Changing the collision detection to continuous for the ball would be advisable as it will help with that issue, and as we have seen, also resolves the primary issue. As such, the starting height of the ball above the paddle theb doesn’t matter, thus irradicating the magic numbers. All moving the ball really did was effect the timings and physics enough to prevent it falling through the paddle. It’s possible on another machine this wouldn’t have been adequate.
Hope this is a bit of a better explanation
This helps a lot Rob. Thanks!
I’m actually confused about why this line isn’t in Update(). Doesn’t it need to be constantly calculated?
Also, my game stops after exactly 5 seconds, regardless of input, with the Trigger log.
This line?
paddleToBallVector = this.transform.position - thePaddle.transform.position;
Assuming so, no, this is setting the paddleToBallVector
. Once you have this, until you launch the ball, the vector between the paddle and ball would remain the same, no matter where the paddle is.
What you obviously do want to be constantly calculating is this line;
this.transform.position = thePaddle.transform.position + paddleToBallVector;
This will ensure that when you are moving the mouse and thus, the paddle, the ball stays in it’s relative position to the paddle (until launched). Around it should be the check to see if the game hasStarted as once it has, you don’t need to do the above.
Regarding your issue about the game ending, try setting the Collision Detection on the Rigidbody2D component of the Ball to Continuous.
Okay! Yes…the difference between the two objects calculates once. Got it…thanks!
Also, I confirmed that Continuous does the trick (just don’t know why).
Ben is getting faster and faster as we go.
Also, I confirmed that Continuous does the trick (just don’t know why).
I think I covered this above, but obviously there are quite a lot of posts
You are effectively increasing the frequency in which a collision is detected. Previously, it was possible for the ball to not trigger a collision with the paddle, fall through the paddle (because of the gravity) and make contact with the LoseCollider.
The collision detection on the paddle on covers a very small area, thus a fast moving object may make it through, the LoseCollider is significantly bigger, so even if it makes it in fractionally, it’s caught on the next iteration.
If you consider which objects will be moving in the game, and how often they are likely to collide with other objects, the paddle will obviously have some collisions, but only with the ball (based on the course anyway), the outer edges are covered by using Mathf.Clamp()
.
The blocks are not going to be moving at all (again, based on the course), however, it is possible that they may be hit in very quick succession depending on the layout of your level (ball bouncing up and down frantically between two rows of blocks for example).
Finally, the ball itself, this object is going to be hitting everything, and, as we have just mentioned above, it maybe bouncing off of other objects like crazy when it’s caught between multi-hit blocks.
I would definitely set the Ball to have Continuous collision detection. There is obviously going to be a small overhead with more checking of collisions, but this is a fairly lightweight game so you aren’t going to really notice anything.
Regarding the blocks, play test - see what happens, if you have a situation where blocks are not registering hits because of missed collisions, increase the Collision Detection - it’s probably unnecessary though.
I just want to say thanks, i had this issue aswell, this thread was very usefull. Thanks!!!
I was having this same issue too, here is what I did to fix it.
Note: I’m using unity 5.5.2
In ball script within the start method add the following:
this.GetComponent<Rigidbody2D>().simulated = false;
then in the update method at the begining of the Input.GetMouseButtonDown(0)
if statement add:
this.GetComponent<Rigidbody2D>().simulated = true;
Below is my whole ball script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour {
public Paddle paddle;
private bool hasStarted = false;
private Vector3 paddelToBallVector;
// Use this for initialization
void Start () {
paddelToBallVector = this.transform.position - paddle.transform.position;
this.GetComponent<Rigidbody2D>().simulated = false;
}
// Update is called once per frame
void Update () {
if (!hasStarted) {
// Lock the ball relative to the paddle
this.transform.position = paddle.transform.position + paddelToBallVector;
// Wait for left click to launch
if (Input.GetMouseButtonDown(0)) {
this.GetComponent<Rigidbody2D>().simulated = true;
hasStarted = true;
print("left click, launch ball");
this.GetComponent<Rigidbody2D>().velocity = new Vector2(1f, 10f);
}
}
}
}
Ditto on the thanks. I’ve been doing this on Unity 4.7, and started having the same problem. I’m still working through the lesson - haven’t even started the OnClick event. Not knowing outside of these lessons I was able to use other.gameObject.name to figure out it was the ball. But still struggling to figure out why.
Changing the Collision Detection to “Continuous” did the trick.
Hi,
I couldn’t work out from your post which bit you were still struggling with, let us know and I will see if I can help
Hi, Rob,
I was in the middle of lesson 78. (After afixing the ball to the paddle.) The ball started randomly dropping through the paddle after starting the scene. I wrote in some script with the debug.log to see if either the ball moved or the paddle moved. I was able to see that the paddle remained, but the balls just dropped through. The ball no longer fell through after setting the collision detection to “continuous” on the paddle.
Great to hear that you’ve resolved the problem and well done for diagnosing it
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.