Question by
Yogurt_ · Jul 25, 2017 at 01:15 PM ·
fpscontroller
How can I make my fps controller jump only on the ground?
I want to make it so that my character will jump only when hes on the ground heres my scripts
using UnityEngine;
public class CharacterController : MonoBehaviour {
public float speed = 10.0f;
// Use this for initialization
void Start () {
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update () {
float translation = Input.GetAxis("Vertical") * speed;
float straffe = Input.GetAxis("Horizontal") * speed;
translation *= Time.deltaTime;
straffe *= Time.deltaTime;
transform.Translate(straffe, 0, translation);
if (Input.GetKeyDown("escape"))
{
Cursor.lockState = CursorLockMode.None;
}
}
}
this ones for the camera looking
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class camMouseLook : MonoBehaviour {
Vector2 mouseLook;
Vector2 smoothV;
public float sensitivity = 5.0f;
public float smoothing = 2.0f;
GameObject character;
// Use this for initialization
void Start () {
character = this.transform.parent.gameObject;
}
// Update is called once per frame
void Update () {
var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")); md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
smoothV.x = Mathf.Lerp(smoothV.x, md.x, 1f / smoothing);
smoothV.y = Mathf.Lerp(smoothV.y, md.y, 1f / smoothing);
mouseLook += smoothV; transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
}
}
Comment
Your answer
Follow this Question
Related Questions
BasicFPS controller "Can not be loaded" 0 Answers
fps script not working 1 Answer
Camera Constantly Rotating 0 Answers
What is the problem with the forward motion in this script? 0 Answers
FPS Controller 1 Answer