*Solved* Noob Character Movement

So, I am returning to game maker after well-over 5 years away and I'm finding that picking up at my previous skill level is clearly not an option (I've forgotten everything it feels like).

Anyway. I was messing around with a super-simple character movement my mouse clicking

I did it two ways, and it seems that both ways make the main player sprite shake back and forth at high speeds whenever its not in motion. I did one way where just the mouse coordinates were used to move the player to the location. When I couldnt get rid of the shake no matter what I tried, I tried doing it another way, by a goto object that is deleted after collision, but the shake is still there.

What am I doing wrong? Maybe I did something wrong with the views or something?


I put the whole folder in 7zip
*Solved*
 
Last edited:

Adjud

Member
the only way I know how to simply do it is in step event for the object you want to move, under code
Code:
if mouse_check_button(mb_left) {
    point_direction(mouse_x,mouse_y,mouse_x,mouse_y)
    move_towards_point(mouse_x,mouse_y,2)
   }
else {
speed=0;
}
 
the only way I know how to simply do it is in step event for the object you want to move, under code
Code:
if mouse_check_button(mb_left) {
    point_direction(mouse_x,mouse_y,mouse_x,mouse_y)
    move_towards_point(mouse_x,mouse_y,2)
   }
else {
speed=0;
}
Ok. I'll check it out. I'll let you know :D
 

NightFrost

Member
You can post the relevant movement code here, too. At a guess, it sounds like your movement doesn't consider overshooting the target position. This makes it shake back and forth because each single step takes it too far, past the target. The typical cure for this is to check distance to target coords before moving. If distance is higher than speed, move normally. If distance is equal or lower than speed, set position to target and stop moving (switch state, set speed to zero, whatever way your movement stop works).
 
the only way I know how to simply do it is in step event for the object you want to move, under code
Code:
if mouse_check_button(mb_left) {
    point_direction(mouse_x,mouse_y,mouse_x,mouse_y)
    move_towards_point(mouse_x,mouse_y,2)
   }
else {
speed=0;
}
so this code did the same thing, but its a lot cleaner than the freakshow I had there before, so I'm gonna keep it and see if i cant work out a distance check as well like @NightFrost said
 
Thanks guys! Finally figured it out :D

if mouse_check_button(mb_left)
{
if distance_to_point(mouse_x,mouse_y) > 0.1
{
point_direction(mouse_x,mouse_y,mouse_x,mouse_y)
move_towards_point(mouse_x,mouse_y,2)
}
else {
speed=0;
}
}
else {
speed=0;
}
 

NightFrost

Member
A few improvements can be done. There's still a chance the character will shake around a little until it manages to find a position that is at 0.1 or closer to target, so we'll fix it by setting position to mouse position whenever distance is less than speed. The point_direction is currenty doing nothing so it can be removed (and will always return zero as it is set to calculate from current mouse position to current mouse position). Character movement speed should be defined in a variable; if you need to call it multiple times and have to change the value, you won't have to hunt around the code and hope you managed to change it in all the places it was used.
Code:
// Add to CREATE event:
Walk_Speed = 2;

// Alter STEP event:
if mouse_check_button(mb_left){
   if distance_to_point(mouse_x,mouse_y) > Walk_Speed { // <-- using speed variable in comparison
      move_towards_point(mouse_x,mouse_y, Walk_Speed); // <-- using speed variable
   } else {
      x = mouse_x; // <-- set to mouse position
      y = mouse_y; // <-- set to mouse position
      speed=0;
   }
} else {
   speed=0;
}
 
Top