- Home /
Strange physics, rigidbody, iTween activity
Hey guys, I'm having some strange behaviors with both my projectiles, and my enemies. I've been trying to figure this out in the back of my mind, while coding the other aspects, but it's still eluding me.
Strange behaviors are: - Projectiles: sometimes fire straight, and sometimes fire at an angle or slanted, or corkscrew. - Enemies getting knocked back using iTween will rotate them in crazy ways, never knocking them directly back, but more knocking them down through the floor usually, etc, even with no rotation code written for them. (I've used this code for other games and it's worked fine with no bugs) - Enemies when spawning, sometimes spawn correctly with the particle effect and work fine (maybe 80% of the time), and other times, they rocket straight into the air at high speed and never come down.
The strange thing is, I've done games before, I've used this same code previously and it's worked perfectly, this time, the same code has erratic behaviors and renders the game buggy enough to be a serious issue.
If you've encountered this before, I'd love some input. Any help would be greatly appreciated.
You can see in the pic attached, that I'm standing in one spot, and the projectiles are going in strange directions.
Answer by Fattie · Dec 26, 2012 at 08:59 AM
"Strange behaviors are: - Projectiles: sometimes fire straight, and sometimes fire at an angle or slanted, or corkscrew"
Almost certainly, one problem could be:
You need to extensively use the "physics layers" system in Unity.
http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html
When hero H fires bullet B, the bullet B will interact with hero H as it begins its journey!
The solution to this issue in game engines is physics layers. In practice, you can't do anything at all in Unity physics without using the layers system.
it is very likely you'd have to totally redo it using layers - before looking for any other problem. Fortunately it's easy to do so.
BTW "spawn enemies" .. if you mean using Instantiate(), generally you don't instantiate anything during gameplay in a vid game. One uses a pool .. here's a long discussion!
http://answers.unity3d.com/questions/321762/how-to-assign-variable-to-a-prefabs-child.html
So physics laters, hope it helps in some way cheers
Actually, this wound up being the reason for the projectiles malfunctioning. It wasn't colliding with the enemies, or other objects, it was colliding with invisible triggers used for AI. I'm sure could very well be the same case with the enemies, and I guess I'll know very soon. :) Thanks for the input, much appreciated for you to dedicate your time and knowledge to the community. :)
For future reference, the physics layers fixed the projectile bug, the rocketing enemies, was caused by the enemy prefabs having both the CharacterController and RigidBody on them. Removing the rigidbody fixed the issue, as well as fixing another issue with jumpy animations.