0 votes

Hi Godot Experts,

Total beginner at Godot here.

I'm looking to create a 2D isometric game. I was playing around with the existing 2D isometric demo template and noticed the collision mechanics is a little wonky.

When a KinematicsBody2D (the Troll in the case of this demo) collides with the isometric tile, it will slide no matter the situation--even if the KinematicsBody2D is colliding head on to the tile (wall in this case). I would expect when there is a head on collision (i.e. normals are opposite of one another) there should be no sliding at all.

Looking into this issue a little deeper, I followed the tutorial here (https://www.youtube.com/watch?v=KvSjJ-kdGio) for isometric movement and converted the movement of the Troll to move along isometric axis. For instance:

extends KinematicBody2D

# This is a demo showing how KinematicBody2D
# move_and_slide works.

# Member variables
const MOTION_SPEED = 160 # Pixels/second

func cartesian_to_isometric(cartesian):
    return Vector2(cartesian.x - cartesian.y, (cartesian.x + cartesian.y) / 2)

func _physics_process(delta):
    var motion = Vector2()

    if Input.is_action_pressed("move_up"):
        motion += Vector2(-1, -1)
    if Input.is_action_pressed("move_bottom"):
        motion += Vector2(1, 1)
    if Input.is_action_pressed("move_left"):
        motion += Vector2(-1, 1)
    if Input.is_action_pressed("move_right"):
        motion += Vector2(1, -1)

    motion = motion * MOTION_SPEED
    motion = cartesian_to_isometric(motion)
    move_and_slide(motion)

I've also tried changing the Troll's collider from a circle collider to a polygon collider that mimic the wall's collider, but the sliding persists.

Also, even when the movement is normalized, moving when pressing left or right is faster than moving when pressing up and down, so the sliding speed is not consistent even when it happens.

Does anyone know the underlying problem? And if so, can you show me how to fix it?

Thanks for the help. I really appreciate it!

in Engine by (18 points)

1 Answer

0 votes

I'm pretty bad at coding but I think I may have Macgyvered a solution for you until someone with more knowledge comes along.

I think the sliding is just part of how moveandslide works. You could try moveandcollide instead to see if that gives you the desired behavior (just be sure to lower the speed to something like 2 or your character will fly off the screen, or hit a wall at mach3).

As for the normalizing problem, try this instead.

motion = cartesian_to_isometric(motion)
motion = motion.normalized() * MOTION_SPEED
move_and_slide(motion)
by (103 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.