Godot Version
Stable Release 4.5
Question
`
P.S. idk why the Syntax Highlights are broken on this, if somebody can tell me I’ll make the edit so it’s more readable.
So I’ve got a script where I pick up an object, drag it, release click a node to set it down on, that part works fine, but then I want the node it gets set down on to have a variable that decides which nodes the object will be moved to next:
extends Node3D
var path_direction : Array = [$"../position_node_1",$"../position_node_2"]
and the script that does the raycasting and dragging around (minus everything not relevant to the task at hand such as multiple raycast functions)
extends Node3D
var screen_size : Vector2
var card_dragging : Variant = null
var plane : Variant = null
var d_node : Variant = null
var card_acceleration : float
var mouse : Vector2 = Vector2()
const DIST : int = 1000
var exclude_list : Array
var plane_exclude : Array
var inactives_list_exclude : Array
var inactives_list : Array
func _input(event : Variant) -> void:
mouse = event.position
if event is InputEventMouseMotion:
var plane_collider : Variant = raycast_check_for_plane_location(mouse)
if plane_collider:
plane = plane_collider
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
print('CLICK')
print(exclude_list)
var card_collider : Variant = raycast_check_for_card_3d(mouse)
if card_collider:
card_dragging = card_collider
else:
print('RELEASED')
var dungeon_node : Variant = raycast_check_for_dungeon_node(mouse)
if dungeon_node:
d_node = dungeon_node
inactives_list_exclude.append_array([card_dragging.rid])
inactives_list.append_array([card_dragging])
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(_delta: float) -> void:
if plane:
if card_dragging:
var drag_position : Vector3 = Vector3(plane.x/1.6,0.1,plane.z/1.5)
card_dragging.collider.position = drag_position
if d_node:
card_dragging.card_dungeon_address = d_node
card_dragging.card_inactive_state = true
d_node = null
and in the script for the instanced object:
extends RigidBody3D
var card_dungeon_address : Variant = null
var card_inactive_state : bool = false
var card_node_interact : bool = false
var next_node : Variant
#potentially make a custom event here and have it set the
#self.position to a variable so that it doesn't do that every frame.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
if card_inactive_state and card_dungeon_address and not card_node_interact:
next_node = card_dungeon_address.path_direction.pick_random()
self.position = Vector3(move_toward(self.position.x, next_node.position.x,30),-0.15,move_toward(self.position.x, next_node.position.x,30))
if self.position == next_node.position:
print('next noding info:')
print(card_dungeon_address)
print(next_node.position)
#add a colliding check with a dungeon node and make it the new
elif card_inactive_state and card_node_interact:
print('not yet implemented behavior')
else:
print('card inactive state: ', card_inactive_state)
print('card dungeon address: ', card_dungeon_address)
print('card node interact: ', card_node_interact)
but after the card gets set down, it should be inactive and the d_node should have been set, but the prints are showing false, null, false on the card.
`