• 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 /
  • Help Room /
avatar image
0
Question by Lord_D1as · Dec 15, 2018 at 10:22 AM · unity 5rigidbodyrigidbody-collisionrigidbody physics

Rigidbody goes through an object

I have a player and it has attached a rigidbody. I use for a horizontal movement a MovePosition() function. But when I get to an object with the player and press keys to move it goes slightly through the object. Triggers are unchecked. I have already set rigidbody collision detection to Continous Dynamic, interpolate to extrapolate. But anyway a part of piece player goes slightly to the object. I would like to know if it is normal behaviour or which properties cause this problems of if there is any solution to avoid this issue.

https://imgur.com/a/btip6uH

There is moving script of the player: movingForward = Input.GetAxisRaw("Horizontal") * speed * Time.fixedDeltaTime; rb.MovePosition(new Vector3(0, transform.position.y, transform.position.z + movingForward));

Comment
Add comment · Show 4
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 Vega4Life · Dec 16, 2018 at 02:59 PM 0
Share

I have a sneaky suspicion you might be moving your character through Update(). When moving your physics gameObjects with a rigidbody, use FixedUpdate().

avatar image Lord_D1as Vega4Life · Dec 16, 2018 at 03:15 PM 0
Share

I use FixedUpdate().

avatar image Vega4Life Lord_D1as · Dec 16, 2018 at 03:49 PM 0
Share

Does the black box collider match its size? Can you link an image of the black one clicked?

Show more comments

1 Reply

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

Answer by Vega4Life · Dec 16, 2018 at 04:47 PM

After looking at your images and viewing your setup, this is a normal behavior against another gameObject that is static. Your situation becomes more problematic as the speed of the gameObject increases. Meaning - the more speed, the more it will penetrate.


I would assume as you hold the bottom down, it will stay penetrated. The second you release, it bounces back where you expect it to be. You are just fighting the physics solver. It is putting it back, but you just keep pushing it forward by the amount of movement forward applied.


As a not, you should use continuous here. Dynamic continuous is for rigidbodies hitting other rigidbodies. Continuous is for rigidbodies hitting statics.


Is there a way to solve this problem. Yes. You can lower the Fixed Timestep in the Time Manager. This will cost you CPU overhead.


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 Lord_D1as · Dec 16, 2018 at 05:24 PM 0
Share

Ok, I have set up the Fixed Timestep to 0.001 and change to CD - Continuous. It works much better but anyway smaller side of a player still goes to an object and it looks like the player is sticking on the object. https://imgur.com/a/ggQTjyy

avatar image Vega4Life Lord_D1as · Dec 16, 2018 at 06:06 PM 0
Share

I don't know why it's sticking like that. I don't think it's related to what we are touching. It could be a physics material on one of them?


So, I did suggest changing the Fixed Timestep, but let me explain what is actually happening here.


On your PC you are probably getting 60fps (unity uses the platforms defaults - 60 is pc). So that means, your getting a frame (1/60) around 0.016 a second or 16ms. Your default Timestep is 0.02 a second or 20ms. In this case, your physics update isn't one to one with your frames. Just going a little bit below 0.016 is probably all you need for Fixed (0.015ish).


With a 0.001 timestep, thats 1ms. At 16ms a frame, you are updating your physics around 16 times per frame. Yeah, you don't want that. Be careful when messing around with fixed timestep. :)


avatar image Lord_D1as Vega4Life · Dec 16, 2018 at 06:14 PM 0
Share

No, no there it is not any physics material and the Fixed Timestep works fine on 0.001. But thank you very much!

Show more comments

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

I want stop the rotation when the player run around 0 Answers

How to add gravity to imported objects? 1 Answer

Having a OnTriggerEnter make another gameobject Add Force in UnityScript. 1 Answer

How to set rigidbody velocity and angularVelocity to Vector3.zero over time? 1 Answer

Object shakes on collide! 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges