# How do I quickly and easy figure out which side of a sprite.

0 favourites
• 22 posts
From the Asset Store
Build your own spaceship for your side scroller space shooter games with various components.
• Also I have a feeling this formula doesn't know which side the sprite is, really. hmm?

Got suggested this post by R0J0hound I will examine the code it might be the solution.

(at first glance I see the ball is not even having any behavior, all coded in events!)

• Doing it with just events is simple enough. Give the ball two variables vx and vy for the x and y velocity. Motion is done by appling the formula speed*time=distance. You can also set it from a speed and direction if you so please with a simple convertion from polar coordinates to rectangular: vx=speed*cos(direction) and vy=speed*sin(direction).

Then instead of using a plugin or behavior, just check the position against the four walls and bounce. See attached capx.

That's just for outside walls. For inside walls you'll need push the ball out of the wall before using overlaps at offset to bounce. In the following link I implemented the push out with just events and it works well enough. If you make the ball too fast so that the jump of positions completely misses the wall then this still could fail.

To solve passing through walls you'll want to check the positions in between or do a raycast.

For the first you could do the same as this bouncing laser example:

• ## Try Construct 3

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

Construct 3 users don't see these ads
• Thank you for your help! Lots of good examples there. I will try to wrap my head around this one.

Looks quite elegant too.

Thanks again.

Now off to do the evening out but tomorrow it is code time!!

• Here is my take of your examples, I combined the two different capx into one.'

No custom plugins, yay!

It seems to work nicely. Even in quite high speeds. Of course on my iphone 4 it is at 10-15 fps. (but it could be the every ticks-change text so nevermind for now)

I have new questions.

1. How do I change the angle, if I like want to nudge it 1-2 degrees? Good to have when ball is stuck in endless loop bounce in levels with intricate solid walls.

2. If I want to make a paddle where it would change angle depending on where it is hit on the paddle itself. Or if I add round objects.

Thanks!!

• 1.

You could either just nudge vx and vy around when bouncing. For example for a horizontal bounce:

set vx to -self.vx

A vertical bounce can be done similarly.

Or you can actually nedge the angle. To do that takes two steps. First calculate speed and angle from vx and vy, then convert it back to vx and vy from that after nudging the angle.

ang = angle(0,0,ball.vx,ball,vy)

speed = distance(0,0,ball.vx,ball,vy)

vx = speed * cos(ang+random(-2,2))

vx = speed * sin(ang+random(-2,2))

2.

For changing the angle depending on where on the paddle was hit you could just add the horizontal distance between the ball and paddle when hitting the top of the paddle (event 16). So basically:

You could multiply it by 0.5 or something to make it more subtle.

For actual round objects you'd need something better for contact normal detection.

This may work, you may want to add 1 or so to the radius check.

``````local number NormalAngle=0

For each roundWall