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

0 favourites
  • 11 posts
From the Asset Store
Bouncing ball
$9.99 USD
Template for a bouncing ball game, fully documented in comments and video
  • 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?

    Thanks in advance!

  • 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.

  • Or do you mean something like This?

  • 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

  • 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!

  • The math was visual initially too. Although I only roughly recall how I derived it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • LittleStain Thanks for the solution

    R0J0hound Very elegant. I learned something new today. Thank you!

  • 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

  • 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.

  • 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

  • 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

    Ok So I was not wrong in thinking you wanted 90 degree right angles.

    R0J0hound made me believe I as incorrect again. I was right about the right angles and R0J0hound was wrong. (This is very unusual)

    Maybe my english is not so bad afterall? This is good. My feelings where hurt yesterday. I felt like I could not read anything. I almost gave up on helping people.

    Glad you got the answer you wanted sivricmarijan

    have a nice day.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)