- Home /
Why when i press space button nothing was happened
I bought course, reached to jumping lesson all okay, but jump dont works
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movePlayer : MonoBehaviour
{
public float moveSpeed, gravModifier, jumpPower;
public CharacterController CharCon;
private Vector3 moveInput;
public Transform camTrans;
public float mouseSens;
public bool invertX;
public bool invertY;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//moveInput.x = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;
//moveInput.z = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime;
//store y velocity
float yStore = moveInput.y;
moveInput.y = yStore;
Vector3 vertMove = transform.forward * Input.GetAxis("Vertical");
Vector3 horiMove = transform.right * Input.GetAxis("Horizontal");
moveInput = vertMove + horiMove;
moveInput = moveInput * moveSpeed;
moveInput.y += Physics.gravity.y * gravModifier * Time.deltaTime;
if(CharCon.isGrounded)
{
moveInput.y = Physics.gravity.y * gravModifier * Time.deltaTime;
}
//handle jumping
if(Input.GetKeyDown(KeyCode.Space))
{
moveInput.y = jumpPower;
}
CharCon.Move(moveInput * Time.deltaTime);
//cam control rotation
Vector2 mouseInput = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")) * mouseSens;
if(invertX)
{
mouseInput.x = -mouseInput.x;
}
if (invertY)
{
mouseInput.y = -mouseInput.y;
}
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + mouseInput.x, transform.rotation.eulerAngles.z);
camTrans.rotation = Quaternion.Euler(camTrans.rotation.eulerAngles + new Vector3(-mouseInput.y, 0f, 0f));
}
}
снимок.png
(254.7 kB)
Comment
Your answer
Follow this Question
Related Questions
Anti-Gravity isn't working 1 Answer
Jumping script WONT WORK!!!!!!!! for 2D 1 Answer
Gravity and jumping is wierd 1 Answer
fps jump Brackeys 0 Answers
Adding a jump feature help? 2 Answers