I have the following code in a script for a 2D game in the XY plane
function FixedUpdate () {
// Make sure we are absolutely always in the 2D plane and with the right rotation.
transform.position.z = 0;
transform.eulerAngles= Vector3 (270,0,0);
}
function LateUpdate () {
var realWorldPosition: Vector3 = Camera.main.ScreenToWorldPoint (Input.mousePosition);
var gamePosition: Vector3 = Vector3(realWorldPosition.x, realWorldPosition.y,0);
transform.position = gamePosition;
}
function OnCollisionEnter (collision : Collision) {
var forceDirection:Vector3 = -1*collision.contacts[0].normal;
collision.rigidbody.AddForce (forceDirection * pushPower, ForceMode.Impulse);
}
The GameObject this is attached to moves with the mouse and applies a force to any collider it encounters. The thing is, once a collision occurs, the attached gameobject becomes all jittery for a while. It then goes back to normal, but it's annoying.
I've set infinite linear and rotational drags to its rigidbody, but it doesn't work.
I have no idea how to solve this.