Is there an equivalent in GDscript of fromtorotation

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

Have you tried look_at()? If you pass the vector of where you clicked, this should work.

1 Like

You can create a quaternion with exactly these arguments:

Quaternion(arc_from: Vector3, arc_to: Vector3)

Quaternion. Ive not worked with quaternions before, it just sounds the same so i think this should be what you are looking for, but yeah look_at() ist way simpler

2 Likes

Thankyou for answering my question so quickly. I will give them a try :+1: I do like how helpful the godot community is.

3 Likes