[Solved]Ray cast isnt triggering and problematic šŸ˜£

Ray cast condintion isnt triggering
The picture below shows the events that do not trigger.

Picture

The proof is the log messages is never to be found in the console except the first one in the loop action that contains the following text:

Found node with a matching id.

Iā€™m tired. Raycast is very problematic. I canā€™t get it to work.

I also want to note that raycast uses scene variables although local variables do exist and I think itā€™s pretty limiting because now youā€™re forced to use one type of variables instead of the three available type of variables global scene local

I went on a bit but Iā€™m trying to cover all of the bases.

What is the current node ID? Iā€™m going to assume the nodes are numbered. If thereā€™s only 1 node with that ID then thatā€™s the only node that currently gets checked because the ray cast is a subevent of that event. If thatā€™s the case I donā€™t know why it has a for each object

If you want to check all of the nodes then you need move the events out of the for each object to their own subevent so itā€™s even with the ray cast events.

For each
ā€” id equals
ā€” ray cast

That way the ray cast event gets triggered when the IDs donā€™t match. IDK if thatā€™s your intention. I donā€™t think you want to check previous nodes. That would be behind the car. Maybe just nodes greater than that current node. Again, Iā€™m not clear on the process. It becomes slightly tricky when the nodes reach the last node and starts back at 0. The next node would be 0 not greater than the last.

Note: when a ray cast is inverted unlike most conditions it doesnā€™t become a negative condition in the way that an inverted collision condition becomes not in collision. An inverted ray cast condition becomes ā€œpick the farthestā€ instead of the nearest. Since itā€™s inside a for each object itā€™s only checking 1 object at a time and possibly only 1 object bc of the ID event. That object would always be the nearest and the farthest because itā€™s the only object being looked at.

If you want to know if the ray cast found something you can add a boolean variable. Set it to false before the ray cast and add the action to the ray cast event to set it to true. Or you can compare the x,y result values and see if theyā€™re the same values. I prefer the boolean. Itā€™s less vague as to the purpose.

Since inverting a ray cast doesnā€™t work like other events, you can put it inside the Not condition. That would invert the result. If the condition was true the Not would make it false. If the ray cast returned false then it would return true and trigger any events.

Each event uses resources and time. The ray cast uses more than other conditions. Unless, youā€™re checking for the nearest and farthest object from within a list of objects then both events arenā€™t needed.

If you want to know if the ray cast is false then you can use the variable approach. You donā€™t need to use both a ray cast and a ray cast with a Not condition because the first ray cast already checked for the object. Thereā€™s no need to check it twice. The variable approach uses less resources then a 2nd ray cast inside of a NOT event.

I mentioned the NOT condition as a way to explain the difference between inverting it. Itā€™s best to either use a ray cast or use a ray cast inside of a NOT condition. It depends on the projects needs. Theyā€™re both checking the same thing. So, only 1 needs to be done. You can check if that event failed or succeeded with one of the variable approach. Thereā€™s no need to do it twice.

I agree with you that the variable return values should be able to use any variable type especially as they simplified the variable system to treat variables more as equals.

1 Like

Dunno what happened to you.
In my game ii have many raycasts and all of them woirks fine.

Thanks so much, anonymous human, @Keith_1357

After I added Not then the ray cast it worked, I didnā€™t know that inverting doesnā€™t invert its result.
To be honest, I do not know if I will post again about ray cast not working, I feel ashamed to be frequently asking for help.


Current node ID is the object variable of bot, bot will follow the node with that ID, if the bot is near the node by 30 px, it will go to the next one.
It has for each object because not all tracks would have one node with one ID.

Is it really resource intensive?

since my problem is solved you wouldnā€™t care much, but if you are interested, here is a short summary of how the bot system works:

Details of bot system

Nodes serve as waypoints that guide bots through a predetermined path. Bots move in a sequential manner, following a linear trajectory between nodes (1, 2, 3, etc.) until they reach a node marked as the finish point. At this point, they redirect to the node with ID 1, continuing in a straight line. The ranking system relies on these nodes to determine the winner, using them as a reference point to identify the first-place finisher.

Hopefully its fixed in later versions

Itā€™s all relative. Computers and devices are getting faster every day but still sometimes every second of processing time counts. Itā€™s just good practice to do things in the most efficient way from the start just in case your project should push the limits of the system itā€™s running on.

Everything gets multipled. One ray cast isnā€™t much but then it gets multipled by the number of objects using it and then again by the number of objects that it needs to test against.

Again, systems are able to process a lot but thereā€™s a lot to process and one event might not use a lot but when every second counts it might be the second that another event might need.

I wouldnā€™t be overly worried if the project isnā€™t too complex. Itā€™s just better to be efficient from the start instead of having to look for ways to streamline it later should there be any issues.

2 Likes

And how will you learn? Ask away, I say. If youā€™ve tried things and hit a brick wall, then youā€™re perfectly entitled to ask for help.


Thank you for this, hopefully itā€™ll help someone else whoā€™s trying to figure out how to simulate AI following a path. Will you look to upgrade to a ML type technique in a future release, once youā€™ve got your the first prod version of the game out?

1 Like