so i am making a multiplayer game in photon and when i try and jump i just stay on the ground.
here is my code
using UnityEngine;
using System.Collections;
public class ProjectJumpCharacterController : MonoBehaviour {
//booleans
public bool issprinting = false;
public bool ShootingEnabled = false;
public bool SprintingEnabled = false;
public bool StaminaEnabled = false;
//floats
//b
public float bulletImpulse = 100f;
//g
public float gravity = 20;
//j
public float jumpHeight = 12;
//L
public float lowgravity = 5;
//m
public float mouseSensitivity = 6.0f;
public float movespeed = 100.0f;
//n
public float normalspeed = 250.0f;
//s
public float sprintspeed = 500.0f;
//u
public float upDownRange = 60.0f;
//v
float verticalRotation = 0;
//KeyCodes
public KeyCode sprint = KeyCode.LeftShift;
//GameObjects
public GameObject bullet_prefab;
public GameObject shootfrom;
//Vectors
private Vector3 amountToMove;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Low-Gravity")
{
gravity = lowgravity * Time.deltaTime;
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Low-Gravity")
{
gravity = 25 * Time.deltaTime;
}
}
void Update()
{
//Walking
float Fspeed = Input.GetAxis("Vertical") * movespeed * Time.deltaTime;
float Sspeed = Input.GetAxis("Horizontal") * movespeed * Time.deltaTime;
//Declaring our Character Controller and assigning it a name
CharacterController cc = transform.GetComponent<CharacterController> ();
//Rotation
//Rotating the camera
float rotLeftRight = Input.GetAxis ("Mouse X") * mouseSensitivity;
transform.Rotate (0, rotLeftRight, 0);
verticalRotation -= Input.GetAxis ("Mouse Y") * mouseSensitivity;
verticalRotation = Mathf.Clamp (verticalRotation, -upDownRange, upDownRange);
Camera.main.transform.localRotation = Quaternion.Euler (verticalRotation, 0, 0);
//Sprinting
//If the player presses the sprint key it adjusts the move speed of the player
//if stamina is enabled it requires stamina to be > 0 and it depletes stamina when sprinting
if (Input.GetKey (sprint) && SprintingEnabled == true)
{
issprinting = true;
}
if (Input.GetKeyUp (sprint))
{
issprinting = false;
}
if (issprinting == true && SprintingEnabled == true)
{
movespeed = sprintspeed;
}
if (issprinting == false )
{
movespeed = normalspeed;
}
//Jumping
if (cc.isGrounded)
{
amountToMove.y = 0;
if (Input.GetButtonDown ("Jump"))
{
amountToMove.y = jumpHeight *Time.deltaTime;
}
}
if ((cc.collisionFlags & CollisionFlags.Above) != 0)
{
if(amountToMove.y > 0)
{
amountToMove.y = -gravity;
}
}
//getting the cc to move
amountToMove.x = Sspeed;
amountToMove.z = Fspeed;
amountToMove.y -= gravity;
amountToMove = transform.rotation * amountToMove;
cc.Move (amountToMove);
//Shooting
if (Input.GetButtonDown ("Fire1") && ShootingEnabled == true)
{
GameObject thebullet = (GameObject)PhotonNetwork.Instantiate ("bullet 1", shootfrom.transform.position, shootfrom.transform.rotation, 0);
thebullet.rigidbody.AddForce (shootfrom.transform.forward * bulletImpulse, ForceMode.Impulse);
}
}
if i remove time.deltatime on the jumping part i go really high really fast and then back down really fast it just pops up and down
i need to fix this fast! please help me