Isometric racing game engine proto
Hello! I want to make 3d isometric racing game prototype.
Something like "Biker Mice From Mars" SNES game. Where camera is in fixed isometric position and object have tiles and rotating according to their angle prior camera: https://youtu.be/C_-RLtfSEi4?t=58
I have an object that attached to ThirdPersonController (from Component -> Scripts -> ThirdPersonController) and custom script that has 8 sprites:
north, northEast, east, southEast, south, southWest, west, northWest;
Then I'm trying to show correct sprite prior to camera angel. Here is my update code:
// Update is called once per frame
void Update () {
Vector2 v2Forward = new Vector2 (transform.parent.forward.x, transform.parent.forward.z);
Vector2 v2Camera = new Vector2 (cameraObject.transform.forward.x, cameraObject.transform.forward.z);
float angle = Vector2.Angle(v2Forward, v2Camera);
SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
if (0 < angle && angle < 45){
spriteRenderer.sprite = north;
}
else if (45 < angle && angle < 90){
spriteRenderer.sprite = northEast;
}
else if (90 < angle && angle < 135){
spriteRenderer.sprite = east;
}
else if (135 < angle && angle < 180){
spriteRenderer.sprite = south;
}
else if (180 < angle && angle < 225){
spriteRenderer.sprite = south;
}
else if (225 < angle && angle < 270){
spriteRenderer.sprite = southWest;
}
else if (270 < angle && angle < 315){
spriteRenderer.sprite = west;
}
else if (315 < angle && angle < 360){
spriteRenderer.sprite = northWest;
}
transform.LookAt(Camera.main.transform.position, Vector3.up);
}
But now it only rotates in a half of interval video I think I calculate angle incorrectly but I can't figure out a right way to do it.
Answer by ivan133 · Jan 20, 2016 at 08:05 PM
Answer found here http://answers.unity3d.com/questions/162177/vector2angles-direction.html