I wanted to create the mechanic of ejecting casings after a shot to add some dynamism and juice to my 3D FPS shooter, but I couldn't find a suitable tutorial anywhere to create this mechanic. Does anyone know a way to implement this mechanic? I'd be grateful for any advice and links to learning materials! Thank you in advance for your help!
How make a system for spent bullet casings to eject after firing in 3D Godot 4?
xyz why not, its possible in this day and age. look, the bicycle wasnt invented in one piece, its an amalgamation of many technologies, they copied things from other things that already existed.. like wheel, gears, chains, seats. etc etc.
as for OP
Create bullet scene with Rigidbody3D, add meshinstance. then Preload that scene in your shoot script, when bulet fires, instantiate new casing from the wapon part, then in the casing script, when it spawns add impulse in some direction, then add timer and when timeout delete the object.
Idk, i havent tested.. there should be ways to streamline this
- Edited
kuligs2 amalgamation of many technologies
Tutorials are not technologies.
kuligs2 why not, its possible in this day and age.
Is it though? Can you name an example?
The thing here is - the exact same "technology" that's used for making shells pop out of weapons is also used for making hundreds other "systems" in a typical 3d game. And that "technology" is - linear algebra. So the right course of action here is to learn linear algebra, instead of asking 100 seemingly unrelated questions all really having the same answer: "learn linear algebra".
To go back to your bicycle analogy, it's like asking over and over "how do I connect part X and part Y of a bicycle" for each two parts that need to go together. The answer is always the same: learn to weld and screw.
- Edited
If you still need the casing eject, you can try this video -
I did not watch this video so I don't know he showed the casing code or not. In case you can't figure it out post here and I will try to post my own code.
don't think about it like the real world 3d spent shells are exact same thing as bullet, just in a different direction. 3d is really just the same as 2d but instead of a flat image it's a 3d mesh.
extends RigidBody3D
func _ready() -> void:
apply_force(Vector3i.UP*500,Vector3i.ZERO)
apply_force(Vector3i.RIGHT*500,Vector3i.ZERO)
func _on_timer_timeout() -> void:
queue_free()
so the scene for that needs to be a RigidBody3D with a timer under it set for 5 sec, a meshinstance3d with a new cylinder shape, and a collisionshap with a cylindershape, save it as bull_shell.tscn
extends Node3D
const Bull: PackedScene = preload("res://Scripts/bull_shell.tscn")
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("ui_accept"):
print("bang")
var BS:=Bull.instantiate()
BS.rotation_degrees=Vector3(90,0,0)
add_child(BS)
the scene for this needs a camera3d backset a bit so it can see vec 0, it needs a directional light3d
then just press space bar to fire
you would hook this up to your gun. maybe scale it down and mess with the BS.position = Vector3(0,0,0) to where it's where the gun would produce the spent shells
Particles is ok