Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 /
avatar image
0
Question by aronthepalmer · Jan 09, 2020 at 07:50 PM · collisionphysicsmovingmovinggameobject

Moving object breaks physics

I'm trying to make a prototype world for my 3rd person ball rolling game, I've finally fixed everything and have been given the chance to work on my world building. Only after attempting to make a spinning object as a test obstacle with an extremely simple transform.Rotate script, do I find that my collision physics don't seem to work with a moving object. I've looked around and can't find a fix.
Here's a video showing what happens:
https://imgur.com/a/bowtYYj
Along with my inspectors for both objects:
https://imgur.com/4qYjzGv
https://imgur.com/gKcU2wy

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by RendrWyre · Jan 09, 2020 at 08:22 PM

What kind of result are you expecting? It seems there is some kind of interaction between the ball and spinning object which suggests the physics engine is working correctly, however, there might be some additional things to consider.


1) Are you directly modifying the rigidbody's velocity? You should not do this as it can result in unrealistic physics simulations.


2) Discrete means Continuous Collision Detection is turned off for that RigidBody. What does that mean? Collisions for this collider will only be checked at the content's Time.fixedDeltaTime.


https://docs.unity3d.com/Manual/ContinuousCollisionDetection.html


have you tried testing with other types of collision detection?

Comment
Add comment · Show 11 · 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 aronthepalmer · Jan 09, 2020 at 08:52 PM 0
Share

Yes, it may seem saying my physics is broken was a bit of an overstatement, but basically I just want my ball to bounce back from the spinning object as it would a stationary wall, except with the added force of the movement from the object. The physics interaction that you see is only when I have the ball ram into the object at a decently high speed and it bounces back like it was a stationary object. What actually happens is no matter if I'm on the ground or in the air, when the object hits my ball it forces it either above or below the object, clipping the ground.
And thanks for pointing out the Discrete Collision detection, but I just tested it multiple times with all other options and I have the same outcome...

avatar image aronthepalmer aronthepalmer · Jan 09, 2020 at 09:00 PM 0
Share

Oh, forgot to mention, no. I'm only using AddForce to control my movement, any direct vector changes I have in my scripts are for my different jump heights which are only used once my jump has been initiated with an AddForce.
Also apologies if I may seem amateurish, it is my second game after all...

avatar image RendrWyre aronthepalmer · Jan 09, 2020 at 09:16 PM 0
Share

@aronthepalmer Don't worry about if your question seems "obvious". Everybody has been in your position. So I think you might want to look into a physics materials. (https://docs.unity3d.com/$$anonymous$$anual/class-Physic$$anonymous$$aterial.html) or use a rigidbody on the spinning arm and rotate it's rigidbody, rather than rotating the transform.

Show more comments
avatar image lgarczyn · Jan 10, 2020 at 08:26 PM 0
Share

This is misleading. AddForce(v, Force$$anonymous$$ode.VelocityChange) is exactly equivalent to rigidbody.velocity += v

avatar image aronthepalmer lgarczyn · Jan 11, 2020 at 05:46 PM 0
Share

Ah, didn't know that, only found that line on some random Unity video after deep diving YouTube. Thanks.
Annoying how some bits of information are hard to come by unless you look in some very specific location, takes ages to find these things the fist time, most of the time.

avatar image lgarczyn aronthepalmer · Jan 12, 2020 at 07:54 PM 0
Share

Oh absolutely. But yes, as long as you're not using a rigidbody's transform you're fine. Only exception is that setting a rigidbody's position is equivalent to a teleportation, not a move, and will mess with the interpolation and the collisions.

avatar image
0

Answer by Rati · Jan 09, 2020 at 09:08 PM

To make it work well, you should move your character by physics, and make the obs tacle moving by physics, too. if you just rotate the obstacle transform, his body never get the acceleration. it is just like if it was "teleported" with a new rotation.

(there is way to play and animation using the physiques too)

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 aronthepalmer · Jan 09, 2020 at 09:19 PM 1
Share

$$anonymous$$y player object is moved by physics, but I didn't know my rotating object had to be as well. Thanks, I'll go ahead and try to learn Unity Animations quickly to see if getting it to rotate that way will work.

avatar image lgarczyn aronthepalmer · Jan 10, 2020 at 08:27 PM 1
Share

The easiest way to do this would be to abandon animations (they don't mesh well with physics)

Ins$$anonymous$$d use a kinematic rigidbody with a script calling $$anonymous$$oveRotation every fixed frame, and the Continuous$$anonymous$$inematic interpolation.

avatar image aronthepalmer lgarczyn · Jan 11, 2020 at 05:53 PM 0
Share

I got it working a different way but I can imagine your way doing it better, I'll do some research and try it out.

Show more comments
avatar image
0

Answer by Bunny83 · Jan 10, 2020 at 08:39 PM

Even others have already mentions it in comments to other answers, I want to stress it as a seperate answer: Any moving object has to have a rigidbody component if you intend to have any sort of interactions with that object. Objects that are driven by your script should have a kinematic rigidbody. Kinematic rigidbodies are not affected by other objects but can affect non-kinematic objects.


A much more general rule: Never move or rotate a collider without being part of a rigidbody. Also keep in mind that rigidbody physics is about simulating rigid bodies. That means if a rigidbody consists of several child colliders, those child colliders should never move relative to each other. They should be rigid. Only the rigidbody object as a whole (the gameobject with the rigidbody component) should move / rotate.

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 aronthepalmer · Jan 11, 2020 at 05:51 PM 0
Share

Yes thanks, of all the places I search for information, this is never mentioned, but now I know it makes sense. Even in school we were learning basics and they failed to mention it there. This is a home project because I so enjoyed making my first game.
It should still be easier to come by this base information for knowing how basic game elements should interact. $$anonymous$$aybe I didn't look hard enough, but hours were spent searching for answers...

avatar image Bunny83 aronthepalmer · Jan 12, 2020 at 01:47 AM 0
Share

Well, all I just said is perfectly explained in the Rigidbody overview, the collider overview and the rigidbody manual

Since a Rigidbody component takes over the movement of the GameObject it is attached to, you shouldn’t try to move it from a script by changing the Transform properties such as position and rotation


There are some cases where you might want a GameObject to have a Rigidbody without having its motion controlled by the physics engine. For example, you may want to control your character directly from script code but still allow it to be detected by triggers (see Triggers under the Colliders topic). This kind of non-physical motion produced from a script is known as kinematic motion. The Rigidbody component has a property called Is $$anonymous$$inematic which removes it from the control of the physics engine and allow it to be moved kinematically from a script. It is possible to change the value of Is $$anonymous$$inematic from a script to allow physics to be switched on and off for an object, but this comes with a performance overhead and should be used sparingly.

Static Collider

This is a GameObject that has a Collider but no Rigidbody. Static colliders are used for level geometry which always stays at the same place and never moves around. Inco$$anonymous$$g rigidbody objects will collide with the static collider but will not move it.

The physics engine assumes that static colliders never move or change and can make useful optimizations based on this assumption. Consequently, static colliders should not be disabled/enabled, moved or scaled during gameplay. If you do change a static collider then this will result in extra internal recomputation by the physics engine which causes a major drop in performance

Parenting

When an object is under physics control, it moves semi-independently of the way its transform parents move. If you move any parents, they will pull the Rigidbody child along with them. However, the Rigidbodies will still fall down due to gravity and react to collision events.

avatar image lgarczyn · Jan 11, 2020 at 07:32 PM 0
Share

That said, there are some pretty amazing things you can do by breaking those rules. If you enable "animate physics" on an animator, you can get away with moving a kinematic rigidbody using an animation, and rigidbodies can now be children of another rigidbody, which allows for example easy moving platforms.

That said those things should not be done unless you understand what you are doing.

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

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

Problems with fast moving colliders 2 Answers

AddForce to a point of a GameObject, not the center 1 Answer

Camera gets flung off of the map when the player collides with certain objects. 0 Answers

Punching a crate 0 Answers

Imported 3D models collisions 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