Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 question was closed Nov 20, 2020 at 09:12 PM by ypermat for the following reason:

Other

avatar image
0
Question by ypermat · Nov 17, 2020 at 10:44 PM · knockback

Knockback player

Hi !

I tried to knockback the player when he collide with an ennemy but i'ts not really a knockback but a teleportation backward. Here is the code :

     [SerializeField]
     private float force;

     void OnCollisionEnter(Collision collision)
     {
         if (collision.transform.tag == "Player")
         {
             collision.transform.GetComponent<CharacterController>().Move(this.transform.forward * force);
             GameController.removeLife(1);
         }
     }

How can I do ? Thank you !

Comment
Add comment · Show 1
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 Nestorlen · Nov 19, 2020 at 12:48 PM 0
Share

Yo, did that scout just run up and miss both force of nature shots?

2 Replies

  • Sort: 
avatar image
1

Answer by Smsaliou5935 · Nov 17, 2020 at 11:38 PM

Do public Rigidbody rb, then do void OnCollisionEnter(Collision collision) { if (collisionInfo.collider.tag == "Enemy") { rb.AddForce(Vector3.back forwardForce Time.deltaTime, ForceMode.VelocityChange); GameController.removeLife(1); } }

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 Smsaliou5935 · Nov 17, 2020 at 11:40 PM 0
Share

sorry for not posting in on code lines.. $$anonymous$$y bad, this was my very first time answering

avatar image
0

Answer by ypermat · Nov 18, 2020 at 04:18 PM

No problem, where do I need to put theses lines ? instead of mine ? Because if I try to type only your lines like this : public Rigidbody rb;

     void OnCollisionEnter(Collision collision)
     {
         if (collision.transform.tag == "Player")
         {
             rb.AddForce(Vector3.back forwardForce Time.deltaTime, ForceMode.VelocityChange);
             GameController.removeLife(1);
         }
     }

VS studio tells me that "forwardForce" and "Time" does not exist. He expected a ",".

PS: The script is on my ennemies, should I make one for the player instead ?

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 Llama_w_2Ls · Nov 18, 2020 at 07:48 PM 0
Share
 rb.AddForce(Vector3.back * forwardForce * Time.deltaTime, Force$$anonymous$$ode.VelocityChange);


You need to multiply those values.

avatar image Llama_w_2Ls · Nov 18, 2020 at 07:49 PM 0
Share

@ypermat ^

Follow this Question

Answers Answers and Comments

139 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Hitting an Enemy and Pushing them back 2 Answers

2D RPG style knockback on attack 0 Answers

How Do I Add Knockback To Player Once Firing Gun In 2D? 0 Answers

2d platformer combat system 1 Answer

change an object's velocity, while you edit its transform as well? 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