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
0
Question by raptorkwok · Jan 16, 2014 at 04:01 AM · collision-detection

Stop affecting Player's velocity when colliding

I have a Runner class, which is a Cube with Rigid Body increases speed gradually with codes in Update() :

 rigidbody.AddRelativeForce(new Vector3(speed, 0, 0), ForceMode.Acceleration);

When I collide with a non-rigid body (a primitive capsule), the Runner stops by the capsule. I have applied the code to destroy the capsule upon collision, but the Runner's speed is still affected. How can the speed not to be affected by the collision? Did I need to set something on the capsule?

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

2 Replies

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

Answer by robertbu · Jan 16, 2014 at 04:03 AM

Set the 'isTrigger' flag to true on the primitive capsule and use OnTriggerEnter() to detect the collision.

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 raptorkwok · Jan 16, 2014 at 04:11 AM 0
Share

After "Is Trigger" of the Capsule is enabled, now the Runner object ignores the Capsule & pass through it without destroying the capsule. The destroy code is now:

     void OnTriggerEnter(Collision collison) {
     if (collison.gameObject.tag.Equals("CollectableTypeA")) {
         Destroy(collison.gameObject);
     }
 }

What do I miss this time?

avatar image robertbu · Jan 16, 2014 at 04:53 AM 0
Share

A Trigger has a collider as a parameter, not a collision:

 void OnTriggerEnter(Collider collider) {
     if (collider.tag.Equals("CollectableTypeA")) {
        Destroy(collider.gameObject);
     }
 }
avatar image raptorkwok · Jan 16, 2014 at 06:09 AM 0
Share

It works! Surprisingly compiler doesn't complain !

avatar image
0

Answer by HummeL_YT · May 17, 2021 at 09:45 AM

Necro, but I still look for an answer. If I can't use triggers, what I should do? Or... Ok, maybe I can calculate speeds of objects, make with them some calculations, and then just set speeds back, but this isn't a good variant for destructible or\and fast-moving objects. I just wanted to try to make a game with some voxel-destruction, but all my solution variants do not work as I want...

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

18 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

Related Questions

Ignore collision, but raise event. 1 Answer

Edge Collision Issue 1 Answer

OnTriggerEnter2D on an empty game object with a box collider? 1 Answer

No collision detected between two gameObjects 1 Answer

Collision Detection not working 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