# How do I work out the direction of a bullet?

Just started using Construct 2? Post your questions here

### » Fri Aug 29, 2014 6:49 pm

I'm doing a bit of a Pong game and I am trying to get the computer controlled paddle to react a bit more that following the Y co-ordinate of the ball.
I would like the paddle to move to the middle of the screen when the ball is traveling away from it and move to the balls Y co-ordinate when the ball is moving towards it.

The ball has a bullet behavior and the paddles bounce the ball in the reverse direction. Its sprite is set to not rotate.

My problem is that I can't work out how to tell which direction the ball is traveling in. I would have thought the bullets Angle Of Motion (as per the manual) but all I get on the ball are 'Compare distance traveled' and 'Compare speed'.

Any help at all would be gratefully received.
Dave
B
9
S
3
G
1
Posts: 23
Reputation: 828

### » Fri Aug 29, 2014 8:44 pm

if you have "set angle" on the bullet behaviour set to on you can just compare the normal angle and if not you can use "System compare two values" for the firwt value you can then set ball.bullet.angleofmotion
B
39
S
11
G
5
Posts: 485
Reputation: 5,365

### » Fri Aug 29, 2014 10:41 pm

Thanks for the reply though I'm not sure I fully understand it. I have set angle to random (360) to start off with and I'm not trying to set angle of motion, just trying to find out what it is. My idea is that if it is 0 degrees (+ or - 90) it is traveling to the right etc. I'm pretty much a beginner here and maybe that is not the easiest way of finding the direction of travel of the bullet object?
B
9
S
3
G
1
Posts: 23
Reputation: 828

### » Fri Aug 29, 2014 10:51 pm

yeah sometimes its hard for me to explain in english
hope this picture helps you

if not i will post a capx tomorrow
B
39
S
11
G
5
Posts: 485
Reputation: 5,365

### » Fri Aug 29, 2014 11:10 pm

Your English is great but I'm an artist so your picture is even better
Many thanks for taking the time to do this. I'll look at it over the weekend.
B
9
S
3
G
1
Posts: 23
Reputation: 828

### » Mon Sep 01, 2014 12:32 pm

I think I am missing something here.

When I use this the sprite 2 only moves to the Bullet sprites Y position if the Bullet sprite is moving downwards as well.

B
9
S
3
G
1
Posts: 23
Reputation: 828

### » Mon Sep 01, 2014 2:58 pm

It seems that AngleOfMotion only works between 180 degrees and -180 degrees.
and needs to be changed to a 360 range for the example to work.

So in the previous post:
ball.Bullet AngleOfMotion > 270
changes to
ball.Bullet(AngleOfMotion+360)%360 >270

Many thanks to R0J0hound in https://www.scirra.com/forum/viewtopic.php?f=147&t=104112&p=779640&hilit=negative+angle#p779640 for the info.

If anyone at all would care to explain how (ang + 360)%360 works I would appreciate it.
B
9
S
3
G
1
Posts: 23
Reputation: 828