Wednesday, March 11, 2026

Methods to transfer characters and RigidBodies "alongside totally different curved platforms"?


Within the GIF, the sport (Klonoa Door to Phantomile) is just like a side-scrolling recreation:

Methods to transfer characters and RigidBodies "alongside totally different curved platforms"?

And on this recreation now we have some traits:

  • Actors may be the participant, enemies, NPCs, projectiles, objects.
  • On every platform, the actors ought to be restricted to shifting left and proper solely, however shifting in line with doable curves on the present platform.
  • A platform can result in totally different different platforms.
  • Leaping from platform 1 (flooring 1) to platform 2 (flooring 2) will make the character observe the platform path of flooring 2.
  • Falling from one flooring to a different ought to make the actor transfer alongside the platform of the ground they fell from.
  • Collisions between actors ought to have an effect on motion (similar to in conventional platform video games).

Within the GIF, the character follows no less than 3 platforms:

  1. Preliminary platform, which is the primary flooring (lowest flooring).
  2. The participant solely reaches the second platform (second flooring) when launched, which they’ll additionally keep away from.
  3. On the finish of the second platform, the participant falls onto a platform that was beforehand hidden behind the surroundings.

The query is not nearly shifting left and proper; that is technically easy. The query is what’s within the title: methods to transfer characters and RigidBodies "alongside totally different curved platforms"? In different phrases, methods to work together with or change the character’s platform.

My preliminary thought is to make use of Path3D to signify the curves on the platforms, and swap between totally different Path3Ds because the actor collides (utilizing Area3D or RayCast) with one other platform, and the actors’ motion will likely be calculated with Path3D and Curve3D, for instance (hypothetical code):

extends CharacterBody3D
...

func _physics_process(delta: float) -> void:
    if not is_on_floor():
        velocity += get_gravity() * delta
    elif Enter.is_action_just_pressed("player_jump"):
        velocity.y = JUMP_VELOCITY

    var input_dir := Enter.get_axis("player_left", "player_right")
    var path := (remodel.foundation * Vector3(input_dir, 0, 0)).normalized()

    if path:
        velocity.x = path.x * SPEED
        velocity.z = path.z * SPEED
    else:
        velocity.x = move_toward(velocity.x, 0, SPEED)
        velocity.z = move_toward(velocity.z, 0, SPEED)

    velocity = get_velocity_from_current_path(velocity)

    move_and_slide()

On condition that get_velocity_from_current_path(...) is a hypothetical code, I’d in all probability should calculate the following location utilizing Path3D and Curve3D:

func get_velocity_from_current_path(velocity: Vector3) -> Vector3:

    ...

    var native := current_path.to_local(participant.global_transform.origin)
    var offset := current_path.curve.get_closest_offset(native)

    ...

Is that this ideally suited, or ought to I do it one other approach (with or with out Path3D) in order that the character can work together with totally different curved platforms in mounted instructions?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles