diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity
index 8734776..5bdea17 100644
Binary files a/Assets/Scenes/Game.unity and b/Assets/Scenes/Game.unity differ
diff --git a/Assets/Scripts/PlayerInput.cs b/Assets/Scripts/PlayerInput.cs
index 7e5569e..c29b1eb 100644
--- a/Assets/Scripts/PlayerInput.cs
+++ b/Assets/Scripts/PlayerInput.cs
@@ -6,35 +6,35 @@ public class PlayerInput : MonoBehaviour
{
public Pokeball pokeball;
- public Vector3 forceLeft;
- public Vector3 forceRight;
+ public Vector3 throwForceLeft = new Vector3(-1, 4, 3.5f);
+ public Vector3 throwForceRight = new Vector3(1, 4, 3.5f);
- bool canThrow = true;
+ bool canThrowPokeball = true;
#if !UNITY_EDITOR
- GestureRecognizer gr;
+ GestureRecognizer gestureRecognizer;
void Awake()
{
- gr = new GestureRecognizer();
+ gestureRecognizer = new GestureRecognizer();
- gr.SetRecognizableGestures(GestureSettings.Tap | GestureSettings.Hold | GestureSettings.ManipulationTranslate);
+ gestureRecognizer.SetRecognizableGestures(GestureSettings.Tap | GestureSettings.Hold | GestureSettings.ManipulationTranslate);
- gr.TappedEvent += Gr_TappedEvent;
- gr.HoldStartedEvent += Gr_HoldStartedEvent;
- gr.HoldCanceledEvent += Gr_HoldCanceledEvent;
- gr.HoldCompletedEvent += Gr_HoldCompletedEvent;
+ gestureRecognizer.TappedEvent += Gr_TappedEvent;
+ gestureRecognizer.HoldStartedEvent += Gr_HoldStartedEvent;
+ gestureRecognizer.HoldCanceledEvent += Gr_HoldCanceledEvent;
+ gestureRecognizer.HoldCompletedEvent += Gr_HoldCompletedEvent;
- gr.StartCapturingGestures();
+ gestureRecognizer.StartCapturingGestures();
}
void OnDestroy()
{
- gr.TappedEvent -= Gr_TappedEvent;
- gr.HoldStartedEvent -= Gr_HoldStartedEvent;
- gr.HoldCanceledEvent -= Gr_HoldCanceledEvent;
- gr.HoldCompletedEvent -= Gr_HoldCompletedEvent;
+ gestureRecognizer.TappedEvent -= Gr_TappedEvent;
+ gestureRecognizer.HoldStartedEvent -= Gr_HoldStartedEvent;
+ gestureRecognizer.HoldCanceledEvent -= Gr_HoldCanceledEvent;
+ gestureRecognizer.HoldCompletedEvent -= Gr_HoldCompletedEvent;
}
#else
@@ -66,12 +66,15 @@ private void Gr_HoldStartedEvent(InteractionSourceKind source, Ray headRay)
private void Gr_TappedEvent(InteractionSourceKind source, int tapCount, Ray headRay)
{
- if (canThrow)
+ if (canThrowPokeball)
{
- canThrow = false;
+ canThrowPokeball = false;
- pokeball.Throw(Camera.main.transform.rotation * Vector3.Lerp(forceLeft, forceRight, Random.Range(0f, 1f)),
- new Vector3(Random.Range(0f, 50f), Random.Range(-2f, 2f), Random.Range(-1f, 1f)));
+ Quaternion cameraRotation = Camera.main.transform.rotation;
+ Vector3 randomThrowForce = Vector3.Lerp(throwForceLeft, throwForceRight, Random.Range(0f, 1f));
+ Vector3 randomThrowAngularForce = new Vector3(Random.Range(0f, 50f), Random.Range(-2f, 2f), Random.Range(-1f, 1f));
+
+ pokeball.Throw(cameraRotation * randomThrowForce, randomThrowAngularForce);
StartCoroutine(Coroutine_ReturnPokeball());
}
@@ -79,11 +82,8 @@ private void Gr_TappedEvent(InteractionSourceKind source, int tapCount, Ray head
IEnumerator Coroutine_ReturnPokeball()
{
- yield return new WaitUntil(() =>
- {
- return pokeball.ready;
- });
+ yield return new WaitUntil(() => { return pokeball.readyToThrow; });
- canThrow = true;
+ canThrowPokeball = true;
}
}
diff --git a/Assets/Scripts/Pokeball.cs b/Assets/Scripts/Pokeball.cs
index 2fab7cb..b63e141 100644
--- a/Assets/Scripts/Pokeball.cs
+++ b/Assets/Scripts/Pokeball.cs
@@ -3,28 +3,25 @@
public class Pokeball : MonoBehaviour
{
- public Transform enterPoint;
+ ///
+ /// We don't have a real pokeball so it can't open for the pokemon to go in
+ ///
+ public Transform pokemonEnterPoint;
Pokemon hitPokemon = null;
- bool isWaitingBeforeCapture = false;
- public bool ready = true;
+ [HideInInspector]
+ public bool readyToThrow = true;
+ bool isWaitingBeforePokemonCapture = false;
- Rigidbody Rigidbody
- {
- get
- {
- return GetComponent();
- }
- }
-
- Vector3 startPosition;
- Quaternion startRotation;
+ new public Rigidbody rigidbody;
+ Vector3 initialPosition;
+ Quaternion initialRotation;
void Awake()
{
- startPosition = transform.localPosition;
- startRotation = transform.localRotation;
+ initialPosition = transform.localPosition;
+ initialRotation = transform.localRotation;
}
void OnCollisionEnter(Collision col)
@@ -38,19 +35,19 @@ void OnCollisionEnter(Collision col)
{
hitPokemon = col.transform.GetComponent();
- isWaitingBeforeCapture = true;
- StartCoroutine(Coroutine_WaitAndCapture());
+ isWaitingBeforePokemonCapture = true;
+ StartCoroutine(Coroutine_CaptureSequence());
}
}
public void Throw(Vector3 velocity, Vector3 angularVelocity)
{
- ready = false;
+ readyToThrow = false;
transform.parent = null;
- Rigidbody.isKinematic = false;
- Rigidbody.velocity = velocity;
- Rigidbody.angularVelocity = angularVelocity;
+ rigidbody.isKinematic = false;
+ rigidbody.velocity = velocity;
+ rigidbody.angularVelocity = angularVelocity;
StartCoroutine(Coroutine_WaitForPokemonReset());
}
@@ -61,10 +58,7 @@ IEnumerator Coroutine_WaitForPokemonReset()
if (hitPokemon != null)
{
- yield return new WaitUntil(() =>
- {
- return !isWaitingBeforeCapture;
- });
+ yield return new WaitUntil(() => { return !isWaitingBeforePokemonCapture; });
yield return new WaitForSeconds(1);
@@ -75,21 +69,21 @@ IEnumerator Coroutine_WaitForPokemonReset()
ResetPokeball();
}
- IEnumerator Coroutine_WaitAndCapture()
+ IEnumerator Coroutine_CaptureSequence()
{
- Vector3 lastVelocity = Rigidbody.velocity;
+ Vector3 lastVelocity = rigidbody.velocity;
if (lastVelocity.z < 0)
{
lastVelocity.z = -lastVelocity.z;
}
- Rigidbody.velocity = lastVelocity;
+ rigidbody.velocity = lastVelocity;
lastVelocity *= 0.5f;
- Vector3 angularVelocity = Rigidbody.angularVelocity;
+ Vector3 angularVelocity = rigidbody.angularVelocity;
yield return new WaitForSeconds(0.25f);
- Rigidbody.isKinematic = true;
+ rigidbody.isKinematic = true;
Vector3 eulerAngles = Quaternion.LookRotation(hitPokemon.transform.position - transform.position, Vector3.up).eulerAngles;
if (eulerAngles.x > 180)
@@ -100,29 +94,26 @@ IEnumerator Coroutine_WaitAndCapture()
yield return new WaitForSeconds(0.15f);
- hitPokemon.Capture(enterPoint);
+ hitPokemon.Capture(pokemonEnterPoint);
- yield return new WaitUntil(() =>
- {
- return !hitPokemon.IsBeingCaptured;
- });
+ yield return new WaitUntil(() => { return !hitPokemon.CanBeCaptured; });
yield return new WaitForSeconds(0.5f);
- Rigidbody.isKinematic = false;
- Rigidbody.velocity = lastVelocity;
- Rigidbody.angularVelocity = angularVelocity;
+ rigidbody.isKinematic = false;
+ rigidbody.velocity = lastVelocity;
+ rigidbody.angularVelocity = angularVelocity;
- isWaitingBeforeCapture = false;
+ isWaitingBeforePokemonCapture = false;
}
public void ResetPokeball()
{
transform.parent = Camera.main.transform;
- Rigidbody.isKinematic = true;
- transform.localPosition = startPosition;
- transform.localRotation = startRotation;
+ rigidbody.isKinematic = true;
+ transform.localPosition = initialPosition;
+ transform.localRotation = initialRotation;
- ready = true;
+ readyToThrow = true;
}
}
\ No newline at end of file
diff --git a/Assets/Scripts/Pokemon.cs b/Assets/Scripts/Pokemon.cs
index 93a6f65..249b6e4 100644
--- a/Assets/Scripts/Pokemon.cs
+++ b/Assets/Scripts/Pokemon.cs
@@ -3,56 +3,57 @@
public class Pokemon : MonoBehaviour
{
- public float moveToPokeballSpeed = 2;
+ const float MOVE_TO_POKEBALL_SPEED = 3;
- public bool IsBeingCaptured
+ Vector3 initialPosition;
+ Quaternion initialRotation;
+ Vector3 initialScale;
+
+ public bool CanBeCaptured
{
get;
private set;
}
- Vector3 startPosition;
- Quaternion startRotation;
-
void Awake()
{
- startPosition = transform.localPosition;
- startRotation = transform.localRotation;
+ initialPosition = transform.localPosition;
+ initialRotation = transform.localRotation;
+ initialScale = transform.localScale;
}
- public void Capture(Transform target)
+ public void Capture(Transform pokeball)
{
- IsBeingCaptured = true;
-
- GetComponent().enabled = false;
+ GetComponent().enabled = false;
- StartCoroutine(Coroutine_Capture(target));
+ StartCoroutine(Coroutine_Capture(pokeball));
}
- IEnumerator Coroutine_Capture(Transform target)
+ IEnumerator Coroutine_Capture(Transform pokeball)
{
+ CanBeCaptured = false;
+
float delta = 0;
while (delta < 1f)
{
- delta = Mathf.Min(1f, delta + Time.deltaTime * moveToPokeballSpeed);
+ delta = Mathf.Min(1f, delta + Time.deltaTime * MOVE_TO_POKEBALL_SPEED);
+ transform.position = Vector3.Lerp(initialPosition, pokeball.position, delta);
transform.localScale = new Vector3(1f - delta, 1f - delta, 1f - delta);
- transform.position = Vector3.Lerp(startPosition, target.position, delta);
-
yield return null;
}
- IsBeingCaptured = false;
+ CanBeCaptured = true;
}
public void ResetPokemon()
{
- transform.localPosition = startPosition;
- transform.localRotation = startRotation;
- transform.localScale = Vector3.one;
+ transform.localPosition = initialPosition;
+ transform.localRotation = initialRotation;
+ transform.localScale = initialScale;
- GetComponent().enabled = true;
+ GetComponent().enabled = true;
}
}