Four centuries ago, the physicist Newton discovered the gravitation and extended three Newton's theorems, which laid a strong theoretical foundation for the development of the physics field. Newton has a sentence I like: "If I see far, it is because I stand on the shoulders of giants." ”
Game design is the same, we write planning documents need word, Excel, Visio and other Office software, writing programs need Visual Studio, Eclipse and other integrated development environment, art needs 3dsMax, Maya, Photoshop ... Because of these powerful tools, our productivity will become more and more efficient. So use Notepad to write code, paint pictures with Windows Mona Lisa What, just the embodiment of personal ability, to retain a respect for the mood is good, do not really apply to the actual work oh, the boss will go crazy ^_^.
The words do not know that that to Newton to bring enlightenment of the apple, in the end is dropped on the ground or really fell on the head of Newton, in short, it is falling down. Using basic physics knowledge of junior middle School we know that this is because the earth exerts gravity on the apples. Also in the "Angry Birds", we put the birds into the air with a slingshot, will always fall on the ground. In most physics engines, you can use a rigid body (rigidbody) to simulate this effect, and unity is no exception.
Take a look at the description of the rigid body in the official document: When a game object is assigned to a rigid body component, the game engine simulates the physical effect. At the same time, we can exert various forces on this object to make it move. In addition, if you want to achieve the effect of gravity, then the corresponding game object must be attached to the rigid body assembly.
I imported an Apple model in unity to experiment with the effects of gravity, select the model and add a rigid body component. (Main menu →component (component) →physics (physical) →rigidbody (rigid body), the operation of adding components is very similar, no longer repeat. You can see that the list of properties is not very complex, just a little bit about:
Mass (Quality): Students who have studied physics know that the greater the quality, the greater the inertia. The units here can be set by themselves, but the official advice is that the object in the scene is best not to have a 100 times-fold ratio. An estimate is to prevent two objects that are too large to collide and cause too much speed, which can affect game performance. Drag (Resistance): This refers to the air resistance, when the game object receives a certain force, the greater the more difficult to move. If set to infinity, the object will stop moving immediately. Angular Drag (angular resistance): Also refers to air resistance, but is used to hinder the rotation of the object. If set to infinity, the object will stop spinning immediately. Use Gravity (using gravity): Tick the item, the game object will be affected by gravity. is kinematic (dynamic): Checking this option causes the game object to be unaffected by the physical engine, but this is not the same as no rigid body component. This is typically used for rigid bodies that need to be animated, so that the animation is not affected by inertia. Interplate (difference type): If you see a rigid body moving, or the movement is not very smooth, you can choose a smooth way: none (no difference): Do not use the difference smoothing. Interpolate (difference): moves smoothly according to the previous frame. Extrapolate: Moves smoothly according to the position of the next frame of the object. Collision Detection (Collision detection mode): discrete (discrete): The default collision detection mode. But if the object A is moving quickly, it is possible that the previous frame is in front of the B object, and the latter frame is behind the B object, which will not trigger the collision event, so if you need to detect this situation, then you must use the latter two methods of detection. Continuous (Continuous): This method can be used for collision detection with a game object with a static mesh collider. Continuous Dynamic: This method can be used for collision detection with all game objects set up in 2 or 3 ways. Freeze position/rotation (frozen position/rotation): The position/rotation of the object on the X, Y, z three axes can be locked, even if the corresponding force does not change, but can be modified by the script.
After understanding the set parameters of the rigid body components, click on the test Run game button (remember to point the camera to the Apple), the results found that the Apple did fall, but did not stop on the ground, but wear the past, embarrassing. Check that the original forgot to add a collider, so find a spherical collider attached to the Apple on the OK. It seems that unity also automatically matches the size of the collider, save me to adjust again, really thoughtful.
As shown in the figure above, the green curve represents the ball collider that Apple has, and if you run the game you can see that the apples have landed correctly. But there is a problem, because the terrain in my scene is not horizontal, so the apple will slowly slowly roll to the center of the lake after landing ... To add a collision material to the terrain looks like Apple or not hesitate to go to the center of the lake, if there is a man passing still hope pointing twos.
Finally, by the way, the constant force component (Constant forces), because it is relatively easy to understand I do not do a detailed introduction. A total of 4 parameters, namely Force/relative Force (World/Relative forces), Torque/relative Torque (World/Relative torque).
These parameters represent the size of the constant force of the XYZ axis attached to the rigid body, and it is also important to note that a rigid body is required to add a constant force. Interested in trying to give the object a force in the y-axis direction, the object will fly like a rocket to the sky, haha.
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.