# Need help with math

Get help using Construct 2

### » Tue May 14, 2013 3:24 pm

Hi everyone,

I'm not a programmer, and my math is pretty much zero at best

I'm creating this mech shooter platformer,
and I encountered some trouble with the gun aiming in my game
it's not really a big problem really, but the curiosity is eating me

so I created a gun, where the origin of the sprite is at the bottom,
and an image point for spawning the bullet.
I have created an action to set the angle to point to mouse position,
so it looks like this:

now, it is working as it should,
but there's a bit problem with the accuracy this way, the gun won't shoot exactly where the pointer at.

So what I need is for the sprite to point from the image point, but still rotate on its origin
so I figured i would need to point the angles toward this position instead:

is there some way I can retrieve this position using equation?
or can this be achieved in some other way instead?
B
8
S
2
Posts: 48
Reputation: 1,098

### » Tue May 14, 2013 3:55 pm

Supposing your image point is index 1, just set the angle of the gun to : [code]angle(Gun.ImagePointX(1), Gun.ImagePointY(1), Mouse.x, Mouse.y)[/code]Magistross2013-05-14 15:55:26
B
45
S
16
G
14
Posts: 826
Reputation: 11,630

### » Tue May 14, 2013 4:01 pm

If your pivot is the origin point, get the angle of the origin point, otherwise, it will give you the angle of the hypotenuse of the triangle between the origin, the image point and the mouse..
B
92
S
18
G
12
Posts: 1,166
Reputation: 18,090

### » Tue May 14, 2013 4:31 pm

Hi @Magistross thanks!
It works!
I wasn't aware of that expression,

but when the mouse get to close to the image point,
the gun starts shaking violently,
any idea what might caused this? or how to prevent this?

*edit:
nevermind, I found the solution
by putting another image point in the back of the gun
thanks for all the help! :)mochakingup2013-05-14 16:50:16
B
8
S
2
Posts: 48
Reputation: 1,098

### » Tue May 14, 2013 5:23 pm

Lolz ! I was wondering what you meant by "shaking violently" so I tried it. I laughed so hard when my "gun" started behaving like a fan !

Good thing you found a way around that issue though, because I don't know why it does that !
B
45
S
16
G
14
Posts: 826
Reputation: 11,630