wrong 3d collision with blocks at same Y level

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

So I have a basic cube scene as ground, it is just a basic static body cube with a basic cube collision on default and cube mesh.

through script, I place them on the world like that

var floor01 = preload("res://Floor01.tscn")

func _ready():
	newFloor(0, -1, 0)
	newFloor(1, -1, 0)
	newFloor(2, -1, 0)

func newFloor(x, y, z):
	var floorTile = floor01.instance()
	add_child(floorTile)
	floorTile.translate(Vector3(x * 2, y * 2, z * 2))

The problem is when I try to move between them, some times it pass through, other it get stuck like they were miss aligned.

I have tried:

  • change the layer, ground on layer 1 with no mask), player on layer 2 with mask on layer 1.
  • change the collision shape on the ground from the cube to convex shape with 8 points as a cube coordinates ([-1,-1,-1], [1,-1, -1]…)
  • change the player collision box from cylinder, to box, to sphere. As a sphere, it can pass most of the time, but you get a small change in direction, like it bumped in something.

Sure I could just make one big floor with the same size as the 3 I have placed, but at some point I still need to load and add more rooms next to it, at the same Y level as a flat floor.

It shouldn’t be that difficult, I imagine I’m missing something very basic here :(…

Made some changes that seems to fixt it.
There is how it looks like now

func newFloor(coord):
	var floorTile = floor01.instance()
	floorTile.set_process(false)
	floorTile.set_physics_process(false)
	floorTile.visible = false
	add_child(floorTile)
	floorTile.global_transform.origin = coord + offset
	floorTile.set_process(true)
	floorTile.set_physics_process(true)
	floorTile.visible = true

sworn | 2022-01-09 04:28

:bust_in_silhouette: Reply From: DaddyMonster

Static bodies are designed to be used in conjunction with rigid bodies and, as the name suggests, are for objects that don’t mode. Directly moving them will result in undesired behaviour as you wrestle for control with the physics engine.

If you want to translate objects then use KinematicBody instead. If you want collisions then use either the built in move_and_slide() or move_and_collide() in _physics_process(), provide it with a velocity Vector3 and you’ll get the desired behaviour.

well that is not very useful. Although I didn’t explained it so not very useful either.

Let me rephrase it.

So I have a object (cylinder), supposed to be a barrel, which is a rigid body. Than I want to see how well it is interacting with the ground, stickness, mass, etc. So I Apply a central force to it like

apply_central_impulse(-get_transform().basis.xform(dir * 0.15))

where “dir” is a Vector3, as one should do to use the physics engine.

This works as it should work, on a giant flat world.

Now, my ground tiles are procedure generated, and I’m placing them one by one.
The ground tiles is a static body.

The problem is, when I place the ground it keeps like an edge or some round errors between them, and the object get stuck.

I was expecting it to just works and the barrel just slides/roll over the intersection between two ground tiles, as it is the same scene placed side by side, with the same Y level, and all have flat positions in the 3D coordinates

I don’t see the point of using KnematicBody and have to remake all the physics for all objects in the world, even less for a static ground. Isn’t that the purpose of the rigid body?

From your comment “want to translate objects” I would imagine that I’m placing the ground tiles with the wrong function, since I’m using translate in

ground.translate

I don’t want to move any ground, I’m just placing it on the fly. So maybe a better way to place the static body on the world and have it be placed precisely without messing with the physics engine some how, any ideas on that?

sworn | 2022-01-08 15:33