targeting Sprite

0 favourites
  • 6 posts
From the Asset Store
Pixel Sprites ala ReactorCore - Builder Hardware - Large pack of sprites!
  • Hello All!

    I have a little top down tank with a rotating turret who's angle slowly follows the mouse. Works great! Now I want to implement a target icon that stays directly in front of the turret, but the y axis moves to the mouse position. I want to know when the turret is lined up with the mouse using this sprite.

    I have tried a few things, but it doesn't quite work.

    I tried:

    Every Tick> Sprite Set position Turret ImagepointY(0), Mouse.x

    and variants of this. I think I am way off base.

    I (think) I need the event to do something like:

    Set position of Sprite along Turret Angle at distance(Turret.x, Turret.y, mouse.x, mouse.y

    My head hurts...   HELP!

  • Ahh, trig time!

    Darn it... 6am... Don't feel like trig!

    Here's a simple solution.

    Every tick:

    Target: set position to turret.x,turret.y

    Target: move at angle angle(turret.x,turret.y,mouse.x,mouse.y), distance distance(turret.x,turret.y,mouse.x,mouse.y).

    This should do what you want.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sprite: set X to turret.X+cos(turret.angle)*distance(turret.x,turret.y,mouse.x,mouse.y)
    Sprite: set Y to turret.Y+sin(turret.angle)*distance(turret.x,turret.y,mouse.x,mouse.y)
  • Thanks Both of you! I took only 1 semester of Trig... Now I wished I had finished!!!!!!

  • Well... I took none.

  • I dont need to go back to school. Yann is schooling me just fine!   <img src="smileys/smiley42.gif" border="0" align="middle" />

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