I am using my main camera as a LookAt point to direct my character’s movement, but when I bind a key to the forward motion if statement, the character accelerates momentarily, then stops.
(I am not, and do not wish to use Unity’s “Horizontal” and “Vertical” automatic Keybinds, they are rubbish for this sort of thing, as they are not dependent of the direction of the object being moved.)
This is the code I am using for the movement:
using UnityEngine;
using System.Collections;
public class Follow : MonoBehaviour
{
public float strength = 1.0f;
public Transform direction = null;
void Update ()
{
if (this.direction != null && Input.GetKeyDown (KeyCode.W))
{
rigidbody.AddForce(direction.forward * strength);
}
}
}
And this is the code I am using to handle the direction:
using UnityEngine;
using System.Collections;
public class CamOrbit : MonoBehaviour
{
public GameObject target = null;
void Start ()
{
}
void Update ()
{
if (target != null)
{
transform.LookAt(target.transform);
}
}
}
How do I make the player move constantly in the direction I am facing, instead of momentarily?
(At this point, to move forward any substantial distance, I must mash the key.)