#Global_Position (On base: nil)

39 messages · Page 1 of 1 (latest)

serene kraken
#

This is weird, and I have no idea why it's happening. But in short, every node2d should have this, yes? Why is it doing a nil when it shouldnt.

unreal dew
#

Are you sure target is a valid node?

serene kraken
#

Heads up, I am stoned so please be patient.

#

Well.

#

It's a node_2d

unreal dew
#

Did you print the target?

serene kraken
#

mmm. good idead.

#

I Anchor2d:<Area2D#25702696163>, will follow <null>

#

Yeah, looks like something aint right

#

Target point is my target

#

Which is just a node 2d with a colored rectangle for testing visual

#

Maybe I should manually (as in hard code temporrallrly) get it

#

I did it manually, it's still null.

#

The weird thing is, it worked before I make the Anchor2d a scene

#

but I might of changed more than just that. But regardless, this code is in Target Trigger not in the anchor

unreal dew
#

Do you set the target variable anywhere, because in the screen shot I only see point target and cam anchor

serene kraken
#
extends Area2D
@export var target: Node2D
@export var player: CharacterBody2D
@export var speed = int()
@export var Freeze_Cam = false
@export var lock_X = false
@export var lock_Y = false
var window_size = get_viewport_rect().size
@onready var cam = $Camera
const Accel = 40

##Math shit


var distance_threashold = 60
var target_pos = Vector2()
@onready var distance = global_position.distance_to(target_pos)

# Called when the node enters the scene tree for the first time.
func _ready():
    print("I ",self,", will follow ", target)
    pass # Replace with function body.

# Called every frame. 'delta' is the elapsed time since the previous frame.

# Un commented for ease of viewing
func _physics_process(delta):
    target_pos = target.position
    var mod_speed = speed + distance * delta * Accel
    var camera_speed 
    if distance > distance_threashold:
        camera_speed = 20 + mod_speed * Maths.cubic(distance, 0.5,-2,3,1)
        print("Balls")
    
    print(distance)
    #vind pos
    #dist
    #MOVE MOVE MOVE
    if !Freeze_Cam:
        position = position.move_toward(target_pos, mod_speed * delta)
    pass
unreal dew
#

You never set target to an actual node

#

Only say that it should be a Node2D

#

But don’t give it a node

serene kraken
#

I gave it a node here.

#

Is that not enough, do I need a ini value?

unreal dew
#

? Is the point target the same variable as target?

serene kraken
#

Wait a second

#

yeah it should be.

unreal dew
#

But then why do they have different names

#

That shouldn’t be the case

serene kraken
#

OH MY GOSH

#

I just realized

#

I never set it in the achor after making it a sence

#

Boy, do I got egg on my face.

#

Yeah, again, stoned, lol

#

Thanks for your time though

unreal dew
#

Lol

serene kraken
#

Would you like a thanks in my credits?

unreal dew
#

Nope

#

Its all good