Skip to content

Adding Physics and Collisions

Giving the game a more realistic approach.

  • Lesson
  • 2 min read
  • 9 of 20 in this chapter

How do we add physics to our player?

First, click on "Player" under the "Characters" tab in the Assets panel.

Then, on the right side of the screen, you should see under the "Start" component an area labeled "Physics".

image

Next to the "Physics" area, click on the drop down menu and select "Dynamic". What the "Dynamic" setting does to the player is add the forces of gravity to it, so that it can fall down instead of floating in a straight line.

Making sure gravity acts on the player

One key thing to note about the "Dynamic" function is that it only affects the Y-axis because it simply adds gravity, which is a vertical force that pulls objects down.

However, our speed sets the Y-speed to zero, which means that gravity will not move the player at all, because the speed keeps our vertical position static.

To fix this, we need to change the Y-speed of our player so that it has no value, and gravity can have an effect on the player.

image

Let's test the game. Now, we see that the player can actually fall, buuuuuuut the player also falls right through the floor, which kinda makes the floor lose its sole purpose.

How do we make the floor a floor?

In order to make the floor an actual object that our player lands on, we have to go to the "Ground" asset in the Assets panel on the left side of the screen.

Just like what we did for the player, we are going to find the "Physics" area under the "Start" component.

However, this time instead of choosing "Dynamic" in the drop down menu, we will choose "Static". What the "Static" function allows us to do is provide the floor and the ceiling to be physical objects, while not letting them fall due to gravity or get pushed by other assets that have physics enabled.

Test the game now, and you see that the player lands on the floor this time.

Since we have added physics and collisions to our player and the floor and ceiling, let's move on to making our player able to jump!