How do I set angle towards mouse position?

  • Hello, comunity :3

    I'm making a sort of an "Asteroids" game, but I'm trying to set the ship angle based on the mouse position, not by the arrow keys.

    I'm using this - Every Tick: Sprite > Set angle toward (Mouse.X, Mouse.Y)

    It's not working, since the nose of the ship does not follow the mouse, just the anchor point of the sprite, which makes it spin in the mouse direction, but not in the way that I want it to.

    Can anyone help me, pls? Thank You

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Try Set angle TO angle(sprite.x,sprite.y,mouse.x,mouse.y)

  • Try Set angle TO angle(sprite.x,sprite.y,mouse.x,mouse.y)

    Sorry, I didn't get it.

  • angle() is an expression that gives you the angle between two points, in this case from the sprite to your mouse.

    So every tick, set angle to angle(sprite.x,sprite.y,mouse.x,mouse.y)

  • angle() is an expression that gives you the angle between two points, in this case from the sprite to your mouse.

    So every tick, set angle to angle(sprite.x,sprite.y,mouse.x,mouse.y)

    Welp, it didn't worked at all. It worked, but had the same issue that I was facing using the other way: it's not facing the right direction, the mouse is always tangentially to the ship. I took a print to show where the mouse was.

  • In the sprite editor, the right side is 0 degrees, or "forward", not the top.

  • So, or rotate the sprite in the image editor 90 degrees clock wards. And account for that in your other events.

    Or, set its angle to angle(sprite.X,Sprite.Y,mouse.X,mouse.Y) + 90 ... (every tick)

  • It worked! Thanku, guys ^^

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