Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 DKKnown · Mar 19, 2018 at 10:26 AM · physics3dvelocityballreflect

[Help] Hovering Ball Not Reflecting Off Walls

Hello there, thx in advance.

I am working on a 3D game.

The intend: I want a Ball that is not affected by gravity but can still be manipulated by velocity(rigidbody). This ball is in a closed off room, but should bounce off the walls. If the ball hits a moving object, the moving objects velocity gets applied to the ball, there by increasing or decreasing its speed. This is why i don't think it can work when its kinematic.

The problem: The ball can float in air quite welll, and i can move it at a speed using in FixedUpdate:

 this.rigidbody.velocity = this.rigidbody.velocity.normalized * Time.deltaTime * 100.0f;
 
 rigidbody.AddRelativeForce(100.0f * this.transform.forward);

But the ball just goes into an instant stop when hitting a wall, even though i should reflect its movement: this code is triggered OnCollisionEnter,

 this.rigidbody.velocity = Vector3.Reflect(this.rigidbody.velocity, contact.normal);

Can someone please explain what i am doing wrong?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Pangamini · Mar 19, 2018 at 10:35 AM

Well If you are using rigidbody for the collision handling, there's a big chance that the physical reaction happens before your code gets called - and if your physics materials have bounciness set to zero, the ball is already stopped when you try to reflect it.

There are two solutions. Decide whether you want to be using the physics of rigidbody or not. Means either

  • use the physical collision reaction to bounce your ball (by using a proper physics material with bounciness).

  • use your own simulation (moving the ball in your code, using your own velocity variable while the rigidbody is set to kinematic (or not present at all)), detecting collisions on your own (using triggers perhaps, kinematic rigidbodies don't produce regular collisions)

Hard to say which is better for you, since I don't know what you are doing. But if you want your ball to interact with the rest of the physics world, then just go with the rigidbody.

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 DKKnown · Mar 19, 2018 at 11:23 AM 0
Share

Hey there,

just a clarification but all my objects have a physics material.

But i want the ball to fly around the room bouncing off walls with a constant speed. If the ball hits a moving object, it gets that objects velocity applied. So hitting a fast object would send the object fast away.

avatar image Pangamini DKKnown · Mar 19, 2018 at 12:53 PM 0
Share

And do your physics materials have bounciness set to 1?

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

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

Related Questions

Fps Movement Velocity Decrease 0 Answers

Move Ball With Same Velocity on Slope 1 Answer

How to transform velocity to world space before calling controller.move? 1 Answer

Horizontal gravity physics on 3d game 1 Answer

Move Player Car in Forward Direction using Physics Force 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