Created
February 27, 2025 22:47
-
-
Save lamarmarshall/d2e370be4a89f574aa09f1bcad58efa5 to your computer and use it in GitHub Desktop.
godot, particle emitting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extends RigidBody3D | |
| ##how much vertical force | |
| @export_range(750.0, 3000.0) var thrust: float = 1000.0 | |
| ##how much horizntal force | |
| @export var torque: float = 100.0 | |
| @onready var audio: AudioStreamPlayer = $Audio | |
| @onready var audio_success: AudioStreamPlayer = $Audio_success | |
| @onready var audio_rocket: AudioStreamPlayer3D = $Audio_rocket | |
| @onready var booster_particles: GPUParticles3D = $BoosterParticles | |
| @onready var explosion_particles: GPUParticles3D = $ExplosionParticles | |
| var next_level: String | |
| var is_transitioning: bool = false | |
| # Called every frame. 'delta' is the elapsed time since the previous frame. | |
| func _physics_process(delta: float) -> void: | |
| if Input.is_action_pressed("boost"): | |
| apply_central_force(basis.y * delta * thrust) | |
| if audio_rocket.playing == false: | |
| audio_rocket.play() | |
| booster_particles.emitting = true | |
| else: | |
| audio_rocket.stop() | |
| booster_particles.emitting = false | |
| if Input.is_action_pressed("left"): | |
| apply_torque(Vector3(0.0, 0.0, torque * delta)) | |
| if Input.is_action_pressed("right"): | |
| apply_torque(Vector3(0.0, 0.0, -torque * delta)) | |
| func crash_sequence() -> void: | |
| print("Kaboom") | |
| explosion_particles.emitting = true | |
| audio.play() | |
| set_process(false) | |
| is_transitioning = true | |
| var tween = create_tween() | |
| tween.tween_interval(2.5) | |
| tween.tween_callback(get_tree().reload_current_scene) | |
| func complete_level(next_level_file: String) -> void: | |
| set_process(false) | |
| audio_success.play() | |
| is_transitioning = true | |
| var tween =create_tween() | |
| tween.tween_interval(2.5) | |
| next_level = next_level_file | |
| tween.tween_callback(go_to_next)#get_tree().reload_current_scene) | |
| print("You Win") | |
| #get_tree().call_deferred("change_scene_to_file", next_level_file) | |
| func go_to_next() -> void: | |
| get_tree().call_deferred("change_scene_to_file", next_level) | |
| func _on_body_entered(body: Node) -> void: | |
| if is_transitioning == false: | |
| if "Goal" in body.get_groups(): | |
| complete_level(body.file_path) | |
| if "Hazard" in body.get_groups(): | |
| crash_sequence() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment