broken_seals/game/scripts/projectiles/WorldSpellGD.gd

68 lines
2.2 KiB
GDScript3
Raw Normal View History

2019-12-10 11:09:02 +01:00
extends WorldSpell
class_name WorldSpellGD
2019-11-20 14:19:41 +01:00
2020-01-31 20:01:34 +01:00
# Copyright (c) 2019-2020 Péter Magyar
2019-12-22 19:20:38 +01:00
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
2019-11-20 14:19:41 +01:00
var _target : Spatial
var _info : SpellCastInfo
var _speed : float
func _ready() -> void:
if _info == null:
set_process(false)
func launch(info : SpellCastInfo, effect : PackedScene, speed : float) -> void:
if not is_instance_valid(info.target):
return
_info = info
_target = info.target.get_character_skeleton().torso_attach_point
_speed = speed
# translation = info.caster.translation
2020-01-02 23:02:45 +01:00
get_body().translation = info.caster.get_character_skeleton().right_hand_attach_point.global_transform.origin
2019-11-20 14:19:41 +01:00
var eff : Node = effect.instance()
eff.owner = self
add_child(eff)
set_process(true)
func _process(delta : float) -> void:
if not is_instance_valid(_target):
# set_process(false)
queue_free()
return
2020-01-02 23:02:45 +01:00
var l : Vector3 = _target.global_transform.origin - get_body().translation
2019-11-20 14:19:41 +01:00
if l.length() < 1:
_info.spell.son_spell_hit(_info)
queue_free()
return
var dir : Vector3 = l.normalized()
2020-01-02 23:02:45 +01:00
get_body().global_transform.origin += dir * _speed * delta
get_body().global_transform = get_body().transform.looking_at(_target.global_transform.origin, Vector3(0, 1, 0))
2019-11-20 14:19:41 +01:00