- Home /
How often do Raycasts check for collisions?
I've put in a raycaster in my Update function. Now supposedely, these should run every frame.
The point of this raycaster is to check if the player has walked over a bonus game object (so basically, if the raycast hits a bonus tile, which is on the floor, he picks it up).
What happens is, sometimes it just completely ignores the bonus and walks over it. Its completely at random, and generally happens when the player is at a much higher speed. The fastest speed that my player can go at is 9 spaces per 0.5seconds, and the slowest being 1 space per 1.5second. The speed is calculated using an input algorithm
So the basic problem is, the player just ignores the bonus object once in a while, generally when at a faster speed.
Do raycast checks have a delay in them? Is there a way to fix this?
As FP writes, raycasts are code, so happen right away. It's like asking when x=x+1;
happens.
In your case, many people use Triggers for pickups. For raycasts (and triggers) you often have to adjust the size. $$anonymous$$aybe use a wider raycast (sphereCast) or make the target area wider. Raycasts have a lot that can go wrong, and often need lots of prints to test.
18 spaces/sec is 0.33 spaces/frame at 60fps, so you probably aren't "jumping" the pickup, but your move code could be messed up.
Or, if your game really is spaces, just use math to figure which space you're on, and see if that space has a pickup.
Answer by Freaking-Pingo · Nov 03, 2013 at 10:20 AM
Raycast doesn't have any delay within itself. I presume you are using the RayCast in the void Update();
method. void Update();
is called for every frame. Instead try implement your raycast in a void FixedUpdate();
loop instead. The void FixedUpdate();
is executed at a particular time instead of each frame and is often used for physics handling because its time of execution is independent of the framerate.
Pleas correct me if I am wrong, because I am not completely sure my intepretation of FixedUpdate is correct.
Your answer
Follow this Question
Related Questions
How to Fix a Guns Firing Script so it Doesn't Constantly Fire 3 Answers
door that closes by itself 2 Answers
Is this way of making a raycast correct 2 Answers
Mouse Over Questions 1 Answer
2D Raycast not working 1 Answer