Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to set rigidbody velocity in unity

//Set Velocity to a certain speed
[SerializeField] private float maxSpeed = 10;
[SerializeField] private Rigidbody rb;

void FixedUpdate() {
  if(rb.velocity.magnitude > maxSpeed) {
    rb.velocity = rb.velocity.normalized * maxSpeed;
  }
}
Comment

unity how to set rigidbody velocity

Vector3 velocity = new Vector3(10f/*x*/, 10f/*y*/, 10f/*z*/);
GetComponent<Rigidbody>().velocity = velocity;
Comment

rigidbody velocity c# unity

//for rigidbody2D
GetComponent<Rigidbody2D>().velocity =new Vector2(40,0);
Comment

how to decrease velocity of a Unity rigidbody

//Drecrese Rigidbody Speed
[SerializeField] private Rigidbody rb;

void FixedUpdate() {
  //Decrease speed
  rb.velocity -= rb.velocity * 0.1f;
}
Comment

unity control velocity on rigidbody

[SerializeField] private Rigidbody rb;
[SerializeField] private float rbMaxSpeed;
[SerializeField] private float rbMag;

private void FixedUpdate()
{
	rbMag = rb.velocity.magnitude; // Total xyz magnitude
    if (rb.velocity.magnitude > rbMaxSpeed)
    {
    	rb.velocity = Vector3.ClampMagnitude((Vector3)rb.velocity,rbMaxSpeed);
    }
}
Comment

rigidbody velocity

rb.velocity = new Vector3(0, 10, 0);
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# initialize empty array 
Csharp :: get all child gameObject of gameObject C# 
Csharp :: unity show colliders 
Csharp :: how to set unique constraint from EF core 
Csharp :: linq query select top 1 c# 
Csharp :: c# list string return concatenate 
Csharp :: get any random item in array c# 
Csharp :: get last 4 character c# 
Csharp :: if in dictionary c# 
Csharp :: replace index in string c# 
Csharp :: c# static meaning 
Csharp :: rotate player unity 
Csharp :: c# list slice 
Csharp :: capitalize first letter c# 
Csharp :: create sequence of squares in c# 
Csharp :: how add text to element in javascript 
Csharp :: 2 rotation unity 
Csharp :: how to check datagridview cell is null or empty 
Csharp :: hello world in unity c# 
Csharp :: increment operator c# 
Csharp :: CS0101 Unity Error Code 
Csharp :: c# how to find character in string 
Csharp :: roman to number 
Csharp :: c# parse string to xml 
Csharp :: C# default value for datetime parameter 
Csharp :: switch expression c# 
Csharp :: array in c# stack overflow 
Csharp :: difference between boxing and unboxing in c# 
Csharp :: c# sort for loop 
Csharp :: c# use api rest 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =