hello ,
i making a tutorial for fps game , like movement and jumping .
im useing addForce to make jump like the tutorial but instead of jumping ith teleporting to the point and falls by gravity.
note: im not useing character controller, i create an empty gameobject (like somes tutorials) with camrea as a child.
and rigidbody,boxcollider,and my script attach to gameobject.
i know this question has asked before ,but i did everything.
please see the code ignore the rotation and movment .
using UnityEngine;
using System.Collections;
public class characterControllerScript : MonoBehaviour {
public float movmentSpeed = 10f;
public float mouseSensetivity = 2.5f;
public float verticalRotationRange = 60f;
public float jumpForce = 50f;
private float VerRotation = 0f;
private double gravity = 0f;
private float timer = 0f;
// Use this for initialization
void Start () {
Cursor.visible = false;
}
// Update is called once per frame
void Update () {
timer += Time.deltaTime;
//characterMovment+mouseDirection,depending the mouse facing to so the movment is.
float horSpeed = Input.GetAxis("Horizontal")*movmentSpeed;
float verSpeed = Input.GetAxis("Vertical")*movmentSpeed;
float horRotation = Input.GetAxis("Mouse X") * mouseSensetivity;
transform.Rotate(0, horRotation, 0);
VerRotation -= Input.GetAxis("Mouse Y") * mouseSensetivity;
VerRotation = Mathf.Clamp(VerRotation, -verticalRotationRange, verticalRotationRange);
GetComponentInChildren<Camera>().transform.localRotation=Quaternion.Euler(VerRotation,0,0);
// Camera.main.transform.localRotation = Quaternion.Euler(VerRotation, 0, 0);
// Debug.Log(VerRotation);
Vector3 speed = new Vector3(horSpeed, 0, verSpeed);
Rigidbody myRG = GetComponent<Rigidbody>();
speed = transform.rotation * speed;
myRG.velocity = new Vector3(speed.x,speed.y,speed.z);
//jumping
if (Input.GetKeyDown(KeyCode.Space))
{
GetComponent<Rigidbody>().AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
}
}