Been trying to find this and failing miserably.
I have a maze set up so that when my character passes under a block, the block is supposed to fall down and block the path so it can no longer be moved.
I’ve encountered two problems with this.
Firstly, and most importantly, even though I’m affecting the blocks with the raycaster I’m using, I can’t change the “Use Gravity” variable from False to True in the Ridged Body… I think I’m using the wrong bit of code and I haven’t been able to find anything to help me.
Secondly, I need a way to make the blocks STOP moving completely once on the ground. I occasionally have a problem where if they character runs into the block hard enough, they’ll send it flying. This just won’t do, since the whole point is that as they character runs through the maze, the maze will shut off paths behind them. Here’s the code I’ve used for the raycaster so far.
function Update () {
var hit : RaycastHit;
if (Physics.Raycast (transform.position, new Vector3(0,1,0), hit, 200) ){
if (hit.collider.gameObject.tag=="Gate") {
//turn gravity on for object
hit.collider.gameObject.GetComponent("RigidBody").UseGravity = true;
//hit.collider.gameObject.transform.position.y = -1000;
}
if (hit.collider.gameObject.tag=="FirstGate") {
//turn gravity on for object
hit.collider.gameObject.GetComponent("RigidBody").UseGravity = true;
//begin counting score
}
if (hit.collider.gameObject.tag=="LastGate"){
//turn gravity on for object
hit.collider.gameObject.GetComponent("RigidBody").UseGravity = true;
//place current score as previous score in HUD
}
}
}
(notice I have the testing data still in there, commented out, that’s how I know the raycaster is working at all
it makes the blocks disappear when it hits them, moving them to -1000 on the up-down axis)
The stuff that’s been commented out isn’t relevant just yet, I’ll MAYBE need help on those later, but I want to try and figure it out on my own first since that’s kinda the point of this project. Only reason I’m here is that I’ve exhausted other options ^^;