How do I "set angle AWAY from position"

Get help using Construct 2

Post » Tue Aug 12, 2014 7:09 am

I am trying to have a bullet that is moving toward an object, change direction and move away from the object while pressing a key down.

Is there a way to do the opposite of "set angle toward position" and move something away from a specific object?
B
4
S
1
Posts: 5
Reputation: 354

Post » Tue Aug 12, 2014 7:17 am

subtract 180 from the angle?
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Aug 12, 2014 7:20 am

would this work?

set angle to: angle(bullet.x,bullet.y,object.x,object.y)+180
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

Post » Tue Aug 12, 2014 7:39 am

LittleStain wrote:would this work?

set angle to: angle(bullet.x,bullet.y,object.x,object.y)+180



Wow, that worked perfectly. Thank you so much! Can you explain what is happening there?
B
4
S
1
Posts: 5
Reputation: 354

Post » Tue Aug 12, 2014 7:59 am

In C2 angles are in degrees, basically,an angle + or - 180° is the opposite angle due to the cyclic nature of angles(adding 360°, aka a full rotation, is the same as adding 0, (360+0)/2=180 so you have half a complete turn, thus the opposite direction)

And angle(x1, y1, x2, y2) return the angle between the two points
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Tue Aug 12, 2014 8:19 am

So simply put C2 calculates the angle between the bullet position and the object position and you add 180 (degrees) to get the opposite angle..
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

Post » Tue Aug 12, 2014 5:17 pm

I understand the flipping the angle by adding 180 degrees. I was unaware of the ability to get the angle between two points with "angle(x1, y1, x2, y2)." That is great. Thank you very much!
B
4
S
1
Posts: 5
Reputation: 354

Post » Tue Aug 12, 2014 9:34 pm

this page of the manual, in the Math paragraph, is quite useful in some cases (since it shows the predefined math functions you can use in C2 directly): https://www.scirra.com/manual/126/system-expressions
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Tue Aug 12, 2014 10:11 pm

Aphrodite wrote:this page of the manual, in the Math paragraph, is quite useful in some cases (since it shows the predefined math functions you can use in C2 directly): https://www.scirra.com/manual/126/system-expressions


That's a fantastic reference, thanks!
B
4
S
1
Posts: 5
Reputation: 354


Return to How do I....?

Who is online

Users browsing this forum: plinkie, Yahoo [Bot] and 20 guests