Skip to content

tutorial_physics_2d

reduz edited this page Apr 19, 2014 · 29 revisions

Physics & Collision (2D)

Introduction

Our world is made of tangible matter. In our world, a piano can't go through a wall when going into a house. It needs to use the door. Video games are often like the the real world and Pac-Man can't go through the walls of his maze (although he can teleport from the left to the right side of the screen and back).

Anyway, moving sprites around is nice but one day they have to collide properly, so let's get to the point.

Shapes

The base collidable object in Godot's 2D world is a Shape2D. There are many types of shapes, all of them inherit this base class:

Shapes are of type Resource, but they can be created via code easily. For example:

#create a circle
var c = CircleShape2D.new()
c.set_radius(20)

#create a box
var b = RectangleShape2D.new()
b.set_half_extents(Vector3(25,20,10))
Clone this wiki locally