Unity physical engine-rigid body collision

Source: Internet
Author: User

Rigid Body components:

Adding a rigid body attribute to an object and setting some parameters can simulate the physical effect of the world:

Add:

Is to select an object, select physical in component, select the Rigidbody

In this case, the object added with the rigid body attribute can fall by gravity.

Specific settings are set in the monitor:

 

You can set the constant force to apply to an object:

Add the following components:

 

You can also use a script to configure the settings:

The force of the rigid body is usually set in the fixedupdate () function, as a fixed-time refresh content:

C # The script is as follows:

1 void FixedUpdate()2     {3         rigidbody.AddForce(0.0F,10.0F,0.0F);4     }

Specific settings can be found in Rigidbody documents.

 

Rigid Body collision and message transmission:

When creating a built-in object, it will automatically set a collision, such as a grid collision tool for a plane object and a spherical collision tool, these things will make some responses when a collision occurs after adding physical properties.

 

Message transmission in rigid body collision:

In the oncollisionenter function, you can set the logic after the collision.

Example: C #

void OnCollisionEnter(Collider collsion)    {        print(collsion.gameObject);    }

Here, the collison variable is the collision body.

Print the collision object type,

It indicates that when a collision occurs, the function receives the message and responds accordingly;

 

Trigger collision and message transmission:

Each collision server has a trigger or not option. This option is set to play the scene again without collision effect, however, the collision message is captured and sent to a function named ontriggerenter for execution.

Like this:

void OnTriggerEnter(Collider other)    {        print(other.gameObject);    }

Figure:

The lower left corner shows all collision objects. The main advantage is that collision detection can be performed without affecting the motion of objects;

Above.

Unity physical engine-rigid body collision

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.