Question by
zachtiktik · Feb 01 at 09:46 AM ·
physics
Why is my character acting so weirdly?
I'm new to unity and I followed Brackeys tutorial on how to make a 3d character for an fps game, everything works except that my fall is slow even if I change gravity and that my character when I jump teleport mid air and start falling. Here is my code:
using System. Collections;
using System.Collections.Generic;
using Unity Engine;
public class Player Movement : MonoBehaviour
{
public CharacterController controller;
public float speed = 16f;
public float gravity = -9.81f;
public float jump Height = 10f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
Vector3 velocity;
bool isGrounded;
void Update ()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if(isGrounded && velocity.y < 0);
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
if(Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
Determining if my target is standing upright 4 Answers
RayCasting 0 Answers
Rigidbody projectile misses collider 1 Answer
Projectile Changing Angle BEFORE Impact 0 Answers
simulate a physics material bounce to find where it will land 0 Answers