I have been looking high and low of how to have my fireball that hits the enemy, it will transform on the GameObject. I succeeded, the only problem is that when the enemy moves, the fireball or I mean to be specific, the particle does not follow along with the enemy it instead just spawns in the previous location that the enemy was last at when it made contact. Which in fact just typing out how my script works gives me an idea of how to fix the issue, but need more help.
I was thinking that since I have Random.Range and rigidbody.addforce, somehow could I stop it by someway because every time the object is instantiated and it hits the enemy it continues to push on forward, but in some cases when I used Rigidbody.velocity it would do what I was saying in the previous paragraph.
My Main goal that I may think solve the problem unless you have a better idea :D. Is there a possible way of having a transform.position act as a vector3 as well as transform.rotation act as one as well.
But anyway my script:
#pragma strict
var FireBallSpawn : GameObject;
var FireBall : Transform;
var Enemy : GameObject;
var EnemyPosition : Transform;
var Character : Transform;
var Speed = 100;
var DestroyTime = 10;
var DelayTime : float = 0.5f;
var NextFireBall : float = 0.0f;
function Update ()
{
if(Input.GetButtonDown("Fire1")&& Time.time > NextFireBall)
{
NextFireBall = Time.time + DelayTime;
var FireBallDirection : Vector3 = Character.TransformDirection(0, 0, 10);
var clone = Instantiate(FireBallSpawn, Character.position, Character.rotation);
clone.rigidbody.AddForce(FireBallDirection*Speed);
Destroy(clone, DestroyTime);
}
}
function OnTriggerEnter (info : Collider)
{
if(info.tag == "Enemy")
{
var rotationspeed : float = Speed*Time.deltaTime;
FireBall.transform.parent = Enemy.transform;
FireBall.rigidbody.velocity = EnemyPosition.position;
}
}