Invalid get index 'orbit_position' (on base: Area2D (').

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

I’m currently following this tutorial by @kidscancode
I’m only at part 1 and I’ve already hit a wall
via this line: transform = target.orbit_position.global_transform

The error shown in the title happens after the object/node ‘jumper’ hits the object/node ‘circle’ upon running the scene.

The root/parent-most node of each scenes colliding that are attached to each of the scripts are of type: Area2D

This is the code of the problem script:

extends Area2D

var velocity = Vector2(100, 0) # start value for testing
var jumpSpeed = 1000
var target = null # if we're on a circle

func _unhandled_input(event):
	if target and event is InputEventScreenTouch and event.pressed:

func jump():
	target = null
	velocity = transform.x * jumpSpeed

func _on_jumper_area_entered(area):
	target = area
	velocity = Vector2()

func _physics_process(delta):
	if target:
		transform = target.orbit_position.global_transform
		position += velocity * delta

This is what it’s hitting.

extends Area2D

onready var orbitPosition = $pivot/orbitPosition
var radius = 100
var rotationSpeed = PI

func _ready():
func init(_radius = radius):
	radius = _radius
	$CollisionShape2D.shape = $CollisionShape2D.shape.duplicate()
	$CollisionShape2D.shape.radius = radius
	var imgSize = $Sprite.texture.get_size().x / 2
	$Sprite.scale = Vector2(1, 1) * radius / imgSize
	orbitPosition.position.x = radius + 25
func _process(delta):
	$pivot.rotation += rotationSpeed * delta

I watched the video version of the tutorial and changed my project settings and everything else accordingly but the result is still the same.

Any ideas/hints to fix this?

Godot 3.1.1

:bust_in_silhouette: Reply From: volzhs

I guess it’s just typo.

you are referring orbit_position in

transform = target.orbit_position.globaltransform

but it’s defined as orbitPosition in

it’s simply orbit_position vs orbitPosition

Thank you so much!

I didn’t know that area from the _on_jumper_area_entered(area) method was actually an object referring to

This really helped! Thanks!

jagc | 2019-05-29 06:10