Jump to content


Photo

Moving with mouse click, do loop error


  • Please log in to reply
1 reply to this topic

#1 Jadestar

Jadestar

    GMC Member

  • New Member
  • 5 posts
  • Version:Unknown

Posted 08 May 2012 - 08:13 PM

So i have created an invisible object and placed it in the room. The idea is that I can click somewhere in the room and the player object will move towards it and then stop. Here is my code.

globalvar tempX;
globalvar tempY;

tempX=mouse_x div 32
tempY=mouse_y div 16

playerX=obj_player.x
playerY=obj_player.y

moddedX = tempX mod 3
moddedY = tempY mod 3

if (moddedX == 1) {
tempX = tempX-1
}
if (moddedX == 2) {
tempX = tempX+1
}
if (moddedY == 1) {
tempY = tempY+1
}
if (moddedY == 2) {
tempY = tempY-1
}

tempX=tempX*32
tempY=tempY*16

do {
mp_potential_step(tempX,tempY,7,true)
} until (playerX == tempX & playerY == tempY);

I know the math is solid, if i use a move towards then it works but of course it keeps going and doesnt stop so i thought about a mp_potential_step which from my understanding should loop itself until it reaches the destination.

Please help

Thanks.
  • 0

#2 Jadestar

Jadestar

    GMC Member

  • New Member
  • 5 posts
  • Version:Unknown

Posted 08 May 2012 - 08:31 PM

i added another code block to execute after this one. I removed the do loop with the mp step and was trying this instead

move_towards_point(tempX,tempY,7)
if (obj_player.x = tempX & obj_player.y = tempY)
{
obj_player.speed=0;
}

The player definately moves towards the point but it doesnt stop.

Another issue I think is that the snap to grid doesnt work. This is for an isometric map which is made up of squares of 3x3 and we want the player to always be in the middle square, hence some of the code math above. When I click on any position in the map, it should be a multiple of 32x16 which is what the snap settings are but it does not work, i can easily click on values outside that range which I believe is the reason why my player.x and tempX never equal.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users