Topic was automatically imported from the old Question2Answer platform.
Asked By
morningkingdom
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.
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.
Bubu | 2021-04-29 01:48
yes thats exactly what i am trying to do.
spheres will snap the locations on the circle path.
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 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)
look_at(translation,Vector3.UP)