19.9 C
New York
Sunday, August 3, 2025

3d – Instantiated little one scene doesn’t rotate with the guardian as pivot


Model 4.4

I’m beginning to be taught Godot by making a recreation during which my ‘Participant’ scene is instantiating and including a ‘Ball’ scene as its little one on beginning the sport. I place the Ball at a distance from the participant. The ball is transferring together with the participant however not rotating with the participant because the pivot.

Participant scene:

Ball scene:

Ball scene

participant.gd:

extends CharacterBody3D
@export var velocity = 14
@export var sensitivity = 0.008
@export var ball : PackedScene 

var target_velocity = Vector3.ZERO

func _ready() -> void:
    var ballPos = $Rig.place
    ballPos.z += 5
    inst_ball(ballPos)

func inst_ball(pos):
    var occasion = ball.instantiate()
    occasion.place = pos
    add_child(occasion)


func _physics_process(delta: float):
//  Motion code
    var route = Vector3.ZERO
    if Enter.is_action_pressed("move_fwd"):
        route.z += 1
    if Enter.is_action_pressed("move_bwd"):
        route.z -= 1
    if Enter.is_action_pressed("move_left"):
        route.x += 1
    if Enter.is_action_pressed("move_right"):
        route.x -= 1
    if Enter.is_action_pressed("move_up"):
        route.y += 1
    if Enter.is_action_pressed("move_down"):
        route.y -= 1

    if route != Vector3.ZERO:
        route = route.normalized()
        route = $Rig.global_transform.foundation * route

    target_velocity = route * velocity
    velocity = target_velocity
    move_and_slide()

func _input(occasion: InputEvent) -> void:
    if occasion is InputEventMouseMotion:
        rotation.y -= occasion.relative.x * sensitivity
        rotation.x += occasion.relative.y * sensitivity

Recreation when began:

Game when started

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles