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 VAN-D00M · Jul 29, 2014 at 10:10 AM · c#objectreflectionbounce

Reflecting Objects off of Boundaries/Walls

Hi

I've got walls around my game area designed to keep my hazards in the game. However, the hazards hit the wall and either stop or slide along the wall never been reflected back into the map. The hazard has a rigidbody component (gravity disabled), and a capsule collider. It is always moving on the x and z axis.

I can't think of the best way to do it, I've looked at this forum which makes sense but I haven't been able to convert it into C# partly because I've been trying to work out how to make it work with my code. Otherwise I have no idea how to do it.

If anyone has any ideas to how this can be done I would be very appreciative.

The code I'm using to make it move around randomly.

 void Start()
 {
         //random rotator
         rigidbody.angularVelocity = Random.insideUnitSphere * tumble;
 
         //movement
         Vector3 randomDirection = new Vector3(Random.Range(-1, 2), 0.0f, Random.Range(-1, 2));
         rigidbody.velocity = randomDirection * speed;
 }





EDIT I'm trying to get this sort of effect. Right at the beginning of this video you see the cubes hit the boundary and effortlessly without fail bounce of it back into the game area. https://www.youtube.com/watch?v=9nLIoj6KEUM

I have messed with settings in the Bouncy Physics Material and they do seem to bounce off of the boundary but they tend to still get collected and stuck on the wall and in the corners.

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
0

Answer by prof · Jul 29, 2014 at 10:29 AM

if you want proper physics, use AddForce, instead of changing velocity

EDIT example

     private Vector3 randomDirection;
     public float force = 20.0f;
     
     void Start () {
         randomDirection = new Vector3(Random.Range(-1.0f, 1.0f), 0, Random.Range(-1.0f, 1.0f));
 
         //Drag is how fast object slowing down 
         rigidbody.drag = 0;
 
         //ForceMode.VelocityChange will ignore mass of object and apply velocity instantly
         rigidbody.AddForce(randomDirection * force, ForceMode.VelocityChange);
     }

Comment
Add comment · Show 4 · 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 VAN-D00M · Jul 29, 2014 at 10:51 AM 0
Share

Would AddForce be better for reflecting?

avatar image prof · Jul 29, 2014 at 01:21 PM 0
Share

Depends. Unless you need some really specific movement, using forces is better.

avatar image VAN-D00M · Jul 29, 2014 at 01:56 PM 0
Share

I just tried the bouncy physic material and it sort of worked with it. Sometimes bothered and others it didn't. Could using velocity be the reason why? I don't think it'll let me just change it from rigidbody.velocity = randomDirection speed; to rigidbody.AddForce = randomDirection speed; ether which might be a stupid thing to say.

avatar image prof · Jul 30, 2014 at 02:42 PM 0
Share

i think this should give you idea) And, of course, learning materials 1 2

avatar image
0

Answer by ironblock · Jul 29, 2014 at 01:28 PM

use a physic material there is a standard(import package > physic materials ) one called bouncy. i used that one for my pinball.

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 VAN-D00M · Jul 29, 2014 at 01:52 PM 0
Share

Just dragged it on and it works but it doesn't seem to work all the time. One will probably bounce off of one wall then it might not bounce off another and some probably won't even bother bouncing once. I don't know why it acts like this. What was the set up on your pinball?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Balls bounce off wall in different ways 1 Answer

How to bounce one object correctly? 1 Answer

Find greatest distance between a List of objects? 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