# How do I force the sprite to bounce with right angle?

Get help using Construct 2

### » Tue Oct 20, 2015 1:22 pm

Hello guys and girls!

I have 2 sprites: a player and enemy. Both of them are just simple circles. When they collide, I want the enemy sprite to bounce off the player sprite but not in the opposite direction of the place where it touched the player sprite. I want it to bounce with the right angle! How can I do it?

B
9
S
4
G
3
Posts: 157
Reputation: 2,300

### » Tue Oct 20, 2015 2:20 pm

A right angle is 90 degrees. so on collision have it set the angle.

Collide with sprite------> set angle: Choose (-90+Self.angle,90+self.angle)

That will randomly pick weather to veer left or right and keep a localized orientation. It will clamp it to a 90 degree turn left or right.

Also change the sprites collision polly , and make it more sphere like, it will make so it will bounce more like a ball. Not sure about C2 but most physics engines support a simplified collision. You can choose Collision poly, box, circle, pill. If C2 uses this, then it is better to use.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

### » Tue Oct 20, 2015 4:05 pm

Or do you mean something like This?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Tue Oct 20, 2015 7:19 pm

While 90 is a "right angle", in this situation right angle means the correct angle. LittleStain's example visualizes it perfectly but you can simplify it to just this:

projectile: on collision with target:
--- projectile: set angle of motion to 2*(angle(Self.X,self.Y,target.X,target.Y)+90)-Self.Bullet.AngleOfMotion
B
95
S
34
G
128
Posts: 5,493
Reputation: 81,674

### » Tue Oct 20, 2015 7:31 pm

R0J0hound wrote:While 90 is a "right angle", in this situation right angle means the correct angle. LittleStain's example visualizes it perfectly but you can simplify it to just this:

projectile: on collision with target:
--- projectile: set angle of motion to 2*(angle(Self.X,self.Y,target.X,target.Y)+90)-Self.Bullet.AngleOfMotion

I think I'll always keep thinking visually..
Thanks for the maths!
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Tue Oct 20, 2015 8:06 pm

The math was visual initially too. Although I only roughly recall how I derived it.
B
95
S
34
G
128
Posts: 5,493
Reputation: 81,674

### » Tue Oct 20, 2015 8:15 pm

@LittleStain Thanks for the solution

@R0J0hound Very elegant. I learned something new today. Thank you!
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

### » Wed Oct 21, 2015 6:11 am

Thanks guys but I want the sprite to bounce with 0, 90, 180 or 270 angle...it depends on the angle of collision. I want it to go left, right, up or down. I hope you understand what I want
B
9
S
4
G
3
Posts: 157
Reputation: 2,300

### » Wed Oct 21, 2015 8:30 am

Ah, so I was wrong about the type of right angle.

so the ball only ever goes 0, 90, 180 or 270 degrees?
You can just brute force it and make an event for each case. Here's one example:

Ball on collision with circle
Ball.angle = 0
Ball.y < circle.y
--- ball set angle to 270

Just make seven more like that for every posibility. It could then be simplified using sub-events and else's.
B
95
S
34
G
128
Posts: 5,493
Reputation: 81,674

### » Wed Oct 21, 2015 9:21 am

R0J0hound wrote:Ah, so I was wrong about the type of right angle.

so the ball only ever goes 0, 90, 180 or 270 degrees?
You can just brute force it and make an event for each case. Here's one example:

Ball on collision with circle
Ball.angle = 0
Ball.y < circle.y
--- ball set angle to 270

Just make seven more like that for every posibility. It could then be simplified using sub-events and else's.

I did that and it didn't work. It started working after I set the "Set angle" property of the Bullet behavior to YES. Thanks guys
B
9
S
4
G
3
Posts: 157
Reputation: 2,300

Next