Normalvector Low Poly World: Basic Physics

Now that we have the globe set up and rendering happily it's time to start doing something with it, and getting some physics working.

We need to be a bit imaginative with this as unlike standard game physics where gravity always acts in the same downwards direction here we need it to go towards the center of the globe.

Checking We Have A Collision Mesh

Before we start doing fancy things it's worth making sure we have a collision mesh set up properly.

For the sea it's easy- we don't want things to bounce off the water so open BP_Globe and set the Collision Preset for SeaMesh to "No Collision".

Find a Static Mesh with a collision shape, I'm using the UnitCubeBevelled from Meshes/BasicPrimitives in my Git repo. Drag it onto the game world, position it above your surface, and scale it down so it quite small, then check Enable Physics and Enable Gravity in the Details panel. Position your player start so they have a good view and press Play. If everything's right you should see the shape fall and bounce off the lumps that make up your planet's surface.

If you're not sure then move the item round, maybe copy it a few times. When you end up with a few it's quite easy to see whether the objects are following the shape of the surface, as the image below shows.

Checking collisions work

Create Test Physics Objects

In order to see the gravity working we're going to need to create some objects for them to attract, and have a good

Create a new Blueprint Class with Actor as a parent and called BP_TestPhysicsActor.

Open up the Blueprint editor for BP_TestPhysicsActor and add a Static Mesh, and choose a mesh which you know has a collision shape attached- Again I'm using the UnitCubeBevelled from the Git repo. Make sure Simulate Physics is checked and Enable Gravity is not checked- we don't want to use Unreal's standard gravity here.

Drag a few of these Blueprint Actors out into the game world, scale them so they're a decent size for objects on the world, and position them round the globe. Press Play and… nothing happens.

Nothing Happens

Applying Gravity

Since we now have objects which can be attracted to the globe it's time to turn gravity on.

Go back into the Blueprint editor for BP_Globe and add a Radial Force, call it GravityRadialForce. Set Impulse Strength to zero as this is a continual force rather than a sudden burst, and check "Impulse Vel Change" as acceleration due to gravity is constant regardless of an object's mass.

As we don't want to need to come into the component itself to set the parameters create three new variables, all editable and all under a category of Gravity. The first is a float called GravityFieldStrength with a default of 1000 and controls how strong the gravitational pull is, the second is a float called GravityRadius with a default of 1000 which controls how far objects can be before they escape gravity's pull, and the final one is a boolean called "GravityFalloff" which is a boolean controlling whether we should simulate gravity falling off as we approach the edge of the field.

To use these values create a new function ReconfigureGravity. It can access the variables directly so doesn't need any inputs or outputs. Add this method after the call to Rebuild Globe Surface in both the Event Graph and the Construction Script.

Handling the GravityRadius is easy enough, just call the Set Radius on the GravityRadialForce component and pass in our GravityRadius value.

To have a force of attraction we need to provide a negative value for field strength, but we don't want the user to need to remember to add a minus sign. Because of this we multiply GravityFieldStrength by -1 before passing it into the GravityRadialForce's Set Force Strength.

The Set Falloff node actually needs an enumerated type for its value, but as we're not able to have one as a variable we've instead created a boolean to control which value goes to it. Create a Branch based on the value of GravityFalloff with both True and False leading to Set Falloff nodes, setting it to RF Constant if it was false and RF Linear if it was true.

Reconfigure Gravity BP

Now we have the radial force set up and configured we can press Play and finally… something happens. The cubes move slowly towards the globe's surface, and then collide with it and one another before coming to rest.

We have gravity.

Cubes Attracted by Gravity