- Home /
Question by
Sajjoo · Jun 01, 2011 at 03:20 PM ·
collisionspeedunityiphone
how to reduce the speed of bike when collide with side walls.
Hello guys, i am stuck in one place actually i am working on racing game in which i have a bike and on the road side i have fence. so when my bike hits the fence in speed it flies in air. i just want to reduce the speed of bike when it collide with the fence.
i have FixedUpdate()
method in which i have all my physics. and OnCollisionEnter()
method in which i am detecting the fence. where i set the speed to 0. but i want to reduce my speed. how do i send message to FixedUpdate method to reduce speed when it hits the fence.
thanks.
Comment
Best Answer
Answer by Anxo · Jun 01, 2011 at 03:33 PM
var hittingFence : boolean = false;
function OnCollisionEnter( other : Collider){
if (other.gameObject.CompareTag("fence"))
{
hittingFence = true;
}
}
function OnCollisionExit(otherObject : Collider){
if (other.gameObject.CompareTag("fence"))
{
hittingFence = false;
}
}
function FixedUpdate(){
if(hittingFence)
{
Bike.AddFoce(Vector3.forward *-1)
}
}
something like that.