mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-21 23:54:23 +00:00
Move mouse physics in _physics_process
This commit is contained in:
parent
0724543d90
commit
d4c844e878
2 changed files with 31 additions and 17 deletions
|
@ -9,6 +9,7 @@ enum State {STATE_IDLE, STATE_WALK, STATE_PICKED, STATE_RUN, STATE_THROWN}
|
|||
var state: State = State.STATE_IDLE
|
||||
var walk_dir: Vector2 = Vector2.ZERO
|
||||
var last_dir: int = 1
|
||||
var last_mouse_pos: Vector2 = Vector2.ZERO
|
||||
|
||||
|
||||
@export var min_run_dist = 200
|
||||
|
@ -39,14 +40,12 @@ func init_timer():
|
|||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
gravity_scale = 0
|
||||
# Update state
|
||||
var curr_mpos = get_viewport().get_mouse_position()
|
||||
last_mouse_pos = curr_mpos
|
||||
|
||||
if state == State.STATE_PICKED and not Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
|
||||
pick_down()
|
||||
if state == State.STATE_THROWN and linear_velocity.length() < 1:
|
||||
state = State.STATE_WALK
|
||||
init_timer()
|
||||
|
||||
var mouse_dis = position.distance_to(curr_mpos)
|
||||
if (state == State.STATE_IDLE or state == State.STATE_WALK) and mouse_dis < min_run_dist:
|
||||
|
@ -57,15 +56,23 @@ func _process(delta):
|
|||
state = State.STATE_IDLE
|
||||
init_timer()
|
||||
|
||||
func _physics_process(delta):
|
||||
gravity_scale = 0
|
||||
print(linear_velocity.length())
|
||||
if state == State.STATE_THROWN and linear_velocity.length() < 300:
|
||||
linear_velocity = Vector2.ZERO
|
||||
state = State.STATE_WALK
|
||||
init_timer()
|
||||
|
||||
var force = Vector2.ZERO
|
||||
|
||||
if state == State.STATE_WALK:
|
||||
force = walk_speed * walk_dir
|
||||
elif state == State.STATE_RUN:
|
||||
var run_dir = -position.direction_to(curr_mpos)
|
||||
var run_dir = -position.direction_to(last_mouse_pos)
|
||||
force = run_speed * run_dir
|
||||
elif state == State.STATE_PICKED:
|
||||
var dest_position = initial_self_position + (curr_mpos - initial_mouse_position)
|
||||
var dest_position = initial_self_position + (last_mouse_pos - initial_mouse_position)
|
||||
apply_central_force(50 * (dest_position - position) * dest_position.distance_to(position) * delta)
|
||||
else:
|
||||
pass
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://3yqvhxeq03rk"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://3yqvhxeq03rk"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/interface/main_menu.gd" id="1_jkswn"]
|
||||
[ext_resource type="PackedScene" uid="uid://bc2bm8lbol18w" path="res://entities/sheep.tscn" id="2_vjm0p"]
|
||||
|
||||
[node name="MainMenu" type="Control"]
|
||||
layout_mode = 3
|
||||
|
@ -68,5 +69,11 @@ layout_mode = 2
|
|||
theme_override_font_sizes/font_size = 36
|
||||
text = "Options"
|
||||
|
||||
[node name="Sheep" parent="." instance=ExtResource("2_vjm0p")]
|
||||
position = Vector2(413, 181)
|
||||
|
||||
[node name="Sheep2" parent="." instance=ExtResource("2_vjm0p")]
|
||||
position = Vector2(950, 662)
|
||||
|
||||
[connection signal="pressed" from="Panel/Layout/Buttons/Layout/Play" to="." method="_on_play_pressed"]
|
||||
[connection signal="pressed" from="Panel/Layout/Buttons/Layout/Options" to="." method="_on_options_pressed"]
|
||||
|
|
Loading…
Reference in a new issue