Reputation: 7
How can I stop the object from running after spawning to checkpoint?
function OnTriggerEnter(col : Collider)
{
if(col.tag =="Player")
{
SpawnPoint.position = Vector3(transform.position.x, transform.position.y, transform.position.z);
}
}
Upvotes: 1
Views: 251
Reputation: 837
I found this over at answers.unity3d.com
What you should do is briefly set the rigidbody to kinematic, as well as brakeTorque
for all wheel colliders to Mathf.Infinity
and than next update switch it back off and the physics engine should reset any forces causing it to move.
Example from link:
function FixedUpdate()
{
// (if the vehicle has been respanwed this frame,
// then a variable respawned is set to true)
if (respawned)
{
wheelCol.brakeTorque = Mathf.Infinity; // Repeat for all wheelcolliders
rigidbody.isKinematic = true;
respawned = false;
}
else
{
rigidbody.isKinematic = false;
// (do the torque calculations here as usual)
}
}
Upvotes: 1