Skip to content

Commit

Permalink
Fixed X travel and Input registers
Browse files Browse the repository at this point in the history
  • Loading branch information
ind9-nau committed Dec 8, 2023
1 parent 3884591 commit bd986d2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
43 changes: 22 additions & 21 deletions JustJuggle/Assets/Scripts/HandleCatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@

public class HandleCatch : MonoBehaviour
{
// public variables
[Header("Scoring")]
[Tooltip("Flag for if object has been thrown (used to prevent catching object and getting bonus input at same time)")]
public bool objectNearHand = false;

[Header("Objects")]

[Tooltip("Player hand attached to this script")]
Expand All @@ -47,6 +42,7 @@ public class HandleCatch : MonoBehaviour

public int leftHandX = 1;
public int rightHandX = -1;
private int thisHandX = 0;
public double xDeviation = 0.25;

[Header("Inputs")]
Expand All @@ -56,6 +52,21 @@ public class HandleCatch : MonoBehaviour
[Tooltip("Actual input from player")]
string playerInput = "";

// Start is called before the first frame update
void Start()
{
// get this hand's x position
if( playerHand.transform.position.x > 0 )
{
thisHandX = leftHandX;
}
else
{
thisHandX = rightHandX;
}

}

// Update is called once per frame
void Update()
{
Expand Down Expand Up @@ -93,7 +104,7 @@ void CheckForObjectThrow()
}

// check for trigger collision with juggling object
if( objectNearHand && collidedObjects.Contains(jugglingObject) )
if( collidedObjects.Contains(jugglingObject) )
{
// get input juggling oject is expecting
expectedInput = jugglingObject.GetComponent<JugglingObject>().expectedInput;
Expand Down Expand Up @@ -149,27 +160,18 @@ void FindJugglingObjects()

void OnTriggerEnter(Collider other)
{
// check if object is juggling object
if( other.gameObject.tag == "Proximity" )
// check if object is juggling object going to this hand
if( other.gameObject.tag == "Proximity" &&
other.gameObject.transform.parent.gameObject.GetComponent<JugglingObject>().destinationHand == thisHandX )
{

// lock out bonus input if object is near hand
objectNearHand = true;
collidedObjects.Add(other.gameObject.transform.parent.gameObject);
}
}

void OnTriggerExit(Collider other)
{
// check if object is juggling object
if( other.gameObject.tag == "Proximity" )
{
// allow bonus input if object is no longer near hand
objectNearHand = false;

// remove object from collided objects list
collidedObjects.Remove(other.gameObject.transform.parent.gameObject);
}
// remove object from collided objects list
collidedObjects.Remove(other.gameObject.transform.parent.gameObject);
}

// Update player score
Expand All @@ -182,7 +184,6 @@ void UpdateScore( UnityEngine.Vector3 handPos, UnityEngine.Vector3 objectPos, bo
// if input is wrong subtract score instead of adding
if( wrongInput )
{
Debug.Log("\t\tScore Mult: " + scoreMult);
scoreMult = -scoreMult;
}

Expand Down
12 changes: 5 additions & 7 deletions JustJuggle/Assets/Scripts/JugglingObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,9 @@ void FixedUpdate()
public void MoveObject()
{
// get position of juggling object
float objectHeight = jugglingObject.transform.position.y*dpi;
float objectX = jugglingObject.transform.position.x;
float objectHeight = jugglingObject.transform.position.y*dpi;

if( Math.Abs(objectX) >= Math.Abs(destinationX/dpi) )
{
xStep = 0;
}
if( objectHeight >= maxHeight )
{
yStep = -yStep;
Expand Down Expand Up @@ -213,10 +209,10 @@ void UpdateDestination()

// get x position of hand (hand location +/- deviation)
// this will make the look of the juggling more natural since the hands will not always be in the same place
destinationX = (destinationHand + UnityEngine.Random.Range(-(float)xDeviation, (float)xDeviation)) * dpi; // convert to pixels
destinationX = (destinationHand + UnityEngine.Random.Range(-(float)xDeviation, (float)xDeviation)) * dpi;

// save step size
xStep = destinationX - currentPos / framesUntilIntercept;
xStep = (destinationX - currentPos) / framesUntilIntercept;

// slow down time
xStep /= slowFactor;
Expand All @@ -227,6 +223,8 @@ void UpdateDestination()

// update position
oldPosition = jugglingObject.transform.position;

Debug.Log("Xstep: " + xStep );

// throw
throwing = true;
Expand Down
1 change: 0 additions & 1 deletion JustJuggle/Assets/Scripts/JustJugglingMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ static public void OBJ_HIT( float scoreMult )
// subtractive scoring for failed inputs
else
{
Debug.Log("Score Mult: " + scoreMult);
Script.playerScore += (int)(Script.scoreAdd * scoreMult);
}

Expand Down

0 comments on commit bd986d2

Please sign in to comment.