- Home /
Question by
nicoolsen10 · Sep 26, 2020 at 03:39 PM ·
playerjumpjumping
How to make the player turn in the air
Hey so im trying to make my player turn in the direction its looking in the air but i cant make it to work everytime i jump i can only jump that way i was looking when i jump here is my playercontroller script
public void Update()
{
playerCam.fieldOfView = playerFov;
if (Input.GetKeyDown(KeyCode.Escape))
{
pauseMenu.Pause();
}
if (playingMode == true)
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
rigidBody.isKinematic = false;
GameObject playerCam = GameObject.Find("Player_Camera");
if (cc.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= currentSpeed;
if (Input.GetButton("Jump"))
{
Jump();
}
else if (Input.GetButton("Jump") && !cc.isGrounded)
{
;
}
}
moveDirection.y -= _gravity * Time.deltaTime;
cc.Move(moveDirection * Time.deltaTime);
//Ændre for at ændre på sensivity
float xMouse = Input.GetAxis("Mouse X") * 5f;
transform.Rotate(0, xMouse, 0);
//Så kan man ikke se 360 grader rundt
pitch -= Input.GetAxis("Mouse Y") * 10f;
pitch = Mathf.Clamp(pitch, -70f, 70f);
Quaternion camRotation = Quaternion.Euler(pitch, 0, 0);
playerCam.transform.localRotation = camRotation;
//Gør så man kan løbe
if (Input.GetKeyDown(KeyCode.LeftShift))
{
isSprinting = true;
Sprint();
}
else if (Input.GetKeyUp(KeyCode.LeftShift))
{
isSprinting = false;
Sprint();
}
}
}
public void Jump()
{
moveDirection.y = _jumpSpeed;
//Remove stamina
}
Comment
Answer by Chrissyeah_ · Sep 26, 2020 at 04:42 PM
Your movement direction code only works when you are grounded. You can move it to your update or Fixed update instead and just use grounded as a jump test.