Hi! I’m going straight to the point:
As you can see in this video, when the player (CharacterBody2D) enters the blue zone (an Area2D, children of an interior component of the ship) it is correctly reparented as I programmed. The issue happens at great speed, the player suddenly is tunneling through the interior of the ship and gets ejected to space!
I tried many things to fix this issue: setting the player’s velocity to the ship’s velocity when in the zone (see my comment down there; I should be able to put a video), trying to get physics fps as high as possible, even tried with CCD and basic RigidBodie2Ds. But the issue persists. I saw there was some possible solution with raycast stuff but couldn’t really get something working.
***Feel free to ask for any info you need. A…
Hi! I’m going straight to the point:
As you can see in this video, when the player (CharacterBody2D) enters the blue zone (an Area2D, children of an interior component of the ship) it is correctly reparented as I programmed. The issue happens at great speed, the player suddenly is tunneling through the interior of the ship and gets ejected to space!
I tried many things to fix this issue: setting the player’s velocity to the ship’s velocity when in the zone (see my comment down there; I should be able to put a video), trying to get physics fps as high as possible, even tried with CCD and basic RigidBodie2Ds. But the issue persists. I saw there was some possible solution with raycast stuff but couldn’t really get something working.
Feel free to ask for any info you need. And thanks in advance for the help :D
Ship node structure :
NorikerMKI (CharacterBody2D)
├── StructuralComponentManager (Node2D)
├── InternalComponentManager (Node2D)
├── InteriorManager (Node2D)
│ └── InteriorChassis1 (Node2D)
├── MotionComponent2D (Node2D)
├── InputComponent2D (Node)
└── ShipStateMachine (Node)
Interior Chassis :
InteriorChassis (Node2D
├── Sprite2D
└── RoomArea (Area2D)
└── CollisionShape2D
And the InteriorManager script (tasked of tracking all the interior zones) :
class_name InteriorManager
extends Node2D
var active_zones: Array[InteriorComponent] = []
var original_parent: Node = null
func _ready() -> void:
initialize_interior_zones()
func initialize_interior_zones() -> void:
for child in get_children():
if child is InteriorComponent:
child.room_area.body_entered.connect(_on_zone_entered.bind(child))
child.room_area.body_exited.connect(_on_zone_exited.bind(child))
func _on_zone_entered(body: Node, zone: InteriorComponent) -> void:
if original_parent == null:
original_parent = body.get_parent()
if zone not in active_zones:
active_zones.append(zone)
call_deferred("_update_parent", body)
func _on_zone_exited(body: Node, zone: InteriorComponent) -> void:
active_zones.erase(zone)
call_deferred("_update_parent", body)
func _update_parent(body: Node) -> void:
var target_parent
if active_zones.size() > 0:
target_parent = active_zones.back()
else :
target_parent = original_parent
if body.get_parent() != target_parent:
body.reparent(target_parent)
body.owner = target_parent
print("Player entered : ", target_parent.name)