I am casting some spell and i am setting it direction by LookAt
. Problem is that LookAt
is setting my spell animation off the gameobject. Object from which i am getting position has scale (3, 3, 3), mesh renderer, sphere collider, and rigidbody. (other colliders are on child objects). Here is the code i am using for casting spell:
public void castSpell(GameObject caster, Transform otherTransform, float duration)
{
if(animationEnabled)
{
foreach(var a in animator)
{
foreach(var b in a.bools)
{
a.animator.SetBool(b.parameterName, b.parameterValue);
}
foreach(var i in a.ints)
{
a.animator.SetInteger(i.parameterName, i.parameterValue);
}
foreach(var f in a.floats)
{
a.animator.SetFloat(f.parameterName, f.parameterValue);
}
}
}
GameObject Temporary_Spell_Handler;
Temporary_Spell_Handler = Instantiate(_Spell, Spell_Emitter.transform.position, Spell_Emitter.transform.rotation) as GameObject;
ParticleSystemRenderer pr = Temporary_Spell_Handler.GetComponent<ParticleSystemRenderer>();
float dist = Vector3.Distance(caster.transform.position, otherTransform.position);
//Add Spell Script to the casted spell so it handes damage and everything about spells.
Spell tempSpell = Temporary_Spell_Handler.GetComponent<Spell>();
tempSpell.caster = caster;
if(b_lenghtScale)
{
pr.lengthScale = -lenghtScale;
}
if(lookAtEnemy)
{
Temporary_Spell_Handler.transform.LookAt(otherTransform);
}
Destroy(Temporary_Spell_Handler, duration);
}
and here is the image how it looks like:
I found the problem. My ball
is scaled to (3, 3, 3), so it went up and pivot of the object stayed down. So how can I overcome this problem?