0
votes

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:

enter image description here

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?enter image description here

1
I am not sure what the problem is. Can you add a screenshot of what you expect to happen?Draco18s no longer trusts SE
you see that lightning is going to the ground, not to the ball (talking about center of thunder). So i want to change angle somehow.Aleksa Ristic
That's going to entirely depend on the setup and nature of your objects there. If the graphic of the lightning bolt isn't aligned with the axis of the game object, then the graphic needs to be fixed. If the prefab plane isn't aligned with the axis, then that needs to be fixed. If the prefab axis isn't pointing to where you want it to be pointing, then that's a different problem entirely. I can't tell which one it is from the picture you have posted.Draco18s no longer trusts SE
Can you tell me what else should i printscreen for you so i post all images at onceAleksa Ristic
It's more of a process: pause your scene when the lightning bolt is there and examine the objects to see if the parent (the cloned prefab) is pointing in the right direction. If it's pointing in the right direction, then check each child until you find which one isn't properly oriented.Draco18s no longer trusts SE

1 Answers

1
votes

I created empty gameobject and make it a parent to my ball. Then i set gameobjects position (it is pivot now) to where i wont (around center of ball y=5) and then on the ball i did the opposite (y= -5).

Then to the gameobject i created as pivot i added tag pivotChange and then in my castSpell script i made this change at lookAtEnemy part:

    if(lookAtEnemy)
    {
        if(other.transform.parent != null && other.transform.parent.gameObject.tag == "pivotChange")
        {
            Temporary_Spell_Handler.transform.LookAt(other.transform.parent.gameObject.transform);
        }
        else
        {
            Temporary_Spell_Handler.transform.LookAt(other.transform);
        }
    }

And it is working okay.