x


Arcade Physics and colliders

I'm doing a top down space shooter type game, and I need the player to react to everything in different ways.

  • For walls, collide and stop movement (unity handles this well with a primitive collider for the wall)
  • For projectiles, damage and brief invulnerability(which is easily handled with scripting), but I do not want the player to be pushed in any way at all, but I still need to detect the actual collision
  • For enemies, I'd like a slight bounce of each other, but nothing too crazy(maybe larger enemies not moving at all)

So what are the best colliders to use? I've tried primitive + Rigidbody with isKinematic = true, this gets me close, but I go right through static walls, and movement with transform just doesn't seem as smooth as adding a force to a rigidbody. Sorry if this question seems long.

more ▼

asked Feb 04 '10 at 04:36 AM

dhendrix gravatar image

dhendrix
2.2k 25 34 59

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

I'd probably do this:

Walls
Yes, primitive colliders are good. Also good is the 'mesh' collider, with its 'static' setting enabled, if your environment is built in an external 3d app. If your environment has complex geometry, you might find that you want to use simpler invisible 'proxy' geometry for the collisions, while still displaying the more complex meshes as the graphics.

Projectiles
If you don't want the projectiles to actually push the player when they hit, use triggers (as has been mentioned in another answer). You can then apply damage and destroy the projectile in the OnTriggerEnter function. Of course there's nothing stopping you from also applying a force in that function - eg, if the projectile is supposed to be explosive, there's even a specific physics function to AddExplosionForce which you could use here.

Enemies
It sounds like you want to create a custom physics material which has a very low value for "Bouncyness". Just use the "Create" menu in the project pane to create a new one, set your settings, then drag it on to the enemy gameobject. It should automatically be placed into the collider's material variable.

Hope this covers everything.

more ▼

answered Feb 04 '10 at 10:04 AM

duck gravatar image

duck ♦♦
41.4k 95 152 415

(comments are locked)
10|3000 characters needed characters left

Just a thought on the player-projectile collision: From what I've seen in other engines --> a problem that the high speed of the projectile could be an issue that it could actually pass through the player/target/etc. between two frames (or physics steps) and collision is not registered. How about ignoring collision (link) between projectile and player and casting a ray instead and triggering your damage and invulnerability this way? Just a thought, so don't mind me if that's not what you want.

more ▼

answered Feb 04 '10 at 05:27 AM

Sebas gravatar image

Sebas
4.1k 12 18 45

Actually, I think I'll just set the projectiles as triggers, don't know why I didn't think of that before. That solves one of my problems.

Feb 04 '10 at 05:51 AM dhendrix

I agree, rays is the way to with projectiles.

Feb 04 '10 at 03:03 PM Jademyr
(comments are locked)
10|3000 characters needed characters left

You can't use isKinematic = true if you want the object to respond to collisions at all.

Would there be any problem in just using a ridigbody (with isKinematic = false) and moving the ship by applying forces? When your projectiles are triggers they shouldn't cause the ship to move.

more ▼

answered Feb 04 '10 at 09:50 AM

runevision gravatar image

runevision ♦♦
8.1k 29 46 112

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2584
x1947
x1765

asked: Feb 04 '10 at 04:36 AM

Seen: 2388 times

Last Updated: Feb 04 '10 at 04:36 AM