3D Gridmap & Moving, Bouncing / colliding with the edge of every grid

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Christoffer

I have made a gridmap with cubes, i have a kinematic character that uses move_and_slide.
when i run across the map im colliding with every edge of every grid.

the gridmap cubes are of a static body with box collider, i’ve tried trimesh static body.
How do i solve this?
i would prefer not to remove all the collision shapes of every cube and place one large box collider in the main scene. :confused:

Have you tried adding small value to cell_scale? Like setting cell_scale to 1.0001, to eliminate tiny gap in between.

imjp94 | 2020-04-02 10:34

i just tried that, i did not notice any change :confused:

Christoffer | 2020-04-02 11:18

it might have worked, i overlapped them alittle more but then my bevel of the cube dissapeared, so that did not work visually for me. but i increased the collision shape by 0.02 units on every cube so the collision box is now overlapping. i think it worked :stuck_out_tongue:
thank you

Christoffer | 2020-04-02 11:30

:bust_in_silhouette: Reply From: Christoffer

Have you tried adding small value to cellscale? Like setting cellscale to 1.0001, to eliminate tiny gap in between.
commented 7 hours ago by imjp94

:bust_in_silhouette: Reply From: CodeGuru12

For anybody that comes across this question, one solution to this issue (maybe a bit hacky) is to create a RayCast that faces at the ground (so negative y axis). Make sure the ray touches the ground when you are actually on the ground, or this may not work.

Then add this bit of code to your physics_processing function. ‘groundRayCast’ is the RayCast Node.

var vel = Vector3()
var jumpForce = 5.0

onready var groundCast = get_node("groundRayCast")

func _physics_process (delta):

    if groundCast.is_colliding:
	    vel.y = 0

if you have jumping in your game, you could add something like this instead. (Leaving out the x and z movement for simplified code). Make sure you set the vel.y = 0 after the gravity calculation.

var vel = Vector3()
var jumping = false
var groundYPosHistory = 0.0
var signFlip = 0
var isOnFloor = true
onready var groundCast = get_node("groundRayCast")

func _physics_process (delta):

    vel.y -= gravity * delta

    custom_is_floor_hit()

    if ( (jumping == false) and (groundCast.is_colliding()) ):
	    vel.y = 0

    if Input.is_action_just_pressed("jump"):
	    jumping = true
	    vel.y = jumpForce
    elif (isOnFloor == true): 
	    jumping = false

This causes is_on_floor() to act funny when the shaking would occur. So we need an alternate way to detect hitting the floor if you allow jumping

func custom_is_floor_hit():
    # Checks whether player has hit floor after a jump
    # Uses previous  y-position to detect a sign change
    # and player jump input to determine ground has been hit again
    # Relies on gravity forcing the y-position negative when ground hit
    if ( vel.y < 0.0 and groundYPosHistory > 0.0):
        signFlip += 1
    else:
        signFlip = 0
	
    if ((signFlip > 0) and (jumping == true)):
        isOnFloor = true
    else: 
        isOnFloor = false