Placing assets with physics
- See also: Physics Toolbar, which contains a beginner-level tutorial on how to use the toolbar, and Physics panel, which covers how to debug and configure collision representations.
This is a short tutorial on how to place assets using in-game physics. This is most useful when you want something to rest "naturally" on an uneven surface (like a wagon on hilly terrain), or when you're placing a lumpy object on a flat surface (like a sack of flour on a countertop).
Normally, you should use the Dynamic Place tool, but sometimes, it is better to use the physics engine.
The location of an object may be different, depending on where the client thinks it is, and where the server thinks it is. Physics is generally handled on the client side, by the Physics plugin, which does not communicate its changes to the server. This is different from other ways to move objects. For example, when an object is moved in the client via one of the tools in the Transform Toolbar, the location is updated on the server. However, if any object "falls" due to physics, its location is not updated on the server, unless you explicitly tell the client to send an update to the server with the new location. This tutorial will walk you through how this works.
You will need the following for this tutorial:
- Properties Panel
- An asset you want to place with physics (if not sure, a generic signpost will work)
- Select the asset you wish to place.
- Either move the object with the Select & Translate Tool, or move your viewpoint so that you have a clear view of it. Ensure that it is selected (you should see a yellow bounding box around it)
- Move the object above the ground and then click away from it to de-select it. The object should stay floating in space and not "fall". This is because it does not currently have physics enabled.
- Select the object
- In the Physics section of the Properties panel, set the PhysicsType property to DYNAMIC.
- De-select the object by clicking away from it. If you have done everything correctly, it should "fall" and hit the surface you want it to collide with, landing in a natural position.
- Do this a few times (lift the object and "drop" it) to get a sense for how it falls. At times, use the Rotate Tool to move the object off-kilter to see how it bounces.
- To see a visual display of the Collision representation shapes:
- Open the Physics panel
- Select the "Visualize Physics Data" checkbox, and ensure that the dropdown menu says WIREFRAME.
- Select the object that you're working with, and ensure that you can see its wireframe. If you cannot, move your view closer, or move the "Visualization Distance" slider on the Physics Panel until you can see its wireframe
- With the signpost selected, in the Properties panel,
PhysicsShape > SIMPLE_SPHERE, and lift and drop the object a few times
- Try the other PhysicsShape options as well, and lift and drop the object to see how it changes
- Note: If you don't see a clear difference in how the object moves, you may wish to try rotating the object to a different orientation, like try to drop it on its "head" in the different modes, and see how the shapes affect which way it falls. For more information on each option, see PhysicsShape.
It is important to understand that when using physics, the position of the object may appear different on the client, than what is recognized by the server. To better visualize this:
- In the Physics Panel, select the checkbox that says "Visualize Server Physics"
- Move the object up into the sky with the Select & Translate tool.
- Now "drop" the object by clicking away from it.
- The object should fall, but the wireframe of the server representation should still be visible in the sky. This is because the new location of the object after "physics", has not been communicated to the server.
- If you move the object with the tool, this new location is communicated to the server, so the wireframe should again synch up with the object. It's only after physics movement (falling, rolling, etc.) that the server location is not updated. This is useful for cases such as setting up rocks ready to fall in an avalanche. The server will know the "pre-avalanche" location of the rocks, and each new player entering the area will see the pre-avalanche location.
- Note: If the wireframe does not seem to be updating right away, simply move your view in the viewport a bit, such as forward and back, to ensure you're seeing the correct wireframe location.
- When you duplicate the object now, by selecting it and pressing CTRL-D, the new duplicated object will appear at the server's memory of the location, not the client's.
- For a dramatic demonstration of this, press CTRL-D several times in quick succession, or just hold it down. Each new duplicated object will appear in the sky, but then be de-selected when the next one appears, so it will fall immediately, or "bounce" off of other objects that are also being created. Keep pressing CTRL-D, and you can get a stream of objects in this way.
- So, how to update the server's idea of where the object is, if you want it to remember where an object has "fallen" or rolled"? To update the object's location on the server:
- Select one of the fallen signposts.
- Tell the server to remember the object's current location, by selecting 'Updated Selected Server Physics' from the physics dropdown menu. The "sky" wireframe that existed before, should now synch up with the current location of the object.
- Congratulations! You just placed an object using physics.
If you have ended up with dozens of the same object because of the CTRL-D exercise, there are multiple ways to delete them:
- Click on each one individually that you wish to delete with the selection pointer, and press DELETE. Or,
- Use the selection pointer to drag a box around all of them and press DELETE. Or,
- In the Assets panel, go to Model > sign_post_demo.gr2, select it, and then in the Instances subpanel, shift-click to select several (or all) of the instances, and then remove them via the Instances Menu link. Or,
- In the Assets panel, right-click the asset and select select "Remove asset". This will generate a couple warning popups, ensuring that you wish to do this.
- Since you are in a test area, it should be alright to remove all instances. Click "Yes".
After the deletion method of your choice, move the view in your viewport a bit, and all of the wireframes of the server representations should disappear.
Working with physics nodes
In building an area, it may be desired to have physics-enabled assets that don't react until a certain condition is met. For example, having a group of rocks at the top of a mountain, which will later fall via an avalanche, but shouldn't fall until after some other condition is met, such as a player being within view of them. This toggling of a group of objects in a physics simulation can be handled via a Physics Node. This node then becomes a parent object to all the "children" nodes for the physics simulation, so that they can be easily toggled on and off as a group.
- Select the signpost
- Create a physics node, by clicking on the physics dropdown meny and selecting 'Create Physics Node'
- A transparent blue sphere should appear in the game world, which is automatically parented to the signpost. You should see a blue line connecting them. (if not, doublecheck that your Filters menu has the Physics category selected)
- If necessary, move the sphere or manipulate your viewpoint so that you can see both the sphere and the signpost
- Using the Select & Translate Tool, move the signpost up to its "start" position
- Notice that when you click away from the signpost, it does not fall. This is because the Physics Node is now controlling whether or not the signpost asset is active in the physics simulation.
- Select the physics node
- In the properties panel for the physics node, set Active to TRUE
- Now, when you select the signpost and then click away, it should fall
- Select the Physics node
- Change the Active property to FALSE
- The signpost should return to its start position
- Tip: To quickly toggle from "True" to "False" in the properties panel, just double-click on the word "Active"