Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Make object follow player?

Discussion in 'Scripting' started by Treasureman, Dec 8, 2014.

  1. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    Hi
    I have a game object, and I want to make it follow the player (FPSController) without rotating.
    I've tried giving the object a mouse orbit script and paring it with the player, but it didn't work. The character ended up rotating with the player. How would I do this?

    Thanks!!!
     
  2. HellSinker

    HellSinker

    Joined:
    Apr 18, 2013
    Posts:
    65
    A clumsy answer for a piece of unseen code is just to add a zeroing rotation at the end of the mouse orbit script...

    something like

    Code (csharp):
    1.  
    2. GameObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
    3.  
    you would have to change "GameObject" to the appropriate object though...

    hope that works - get back to me if it doesn't...

    really though - if you want the object to ""follow"" there are a lot of better solutions...

    I am curious - if you want the object always behind, or just draging like a corpse, or perhaps something more elaborate like orbiting and moving closer as such, but generally always behind....

    There is some abiguity to the question

    One thing I might suggest is to make the object move around a little - like with a range of -1.0 to 1.0 or something a little larger depending on your scale - you can then add a negative forward vector to the player - and move the object to that position...

    This will ensure the object is always behind the player - but not directly behind at all times...
     
    Last edited: Dec 8, 2014
  3. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    It didn't work, it said that "the file didn't exist".

    As for my desired effect. I want the camera to rotate around the offset character (done) and to move in the direction the camera's looking (done), but I haven't gotten the character model to move with my invisible FPSController. It looks something like this Untitled.png
    Here's a snapshot of my game. Screenshot (57).png Screenshot (58).png
    By the way, thanks for not being a huge jerk about this. people on the forums can be so mean.
     

    Attached Files: