Im struggling for weeks now, idk, tried all kinds of things, but the simple one is holding me back..

So for a test i want to orient the ball with axis to look at camera. Simple right?

Anyways, so heres the setup:
an object camera rotates around - the head
then i have pink ball with axis, when i click on it and move mouse it triggers function (for now).

In the function script i set the ball look at to camera position. The camera position prints out correct but the ball is not looking at camera.

Am i mentally held back or what?

cam position is at 0,0,-4

ball position some random position but rotated at 0,0,0

The function in ball script

World

  • Tomcat and xyz replied to this.
  • kuligs2 For start maybe you should be looking at the camera position not at the minus camera position.

    Tomcat you mean this code?

    	if target_object != null:
    		# Get target position in eye's local space
    		var target_local_position = to_local(target_object.global_transform.origin)
    		var look_at_position = -transform.origin.direction_to(target_local_position)
    		var look_at_rotation = Basis()
    
    		# Calculate look-at rotation and extract X/Y rotation angles
    		if look_at_position.length_squared() > 0.00001:
    			var z_axis = -look_at_position.normalized()
    			var y_axis = Vector3.UP.cross(z_axis).normalized()
    			var x_axis = z_axis.cross(y_axis)
    			look_at_rotation.x = x_axis
    			look_at_rotation.y = y_axis
    			look_at_rotation.z = z_axis
    		var x_rotation = look_at_rotation.get_euler().x
    		var y_rotation = look_at_rotation.get_euler().y
    
    		# Limit rotation angles
    		x_rotation = clamp(x_rotation, deg_to_rad(min_rotation.x), deg_to_rad(max_rotation.x))
    		y_rotation = clamp(y_rotation, deg_to_rad(min_rotation.y), deg_to_rad(max_rotation.y))
    
    		# Apply limited rotation to transform
    		var target_rotation = Basis().rotated(Vector3(0, 1, 0), y_rotation).rotated(Vector3(1, 0, 0), x_rotation)
    		var current_quat = transform.basis.get_rotation_quaternion()
    		var target_quat = target_rotation.get_rotation_quaternion()
    		transform.basis = Basis(current_quat.slerp(target_quat, rotation_speed * delta))

    kuligs2 For start maybe you should be looking at the camera position not at the minus camera position.

      xyz jesus christ...

      wanted to see the Z gizmo arrow pointing at camera and it was pointing the opposite way, now when i changed the gizmo because i thought the forward was in the direction of the Z axis, and took away the minus sign, it works..
      Updated gizmo

      Updated ball with gizmo

      Updated script

      Works