# 2D physics without "rebound"

I'm trying to get my 2D top down shooter to use -some- physics.

I want the player and enemies not be able to exist in the same position, in other words, use collisions.

My first attempt was to use a CharacterController, but I could not get my other game objects to collide with my player, even though I had a RigidBody2D and a BoxCollider2D on them. Obviously, due to using a CharacterController, I was not able to add these components on my player.

Going one step back, I removed the CharacterController, and rather opted to go the Rigidbody2D route. This worked partially. I now get collisions on my player when he walks into other gameobjects (with RB2D and BC2D on them), but there seems to be a "rebound" anomaly occurring; my player moves around after collision.

I've tried playing around with the settings on the RigidBody2D on the player, but it does not seem to have any effect.

This is my PlayerMovement script :

void Update()
{
HandleRotation();
HandleMovement();
}

void HandleRotation()
{
var mousePos = Input.mousePosition;
mousePos.z = 5.23f;

var objectPos = Camera.main.WorldToScreenPoint(transform.position);
mousePos.x -= objectPos.x;
mousePos.y -= objectPos.y;

float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
}

void HandleMovement()
{
float horizontal = Input.GetAxisRaw(Constants.Axis.Horizontal);
float vertical = Input.GetAxisRaw(Constants.Axis.Vertical);

Vector3 direction = new Vector3(horizontal, vertical, 0f).normalized;

if (direction.magnitude >= 0.1f)
{
var speed = (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
? mobileController.runningSpeed
: mobileController.walkingSpeed;
var moveVector = (direction * speed) + transform.position;
mobileController.rigidbody2d.MovePosition(moveVector);

var camPosition = new Vector3(mobileController.transform.position.x, mobileController.transform.position.y, -10);
cam.position = camPosition;

}
}


The settings on my Player :

I would like my player to stop dead in his tracks when colliding with another RigidBody2D. Is this possible? And if so, how would I go about doing that?

• How have you configured the physics material on your player's collider, and how are you moving your player/enemies in script? Jan 9, 2021 at 13:20
• @DMGregory, thanks again for replying! Please see the edits on my post Jan 9, 2021 at 13:24