Can an object with a script, implemented multiple time, be used on it's on and not in the same time of his siblins.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By elfefe

Hey !

Noob here, i can’t find an explication on internet (i don’t know how to search it i think ^^').

I’ve created a scene named “card”, it’s a rigidbody object representing a card. I add to this card a script, in wich i add a method to move the card on click.

So i implement the card multiple time in an other scene named “world”, BUT when i click on a card, all the cards move ! And not only when i click on the card ! Even when i click outside !

A quick video to help you to understand:

I would like to make all the cards move on their on … Can you help me please ?

:bust_in_silhouette: Reply From: Dlean Jeans

Your script is only checking if the mouse is pressed but not whether the mouse is on the card or not. This should work:

From the Node tab, connect the input_event signal of the Card scene to this function below:

func _input_event(camera, event, click_position, click_normal, shape_idx):
	if event is InputEventMouseMotion and Input.is_mouse_button_pressed(BUTTON_LEFT):
		translate(Vector3.UP * .1)

##Thanks you mate ^^

Do you have a good GDScript tutorial to suggest me ?

elfefe | 2019-06-14 19:42

The docs is a good place to start. I read everything back then when I was starting out with Godot. Read things that you think that’s even remotely helpful for you. For example, if you read this page, you’ll find this part that would help you in this problem:

4. If no one wanted the event so far, and a Camera is assigned to the Viewport, a ray to the physics world (in the ray direction from the click) will be cast. If this ray hits an object, it will call the CollisionObject._input_event() function in the relevant physics object (bodies receive this callback by default, but areas do not. This can be configured through Area properties).

I might give the docs another go since lots of things been added and updated since my last read-through a couple of years ago :slight_smile:

Dlean Jeans | 2019-06-15 04:18