I'm making a marbles-like game in which you drag your mouse on the screen and shoot a marble ball, trying to get it into the hole at the end of the level. There'll be walls and other marbles in your way. I already used step velocity rather than x velocity + y velocity. How can I make it so the ball will bounce off other marbles and walls in a realistic way?
Offline
Make sure to use directional values, and when it hits a wall use this script:
if touching wall?
Point in direction (direction) - 180)
Try to figure out the rest. I hope that helped!
Offline
samurai768 wrote:
Make sure to use directional values, and when it hits a wall use this script:
if touching wall?
Point in direction (direction) - 180)
Try to figure out the rest. I hope that helped!![]()
That doesn't work on the left wall.
60 second rule must die. now.
Offline
samurai768 wrote:
Make sure to use directional values, and when it hits a wall use this script:
if touching wall?
Point in direction (direction) - 180)
Try to figure out the rest. I hope that helped!![]()
That only half works- it makes the marble bounce back the way it started.
Offline
ScratchReallyROCKS wrote:
samurai768 wrote:
Make sure to use directional values, and when it hits a wall use this script:
if touching wall?
Point in direction (direction) - 180)
Try to figure out the rest. I hope that helped!![]()
That doesn't work on the left wall.
60 second rule must die. now.
It should work for both walls if any.
And you probably need to add a "Move 10 steps" after the script just to make sure it comes off the wall when it turns around.
Offline
you need 2 formulas for horizontal and vertical bounces in Scratch...
direction * (-1)
(180) - direction
http://scratch.mit.edu/projects/Locomule/709464
Last edited by Locomule (2010-08-24 23:15:33)
Offline
If all walls are vertical or horizontal, it's pretty easy. If you have slanted walls, it gets much more complicated.
For vertical walls, the bounce direction is (0 - direction)
For horizontal walls, the bounce direction is (180 - direction)
For slanted walls, see my Marble Roll Kit project
http://scratch.mit.edu/projects/Paddle2See/800850
Oops, I see that Locomule gave pretty much the same exact answer previously
Offline
Now we call that ninja'd lol. But you are being kind, I've seen your pinball projects, awesome! Guess I missed the marble roll kit, have to check that out too.
Offline
Wait, you will need to explain a bit more about your project.
I thought it was flat and looking down at it, but it could be vertical and looking at it from a side or even sort of 3D
Offline
colorfusion wrote:
Wait, you will need to explain a bit more about your project.
I thought it was flat and looking down at it, but it could be vertical and looking at it from a side or even sort of 3D
You were right the first time.
Offline