invalid get index "rotate" (on base: "null instance"

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ragacakaci

func _unhandled_input(event):
if event is InputEventMouseMotion:
_handle_camera_rotation(event)

func _handle_camera_rotation(event):
rotate_y(deg2rad(-event.relative.y * camera_sensitivity))
payer1.rotate.x(deg2rad(-event.relative.x * camera_sensitivity))
payer1.rotation.x = clamp(payer1.rotation.x, deg2rad(MIN_CAMERA_ANGLE), deg2rad(MAX_CAMERA_ANGLE))

func _get_movement_direction():
var direction = Vector3.DOWN

if Input.is_action_pressed("forward"):
	direction += transform.basis.z
if Input.is_action_pressed("backwards"):
	direction -= transform.basis.z

i dont get it whats the problem here can somvone help me

You’ve asked the same question again, but not answered the comment on the other question. It will make it much easier to answer if you tell us which line is getting the error.

SteveSmith | 2022-11-30 12:07

:bust_in_silhouette: Reply From: SteveSmith

payer1 is null.

when what shoould i do with this??

ragacakaci | 2022-11-30 12:21

Where are you setting payer1?

SteveSmith | 2022-11-30 12:39

i setted it in “map”

ragacakaci | 2022-11-30 12:41

Sorry, that doesn’t mean anything to me. What is “map”? Can you show the code that says “var payer1 = …”

SteveSmith | 2022-11-30 12:42

soo this is the whole script
extends KinematicBody

const MIN_CAMERA_ANGLE = -60
const MAX_CAMERA_ANGLE = 70
const GRAVITY = -20

export var camera_sensitivity: float = 0.010
export var speed: float = 20.0
export var acceleration: float = 13.0
export var jump_impulse: float = 11.0
var velocity: Vector3 = Vector3.ZERO

onready var payer1: Spatial = $Head

func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _physics_process(delta):
var movement = _get_movement_direction()

velocity.x = lerp(velocity.x,movement.x * speed,acceleration * delta)
velocity.z = lerp(velocity.z,movement.z * speed,acceleration * delta)
velocity.y += GRAVITY * delta
velocity = move_and_slide(velocity)

func _unhandled_input(event):
if event is InputEventMouseMotion:
_handle_camera_rotation(event)

func _handle_camera_rotation(event):
rotate_y(deg2rad(-event.relative.x * camera_sensitivity))
head.rotate.x(deg2rad(-event.relative.y * camera_sensitivity))
head.rotation.x = clamp(payer1.rotation.x, deg2rad(MIN_CAMERA_ANGLE), deg2rad(MAX_CAMERA_ANGLE))

func _get_movement_direction():
var direction = Vector3.DOWN

if Input.is_action_pressed("forward"):
	direction += transform.basis.z
if Input.is_action_pressed("backwards"):
	direction -= transform.basis.z
if Input.is_action_pressed("left"):
	direction += transform.basis.x
if Input.is_action_pressed("right"):
	direction -= transform.basis.x
if Input.is_action_just_pressed("jump"):
	velocity.y += jump_impulse

return direction

my player it walks jsut fine but when i get my coursor in debugg it crrashes somthing like that hope you can help me

ragacakaci | 2022-11-30 12:55

This code is different. Instead of payer1.rotate, it now says head.rotate. Where are you setting head? And is there a child node of this node called “Head”?

SteveSmith | 2022-11-30 13:02

i detted it in kinematickbody named payer1

yes there is child called head

ragacakaci | 2022-11-30 13:26

“head” won’t work. It needs to be called “Head”.

SteveSmith | 2022-11-30 13:38