- Home /
 
               Question by 
               manegame · Jul 12, 2016 at 05:35 PM · 
                collisionfirst-person-controllerfps controllerpushfpscontroller  
              
 
              Pushing First Person Controller
Hi all,
I am working on a game in which the character dies when he gets pushed off level by enemies.
I am using the prefab FPS controller to control the player, and am looking for a way that enemies have more push to get the First Player over the edge. I made it this far, with the enemies pushing the player.
The problem is that I don't know how to diminish the push power after first impact. It should ease out after about half a second. Any ideas?
I'm trying to use a coroutine, which is something I am new to, so any help on that would be appreciated.
 using UnityEngine;
 using System.Collections;
 
 public class PlayerPusher : MonoBehaviour {
     public float pushPower = 2.0F;
     private Vector3 moveDirection = Vector3.zero;
     private Vector3 pushDirection;
     bool trigger;
     CharacterController controller;
 
     void Start()
     {
         controller = GetComponent<CharacterController>();
     }
 
     void OnControllerColliderHit(ControllerColliderHit hit) {
         Rigidbody body = hit.collider.attachedRigidbody;
         if (body == null || body.isKinematic)
             return;
 
         if (hit.moveDirection.y < -0.3F)
             return;
 
         pushDirection = new Vector3(hit.moveDirection.x, hit.moveDirection.y, hit.moveDirection.z);
 
         trigger = true;
 
         StartCoroutine (PushPlayer ());
     }
 
     IEnumerator PushPlayer() {
         while (trigger) 
         {
             controller.Move (pushDirection * pushPower / 100);
             yield return null;
         }
 
         yield return new WaitForSeconds(1);
 
         trigger = false;
     }
 }
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                