Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Stuntrally · Oct 28, 2012 at 06:20 PM · javascriptexplosiondetonator

Detect explosion Character Controller

I have a character controller and a missile that causes an explosion. I want the explosion to knock back/allow the player to rocket jump. How can I do this? The Character Controller does not respond to rigidbody physics such as a Detonator explosion or a high velocity rigidbody projectile. What is the best way to allow the functions of both on my Character Controller so that it is effected by explosions but still functions like a Character Controller?

Comment
Add comment · Show 6
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
avatar image Montraydavis · Oct 29, 2012 at 12:44 AM 0
Share

Do you have Rigidbodies and Colliders on both objects ?

avatar image Stuntrally · Oct 29, 2012 at 11:18 AM 0
Share

Well, one is an explosion, so no, but it's able to push rigidbodies away. Also, character controllers with rigidbody's don't act like a rigidbody.

avatar image ZenithCode · Oct 29, 2012 at 02:25 PM 0
Share

I'm not 100% sure on this but character controller adds a rigidbody underneath but it acts weird with any physics you apply to it.

avatar image Stuntrally · Oct 29, 2012 at 09:41 PM 0
Share

That doesn't help me.

avatar image sparkzbarca · Oct 29, 2012 at 10:04 PM 1
Share

add a rigidbody but disable the rigidbody.

on collision with an explosion disable character controller and enable rigidbody. Add forces to rigidbody to simulate explosion, on landing disable rigidbody enable character controller.

Show more comments

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by sparkzbarca · Oct 30, 2012 at 06:04 PM

well do you understand basic coding?

 Like do you know what an array is?
 
     Sphere cast all returns an array
     
     //impact point you'll need to find, its the point at
     //which the round exploded
     vector3 ImpactPoint; 
     
     //DamageRadius is just chosen by you based on
     //what you think is appropriate explosion radius
     float DamageRadius;
     
     //this is an array, it will contain information
     //on every object that was in the explosion radius
     RayCastHit[] ArrayOfObjectsHit;
     
     
     //this is the line that finds all objects with
     //colliders inside the radius DamageRadius whose
     //center or origin is ImpactPoint
     //this Returns an array which we'll store.
     ArrayofObjectsHit = physics.spherecastall(ImpactPoint,DamageRadius)
 
 //This will do alot of things so read carefully
 //it will go through the array of objects, it will take the players
 //position and the explosions position and use that to figure out which
 //way to throw the player.
 //it will then move the player some
 
 vector3 TossDirection;
 
 //speed is meters per second, thats how unity does speed for a character controller
 //speed is how fast you will be thrown
 float speed = 1;
 
 foreach (RayCastHit ObjectHit in ArrayOfObjectsHit)
 {
    if (ObjectHit.transform.GameObject.Tag == "Player")
     {
       TossDirection = ObjectHit.transform.position - ImpactPoint;
       //this next line varies, its the line that will move the player
       //but physics based movement is done differently than 
       //character controller movement which is done slightly
       //differently than transform movement or kinematic 
       //rigidbody transform movement
       //this assumes your using a character controller 
       //we will multiply the direction by the speed to get a Movement Vector
       ObjectHit.transform.GameObject.CharacterController.Move(TossDirection * Speed);
      }
 }

That took awhile, mark as answered. If you can't turn that into the answer you need to learn more about programming.

Comment
Add comment · Show 1 · Share
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
avatar image Stuntrally · Oct 30, 2012 at 07:05 PM 0
Share

Yes, thank you. I just didn't understand how the array was outputted.

avatar image
1

Answer by gnubberlang · Oct 29, 2012 at 11:17 PM

Looks like you need to do away with the character controller peice all together and work with a rigid body + some sort of collider.

I was dealing with this issue too. I got it working with a box collider and rigid body only.

http://www.packtpub.com/article/unity-3.x-rigidbody-character-controller-script

Comment
Add comment · Show 2 · Share
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
avatar image Bunny83 · Oct 29, 2012 at 11:21 PM 0
Share

Yes, the point of the CharacterController is that it isn't affected by external forces. If you want this, use a Rigidbody.

avatar image Stuntrally · Oct 29, 2012 at 11:33 PM 0
Share

Which method is better, this one or the one below?

avatar image
0

Answer by sparkzbarca · Oct 29, 2012 at 10:04 PM

add a rigidbody but disable the rigidbody.

on collision with an explosion disable character controller and enable rigidbody. Add forces to rigidbody to simulate explosion, on landing disable rigidbody enable character controller.

note, this is how games do ragdoll physics on characters.

If you dont want physics do a rough simulation by using charactercontroller.move() to move the character in the direction opposite the explosion at the speed thats the max speed / distance. The direction opposite can be found by

explosion.position - character.position.

That willl give you a vector pointing from explosion in the direction of character.

Comment
Add comment · Show 3 · Share
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
avatar image Stuntrally · Oct 29, 2012 at 11:12 PM 0
Share

How would I do this with explosions (sense them)?

avatar image sparkzbarca · Oct 30, 2012 at 01:19 AM 0
Share

at the point of the "explosion" you spherecastall to find all nearby colliders

http://docs.unity3d.com/Documentation/ScriptReference/Physics.SphereCastAll.html

SphereCastAll basically returns all colliders within the radius you define. It will return an array containing all colliders it hit. Tell it to ignore terrain. You now know what was within the "blast" radius.

So basically you attach a spherecastall script to the projectile and have it called on explosion.

you then check all the colliders returned and if it returns a player you damage them based on distance and move them based on distance in a direction opposite the explosion.

avatar image Stuntrally · Oct 30, 2012 at 11:52 AM 0
Share

Thanks for the help! How would I get and use the results of my SphereCastAll?

avatar image
0

Answer by ZenithCode · Oct 29, 2012 at 10:08 PM

Ok I think you have to 'hack this'. What I would try is to: ` 1. Add an empty Game object as child of my character 2. Add a box collider and set it to trigger and add a rigidbody (disable this) 3. Put a script in there which handles OnTriggerEnter 4. In this method, that is on trigger, disable the character controller on the parent and enable the character controller. `

Please let me know if this helps.

Comment
Add comment · Show 1 · Share
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
avatar image Stuntrally · Oct 29, 2012 at 11:12 PM 0
Share

Thanks, but what about Detonator explosions?

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

14 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

Related Questions

FPS Controller and Explosion? 2 Answers

How to trigger different prefabs (JavaScript) 2 Answers

Shuriken Explosion Example - Collision 0 Answers

Move a detonator 1 Answer

Object only explodes when it collides with certain object, not all rigidbodies. 2 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