Cláudia Ribeiro PHYSICS
Cláudia Ribeiro Goals: - Colliders - Rigidbodies - AddForce and AddTorque
Cláudia Ribeiro AVT 2012 Colliders Colliders components define the shape of an object for the purpose of physical collisions. These are denominated static colliders: they do not move in response to colisions (e.g. walls, floors, etc) When colliders interact, their surfaces can simulate the properties of a physical material (e.g. ice will be slippery, a rubber ball will offer friction and be bouncy)
Cláudia Ribeiro AVT 2012 Colliders Functions Colliders: Colliders as triggers: Collider Character Controller: A collider configured as a trigger does not behave as a solid object and will simply allow other colliders to pass through.
Goals: Detect collisions with static colliders (as trigger and not trigger) Steps: 1. 2. 3. Create a box: GameObject > Create Other> Cube and add a new tag box in the inspector and assigned it to the object Add Script: Assets->Create->JavaScript or C# and add it to the First Person Controller. use OnControllerColliderHit to detect collisions and hit.transform.tag to only react to the collision with the box (otherwise, it will react to collisions with every object that has a collider, such as walls, floor, etc..)
Cláudia Ribeiro Rigidbodies Is the main component that enables physical behaviour for an object Dynamic colliders - Drag: how much air resistance affects the object when moving (forces) - Angular Drag: how much air resistance affects the object when rotating (torque) - iskinematic: the object will not be driven by physics engine, and can only be manipulated by its transform - Interpolate: Transform is smooth based on previous or next frame. To change this attributes by script: Use transform.rigidbody.[attribute] - Collision Detection: Use Discrete collision detection against dynamic colliders (with a rigidbody) and continuous collision detection against static MeshColliders (without a rigidbody). To adjust physics engine settings: Edit -> Project Settings -> Physics
Goals: Rigidbodies Steps: First Part: 1. 2. Create several primitives: GameObject > Create Other> Cube, Sphere, etc Add a rigidbody (Component -> Physics -> RigidBody) and change the attributes to experiment different behaviors. Second Part: 1. Create a Script: Assets->Create->JavaScript or C# and add it to the object in the scene (cube, sphere, etc). 2. Set the iskinematic to true (RigidBody) and use transform.translate in the Update() function to move your object in the scene. You can also use OnTriggerEnter, etc to maintain the object in the scene
Cláudia Ribeiro AddForce and AddTorque AddForce: applies a force to a rigidbody. As a result it will affect the object movement according to the type of force being applied AddForce(force: Vector3, mode: ForceMode = ForceMode.Force): void; AddTorque: torque is the tendency of a force to rotate an object. In unity this function allows to apply a force around a rotation axis AddTorque(torque: Vector3, mode: ForceMode = ForceMode.Force): void; Force Types: Force: add a continuous force to the rigidbody, using its mass Accelaration: add a continuous accelaration, ignoring its mass Impulse: add na instant force impulse, using its mass VelocityChange: add na instant velocity change, ignoring its mass
Goals: Use AddForce to allow the character controller to push a box Steps: 1. 2. Add the necessary code to the OnControllerColliderHit() function Add a rigidbody (Component -> Physics -> RigidBody) and change the attributes to experiment different behaviors.
Goals: Use AddTorque to continuously rotate an object Steps: 1. 2. 3. 4. Create several primitives: GameObject > Create Other> Cube, Sphere, etc Add a rigidbody (Component -> Physics -> RigidBody) Create a Script: Assets->Create->JavaScript or C# and add it to the object in the scene (cube, sphere, etc). Add the necessary code to the Update() function
Goals: Use a collider to move an object in a contained space Steps: 1. Create an empty gameobject: GameObject > Create Empty 2. Add a Box Container (Component -> Physics -> Box Container) 3. Position the box container and the box (created earlier) in the scene 4. Create a Script: Assets->Create->JavaScript or C# and add it to the box 5. Add the necessary code to the OnTriggerStay() and OnTriggerExit function 6. Try to do the same with a sphere hovering in the Y axis!