#PhysicsServer3D.body_test_motion margin seems to be behaving incorrectly

1 messages · Page 1 of 1 (latest)

fossil swallow
#

Does anyone know why a call to PhysicsServer3D.body_test_motion with a high margin (0.15) doesn't register a collision but the same call with a low margin (0.0001) does? I would expect it to be the opposite

In the attached picture I have a cylinder walking forward into a wall. direction_test_collides is returning as false but the same test with a smaller margin is returning true (direction_test_collides_no_margin)

cosmic dock
#

margin is used to solve overlaps at the start and end of the motion

#

so the order of operations is:

  1. solve overlaps (with the shape increased by margin)
  2. cast the body
  3. solve overlaps again (with the shape increased by margin)
#

0.15 is a giant margin to be using in 3D physics

#

it's supposed to be numerically insignificant

fossil swallow
#

So with a large margin like that right up on another shape is step 1 pushing the body back farther than my test motion?

#

Its not clear why step 1 is happening at all. The way the documentation is phrased I'd expect flatly more collisions with a larger margin

cosmic dock
#

oh, are you trying to use it like a shape cast?

#

it's not that

#

body_test_motion is meant to be used by character controllers

#

it only registers one collision at a time

fossil swallow
#

Right, I'm working on adding stair stepping to a characterbody3d

fossil swallow
cosmic dock
#

had to reference the source code again to be sure

cosmic dock
fossil swallow
#

I just meant I'd expect it to be catching more of the level

cosmic dock
fossil swallow
#

in the sample code I repeated the same test with a larger and a smaller margin. for any given test I'd expect a larger margin to catch more of the level

cosmic dock
#

to cast a body with a certain margin, you'll want to use the shape cast node

#

which does account for the margin you provide it

#

I believe it uses a method like cast_motion under the hood?

#

update: yep it's cast_motion

fossil swallow
#

I can't use a shapecast node since the directions I need to test aren't known at design time

cosmic dock
#

you can change the direction and transform of the shapecast node and force it to update at any time

#

you can use physics server directly or the node - both work

fossil swallow
#

That seems needlessly cumbersome

#

Is it best practice then to just have a shapecast node hanging off my character to do these kinds of tests

I'm assuming this is the method you're talking about?
https://docs.godotengine.org/en/latest/classes/class_shapecast3d.html#class-shapecast3d-method-force-shapecast-update

Are there any considerations to using the same shapecast multiple times in a single frame or do I need to have as many shapecast nodes as tests I want to run?

cosmic dock
#

this is the method ShapeCast3D uses under the hood

#

using the node just lets you configure the parameters more easily in the editor

fossil swallow
#

Thanks for the information by the way, any frustration I'm expressing is with the engine and not with you or your help

cosmic dock
#

i understand gdskull

fossil swallow
#

I have a quick follow up if you don't mind since you seem very knowledgeable about the physics engine. I've run into issues trying to use the CharacterBody3D methods move_and_slide and move_and_collide in the same frame. It looks like move_and_slide resets the position of the character and move_and_collide doesn't set any of the nice is_on_floor flags

Is there any way to trigger those checks without calling move_and_slide or if not are there any considerations to manually manipulating the velocity and calling move_and_slide multiple times in a frame?

cosmic dock
#

You might be at a point where you should stop inheriting from CharacterBody3D

#

move_and_slide uses move_and_collide once every iteration and is the only function that can update the state of the character body

#

there's a lot of code, but it is definitely possible to rewrite this in GDScript or C#

cosmic dock
#

but once you hit a certain level of complexity it makes more sense to inherit from AnimatableBody3D than CharacterBody3D

#

or any physicsbody for that matter

#

they all have access to move_and_collide (for some reason??)

#

btw move_and_collide is essentially just body_test_motion but more convenient

#

so I'd use that unless you need to set the starting point of the motion

fossil swallow
#

I would but I don't want to actually move the character unless there's a path. Otherwise I can climb walls haha

cosmic dock
#

move and collide has a test_only argument

#

the only difference is that you can't give it a from transform as an argument

fossil swallow
#

True but I have to make 3 tests before actually moving. Up over down