From b0f3d0c25642730cddf8594457c520c762115ff2 Mon Sep 17 00:00:00 2001 From: Mayhew Steyn Date: Sun, 5 Apr 2020 02:05:18 +0200 Subject: [PATCH] Fix unwanted character sliding on slopes and add new ramp obstical The character used to slide down slopes with a low enough incline to be the floor. The character used to run up (or slide up if in the Air state) slopes that are too steep to be the floor. New bad behaviour: - On slopes with an incline equal to max_floor_angle, the character makes a slight hop after running up and looses their grounding when running down them. - When the character runs into a steep slope they perform short hops due to sliding upwards. Ideally the player would stay on the ground (no sliding up the slope). This can be exploited to jump higher. A new ramp obstical (Rampy) was added to the main Game scene to test the slope behaviour. Closes: #25 --- assets/3d/level/rampy.glb | Bin 0 -> 2896 bytes assets/3d/level/rampy.glb.import | 1062 ++++++++++++++++++++++++++++++ src/Level/Rampy.tscn | 19 + src/Main/Game.tscn | 12 +- src/Player/States/Air.gd | 6 + src/Player/States/Move.gd | 4 +- src/Player/States/Run.gd | 2 +- 7 files changed, 1101 insertions(+), 4 deletions(-) create mode 100644 assets/3d/level/rampy.glb create mode 100644 assets/3d/level/rampy.glb.import create mode 100644 src/Level/Rampy.tscn diff --git a/assets/3d/level/rampy.glb b/assets/3d/level/rampy.glb new file mode 100644 index 0000000000000000000000000000000000000000..de0c8919d13190d17541253d4dc91e3608a03ff9 GIT binary patch literal 2896 zcmb7E+iu%N5S_YC(=<)5X`8lb!)|&n&5#tOSbB)%s1D%7wgSrt3K(fkNo$#aL>eUJ zHV_QxQ~D?I$MmspeacJGnbEF9)3(emu)DLf=bX7LrCxvM(EqhkY4#Wo)e9YZ^z6Wm{!oiX#~(K@=j^wQO;0 zill>lQL~kmh}!N*g#G}1qQ!Tn2&1l~3;X%;^Vw-61~NHds=_yhZ7B#c@KYHFet)9Y zjfU;MYz1A}6}2=TO4OJH*i<-7?64hg%GB@ogU)s|>>Y$MLH0&03ZSL1=vc>^`YdmvZkMYS+pBoxW3C8GuqfmzF&Wl5Qva;h=OwoykA$}WWR{H}V zu55bdGBqH;m)~7-Oxs*4;W=fJc(&Fk;kSUz&WK~0mx<4#yZ?voo{5gBpN-B=F6}c;9ee|EF{;!XgONQ4?z!G+ZO6Tj zFRWX8M&9xA_)4`xAKauCRYxXyXW66g!Y~Z`D!{|_E&OK~ui&h!UE445Oq2Xso9^*U zgL%q^RfVh1{8=vJl}?sBjeCwJ$6X<`($+Ta6r26Zp6V$7dHFDb^2}n0U!VB?#GMA+ zPwkg8{Hc71hj%NM1$L2q z0j#xOSN^{8?*mdSVq;wF9o0pnkWKv^6B@T7_FVmc7RxI%Nvw!XxXGO6isv&nLTJo? z2kX^e53E;RssS#yIR=ZWc<0##`e9(LV|*Xl0q0(3C;th*-E60Ojjy9k_j(`W*`Rxz zfPTW!4hpAt@}H=C#%IoZ#8+ozUWg;U*3)~Qm*wktng@!n_k122NB+G27`a(I-Dh#< zopqeOj2_|gaq>8Qehn5dkp*}i7U2rK0axKoxQ6RBcnhw>+i(Nd8}JUi3-7`E@Bw@X zH*viQAHm1)3EaZ<7JLey!RK%r*W2&~p1*`UxZVK+z5)SvalH#)!#D6Pd void: + var velocity_previous_y = _parent.velocity.y _parent.physics_process(delta) if player.is_on_floor(): _state_machine.transition_to("Move/Idle") elif player.is_on_ceiling(): _parent.velocity.y = 0 + elif player.is_on_wall() and _parent.velocity.y > velocity_previous_y: + _parent.velocity.y = velocity_previous_y + _parent.gravity*delta + func enter(msg: Dictionary = {}) -> void: @@ -16,8 +20,10 @@ func enter(msg: Dictionary = {}) -> void: {"velocity": var v, "jump_impulse": var ji}: _parent.velocity = v + Vector3(0, ji, 0) skin.transition_to(skin.States.AIR) + _parent.snap = Vector3.ZERO _parent.enter() func exit() -> void: + _parent.snap = Vector3.DOWN _parent.exit() diff --git a/src/Player/States/Move.gd b/src/Player/States/Move.gd index 06f2bd5..fb8e70e 100644 --- a/src/Player/States/Move.gd +++ b/src/Player/States/Move.gd @@ -12,7 +12,7 @@ export var jump_impulse = 25 export(float, 0.1, 20.0, 0.1) var rotation_speed_factor: = 10.0 var velocity: = Vector3.ZERO - +var snap: = Vector3.DOWN func unhandled_input(event: InputEvent) -> void: if event.is_action_pressed("jump"): @@ -39,7 +39,7 @@ func physics_process(delta: float) -> void: # Movement velocity = calculate_velocity(velocity, move_direction, delta) - velocity = player.move_and_slide(velocity, Vector3.UP) + velocity = player.move_and_slide_with_snap(velocity, snap, Vector3.UP, true) func enter(msg: Dictionary = {}) -> void: diff --git a/src/Player/States/Run.gd b/src/Player/States/Run.gd index 569f6ba..43ee83b 100644 --- a/src/Player/States/Run.gd +++ b/src/Player/States/Run.gd @@ -8,7 +8,7 @@ func unhandled_input(event: InputEvent) -> void: func physics_process(delta: float) -> void: _parent.physics_process(delta) - if player.is_on_floor() or player.is_on_wall(): + if player.is_on_floor() : if _parent.velocity.length() < 0.001: _state_machine.transition_to("Move/Idle") else: