|
Following a tutorial, I have created a ball that bounces along 3 walls with a paddle at the bottom, like the game Pong. Sometimes the ball gets stuck in a straight line bounce loop, bouncing from one wall to the other and back with no variation. I'd like to add a bit of randomness to the bounce angle to the ball so that it doesn't get stuck. I found a similar question answered already, but it was answered with C#, and the tutorial script is in javascript. Everything I tried did not work. Would Random range and vector help? I don't know how to implement them into the script. Part of the script added to the ball:
(comments are locked)
|
|
I guess you could just add some force when it hits: I tried this and I thought it might have worked. But today it got into another loop. The ball started bouncing from one side of the wall, to the other, and back and forth. I was hoping a little random variation in it's bounce angle would get it out of those loops? Maybe the title of my question is wrong. I'm really looking for some random bounce in the ball, specifically in the angles, when it hits a surface. So if the ball bounces onto a surface at 90 degrees, maybe the bounce off would be 88, or 91 degrees (just a random degree or 2 off) the other way.
Jul 17 '12 at 02:00 AM
wakeupscreaming
Try a bigger force?
Jul 17 '12 at 02:57 AM
whydoidoit
I used a higher force. What I'm noticing is that the ball then has a higher propulsion -- it goes faster, or slower. I'm not really looking for something that goes faster, or has anything to do with the speed of the ball at all. I want the angle of the bounce to be random. Here is a similar question, not the exact problem, but similar: http://forum.unity3d.com/threads/138770-Breakout-Pong-ball-stuck-to-wall-problem All the answers are in C#. I'm working in Javascript. Thanks.
Jul 17 '12 at 03:12 AM
wakeupscreaming
Right so take the velocity magnitude before you apply the force and map it back after:
Jul 17 '12 at 03:15 AM
whydoidoit
Just FYI, with a 1000, it still got into a vicious loop bounce cycle from wall to wall. What does the 1000 mean? So if 1000 still gets the ball bouncing from one wall to the other, then should I put in 10000?
Jul 17 '12 at 03:55 AM
wakeupscreaming
(comments are locked)
|

Can anyone just translate the C# Answers from "Breakout Pong Ball Stuck to Wall Problem" to Javascript? Please help me. http://forum.unity3d.com/threads/138770-Breakout-Pong-ball-stuck-to-wall-problem
It's just a direction of vector problem.