Hello again. I’m back with yet another problem.
I have a good move script that is working pretty well, using Translate, Raycasts, and a rigidbody for some other things.
It works great! Except for one problem with the Raycasts.
I’m telling it to check left and right every frame to see if there’s a collider right next to the ship and if so, the ship’s speed = 0, else it equals 15 (the normal speed).
So anyway, the problem is this.
See this video I made:
The only part of my script that matters:
var lft = transform.TransformDirection (Vector3.left);
var rgt = transform.TransformDirection (Vector3.right);
if (Physics.Raycast (transform.position, lft, 1.8))
{
speed = 0;
}else
{
speed = 15;
}
if (Physics.Raycast (transform.position, rgt, 1.8))
{
speed = 0;
}else
{
speed = 15;
}
}
If I take off either the LEFT raycast or the RIGHT raycast, the one that is actually in there works fine, as seen in the video. If they’re both in there together (as they are above in my code) then one works and the other doesn’t. It just glitches like in the video.
Anyone got any ideas? Surely I’m doing something wrong, but it’s weird that one of them works perfectly fine and the other doesn’t, when they are the EXACT same code, just reversed…
Thanks!