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.
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 = 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.