Hi!
First time poster, I'm a novice looking for some help with the use of global_positioning troubles. I've been following various youtube guides to build a Mario clone for fun and am trying to add a Mario style question mark block to my game that may be bumped in to to produce a power up item. I've been using the youtube channel, AJ's Learning Labs - Question Mark Blocks tutorial and am trying to bash his lesson into what I had already built. The tutorial runs functions across two scripts and then pulls in an item with a third script. However when added to my game it gets hung up on pulling the global_postion of the item i wish to be produced from the block.
The Stack Trace log error is:
Invalid set index 'global_position' (on base: 'CharacterBody2d (Bottoms.gd)') with value of type 'Vextor2'
Stack Frames being flagged are:
global.gd:6 - at function: spawn_bottoms
p_block.gd21 - at function bump_block
p_block.gd14 - at function _on_body_entered
My 3 scripts are:
global.gd <-- This script is setup to autoload in the project settings.
extends Node
func spawn_bottoms(pos):
var BottomsScene = load("res://World Objects/bottoms.tscn")
var Bottoms = BottomsScene.instantiate()
Bottoms.global_postion = pos
get_tree().root.add_child(Bottoms)
p_block.gd <-- script for the block | Enter Body node connected on "func _on_body_entered" line 12
extends Area2D
enum State { UNBUMPED, BUMPED }
var state: int = State.UNBUMPED
var original_position: Vector2
func _ready():
original_position = position
func _on_body_entered(body):
if body.is_in_group("Player") and state == State.UNBUMPED:
bump_block()
#Logic for bumping the block
func bump_block():
state = State.BUMPED
$Sprite2D.frame = 1
Global.spawn_bottoms(self.global_position + Vector2(0, -20))
bump_upwards()
var timer = get_tree().create_timer(0.2)
await timer.timeout
return_to_original_position()
#Function to move the block upwards
func bump_upwards():
position.y -= 10 # move up 10 units
#Function to return block to original position
func return_to_original_position():
position = original_position
Bottoms.gd <-- script for item being produce by the block | Enter Body node connected on "func _on_area_2d_body_entered" line 12
extends CharacterBody2D
var speed = 30
var direction = 1
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _physics_process(delta):
move_and_slide()
velocity.y += gravity * delta
velocity.x = speed
func _on_area_2d_body_entered(body):
if body.is_in_group("Player"):
queue_free()
else:
direction *= -1
The game will crash when my character (it is grouped as "Player") jumps up and bumps into the block. If I trace the log back it looks like the issue stems from this line of code in global.gd:
Bottoms.global_postion = pos
But at this point i'm ignorant as to what to do next.
May I please have some help on how to solve this or best proceed🙂
Thanks!!