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 baby on beginning the sport. I place the Ball at a distance from the participant. The ball is shifting together with the participant however not rotating with the participant because the pivot.
Participant scene:
Ball scene:
participant.gd:
extends CharacterBody3D
@export var pace = 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 course = Vector3.ZERO
if Enter.is_action_pressed("move_fwd"):
course.z += 1
if Enter.is_action_pressed("move_bwd"):
course.z -= 1
if Enter.is_action_pressed("move_left"):
course.x += 1
if Enter.is_action_pressed("move_right"):
course.x -= 1
if Enter.is_action_pressed("move_up"):
course.y += 1
if Enter.is_action_pressed("move_down"):
course.y -= 1
if course != Vector3.ZERO:
course = course.normalized()
course = $Rig.global_transform.foundation * course
target_velocity = course * pace
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: