I am trying to make a 3d chracter look at the mouse and move in facing direction when pressing a key - sounds simple ( and i think it is) - but i dont get it.
the code i use to look at the mouse:
onready var camera = $Camera
onready var hero = $Grafik/PlayerBody/Hector
var velocity = Vector3()
var RayOrgigin = Vector3()
var RayEnd = Vector3()
var space_state = get_world().direct_space_state
var Mouse_pos = get_viewport().get_mouse_position()
RayOrgigin = camera.project_ray_origin(Mouse_pos)
RayEnd = RayOrgigin + camera.project_ray_normal(Mouse_pos) * 100
var Ray_Hit = space_state.intersect_ray(RayOrgigin, RayEnd)
if not Ray_Hit.empty():
var pos_ray = Ray_Hit.position
if i rotate (via look at) the whole scene the camera rotates too and u get an endless spinning around ....
and i cant move and colide on just the model i think ....
nodes in the szene are:
Hector(the glft file - Spatial)
i know ther maybe an esay way but i rly dont find it...