Hey guys- I have a trigger in my 3D game. When I enter the trigger, I set a bool called canShrink to true. Then when I hold Shift, my character (and character controller capsule) shrinks. The code is like this:
void OnTriggerStay (Collider other)
{
if (other.tag == “ShrinkArea”) {
canShrink = true;
}
}
void OnTriggerExit (Collider other)
{
canShrink = false;
}
void Update ()
{
if (Input.GetKey(KeyCode.LeftShift)){
Shrink();
}
}
// This is called by MyPlayer upon groundswim input
public void Shrink ()
{
//if (canShrink) {
//if (CurrentMovementState == DefaultMovementState) {
//this sets our character controller capsule dimensions to be very small
this.GetComponent<KinematicCharacterMotor> ().SetCapsuleDimensions (.1f, .2f, .1f);
//this turns off our playerSphere mesh renderer
playerMesh.GetComponent<MeshRenderer> ().enabled = false;
//This transitions us to Shrunken State
TransitionToState (ShrinkState);
//}
//} else if (!canShrink) {
//ExitShrink();
//}
}
public void ExitShrink()
{
if (CurrentMovementState == ShrinkState)
{
// this resets our capsule to the size it was at Start()
this.GetComponent<KinematicCharacterMotor>().SetCapsuleDimensions(originalCharacterRadius, originalCharacterHeight, originalCharacterHeight*.5f);
//this transitions us back to default movement state
TransitionToState(DefaultMovementState);
//this re-enables our mesh renderer on player geometry
playerMesh.GetComponent<MeshRenderer>().enabled = true;
}
}
The issue I’m getting is, when I hold shift and my character shrinks, they are then outside of the “CanShrink” trigger zone (because the character controller capsule shrank, so then they can’t shrink, and return to normal size, at which point they “Canshrink” and shrink again, and so on and so forth.
Does anyone know how to check if the CENTER of my character is within a trigger? This way, it will consistently be within the trigger whether I am small, or large