Godot Version
4.6
Question
I have made the switch from unity and am in the process of learning GDscript. I cannot seem to find an equivalent of ‘fromtorotation’ used in unity for GDscript. I have placed the code below to show what I am doing. I instantiate a cube using the normal that places this directly next to the original cube’s normal I clicked on. I am then looking to change the rotation of the instantiated object to face away from the normal I clicked on. Doing this in unity would be Quaternion rotation = Quaternion.fromtorotation(Vector3.forward, hit.normal) # hit being the normal i clicked on. Sadly I cannot seem to replicate this and wondered if anyone had any idea’s. Thankyou in advance for any assistance.
extends Camera3D
const RAY_LENGTH = 1000.0
var temp
@onready var cube = preload("res://cube.tscn")
func _physics_process(delta: float) -> void:
if Input.is_action_just_pressed("Mouse_Left"):
var camera = get_viewport().get_camera_3d()
var mouse_pos = get_viewport().get_mouse_position()
var origin = camera.project_ray_origin(mouse_pos)
var end = origin + camera.project_ray_normal(mouse_pos) * RAY_LENGTH
var space_state = get_world_3d().direct_space_state
var query = PhysicsRayQueryParameters3D.create(origin, end)
query.collide_with_bodies = true
var result = space_state.intersect_ray(query)
if result:
var temp = cube.instantiate()
add_child(temp)
var tempos = result.collider.global_position + result.normal
temp.global_position = tempos