官术网_书友最值得收藏!

Collision shape

When using Area2D, or one of the other collision objects in Godot, it needs to have a shape defined, or it can't detect collisions. A collision shape defines the region that the object occupies and is used to detect overlaps and/or collisions. Shapes are defined by Shape2D, and include rectangles, circles, polygons, and other types of shapes.

For convenience, when you need to add a shape to an area or physics body, you can add a CollisionShape2D as a child. You then select the type of shape you want and you can edit its size in the editor. 

Add a CollisionShape2D as a child of Player (make sure you don't add it as a child of the AnimatedSprite). This will allow you to determine the player's hitbox, or the bounds of its collision area. In the Inspector, next to Shape, click <null> and choose New RectangleShape2D. Adjust the shape's size to cover the sprite:

Be careful not to scale the shape's outline! Only use the size handles (red) to adjust the shape! Collisions will not work properly with a scaled collision shape.

You may have noticed that the collision shape is not centered on the sprite. That is because the sprites themselves are not centered vertically. We can fix this by adding a small offset to the AnimatedSprite. Click on the node and look for the Offset property in the Inspector. Set it to (0, -5).

When you're finished, your Player scene should look like this:

主站蜘蛛池模板: 义乌市| 安平县| 杭州市| 当涂县| 金坛市| 来凤县| 宜君县| 会理县| 罗甸县| 沈丘县| 南乐县| 上栗县| 吉林市| 娱乐| 于田县| 阿合奇县| 黄大仙区| 西丰县| 大冶市| 乐山市| 阿拉善右旗| 晋州市| 随州市| 南开区| 淮滨县| 元朗区| 延寿县| 乳山市| 清新县| 响水县| 丹棱县| 平湖市| 阿图什市| 乐山市| 丹阳市| 噶尔县| 新宁县| 长治市| 灵台县| 隆回县| 府谷县|