This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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...

Godot version 3.4.2
in Engine by (12 points)

Please log in or register to answer this question.

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.