#Array?

1 messages · Page 1 of 1 (latest)

onyx sable
#

I just copied from this Youtube. https://youtu.be/eGt7ikx7FcQ?si=z1knVuGEdIkl38-v
When I pressed play, the error Array kept popping up.
Whats this mean by "Out of bounds get index '0'(on base: 'array'[Node]')? on 23 line.

On 40 lines, "Invalid get index 'global_position' (on base:'Nil').
Im new in Python and need some help with coding.

Im trying to make a game where my character could walk around with free MouseLook, also combined two Godot codes together to see if its work.

Subscribe and learn more from me about Game Development and Programming!

In this video, we talk about how to make a 3d character controller in Godot 4! We talk about how to do animations and how to handle collisions with the camera!

RESOURCES
Source Beginning: https://github.com/finepointcgi/3D-Movement-Tutorial-Godot-4/tree/Start
Source End: ...

▶ Play video
lusty bramble
#

Out of bounds get index '0'(on base: 'array'[Node]')? on 23 line.
You have an array that you're trying to access, but you are trying to get an item that doesn't exist. To be more precise, you're trying to access the item with index 0. This is the first item, so this means your array is empty.

#

On 40 lines, "Invalid get index 'global_position' (on base:'Nil')
Player is null, meaning it's either empty or doesn't exist.

onyx sable
#

I don't have any kind of a item and I do have a player, but how I can wrote both of codes?

lusty bramble
#

On line 23 you are doing [0], which means accessing the first item in the array get_tree().get_nodes_in_group("CameraPivot").
Based on the error, it looks like that group is empty.

#

On line 40 in the _physics_process() there's nothing that defined player, so that function is unaware of player. It is out of scope.

#

Unless you have defined var player at the top of the script?

onyx sable
#

Yes, I have var player at the top of the script.

onyx sable
lusty elbow
#

Python? This is Gdscript.
Anyhow "on base Nil" hints that it's not getting a reference to player.

Looks like the script is using Node groups for identification.
Make sure your node groups in your editor are the same as the ones in the tutorial and that you've typed the group names right.

onyx sable
lusty elbow
#

5:52 he adds Player into the node group.
6:00 he types in code that makes it get player from the group and explains how [0] gets the first node in the group.

pseudo pine
#

@onyx sable don’t make multiple threads for the same issue at the same time…

onyx sable
onyx sable
lusty elbow
#

I'm assuming that's created somewhere in the tutorial, too.

#

Maybe he adds the animator to it.

onyx sable
#

Yeah he also added AnimationPlayer and AnimationTree. I just combined two codes together to see if its work. So far I got two errors.

lusty elbow
#

Honestly you could probably also just do it through @export but I'm guessing he's teaching about node groups, which are pretty cool, too.

onyx sable
#

@export can be put in node group?

lusty elbow
#

No but if you put it before a var you can assign it manually in editor. It will work as long as the thing is in the scene.

onyx sable
#

Like @export var AnimationPlayer or AnimationTree?

lusty elbow
#

Just like how the @export var sens_horizontal is put up top to be manually changed in inspector, you could use @export var player: CharacterBody3D or w/e and assign it manually in inspector.
But I dunno if he uses groups for other things.

#

It will also break if the thing you put in it gets deleted or w/e, it's not an automatic re-assignment.

onyx sable
#

`I've finally solved my Gscript, but some reason, whenever I moved its started shaking and spinning.

extends CharacterBody3D

@export var player: CharacterBody3D
@export var sensitivity := 1

@onready var CameraPivot = $CameraPivot
@onready var animation_player = $AnimationPlayer
@onready var visuals = $visuals

const SPEED = 60
const JUMP_VELOCITY = 80

@export var sens_horizontal = 7
@export var sens_vertical = 7

Get the gravity from the project settings to be synced with RigidBody nodes.

var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
var lookat
var lastLookAtDirection : Vector3
func _ready():

lookat = get_tree().get_nodes_in_group("ControllerPlayerAnimate")[0].get_node("LookAt")
player = get_tree().get_nodes_in_group("Player")[0]
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
pass

func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg_to_rad(-event.relative.xsens_horizontal))
visuals.rotate_y(deg_to_rad(event.relative.x
sens_horizontal))
CameraPivot.rotate_x(deg_to_rad(event.relative.y*sens_vertical))

func _physics_process(delta):
global_position = player.global_position
$CameraPivot/Camera3D.look_at(player.get_node("LookAt").global_position)
pass

if not is_on_floor():
    velocity.y -= gravity * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
    velocity.y = JUMP_VELOCITY


# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("right", "left", "backward", "forward")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
#
    if animation_player.current_animation != "Idle_Amy":
        animation_player.play("Idle_Amy")
    
    visuals.look_at(position + direction)

    velocity.z = direction.z * SPEED
    velocity.x = direction.x * SPEED
else:
    if animation_player.current_animation != "Amy_Walking":
        animation_player.play("Amy_Walking")
        
    velocity.x = move_toward(velocity.x, 0, SPEED)
    velocity.z = move_toward(velocity.z, 0, SPEED)