- Home /
Player sprite clipping through game boundary in 2d scene
Hello,
I'm a newb learning Unity and working on a Geometry Wars clone project. I'm having an issue where my player ship is clipping through the game boundary if I continually attempt to pass through it moving back and forth. Here is a video of the issue in action:
My boundary has a Box Collider 2D attached to it and my player ship has a Rigidbody 2D. My player movement function is quite basic:
private void movePlayer()
{
Vector3 movement = new Vector3(inputDeltaX.Value, inputDeltaY.Value, 0) * speed.Value * Time.deltaTime;
Vector3 newPosition = transform.position + movement;
rigidBody.MovePosition(newPosition);
}
Boundary Box Collider 2D settings:
Player ship Rigidbody 2D:
The player_collision material has a friction and bounciness value of 0.
My theory about the issue is that because I'm manually setting the transform of my player ship on update, the updated position is within the bounds of the boundary. The physics system tries to process this as a collision and sometimes ends up pushing the player out through the other side of the boundary.
Can anyone confirm if this is what could be happening, or is there anything obvious I'm doing incorrectly here? Thanks for your time.
Answer by arrowmaster1252 · Feb 12 at 07:00 PM
The problem is most likely that it has enough speed to move through the wall. You could have the collider for the walls be bigger, or do some brute force methods and just if you are out of the bounds push the object into the bounds.
I was thinking that I may have to brute force it. Calculate if the ships updated position falls outside of the valid area, and adjust as necessary. Thanks for the response.
Your answer
Follow this Question
Related Questions
2D box collision not working,2d Box Collider not working 0 Answers
Platformer2D Player sticks to platform corners 0 Answers
Object passes through collider even when isTrigger is turned off. 2 Answers
Character input works but gets dragged back for no reason 1 Answer
Why is my quad not moving in sync with its collider? 1 Answer