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 /
avatar image
1
Question by anildemir · Jan 23, 2014 at 12:53 AM · collisionvector3charactercontrollerdirectionknockback

Fire Knockback

I can imagine this: alt text

I just cannot code it in C#. I think the script should be on fire prefab and it should detect the charactercontroller collision and get the point firstly. Then send charactercontroller by some amount in the opposite direction with gravity so it stops somewhere. (Oh and it should be collision point(x,charactercollider's bottom.y,z) if collision is a line. I don't know how it would detect the collision point in ths situation honestly.)

Am I on the right track? Is the script should be attached to fire or character? How to create the direction and move charactercontroller in that way?

Sorry, I'm a beginner but this will help me understand a lot of things. Can anyone help me out?

knockback.png (17.7 kB)
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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by YoungDeveloper · Jan 23, 2014 at 01:15 AM

  • for detailed question explanation, instead of "plz help need script".

Anyway, you are on right track. I suggest checking the collison only on player, because if you will have 5 fires, there will be 5 collision checks each frame.

When player collides or triggers, get direction vector from fire to player(you know fire GO from collision), then call some method which apply force and to player in that vector* strength from fire, and create some method to remove heath.

 public float health = 100f;
 
 void RemoveHealth(){
     health -= 5f;
 }
 
 //When you want to remove health, just call the method
 RemoveHealth();

Direction: http://docs.unity3d.com/Documentation/Manual/DirectionDistanceFromOneObjectToAnother.html

Force: http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html

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 anildemir · Jan 23, 2014 at 01:19 PM 0
Share

Thank you very much.

I think Force can only be used if character has a rigidbody. In this case I have character controller. I guess I'll just start to code by checking collision and producing the vector in the right direction. I could manage with damage code but still thanks :)

avatar image
0

Answer by Alpha_Guac · Oct 19, 2015 at 10:40 AM

have the collision attached to the player. and try

void OnCollisionEnter(Collider c) if(c.gameObject == "Fire") { Health-= fireDamage; this.rigidbody.addForce(force applied in knockback as Vector3, ForceMode that you are using) }

check this out to determine what force mode you want to use. http://docs.unity3d.com/ScriptReference/ForceMode.html

Comment
Add comment · 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
0

Answer by RavenOfCode · Jan 04, 2016 at 01:23 PM

  Rigidbody rb;
     void Start ()
     {
         rb = GetComponent<Rigidbody>();
     }
     void TakeKnockback(float amount, GameObject hitter)
     {
         rb.AddForce((transform.position - hitter.transform.position) * 100 * amount);
     }

Call TakeKnockback on what is getting hit, use hitter as the object who hit.

Comment
Add comment · 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

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

20 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

Related Questions

Respawn when a character hits an object with a tag of "Kill" , but after 3 deaths the controller is destroyed 0 Answers

Can't change vector direction 0 Answers

Vector direction after collision 1 Answer

Slerp look at direction not working... 3 Answers

Trying to Lerp knock-back on Character Controller 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