# Help with some simple-ish math. =)

Get help using Construct 2

### » Sat May 04, 2013 5:26 am

So my game has heavily gravity effected bullets, and what I do for the enemies to make them compensate for their aim is place a position between the player and them, and then put it into the air by some amount of their total distance, so if all the gravities and whatnot are balanced, the bullets should arc towards the player no matter what the distance.

BUT I don't fully understand the math I am doing and I have run into a bug that only happens when the player goes on the right side of the enemies.

Desired effect on the left (somewhat)

and here is my math:

I have basically no idea what I am doing on the second line but it almost works...
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

### » Sat May 04, 2013 5:40 am

@Sushin
If I really understand what you do, I guess Y expression should be using these:

Distance Player/FootSoldier : abs(Player.X - FootSoldier.X)
Y origin: FootSoldier.Y
Ratioxy: a constant which you can use to adjust the height (4 maybe)
so, I guess you can try:

-abs(Player.X - FootSoldier.X)/Ratioxy + FootSoldier.Y

Not sure It will work though

EDIT: If FootSoldier and the player aren't at the same Y, the formula should not work really greatAphrodite2013-05-04 05:51:45
https://www.scirra.com/forum/viewtopic.php?t=152506

And that is why you shall respect the bug reports guidelines, not only giving a capx is making the bug reproductible in one click in a situation they can work with (less time wasted trying to reproduce vague instructions) but also it helps filtering false positives.

Game design is all about decomposing the core of your game so it becomes simple instructions.
B
41
S
16
G
15
Posts: 2,050
Reputation: 14,697

### » Sat May 04, 2013 5:55 am

Thanks. I took out the "- FootSoldier.Y" part and it works well, although the problem now is that when the player is next to the foot soldier, the crosshair is as high as it can get, but what it really should be doing is getting lower when the player gets closer.
So it works but I need the effect to be reversed...
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

### » Sat May 04, 2013 6:24 am

@Sushin

Right after I realized my mistake, in C2, the Y axis is reversed compared to the One I am using in mathematics ^^"':

-abs(Player.X - FootSoldier.X)/Ratioxy + FootSoldier.Y

this should work better
https://www.scirra.com/forum/viewtopic.php?t=152506

And that is why you shall respect the bug reports guidelines, not only giving a capx is making the bug reproductible in one click in a situation they can work with (less time wasted trying to reproduce vague instructions) but also it helps filtering false positives.

Game design is all about decomposing the core of your game so it becomes simple instructions.
B
41
S
16
G
15
Posts: 2,050
Reputation: 14,697

### » Sat May 04, 2013 6:38 am

Ah. Thank you. That's exactly what I wanted. =)
B
10
S
3
G
3
Posts: 234
Reputation: 3,467