Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Player "pinball" effect 0 Answers

How to get the first person controller to collide with an animated object? 1 Answer

extreme lag upon touching round surfaces 0 Answers

Affecting FPS controller/Character Motor physics with game object 1 Answer

FirstPersonController script on Network 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges