added a rotation system for player and improved camera movement
This commit is contained in:
@@ -61,22 +61,36 @@ height = 43.9998
|
|||||||
process_mode = 1
|
process_mode = 1
|
||||||
script = ExtResource("1_qehox")
|
script = ExtResource("1_qehox")
|
||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="rotation_center" type="Marker2D" parent="."]
|
||||||
|
|
||||||
|
[node name="ray_cast_2d" type="RayCast2D" parent="rotation_center"]
|
||||||
|
rotation = 3.14159
|
||||||
|
target_position = Vector2(-64, 0)
|
||||||
|
collision_mask = 2
|
||||||
|
collide_with_areas = true
|
||||||
|
|
||||||
|
[node name="animated_sprite_2d" type="AnimatedSprite2D" parent="."]
|
||||||
position = Vector2(-0.0625, -17.0625)
|
position = Vector2(-0.0625, -17.0625)
|
||||||
scale = Vector2(0.733398, 0.733398)
|
scale = Vector2(0.733398, 0.733398)
|
||||||
frames = SubResource("SpriteFrames_2x1cy")
|
frames = SubResource("SpriteFrames_2x1cy")
|
||||||
animation = &"move_down"
|
animation = &"move_down"
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="collision_shape" type="CollisionShape2D" parent="."]
|
||||||
position = Vector2(0, 12)
|
position = Vector2(0, 12)
|
||||||
rotation = 1.57345
|
rotation = 1.57345
|
||||||
shape = SubResource("CapsuleShape2D_38v5o")
|
shape = SubResource("CapsuleShape2D_38v5o")
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="camera_2d" type="Camera2D" parent="."]
|
||||||
current = true
|
current = true
|
||||||
zoom = Vector2(0.8, 0.8)
|
zoom = Vector2(0.8, 0.8)
|
||||||
|
rotation_smoothing_enabled = true
|
||||||
|
drag_horizontal_enabled = true
|
||||||
|
drag_vertical_enabled = true
|
||||||
|
drag_left_margin = 0.15
|
||||||
|
drag_top_margin = 0.15
|
||||||
|
drag_right_margin = 0.15
|
||||||
|
drag_bottom_margin = 0.15
|
||||||
|
editor_draw_drag_margin = true
|
||||||
|
|
||||||
[node name="ray_cast_2d" type="RayCast2D" parent="."]
|
[node name="audio_listener_2d" type="AudioListener2D" parent="."]
|
||||||
target_position = Vector2(0, 64)
|
current = true
|
||||||
collision_mask = 2
|
|
||||||
collide_with_areas = true
|
|
||||||
|
@@ -5,14 +5,14 @@ public partial class player : CharacterBody2D
|
|||||||
{
|
{
|
||||||
[Export] public string playerName;
|
[Export] public string playerName;
|
||||||
[Export] public int speed = 200;
|
[Export] public int speed = 200;
|
||||||
public float rayCastLength;
|
|
||||||
public Vector2 movement;
|
public Vector2 movement;
|
||||||
public AnimatedSprite2D animatedSprite;
|
public AnimatedSprite2D animatedSprite;
|
||||||
|
public Marker2D rotCenter;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
rayCastLength = GetNode<RayCast2D>("ray_cast_2d").TargetPosition.y;
|
animatedSprite = GetNode<AnimatedSprite2D>("animated_sprite_2d");
|
||||||
animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
|
rotCenter = GetNode<Marker2D>("rotation_center");
|
||||||
}
|
}
|
||||||
public void ChangeProcess(bool process)
|
public void ChangeProcess(bool process)
|
||||||
{
|
{
|
||||||
@@ -22,18 +22,17 @@ public partial class player : CharacterBody2D
|
|||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
movement = Input.GetVector("move_left", "move_right", "move_up", "move_down");
|
movement = Input.GetVector("move_left", "move_right", "move_up", "move_down");
|
||||||
|
rotCenter.Rotation = movement.Angle();
|
||||||
MoveAndCollide(movement * speed * (float)delta);
|
MoveAndCollide(movement * speed * (float)delta);
|
||||||
}
|
}
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
//set ray_cast target position
|
|
||||||
RayCast2D rayCast = GetNode<RayCast2D>("ray_cast_2d");
|
|
||||||
Vector2 rayCastPosition = new Vector2((float)Math.Round(movement.x), (float)Math.Round(movement.y)) * rayCastLength;
|
|
||||||
if (rayCastPosition.Length() != 0) rayCast.TargetPosition = rayCastPosition;
|
|
||||||
//call event in raycasted object
|
//call event in raycasted object
|
||||||
/*if (Input.IsActionJustPressed("ui_accept") && rayCast.IsColliding())
|
/*if (Input.IsActionJustPressed("ui_accept") && rayCast.IsColliding())
|
||||||
rayCast.GetCollider().Call("OnInteraction", playerName);*/
|
rayCast.GetCollider().Call("OnInteraction", playerName);*/
|
||||||
//animation system (with controller support wcih cant get normalized vector)
|
|
||||||
|
//animation system (with controller support wich cant get normalized vector)
|
||||||
if (movement.Length() != 0)
|
if (movement.Length() != 0)
|
||||||
animatedSprite.Play();
|
animatedSprite.Play();
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user