3 hours ago, Timothy Sharp said:
I added my gameObject and a capsule collider to the follow model, but whenever it follows me, it hovers in the air and tries to push me off the plane
That is indeed what your script is telling it to do.
You will want a rigid body attached to the capsule to get it down to the ground.
For following use vector math instead of moving in the direction:
public Transform Target; //This will be the player that you feed to the script
public float Lag = 50f; //How much the object lags behind before catching up
Vector3 offset;
Rigidbody FollowerRigidbody; //Physics object needs to be moved by there physics body
// Use this for initialization
void Start () {
offset = this.transform.position - Target.position;
//Tis means how far between the two for example if x = 5 for player
//and x = 12 for follow object then 12 - 5 =7
//This means there is 7 spaces between Player and Follower
FollowerRigidbody = this.GetComponent<Rigidbody> (); // so we can call the physics object when needed//
}
void FixedUpdate(){
Vector3 TargetPosition = Target.position + offset; // So now if player moves we just get the player position and + our 7 to it
// this gives us the new destenation for the follower
FollowerRigidbody.MovePosition (Vector3.Lerp(this.transform.position,TargetPosition, Lag* Time.deltaTime));
//This is how we move. The lerp takes the old position and the new destenation and moves to it smoothly based on a lag factor.
//If it isn't a physics object we use:
//Lerp is a slider so if our first value is 0 and the second 10; then lerp(0,10, 0.5f) = 5
}
This can be used for camera also:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public Transform Target;
public float Lag = 50f;
Vector3 offset;
// Use this for initialization
void Start () {
offset = this.transform.position - Target.position;
}
void FixedUpdate(){
Vector3 TargetPosition = Target.position + offset; //Finds the relative target point
this.transform.position = Vector3.Lerp(this.transform.position,TargetPosition, Lag* Time.deltaTime);
}
// Update is called once per frame
void Update () {
}
}
If this is your first game this tutorial series will be great for you: https://unity3d.com/learn/tutorials/s/survival-shooter-tutorial
What I explained was this part: https://unity3d.com/learn/tutorials/projects/survival-shooter/camera-setup?playlist=17144 and they take there time to explain in detail.