Simple Node Based movement System
Every Field is a Node Additional: Camera dump smooth follow
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb6f7c9a6e6cd424c853338442fa92fc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Camera : MonoBehaviour
|
||||
{
|
||||
//TODO: Replace with Follow Function later (player camera should follow)
|
||||
[SerializeField] private GameObject followUp;
|
||||
private Vector3 offset;
|
||||
private Vector3 velocity = Vector3.zero;
|
||||
|
||||
//TODO: Replace with Follow Function later (player camera should follow)
|
||||
private void Start()
|
||||
{
|
||||
offset = followUp.transform.position - transform.position;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
transform.position = Vector3.SmoothDamp(transform.position, followUp.transform.position - offset, ref velocity, 0.6f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f02425538b327cc47a5d70da69804669
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -4,9 +4,10 @@ using UnityEngine;
|
||||
|
||||
public abstract class Field : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject[] target;
|
||||
//Liste der nächsten Feld, die auf das diesige Feld folgen
|
||||
[SerializeField] private Field[] target;
|
||||
|
||||
public GameObject[] Target
|
||||
public Field[] Target
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -14,5 +15,6 @@ public abstract class Field : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
//Feld aktion (Münzen etc..)
|
||||
public abstract void Action();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcbe5b660ed69574181c2fc9d164238d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Field nextField;
|
||||
private Field currentField;
|
||||
[SerializeField] private GameObject dice;
|
||||
private Vector3 moveTo = Vector3.zero;
|
||||
private Vector3 lastPos = Vector3.zero;
|
||||
private float speed = 5;
|
||||
private float interPol = 0;
|
||||
private int wurfelZahl = 0;
|
||||
|
||||
private bool activated = true;
|
||||
private bool wait = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Debug.Log("Test: zum Würfeln Leertaste drücken!");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(activated)
|
||||
{
|
||||
//Generiere Würfelzahl von 1-6 wenn gerade gewürfelt werden darf
|
||||
if (Input.GetKeyDown(KeyCode.Space) && wurfelZahl == 0)
|
||||
{
|
||||
wurfelZahl = Random.Range(1, 7);
|
||||
Debug.Log("Test: gewürfelt wurde " + wurfelZahl);
|
||||
//nächstes Feld anvisieren
|
||||
TargetNextField();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (activated)
|
||||
{
|
||||
if (!wait)
|
||||
{
|
||||
//Laufe zum nöchsten Feld, falls noch Züge übrig sind
|
||||
if (interPol < 1 && wurfelZahl > 0)
|
||||
{
|
||||
InterPolerate();
|
||||
}
|
||||
//Würfelzahl um 1 verringern falls noch züge übrig sind
|
||||
else if (wurfelZahl > 0 )
|
||||
{
|
||||
wurfelZahl--;
|
||||
|
||||
//Visiere das nächste Feld an falls noch ein Zug übrig ist (Player steht gerade auf einem Feld oder läuft darüber)
|
||||
if (wurfelZahl > 0)
|
||||
{
|
||||
TargetNextField();
|
||||
}
|
||||
}
|
||||
//Der Spieler steht gerade
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//TEST!!!!!!!!!!!!!!!
|
||||
//TODO: Replace with selection arrows
|
||||
if (Input.GetKeyDown(KeyCode.N))
|
||||
{
|
||||
nextField = nextField = nextField.Target[0];
|
||||
moveTo = nextField.transform.position;
|
||||
wait = false;
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.A))
|
||||
{
|
||||
nextField = nextField = nextField.Target[1];
|
||||
moveTo = nextField.transform.position;
|
||||
wait = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Das nächste Feld aufgrund des aktuellen Feldes anvisieren
|
||||
private void TargetNextField()
|
||||
{
|
||||
interPol = 0;
|
||||
lastPos = transform.position;
|
||||
currentField = nextField;
|
||||
if(nextField.Target.Length == 1)
|
||||
{
|
||||
nextField = nextField.Target[0];
|
||||
moveTo = nextField.transform.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
wait = true;
|
||||
Debug.Log("Test: AlternativWeg = A NormalerWeg = N");
|
||||
}
|
||||
}
|
||||
|
||||
//Bewegt den Player von einem Punkt(lastPos) zu einem anderen Punkt(moveTo) mit konstanter Geschwindigkeit
|
||||
private void InterPolerate()
|
||||
{
|
||||
Vector3 nextPoint = Vector3.Lerp(lastPos, moveTo, interPol);
|
||||
transform.position = new Vector3(nextPoint.x, transform.position.y, nextPoint.z);
|
||||
interPol += (Time.deltaTime * speed) / Mathf.Abs(Vector3.Distance(moveTo, lastPos));
|
||||
}
|
||||
|
||||
//Aktiviert den Player
|
||||
public void Activate()
|
||||
{
|
||||
activated = true;
|
||||
}
|
||||
|
||||
//Deaktiviert den Player
|
||||
public void DeActivate()
|
||||
{
|
||||
activated = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c5b74f4bdf875641a8d9ac432a5166f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user