I want to create an enemy that moves to the current location of the player. It locks that position and even the player starts moving, the beginning position of the player when the command start will be the target place. It’s like a Minotaur or boar enemies that lock-in to the current position of the player then charges through that location. Hope someone can help me thanks in advance!
give the npc a variable, call it state.
if state =1 (search)
move random/pattern/however you move the npc, when not charging the player.
(method the npc decides to charge) like
if distance to player is less then bla, or if is in collusion with view cone/is distance to raycast
change state to 2
if state=2 (lock on) trigger once.
when npc “locks” on player. store the players X and Y position in variables (LockX & LockY) and change state to 3
if state =3 (charge)
move the npc to the variables. and when reached that destination change state back to 1
I use your idea but I think I do something wrong.
In the first 2 states it’s fine. The boar moves to the location of the player but it wont stop if I use permanent force. and if use instant force, it moves on a short distance only. I guess there’s something to do with checking the position of the boar if it manages to go to the players lock-in position. Hope you help me again thanks in advance!
The problem is that the force won’t update the position in perfect increments, and unless the boar is exactly at Boar.Variable(X) and Boar.Variable(Y), and not a smidgen of a pixel off, the last event’s conditions will never be satisfied. You’d be better off determining the initial distance from boar to player, and keeping track on how far the boar has travelled, stopping once the travelled distance exceeds the initially calculated distance.
Or use path finding if there are obstacles to avoid. This will require a bit of setting up the environment and adding a few behaviours to a number of objects.
Or if it’s a straight line chase, you can always use a positional tween (they’re great - you kick it off and it runs by itself). This will guarantee it stops the boar at the player’s position. Tweens are a behaviour you need to add to the boar object. If you’re not sure about tweens, there’s a link to a good tutorial once you select the behaviour.