I am new to coding and watched Brackets tutorial on FPS movement, after i tried some on my own and made a little strip of code to add on to the movement script. it “worked” Unity could run the game, but when I am in the game it tells me that the key I had wasen’t bound, that was my first mistake I think. Then I tried walking around and it was working like normal untill I tried my staircase. When i walked of i registered that my gravety was of. I dind’t tuch that code and can’t se how any of the changes I made could have affected it.
It is an running script. I thought it would be easy, just make another key for extra speed. But shows how new i am when it dosen’t work and it destroys something else also. Plz help.
Here is the paste:
The bold text is the new code i added on.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
public float speed = 12f;
public float gravity = -9.82f;
public float jumpHeight = 9f;
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);
//New Code
if(Input.GetButtonDown(“Shift”) && isGrounded)
{
Vector3 speed = transform.right * x + transform.forward * z * 2;
}
if(Input.GetButtonDown(“Jump”) && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
velocity.y += gravity * 3 * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}