- Home /
Make object shaking when is damaged
Hi, in my game, I have enemies composed of a Gameobject with Sprites/Models as child. I want the Sprite/Model shake when the enemies are damaged, but I don't have any idea how can I shake these object (X axis). I appreciate any advice you could give me.
Answer by theLucre · Dec 09, 2014 at 12:39 AM
I recommend keeping the original transform.position of your game object when the shaking begins. Then in each frame offset the transform position by a random amount using Random.InsideUnitCircle(). This will give you a random vector with a maximum magnitude of 1 which you can multiply by for greater shakiness.
One thing to watch for, if your GameObjects have RigidBodies or colliders, directly translating them may screw up your physics.
http://docs.unity3d.com/ScriptReference/Random-insideUnitCircle.html
Same applies to 3D http://docs.unity3d.com/ScriptReference/Random-insideUnitSphere.html
Reading those links, the solution came and I applied it well only on X axis like I wanted. Thanks.
Your answer
Follow this Question
Related Questions
Camera Shaking Problem 0 Answers
Dice shaking (mobile) 1 Answer
how can my gameobject stop shaking? 1 Answer
Shaking angles using gyro attitude 1 Answer
Unity Pathfinding Starting Shake! 0 Answers