Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: SOLO on August 28, 2008, 11:54:25 AM

Title: Actor turn relative to mouse pointer
Post by: SOLO on August 28, 2008, 11:54:25 AM
Hello,
I am thinking about using the software and was wondering for a 2D game (not 3D, not that advanced yet hahahaha) can it be scripted that the main actor turns or moves its head relative to the mouse pointer on the screen?

Example: Actor is in foreground, player moves pointer from directly ahead of actor to the right - Actor moves head to the right, player moves pointer up and actor turns UPRIGHT. Player moves pointer above actor, actor moves UP etc

Depending how far away the pointer is from the actor depends wether he turns or just moves his head.

And then if the main actor is in the distance and the player moves the pointer the actor would then animate slightly different.

Is this possible in 2D??

Thanx
Title: Re: Actor turn relative to mouse pointer
Post by: Spellbreaker on August 28, 2008, 07:41:58 PM
It is possible. You have to calculate where the "head is", and get a pixel as hotspot, and then calculate in a loop how far away in x and y the pointer is. Then start the movement you'd like. Don't know if this is a good idea at all, because if you have other animations you have to make sure that the "movement" does not happen while sitting down, or while walking.
Title: Re: Actor turn relative to mouse pointer
Post by: SOLO on August 29, 2008, 10:26:55 AM
Thanks for the pointers Spellbreaker, If the actor is doing other animations then I would make the mouse pointer inactive, so the check for the actor to follow the pointer would also check if the mouse pointer was active initially.

Has anyone on the forum done something like this? or got a basic test?

Thanx
Title: Re: Actor turn relative to mouse pointer
Post by: Mnemonic on August 29, 2008, 12:09:31 PM
It should be pretty simple, using a little math. You have the position of the actor (actor.X, actor.Y) and you have the mouse position within scene (Scene.MouseX, Scene.MouseY). And you can get the vector angle like this:

Code: WME Script
1. var AngleInRadians = Math.Atan2((y2 - y1), (x2 - x1));
2.

Most work would need to be done in art department, really.
Title: Re: Actor turn relative to mouse pointer
Post by: SOLO on August 29, 2008, 12:41:30 PM
Simple................easy for you to say  :D

So this variable is then called within a script.................how?....sorry but I am just getting into all this  :D

Art-wise is no issue, I will create the sprites for the different frames needed, I just need help with the scripting side.

Many thanx Mnemonic !