# Help with implementing collisions and gravity in Scratch

I am fairly new to programming & only have extremely novice experience using Python (which was even more basic than what I can do in Scratch).

I have been trying to make a 2 player volleyball game in Scratch: http://scratch.mit.edu/projects/24260954

Things had been going smoothly until the interaction of the ball sprite and the player sprite. When the ball touches the player, it should move opposite to the angle it came from (taking the the player as the normal) & afterwards, gravity should also affect it so that it actually comes down towards the other player. I did see how to add gravity using the scratch help page but can't seem to implement it properly.

I would be very thankful if someone can shed a little light on this problem.

P.S: I mostly worked on Brock sprite, since the other sprite will pretty much replicate the first one so please note that before checking it.

This needs a bit of physics knowledge. It should be basically easy though! Let's imagine how gravity affects the ball in real life!

I'm not sure the following will be 100% correct since I haven't studied physics in years

As I hit the ball up when it's going down, it starts moving up. It's velocity as I hit it is 0. It then increases, let's say (supposing I'm a superman) by 100 m/s and as the gravity affects the ball with some force in the opposite direction, then velocity starts decreasing until it gets to 0 again (in the air this time), then the ball starts moving down with acceleration of 9.8 m/s squared.

How to simulate this?

The key to the solution is definitely variables. You should create a variable that stores the velocity of the ball on the y-axis. We'll assume that when the velocity of the ball on the y-axis is negative, this means that the ball is moving up and when it's positive, then the ball is moving down.

We could have assumed the opposite (i.e., positive means up and negative means down) and in fact, that would be more familiar, but unfortunately, this is the way computer graphics work so not to be confused.

As the player hits the ball, the velocity should become negative and starts increasing until it becomes 0 then it keeps increasing until it hits the a player or the ground. At this moment, it should become negative again and the process repeats!

The amount with which the velocity of the ball is decreased/increased may be stored in another variable and this amount itself may be increased/decreased depending on how much you want your game to be realistic! ;)

add a line to ball sprite in motion->if on edge bounce. so that the ball will bounce back! you've created speed,set it to 1. if ball touches the ground, then change speed by -1. so, speed decreases n finally becomes zero! if its zero end script saying game over! i ask you to include a line in sprite net, if net touches ball say net and change speed by -1. hope this works