Need help with math

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hi everyone,

    please bear with me

    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:

    <img src="" border="0" />

    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:

    <img src="" border="0" />

    is there some way I can retrieve this position using equation?

    or can this be achieved in some other way instead?

  • Supposing your image point is index 1, just set the angle of the gun to :

    angle(Gun.ImagePointX(1), Gun.ImagePointY(1), Mouse.x, Mouse.y)
  • 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..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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?


    nevermind, I found the solution

    by putting another image point in the back of the gun

    thanks for all the help! :)

  • 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 ! <img src="smileys/smiley36.gif" border="0" align="middle" />

    Good thing you found a way around that issue though, because I don't know why it does that ! <img src="smileys/smiley5.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)