- Home /
Local player always on bottom
I am trying to create a 1v1 turn based game where the local player is always on the bottom of the screen(as seen in the screen shots below). I need the world to flip based on which player you all because I limited the rotation of the player but the top player seemed to be backwards.
Red is player 1 and green is player 2
Player 1 view Player 2 view
void Dragging(){
Vector3 mouseWorldPoint = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Vector2 cannonToMouse = mouseWorldPoint - this.transform.position;
rayToMouse.direction = cannonToMouse;
float num = cannonToMouse.sqrMagnitude;
arrow.value = num;
Quaternion q = Quaternion.FromToRotation(this.transform.position, rayToMouse.direction);
Vector3 v3Euler = q.eulerAngles;
if (v3Euler.z > maxRotation && v3Euler.z <= 180f)
v3Euler.z = maxRotation;
else if (v3Euler.z < minRotation && v3Euler.z > 180f)
v3Euler.z = minRotation;
if (mouseWorldPoint.y <= this.transform.position.y) {
this.transform.eulerAngles = v3Euler;
}
}
This is the code that controls the players rotation and the arrows length.
Answer by Hassurunous · May 10, 2018 at 01:12 AM
You could probably get away with simply rotating the camera, depending on how you have the game set up.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraRotate : MonoBehaviour {
bool rotated = false;
public void RotateCamera()
{
Vector3 currentRotation = Camera.main.transform.rotation.eulerAngles;
Vector3 newRotation = Vector3.zero;
if (rotated)
{
newRotation = new Vector3(currentRotation.x, currentRotation.y, 0);
} else
{
newRotation = new Vector3(currentRotation.x, currentRotation.y, 180);
}
Camera.main.transform.Rotate(newRotation);
}
}
If you want it to look smoother, you can always throw a lerp into the rotation as well.
@Hassurunous I do believe I can rotate the camera but that cause the problem with my rotation script for my player. I seem to need a way to reverse this part of my code for player 2.
void Dragging(){
Vector3 mouseWorldPoint = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Vector2 cannonTo$$anonymous$$ouse = mouseWorldPoint - this.transform.position;
rayTo$$anonymous$$ouse.direction = cannonTo$$anonymous$$ouse;
float num = cannonTo$$anonymous$$ouse.sqr$$anonymous$$agnitude;
arrow.value = num;
Quaternion q = Quaternion.FromToRotation(this.transform.position, rayTo$$anonymous$$ouse.direction);
Vector3 v3Euler = q.eulerAngles;
if (v3Euler.z > maxRotation && v3Euler.z <= limiter)
v3Euler.z = maxRotation;
else if (v3Euler.z < $$anonymous$$Rotation && v3Euler.z > limiter)
v3Euler.z = $$anonymous$$Rotation;
if (mouseWorldPoint.y <= this.transform.position.y) {
this.transform.eulerAngles = v3Euler;
}
}