playMaker

Author Topic: Bullet with Collider/Trigger or Raycast?  (Read 7840 times)

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Bullet with Collider/Trigger or Raycast?
« on: December 15, 2015, 07:25:20 AM »
Hi!

What is the best solution? I have a bullet with Raycast, but the bullet go through the walls if the bullet is too fast. Will it be better to use a trigger?
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Bullet with Collider/Trigger or Raycast?
« Reply #1 on: December 15, 2015, 07:45:46 AM »
Just a little update!

I created a new scene, one bullet, one wall.
On the bullet, I have a Collider and a Rigidbody.
I have one FSM on the bullet with only the Action Translate to move the bullet. I tried with 5 in the x field first to move the bullet to the right. And it stopped on the wall. I tried with 25. The bullet just went straight through the wall. Why? It's not THAT fast!
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Bullet with Collider/Trigger or Raycast?
« Reply #2 on: December 15, 2015, 08:59:05 AM »
First thing: If you're going to move rigidbodies really fast and need high quality detection then you need to put the collision detection to Continuous Dynamic.

Second: If you are using Translate then I don't think the physics system will actually pick up the change. Try the first change, then see if it works with Translate. If not, you'll need to use Rigidbody MovePosition or something physics based.

The reason is because the physics engine does a lot of internal optimization and it tries to ignore rigidbodies that don't need to be updated whenever that is possible and the physics based movement commands will flag that rigidbody to be updated while basic Translate does not do this (iirc! It might have changed in 5.0+ with PhysX 3.3!) so its common to see stuff slip through the cracks when mixing translation types like this.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
Re: Bullet with Collider/Trigger or Raycast?
« Reply #3 on: December 15, 2015, 09:20:05 AM »
I tired this on my projects over and over. No matter what I do the "bullets" always go thorough walls no matter what when the force on a ridget body os set to high.

In the end i just use ray casting which actually detects objects a lot better. Only thing is its to accurate. But i am experimenting on how to set up recoil.

Also I am looking into maybe i can use a particle system which detects cillsion and sends fsm events that way.

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Bullet with Collider/Trigger or Raycast?
« Reply #4 on: December 15, 2015, 11:28:13 AM »
First thing: If you're going to move rigidbodies really fast and need high quality detection then you need to put the collision detection to Continuous Dynamic.

Second: If you are using Translate then I don't think the physics system will actually pick up the change. Try the first change, then see if it works with Translate. If not, you'll need to use Rigidbody MovePosition or something physics based.

Hi!

I set the Rigidbody to Continuous Dynamic, but it didn't work.
I tried Rigidbody Move Position. But this has no option for the speed of the object, so I didn't understand how this could help me.

I also got another tip to go to Edit/Project Settings/Time and change the Fixed Timestep to a lower value. It was 0.02. I changed it to 0.001. It worked very well. I don't know how bad for the game it is to change it! I tried with iTween Move with the speed of 150 and Fixed Timestep to 0.001! The bullet detected the collision everytime!


In the end i just use ray casting which actually detects objects a lot better. Only thing is its to accurate. But i am experimenting on how to set up recoil.

I also tried with Raycast, but it doesn't always detect the Raycast on highspeed objects!
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
Re: Bullet with Collider/Trigger or Raycast?
« Reply #5 on: December 15, 2015, 06:25:19 PM »
I don't understand. so when you raycast like shooting a weapon. the ray still goes through the object?

What I forgot to add is when I use ray casting I do not use kind of objects to be the bullet or tracers. I just use the raycast as the detaction of the bullet fired, and then I take the hit location, and spawn a bullet impact in location the ray cast hit the object. you can how ever use the liner render to spawn a line to give the illusion of tracers. 

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Bullet with Collider/Trigger or Raycast?
« Reply #6 on: December 16, 2015, 04:32:57 AM »
What I meant, is that the state with the Raycast, doesn't goes to the next state when the Raycast hits an object when the bullet is too fast. So yes, the bullet still goes through the object. But when I changed the Fixed Timestep from 0.02 to 0.001, it works fine.

On my Raycast I store Did Hit in a bool variable and use Bool Test and send an event if it's true. And in Layer Mask, I use the Layer Default.
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
Re: Bullet with Collider/Trigger or Raycast?
« Reply #7 on: December 17, 2015, 12:05:48 AM »
Oh ok. What i do with my weapon systesm using the ray cast is store the object it hits, then in an other action actually take the object it hit and compare the tag, so if its a certain tag it will send events based on that the ray cast hit

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Bullet with Collider/Trigger or Raycast?
« Reply #8 on: December 17, 2015, 01:46:50 AM »
It's many ways to do it, so as long as it works! :)
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no