Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[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?

Character CollisionShape2d

Character not colliding appropriate

Character colliding as intended

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]

Leave a Reply

Your email address will not be published. Required fields are marked *