|
|
|
|
Reply From: |
splite |
Edit: Nevermind, Zylanns answer is much better (see yourself below) i didnt know that godot support static func (cool to know & +1 )
Well, you can just load your script without existing node
file res://Scripts/Utils.gd
extends Node #or whatever
#silly example :)
static func plus(x, y):
return x + y
and in ‘real’ node:
var x
func _ready():
x = load("res://Scripts/Utils.gd")
var p = x.plus(1,2)
Or maybe, you would like to extend your base class (its always better then having Utils class) like this:
file res://Scripts/SpaceshipBase.gd
extends RigidBody
var _turn_speed
func set_turn_speed(x):
_turn_speed = x
script on your (RigidBody) node:
extends "res://Scripts/SpaceshipBase.gd"
func _ready():
set_turn_speed(10)
edit: i re-read your question and flip examples Sorry for confusion
I’m unsure about the last recommendation, as you probably want your spaceship node to keep the functionality you get from extending RigidBody2D/3D, and everything up its hierarchy.
avencherus | 2016-08-25 12:15
I dont lose any functionality, its classic inheritance (see another question), SpaceShipBase extends RigidBody (RigidBody = “RigidBody3D”, dont have “3D” in name), node-specific-script extends SpaceShipBase. So in node-specific-script, i have access to SpaceShipBase and RigidBody functions.
What i get is central script of common functions of all spaceships (like movement func etc) without caring of ship specific (one or dozen thrusters, etc… )
edit: Of course, all my spaceships have to be RigidBody node
splite | 2016-08-25 13:15