Introduction to 003-unity3d physics engine and examples

Source: Internet
Author: User

I. Overview

The physics engine is the engine that simulates the collision and fall of objects in the real world, through ballence, Angry Birds and so on. Unity3d's physics engine uses Nvidia's PhysX.

The physics engine is a computer program that simulates Newton's mechanical model using variables such as mass, velocity, friction, and air resistance. Can be used to predict the effects of this different situation. It is mainly used in computational physics and video games as well as in computer animation.

There are two common types of physics engines: the real-time physics engine and the high-precision physics engine. High-precision physics engines require more processing power to calculate very precise physics, usually used in scientific research (computational physics) and computer animated film productions. Real-time physics engines are often used in video games and simplify operations, reducing accuracy by reducing computational time and getting processing speeds that are acceptable in video games.

Ii. examples

Choose a Game object, the main menu →component→physics→rigidbody, so add a rigid component, once a gameobject to add a rigid component, he will be affected by gravity, collision, etc., the most typical is "underfoot" will fall, Collisions with other rigid bodies can rebound, cannot enter, etc. The ground with plane, add illumination will be better.

Development steps:

1, create the project, open the software,

    

    

The default is as follows

    

You can also add a new sence by hand,

    

2. Create a sphere, click Create, creating a 3d object→sphere. Configure its coordinates x:0 y:5 z:0

3, set the sphere as a rigid body, select sphere, select Physics→rigidbody on component, at this time in inspector, you can see

    

Set Drag to 1

Specific meaning can be seen in the first installation of the document

    

4. Set the sphere material

  

Import only the necessary packages

  

Drag the material properties onto the sphere to

5. Add Ground

At Create→plane, you can see the effect by clicking the toolbar to run.

6. Add Scripts

    

    

7. Script Content Writing

Set script Open by: edit→perferences→external tool→ Select the Development script tool to

Script Default has two methods

Start Object Initialization

Update: Each frame is invoked at the time of execution

Add the following to update

if (Input.getmousebuttondown (0))        {            this.gameobject.getcomponent<rigidbody>(). Addforce (Vector3.forward, Forcemode.impulse);        }

Drag the script to a specific game to push, the same script can give multiple game objects.

Run the test click the mouse to view the effect.

Introduction to 003-unity3d physics engine and examples

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.