Grapple effects & particles & stuff :)
This commit is contained in:
parent
c290b1ce72
commit
421220e763
13 changed files with 203 additions and 61 deletions
|
@ -10,6 +10,7 @@ extends Node2D
|
|||
var grappleProjectile = preload("res://Player/GrappleHook/GrappleHookProjectile/GrappleHookProjectile.tscn")
|
||||
|
||||
var proj = null
|
||||
var retractingProj = []
|
||||
|
||||
var grappleSpeed = Vector2.ZERO
|
||||
var retractDur = 0
|
||||
|
@ -18,18 +19,40 @@ var retractStart = Vector2.ZERO
|
|||
var grappleDur = 0
|
||||
|
||||
var grappling = false
|
||||
var retracting = false
|
||||
|
||||
var grapples = 0
|
||||
|
||||
var grappleShootParti = preload("res://Particles/Grapple/GrappleParti.tscn")
|
||||
|
||||
func renderLine(proj):
|
||||
var grappleLine = proj.get_node("GrappleLine")
|
||||
var grappleBord = proj.get_node("GrappleBord")
|
||||
|
||||
var grapOffset = grappleCore.offset * sprite.scale
|
||||
|
||||
grappleLine.set_point_position(1, player.position + grapOffset)
|
||||
grappleBord.set_point_position(1, player.position + grapOffset)
|
||||
|
||||
grappleLine.set_point_position(0, proj.position)
|
||||
grappleBord.set_point_position(0, proj.position)
|
||||
|
||||
var curve = Curve.new()
|
||||
curve.add_point(Vector2(0, 1))
|
||||
curve.add_point(Vector2(1, sprite.scale.y))
|
||||
|
||||
grappleLine.width_curve = curve
|
||||
grappleBord.width_curve = curve
|
||||
|
||||
func launch(delta):
|
||||
if proj:
|
||||
player.jumps = player.MAX_JUMPS - 1
|
||||
var grappleVeloc = (proj.position - player.position).normalized() * grappleSpeed
|
||||
player.launch(grappleVeloc.x)
|
||||
player.velocity.y = grappleVeloc.y
|
||||
player.velocity.y = lerp(player.velocity.y, grappleVeloc.y, 10 * delta)
|
||||
|
||||
func grappleStart():
|
||||
grappleSpeed = (500 + clamp(player.velocity.length(), 500, 1000))
|
||||
grappleDur = 1
|
||||
grappleDur = 0.5
|
||||
grappling = true
|
||||
|
||||
func _physics_process(delta):
|
||||
|
@ -37,57 +60,59 @@ func _physics_process(delta):
|
|||
|
||||
var moveVector = (get_global_mouse_position() - player.position).normalized()
|
||||
|
||||
if Input.is_action_just_pressed("pullGrapple") and not proj:
|
||||
#player.velocity.y = player.JUMP_VELOCITY / 2
|
||||
if player.is_on_floor():
|
||||
grapples = 2
|
||||
|
||||
if Input.is_action_just_pressed("pullGrapple") and not proj and grapples:
|
||||
grapples -= 1
|
||||
|
||||
proj = grappleProjectile.instantiate()
|
||||
|
||||
proj.position = player.position
|
||||
proj.rotation = moveVector.angle()
|
||||
proj.modulate = Color8(0, 255, 0)
|
||||
|
||||
proj.velocity = (moveVector * 1500) + player.velocity
|
||||
#grappleDur = 10
|
||||
add_child(proj)
|
||||
|
||||
var parti = grappleShootParti.instantiate()
|
||||
parti.rotation = proj.rotation
|
||||
parti.position = proj.position
|
||||
parti.process_material.initial_velocity_min = (proj.velocity.length() + player.velocity.length()) / 6
|
||||
add_child(parti)
|
||||
#else:
|
||||
|
||||
if proj and grappleDur > 0 and (player.position - proj.position).length() > 15 and not Input.is_action_just_pressed("jump"):
|
||||
launch(delta)
|
||||
elif proj and grappling:
|
||||
player.jumps = 1
|
||||
player.jumps += 1
|
||||
player.falling = false
|
||||
#player.velocity.y = player.JUMP_VELOCITY
|
||||
grappleDur = 0
|
||||
|
||||
retractStart = proj.position
|
||||
retracting = true
|
||||
retractingProj.append({"proj": proj, "retractStart": proj.position, "retractDur": 0})
|
||||
proj = null
|
||||
grappling = false
|
||||
|
||||
func _process(delta):
|
||||
if proj and retracting == true:
|
||||
proj.position = lerp(retractStart, player.position, retractDur)
|
||||
retractDur += delta * 4
|
||||
if retractDur >= 1:
|
||||
proj.queue_free()
|
||||
proj = null
|
||||
retracting = false
|
||||
retractDur = 0
|
||||
for projData in retractingProj:
|
||||
var proj = projData.proj
|
||||
if is_instance_valid(proj):
|
||||
proj.position = lerp(projData.retractStart, player.position, projData.retractDur)
|
||||
projData.retractDur += delta * 4 / ((projData.retractStart - player.position).length() / 300)
|
||||
renderLine(proj)
|
||||
if projData.retractDur >= 1:
|
||||
var parti = proj.get_node("parti")
|
||||
parti.emitting = false
|
||||
parti.modulate = proj.modulate
|
||||
parti.reparent(player)
|
||||
proj.queue_free()
|
||||
proj = null
|
||||
retractDur = 0
|
||||
else:
|
||||
retractingProj.remove_at(retractingProj.find(projData))
|
||||
|
||||
if proj:
|
||||
#Engine.time_scale = 0.1
|
||||
var grappleLine = proj.get_node("GrappleLine")
|
||||
var grappleBord = proj.get_node("GrappleBord")
|
||||
|
||||
var grapOffset = grappleCore.offset * sprite.scale
|
||||
|
||||
grappleLine.set_point_position(1, player.position + grapOffset)
|
||||
grappleBord.set_point_position(1, player.position + grapOffset)
|
||||
|
||||
grappleLine.set_point_position(0, proj.position)
|
||||
grappleBord.set_point_position(0, proj.position)
|
||||
|
||||
var curve = Curve.new()
|
||||
curve.add_point(Vector2(0, 1))
|
||||
curve.add_point(Vector2(1, sprite.scale.y))
|
||||
|
||||
grappleLine.width_curve = curve
|
||||
grappleBord.width_curve = curve
|
||||
if is_instance_valid(proj):
|
||||
renderLine(proj)
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ var lastPos = null
|
|||
|
||||
var detecting = true
|
||||
|
||||
var partiDebounce = true
|
||||
|
||||
func objectHit(body):
|
||||
if body != self:
|
||||
velocity = Vector2.ZERO
|
||||
|
@ -19,11 +21,15 @@ func _physics_process(delta):
|
|||
|
||||
move_and_slide()
|
||||
|
||||
$"parti".emitting = (lastPos - position).length() > 0
|
||||
|
||||
if detecting:
|
||||
if lifeTime <= 0:
|
||||
velocity = Vector2.ZERO
|
||||
parent.retracting = true
|
||||
parent.retractStart = position
|
||||
parent.retractingProj.append({"proj": self, "retractStart": position, "retractDur": 0})
|
||||
parent.grappling = false
|
||||
parent.proj = null
|
||||
detecting = false
|
||||
lifeTime -= delta
|
||||
var space_state = get_world_2d().direct_space_state
|
||||
|
||||
|
@ -34,4 +40,4 @@ func _physics_process(delta):
|
|||
detecting = false
|
||||
position = result.position
|
||||
objectHit(result.collider)
|
||||
print(result.position)
|
||||
lastPos = position
|
||||
|
|
|
@ -1,9 +1,29 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://dmgf8fsvy1wjh"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://dmgf8fsvy1wjh"]
|
||||
|
||||
[ext_resource type="Script" path="res://Player/GrappleHook/GrappleHookProjectile/GrappleHookProjectile.gd" id="1_nba88"]
|
||||
[ext_resource type="Texture2D" uid="uid://bncu47o5ynskj" path="res://Player/GrappleHook/GrappleHookProjectile/Grapple.png" id="2_sst4t"]
|
||||
[ext_resource type="Texture2D" uid="uid://gn347ng3iu02" path="res://Player/GrappleHook/GrappleHookProjectile/GrappleTether.png" id="2_xkdsl"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_qnwwb"]
|
||||
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), -2.51429, 0.0, 0, 0]
|
||||
point_count = 2
|
||||
|
||||
[sub_resource type="CurveTexture" id="CurveTexture_f4r8k"]
|
||||
curve = SubResource("Curve_qnwwb")
|
||||
|
||||
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_tkwr2"]
|
||||
particle_flag_align_y = true
|
||||
particle_flag_disable_z = true
|
||||
inherit_velocity_ratio = 0.1
|
||||
spread = 180.0
|
||||
initial_velocity_min = 50.0
|
||||
initial_velocity_max = 50.0
|
||||
gravity = Vector3(0, 0, 0)
|
||||
damping_min = 50.0
|
||||
damping_max = 50.0
|
||||
scale_max = 2.0
|
||||
scale_curve = SubResource("CurveTexture_f4r8k")
|
||||
|
||||
[node name="GrappleHook" type="CharacterBody2D"]
|
||||
top_level = true
|
||||
disable_mode = 2
|
||||
|
@ -41,3 +61,11 @@ joint_mode = 2
|
|||
begin_cap_mode = 2
|
||||
end_cap_mode = 2
|
||||
round_precision = 4
|
||||
|
||||
[node name="parti" type="GPUParticles2D" parent="."]
|
||||
amount = 100
|
||||
process_material = SubResource("ParticleProcessMaterial_tkwr2")
|
||||
lifetime = 2.0
|
||||
fixed_fps = 0
|
||||
interpolate = false
|
||||
visibility_rect = Rect2(-12500, -12500, 25000, 25000)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue