Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | flaae |
After searching around, I think that my KinematicBody is not facing -Z but I have no clue how to fix this.
The KinematicBody’s “Transform” is all zeros for Translation and Rotation Degrees. My code follows:
const RAY_LENGTH = 1000
const ENVIRONMENT = 1
onready var camera = $Camera # Spatial Camera
func _process(delta):
if Input.is_action_just_pressed("movement"): # Right mouse click
var mouse_position = get_viewport().get_mouse_position()
var ray_start = camera.project_ray_origin(mouse_position)
var ray_end = ray_start + (camera.project_ray_normal(mouse_position) * RAY_LENGTH)
var space_state = get_world().direct_space_state
var result = space_state.intersect_ray(ray_start, ray_end, [], ENVIRONMENT)
if result:
var target_position = result.position
look_at(target_position, Vector3.UP)
Edit: I tried changing the KinematicBody’s Rotation Degrees to 90 but it did not solve the issue.