Compare commits
2 Commits
1e0268032f
...
a0abce8306
Author | SHA1 | Date |
---|---|---|
Cat Flynn | a0abce8306 | |
ktyl | e516150465 |
|
@ -1,7 +1,7 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://scenes/Train.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://scenes/Railway.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://scenes/trains/Train.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://scenes/trains/Railway.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://scenes/OrbitCamera.tscn" type="PackedScene" id=3]
|
||||
|
||||
[node name="Main" type="Node2D"]
|
||||
|
@ -10,7 +10,6 @@
|
|||
transform = Transform( 0.515898, 0.606099, -0.605386, -0.393123, 0.795389, 0.461314, 0.76112, -2.26831e-08, 0.648611, 0, 0, 0 )
|
||||
|
||||
[node name="OrbitCamera" parent="." instance=ExtResource( 3 )]
|
||||
_speed = 0.5
|
||||
|
||||
[node name="Railway" parent="." instance=ExtResource( 2 )]
|
||||
|
||||
|
|
|
@ -6,5 +6,5 @@
|
|||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Camera" type="Camera" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 0.913325, 0.407231, 0, -0.407231, 0.913325, 0, 24.1191, 58.6188 )
|
||||
transform = Transform( 1, 0, 0, 0, 0.964146, 0.265371, 0, -0.265371, 0.964146, 0, 2.21115, 9.48434 )
|
||||
fov = 25.0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://scripts/trains/Train.cs" type="Script" id=1]
|
||||
[ext_resource path="res://scenes/TrainCar.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://scenes/trains/TrainCar.tscn" type="PackedScene" id=2]
|
||||
|
||||
[node name="Train" type="Spatial"]
|
||||
script = ExtResource( 1 )
|
|
@ -1,7 +1,7 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://scripts/trains/TrainCar.cs" type="Script" id=1]
|
||||
[ext_resource path="res://scenes/Bogie.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://scenes/trains/Bogie.tscn" type="PackedScene" id=2]
|
||||
|
||||
[node name="Train Car" type="Spatial"]
|
||||
script = ExtResource( 1 )
|
|
@ -4,15 +4,44 @@ using System;
|
|||
public class OrbitCamera : Spatial
|
||||
{
|
||||
[Export]
|
||||
private float _speed;
|
||||
private float _sensitivity = 200f;
|
||||
|
||||
public override void _Ready()
|
||||
private Vector2 _rotation;
|
||||
private bool _canRotate = false;
|
||||
|
||||
public override void _Input(InputEvent e)
|
||||
{
|
||||
|
||||
if (e is InputEventMouseMotion mouseMotion)
|
||||
{
|
||||
HandleMouseMovement(mouseMotion);
|
||||
}
|
||||
if (e is InputEventMouseButton mouseButton)
|
||||
{
|
||||
HandleMouseButton(mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(float delta)
|
||||
{
|
||||
Rotate(Vector3.Up, _speed * delta);
|
||||
Rotation = Vector3.Zero;
|
||||
var sensitivity = -1f / _sensitivity;
|
||||
Rotate(Vector3.Right, _rotation.y * sensitivity);
|
||||
Rotate(Vector3.Up, _rotation.x * sensitivity);
|
||||
}
|
||||
|
||||
// left click to drag
|
||||
private void HandleMouseButton(InputEventMouseButton mouseButton)
|
||||
{
|
||||
if (mouseButton.ButtonIndex != (int)ButtonList.Left) return;
|
||||
|
||||
_canRotate = mouseButton.Pressed;
|
||||
}
|
||||
|
||||
private void HandleMouseMovement(InputEventMouseMotion mouseMotion)
|
||||
{
|
||||
if (!_canRotate) return;
|
||||
|
||||
var delta = mouseMotion.Relative;
|
||||
_rotation += delta;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue