playMaker

Author Topic: best action to move a bullet at high speed ?  (Read 9882 times)

invayne

  • Full Member
  • ***
  • Posts: 105
best action to move a bullet at high speed ?
« on: April 19, 2015, 09:23:52 AM »
as it says im trying to figure out which is best for moving a bullet in the directions its being fired at a high speed

FrankDePaul

  • Playmaker Newbie
  • *
  • Posts: 25
Re: best action to move a bullet at high speed ?
« Reply #1 on: April 19, 2015, 10:39:19 AM »
I would like to know opinions on this also. I am also wondering if Create/Destroy is the best method for spawning bullets.

Any ideas?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: best action to move a bullet at high speed ?
« Reply #2 on: April 19, 2015, 10:59:19 AM »
Use the Create Object action. A Pooling system will improve optimization. If you are firing them at very high speeds then you will run into the "bullet through paper" problem.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

invayne

  • Full Member
  • ***
  • Posts: 105
Re: best action to move a bullet at high speed ?
« Reply #3 on: April 19, 2015, 11:07:43 AM »
that doesnt help my problem  i need to know which action will move it in a straight line from the point of creation  depending on which way the z axis is pointing at a high speed...

FrankDePaul

  • Playmaker Newbie
  • *
  • Posts: 25
Re: best action to move a bullet at high speed ?
« Reply #4 on: April 19, 2015, 11:08:55 AM »
I am starting to see the bullet collision issues. At times it takes 3 or 4 hits to register.

Invayne, I am using the Move Towards behavior. Not sure it is the best, but I can use a game variable object as my target. This way I can switch targets on the fly.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: best action to move a bullet at high speed ?
« Reply #5 on: April 19, 2015, 11:13:16 AM »
Use Add Force if you're working with rigidbodies, Translate otherwise.

Anything moving super fast is usually done with Raycasts because you never really see the object before it hits.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

invayne

  • Full Member
  • ***
  • Posts: 105
Re: best action to move a bullet at high speed ?
« Reply #6 on: April 19, 2015, 11:23:07 AM »
yeah need a solid object in order to  have collision  working properly so using triggers instead which is less heavy. raycasting dosent hit collision triggers properly so cant grab tags  set up on the enemy's body.  raycast works if your doing a solid  collider  but i need to hit differnt parts of the body with specific tags. ill test these out thanks

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
Re: best action to move a bullet at high speed ?
« Reply #7 on: April 19, 2015, 05:25:36 PM »
I am too running to collision problems, sadly I spend hours and hours trying to find a "fix ; but at high speeds the object do go through object collsions.

What I did that kinda works is make the billet object trigger collision bigger. It helps some what, BUT it can be to big that it will collide with other objects that it touches.

Ray casting is really a solid way on making bullets hit their target dead on with no issue. Only thing is I have no idea how to make bullet particles spawn and fly along the ray cast.

FrankDePaul

  • Playmaker Newbie
  • *
  • Posts: 25
Re: best action to move a bullet at high speed ?
« Reply #8 on: April 19, 2015, 05:37:57 PM »
I think that will have to be my option also. Even slow moving missiles miss at times. I am not sure about raycasting with a turret in 2d. Not many tutorials out there.  :(

I wold be happy to be able to spawn a bullet in a certain direction and just have it go, but this seems to be difficult in 2d. I am sure I will find a way, just sucks spending hours trying to get this to work and it fails.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: best action to move a bullet at high speed ?
« Reply #9 on: April 19, 2015, 05:58:28 PM »
Regarding the bullet through paper issue...

The problem lies in the way the object is moved and the collisions are detected. If a wall is 1 unit thick but a projectile is moving at 3 units per frame then it is very likely to be seen on Frame 1 on one side of the object, then when the position for it is calculated on Frame 2 it is already on the other side of the object and never registers a collision on the wall because it literally never collided with it. The 'speed' is how many units per second something moves and movement is just a change of position so this is a fundamental problem where the two objects never collided and therefore don't register a collision.

One fix that is cheap is to make the collider longer. This can work, but is awkward to work with sometimes. It makes it so that when the situation above does occur, the collider tail is long enough to touch the object that it passed through. This can make all of your collision data unreliable because the projectile would be registering a hit from the other side of the object it passed through.

I generally fix this by Raycasting from the last position to the current position every frame.... If the raycast hits anything then I know that it went 'through' something and I just stop it there and register the hit. This works fine for objects that are traveling very fast but can still be seen... however this can eventually get costly with all the raycasting happening on top of the regular projectile calcs..

If your objects are going super fast and cannot be seen then there is no reason to spawn something physically visible. The best solution is to just raycast from the barrel, forward... This is completely reliable and best for instant hit type things like actual bullets that are obviously going to fast to be observed. You can draw a line renderer or trail for these and see the effect of the projectile and it is common practice to do that.
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: best action to move a bullet at high speed ?
« Reply #10 on: April 19, 2015, 10:15:30 PM »
Regarding the bullet through paper issue...

The problem lies in the way the object is moved and the collisions are detected. If a wall is 1 unit thick but a projectile is moving at 3 units per frame then it is very likely to be seen on Frame 1 on one side of the object, then when the position for it is calculated on Frame 2 it is already on the other side of the object and never registers a collision on the wall because it literally never collided with it. The 'speed' is how many units per second something moves and movement is just a change of position so this is a fundamental problem where the two objects never collided and therefore don't register a collision.

One fix that is cheap is to make the collider longer. This can work, but is awkward to work with sometimes. It makes it so that when the situation above does occur, the collider tail is long enough to touch the object that it passed through. This can make all of your collision data unreliable because the projectile would be registering a hit from the other side of the object it passed through.

I generally fix this by Raycasting from the last position to the current position every frame.... If the raycast hits anything then I know that it went 'through' something and I just stop it there and register the hit. This works fine for objects that are traveling very fast but can still be seen... however this can eventually get costly with all the raycasting happening on top of the regular projectile calcs..

If your objects are going super fast and cannot be seen then there is no reason to spawn something physically visible. The best solution is to just raycast from the barrel, forward... This is completely reliable and best for instant hit type things like actual bullets that are obviously going to fast to be observed. You can draw a line renderer or trail for these and see the effect of the projectile and it is common practice to do that.

Is there a place th at shows how to draw using aline or trail render? I know how to get the ray casting working. but i just need visual feed back like a trail to give it a cool effect.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: best action to move a bullet at high speed ?
« Reply #11 on: April 19, 2015, 11:23:46 PM »
If you're using a Ray I would just spawn an object with a line renderer on it. Or if you have something more elaborate you can just spawn a prefab that has more stuff, like particles etc.

There should be some tutorials on line renderer, it's a basic unity component.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D