Custom IK script doesn't work
I'm trying to make a simple IK solution for an archer AI (for aiming) whose animations are generic. Here's what I have so far:
void LateUpdate()
{
if (enabled)
{
Vector3 lookPos = (EnemyToAttack.position - transform.position) + lookRotationOffset;
Quaternion lookRot = Quaternion.LookRotation(lookPos, Vector3.up);
spine.rotation = Quaternion.Lerp(spine.rotation, lookRot, Time.deltaTime * lookSpeedMultiplier);
}
}
This works fine when I'm debugging it and manually changing lookRotationOffset, but then, afterwards, the AI always looks in the same direction. I'm at my wit's end on this one, is there a better method of doing this or am I doing something wrong? I'd appreciate any help anyone can give me.
EDIT: I apologize for the weird title, I think it's my internet connection :)
I'm a little confused by your "lookRotationOffset" variable. What is that supposed to represent?
LookRotation is based around the idea at pointing towards a relative position, so if that offset's trying to do anything drastic, I would think that might be causing problems.
Answer by pbitschy · Nov 11, 2015 at 01:05 AM
As a low mathematical cultured, amateur programmer, I usualy setting transform.forward when I need looking rotation:
// not sure you need to normalize
lookPos== lookPos.normalized;
spine.forward= lookPos;
// or (not try)
spine.forward=Vector3.lerp(spine.forward, lookRot, Time.deltaTime * lookSpeedMultiplier);
// As I undertand your lookrotationoffset you don't need that but if needed
spine.up= Vector3.up;