Stop physics object moving after reaching certain point

J

jaakko meyn

Guest
I have an enemy that Is moving towards a randomly generated point above the player, but I cant seem to get it to stop when reaching the destination point (the object does stop, but it still tries to move causing the sprite to twitch, which is the actual problem here)
here is the movement code
Code:
dir = point_direction(phy_position_x,phy_position_y,obj_player.phy_position_x - random_x,obj_player.phy_position_y - random_y)


phy_position_x = phy_position_x + lengthdir_x(randomspeed,dir)
phy_position_y = phy_position_y + lengthdir_y(randomspeed, dir)
my aim is to make it stop when reaching the player position + random_x/y, but nothing ive tried works

Im still quite new to Gamemaker and ive heard that I shouldnt move physics objects with the phy_position variable nut instead use impulses, so getting some advice for that would be helpful too :)
 

samspade

Member
I have an enemy that Is moving towards a randomly generated point above the player, but I cant seem to get it to stop when reaching the destination point (the object does stop, but it still tries to move causing the sprite to twitch, which is the actual problem here)
here is the movement code
Code:
dir = point_direction(phy_position_x,phy_position_y,obj_player.phy_position_x - random_x,obj_player.phy_position_y - random_y)


phy_position_x = phy_position_x + lengthdir_x(randomspeed,dir)
phy_position_y = phy_position_y + lengthdir_y(randomspeed, dir)
my aim is to make it stop when reaching the player position + random_x/y, but nothing ive tried works

Im still quite new to Gamemaker and ive heard that I shouldnt move physics objects with the phy_position variable nut instead use impulses, so getting some advice for that would be helpful too :)
In general, I agree with FrostyCat. Unless you really need it, don't use the physics engine. Also, to use it well, you will probably need to learn the basics of how physics work. While the physics engine will do many of the calculations for you, you still have to understand what to ask it for, etc. Additionally, a lot of things are easier to 'fake' than accomplish through physics. For example, it's a lot easier to say vsp += grav; y += vsp than mess around with the physics engine.
 
Top