Created
July 9, 2021 07:57
-
-
Save spacechase0/f1cd399f67205383d5b7fdbb3db72036 to your computer and use it in GitHub Desktop.
SpaceECS v2
This file contains 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 Node2D | |
func _physics_process(delta): | |
var vels = get_tree().get_nodes_in_group( "components/VelocityComponent" ) | |
for node in vels: | |
var vel = node.get_component( "VelocityComponent" ) | |
node.move_and_collide( vel.velocity * delta ) |
This file contains 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 Node2D | |
func _ready(): | |
var c := VelocityComponent.new() | |
var dir := randf() * PI * 2 | |
c.velocity = Vector2( cos( dir ) * 100, sin( dir ) * 100 ) | |
add_component( c ) |
This file contains 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 Component | |
class_name VelocityComponent # Not necessary | |
export var velocity : Vector2 = Vector2( 0, 0 ) | |
func _get_component_name(): # Is necessary | |
return "VelocityComponent" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment