- Home /
thing not doing the right thing
i made a script for my game randomly in detention today and everything works fine except that the guy doesn't turn when there is a wall in front of him. also i forgot the code to make the ray visible so if someone can tell me that would be good
var movespeed = 2;
var turn = 30;
var turnDist = 5;
var ragdoll : GameObject;
var endlevelondeath = 0;
var nextscene = 0;
function Update() {
transform.Translate(Vector3.forward * Time.deltaTime * movespeed);
if(Physics.Raycast(transform.position, Vector3.forward, turnDist)) {
transform.Rotate(Vector3.right * Time.deltaTime * turn);
}
}
function ApplyDamage() {
Destroy (gameObject);
Instantiate(ragdoll, transform.position, transform.rotation);
if (endlevelondeath == 1){
Application.LoadLevel(nextscene);
}
}
$$anonymous$$aybe you meant Physics.Raycast(transform.position, transform.forward, turnDist)
statement is probablty right, Vector.forward always is (0,0,1) so rotating your transform won't change your direction when using this. transform.forward however depends on the orientation of your object ;)
Your answer
Follow this Question
Related Questions
how to make it so i can see a raycast 2 Answers
Accessing Variables from Another Script 1 Answer
General Way To 'Widen' A Ray Cast? 1 Answer
Make an Enemy Shoot through Raycast 1 Answer
change object material on mouse click. 2 Answers