Home>

I'm playing with unity, but when I want to accelerate, there is no speed limit, so it gets really fast. When I reach a certain speed, I wonder if I can continue to run at that speed.

I will fly at a tremendous speed

Corresponding source code

Written in Microsoft visual studio in C #
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MyObject: MonoBehaviour
{
void FixedUpdate ()
{
Rigidbody rb = this.GetComponent();// Get rigidbody
Vector3 force = new Vector3 (10f, 0.0f, 0.0f);// Set the force
rb.AddForce (force, ForceMode.Force);// Apply force
}
}

What I tried

I wrote public float Speed ​​= 200 ;, maybe this is the cause

Supplementary information (FW/tool version, etc.)

unity 2018 4,12f1 personal.

  • Answer # 1

      [SerializeField]
        float Limit Speed


    After adding this as a variable

      if (rb.velocity.magnitude>LimitSpeed)
        {
            rb.velocity = new Vector3 (rb.velocity.x/1.1f, rb.velocity.y, rb.velocity.z/1.1f);
        }


    Try embedding this in your Fixed Update
    I get the speed with rigidbody.velocity.magnitude so that it doesn't get any faster when it reaches the speed specified by LimitSpeed.
    If this doesn't happen, it's in new Vector 3/ 1.1fIt may be better to adjust by increasing the number in the part of