[ad_1]
I used to be attempting to the arrange a tile map for a 2D pixel artwork sport (following a tutorial) and realized that there appears to be a problem / or sth. I’m not conscious of with the best way collisions work.
At any time when my character jumps in -y course up in direction of the block, the collision seems to occur a little bit to early (see footage), which ends up in a really unintuitive expertise. However this solely occurs when approaching the block from -y course, from another course (with various velocity) the character will get as shut as to the block as supposed by the collision’s form.
The identical happens when involving the block as CollisionShape2D, as a substitute of a tile map.
What am I lacking right here?
Right here is the character script:
extends CharacterBody2D
const SPEED = 150.0
const JUMP_VELOCITY = -300.0
const ACCELERATION = 0.25
# This may change, as a consequence of the truth that it is determined by
#the bottom floor or debufs utilized to the character
const AIR_FRICTION = 0.05
const GROUND_FRICTION = 0.6
@onready var animatedSprite2D = $AnimatedSprite2D
# Get the gravity from the venture settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/second/default_gravity")
func _physics_process(delta):
move_and_slide()
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
velocity.x = lerp(velocity.x, 0.0, AIR_FRICTION)
# Deal with Soar.
if Enter.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the enter course and deal with the motion/deceleration.
var course = Enter.get_axis("ui_left", "ui_right")
if course:
set_facing_direction(course)
velocity.x = lerp(velocity.x, course * SPEED, ACCELERATION)
animatedSprite2D.play("Run")
else:
velocity.x = lerp(velocity.x, 0.0, GROUND_FRICTION)
animatedSprite2D.play("Idle")
func set_facing_direction(course):
if(course > 0):
animatedSprite2D.flip_h = true
if(course < 0):
animatedSprite2D.flip_h = false
[ad_2]