Bracer Jack | Bullet Collision Marks Rigid Body Edition! @BracerJack | Uploaded September 2015 | Updated October 2024, 5 days ago.
How to leave a Bullet Collision Mark Rigidbody Edition.
Script:
pastebin.com/8tJAa9gb
Transcript:
Leaving marks after bullet collision in 1 minute !
Step 1:
Drag out a plane or import a flat plane geometry, add in your bullet mark texture.
For the purpose of this tutorial, there will be a slight exaggeration, instead of a small bullet Mark which you probably will be using, I will be using this big bright texture for extreme visibility.
Scale it to what you would deem as a reasonable size.
Rename it as Bullet Mark.
Drag it back into the project panel to form a prefab.
Remember that for any collision detection to occur, your bullet must already have a rigidBody attached to it, I have to mention this in case you are using a form of bullet shooting mechanism that doesn't employ RigidBody.
The object you are trying to hit should also at the very least, have a collider attached to it.
You can now delete the Bullet Mark game object in the scene, it will no longer be needed.
Step 2:
This is the script we will be attaching to the bullet itself.
This line will create a variable to store an array of collision contact points when the bullet hits one of the Blocks.
This variable will hold the Bullet Mark Prefab.
Before we continue, let's get to the Prefab assignments out of the way.
Save and attach this script to the bullet prefab.
Drag the Bullet Mark Prefab to the slot that requires the Bullet Mark.
Now back to the script.
This is one of the two things this video is all about:
If a collision occur, this function will trigger.
This variable will then hold a reference to the object the bullet have collided with.
This line detects if the game object being hit is tagged as a block.
This line retrieve the array of contact points generated from the impact.
This temporary variable will hold a reference to the bullet mark object that will be created on the next line.
This is where we instantiate the bullet mark and THIS, is the money shot or code.
This piece of magic will orientate the instantiated object correctly so that its normal is facing the same direction as the collided surface.
This is AWESOME.
This is what I would call compensation code, depending on the way you create your bullet mark mesh, you may or may not have to offset the resulting orientation.
Here is where we push the Bullet Mark mesh out slightly.
Why ? Because if the mesh is exactly on the same plane as the collided geometry, the renderer will have to decide which surface to show using voodoo magic, here we make sure that the bullet mark will be visible by pushing it out of the surface by a small amount.
Understand that depending on the way your bullet mark mesh was created, your translation axis might be on some other axis other than up.
This line tells the Bullet Mark Mesh to kill itself after 3 seconds, you may or may not want to do that for your game, you probably will though to save resources.
This line informs the bullet that life is meaningless and it should just die.
That's it for this tutorial, it is actually quite easy isn't it !
See you next week !
Support me by reading my books !
===============================================================
Humpty Dumpty God
Google Play eBook:
play.google.com/store/books/details?id=I-_cDwAAQBAJ
Kindle eBook:
amazon.com/dp/B0875KWW4Z
Paperback:
amazon.com/dp/B087647N67
===============================================================
===============================================================
Book 1 :: God Guardian: The Life Review Simulation
Google Play eBook:
play.google.com/store/books/details?id=IxnRDwAAQBAJ
Kindle eBook:
amazon.com/dp/B07SGZLMK9
Paperback:
amazon.com/dp/1070820237
===============================================================
===============================================================
Book 2 :: God Guardian: Incarnation Troll
Google Play eBook:
play.google.com/store/books/details?id=RxnRDwAAQBAJ
Kindle eBook:
amazon.com/dp/B07SJ8TLV5
Paperback:
amazon.com/dp/1070940291
===============================================================
===============================================================
Book 3 :: God Guardian: Perpetual Slaves
Google Play eBook:
play.google.com/store/books/details?id=aRnRDwAAQBAJ
Kindle eBook:
amazon.com/dp/B084TJ6JKN
Paperback:
amazon.com/dp/B084QKYCML
===============================================================
Please support my Patreon:
patreon.com/BracerJack
Paypal Donation:
bracercom@hotmail.com
Bitcoin Address Donation:
1698RW9rSJUXeSSbyNaQY7aNNbxQkLtjs5
===============================================================
How to leave a Bullet Collision Mark Rigidbody Edition.
Script:
pastebin.com/8tJAa9gb
Transcript:
Leaving marks after bullet collision in 1 minute !
Step 1:
Drag out a plane or import a flat plane geometry, add in your bullet mark texture.
For the purpose of this tutorial, there will be a slight exaggeration, instead of a small bullet Mark which you probably will be using, I will be using this big bright texture for extreme visibility.
Scale it to what you would deem as a reasonable size.
Rename it as Bullet Mark.
Drag it back into the project panel to form a prefab.
Remember that for any collision detection to occur, your bullet must already have a rigidBody attached to it, I have to mention this in case you are using a form of bullet shooting mechanism that doesn't employ RigidBody.
The object you are trying to hit should also at the very least, have a collider attached to it.
You can now delete the Bullet Mark game object in the scene, it will no longer be needed.
Step 2:
This is the script we will be attaching to the bullet itself.
This line will create a variable to store an array of collision contact points when the bullet hits one of the Blocks.
This variable will hold the Bullet Mark Prefab.
Before we continue, let's get to the Prefab assignments out of the way.
Save and attach this script to the bullet prefab.
Drag the Bullet Mark Prefab to the slot that requires the Bullet Mark.
Now back to the script.
This is one of the two things this video is all about:
If a collision occur, this function will trigger.
This variable will then hold a reference to the object the bullet have collided with.
This line detects if the game object being hit is tagged as a block.
This line retrieve the array of contact points generated from the impact.
This temporary variable will hold a reference to the bullet mark object that will be created on the next line.
This is where we instantiate the bullet mark and THIS, is the money shot or code.
This piece of magic will orientate the instantiated object correctly so that its normal is facing the same direction as the collided surface.
This is AWESOME.
This is what I would call compensation code, depending on the way you create your bullet mark mesh, you may or may not have to offset the resulting orientation.
Here is where we push the Bullet Mark mesh out slightly.
Why ? Because if the mesh is exactly on the same plane as the collided geometry, the renderer will have to decide which surface to show using voodoo magic, here we make sure that the bullet mark will be visible by pushing it out of the surface by a small amount.
Understand that depending on the way your bullet mark mesh was created, your translation axis might be on some other axis other than up.
This line tells the Bullet Mark Mesh to kill itself after 3 seconds, you may or may not want to do that for your game, you probably will though to save resources.
This line informs the bullet that life is meaningless and it should just die.
That's it for this tutorial, it is actually quite easy isn't it !
See you next week !
Support me by reading my books !
===============================================================
Humpty Dumpty God
Google Play eBook:
play.google.com/store/books/details?id=I-_cDwAAQBAJ
Kindle eBook:
amazon.com/dp/B0875KWW4Z
Paperback:
amazon.com/dp/B087647N67
===============================================================
===============================================================
Book 1 :: God Guardian: The Life Review Simulation
Google Play eBook:
play.google.com/store/books/details?id=IxnRDwAAQBAJ
Kindle eBook:
amazon.com/dp/B07SGZLMK9
Paperback:
amazon.com/dp/1070820237
===============================================================
===============================================================
Book 2 :: God Guardian: Incarnation Troll
Google Play eBook:
play.google.com/store/books/details?id=RxnRDwAAQBAJ
Kindle eBook:
amazon.com/dp/B07SJ8TLV5
Paperback:
amazon.com/dp/1070940291
===============================================================
===============================================================
Book 3 :: God Guardian: Perpetual Slaves
Google Play eBook:
play.google.com/store/books/details?id=aRnRDwAAQBAJ
Kindle eBook:
amazon.com/dp/B084TJ6JKN
Paperback:
amazon.com/dp/B084QKYCML
===============================================================
Please support my Patreon:
patreon.com/BracerJack
Paypal Donation:
bracercom@hotmail.com
Bitcoin Address Donation:
1698RW9rSJUXeSSbyNaQY7aNNbxQkLtjs5
===============================================================