Browse Source

Updates to player movement

master
NickFowler 4 years ago
parent
commit
6f863020a2
5 changed files with 85 additions and 11 deletions
  1. +20
    -0
      Assets/Scripts/Input/DynamicCamera.cs
  2. +11
    -0
      Assets/Scripts/Input/DynamicCamera.cs.meta
  3. +1
    -1
      Assets/Scripts/Input/HerdController.cs
  4. +17
    -9
      Assets/Scripts/Input/PlayerController.cs
  5. +36
    -1
      Assets/WorldAssets/Prefabs/Horse.prefab

+ 20
- 0
Assets/Scripts/Input/DynamicCamera.cs View File

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public GameObject Target;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

+ 11
- 0
Assets/Scripts/Input/DynamicCamera.cs.meta View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 49812763c430a0f4cb0f5e99a203f1ad
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 1
- 1
Assets/Scripts/Input/HerdController.cs View File

@ -92,7 +92,7 @@ public class HerdController : MonoBehaviour
{ {
foreach (PlayerController pc in Herd) foreach (PlayerController pc in Herd)
{ {
pc.MoveObject();
pc.MoveObject(WaitTime);
} }
yield return new WaitForSeconds(WaitTime); yield return new WaitForSeconds(WaitTime);

+ 17
- 9
Assets/Scripts/Input/PlayerController.cs View File

@ -2,16 +2,20 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using Random = System.Random;
public class PlayerController : MonoBehaviour public class PlayerController : MonoBehaviour
{ {
public float walkSpeed; public float walkSpeed;
public GameObject model; public GameObject model;
private float speedMulitplier;
private Vector2 receivedInput; private Vector2 receivedInput;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
speedMulitplier = UnityEngine.Random.Range(0.8f, 1.2f);
} }
public void SetMovement(Vector2 input) public void SetMovement(Vector2 input)
@ -27,8 +31,8 @@ public class PlayerController : MonoBehaviour
float rotateTo = RotateObject(HorseX, HorseZ); float rotateTo = RotateObject(HorseX, HorseZ);
HorseZ *= walkSpeed;
HorseX *= walkSpeed;
HorseZ *= Time.deltaTime * walkSpeed * speedMulitplier;
HorseX *= Time.deltaTime * walkSpeed * speedMulitplier;
transform.Translate(HorseX, 0, HorseZ); transform.Translate(HorseX, 0, HorseZ);
@ -66,18 +70,22 @@ public class PlayerController : MonoBehaviour
return to; return to;
} }
public void MoveObject()
public void MoveObject(float wait)
{ {
UpdatePosition();
if (receivedInput.x != 0 || receivedInput.y != 0)
{
model.transform.Rotate(-90, 0, 0);
}
StartCoroutine(RandomWait(wait));
}
public IEnumerator RandomWait(float wait)
{
yield return new WaitForSeconds(UnityEngine.Random.Range(0, wait/2));
Vector3 rotateDir = new Vector3(90 * Math.Sign(receivedInput.y), 0, -90 * Math.Sign(receivedInput.x));
model.transform.Rotate(rotateDir, Space.World);
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
UpdatePosition();
} }
} }

+ 36
- 1
Assets/WorldAssets/Prefabs/Horse.prefab View File

@ -64,7 +64,7 @@ CharacterController:
m_StepOffset: 0.3 m_StepOffset: 0.3
m_SkinWidth: 0.08 m_SkinWidth: 0.08
m_MinMoveDistance: 0.001 m_MinMoveDistance: 0.001
m_Center: {x: 0, y: 1, z: 0}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1001 &7371939184763441364 --- !u!1001 &7371939184763441364
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -77,6 +77,11 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: Cube value: Cube
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 687741958870159176, guid: 4d11c77c6b58b7040a8596bc47f45d97,
type: 3}
propertyPath: m_LocalPosition.y
value: -0.5
objectReference: {fileID: 0}
- target: {fileID: 1281286576698487906, guid: 4d11c77c6b58b7040a8596bc47f45d97, - target: {fileID: 1281286576698487906, guid: 4d11c77c6b58b7040a8596bc47f45d97,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
@ -132,6 +137,36 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1317434602306065355, guid: 4d11c77c6b58b7040a8596bc47f45d97,
type: 3}
propertyPath: m_LocalPosition.y
value: -0.5
objectReference: {fileID: 0}
- target: {fileID: 1652654074722291708, guid: 4d11c77c6b58b7040a8596bc47f45d97,
type: 3}
propertyPath: m_LocalPosition.y
value: -0.5
objectReference: {fileID: 0}
- target: {fileID: 1731993206513226773, guid: 4d11c77c6b58b7040a8596bc47f45d97,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.06
objectReference: {fileID: 0}
- target: {fileID: 2458785659072919632, guid: 4d11c77c6b58b7040a8596bc47f45d97,
type: 3}
propertyPath: m_LocalPosition.y
value: -0.5
objectReference: {fileID: 0}
- target: {fileID: 7081464788313828805, guid: 4d11c77c6b58b7040a8596bc47f45d97,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.15
objectReference: {fileID: 0}
- target: {fileID: 8693433057835279953, guid: 4d11c77c6b58b7040a8596bc47f45d97,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.577
objectReference: {fileID: 0}
m_RemovedComponents: m_RemovedComponents:
- {fileID: -641725564868193174, guid: 4d11c77c6b58b7040a8596bc47f45d97, type: 3} - {fileID: -641725564868193174, guid: 4d11c77c6b58b7040a8596bc47f45d97, type: 3}
- {fileID: 6187295151528677371, guid: 4d11c77c6b58b7040a8596bc47f45d97, type: 3} - {fileID: 6187295151528677371, guid: 4d11c77c6b58b7040a8596bc47f45d97, type: 3}

Loading…
Cancel
Save