Hi
I am curently trying to prgram a lader script. The way that I have planed it out is that when the player game object enters a trigger zone around the ladder it will add a steady force to the player if W is pressed.
At the moment I know how to detect if the player is in the trigger zone but just dont know how to add a steady vertical force over time to the player.
You need to use Time.deltaTime to smooth out the movement. Try this
bool wPressed = false;
bool insideTrigger = false;
bool autoPilotStandard = true;
//Use your existing collider code to set this value as applicable
void Update()
{
if (insideTrigger)
{
//Needs to be GetKey :)
if (Input.GetKey(KeyCode.W))
{
wPressed = true;
}
else
{
wPressed = false;
}
}
if (autoPilotStandard)
{
//Adds constant change
float translation = Time.deltaTime * 2;
transform.Translate(0, translation, 0);
}
}
void FixedUpdate()
{
if (wPressed)
{
//Will add further force on top of existing, might not be want you want?
GetComponent<Rigidbody>().AddForce(Vector3.up * Time.fixedDeltaTime);
}
}
Assumes you have a Rigidbody attached to the GameObject.
Turn isKinematic and Gravity off.
Edited 1600 re OP comments