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

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:

主站蜘蛛池模板: 阳高县| 卓资县| 焉耆| 南阳市| 江阴市| 武清区| 神农架林区| 荆州市| 珲春市| 师宗县| 东乌珠穆沁旗| 大兴区| 潼南县| 化德县| 彰武县| 浠水县| 大荔县| 图们市| 柘荣县| 柳河县| 枣阳市| 沙坪坝区| 香河县| 海伦市| 台州市| 年辖:市辖区| 平谷区| 张家川| 北安市| 翁牛特旗| 青浦区| 西青区| 陇川县| 黄骅市| 宜川县| 那曲县| 凤凰县| 无为县| 浮梁县| 称多县| 南江县|