Set_position() or set_translation()

Godot Version

GoDot 4.21

Question

set_position(newP) , error → Function “set_position()” not found in base self.

im, trying to click and object and hold it untill mouse is released

In which class do you try to use set_position? It looks like that class doesn’t provide a position.

extends Node

func _0n_ridigbody_input_event(camera,event,click_position,normal,shape_idx):
if Input.is_action_pressed(“mouse_click”):
if event is InputEventMouseMotion:
var newP = Vector3(click_position.x,click_position.y,0)
set_position(newP)

pass

That is the issue. Node doesn’t have a position. You would need to use Node2D, Node3D, Control or Window.

1 Like

okay thanks
can you give me some insights if you can
cheer :slight_smile:

extends Node3D

func _0n_ridigbody_input_event(camera,event,click_position,normal,shape_idx):
if Input.is_action_pressed(“mouse_click”):
if event is InputEventMouseMotion:
var newP = Vector3(click_position.x,click_position.y,0)
set_position(newP)

pass

does this do the job
i dont see my object held onto to my cursor/mouse

A few things come to mind:

  • please mark code in your posts as source code (e.g. use the “</>” button)
  • Instead of Input.is_action_pressed(“mouse_click”): use event.is_action_pressed. In most cases it is not a good idea to use Input.is_action_* within _on_*_input_event()
  • You are mixing different coordinate systems:
    • click_position is in global coordinates of the 3D world.
    • Node3D.set_position is in local 3D coordinates relative to its parent node.
    • Vector3(click_position.x,click_position.y,0): I have no idea, what this vector should represent?!

so what im trying is
using the mouse input on clicked at any mesh in my scene unless i unclick it
it should be held on to the cursor