Join Sue Blackman for an in-depth discussion in this video Working with physics components, part of Unity 3D: 3.5 Essential Training.
So what if you wanted a sign outside an old inn to swing in the wind during the whole game? First off, you'd probably only have it swing when the player was around to see it. You already know a few ways to do that. Assuming we'd eventually make it dependent on the player's presence, we would still need to know how to keep it swinging, and that's where physics--the Constant Force component--comes into play. Let's add one to our board parent. That's where all the action is. Remember, the board is just going along for the ride.
So we will select our board parent, go to Component > Physics, and way down at the bottom, we will find Constant Force. In the Inspector, we can see that we've got Force and Relative Force. The first is global coordinates. So if you had a bunch of physics objects that were going to be affected by wind, you'd use this one. Relative would be useful for pushing an object the direction it was facing.
We're going to use Force. Let's open it up. If I check my scene gizmo, it looks like I need to use the Z direction. Positive values go one direction and negative ones go the opposite. In our Scene view, our Z is on the right-hand side, but we need our wind to blow to the left, so we're going to need to use a negative value in our Z parameter. So back in the Inspector, in the Constant Force component, I'm going to type in a -1.
Before we hit play, let's go ahead and fix one thing. Our cube falls, so in the Inspector, in the Rigidbody, let's tell that guy to be Is Kinematic. Now we are ready to click play and check on our wind. So let's select our board parent again and expose the Constant Force parameters in the Inspector and hit Play. Now you can see our board swinging. You might want to try increasing the force to see what reaction we get.
Okay, let's go ahead and exit play mode. The next parameter in the Constant Force is Torque. Torque is rotation. We're going to go ahead and add a Constant Force to the original cube, Cube1, and we'll try Torque on it. So Component > Physics > Constant Force. This time we didn't add a Rigidbody first, but because we added Constant Force, one was added for us.
And let's set the Torque, the Y parameter-- since that's up in the world--to about 50. Now there's one more thing we need to know. According to the docs, never have transforms and physics controlling an object at the same time. That means we need to disable the rotation script on this cube before we test. And we can just turn it off or we could right-click and say Remove Component.
Now we'll click play, and the original cube is happily rotating. If we left it going for a while, it might wander off the board, so we're going to try something else. Exit play and to keep him from leaving town, we need to go up to his Rigidbody, open Constraints, and now we can freeze his position to keep him from going anywhere but spinning around.
In case you're wondering, when a character is turned into a rag doll, all the objects were animated by keyframe animation and they already had Rigidbodies set to Is Kinematic. They're unchecked dynamically and the keyframe animation turned off to allow the character to tumble into a heap of bones. Okay, since they're pretty important, let's do a little recap on physics rules. Number one: objects that have colliders and are transformed by other than physics need to have a Rigidbody with Is Kinematic checked.
Two: don't mix active physics and transforms at the same time. Three: don't have parent and child Rigidbodies together and use joints to create hierarchies. And four: never scale the parent of a Rigidbody. Remember, children inherit the transforms of their parents.
Author
Released
7/19/2012- Understanding game and level design theory
- Organizing your project in Unity
- Creating and transforming objects
- Setting up the geometry
- Painting in terrain, textures, and trees
- Adjusting the render settings
- Importing terrains
- Creating a first-person controller
- Building projectiles with JavaScript
- Creating materials and shaders
- Lighting the game
- Working with cameras and multiple views
- Animating characters and assets
- Creating fire with particle systems
- Managing the GUI (graphical user interface)
Skill Level Beginner
Duration
Views
Related Courses
-
Game Character Creation in Maya
with Chris Reilly2h 58m Intermediate
-
Introduction
-
Welcome55s
-
Unity basics1m 8s
-
Using the exercise files1m 29s
-
-
1. Exploring Unity 3D
-
Exploring the interface4m 28s
-
Organizing your project8m 12s
-
Exploring Scene view3m 14s
-
Navigating Scene view2m 52s
-
Creating objects7m 38s
-
Transforming objects8m 16s
-
-
2. Exploring the Terrain Editor
-
Painting the topography3m 56s
-
Painting trees and forests4m 56s
-
Painting detail meshes5m 4s
-
Adjusting terrain settings3m 23s
-
3. Creating the Environment
-
Publishing project settings3m 37s
-
4. Introducing Unity Scripting
-
Exploring Unity scripting3m 34s
-
Using variables11m 46s
-
Discovering functions4m 10s
-
Looking at function syntax3m 44s
-
Printing to the console8m 28s
-
Scripting basic functions7m 12s
-
Combining transforms5m 27s
-
Setting transforms8m 34s
-
-
5. In-Game Scripting
-
Raycasting6m 56s
-
Building timers7m 8s
-
Creating a simple projectile13m 16s
-
Refining the projectile5m 32s
-
Sending messages3m 38s
-
Reacting to messages4m 50s
-
Juggling Play and Edit modes7m 33s
-
Suppressing input8m 2s
-
6. Working with GameObjects and Components
-
Creating GameObjects6m 14s
-
Understanding components5m 3s
-
Using colliders for barriers7m 15s
-
Using colliders for triggers4m 28s
-
Exploring physics7m 15s
-
Making cloth9m 56s
-
Working with wind zones7m 50s
-
Using an audio source6m 14s
-
Creating a sound zone5m 34s
-
Adding audio effects6m 31s
-
-
7. Exploring Prefabs
-
Creating and reusing prefabs8m 11s
-
Using prefabs with arrays5m 28s
-
Creating particle systems6m 58s
-
Refining particle systems5m 30s
-
Combining particle systems7m 10s
-
Upgrading weapons6m 15s
-
Exploring water effects7m 53s
-
-
8. Using Imported Assets
-
Importing static objects12m 36s
-
Manipulating textures5m 42s
-
Handling multiple materials5m 42s
-
Animating UVs8m 27s
-
Tracking objects with LookAt5m 45s
-
-
9. Understanding Lighting
-
Investigating ambient light2m 21s
-
Looking at light types3m 13s
-
Exploring shadows5m 23s
-
Baking lighting with Beast8m 16s
-
Experimenting with Beast7m 42s
-
Baking the game scene4m 20s
-
Creating lighting effects6m 24s
-
Adding a flashlight9m 20s
-
-
10. Keyframing Animation
-
Using the Animation view9m 53s
-
Animating transparency7m 12s
-
Keyframing events6m 28s
-
Avoiding keyframing pitfalls5m 27s
-
11. Animating Skinned Meshes and Controlling Characters
-
Importing skinned meshes9m 42s
-
Dynamic parenting6m 44s
-
-
12. Working with Cameras and Layers
-
Introducing cameras4m 53s
-
Managing multiple levels7m 34s
-
-
13. Creating Game GUIs
-
Working with the Unity GUI10m 31s
-
Using GUI skins6m 30s
-
Introducing fonts and styles5m 56s
-
Scripting in-game menus3m 44s
-
Hooking up an in-game menu5m 20s
-
Creating custom cursors8m 42s
-
-
14. Extra Techniques and Features
-
Creating fade transitions5m 34s
-
Setting AI pathfinding9m 56s
-
-
Conclusion
-
What's next1m 13s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Working with physics components