godot-third-person-basic-scene/scenes/main/main.gd

67 lines
1.8 KiB
GDScript

extends Node3D
var oldobject:Node3D = null
@onready var player_ptr = $player
func _init():
var file = File.new()
file.open("res://.git/HEAD", File.READ)
var content = file.get_as_text().strip_escapes()
file.close()
var head:String = content.split(' ')[1]
file.open("res://.git/" + head, File.READ)
content = file.get_as_text().strip_escapes()
file.close()
Common.msg_debug("Commit: " + content)
# Called when the node enters the scene tree for the first time.
func _ready():
$player.connect("switch_to_ship", self.switch_to_ship.bind() )
# $player_ship.set_process(false)
# $player_ship.hide()
func change_creature( new_model_path ):
var new_model = load( new_model_path )
if new_model:
new_model = new_model.instantiate()
new_model.translate($player.get_position())
if $player:
print("Remove old")
var old_model = $player
self.remove_child( old_model )
#self.animation_object = null
old_model.queue_free()
if new_model:
print("Add new")
self.add_child( new_model )
#new_model.connect( "animation_finished", self, "_on_creature_animation_finished" )
# new_model.duplicate_meshes()
func switch_to_ship(near_boat):
near_boat.hide()
oldobject = near_boat
print("GO switch_to_ship:", str(near_boat))
var new_model = load( "res://player/player_ship/player_ship.tscn" )
if new_model:
new_model = new_model.instantiate()
print("A:", near_boat.get_position())
print("B:", near_boat.get_global_transform().origin )
var newpos:Vector3 = near_boat.get_global_transform().origin
new_model.translate(newpos)
if $player:
print("Remove old")
var old_model = $player
self.remove_child( old_model )
#self.animation_object = null
old_model.queue_free()
if new_model:
print("Add new")
self.add_child( new_model )
# $player.set_process(false)
# $player.hide()
# $player_ship.show()
# $player_ship.set_process(true)