I’m very new to Unity and I’m working on a game that player has to push and pull objects.I can push the objects but I don’t know how to make the player pull them. If anything I’m using CharacterController.
private void OnControllerColliderHit(ControllerColliderHit hit)
{
Rigidbody _rig = hit.collider.attachedRigidbody;
if (_rig != null && Input.GetKey (KeyCode.E))
{
Vector3 forceDirection = hit.gameObject.transform.position - transform.position;
forceDirection.y = 0;
forceDirection.Normalize();
_rig.AddForceAtPosition(forceDirection * pushForce, transform.position, ForceMode.Impulse);
}
}
Also I’m not sure if I will make the player push and pull in one direction at a time, but if I have to do it that way, I’d like to hear some tips about it.