- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
piedoom · Aug 25, 2013 at 08:34 AM ·
transformphysics settings
Set maximum allowable transform for rigidbody
I'm creating a simple elevator. When the player is inside the elevator, ElevatorTrigger reads as 1.
Then, I would like unity to check that the elevator has not exceeded a certain point relative to its beginning. If both are true, the elevator will continue upwards.
How can I set this so I can find and limit how far the elevator has traveled since its beginning? My current code:
#pragma strict
var elevatorSpeed : float = 1;
function Start () {
}
function FixedUpdate () {
//check if cube is inside of elevator
if (ElevatorTrigger.inside == 1){
//set height of elevator
if
(// what do I check here?)
//speed
{
rigidbody.transform.position.y = rigidbody.transform.position.y + elevatorSpeed/10;
}
}
}
Comment
Best Answer
Answer by wiiarethesound · Aug 27, 2013 at 12:40 AM
You would have to set some variable when the cube first enters the trigger, probably a Vector3 (for position). And then check the distance between the elevator's current position and the saved position. If the distance is great than some value, don't move the elevator.
Your answer
![](https://koobas.hobune.stream/wayback/20220613112925im_/https://answers.unity.com/themes/thub/images/avi.jpg)