The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Hi, i have a circle path and spheres as a child so that they can follow the path and stay on the path.

i want to drag the spheres on the path while they will still say on the circle path, and i thing i can do that with raycasting from camera but, what im not sure is, can spheres still stay on the path?

and is pathfollow3d offset properties can get equal with the return value of the raycasting.

or is there any diffrent approach for this?
generaly what im trying to do mostly this.

-a static circle path,
-touch-drag inputs(for android bdw)
-3d meshs on the path follow the touch drag inputs and stay still on the path.
i was thinking how can i solve this and find the follow path node and think of the raycasting from camera, but not sure if its work and not sure if there is a better way to solve this.


Godot version 3.2.2 stable
in Engine by (98 points)
edited by

Would you like to make the spheres snap their location to the circle? This is something that I made way back when I needed to get the closest point to a path, works in 2D and 3D.

yes thats exactly what i am trying to do.
spheres will snap the locations on the circle path.

i did reach the points data with this:

orb_2_point= $Path_node.curve.get_closest_point($PathFollow/MeshInstance.global_transform.origin)

i think i have some idea right now and i will try them out on this weekend, if i can get any succes i will update this topic and share...


1 Answer

+2 votes
Best answer

This is the method I used. Snapping the nodes to their positions was easy using a single Path node:

$Sphere.translation = $Path.get_curve().get_closest_point($Sphere.translation)

by (298 points)
selected by

Well thank you for care. I made something today, and almost reach what i want to do thank you for clue bro realy help me out. This is outcome right now,

-make sure that paths translation is zero.
-make sure sphere's face is looking at the local -z axis.
-add a little bit more points for the path. so that shphere can look around more sensitive angles.

this is path:



this is nodes:

this is touch screen script for drag and drop position data:

extends Node2D

var current_drag_pos = Vector2()
var can_drag = false
var go_intepolite = false

func _input(event):

    if event is InputEventScreenTouch:
        if not event.pressed:
            can_drag = false
            go_intepolite = true

    if event is InputEventScreenDrag:
        current_drag_pos = event.position
        can_drag = true
        go_intepolite = false

this is raycasting and interpolite to do closest path point:

extends MeshInstance

onready var camera_node_for_ray = get_parent().get_parent().get_parent().get_node("camera_for_raycast")
onready var get_touch_data = get_parent().get_parent().get_parent().get_node("touch_drag_script")
const ray_length = 10000
var result

onready var path1 = get_parent().get_parent().get_parent().get_node("Path")

func _process(delta):
    global_transform.origin.y = 0.2

    if get_touch_data.can_drag == true:
        var camera = camera_node_for_ray
        var from = camera.project_ray_origin(get_touch_data.current_drag_pos)
        var to = from + camera.project_ray_normal(get_touch_data.current_drag_pos) * ray_length
        var space_state = get_world().direct_space_state
        result = space_state.intersect_ray(from,to)
        if result.empty() == false:
            global_transform.origin = result["position"]
    if get_touch_data.go_intepolite == true:
        translation = translation.linear_interpolate(path1.get_curve().get_closest_point(translation),0.1)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.