Werid stuff happing

4.3
https://www.dropbox.com/scl/fi/6xadzw0grjkss0nv0297o/hi1.avi?rlkey=snz4klvp419ecneohd5l0bg6u&st=s8c39ecf&dl=0
it stops randomly.
video its acting werid. I tested the code in another project(bit messy)
https://www.dropbox.com/scl/fi/4sn7zc1cpqwfnplfo6ezy/file2.avi?rlkey=oxxhgsc7ebdl9yjl1csbap5ie&st=096gmw7e&dl=0
this one works
heres the code
start
start

extends Area2D
#gets player node
@onready var player = $“…/CharacterBody2D”
#range number
var range = 500

#gets the child icon node into varbile shortcut
@onready var icon = $ColorRect

#distance keeper from player
var mouse_distance_from_player = 0

#this is to hold player positon
var player_postion:Vector2 = Vector2(0,0)

#varbile to store/save mouse position
var mouse_postion = Vector2(0,0)
#slasher3 distance to player
var self_distance_from_player = 0.0

#for debugging purposes printed out true or flaulse if mouse is outside range
var mouse_outside = true

Called when the node enters the scene tree for the first time.

func _ready():
#if statement to see we could find icon child
if icon == null:
#prints out so we know if did find or not
printt(“icon node not found.”,icon)

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _process(delta):
#calling funtion to keep in player range
keep_in_the_player_range(delta)

#defning function
func keep_in_the_player_range(delta):
setting_varbiles()
#check if mouse is in range
if mouse_distance_from_player <= range:
global_position = global_position.move_toward(mouse_postion,1500*(delta+0.0001))

elif mouse_distance_from_player >= range:

  if self_distance_from_player <= range:
  	   
  	global_position = global_position.move_toward(mouse_postion,1500*delta)

#can be false or true /if this is true the mouse can damge else it can not
mouse_outside = mouse_distance_from_player <= range
#prints out mouse_outside, mouse_position, mouse_distance_from_player
printt(mouse_outside,‘<-mouse outside’,mouse_postion,‘<-mouse position’,mouse_distance_from_player,‘<-mouse distance from player’,“at slasher3.gd”)
#prints player_postion,slasher position
printt(player_postion,‘<-player position’,position,‘self postion’)
func setting_varbiles():
#SETING VARBILES
#gets the player postion
player_postion = player.global_position
#gets the mouse position
mouse_postion = get_global_mouse_position()
#gets the mouse distance to player
#mouse_distance_from_player = player_postion.distance_to(mouse_postion)
mouse_distance_from_player = distance_too(player_postion,mouse_postion)

#get slasher 3 distance to player position
#self_distance_from_player = player_postion.distance_to(global_position)
self_distance_from_player =distance_too(player_postion,global_position)
func distance_too(one,two):
var distance:float
distance=( ( (one[0]-two[0])**2 )+((one[1]-two[1])**2) )**0.5
return distance
end
end

When pasting code make sure to use three ticks to create a pre-formatted block. You can press the </> button or ctrl+e in the forum to create this like so

```
type or paste code here
```

Can you explain what is supposed to be happening in this video/script? And what is going wrong?

it sometimes thinks the distance is too big so it stops(to keep in range)>
I made a custom distance getting system to make sure is not a bug.
The code works in the recreated project totally fine(to check if its the code)
I don’t know why it randomly stops its earthier something to with getting wrong position
heres better version of code

extends Area2D
#gets player node
@onready var player = get_node("/root/Player")
#25887245520
#range number
var range = 500

#gets the child icon node into varbile shortcut
@onready var icon = get_node('Icon')

#distance keeper from player
var mouse_distance_from_player = 0

#this is to hold player positon
var player_postion:Vector2 = Vector2(0,0)

#varbile to store/save mouse position
var mouse_postion = Vector2(0,0)
#slasher3 distance to player
var self_distance_from_player = 0.0


#for debugging purposes printed out true or flaulse if mouse is outside range
var mouse_outside = true

   



# Called when the node enters the scene tree for the first time.
func _ready():
	#if statement to see we could find icon child
	if icon == null:
		#prints out so we know if did find or not
		printt("icon  node not found.",icon)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	#calling funtion to keep in player range
	keep_in_the_player_range(delta)
	
	
#defning function 
func keep_in_the_player_range(delta):
	setting_varbiles()
	#check if mouse is in range
	if mouse_distance_from_player <= range:
		global_position = global_position.move_toward(mouse_postion,1500*(delta+0.0001))
	
	elif mouse_distance_from_player >= range:
	
		if self_distance_from_player <= range:
			   
			global_position = global_position.move_toward(mouse_postion,1500*delta)
	#can be false or true /if this is true the mouse can damge else it can not		
	mouse_outside = mouse_distance_from_player <= range
	#prints out mouse_outside, mouse_position, mouse_distance_from_player
	printt(mouse_outside,'<-mouse outside',mouse_postion,'<-mouse position',mouse_distance_from_player,'<-mouse distance from player',"at slasher3.gd")	
	#prints player_postion,slasher position
	printt(player_postion,'<-player position',position,'self postion') 
func setting_varbiles():
		#SETING VARBILES
	#gets the player postion
	player_postion = player.global_position
	#gets the mouse position
	mouse_postion = get_global_mouse_position()
	#gets the mouse distance to player
	#mouse_distance_from_player = player_postion.distance_to(mouse_postion)
	mouse_distance_from_player = distance_too(player_postion,mouse_postion)
	
	#get slasher 3 distance to player position
	#self_distance_fr om_player = player_postion.distance_to(global_position)
	self_distance_from_player =distance_too(player_postion,global_position)
func distance_too(one,two):
	var distance
	distance=( ( (one[0]-two[0])**2 )+((one[1]-two[1])**2) )**0.5
	return distance

hi added context

You should use “_physics_process” instead of “_process” since you are moving physics-objects. Can you send whats being printed by this script?

I still don’t understand what’s supposed to be happening, what am I to pay attention to in the first video? What is happening with the red and white blocks in the second? Your script has a lot to do with the mouse, what role does the mouse play in this project?

As a writing exercise try to only use proper nouns, no more “it” and “it’s”, instead “Godot icon”, “blue paddle”, “the mouse”, “black and red squares”

1 Like

I quit i started on a new game