Player defies gravity and constantly returns to origin point.
I realise that gravity questions are often asked, but I can't seem to find an answer that fits my problem.
What I have created is really simple - I have my first person perspective (attached to a capsule), a terrain and a boat.
Now when the game starts, the boat falls down to meet the terrain, but my player actually moves up so that it returns to the origin point and then is quite happy to move around in the air.
For my FPS I am using the coding provided in Joseph Hockings book 'Unity in Action: Covers Unity 5.0' :
using UnityEngine; using System.Collections;
[RequireComponent(typeof(CharacterController))] [AddComponentMenu("Control Script/FPS Input")] [RequireComponent(typeof(AudioSource))]
public class FPSInput : MonoBehaviour { public float speed = 6.0f; public float gravity = -9.8f;
private CharacterController _charController;
void Start()
{
_charController = GetComponent<CharacterController>();
}
void Update()
{
float deltaX = Input.GetAxis("Horizontal") * speed;
float deltaZ = Input.GetAxis("Vertical") * speed;
Vector3 movement = new Vector3(deltaX, 0, deltaZ);
movement = Vector3.ClampMagnitude(movement, speed);
movement.y = gravity;
movement *= Time.deltaTime;
movement = transform.TransformDirection(movement);
_charController.Move(movement);
}
}
So not only is my FPS not falling but he refuses to leave the origin line! Any help would be really appreciated!
Your answer
Follow this Question
Related Questions
How to destroy Terrain-Tree-Collider? 3 Answers
Restrict public field to powers of 2? 1 Answer
i have a red error when i create c# script 0 Answers
Destroying 2D terrain at runtime 0 Answers
Move only if mouse click the Terrain 0 Answers