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

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:

主站蜘蛛池模板: 登封市| 崇州市| 成武县| 菏泽市| 临汾市| 临沧市| 高青县| 凉山| 平舆县| 宁河县| 壤塘县| 吉安市| 南江县| 临漳县| 武胜县| 榆社县| 安龙县| 屏边| 镇赉县| 介休市| 长岛县| 隆安县| 西藏| 屯留县| 鹤庆县| 尼木县| 宁强县| 泸水县| 越西县| 蓬溪县| 凤冈县| 磐石市| 杭锦后旗| 周宁县| 黄石市| 乌海市| 伊吾县| 虞城县| 安吉县| 句容市| 武清区|