Getting a game object to move towards FPS

Hi guys. I am trying to let a game object to move towards the FPS.

I managed to get the object to turn towards the direction of the FPS and i need it to move to the front of the FPS.

For some reasons i am playing with the gameobject’s position and it did moved to the FPS but it is not in front of him. so what should i do.

Thanks.

FPS in this case means???

Whatever “FPS” means you clearly have a starting position and an intended ending position, just write a simple function that uses WaitForSeconds/yield to animate there in steps stopping when it reaches its target. Let us know if you’re not familiar with the use of WaitForSeconds/yield and we can cover those, but look in the docs to begin with and we’ll go from there as needed!

or …

transform.Translate(Vector3Direction(transform.position, Player.transform.position) * Time.deltaTime * speed, Space.World);

This will make the object “follow” a player. As far as being “in front” of the player, that’s a different problem.

Hi guys thanks for the reply. Maybe i did not explain that well.

Lets put it this way.

I have a gameobject at point A and it will detect the FPS capsule (Player) when it is within its range, say a radius of 5cm.

Once detected, I need it to turn towards the FPS capsule (Player) and move towards it and stop right in front of the FPS capsule (Player).

For now i am able to get the object to turn towards the direction of the player. But the issue is due to the object moving towards the FPS Capsule (Player). Due to the player’s rotation the object does not always move to the front of the Player.

Hope I explained more clearly.

There are two issues here:

  1. If the player is rotating/moving while you’re animating the object then you simply need to be sure and update the destination position each frame. This is a “move towards a moving target” type approach.

  2. If the player is rotating/moving then you need to think about what happens when this object gets in front of the player, what happens if the player then moves again? Either (a) the object stays locked in front of them, or (b) the object stays put and the player walks away. If you go with option (a) then simply child the object to the player once they reach the destination position (or get “close enough”). If you go with option (b) then animate to (or close enough to) the destination position then simply stop animating as you’ve reached your goal.

Let me know if those make sense, and if so whether you have an idea as to how to go about them. I sense that you might but am not sure, so let us know!

You want a person to move in front of the player. Likewise it wants to talk to you.

Well it’s easy to move something to a certain position. But not easy to figure out the view field.

Maybe this works:
Attach an object to the player in front of him where you want to move. Make it invisible. Make it the target of the person you want to get in the players view.

You should let it wait in beetween. Or it would move endlessly as the Player is looking around.