In this tutorial we will learn how to create a fake hole in the ground, a hole that actually doesn’t exit physically in the mesh but it function as a hole !
Why we need a fake hole, why not just simply tell the 3d artist to create a hole in the mesh with proper physic collisions and we call it a hole ?
A fake hole is useful when the hole is an element of gameplay, and we want to give the level designer the freedom to put it wherever he sees it fit, depending on the requirements of the level and gameplay.
Casual Game Lighting is a material function with a collection of lighting features like fog, diffuse, ambient lighting, and specular lighting. It’s made for anyone who wants to make a beautiful and appealing casual (or hyper casual) mobile games. It will make your game looks on mobile devices exactly the same way it looks in the editor.
– Marketplace Link: Click Here
– Documentation and how to use it: Link
Meshes we need
What we will need:
- Hole (cylinder) with normals inverted
- Hole mask (Top cirecle)
- A ring or the any object to hide hole edge
We will also need an additional mesh for collision, I will explain how we will use it later:
Now, export meshes and import them in unreal engine and lets make a blueprint for the hole.
Create a blueprint BP_Hole of type Actor, and add these component:
Disable collision for HoleMesh and HoleMask:
Hide HoleCollision component as we don’t need it to be visible:
Drag and drop hole blueprint in the level:
Now the hole is in the level, Let’s add the MAGIC !
Select HoleMaskMesh compoenent, then, in Lighting section uncheck CastShadow, expand Rendering section to uncheck Render in Main Pass and Render in Depth Pass, lastly check CustomDepth Pass:
The hole look like this now, nothing interesting yet right !?
Now we will work on the material applied to the ground.
Before changing the material, let’s explain what we did recently: We prevented the hole mask mesh from being drawn in the main pass and draw it only in a custom depth buffer:
We will use the custom depth buffer as an input mask for translucency of the ground.
Select ground material and set blend mode to Translucent, also set Lighting mode in translucency section to Surface Translucency.
Add these nodes to the material of the ground (or the surface that will have the hole):
Some couple of things we need to do.
Select HoleCollision mesh asset and remove any collision, set Collision Complexity to “Use Complex Collision As Simple”:
Open Project Settings > Collision: Add new object channel, name it Hole, set default response to ignore.
Add new preset with settings like in the image bellow:
When the player is in near the hole (overlap the hole sphere collision) we will change his collision preset from Pawn to Pawn_Hole, as you can see Pawn_Hole preset ignore WordStatic and WorldDynamic channels for ground, and collide with the hole object, so when player step in the hole he will fall in it !
Add the tag “HOLE” to the hole actor blueprint.
Lets add some nodes to the player blueprint.
Add these nodes to your player blueprint:
Last touch, add a new static mesh component to the hole blueprint to add a hole ring to hide the edge:
Looks nice ! Let’s test this out…
That’s all folks, I hope I didn’t miss anything ! If you have any question please leave me a comment.