Reputation: 79
I have a ledge grab system with hanging. Player then has 2 options: to climb or to let go. However, I don't know a way to reset the transform from the one I've got set to hold to a ledge. The player would be falling so I don't know the exact vector because it would be changing.
I use dropLedge boolean to cancel the ledge holding and let the player fall.
Here is my ledge holding code:
private void LedgeHold()
{
dropLedge = Input.GetKeyDown(KeyCode.S);
if(ledgeDetected == true && canClimbLedge == false)
{
holdGrab = true;
if(isFacingRight)
{
ledgePos1 = new Vector2(Mathf.Floor(ledgePosBot.x + wallCheckDistance) - ledgeClimbXOffset1, Mathf.Floor(ledgePosBot.y) + ledgeClimbYOffset1);
}
transform.position = ledgePos1;
canMove = false;
if(holdGrab == true && dropLedge == true)
{
holdGrab = false;
canFlip = true;
canMove = true;
}
}
}
Upvotes: 0
Views: 115
Reputation: 51
If I'm understanding you correctly, you just want to go back to the position you were before you set it with transform.position = ledgePos1;
. Before doing this, store the value of transform.position
temporarily.
Set the transform.position
back to the temp variable when the player lets go.
Upvotes: 1