How do I set a pivot on a sprite to follow the mouse?

0 favourites
  • 10 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hello, im new in Construct 2 and my problem is that i have a sprite ( an aeroplane ) that is set the position to Mouse.X and Mouse.Y when Touch is in Touch, to follow the mouse movement when i make click. But i dont know how to make the plane rotate as i move the mouse, hope i can make me understand my english is not very good.

  • There is an action called "Set Angle Toward Position." It takes an X and Y coordinate and rotates your sprite so the right side of the sprite is facing it. Remember, the right side of your sprite is considered the front or angle 0. So, to get your sprite to face where you touch, you pass in the Touch.X and Touch.Y.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There is an action called "Set Angle Toward Position." It takes an X and Y coordinate and rotates your sprite so the right side of the sprite is facing it. Remember, the right side of your sprite is considered the front or angle 0. So, to get your sprite to face where you touch, you pass in the Touch.X and Touch.Y.

    Thank you, but "Set Angle Toward Position." only works when i disable "Set position to (Touch.X , Touch.Y)" and the sprite doesnt move only rotates. Is something else i can do?

  • Could you explain?

    Why wouldn't set angle towards position work?

    Maybe you haven't explained what you are trying to achieve clearly..

    Could you make a screenshot of your events and/or upload a capx to show your issue?

  • Ah..

    I guess you want to move the sprite by setting it's position to touch.x,touch.y and while moving have it face in the direction you are moving..

    To do that you could give the sprite two instance variables oldX an OldY

    is in touch-

    sprite set value OldX : sprite.x

    sprite set value OldY : sprite.y

    sprite set position to : touch.x,touch.y

    sprite set angle : angle(sprite.oldX,sprite.OldY,touch.x,touch.y)

  • From your first post it also sounds like you are using both the Touch and Mouse plugin.

    It is not necessary. Just having the Touch plugin is enough as it emulates the mouse cursor on desktop, so you can program everything relying only on the Touch actions/expressions.

    As for the rest, post/attach your capx to a message, it will make it far easier for us to be able to help your according to the current state of your project.

    See the attached file to my post for an example that might work according to what you've described nonetheless.

  • Ah..

    I guess you want to move the sprite by setting it's position to touch.x,touch.y and while moving have it face in the direction you are moving..

    To do that you could give the sprite two instance variables oldX an OldY

    is in touch-

    sprite set value OldX : sprite.x

    sprite set value OldY : sprite.y

    sprite set position to : touch.x,touch.y

    sprite set angle : angle(sprite.oldX,sprite.OldY,touch.x,touch.y)

    Thank you so much it worked very well!!! <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy"> now i have to see a way that the plane keeps the rotated position instead going back to the default position. i have uploaded the file to dropbox

    https://www.dropbox.com/s/hyof8the1zzvdfs/Planes.capx

  • From your first post it also sounds like you are using both the Touch and Mouse plugin.

    It is not necessary. Just having the Touch plugin is enough as it emulates the mouse cursor on desktop, so you can program everything relying only on the Touch actions/expressions.

    As for the rest, post/attach your capx to a message, it will make it far easier for us to be able to help your according to the current state of your project.

    See the attached file to my post for an example that might work according to what you've described nonetheless.

    Thank you Kyatric its more or less what i want to do but the ship moves little bit slow and for the kind of game im doing its not efective and i dont know how to change the velocity of the ship je i think its very advanced yet to me that way!

  • Updated it a bit..

  • Updated it a bit..

    Thank you for all the help LittleStain, the game is now just as i wanted to be

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