Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

I Want My Player To Get Push Forward And I Don't Want The Enemy To Get Push Backward.

$
0
0
When the enemy hit's the player the enemy get's push backward but the player just stand's still. I want the player to get push forward and the enemy to keep on moving. here is all my codes for the enemy and the player.> [Player Component's] Box Collider,> Character Controller Slope Limit = 45,> Step Offset = 0.3, Skin Width = 0.08,> Min Move Distance = 0, Center = X0 Y0> Z0, Radius = 0.5, Height = 2,>> [Enemy Component's] Box Collider,> Rigidbody, Mass = 1, Drag = 0, Angular> Drag = 0.05, Use Gravity = off, Is> Kinematic = off, Inerpolate = none,> Collision Detection = Discrete, Freeze> Position X=Yes Y=Yes Z=No, Freeze> Rotation X=Yes Y=Yes Z=Yes, **Enemy Code** public class enemy : MonoBehaviour { public float speed; void Start () { rigidbody.velocity = transform.forward * speed; } } ****Player Jump Code**** public class PlayerJump : MonoBehaviour { public float jumpSpeed = 0.5f; public float gravity = 1.1f; CharacterController controller; Vector3 currentMovement; // Use this for initialization void Start () { controller = GetComponent(); } // Update is called once per frame void Update () { if (!controller.isGrounded) currentMovement -= new Vector3 (0, gravity * Time.deltaTime, 0); else currentMovement.y = -9.81f; if (controller.isGrounded && Input.GetButtonDown("Jump")) currentMovement.y = jumpSpeed; controller.Move (currentMovement); } } **Player Death Code** public class PlayerDeath : MonoBehaviour { public GameObject deathParticles; private Vector3 spawn; // Use this for initialization void Start () { spawn = transform.position; } // Update is called once per frame void OnCollisionEnter(Collision other) { if (other.transform.tag == "Enemy") { Instantiate(deathParticles, transform.position, Quaternion.identity); transform.position = spawn; } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>