Unfortunately, I do not think it is possible to change the GridMap node so that it snaps on a sphere without editing the C++ code. There should be a way to snap objects to a sphere through code, but I haven't done it myself and Google searches are not yielding helpful results.
I think the code for keeping an object on the surface of a sphere would look something like this (untested):
tool
class_name Spatial_On_Sphere
extends Spatial
export (NodePath) var path_to_sphere setget _sphere_path_changed
var sphere
export (float) var sphere_radius = 2
export (bool) var snap_position_to_sphere = true
func _ready():
if path_to_sphere != null:
sphere = get_node(path_to_sphere)
else:
sphere = null
func _physics_process(delta):
if snap_position_to_sphere == true:
if sphere != null:
var direction_vector = (sphere.gobal_transform.origin - global_transform.origin).normalized()
direction_vector = direction_vector * sphere_radius
global_transform.origin = sphere.global_transform.origin
global_transform.origin += direction_vector
func _sphere_path_changed(new_value):
path_to_sphere = new_value
if path_to_sphere != null:
get_node(path_to_sphere)
I added a few extra things, like tool
and the ability to turn the snapping on/off, but I have no idea if the script will work and there is probably a better way to do it. Hopefully it helps give an idea on how it could be achieved though.
I'll keep my eyes open for a better solution and will post if I find something.
(Side note: Welcome to the forums!)