Question by
DerpyExplode · Nov 07, 2016 at 04:20 PM ·
rotationairaycastingmovement script
I have a few truck driving forward automatically, but I want that when they come on their side that they stop moveing.
I've tried these 2 scripts, but they don't (fully) work.
1: #pragma strict
function Start () {
}
function Update () {
//print(transform.rotation.eulerAngles.z);
if(transform.rotation.eulerAngles.z >= 80 || transform.rotation.eulerAngles.z <= -80)
{
transform.Translate(Vector3.forward * Time.deltaTime * 0);
}
else
{
transform.Translate(Vector3.forward * Time.deltaTime * 5);
}
}
2:
#pragma strict
var hit : RaycastHit;
var Reach : float = 3.0;
function Start () {
}
function FixedUpdate () {
var fwdleft: Vector3 = transform.TransformDirection(Vector3.left) * 2;
Debug.DrawRay (transform.position, fwdleft, Color.green, 2, false);
if (Physics.Raycast (transform.position, fwdleft, hit, Reach) && hit.transform.tag == "Death")
{
transform.Translate(Vector3.forward * Time.deltaTime * 0);
}
var fwdright: Vector3 = transform.TransformDirection(Vector3.right) * 2;
Debug.DrawRay (transform.position, fwdright, Color.blue, 2, false);
if (Physics.Raycast (transform.position, fwdright, hit, Reach) && hit.transform.tag == "Death")
{
transform.Translate(Vector3.forward * Time.deltaTime * 0);
}
else
{
transform.Translate(Vector3.forward * Time.deltaTime * 5);
}
}
If anyone has an idea on how to do this, please let me know. Thanks in advantage.
Comment
Your answer
Follow this Question
Related Questions
Rotating, moving and keep on going with constant velocity in direction of click 1 Answer
Shoot Raycast through RaycastHit point 0 Answers
AI Raycasting Question (Almost there!!!) 0 Answers
How to make GoalKeeper move within post but not move towards to the player? 1 Answer
Landing doesnt work 0 Answers