Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: johanvepa on Sat 02/01/2016 10:23:24

Title: [SOLVED] Making a character follow the mouse
Post by: johanvepa on Sat 02/01/2016 10:23:24
I'm trying to make a function that enables me to make a character follow the mouse cursor around. I also need to turn that function off and on in the game.

This works fine with a bool and a small funtion. In global script:
Code (ags) Select

bool shovelfollowingcursor;

function repeatedly_execute()
{
  if (shovelfollowingcursor == true)
  {
    cShovel.x = mouse.x;
    cShovel.y = mouse.y;
  }
}

function cShovel_PickUp()
{
  shovelfollowingcursor = true;
}


Now I want to extend this to more characters to pick up and follow the cursor around. I figured something like an integer that keeps track of which character is the one I want to do this and then a function to make character[integer] follow the cursor, but I get the message that I cant convert character* to integer.

How do I make a function recognize a character by way of a global integer value?



Title: Re: Making a character follow the mouse
Post by: Khris on Sat 02/01/2016 18:37:30
If you want to store a character in the integer variable, you use followingCursor = cShovel.ID;

Or you use a character pointer:
Character *followingCursor;

  followingCursor = cShovel;

  if (followingCursor != null) {
    followingCursor.x = mouse.x;
    followingCursor.y = mouse.y;
  }
Title: Re: Making a character follow the mouse
Post by: johanvepa on Sat 02/01/2016 19:13:46
That was just the word I was looking for. Thank you Khris ;)