|
Post by cyber2016 on Sept 7, 2016 6:40:08 GMT
Not sure but I've read somewhere about Turrets or anything using rotation doesn't reset if reused... EX: If I pool 3 FireBalls that shoot out of a Lizard or whatever, the 3 pooled 1's no problem.. but, once I reuse a FireBall things get wild and shitty with the "Direction" So I've tried to use/ void OnSpawned() in my Script: public float FireBallSpeed = 500; Rigidbody fireball; // Use this for initialization void OnSpawned () { Debug.Log ("Cyber_2017"); fireball = GetComponent<Rigidbody>(); fireball.AddForce (transform.forward * FireBallSpeed); } Now I can't find any info on how or if I'm using the void OnSpawned () ..... properly Any help please and Ty!
|
|
|
Post by DarkTonic Dev on Sept 7, 2016 7:31:00 GMT
Just move any code that was in awake and start into OnSpawned. Any code that should run every time it's spawned to reset initial state. Because awake and start will only run the very first spawn.
|
|
|
Post by cyber2016 on Sept 7, 2016 18:40:28 GMT
Thanks for the fast reply And yes, I kinda figured that would work... However this line of code: GameObject fireball = Instantiate(FireBall); was placed after this: public void FireAttack(int type) { Anyhow so I did this: //GameObject fireball = Instantiate(FireBall); //I prefer the PoolBoss way! Transform fireball = PoolBoss.SpawnOutsidePool(FireBall.transform, FirePoint.position, FirePoint.rotation); fireball.transform.position = FirePoint.transform.position; fireball.transform.rotation = FirePoint.transform.rotation; Again, everything is great until the FireBall is Re-used... So, I'm trying to use: void OnSpawned() somewhere in this Script for this line: fireball.GetComponent<Rigidbody>().AddForce(dir * FireBallSpeed);
|
|
|
Post by DarkTonic Dev on Sept 7, 2016 19:17:13 GMT
Those lines after SpawnOutsidePool don't do anything since you're already passing those in with the SpawnOutsidePool call. That is, you're already setting its position and rotation. Is the direction still wrong or are you having a different problem now?
Note that you should probably set the velocity back to zero before applying force in case it despawned last time with a non-zero velocity.
|
|
|
Post by cyber2016 on Sept 7, 2016 19:53:19 GMT
Thanks, ya makes sense. I'll take these 2 lines out:
fireball.transform.position = FirePoint.transform.position; fireball.transform.rotation = FirePoint.transform.rotation;
And I still have the rotation issue. I Pooled [3] FireBalls in PoolBoss... So when I fire the first 3, all is good. But, after 3 I still got the FireBall shooting off in a weird direction.. I'll keep at it, Ty!
|
|
|
Post by cyber2016 on Sept 7, 2016 20:01:43 GMT
About the: set the velocity back to zero before applying force. This makes sense, I'll c if I can figure something out
|
|
|
Post by DarkTonic Dev on Sept 7, 2016 20:55:22 GMT
About the: set the velocity back to zero before applying force. This makes sense, I'll c if I can figure something out I think that's what the problem is.
|
|
|
Post by cyber2016 on Sept 7, 2016 21:21:57 GMT
HappY Day! [Solved] Yes, you are correct... I Added this to my Mover Script, put on the FireBall. TY!
void OnDespawned() { rb.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; }
|
|
|
Post by DarkTonic Dev on Sept 7, 2016 22:38:17 GMT
That's what i figured. Had the same problem on our first game
|
|