Weird Issues with Rotation though the code

So it does rotate but I think its rotating based on the global rather than local even though my code uses local rotation. Thinking it was a bug I switched to the old Input system rather than the new one. Did not fix the issue. https://www.youtube.com/watch?v=fqZd9yFYX24

[SerializeField] InputAction movement;
[SerializeField] float controlSpeed;
[SerializeField] float xRange = 5f;
[SerializeField] float yRange = 5f;
private float XAxis;
private float YAxis;

[SerializeField] float positionPitchFactor = -2f;
[SerializeField] float controlPitchFactor = -10f;
[SerializeField] float positionYawFactor = -2f;
[SerializeField] float controlRollFactor = 5f;
// Start is called before the first frame update
void Start()
{
    
}


private void OnEnable()
{
	movement.Enable();
}

private void OnDisable()
{
	movement.Disable();
}

// Update is called once per frame
void Update()
{
    ProccessTranslation();
    ProccessRotation();

}

void ProccessRotation()
{
	
	float pitchBasedOnPosition = transform.localPosition.y * positionPitchFactor;
	float pitchBasedOnInput = controlPitchFactor + YAxis;
	
	float pitch = pitchBasedOnPosition + pitchBasedOnInput;
	
	float YawBasedOnPosition = transform.localPosition.x * positionYawFactor;
	
	float yaw = transform.localPosition.x + positionYawFactor;
	float roll = YAxis + controlRollFactor;;
	transform.localRotation = Quaternion.Euler(pitch, yaw, roll);
}

void ProccessTranslation()
{
    XAxis = Input.GetAxis("Horizontal");
    YAxis = Input.GetAxis("Vertical");

    float xOffset = XAxis * Time.deltaTime * controlSpeed;
    float rawXPos = transform.localPosition.x + xOffset;
    float clampedXPos = Mathf.Clamp(rawXPos, -xRange, xRange);

    float yOffset = YAxis * Time.deltaTime * controlSpeed;
    float rawYPos = transform.localPosition.y + yOffset;
    float clampedYPos = Mathf.Clamp(rawYPos, -yRange, yRange);

    transform.localPosition = new Vector3
    (clampedXPos, clampedYPos, transform.localPosition.z);
}

}

Hi Mathew,

I’ve watched your video (without sound!) but the rotation looks correct to me. Could you point me to the minute where I can see what you mean?

So My issue I was noticing is that unless I set the values to be very subtle I ended up with their being too much rotation (yaw/roll when in the center of the screen) (also not sure why the sound didn’t work with the video ill look into that for next time) beyond then rotation caused from yaw or roll seemed to have a larger effect on the left side where the right side of the screen or Input would be barely affected

I took a quick look at your code and I see these issues in ProccessRotation() :

That " + " should be " * ".

Same here. Also, “YAxis” should be “XAxis”. You want the ship to roll when you move it horizontally on the screen. Also, double semicolon, but now I’m just being silly…

Are you using this variable anywhere? That’s what your yaw is supposed to be.

I hope this helps and I haven’t simply minunderstood your code.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms