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 osisdie · Jul 19, 2013 at 03:28 AM · rigidbodybulletbounce

perfect bounce when a bullet hits a wall

I wanna create bullets at runtime with physical features as the following code. As long as the speed increases to a higher enough number, such as 350.0f, 400.0f, 1000.0f etc, the bullet will pass through the surrounding walls without any bounce and any collision, which is not what I want.

Is there a way to set perfect bounce but the speed regardless ? (the Bounce Threshold is 0, Friction is 0, Minimum Friction Combine and Maximum Bounce Combine)

thanks ~

 // bullet gameobject's physics settings
 bullet.rigidbody.useGravity = false;
 bullet.rigidbody.isKinematic = false;        
 bullet.rigidbody.collisionDetectionMode = CollisionDetectionMode.Continuous;
     
 Vector3 direction = (target.transform.position - bullet.transform.position) 
 Vector3 directionWithSpeed = changeSpeed(direction);
 // to fire a bullet with a force here
 bullet.rigidbody.AddForce(directionWithSpeed)
 
 public float speed = 100f;
 Vector3 changeSpeed(Vector3 src){
     // the problem : there should be a limit on speed
     speed +=10.0f;
     return new Vector3(src.x*speed,0,src.z*speed)
 }
Comment
Add comment · Show 7
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 robertbu · Jul 19, 2013 at 05:59 AM 0
Share

This question comes up frequently. There is no one solution. The two ideas that come up as most helpful seem to be:

  1. Reducing the Fixed Timestep. Go to Edit/Project Settings/Time and change the timestep from to 0.02 to something smaller like 0.01.

  2. DoGoThroughThings Script.

avatar image osisdie · Jul 19, 2013 at 06:14 AM 0
Share

awesome, set timestep to 0.01(or lower) works. thanks

avatar image osisdie · Jul 19, 2013 at 08:15 AM 0
Share

but this setting sounds evil, doesn't it ?

avatar image hatuf · Jul 19, 2013 at 08:18 AM 0
Share

What kind of a bullet is it? For a rifle or something real like that using a Raycast ins$$anonymous$$d of a rigidbody is much safer.

avatar image osisdie · Jul 19, 2013 at 09:29 AM 0
Share

the bullet is like a pin ball, running around inside a 2d box. it might hit the player(another ball) or the walls, so I give it rigidbody feature without gravity and friction

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DanFrias · Jul 19, 2013 at 03:43 AM

For the bullet you want to use ContinuousDynamic mode, rather than Continuous, and for those objects with which it will collide (such as the wall), use Continuous mode for those.

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 osisdie · Jul 19, 2013 at 05:31 AM 0
Share

I've tested both mode. The result is almost the same. That is, they all run into the wall when speed raises.

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

17 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

Related Questions

Collision misses - possibly not bullet through paper! (now with video) 1 Answer

Wheelcolliders launch the car. 0 Answers

Changing physics properties of a gameobject through code. 1 Answer

How to tell the exact moment a rigidbody bounces? 1 Answer

bounce and roll a die 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