After finishing my FPS movement, I decided to add a basic RigidBody3D, however with Jolt Physics, this happens when CharacterBody3D collides with RigidBody3D, I'm not sure how to prevent this behaviour, also Godot Physics has the same problem but less frequent. How do I fix this?
The issue is the CharacterBody3D if moving too fast off the RigidBody3D gets launched off by the RigidBody3D and the RigidBody3D gets launched off by the CharacterBody3D
I expect the physics to collide normally, canât push because thereâs no programmed logic for that but can collide
What happened is that the CharacterBody3D if moving too fast off the RigidBody3D gets launched off by the RigidBody3D and the RigidBody3D gets launched off by the CharacterBody3D
What triggers the issue:
Set the physics engine into Jolt Physics (yes, Itâs not the default for me somehow.)
Setup a basic Gridmap
Setup a basic RigidBody3D
Setup CharacterBody3D with this script
extends CharacterBody3D
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
const acceleration = 0.3
const sens = 0.003
@onready var camera = $Camera3D
func \_ready() â void:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func \_unhandled_input(event: InputEvent) â void:
if event is InputEventMouseMotion:
rotate_y(-event.relative.x \* sens)
camera.rotate_x(-event.relative.y \* sens)
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-90), deg_to_rad(90))
func \_physics_process(delta: float) â void:
if not is_on_floor():
velocity += get_gravity() * delta
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
var input_dir := Input.get_vector("move_left", "move_right", "move_up", "move_down")
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if is_on_floor():
if direction:
velocity = velocity.move_toward( Vector3(direction.x * SPEED, velocity.y, direction.z * SPEED), acceleration )
else:
velocity = velocity.move_toward( Vector3(0, velocity.y, 0), acceleration )
# $Camera3D/Label.text = str(ground_ray.get_collider(0))
move_and_slide()
Move the CharacterBody3D on top of the RigidBody3D
I did a quick test using your code and it did moving too fast when jump on top of the rigidbody. Iâm not sure myself but it might be logic in the code which repeatedly increase the velocity value through acceleration.
Your CharacterBody3D believes the rigid body is a moving platform, as the rigidbody moves and rotates it will move and displace your character, using collision layers you can set the rigid body to a layer different from the character bodyâs moving platform layers.
I donât think this explains all of the issue in of itself. I think the RigidBody is being pushed by the CharacterBody, causing the moving platform code to go into a feedback loop. This might not be easily fixed with changing collision layers.
If this canât be fixed with changing collision layers to the CharacterBody, then adding a StaticBody to the playerâs feet to interact with the Rigidbodies may be needed. Since StaticBodies donât get affected by physics at all, this should fix the issue. Though, I admit it sounds janky.
That was not the solution, but i found a mitigation
Moving Platform > Upward Velocity = Do Nothing MITIGATES the problem, not ELIMINATES (Mitigation: The player doesnât get launched anymore)
(Criteria for elimination: The RigidBody3D shouldnât get launched anymore)
Floor > Snap Length = 0.0 MITIGATES this even further, still doesnât eliminate because an edge case : hitting the edge of the rigidbody in a certain way will make it launch
Iâve been having the same problem in the game Iâm trying to make and removing the rigidbody3D layer from the âFlor Layersâ in the âMoving Platformâ section of the CharacterBody3D settings does solve the issue of the character being launched, but it doesnât solve the problem of the rigidbody3D being launched.
Meaning, when the character steps off from the top of the box, the box still gets launched, but not the character - which is an improvement but not a complete solution.
I noticed that setting the characterâs âSafe Marginâ to a âbigâ number like 0.1m does fix the box being launched (and so you donât even need to remove the layer from the moving platforms layers because if the box isnât launched, the feedback loop doesnât happen and so the character is also not launched).
However, my game is in 3rd person, and setting the safe margin so high makes the characterâs feet look like they are hovering 10 cm above the ground (because they are doing exactly that, I guess). Then I tried reducing the characterâs capsule height by double the value of the safe margin, so the capsule starts 10cm above the origin of the character. It seemed to work perfectly at first, I could get on the boxes and walk off them and nothing weird happened, and the feet looked like they were touching the floor/platforms. However, I later noticed that if I just jumped without moving horizontally, the player landed on the ground with the feet digging into the ground. So for some reason, if the character is not moving horizontally when it lands on the ground, the safe margin is ignored and so the feet dig 10cm into the ground, so not a good solution after allâŚ
They are right that you want to use delta with acceleration on move_toward, they are wrong about your acceleration being too high.
Currently your SPEED represents 5 meters per second and your acceleration represents 0.3 meters per frame, so low-framerate players will accelerate slower than high-framerate players. An acceleration of ~5 times the speed will reach max speed in ~1/5th of a second, if you are testing at 60FPS multiplying 0.3 by 60 gets you about the same number, try acceleration * delta with an acceleration of 20 meters per second.