- Home /
Question by
Phantom07 · Sep 12, 2019 at 09:51 AM ·
movementinputplayer movementrigidbody.velocitybuilds
Rigidbody movement not working after build
After I build the game, none of the buttons to move or jump work.
The movement works fine in the editor.
the rigidbody still is affected by gravity after the build.
the inputs for pausing still work after the build.
I've tried restating my computer and moving the files to a new project, but it didn't work.
Here is my movement script \/\/\/
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using UnityStandardAssets.Utility.Inspector;
public class playerMovement : MonoBehaviour
{
public float WalkSpeed = 400;
public float RunSpeed = 500;
public bool IsGrounded;
public bool CanMove = true;
public GameObject Player;
public GameObject ResumeButton;
public Rigidbody PlayerRb;
public float HorizontalAxis;
public float VerticalAxis;
public float JumpForce = 150;
public float MovementSpeed = 400;
public KeyCode Pause;
public KeyCode Run;
public Vector3 MoveDirection;
public Vector3 YVelFix;
void Awake()
{
Run = KeyCode.LeftShift;
Pause = KeyCode.Escape;
Player = GameObject.FindWithTag("Player");
PlayerRb = Player.GetComponent<Rigidbody>();
}
private void Start()
{
CanMove = true;
ResumeButton.SetActive(false); //immediatly turns off the pause menu
}
private void OnTriggerEnter(Collider other)//ground check
{
IsGrounded = true;
}
private void OnTriggerExit(Collider other)//ground check
{
IsGrounded = false;
}
void Update()
{
if (Input.GetKey(KeyCode.A))//left movement
{
HorizontalAxis = -1;
}
else if (Input.GetKey(KeyCode.D))//right movement
{
HorizontalAxis = 1;
}
if (Input.GetKey(KeyCode.S))//back movement
{
VerticalAxis = -1;
}
else if (Input.GetKey(KeyCode.W))//forward movement
{
VerticalAxis = 1;
}
if (Input.GetKeyUp(KeyCode.A))//stops movement
{
HorizontalAxis = -0;
}
if (Input.GetKeyUp(KeyCode.D))//stops movement
{
HorizontalAxis = 0;
}
if (Input.GetKeyUp(KeyCode.S))//stops movement
{
VerticalAxis = 0;
}
if (Input.GetKeyUp(KeyCode.W))//stops movement
{
VerticalAxis = 0;
}
MoveDirection = (HorizontalAxis * transform.right + VerticalAxis * transform.forward).normalized;//finds direction of movement
}
void FixedUpdate()
{
// Running
if (Input.GetKey(Run))//run button
{
MovementSpeed = RunSpeed;
}
else
{
MovementSpeed = WalkSpeed;
}
// Pausing
if (Input.GetKeyDown(Pause))//pause button
{
if (CanMove == true)
{
Button.SetActive(true);
CanMove = false;
Time.timeScale = 0.2f;
}
}
if (CanMove == true)//jumping
{
if (CanMove == true && IsGrounded == true)
{
if (Input.GetKey(KeyCode.Space))
{
PlayerRb.AddForce(Vector3.up * JumpForce);
}
}
Move();
}
}
public void Resume()//resume button for pause menu
{
CanMove = true;
Time.timeScale = 1.0f;
Button.SetActive(false);
}
void Move()//movement
{
YVelFix = new Vector3(0, PlayerRb.velocity.y, 0);
PlayerRb.velocity = MoveDirection * MovementSpeed * Time.deltaTime;
PlayerRb.velocity += YVelFix;
}
}
Comment