Jump to content


Photo

Monster movement/sprites


  • Please log in to reply
3 replies to this topic

#1 _252547

_252547

    GMC Member

  • GMC Member
  • 23 posts

Posted 03 August 2012 - 10:32 PM

I'm making a maze RPG but I'm struggling with the movement of my monsters. I had a different object for each direction but when it comes to collisions it would be hard. I want the monster to move randomly up,down,left and right. I also have a different sprite strip for each direction. If anyone has any ways to help me solve my problem that would be very helpful. Thank you.
  • 0

#2 TerraFriedSheep

TerraFriedSheep

    GMC Member

  • GMC Member
  • 2846 posts
  • Version:GM:Studio

Posted 03 August 2012 - 11:13 PM

I'm making a maze RPG but I'm struggling with the movement of my monsters. I had a different object for each direction but when it comes to collisions it would be hard. I want the monster to move randomly up,down,left and right. I also have a different sprite strip for each direction. If anyone has any ways to help me solve my problem that would be very helpful. Thank you.


Rather than have 1 object for each monster direction, try creating just one object for the monster and adjust it's sprite index accordingly (to the direction it is moving).

The random movement could be accomplished like this:

//Monster create event
direction=choose(0,90,180,270);
speed=4;//Make the monster move in a random direction at a speed of 4

//Monster collision with a wall
//Assuming the wall is solid, the monster will move back to it's previous position before the wall.
move_contact_solid(direction,speed);//Move the monster to be aside the wall.
direction=choose(0,90,180,270);//Make the monster move in a new random direction.

switch direction
{
case 0:
sprite_index=spr_monster_right;
break;
case 90:
sprite_index=spr_monster_up;
break;
case 180:
sprite_index=spr_monster_left;
break;
case 270:
sprite_index=spr_monster_down;
break;
}

It's as simple as that. The switch statement will check which way the monster is moving, and set the sprite to the relevant direction.

Edit: Spelling.

Edited by TerraFriedSheep, 03 August 2012 - 11:13 PM.

  • 0

#3 _252547

_252547

    GMC Member

  • GMC Member
  • 23 posts

Posted 04 August 2012 - 04:46 AM


I'm making a maze RPG but I'm struggling with the movement of my monsters. I had a different object for each direction but when it comes to collisions it would be hard. I want the monster to move randomly up,down,left and right. I also have a different sprite strip for each direction. If anyone has any ways to help me solve my problem that would be very helpful. Thank you.


Rather than have 1 object for each monster direction, try creating just one object for the monster and adjust it's sprite index accordingly (to the direction it is moving).

The random movement could be accomplished like this:

//Monster create event
direction=choose(0,90,180,270);
speed=4;//Make the monster move in a random direction at a speed of 4

//Monster collision with a wall
//Assuming the wall is solid, the monster will move back to it's previous position before the wall.
move_contact_solid(direction,speed);//Move the monster to be aside the wall.
direction=choose(0,90,180,270);//Make the monster move in a new random direction.

switch direction
{
case 0:
sprite_index=spr_monster_right;
break;
case 90:
sprite_index=spr_monster_up;
break;
case 180:
sprite_index=spr_monster_left;
break;
case 270:
sprite_index=spr_monster_down;
break;
}

It's as simple as that. The switch statement will check which way the monster is moving, and set the sprite to the relevant direction.

Edit: Spelling.


Thank you so much but i'm unfimiliar with gml and with the execute script function it didnt work im not sure how to make it work.
  • 0

#4 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 5234 posts
  • Version:GM8

Posted 04 August 2012 - 12:58 PM

You'd use Execute Code, not Execute Script.

In the monster Create Event, you'd put the first, small block of code he posted inside an Execute Code function.

In the monster Collision With Wall Event, you'd put that bigger code he posted inside an Execute Code function.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users