Hello Guest

Author Topic: Fast Object's (bullets) not colliding  (Read 5140 times)

sfbaystudios

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 40
    • View Profile
Fast Object's (bullets) not colliding
« on: January 03, 2013, 05:24:06 am »
I swear I saw a post on this before, but I can't seem to find it.

I've got bullets that move fast, and often they skip the collider and go right through walls.  I've added a RayCast to them, as often suggested in the Unity forums, but that also misses it sometimes, so if you shoot at the right angle, you can still skip the walls.  I've even gone so far to add a 2nd ray cast to judge the distance between the projectile and a "wall" object, and destroy it if it gets too close, but often the ray doesn't even see the object, even though it's part of a tile set without any spaces.

Any one know how to fix this?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Fast Object's (bullets) not colliding
« Reply #1 on: January 03, 2013, 11:38:04 am »
In all the cases I've used raycasts for, they have been near enough perfect for me. Perhaps someone else has more experience with this issue than me?

sfbaystudios

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Fast Object's (bullets) not colliding
« Reply #2 on: January 03, 2013, 09:02:19 pm »
Using raycasts makes it happen less often, but it seems at sharper angles the bullet will still go through.

Likely the raycast isn't long enough -- at a sharper angle it needs to be longer to actually hit the edge of the ground object, or the next frame it may be too far past to register.  Unfortunately the longer the raycast, the further out it registers on flat surfaces, which looks silly when the bullet is destroyed too far away from a wall.

cokerms

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Fast Object's (bullets) not colliding
« Reply #3 on: January 07, 2013, 04:00:16 pm »
Maybe you use a long raycast and when you get the hit detection back, you don't immediately destroy the object but use the hitinfo & velocity to determine at what time the impact will happen and then use a countdown in your update to destroy at the right time.