Hi,
I am trying to do some two handed shooter where I use both stick in gamepad. To make game more consistent I want to implement a middle invisible collider. What I am tring to do is basically putting a pivot point to head of character that rotating according to other two input. Here what ı have done:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Windows;
public class ColliderHandler : MonoBehaviour
{
Input input;
private Vector2 leftR;
private Vector2 rightR;
private float left;
private float right;
public GameObject pivot;
// Start is called before the first frame update
void Start()
{
input = new Input();
input.Gameplay.Enable();
pivot.transform.position = new Vector3(transform.position.x,transform.position.y + 1.40f,transform.position.z);
}
// Update is called once per frame
void Update()
{
//pivot's place
pivot.transform.position = new Vector3(transform.position.x, transform.position.y + 1.40f, transform.position.z);
//reading other 2 pivot vector value
leftR = input.Gameplay.LeftRotation.ReadValue<Vector2>();
rightR = input.Gameplay.RightRotation.ReadValue<Vector2>();
/*if(leftR.x >= 0)
{
if(rightR.x >= 0)
{
}
else
{
}
}*/
calculateRotate();
}
private void calculateRotate()
{
float x = (leftR.x + rightR.x)/2;
float y = (leftR.y + rightR.y)/2;
float angle = x+y*90;
Debug.Log(angle);
pivot.transform.rotation = Quaternion.Euler(0f,0f,angle);
//pivot.transform.rotation = Quaternion.Euler(0,0,Mathf.Atan2(y,x)*-90);
}
this method rotate my middle pivot in wrong way. If you have any suggestion. Some tutorial or blog about rotating. But if you gimme a hand it is ok too.
Basically. Player rotates purple arms and purple arms value control over blue middle pivot.
I want to rotate middle point to middle of other two arms. So is they are facing other ways there should be no value right and if they both look same direction middle pivot(blue drawing) match with their angle.
When ı tried with code in post. my code takes two input and make them a vector 2 after that when ı use pivot.transform.rotation = Quaternion.Euler(0f,0f,angle);
this function it is use my vector as a angle and rotate towards it. But it is always in opposite direction.
I think my question is which function should ı use to rotate towards a vector 2. If there is any confussion please let me know. I will try to explain more and more in that situation.