dragging objects in 3d environment doesnt work as expected

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

I am trying to build something in 3d environment which allows player to grab objects and swipe them across a table i have managed to make node responsive and move upon click yet not as i desired.I have used an input event on a collision shape to detect grabbing and moved on to parent node to cast a ray and determine the cursor position to move it on that object.

this is my code for the object which is being dragged:

extends Spatial
var beingdragged=0
signal dragme
const ray_length = 10
func _ready():
func _on_RigidBody_input_event(camera, event, click_position, click_normal, shape_idx):
	if (event is InputEventMouseButton):
		var clickZone=get_node("./RigidBody")

and here is the code where i cast ray to determine cursor location and do certain translations.

extends Spatial
var laser_color = Color(.867, .91, .247, 0.1)
const  ray_length = 200
var dragGoingON
var intersection
func _ready():


func _on_Clam_dragme():
	print ("now we can handle ray casting operations")

func _on_StaticBody_input_event(camera, event, click_position, click_normal, shape_idx):
	 if (event is InputEventMouseButton):
        var clickZone=get_node("Clam/RigidBody")
	 if(dragGoingON == 1):
        var from = camera.project_ray_origin(event.position)
        var to = from + camera.project_ray_normal(event.position) * ray_length
        var space_state = get_world().direct_space_state
        var result = space_state.intersect_ray(from, to)
        var clamUnderControl=get_node("Clam")

When i use this snippet object locks to cursor but allways stays far in a far location random at each play state.

Thank you for reading.

Hey um, could you reformat your question better? It’s a little hard to read.

To format multi-lined code, you must skip a line after the last one, then start with four spaces.

One space

Two spaces

Three spaces

You must make sure the subsequent lines of code have
at least four spaces as well.

Mono fonts are best used with a single line of code or better yet, just a property, function or variable name.

SIsilicon | 2018-11-17 15:15

Thanks for the format tips i will keep them in mind next time i post a question or answer.While waiting for approval i have resolved the issue and i don’t need to ask this question anymore thank you in advance.

pnptr | 2018-11-17 22:08

updated original post for better looking

volzhs | 2018-11-17 23:45