Difference between revisions of "Physics"

From __space Wiki
Jump to: navigation, search
m (Fixed Joints)
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
Go read the at least the [http://space.apps.uri.edu/wiki/index.php?title=Getting_Started_-_No_Scripting first part] of this tutorial series first, if you haven't already.
+
[http://space.apps.uri.edu/wiki/index.php?title=Learn_Unity_First '''Main guide page''']
 +
 
 +
Go read the at least the [http://space.apps.uri.edu/wiki/index.php?title=Getting_Started_-_No_Scripting first part, Getting Started], of this tutorial series first, if you haven't already.
 
==Colliders==
 
==Colliders==
These give objects the ability to have physics interactions with each other, and detect if the object is touching another object that also has a collider.  They are always only seen as components on objects.  Trigger changes whether or not you want the object to just have a code trigger for when a hit is detected or if you also want it to have the normal physical reaction of bouncing (vs going straight through the object). Choosing Box, Sphere, Capsule, or any of the other shape colliders depends on what the object it is going to be attached to looks like and where you want hits to count.  Mesh collider makes a collider that conforms exactly to the shape of the mesh of the object it is attached to, but using a mesh collider can be very expensive frame-wise, depending on the complexity of the model.  You can usually get by using a box, sphere, or capsule collider and getting it as close to the object's dimensions as possible, because though the object won't have hit detection exactly skintight, no player will notice because colliders are invisible and much of the time, collisions for the player character happen anywhere but in front of them.  So basically, don't use a mesh collider unless it really can't be avoided!
+
These give objects the ability to have physics interactions with each other, and detect if the object is touching another object that also has a collider.  They are only ever seen as components on objects.  The trigger option changes whether or not you want the object to just have a trigger event to activate in the code for when a hit is detected or if you also want it to have the normal physical reaction of bouncing (vs going straight through the object).
 +
 
 +
Choosing Box, Sphere, Capsule, or any of the other collider shapes depends on what the shape of the object it is going to be attached and where you want collisions to count.  A mesh collider would make a collider that conforms exactly to the shape of the mesh of the object it is attached to, but using it can be very expensive frame-wise, depending on the complexity of the model.  You can usually get by using a box, sphere, or capsule collider and getting it as close to the object's dimensions as possible, because though the object won't have hit detection exactly skintight, no player will notice because colliders are invisible and much of the time.  Even collisions for the player character itself happen anywhere but in front of them.  So basically, don't use a mesh collider unless it really cannot be avoided!
  
The material option affects what happens when the object with the collider hits another object with a collider, like whether it bounces and how much, just land, or slide around a little.   
+
The material option affects what happens when the object with the collider hits another object with a collider, like whether it bounces and how much, just land, or slide around a little.  The example below is an object using the bouncy material.
  
 
[[File:bouncy.gif]]
 
[[File:bouncy.gif]]
  
 
==Rigid Bodies==
 
==Rigid Bodies==
Putting a rigid body component object means it can be affected by the game world's gravity and physics.
+
Putting a rigid body component object means it can be affected by the game world's gravity and physics.
 +
This is what happens when you put the default rigid body on a collider with a default collider (no special bouncy material).
 +
 
 
[[File:physics.gif]]
 
[[File:physics.gif]]
  
Line 18: Line 24:
 
Think of fixed joints as metal wires that can connect 2 objects and keep them the same distance apart and considered the same object as far as the physics engine is concerned.
 
Think of fixed joints as metal wires that can connect 2 objects and keep them the same distance apart and considered the same object as far as the physics engine is concerned.
  
[[File:fixedJoint.gif]]
+
If you add a fixed joint to a cube and then drag the sphere from the hierarchy into where it says 'Connected Body' (make sure the sphere and the cube are somewhat close in position, otherwise it will be really weird and probably not work right).
  
The Fixed Joint component on the cube in the scene:
 
 
[[File:cubeFixedJoint.png]]
 
[[File:cubeFixedJoint.png]]
 +
 +
Then, if you press Play and go up to the paired objects you'll see something like the below happening.
 +
 +
[[File:fixedJoint.gif]]

Latest revision as of 16:10, 1 June 2017

Main guide page

Go read the at least the first part, Getting Started, of this tutorial series first, if you haven't already.

Colliders

These give objects the ability to have physics interactions with each other, and detect if the object is touching another object that also has a collider. They are only ever seen as components on objects. The trigger option changes whether or not you want the object to just have a trigger event to activate in the code for when a hit is detected or if you also want it to have the normal physical reaction of bouncing (vs going straight through the object).

Choosing Box, Sphere, Capsule, or any of the other collider shapes depends on what the shape of the object it is going to be attached and where you want collisions to count. A mesh collider would make a collider that conforms exactly to the shape of the mesh of the object it is attached to, but using it can be very expensive frame-wise, depending on the complexity of the model. You can usually get by using a box, sphere, or capsule collider and getting it as close to the object's dimensions as possible, because though the object won't have hit detection exactly skintight, no player will notice because colliders are invisible and much of the time. Even collisions for the player character itself happen anywhere but in front of them. So basically, don't use a mesh collider unless it really cannot be avoided!

The material option affects what happens when the object with the collider hits another object with a collider, like whether it bounces and how much, just land, or slide around a little. The example below is an object using the bouncy material.

Bouncy.gif

Rigid Bodies

Putting a rigid body component object means it can be affected by the game world's gravity and physics. This is what happens when you put the default rigid body on a collider with a default collider (no special bouncy material).

Physics.gif

Some other features, like joints, require rigid bodies but you may not want physics to apply to that object, that case is what the 'Is Kinematic' option is for.

More info on rigid bodies

Fixed Joints

Think of fixed joints as metal wires that can connect 2 objects and keep them the same distance apart and considered the same object as far as the physics engine is concerned.

If you add a fixed joint to a cube and then drag the sphere from the hierarchy into where it says 'Connected Body' (make sure the sphere and the cube are somewhat close in position, otherwise it will be really weird and probably not work right).

CubeFixedJoint.png

Then, if you press Play and go up to the paired objects you'll see something like the below happening.

FixedJoint.gif