• Register

A group dedicated to indie and standalone game development.

Post tutorial Report RSS High speed projectile fun

Unity doesn't like high speed projectiles very much. There's some settings you can tweak to make the physics system handle them a wee bit better but they will never be able to fully correct one of the major issues...

Posted by on - Intermediate Client Side Coding

Unity doesn't like high speed projectiles very much. There's some settings you can tweak to make the physics system handle them a wee bit better but they will never be able to fully correct one of the major issues, which I will call "frame skipping" (I'm sure the name is used somewhere else but that's what we're going to call it here).
Excuse my poor drawing skills by the way.


Slinki's boomerang doesn't travel all that fast so we tried to rely on the physics system and give it some tweaks here and there to make it behave more neatly. Unfortunately it still ended up failing and you can sometimes see the boomerang simply go through enemies and some obstacles 1 out of 10 times.

So what could we do? Usually for first person shooters and such we don't move a really fast bullet towards an opponent, we just cast a ray every time a bullet exits the barrel and see what it hits. The effects are just that: effects.

Slinki's boomerang isn't actually moving THAT fast, it exists in the game world so we decided to use a hybrid approach. Every time the boomerang moves we project a ray between it's current and next position.


Then we take the first object we collided with, take the collision point and place the boomerang there. As an extra, we change the boomerang's movement vector to represent a ricochet according to the impact point's normal.


We are currently exploring these mechanics to look into potential puzzles we can offer the players. Like ricocheting the boomerang between walls to hit levers.

Post comment Comments
tiagofabre
tiagofabre - - 3 comments

Did you try use only add force and rigibodies with continuous collision detection?

Reply Good karma Bad karma+2 votes
Crushy Author
Crushy - - 2 comments

Hey, sorry about the late reply (didn't get a notification).

We tried using the normal physics system and continuous collision but it still had flaws when moving really fast.

Docs.unity3d.com suggests it should at least work for static meshes but we still had instances where level geometry was being intersected around 1 out of 50 times, which might let you bypass puzzles.

AddForce also wasn't very useful for us as the boomerang didn't really obey the actual laws of physics in any way.

Reply Good karma+1 vote
tiagofabre
tiagofabre - - 3 comments

How are you moving the objects? are you setting up a new vector3 to the transform on Update?

Reply Good karma Bad karma+1 vote
Crushy Author
Crushy - - 2 comments

Exactly, we also use FixedUpdate to do the raycasts (mostly because we can, I don't think there's a reason you can't use the regular Update).

I would paste a code snippet but it's highly specialized as we have the Boomerang slowing down as we reach it's maximum distance and things like that. Maybe one day if we work on more conventional projectiles we'll have a neater version of this.

Now if you'll excuse me I'm going to figure out why the hell I'm still not getting notified on replies (sorry about that).

Reply Good karma+1 vote
Guest
Guest - - 688,627 comments

This comment is currently awaiting admin approval, join now to view.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: