Add working camera with an offset effect for persception of motion
This commit is contained in:
parent
9d052b0489
commit
e90949a8d9
|
|
@ -1,7 +1,8 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://ckh362yqjkpi0"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://ckh362yqjkpi0"]
|
||||
|
||||
[ext_resource type="Script" path="res://script/player.cs" id="1_lhmq0"]
|
||||
[ext_resource type="Texture2D" uid="uid://lcb2vm87qo30" path="res://assets/PNG/playerShip1_blue.png" id="2_1ykv0"]
|
||||
[ext_resource type="Script" path="res://script/camera.cs" id="3_ui7sm"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_btpq3"]
|
||||
radius = 41.0488
|
||||
|
|
@ -18,3 +19,6 @@ texture = ExtResource("2_1ykv0")
|
|||
|
||||
[node name="LaserSpawn" type="Node2D" parent="."]
|
||||
position = Vector2(0, -58)
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
script = ExtResource("3_ui7sm")
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ public partial class asteroid : Area2D
|
|||
var radius = circleshape.Radius;
|
||||
var ScreenSize = GetViewportRect().Size;
|
||||
|
||||
/*
|
||||
if (GlobalPosition.Y + radius < 0)
|
||||
{
|
||||
GlobalPosition = new Vector2(GlobalPosition.X, ScreenSize.Y + radius);
|
||||
|
|
@ -97,5 +98,6 @@ public partial class asteroid : Area2D
|
|||
{
|
||||
GlobalPosition = new Vector2(-radius, GlobalPosition.Y);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
28
MB_FYP/script/camera.cs
Normal file
28
MB_FYP/script/camera.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class camera : Camera2D
|
||||
{
|
||||
[Export] public Vector2 OffsetAmount = new Vector2(100, 0);
|
||||
[Export] public float SmoothingSpeed = 0.1f;
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
|
||||
public CharacterBody2D Player;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
Player = GetParent<CharacterBody2D>();
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
|
||||
Vector2 playerPos = Player.GlobalPosition;
|
||||
Vector2 playerV = Player.Velocity;
|
||||
Vector2 direction = playerV.Normalized();
|
||||
Vector2 cameraTargetPos = playerPos + OffsetAmount * direction;
|
||||
GlobalPosition = GlobalPosition.Lerp(cameraTargetPos, SmoothingSpeed);
|
||||
}
|
||||
}
|
||||
|
|
@ -46,18 +46,12 @@ public partial class player : CharacterBody2D
|
|||
Node2D Laser = LaserScene.Instantiate<Node2D>();
|
||||
Laser.Position = LaserSpawn.GlobalPosition;
|
||||
Laser.Rotation = Rotation;
|
||||
GD.Print("shoooot");
|
||||
var l = new Laser
|
||||
{
|
||||
Position = new Vector2(LaserSpawn.Position.X, LaserSpawn.Position.Y),
|
||||
Rotation = Rotation
|
||||
};
|
||||
EmitSignal(SignalName.LaserShot, Laser);
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
GD.Print(GetViewportRect().Size);
|
||||
//GD.Print(GetViewportRect().Size);
|
||||
ScreenSize = GetViewportRect().Size;
|
||||
LaserSpawn = GetNode<Node2D>("LaserSpawn");
|
||||
}
|
||||
|
|
@ -77,9 +71,11 @@ public partial class player : CharacterBody2D
|
|||
|
||||
MoveAndSlide();
|
||||
|
||||
/*
|
||||
if (Position.Y < 0) {Position = new Vector2(Position.X, ScreenSize.Y);}
|
||||
if (Position.Y > ScreenSize.Y) {Position = new Vector2(Position.X, 0);}
|
||||
if (Position.X < 0) { Position = new Vector2(ScreenSize.X, Position.Y);}
|
||||
if (Position.X > ScreenSize.X) { Position = new Vector2(0, Position.Y);}
|
||||
*/
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue