Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | dari0us |
Been stuck on this all week. Im very new to godot and its scripting language.
I have a raycast node, that is supposed to change the color of a ball when its colliding.
when i duplicate the ball, it is only unique in its transforms, and upon raycast collision, all the present balls change color, instead of the specific one that its colliding with, which is not what im after.
heres the code:
extends Spatial
var defcolor = Color.black
var eqcolor = Color.green
var selcolor = Color.white
onready var mesh = $RigidBody/MeshInstance
onready var col = $RigidBody/CollisionShape
onready var rig = $RigidBody
onready var raycast = get_node("/root/World/Player/Camera/RayCast")
onready var material = mesh.get_surface_material(0)
func _ready():
material.albedo_color = defcolor
func _process(delta):
if raycast.get_collider() == rig:
material.albedo_color = selcolor
else:
material.albedo_color = defcolor
I believe your material is not private to a certain ball instance, instead it is common to all. Maybe try to create a new material in _ready for every instance and keep a reference to it?
grok | 2020-10-05 17:33