Facing and moving towards a player at a certain distance
In one of my games I've been facing a problem to "detect" a player.
Scenario:
An enemy unit is patrolling an area, and if the player moves within ex. 100 pixels they will automatically be detected and the enemies will face and move towards them.
Any tips on how to get this working ?
Scenario:
An enemy unit is patrolling an area, and if the player moves within ex. 100 pixels they will automatically be detected and the enemies will face and move towards them.
Any tips on how to get this working ?
Comments
Its that?
@Lybotech
Hi, the following is untested but should work out (hopefully... ;-) ):
Make 4 real integers, PlayerX and PlayerY, Enemy1X and Enemy1Y
---in the Player Rules
Constrain Attribute self.Player.Position.X to PlayerX
Constrain Attribute self.Player.Position.Y to PlayerY
---in the Enemy Rules
Constrain Attribute self.Enemy1.Position.X to Enemy1X
Constrain Attribute self.Enemy1.Position.Y to Enemy1Y
Rule:When All
PlayerX > Enemy1X -101
PlayerX < Enemy1X +101
PlayerY > Enemy1Y -101
PlayerY < Enemy1Y +101
Change Attribute self.Rotation to vectorToAngle(scene.Background.Player.Position.X,scene.Background.Player.Position.Y)
---the following if wanted----
Otherwise
Change Attribute self.Rotation to 0
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Glad it helped. :-) I've just thought, I think if you make the rotation change attribute behaviour a constrain, it should adjust its angle when the player is moving within the area. Also, the x and y in the vectorToAngle expression ideally should be the constrained attributes. So that bit of the rule in the Enemy now is:
Constrain Attribute self.Rotation to vectorToAngle(PlayerX,PlayerY)
Fingers crossed that works OK.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps