Hello mates,
I made a car game. I tried to make the car moves faster when it is on the street, and slower when it is on the terrain or grass. but it does not work because I could not know how to tell the if statement about the colliders that I am using.
if () // here is the problem
// I tried to use something like (collider.name == “terrain”)
// but it also does not work because it did not recognise what happen to it and which collider is touching it
{
maxSpeed = 250;
}
else
{
maxSpeed = 100 ;
}
I also tried, function OnTriggerEnter(other : Collider)
but the way I did it could be wrong
I did not know how can I search for such as this problems in unity website
If you want to do it with collision detection you’ll need to tag your “street” and “terrain” then attach a similar script to your car (make sure all these objects have a collider component)
Don’t use colliders for this, instead use physic materials. Create a physic material for your street and for your grass, and play with those values untill you get the right effect. I recommend using gameObject.rigidbody.AddForce(); for your movement and letting the physic material do the rest.
thanks both of you for trying to help me.
I tried what u said but the problem is the fact it is not recognizing the car. I tried doing something smiler and easier like collecting the money. but it also does not work. the car just pass the through the money and its not collected. the money collier is on trigger. the car is tagged as (Player)
function OnTriggerEnter( other : Collider ) {
if (other.gameObject.tag == “Player”) {
Destroy(other.gameObject);
}
}