- Home /
Projectiles, their speed, and collisions
Argh... I've been fooling around with a projectile object and almost got it to work. I've got a projectile that flies out at an (initial) speed of 500m/s. If it hits anything in the air, it will call its OnTriggerEnter()
function and if the collider's an enemy agent, it'll deal it some damage.
Alright, it sort of works. Almost because sometimes when the enemy agent is very close the trigger isn't called. That's one problem. I tried to fix that by making the collider large enough (10m at a fixed update of 50Hz), but still, since the trigger functions are called after all physics updates, the projectile will have moved considerably in that time span.
So I reduced the timestep to 100Hz, which kind of helps. Updates are more frequent and most times the enemy's collider is struck. But not all the time. Hmph.
A second problem is that since the collider is so large (and travelling so fast), if the agents are so placed: |Shooter||Victim||Wall|, the collider may actually trigger on the wall, which calls the Destroy()
on the projectile without ever calling the damage dealin' function.
A final problem is that the projectile's attached mesh renders right on top of the shooter if I instantiate it as close as possible (which, because of the other two problems, I need to do).
So what are my options here?
Reduce the timestep further? (Doesn't this hog the CPU?)
Have the bullets fly slower? (Wouldn't that be less than realistic? Nevertheless, if that's how it's done, that's how it's done).
Forget this high-speed projectile poppycock and go for raycasting? (Same as above).
Just a thought but you could have the projectile start out slightly slower and then speed up.
Not a bad idea. I was hoping for a cleaner solution though.
Answer by krisdamato · Apr 25, 2013 at 09:17 AM
I "fixed" this by raycasting back along the path of the projectile, using the distance it travels in one timestep to determine the length of the ray.
At first I thought it would be too expensive, but then again there's only going to be a handful of projectile at most at the same time. It seems to do the trick.
So you basically reinvented DontGoThroughThings, right? ;)
Your answer
Follow this Question
Related Questions
Bullet projectiles with collision info without affecting others 0 Answers
Collision occurring when it should not! Help! 1 Answer
How can i create a character like dragon hill game, Digging underground, what collider should i use? 0 Answers
Camera gets flung off of the map when the player collides with certain objects. 0 Answers