Well, it seems as though my little script stopped working after the update to Unity 5. This may very well be a simple problem…again, so I’ll give you some details on how everything’s set up.
Kinematic is off
Gravity is on and set to y -1e-05
The object is awake.
There are about half a dozen colliders overlapping the ball, however most of them are set to trigger except for the collider that the ball rests on.
When addForce is applied, the ball moves for 1 frame and the velocity shows a vector other than zero. After the first frame, the vector returns to (0, 0, 0).
Here’s the code. Thanks in advance for all of your help.
#pragma strict
var GravityObject : Transform;
var GravityState : boolean;
var InitialVelocity : float;
var Ship : Collider;
internal var MouseIsDown : boolean;
function Start () {
transform.position = GravityObject.position;
}
function Update () {
if (GravityState) transform.position = GravityObject.position;
if (Input.GetMouseButtonDown(0)) MouseDown();
if (Input.GetMouseButtonUp(0)) MouseUp();
print(GetComponent.<Rigidbody>().IsSleeping());
}
function MouseDown () {
var Raycast : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var TheHit : RaycastHit;
if (Ship.Raycast(Raycast, TheHit, 100.0)) {
MouseIsDown = true;
}
}
function MouseUp () {
if (MouseIsDown && GravityState) {
GravityState = false;
MouseIsDown = false;
GetComponent.<Rigidbody>().AddForce(Vector3.up * InitialVelocity, ForceMode.Impulse);
}
}