Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Twisted LookAt Bug/Fix

A topic by CLAYMORE_njf created May 31, 2023 Views: 118 Replies: 1
Viewing posts 1 to 2

The LookAt IK modifier can produce unintended results when used on objects that are not meant to rotate around the Y axis due to the modifier defaulting to using basis.Y when rotating the bone transform.  I have attached an example from my project where I am using several LookAt IK modifiers to animate the secondary motion and aiming of my player character.


Unmodified Code:

# The bone_up_dir is defaulted to basis.Y
Vector3 bone_up_dir = twisted_bone.get_reset_bone_global_pose().Basis.y.Normalized();         
twisted_bone.LookAt(target_node.GlobalTransform.Origin, bone_up_dir);

This results in the weapons on the side of my player character flipping at extreme angles instead of pointing directly towards the IK targets as intended

Modified Code:

# Specifying the intended basis fixes the issue
Vector3 bone_up_dir = twisted_bone.get_reset_bone_global_pose().Basis.X.Normalized();         
twisted_bone.LookAt(target_node.GlobalTransform.Origin, bone_up_dir);

The issue is fixed by specifying which basis I want to be the bone_up_dir.  


Proposed Fix/Change:

I don't use C# in Godot and don't really know how to do this, but I think adding an additional export variable that lets you specify the basis you want to rotate around would be a good fix for all cases here.  Defaulting the Y basis would work for a majority of cases, but it doesn't work very well in some edge cases, like mine.

Developer(+1)

Thanks for reporting this issue! Version 2.8.0 adds a new option to allow setting which of the basis directions is being used, which will allow you to fix this issue 馃檪

(Aside: awesome mech-bird! Looks cool)