Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: Actor turn relative to mouse pointer  (Read 3677 times)

0 Members and 1 Guest are viewing this topic.

SOLO

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 23
    • View Profile
Actor turn relative to mouse pointer
« 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
Logged
Best Regards
SOLO

Spellbreaker

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Gender: Male
  • Posts: 376
    • View Profile
    • Apeiron Studios
Re: Actor turn relative to mouse pointer
« Reply #1 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.
Logged

SOLO

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 23
    • View Profile
Re: Actor turn relative to mouse pointer
« Reply #2 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
Logged
Best Regards
SOLO

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Actor turn relative to mouse pointer
« Reply #3 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.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

SOLO

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 23
    • View Profile
Re: Actor turn relative to mouse pointer
« Reply #4 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 !
Logged
Best Regards
SOLO
 

Page created in 0.023 seconds with 25 queries.