Added Sprite Swap and Horizontal flipping to character controller
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
@@ -0,0 +1,35 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://duaideiajsu8r"
|
||||
path.s3tc="res://.godot/imported/babushka concept art vesna.png-93b9cf316889e012747999bc7ff6e108.s3tc.ctex"
|
||||
metadata={
|
||||
"imported_formats": ["s3tc_bptc"],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://art/Characters/Vesna/babushka concept art vesna.png"
|
||||
dest_files=["res://.godot/imported/babushka concept art vesna.png-93b9cf316889e012747999bc7ff6e108.s3tc.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=true
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=0
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
+18
-4
@@ -1,7 +1,7 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://dbd1niu3tp8y5"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cp4snd0amnhfu" path="res://scripts/CSharp/Common/Player3D.cs" id="1_3trg2"]
|
||||
[ext_resource type="Texture2D" uid="uid://cvn2p215jq2am" path="res://art/mockups/concerned.png" id="1_5jpx2"]
|
||||
[ext_resource type="Texture2D" uid="uid://duaideiajsu8r" path="res://art/Characters/Vesna/babushka concept art vesna.png" id="2_3trg2"]
|
||||
[ext_resource type="Script" uid="uid://c81bn1w8o0n2n" path="res://scripts/CSharp/Common/CameraPivot.cs" id="3_3trg2"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_1vdrh"]
|
||||
@@ -10,19 +10,33 @@ height = 0.234557
|
||||
|
||||
[node name="Player3d" type="Node3D"]
|
||||
|
||||
[node name="CharacterBody3D" type="CharacterBody3D" parent="." node_paths=PackedStringArray("_camera")]
|
||||
[node name="CharacterBody3D" type="CharacterBody3D" parent="." node_paths=PackedStringArray("_camera", "_frontSprite", "_sideSprite")]
|
||||
collision_layer = 16
|
||||
collision_mask = 17
|
||||
script = ExtResource("1_3trg2")
|
||||
_speed = 10.0
|
||||
_camera = NodePath("CameraPivot2/SubPivot/Camera3D")
|
||||
_frontSprite = NodePath("FrontSprite")
|
||||
_sideSprite = NodePath("SideSprite")
|
||||
|
||||
[node name="Sprite" type="Sprite3D" parent="CharacterBody3D"]
|
||||
[node name="FrontSprite" type="Sprite3D" parent="CharacterBody3D"]
|
||||
transform = Transform3D(0.04, 0, 0, 0, 0.04, 0, 0, 0, 0.04, 0, 0.110813, 0)
|
||||
billboard = 1
|
||||
shaded = true
|
||||
render_priority = 100
|
||||
texture = ExtResource("1_5jpx2")
|
||||
texture = ExtResource("2_3trg2")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(52, 20, 648, 1175)
|
||||
|
||||
[node name="SideSprite" type="Sprite3D" parent="CharacterBody3D"]
|
||||
transform = Transform3D(0.04, 0, 0, 0, 0.04, 0, 0, 0, 0.04, 0, 0.110813, 0)
|
||||
visible = false
|
||||
billboard = 1
|
||||
shaded = true
|
||||
render_priority = 100
|
||||
texture = ExtResource("2_3trg2")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(803, 17, 663, 1161)
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="CharacterBody3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.119886, 0)
|
||||
|
||||
@@ -6,23 +6,76 @@ public partial class Player3D : CharacterBody3D
|
||||
{
|
||||
[Export] private float _speed = 1.0f;
|
||||
[Export] private Camera3D _camera;
|
||||
[Export] private Sprite3D _frontSprite;
|
||||
[Export] private Sprite3D _sideSprite;
|
||||
|
||||
private bool _sideFlipped;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (!IsOnFloor()) Velocity += Vector3.Down * (float) delta;
|
||||
|
||||
var inputDir = Input.GetVector("move_left", "move_right", "move_up", "move_down");
|
||||
if (inputDir == Vector2.Zero)
|
||||
return;
|
||||
|
||||
MoveOnInput(inputDir, delta);
|
||||
SwitchSprites(inputDir);
|
||||
}
|
||||
|
||||
private void MoveOnInput(Vector2 inputDir, double delta)
|
||||
{
|
||||
inputDir = inputDir.Rotated(-_camera.GlobalRotation.Y);
|
||||
var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
|
||||
if (direction != Vector3.Zero)
|
||||
{
|
||||
Velocity = new Vector3(direction.X * _speed, Velocity.Y, direction.Z * _speed * (float) delta * Scale.X);
|
||||
}
|
||||
Velocity = new Vector3(direction.X * _speed * (float) delta * Scale.X, Velocity.Y, direction.Z * _speed * (float) delta * Scale.Z);
|
||||
else
|
||||
{
|
||||
Velocity = Velocity.MoveToward(new Vector3(0, 0, 0), _speed);
|
||||
}
|
||||
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
private void SwitchSprites(Vector2 inputDir)
|
||||
{
|
||||
float X = inputDir.X;
|
||||
float Y = inputDir.Y;
|
||||
|
||||
if (X == 0.0 && Y == 0.0)
|
||||
{
|
||||
ActivateFrontSprite(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (X != 0)
|
||||
{
|
||||
ActivateFrontSprite(false);
|
||||
|
||||
if (X > 0.0f)
|
||||
{
|
||||
_sideFlipped = false;
|
||||
_sideSprite.FlipH = _sideFlipped;
|
||||
}
|
||||
|
||||
if (X < 0.0f)
|
||||
{
|
||||
_sideFlipped = true;
|
||||
_sideSprite.FlipH = _sideFlipped;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Y != 0)
|
||||
{
|
||||
ActivateFrontSprite(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ActivateFrontSprite(bool activate)
|
||||
{
|
||||
_frontSprite.Visible = activate;
|
||||
_sideSprite.Visible = !activate;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user