I’m working on a project that involves simulation. I created some cars and the road network, but i need the counters on the road to read the cars and add 1 to a counter variable. WHat do i do. I’ve already created raycast colliders on the car but collision is not been noticed.
The grey strips are the counters.
Hi, welcome to the forum!
Would I be right in thinking you are using wheel colliders for the cars? These are not really colliders in the strict sense but are actually implemented using raycasts. Since there isn’t a “solid” collider involved, another raycast won’t pick up the position of the wheel. You could fix this by performing the induction loop raycast higher above ground so that the main body of the car crosses the ray rather than just the wheels.
I really don’t understand how to create an induction loop raycast.
I created a raycast for the car, it was not properly done.
Here’s what i did.
- I created a raycast component for my car object. I then set the center / Y variable at 1.07 which is a height where the raycast causes a vibration in the vehicle.
What i want
- A method for the vehicle to communicate to each counter individually as each of those counters have different purposes. It doesn’t have to be a raycast. any other method would be greatly appreciated
- I’d prefer if i could get help with a script that allows the car notify the counter of it’s presence without resorting to raycast as it is actually going to be judged brutish. I also don’t think it would be able to report he speed of the car
Warning: I am not exactly sure what an inductive loop system is, and how that works.
- Would you be able to use a trigger collider box (stretching that in height)?
Are you trying to somehow simulate an actual induction loop or do you just need to know when the car model crosses the white lines in your road?
If all you need to know is that the model went past, you can create a box, make it fill the lane and be as high or higher than the car, and make it a trigger. Make sure you turn the mesh render off so it is invisible to the player. Then you handle the counting code there. (With some sort of sanity check to make sure that you don’t register a car over and over if it sits there or moves slowly back and forth.)
If you actually want to simulate an induction coil where a current is generated because of the big metal object moving over the loop buried in the roadway… I really don’t know how to answer that because it would depend on just how detailed you want the simulation to be.
Yeah. that’s all i want to do.
I’ve tried it.
When i try to get the car past it the car collides. ( i’m sounding like a terrible newbie “i’m not” but i felt that would not really achieve it cuz i have cars of various sizes, including a GMC Typhoon, A jaguar XKR , a classic dodge charger( Bullit). they are of varying heights and even though the countach can pass cuz it’s really low, i doubt the 206GTI or the XKR can pass.
Instead would it be better if i created the box overhead and attached raycast to it. If i do, how do i get the cars to ignore the collision and also get the raycast to increment the counter variable.
Tnx
No need for a raycast than, just create a trigger collider with an arbitary height bigger than you tallest car.
Simplified Answer:
Trigger Colliders are practically ignored by the physics engine. (Somebody is going to slap me for this)
They will not enact any force on the colliding object, but will still send out specific OnTrigger Collision Messages.
#Edit: Make sure to tick the Is Trigger Checkbox on the Collider for the Counter
THanks hallamasch.
I wrote the ffg
var Cars_On_Street;
function OnCollisionEnter()
{
- if(hit.collider.gameObject.tag ==“car”)*
- {*
- Cars_On_Street++;*
- Debug.Log(“”+Cars_On_Street);*
- }*
}
The code doesn’t seem to work. I know the problem is with the hit. I declared it as a raycast before and then adapted the code to work for the trigger collider. Op you could help me with the unbugging. TNX
The Important Part is to have your Collider set as a Trigger.
And then handle the Trigger Messages.
See the Scripting Reference for them
Your Code is not working, because your Trying to handle non Trigger Messages.

