#Transform starts bugging out when on a wall
1 messages · Page 1 of 1 (latest)
var point: Vector3 = cast.get_collision_point()
var normal = cast.get_collision_normal()
var offset: Vector3 = normal * ((bb.size.y/2) + 0.01)
var trans = Transform3D(
Basis(quaternion_from_two_points(point, point+offset)),
point
)
var rot = _prefab.transform
var angle = rot.basis.y.angle_to(normal)
var axis = rot.basis.y.cross(normal).normalized()
rot = rot.rotated(axis,angle)
DebugDraw3D.draw_line(point, point + rot.basis.y*2, Color.RED)
DebugDraw3D.draw_line(point, point + main_hand.basis.z * 2, Color.YELLOW)
var fixed = rot.basis.get_euler().y
var fixed2 = main_hand.basis.get_euler().z
var hand_miss = fixed2 - fixed
_prefab.transform = rot.rotated(normal,hand_miss)
_prefab.position = point+offset
DebugDraw3D.draw_line(point, point + normal * 2,Color.BLUE)
print(fixed)
print(fixed2)
print(rad_to_deg(hand_miss))
does anyone have any idea why it spins
so I have updated-ish the script
so basically the issue is that while on flat ground rotation works perfectly
but since rotation is based on the "global basis" it doesn't use the local basis
which means that it cannot properly "allign" it's self
var hand_miss = fixed2 - _prefab.rotation.y
DebugDraw3D.draw_line(point, point + _prefab.basis.y * 2, Color.BLACK)
DebugDraw3D.draw_line(point, point + _prefab.basis.z * 2, Color.BLUE)
print("hand_rotation: %s" % deg_to_rad(fixed2))
print("prop_rotation: %s" % _prefab.rotation_degrees.y)
print("error: %s" % hand_miss)
_prefab.transform = _prefab.transform.rotated(normal,hand_miss)
print("prop_port trans: %s" % _prefab.rotation_degrees.y)
_prefab.position = point+offset
so that leads me to my question. is there any way to make it so the rotation is in basis-orientation
You can use quaternion multiplication to apply surface normal on a local rotation eg.
var angle := (Time.get_ticks_msec() % 1000) / 1000.0 * TAU
var q_normal := Quaternion(Vector3.UP, hit.normal)
var q_local := Quaternion(Vector3.UP, angle)
node.transform.basis = Basis(q_normal * q_local)
node.transform.origin = hit.position + hit.normal * 0.5
so right q_normal will become my up direction right?. and for angle I can plug in my hand rotation to rotate it around that normal direction right?
Yes, that's pretty much it. I just used a simple time based angle because I don't have a vr set to easily control it 😅