#Followed FPS Movement Tutorial Video, completed script, but one portion doesn't serve it's purpose

1 messages · Page 1 of 1 (latest)

carmine warren
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playermovement : MonoBehaviour
{

    public CharacterController controller;

    public float speed = 12f;
    public float gravity = -9.81f;
    public float jumpHeight = 3f;

    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);
    }
}

So when I started this tutorial before the ground check I realized I fell down quite quickly, so after watching a bit further, I see he solves it by adding a ground check, and the velocity y doesn't keep going while your still on the floor, but for some reason mine keeps going after the ground check is complete, and all values are assigned in unity, how do I fix this?

copper sleet
#

You need to add the Ground tag to any object you want to stand on

carmine warren
#

i did do that

#

the picture of the player selected tag is to show what tags i have the tag is assigned to the player in that photo

copper sleet
#

maybe increase the ground distance?

carmine warren
#

YOU ARE A GENIUS

#

THANK YOIU