Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Amir on Mon 02/08/2021 17:59:38

Title: Pupils follow mouse cursor/character (solved)
Post by: Amir on Mon 02/08/2021 17:59:38
Hi,

As you can see in some games, most of the time at the menu on the background image. The pupils follow the mouse cursor.
I made a walkable area in the eyes 2 circles then made something little transparent and pupils as characters. I tried to do something like this:

In the room c.Fakemouse.Transparency = 100;

and

Code (ags) Select

function repeatedly_execute()
{
cEyes.FollowCharacter(cFakemouse, 1, 1);
cFakemouse.x = mouse.x;
cFakemouse.y= mouse.y;
}


It's not so bad but the problem is that the pupils move sometimes constantly because they want to follow the mouse cursor and cannot leave the walkable area. for example, when the cursor is in the lower center, the pupils go down but move right and left all the time, as I said because they want to get out. I don't really like it that much.

Another thought: views of animating pupils and depending on the position of the mouse cursor x and y. But the movement of the pupils will look terrible.
Does anyone have a smarter idea?

I would like to do the same thing too, so that character's eyes follow the main character when he walks past. I think that would be the same technique. But pupils follow the mouse cursor is more important to me.
Title: Re: Pupils follow mouse cursor/character
Post by: Cassiebsg on Tue 03/08/2021 16:50:28
FollowCharacter will always make it "fudgy".

Just get the mouse the mouse coordinates, and then update the pupil by moving them instead.
Title: Re: Pupils follow mouse cursor/character
Post by: Cassiebsg on Tue 03/08/2021 16:52:52
FollowCharacter will always make it "fudgy".

Just get the mouse coordinates, and then update the pupil by moving (or just update the x,y) instead.
Title: Re: Pupils follow mouse cursor/character
Post by: Amir on Tue 03/08/2021 17:13:24
Quote from: Cassiebsg on Tue 03/08/2021 16:52:52
FollowCharacter will always make it "fudgy".

Just get the mouse coordinates, and then update the pupil by moving (or just update the x,y) instead.

But the pupils would go out and not stay in the eyes, that's why I had to use FollowCharacter and walkable area in the eyes.
Title: Re: Pupils follow mouse cursor/character
Post by: Cassiebsg on Tue 03/08/2021 17:55:08
Just don't provide x,y that is inside the the eyes/walkable area. Or use walk, results in the same anyway just make sure it's not set to anywhere.  ;)
Title: Re: Pupils follow mouse cursor/character
Post by: Amir on Tue 03/08/2021 19:14:17
If I use walk you will have to click first to make the pupils move and I don't want it like that.

QuoteJust don't provide x,y that is inside the the eyes/walkable area.

Hmmmm ok I will try.


Title: Re: Pupils follow mouse cursor/character
Post by: Cassiebsg on Tue 03/08/2021 19:46:07
Correction: Just don't provide x,y that is inOUTside the eyes/walkable area.  (roll)
This is what happens when I change a sentence in my mind halfway of writing it.  (laugh)

Also, you don't need to click anywhere, the pupils will only move when the mouse moves, and if they're already where they're suppose to be looking, then they'll just stay there. You aren't processing the clicks, you are moving the character your self to the designated x,y, and the character will try to move there, if it can (but since you've limited it to a walking area, it's trapped as long as you don't use eAnywhere).
The only difference between using walk and move, is that walk will play the walk animation (if there's more that 2 frames) and move won't.
Title: Re: Pupils follow mouse cursor/character
Post by: Khris on Tue 03/08/2021 20:15:12
Use math to move the eyes instead.

Code (ags) Select
  cEyes.x = eyes_center_x + (mouse.x - eyes_center_x) / 100;
  cEyes.y = eyes_center_y + (mouse.y - eyes_center_y) / 100;


https://de.wikipedia.org/wiki/Strahlensatz ;)
Title: Re: Pupils follow mouse cursor/character
Post by: Amir on Tue 03/08/2021 21:32:46
@Khris - I would love to give you a Nobel Prize for this idea. It works like a charm, thank u. I just had to change /100 to /40 for x and /20 for y to give the pupils a little more space.

@Cassiebsg - Thank u too for ur suggestions and help. I will try it anyway, even though I will leave the math solution in my script.