- Home /
Other
I Want My Player To Be Sent Flying In The Air When He Get's Hit By An Enemy
I add a simple particle system and when the player get's hit the particle's take effect but now i want my player be sent flying in the air when he get's hit. right now if the player get's hit they will be sent back to spawn which is what i don't want.
public class PlayerDeath : MonoBehaviour {
public GameObject deathParticles;
private Vector3 spawn;
// Use this for initialization
void Start () {
spawn = transform.position;
}
void OnCollisionEnter(Collision other)
{
if (other.transform.tag == "Enemy")
{
Instantiate (deathParticles, transform.position, Quaternion.identity);
transform.position = spawn;
}
}
Answer by HarshadK · Feb 18, 2015 at 09:30 AM
If your player has a rigidbody attached to it then just apply a force (usign Rigidbody.AddForce) with ForceMode.Impulse to your player object.
Otherwise you can start a coroutine that will move your player by changing its transform with Transform.Translate or Transform.position.
Follow this Question
Related Questions
How do I cap jumping? 1 Answer
[C#] JUMP - What i must add to this code to jump? :> 1 Answer
Multiple Cars not working 1 Answer
2D Character Switching HELP! 0 Answers
Distribute terrain in zones 3 Answers