This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -91,6 +91,12 @@ move_down={
|
|||||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
turn_back={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":86,"key_label":0,"unicode":118,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":10,"pressure":0.0,"pressed":true,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[physics]
|
[physics]
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
|||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public float JumpHeight { get; set; } = 5.5f;
|
public float JumpHeight { get; set; } = 5.5f;
|
||||||
|
|
||||||
private float PeakTime { get; set; } = 0.1f;
|
|
||||||
|
|
||||||
[ExportCategory("Max Speeds")]
|
[ExportCategory("Max Speeds")]
|
||||||
[Export]
|
[Export]
|
||||||
@@ -73,7 +71,7 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
|||||||
private float _lv = 0.0f;
|
private float _lv = 0.0f;
|
||||||
|
|
||||||
private void RecalculateLv() {
|
private void RecalculateLv() {
|
||||||
_lv = Mathf.Sqrt(Mathf.Pow(Gravity * PeakTime / 2, 2) + 2 * Gravity * JumpHeight);
|
_lv = Mathf.Sqrt(Mathf.Pow(Gravity * 0.1f / 2, 2) + 2 * Gravity * JumpHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Ready() {
|
public override void _Ready() {
|
||||||
@@ -151,7 +149,7 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
|||||||
vely *= 1/4f;
|
vely *= 1/4f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.IsActionJustPressed("jump") && vely > 0) {
|
if (Input.IsActionJustPressed("turn_back") && vely > 0) {
|
||||||
var side = velx > 0 ? PredictiveCollisions.Location.BottomRight : PredictiveCollisions.Location.BottomLeft;
|
var side = velx > 0 ? PredictiveCollisions.Location.BottomRight : PredictiveCollisions.Location.BottomLeft;
|
||||||
if (Predictor.AnyHit(side) && !this.IsOnWall()) {
|
if (Predictor.AnyHit(side) && !this.IsOnWall()) {
|
||||||
EmitSignal(SignalName.OnTurnbackJump, true, this.IsOnWall());
|
EmitSignal(SignalName.OnTurnbackJump, true, this.IsOnWall());
|
||||||
@@ -174,17 +172,31 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
// has jump point
|
// has jump point
|
||||||
float theta = Mathf.Atan2(-yAxis, xAxis);
|
float theta = Mathf.Atan2(-yAxis, Mathf.Abs(xAxis));
|
||||||
if (theta < 0) theta = 0;
|
float margin = 20 * (Mathf.Pi / 180f);
|
||||||
if (theta > Mathf.Pi / 2) theta = Mathf.Pi/2;
|
if (theta < margin) theta = margin;
|
||||||
Vector2 turnjump = new Vector2(Mathf.Cos(theta), -Mathf.Sin(theta) - 0.2f) * _lv;
|
if (theta > Mathf.Pi / 2 - margin) theta = Mathf.Pi/2 - margin;
|
||||||
|
Vector2 turnjump = new Vector2(-Mathf.Sign(velx) * Mathf.Cos(theta), -Mathf.Sin(theta) - 0.2f) * _lv;
|
||||||
|
GD.Print($"Theta: {theta * (180 / Mathf.Pi)}, turnjump: {turnjump}");
|
||||||
velx = turnjump.X;
|
velx = turnjump.X;
|
||||||
vely = turnjump.Y;
|
vely = turnjump.Y;
|
||||||
} else {
|
} else {
|
||||||
// does not have jump point
|
// does not have jump point
|
||||||
|
// float theta = Mathf.Atan2(-yAxis, Mathf.Abs(xAxis));
|
||||||
|
// float margin = 20 * (Mathf.Pi / 180f);
|
||||||
|
// if (theta < margin) theta = margin;
|
||||||
|
// if (theta > Mathf.Pi / 2 - margin) theta = Mathf.Pi/2 - margin;
|
||||||
|
// Vector2 turnjump = new Vector2(-Mathf.Sign(Velocity.X) * Mathf.Cos(theta), -Mathf.Sin(theta) - 0.2f) * _lv;
|
||||||
|
// GD.Print($"Theta: {theta * (180 / Mathf.Pi)}, turnjump: {turnjump}");
|
||||||
|
// velx = turnjump.X;
|
||||||
|
// vely = turnjump.Y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Input.IsActionJustPressed("jump") && Mathf.Abs(vely) < 2) {
|
||||||
|
vely = -_lv;
|
||||||
|
}
|
||||||
|
|
||||||
velx += xAxis * AirAcceleration * (float)delta;
|
velx += xAxis * AirAcceleration * (float)delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user