Create player for 2D game

magarcanmagarcan Posts: 14Member

I've just started a simple 2D game for learning. Trying to define my player, I've some doubts about what Collision Objects should use. First of all I don't need physics, just collision detection.

I've taken a look to these:
https://docs.godotengine.org/en/3.0/tutorials/physics/physics_introduction.html
http://kidscancode.org/blog/2017/02/godot_101_05/

So I can use Area2D, KinematicBody2D even StaticBody2D.

How do you know which one to use?

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 1,049Admin

    I'd say it depends on what your player will be able to do, and how you want to go about implementing it.

    If you only need to detect collision bodies with the player then I'd suggest using a Area2D node. The Area2D node will allow you to know if another collision body has entered the area, but it will not do anything to said collision body. So for example, unless you do something when you detect a collision, the player will be able to go through solid objects like walls by default.

    If you want to collide with other physics objects and move them on collision, then I'd use either a KinematicBody2D or a StaticBody2D. Personally for a player I'd use a KinematicBody2D node, as it has several handy functions for moving a around and has functions for detecting which side a collision occurred at.

    Without knowing what you're project will need it is hard to say, but the most common node to use for a player, at least as far as I know, is the KinematicBody2D node. It is easy to use, collides with other objects, and there are several examples of how to use it online. That said, if you do not want to collide with other objects, or you want to handle what happens when the player collides yourself, then maybe you would want to use an Area2D node instead.

    Hopefully this helps! :smile:

  • magarcanmagarcan Posts: 14Member
    Answer ✓

    So...
    KinematicBody2D for player, enemy…
    StaticBody2D elements in the scenary
    Area2D is similar to Triggers in Unity 3D

  • TwistedTwiglegTwistedTwigleg Posts: 1,049Admin

    @magarcan said:
    So...
    KinematicBody2D for player, enemy…
    StaticBody2D elements in the scenary
    Area2D is similar to Triggers in Unity 3D

    Yup, pretty much!

  • SparrowSparrow Posts: 15Member

    This post is the best :)

Sign In or Register to comment.