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 /
  • Help Room /
avatar image
0
Question by Pixelch3f · Jan 12, 2018 at 03:33 PM · charactercontrollerforceexplosionrocket

Character controller rocket jumping (adding force, while still maintaining control of the character)

Hi,

I have a movement script using a character controller component, and I want to add rocket jumping to it, the affect I'm after is similar to AddExplosionForce to a rigidbody.

I have found a similar answer here: https://answers.unity.com/questions/242648/force-on-character-controller-knockback.html

It's for a first person shooter game, and the issue I have with this is that my player does not have full control after rocket jumping, I can't move or jump until the knockback effect has completely finished, I believe this is due to the Vector3.Lerp method, so the player is moving between 2 vector3 locations

Does anyone know an alternative way to add force to the character controller while still maintaining full control? Thanks in advance!

Here is the code I'm using for Knockback at the moment:

// Player script

 public float knockbackSpeed = 4f;
 public float playerMass = 3f;
 public Vector3 knockbackImpact = Vector3.zero;
 
 private void Update()
     {
         // This is to move the player if they are affected by a rocket explosion
         if (knockbackImpact.magnitude > 0.2f) playerCC.Move(knockbackImpact * Time.deltaTime);
         // moves the character between two vector3 locations per second
         knockbackImpact = Vector3.Lerp(knockbackImpact, Vector3.zero, knockbackSpeed * Time.deltaTime);
 }
 
 // function to apply force to the player when hit by a rocket explosion
     public void Knockback(Vector3 direction, float force)
     {
         direction.Normalize();
         if (direction.y < 0) direction.y = -direction.y; // reflect down force on the ground
         knockbackImpact += direction.normalized * force / playerMass;
     }

// Rocket explosion script

 private Vector3 explosionOrigin;
 public float explosionRadius = 3f;
 public float explosionForce = 70f;
 public float explosionUpwardsForce = 1f;
 
 private IEnumerator Start()
     {
         explosionOrigin = transform.position;
         // Wait one frame before starting, to ensure all objects are affected
         yield return null;
         Collider[] objectsInRange = Physics.OverlapSphere(explosionOrigin, explosionRadius);
 
         foreach (Collider collision in objectsInRange)
         {
 foreach (Collider collision in objectsInRange)
         {
             Player player = collision.GetComponent<Player>();
             if (player != null)
             {
                 // Apply knockback force to player if they are in explosion radius
                 player.Knockback(player.transform.position - explosionOrigin, explosionForce);
             }
 }
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

134 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why is AddRelativeForce not adding force to player? 0 Answers

How do I get objects in front of the player to be blasted away? 1 Answer

Why Rigidbody.AddForce is not acting like the correct physical force? 1 Answer

How do I make a rocket? 2 Answers

Rocket Landing 1 Answer


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