- Home /
Question by
BLEN-Coding-Unity · Apr 28, 2019 at 04:55 PM ·
3dmovement script
why does update only run once?
No errors come on the console, but the script only runs once and then just stops. There is another script in this game that works fine.
This is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movement_collision : MonoBehaviour
{
public Rigidbody rb;
public float Xamount_to_move;
public float Zamount_to_move;
public float XLamount_move;
public float YLamount_move;
public float yaw;
public static float yawspeed = 1;
public static float acceleration = 125;
public static float top_speed = 75;
public static float throttlePunch = 7000;
void FixedUpdate()
{
Xamount_to_move = Input.GetAxis("RightStickHorizontal");
Zamount_to_move = Input.GetAxis("RightStickVertical");
XLamount_move = Input.GetAxis("LeftStickHorizontal");
YLamount_move = Input.GetAxis("LeftStickVertical") * -1;
yaw = yaw + XLamount_move;
rb.AddForce(Mathf.Sin(yaw * yawspeed) * Zamount_to_move * -acceleration * Time.deltaTime,
0, Mathf.Cos(yaw * yawspeed) * Zamount_to_move * -acceleration * Time.deltaTime, ForceMode.Impulse);
rb.AddForce(Mathf.Cos(yaw * yawspeed) * Xamount_to_move * acceleration * Time.deltaTime,
0, Mathf.Sin(yaw * yawspeed) * Xamount_to_move * -acceleration * Time.deltaTime, ForceMode.Impulse);
if (YLamount_move > 0)
{
rb.AddForce(0, YLamount_move * throttlePunch * Time.deltaTime, 0);
}
if (YLamount_move < 0)
{
rb.AddForce(0, YLamount_move * 10000 * Time.deltaTime, 0);
}
rb.rotation = Quaternion.Euler(-Zamount_to_move * 24, yaw * (Mathf.PI * 2) * yawspeed, -Xamount_to_move * 24);
rb.velocity = new Vector3(Mathf.Clamp(rb.velocity.x, -top_speed, top_speed),
Mathf.Clamp(rb.velocity.y, -10000000, 10000000),
Mathf.Clamp(rb.velocity.z, -top_speed, top_speed));
if (YLamount_move < 0.01)
{
if (YLamount_move > -0.01)
{
rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y / 1.075f, rb.velocity.z);
}
}
if (Xamount_to_move < 0.01)
{
if (Xamount_to_move > -0.01)
{
rb.velocity = new Vector3(rb.velocity.x / 1.05f, rb.velocity.y, rb.velocity.z);
}
}
if (Zamount_to_move < 0.01)
{
if (Zamount_to_move > -0.01)
{
rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y, rb.velocity.z / 1.05f);
}
}
Debug.Log("frame complete");
}
}
Comment
You could add try those
void OnDestroy(){ print("Destroyed"); }
void OnDisable(){ print("Disabled"); }
to see if something is deactivating or destroying your object/component.
Your answer
Follow this Question
Related Questions
How can i make my character jump and slide on command? 0 Answers
how to make automatic gradual acceleration 1 Answer
My movement script is kind of broken for jumping (upward force is diminished after first jump) 1 Answer
sonic movement stick to the ground 1 Answer
How to make a top down character snap to different directions 0 Answers