Rotating a gameobject using two input at the same time

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.

I like your drawings… but I am slightly confused.

What is the player controlling with the gamepad? The purple?

Are you computing the blue as halfway between the purples? Or is that his nose direction?

So I guess my question is just a data one:

  • what are your inputs (the hands? the player’s nose? etc.)
  • what outputs do you want (eg, describe how to arrive at them)

Here’s the general format:

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

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.

As far as I can read, lines 53 to 55 use cartesian coordinates to make an angle.

That won’t work. :slight_smile:

Here’s the magic sauce:

Use Mathf.Atan2() to derive heading (angles) from cartesian coordinates:

Sine/Cosine/Atan2 (sin/cos/atan2) and rotational familiarity and conventions

So… either add the two vectors to get the average and use that to make an angle… Or

Compute the two angles and compute the angle between, probably by Mathf.MoveTowardsAngle(), but the vector addition solution might be best.