Collision problems

I have a stage with 2 platforms and a lifting platform for moving. I have added NavigationRegion and also NavigationLink3D to all platforms so that the character can get off the lifting platform on each of the platforms.
If I add CharacterBody3D: Base Movement to the character as a script, he moves and interacts with the lifting platform normally.

Next, I added NavigationAgent3D to the character, as well as the code:

extends CharacterBody3D

var Speed = 5
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")


func _ready():
   pass 

func _physics_process(delta):
   if not is_on_floor():
	  velocity.y -= gravity * delta

func _process(delta):
   if(navigationAgent.is_navigation_finished()):
	  return
	
   moveToPoint(delta, Speed)
   pass


func moveToPoint(delta, speed):
   var targetPos = navigationAgent.get_next_path_position() - global_position
   targetPos = targetPos.normalized()

  velocity = velocity.lerp(targetPos * Speed, 10 * delta)
  move_and_slide()

func _input(event):
  if Input.is_action_just_pressed("LeftMouse"):
	var camera = get_tree().get_nodes_in_group("Camera")[0]
	var mousePos = get_viewport().get_mouse_position()
	var rayLength = 100
	var From = camera.project_ray_origin(mousePos)
	var To = From + camera.project_ray_normal(mousePos) * rayLength
	var space = get_world_3d().direct_space_state
	var rayQuery = PhysicsRayQueryParameters3D.new()
	rayQuery.from = From
	rayQuery.to = To
	rayQuery.collide_with_areas = true
	var result = space.intersect_ray(rayQuery)
	print(result)
	
	navigationAgent.target_position = result.position

The idea behind the code is simple: Add the ability to move the character to a selected point with path building via NavigationAgent3D.

The problem itself is that after getting on the lifting platform the character just stays hanging over the void while the lifting platform is already going up and passing through the character.

Is the platform a RigidBody3D or CharacterBody3D? I think those are the only things that can push a CharacterBody around without just telling the Character it should simulate being on a platform (which you could also do, but seems silly).

зображення
This is the structure that is the lifting platform and the script responsible for the movement is attached to parent NavigationRegion3D

I’m also quite curious as to why there’s such a big difference in character behaviour between the standard arrow movement script and the one I’ve attached to the thread? As I mentioned before, in one case the character goes up on the lift normally and in the other case he just falls through.

If you need I can give a link to download the full project.

Your elevator is a StaticBody. You can’t move a StaticBody. It is in the name. Make it a RigidBody (and lock its rotation).

This is a complete project for better understanding. For some reason the platform can’t lift the character.

1 Like

Here you go. Changed the Elevator and Player so they cooperate. XD
https://send.vis.ee/download/bcc600a1d5576e73/#GRk4KUXK2hW-kOjstmWe8A

Why does the character bounce when the platform stops at the top point?

Because its velocity was up, but when it gets back to having gravity, gravity is not as strong as that velocity, so it takes a second to turn around. =P

if feet.is_colliding() and not feet.get_collider() is StaticBody3D:
	velocity.y = min(velocity.y, feet.get_collider().linear_velocity.y)

The character is no longer tossed, but the platform rises very slowly.

Because velocity.y is zero at the start.
I think all you need to do is make the feet ray a bit longer instead.

Alternatively

if feet.is_colliding() and not feet.get_collider() is StaticBody3D:
	velocity.y = feet.get_collider().linear_velocity.y
else:
	velocity.y = min(0, velocity.y)

Since standing on a StaticBody means you’re not gonna move up.

It’s working. Except that the character jerks a bit when lifting.

That im not sure how to fix without redoing a lot of other things…

Okay, that’s enough for now. Thanks for everything.