- Home /
Blocking a kinematic rigid body2D through collision with static and/or other kinematic object?
Hi everybody,
This is my first time asking a question here, hope to make it right! So I have been using Unity 2017 for some time and I was trying to create a 2D topdown game. I am having some issues with the collisions: basically I created my player as a 2D kinematic object with a capsule collider 2D and then tried to block its movement trough collisions with some wall, which I created as a 2D static object with an edge collider 2D. Since from what I understood a kinematic body should not be able to interact straightforwardly with other kinematic or static objects, I went to Edti>Project Settings>Physics and enabled kinematic static pairs, as well as ticking Use full kinematic Contact. But still, my player goes through walls and everything. I thought it was a layer problems, so I double checked the interaction matrix, but it was ok, same for the Z-position. As last thing I tried to debug trying to print something using OnCollisionEnter2D, and it actually detected the collision! So finally the question: is there a way to make such that a static rigidbody2D is able to block the movement of my kinematic rigidbody?
PS: Before using the edge collider2D, i tried as well with polygon and box collider, with the same results. I have also tried to set the walls as dynamic and clamping all their movement, but the result was that the player simply carried around the walls as if it was nothing LOL (i think it is due to the fact that a kinematic rigidbody is assumed to have infinite mass when colliding with a dynamic one).
Answer by hectorux · Nov 08, 2018 at 10:49 PM
What function are you using for move? Translate is a teleport and will make it pass through colliders, if you want to move a rigidbody try MovePosition in the rigidbody component
Answer by Sici9 · Nov 08, 2018 at 10:55 PM
I am actually calling it already in the fixed update:
private void FixedUpdate()
{
myRigidBody.MovePosition(myRigidBody.position + moveVelocity * Time.fixedDeltaTime);
}
Try to constrain all the axis, and set it to unkinematic, if this doesnt work sorry:¨(
Your answer
Follow this Question
Related Questions
How to get acceleration in a top-down angle 0 Answers
Spin a non-kinematic 2d object ? 0 Answers
Why doesn't Rigidbody.velocity.x = 0 in a collision? 1 Answer
I need help with rigidbody and collision or something idk 2 Answers
2D Colliders stops working at random despite rigidbody, OnMouseDown not called 0 Answers