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:
extends Spatial
onready var camera = $Camera
onready var hero = $Grafik/PlayerBody/Hector
var velocity = Vector3()
var RayOrgigin = Vector3()
var RayEnd = Vector3()
func physicsprocess(delta):
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
hero.look_at(Vector3(-pos_ray.x,1,-pos_ray.z),Vector3(0,1,0))
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:
Player (Spatial)
Grafik (Spatial)
PlayerBody(KinematicBody)
Hector(the glft file - Spatial)
Collision Shape
Camera
i know ther maybe an esay way but i rly dont find it...