More player adjustments, Node for aligning to earth center
This commit is contained in:
parent
11bd9d46fd
commit
ae56d78b22
8 changed files with 51 additions and 29 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
[gd_scene load_steps=4 format=3 uid="uid://jjoyj1ldafkf"]
|
[gd_scene load_steps=4 format=3 uid="uid://jjoyj1ldafkf"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://b5fhsy1xlreco" path="res://draw_circle.gd" id="2_2bhor"]
|
[ext_resource type="Script" uid="uid://b5fhsy1xlreco" path="res://draw_circle.gd" id="2_2bhor"]
|
||||||
[ext_resource type="Script" uid="uid://m3vyyfk8gnma" path="res://grid.gd" id="3_2bhor"]
|
[ext_resource type="Script" path="res://grid.gd" id="3_2bhor"]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_5i67w"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_5i67w"]
|
||||||
radius = 3000.0
|
radius = 3000.0
|
||||||
|
|
|
||||||
12
earth_aligner.gd
Normal file
12
earth_aligner.gd
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
var parent : Node2D
|
||||||
|
@export var center = Vector2.ZERO
|
||||||
|
var angle = 0
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
parent = get_parent()
|
||||||
|
|
||||||
|
func _physics_process(delta: float) -> void:
|
||||||
|
angle = -(parent.position - center).angle_to(Vector2.UP)
|
||||||
|
parent.rotation = angle;
|
||||||
1
earth_aligner.gd.uid
Normal file
1
earth_aligner.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://ciehyjlxjvrvb
|
||||||
6
earth_aligner.tscn
Normal file
6
earth_aligner.tscn
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
[gd_scene load_steps=2 format=3 uid="uid://chs0u61f45nau"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://ciehyjlxjvrvb" path="res://earth_aligner.gd" id="1_sx2xq"]
|
||||||
|
|
||||||
|
[node name="EarthAligner" type="Node2D"]
|
||||||
|
script = ExtResource("1_sx2xq")
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
[gd_scene load_steps=4 format=3 uid="uid://chu67ci7sl488"]
|
[gd_scene load_steps=5 format=3 uid="uid://chu67ci7sl488"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://12jns4dppxxj" path="res://ghost.gd" id="1_6attn"]
|
[ext_resource type="Script" uid="uid://12jns4dppxxj" path="res://ghost.gd" id="1_6attn"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="2_obmiq"]
|
[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="2_obmiq"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://chs0u61f45nau" path="res://earth_aligner.tscn" id="3_obmiq"]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_6attn"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_6attn"]
|
||||||
|
|
||||||
|
|
@ -15,3 +16,5 @@ texture = ExtResource("2_obmiq")
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
scale = Vector2(6, 6)
|
scale = Vector2(6, 6)
|
||||||
shape = SubResource("CircleShape2D_6attn")
|
shape = SubResource("CircleShape2D_6attn")
|
||||||
|
|
||||||
|
[node name="EarthAligner" parent="." instance=ExtResource("3_obmiq")]
|
||||||
|
|
|
||||||
43
player.gd
43
player.gd
|
|
@ -2,16 +2,16 @@ extends CharacterBody2D
|
||||||
# Child Nodes
|
# Child Nodes
|
||||||
var camera : Camera2D;
|
var camera : Camera2D;
|
||||||
var anim_sprite : AnimatedSprite2D
|
var anim_sprite : AnimatedSprite2D
|
||||||
|
var earth_aligner : Node2D
|
||||||
|
|
||||||
# Gravity
|
# Gravity
|
||||||
var earth_center = Vector2.ZERO;
|
var earth_center = Vector2.ZERO;
|
||||||
var max_fall_speed = 700;
|
var max_fall_speed = 700;
|
||||||
var gravity = 100;
|
var gravity = 100;
|
||||||
var angle = 0;
|
|
||||||
|
|
||||||
# Movement
|
# Movement
|
||||||
var hspeed = 150;
|
var hspeed = 150;
|
||||||
var jump_strength = 900;
|
var jump_strength = 1100;
|
||||||
var air_jumps_max = 1;
|
var air_jumps_max = 1;
|
||||||
var air_jumps_current = 1;
|
var air_jumps_current = 1;
|
||||||
|
|
||||||
|
|
@ -22,30 +22,31 @@ var hit_invulnerability = 0.5
|
||||||
var inv_time = 0;
|
var inv_time = 0;
|
||||||
|
|
||||||
# Received Knockback
|
# Received Knockback
|
||||||
var bonus_velocity = Vector2.ZERO
|
var reset_to_velocity = Vector2.ZERO
|
||||||
var knockback_strength = 1200
|
var knockback_strength = 1500
|
||||||
var damage_knockup = 200
|
var damage_knockup = 500
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
camera = $Camera2D
|
camera = $Camera2D
|
||||||
anim_sprite = $AnimatedSprite2D
|
anim_sprite = $AnimatedSprite2D
|
||||||
|
earth_aligner = $EarthAligner
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
if(inv_time > 0):
|
manage_iframes(delta)
|
||||||
inv_time = max(0, inv_time-delta)
|
manage_movement_options()
|
||||||
|
|
||||||
angle = -(position - earth_center).angle_to(Vector2.UP)
|
|
||||||
rotation = angle;
|
|
||||||
up_direction = (position - earth_center).normalized();
|
|
||||||
|
|
||||||
if(is_on_floor()):
|
|
||||||
air_jumps_current = air_jumps_max
|
|
||||||
|
|
||||||
manage_animation()
|
manage_animation()
|
||||||
manage_velocity()
|
manage_velocity()
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
|
func manage_iframes(delta: float):
|
||||||
|
if(inv_time > 0):
|
||||||
|
inv_time = max(0, inv_time-delta)
|
||||||
|
|
||||||
|
func manage_movement_options() -> void:
|
||||||
|
if(is_on_floor()):
|
||||||
|
air_jumps_current = air_jumps_max
|
||||||
|
|
||||||
func manage_animation() -> void:
|
func manage_animation() -> void:
|
||||||
var walk_dir = 0
|
var walk_dir = 0
|
||||||
if(Input.is_action_pressed("move_right")):
|
if(Input.is_action_pressed("move_right")):
|
||||||
|
|
@ -63,6 +64,7 @@ func manage_animation() -> void:
|
||||||
anim_sprite.stop()
|
anim_sprite.stop()
|
||||||
|
|
||||||
func manage_velocity() -> void:
|
func manage_velocity() -> void:
|
||||||
|
up_direction = (position - earth_center).normalized();
|
||||||
var old_local_velocity = local_from_global(velocity)
|
var old_local_velocity = local_from_global(velocity)
|
||||||
var local_velocity = Vector2(old_local_velocity.x/1.7, old_local_velocity.y);
|
var local_velocity = Vector2(old_local_velocity.x/1.7, old_local_velocity.y);
|
||||||
local_velocity += Vector2(0, gravity)
|
local_velocity += Vector2(0, gravity)
|
||||||
|
|
@ -80,16 +82,17 @@ func manage_velocity() -> void:
|
||||||
if(local_velocity.y > max_fall_speed):
|
if(local_velocity.y > max_fall_speed):
|
||||||
local_velocity.y = max_fall_speed
|
local_velocity.y = max_fall_speed
|
||||||
|
|
||||||
local_velocity += bonus_velocity
|
if(reset_to_velocity != Vector2.ZERO):
|
||||||
bonus_velocity = Vector2.ZERO
|
local_velocity = reset_to_velocity
|
||||||
|
reset_to_velocity = Vector2.ZERO
|
||||||
velocity = global_from_local(local_velocity)
|
velocity = global_from_local(local_velocity)
|
||||||
|
|
||||||
|
|
||||||
func global_from_local (_velocity: Vector2) -> Vector2:
|
func global_from_local (_velocity: Vector2) -> Vector2:
|
||||||
return _velocity.rotated(angle)
|
return _velocity.rotated(earth_aligner.angle)
|
||||||
|
|
||||||
func local_from_global (_velocity: Vector2) -> Vector2:
|
func local_from_global (_velocity: Vector2) -> Vector2:
|
||||||
return _velocity.rotated(-angle)
|
return _velocity.rotated(-earth_aligner.angle)
|
||||||
|
|
||||||
func hurt(dmg: int, dir: Vector2 = Vector2.ZERO):
|
func hurt(dmg: int, dir: Vector2 = Vector2.ZERO):
|
||||||
if(inv_time <= 0):
|
if(inv_time <= 0):
|
||||||
|
|
@ -98,7 +101,7 @@ func hurt(dmg: int, dir: Vector2 = Vector2.ZERO):
|
||||||
die()
|
die()
|
||||||
|
|
||||||
inv_time = hit_invulnerability
|
inv_time = hit_invulnerability
|
||||||
bonus_velocity = Vector2(-sign(local_from_global(dir).x)*knockback_strength, -damage_knockup)
|
reset_to_velocity = Vector2(-sign(local_from_global(dir).x)*knockback_strength, -damage_knockup)
|
||||||
|
|
||||||
func die():
|
func die():
|
||||||
print("You Died") # Placeholder
|
print("You Died") # Placeholder
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
[gd_scene load_steps=10 format=3 uid="uid://cmaovvr15b3qk"]
|
[gd_scene load_steps=11 format=3 uid="uid://cmaovvr15b3qk"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://ddidj1uau28ck" path="res://player.gd" id="1_4flbx"]
|
[ext_resource type="Script" uid="uid://ddidj1uau28ck" path="res://player.gd" id="1_4flbx"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cyvxm1hf1rc12" path="res://player_walk.png" id="2_onrkg"]
|
[ext_resource type="Texture2D" uid="uid://cyvxm1hf1rc12" path="res://player_walk.png" id="2_onrkg"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://chs0u61f45nau" path="res://earth_aligner.tscn" id="3_i3pqv"]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_onrkg"]
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_onrkg"]
|
||||||
|
|
||||||
|
|
@ -65,3 +66,5 @@ animation = &"walk"
|
||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
position = Vector2(0, -50)
|
position = Vector2(0, -50)
|
||||||
ignore_rotation = false
|
ignore_rotation = false
|
||||||
|
|
||||||
|
[node name="EarthAligner" parent="." instance=ExtResource("3_i3pqv")]
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@ dest_files=["res://.godot/imported/player_walk.png-dd7b13f797aca66ef3a8a41ed9897
|
||||||
compress/mode=0
|
compress/mode=0
|
||||||
compress/high_quality=false
|
compress/high_quality=false
|
||||||
compress/lossy_quality=0.7
|
compress/lossy_quality=0.7
|
||||||
compress/uastc_level=0
|
|
||||||
compress/rdo_quality_loss=0.0
|
|
||||||
compress/hdr_compression=1
|
compress/hdr_compression=1
|
||||||
compress/normal_map=0
|
compress/normal_map=0
|
||||||
compress/channel_pack=0
|
compress/channel_pack=0
|
||||||
|
|
@ -27,10 +25,6 @@ mipmaps/generate=false
|
||||||
mipmaps/limit=-1
|
mipmaps/limit=-1
|
||||||
roughness/mode=0
|
roughness/mode=0
|
||||||
roughness/src_normal=""
|
roughness/src_normal=""
|
||||||
process/channel_remap/red=0
|
|
||||||
process/channel_remap/green=1
|
|
||||||
process/channel_remap/blue=2
|
|
||||||
process/channel_remap/alpha=3
|
|
||||||
process/fix_alpha_border=true
|
process/fix_alpha_border=true
|
||||||
process/premult_alpha=false
|
process/premult_alpha=false
|
||||||
process/normal_map_invert_y=false
|
process/normal_map_invert_y=false
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue