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

Just started using Construct 2? Post your questions here

Post » Tue Aug 19, 2014 7:55 pm

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.
B
3
Posts: 6
Reputation: 175

Post » Tue Aug 19, 2014 8:29 pm

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.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Tue Aug 19, 2014 10:48 pm

FragFather wrote: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?
B
3
Posts: 6
Reputation: 175

Post » Wed Aug 20, 2014 11:41 am

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?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Aug 20, 2014 11:45 am

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)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Aug 20, 2014 1:17 pm

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.
You do not have the required permissions to view the files attached to this post.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
296
S
119
G
96
Posts: 7,332
Reputation: 71,306

Post » Wed Aug 20, 2014 6:47 pm

LittleStain wrote: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!!! :D 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
B
3
Posts: 6
Reputation: 175

Post » Wed Aug 20, 2014 6:51 pm

Kyatric wrote: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! :D
B
3
Posts: 6
Reputation: 175

Post » Wed Aug 20, 2014 7:01 pm

Updated it a bit..
You do not have the required permissions to view the files attached to this post.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Aug 20, 2014 8:46 pm

LittleStain wrote:Updated it a bit..


Thank you for all the help LittleStain, the game is now just as i wanted to be ;)
B
3
Posts: 6
Reputation: 175


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests