Bracer Jack | Unity Tutorial Bullet Mark Using Ray Cast! @BracerJack | Uploaded September 2015 | Updated October 2024, 5 days ago.
Code/Script:
pastebin.com/QVjJxLv5
Transcript:
For the Raycast version of this tutorial, instead of attaching the script to the bullets, we will be attaching it to the bullet emitter itself.
If you don't know what that is, please refer to my straight to the point tutorial titled: “How to Shoot Bullets in Unity in 3mins” M’kay? M’kay.
This is the script we will be attaching to the empty Bullet emitter:
This variable is used to indicate how long the ray line should be extended.
This variable will hold everything that is relevant at the moment of contact between the Raycast and a Collider.
This variable holds an instance of the bullet mark to be instantiated.
If this variable confuses you, please refer to my Rigidbody edition of this same tutorial.
Now onto the update function !
This function merely shows you visually where the ray will be cast toward, it doesn’t do anything besides that, it also only appear in the scene view and NOT in the actual game view, isn’t that sad ?
You might have to change this axis depending on how your bullet emitter was orientated.
This block of function will execute every time the space bar is down.
This is what this entire tutorial is all about, cast the ray from the emitter’s position, from this axis and output any collision data into this variable.
If the collided object is tagged “Blocks” execute the following.
Display the distance to the object.
Display the coordinate where the collision occur.
The following 4 lines of codes are explained in the RigidBody edition of this tutorial so watch it !
As you can see, using the RayCast technique causes the bullet marks to appear even before the Bullet has physically reach the target, it will also not be located at where the bullet will eventually end up because unlike a simple Raycast, the physical bullet itself will be affected by gravity and other forces that maybe a part of your game.
The Rigidbody and Raycast method both have their advantages if you consider the array of weapons that a typical good shooting game will have.
Now that you have this knowledge, choose whatever is appropriate for your weapon of choice :-)
And please support me in Patreon, with just $1 a month, you will be helping me to make more straight to the point unity tutorials for you and benefit the world !
Think of the children’s !
or whatever that would motivate you to support me ;-p
Yeah !
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
===============================================================
Code/Script:
pastebin.com/QVjJxLv5
Transcript:
For the Raycast version of this tutorial, instead of attaching the script to the bullets, we will be attaching it to the bullet emitter itself.
If you don't know what that is, please refer to my straight to the point tutorial titled: “How to Shoot Bullets in Unity in 3mins” M’kay? M’kay.
This is the script we will be attaching to the empty Bullet emitter:
This variable is used to indicate how long the ray line should be extended.
This variable will hold everything that is relevant at the moment of contact between the Raycast and a Collider.
This variable holds an instance of the bullet mark to be instantiated.
If this variable confuses you, please refer to my Rigidbody edition of this same tutorial.
Now onto the update function !
This function merely shows you visually where the ray will be cast toward, it doesn’t do anything besides that, it also only appear in the scene view and NOT in the actual game view, isn’t that sad ?
You might have to change this axis depending on how your bullet emitter was orientated.
This block of function will execute every time the space bar is down.
This is what this entire tutorial is all about, cast the ray from the emitter’s position, from this axis and output any collision data into this variable.
If the collided object is tagged “Blocks” execute the following.
Display the distance to the object.
Display the coordinate where the collision occur.
The following 4 lines of codes are explained in the RigidBody edition of this tutorial so watch it !
As you can see, using the RayCast technique causes the bullet marks to appear even before the Bullet has physically reach the target, it will also not be located at where the bullet will eventually end up because unlike a simple Raycast, the physical bullet itself will be affected by gravity and other forces that maybe a part of your game.
The Rigidbody and Raycast method both have their advantages if you consider the array of weapons that a typical good shooting game will have.
Now that you have this knowledge, choose whatever is appropriate for your weapon of choice :-)
And please support me in Patreon, with just $1 a month, you will be helping me to make more straight to the point unity tutorials for you and benefit the world !
Think of the children’s !
or whatever that would motivate you to support me ;-p
Yeah !
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
===============================================================