当前位置:网站首页>[unity3d] rigid body component
[unity3d] rigid body component
2022-06-26 05:02:00 【little_ fat_ sheep】
1 Preface
rigid body (Rigidbody) yes kinematics (Kinematic) A concept in , It refers to the movement and force , The shape and size remain the same , And the relative positions of the interior points remain unchanged . stay Unity3D in , Rigid body components give game objects some kinematic properties , It mainly includes Mass( quality )、Drag( resistance )、Angular Drag( Angular resistance )、Use Gravity( Whether to use gravity )、Is Kinematic( Whether it is affected by physics )、Collision Detection( collision detection )、 Velocity( Speed )、Force( Stress )、Explosion Force( Explosive force ). No rigid body (RigidBody) Components , Game objects can penetrate each other , There's no collision .
1) Get the rigid body component
Rigidbody rig = GetComponent<Rigidbody>();
2) Rigid body component panel properties
- Mass: The mass of the object ( Default in kilogram )
- Drag: The amount of air resistance to the object
- Angular Drag: When an object rotates , The magnitude of the rotational resistance received
- Use Gravity: If enabled , Objects will be affected by gravity
- Is Kinematic: If enabled , Objects will not be driven by the physics engine , Only by its Transform Component operations
- Interpolate: Interpolator of the moving position of the object
- Collision Detection: Collision detection type , When you see an object moving too fast through a wall , Collision detection frequency can be enhanced , choice Continuous Options
- Constraints: Restrictions on the motion and rotation of rigid bodies , The component on a coordinate axis remains unchanged when restricting the motion of an object
- velocity: Object motion vector velocity
3) Rigid body component method
// The thrust on the rigid body
public void AddForce(Vector3 force)
// The explosive force on the rigid body ,explosionForce: The magnitude of the explosive force ,explosionPosition: Explosion point ,explosionRadius: Explosion radius
public void AddExplosionForce(float explosionForce, Vector3 explosionPosition, float explosionRadius)
2 application
2.1 Application 1
1) Create game objects
establish Cube and Plane The game object , as follows :
2) to Cube Game objects add rigid body components
Choose Cube The game object , Click on Add Component Button , Search for Rigidbody, Add rigid body components .
3) add to RigidbodyController Script
RigidbodyController.cs
using UnityEngine;
public class RigidbodyController : MonoBehaviour {
private Rigidbody rig;
void Start () {
rig = GetComponent<Rigidbody>();
}
void Update () {
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
float up = Mathf.Sqrt(hor * hor + ver * ver);
if (up > 0.1) {
rig.velocity = new Vector3(hor, up, ver);
}
}
}
4) Running effect
Use the up, down, left and right arrow keys , Control the cube to lift up to the surrounding sky , Release the key , The cube fell down under the action of gravity .
2.2 Application 2
1) add to RigidbodyController Script
On the basis of application one , take RigidbodyController The script is modified as follows :
RigidbodyController.cs
using UnityEngine;
public class RigidbodyController : MonoBehaviour {
private Rigidbody rig;
void Start () {
rig = GetComponent<Rigidbody>();
}
void Update () {
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
float up = Mathf.Sqrt(hor * hor + ver * ver);
if (up > 0.1) {
rig.AddForce(new Vector3(hor, 0, ver) * 10); // Add thrust
}
}
}
2) Running effect
Use the up, down, left and right arrow keys , The control cube receives a push from all around .
2.3 Application 3
1) Create game objects
On the basis of application one , establish 4 individual Cube The game object ,position Respectively :(0, 1, 2)、(0, 1, -2)、(-2, 1, 0)、(2, 1, 0), as follows :
to 4 individual Cube Game objects are added Rigidbody Components and RigidbodyController Script components .
2) add to RigidbodyController Script
using UnityEngine;
public class RigidbodyController : MonoBehaviour {
private Rigidbody rig;
void Start () {
rig = GetComponent<Rigidbody>();
}
void Update () {
if (Input.GetKeyDown(KeyCode.Space)) {
// stay (0,0,0) Add... At coordinates 10 Within meters 300N Explosive force of
rig.AddExplosionForce(300, Vector3.zero, 10);
}
}
}
3) Running effect
Press the space bar ,4 Three cubes are subjected to an explosive force from the center .
边栏推荐
- dijkstra
- Day3 data type and Operator jobs
- 【quartz】从数据库中读取配置实现动态定时任务
- 2022.2.17
- Computer Vision Tools Chain
- Differences between TCP and UDP
- Image translation /gan:unsupervised image-to-image translation with self attention networks
- Yolov5 super parameter setting and data enhancement analysis
- Interpretation of yolov5 training results
- 2022.2.13
猜你喜欢
UWB超高精度定位系统架构图
广和通联合安提国际为基于英伟达 Jetson Xavier NX的AI边缘计算平台带来5G R16强大性能
UWB超高精度定位系统原理图
A new paradigm for large model application: unified feature representation optimization (UFO)
1.12 learning summary
0622-马棕榈跌9%
钟珊珊:被爆锤后的工程师会起飞|OneFlow U
#微信小程序# 在小程序里面退出退出小程序(navigator以及API--wx.exitMiniProgram)
超高精度定位系统中的UWB是什么
Image translation /gan:unsupervised image-to-image translation with self attention networks
随机推荐
Resample
图解OneFlow的学习率调整策略
Day3 data type and Operator jobs
22.2.8
torchvision_ Transform (image enhancement)
1.16 learning summary
Multipass中文文档-使用Multipass服务授权客户端
PowerShell runtime system IO exceptions
Numpy general function
Solution to back-off restarting failed container
【Unity3D】人机交互Input
One of token passing between microservices @feign's token passing
微信小程序保存圖片的方法
天才制造者:獨行俠、科技巨頭和AI|深度學習崛起十年
Some parameter settings and feature graph visualization of yolov5-6.0
86. (cesium chapter) cesium overlay surface receiving shadow effect (gltf model)
2.< tag-动态规划和常规问题>lt.343. 整数拆分
Using Matplotlib to add an external image at the canvas level
1.17 learning summary
Happy New Year!