Rotate sprite to direction?

For questions about using Classic.

Post » Sat Nov 15, 2008 2:57 pm

Ok In a top down style I have a sprite, that uses the "Mouse" behavior, and in groups, attribute is set to "Center view on me", and mouse is set invisible.
So basically Ive made a sprite into a cursor, so how to make the sprite rotate facing the direction its going?
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sat Nov 15, 2008 3:07 pm

In the 'Angle' category of the Sprite's actions, there's a few actions like 'Set angle towards position' and 'Rotate towards position'. For example, Set angle towards MouseX, MouseY will make the object look at the mouse.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Sat Nov 15, 2008 3:12 pm

I tried that, and either the sprite wont change directions, or it just works one time.
I think the problem is that the sprite, basically is the cursor, so it cant look to it.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sat Nov 15, 2008 7:05 pm

Here's a link to the cap:[url:1vnvzu9x]http://www.badongo.com/file/12108816[/url:1vnvzu9x]
Ive tried just about all I can think of.
Thanks
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sat Nov 15, 2008 7:14 pm

[quote="Ashley":19h3iw34]In the 'Angle' category of the Sprite's actions, there's a few actions like 'Set angle towards position' and 'Rotate towards position'. For example, Set angle towards MouseX, MouseY will make the object look at the mouse.[/quote:19h3iw34]

Ash, if he's got the Mouse behavior on the object, then it can't point towards MouseX, MouseY ;)

What you could try is this:

Make two variables for your object called "lastX" and "lastY."

[code:19h3iw34]
+Always
-Sprite: Set angle to (angle(lastX, lastY, MouseX, MouseY)
-Sprite: Set sprite.value('lastX') to MouseX
-Sprite: Set sprite.value('lastY') to MouseY
[/code:19h3iw34]

I think that should work.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Nov 15, 2008 8:16 pm

No idea.
It wont let me use lastX, as a value. I tried making it a private variable, and a global.
So either Im doing it wrong, or Im an idiot... same thing.
Wah, eeh Ill go make the honey pot.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sat Nov 15, 2008 8:27 pm

I think he was typing pseudo-code. It should work if you use Sprite('lastX') instead of just lastX on its own.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Sat Nov 15, 2008 10:30 pm

Yes, that's what I meant. Sorry, I'm used to people understanding the whole pseudocode thing.

The proper way to type it out in the editor would be:

[code:xtw1yy8h]
(angle(Sprite.Value('lastX'), Sprite.Value('lastY'), MouseX, MouseY)
[/code:xtw1yy8h]

But that's a lot to type, so I used pseudocode :P
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sun Nov 16, 2008 4:41 am

Thats a bit better, still a little bit off.
Thanks guys.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests