The following is code for standard FPS style movement. I got this code from my text book, except I added: speed = 0.1f;
The script is a component of Main Camera which also has a ‘Rigidbody’ and ‘Capsule Collider’.
Unfortunetly there is some buggy sliding around the ground (like slipping on ice). I consulted the text book, and read that in the Inspector, Rigidbody’s variable “Drag” needs to be set to 1.
I did this, and it helped a little, but I’m still seeing the bug. Is there a reason it’s doing this in the first place?
EDIT: I noticed this is only happening when Main Camera collides with other “Collidable” 3D objects. Perhaps I need to learn more about the physics features.
using UnityEngine;
using System.Collections;
public class FPSMove : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
public float speed;
void Update()
{
speed = 0.1f;
if (Input.GetKey(KeyCode.W))
{
transform.position += transform.forward * speed;
}
if (Input.GetKey(KeyCode.S))
{
transform.position -= transform.forward * speed;
}
if (Input.GetKey(KeyCode.A))
{
transform.position -= transform.right * speed;
}
if (Input.GetKey(KeyCode.D))
{
transform.position += transform.right * speed;
}
}
}