H
H
howiu2021-08-02 10:42:03
Unity
howiu, 2021-08-02 10:42:03

Why doesn't movement work in the build?

Everything works fine in the unit, but when I create a build, only one script with movement does not work, everything else works. I've looked all over, and there's no answer anywhere.
Here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Moving : MonoBehaviour
{
    public Rigidbody rb;
    float maxSpeed = 8;
    float staticSpeed = 8;
    void Update()
    {
        if (Input.GetKey(KeyCode.W))
        {
            rb.AddForce(Vector3.forward);
        }
        if (Input.GetKey(KeyCode.S))
        {
            rb.AddForce(Vector3.back);
        }
        if (Input.GetKey(KeyCode.A))
        {
            rb.AddForce(Vector3.left);
        }
        if (Input.GetKey(KeyCode.D))
        {
            rb.AddForce(Vector3.right);
        }
        maxSpeed = staticSpeed;
        if (rb.velocity.magnitude > maxSpeed)
        {
            rb.velocity = rb.velocity.normalized * maxSpeed;
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-08-02
@howiu

Find out step by step:

  • Does your game object even exist on stage?
  • Is your component enabled
  • What kind of regidbody does he have in the settings
  • Does GetKey work?
  • Does Addforce work?
  • What is your condition

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question