Are such small values "normal"?

Hi there! I want to ask a simple question. I’m following this lecture quite slowly and I’ve reached the point of dealing with Yaw. However, I have this issue:

In the beginning, I have a PositionYawFactor of 5, which is used by almost everyone here and it has good results. However, it resulted in the not so good looking rotation at the beginning of the video (plus the ship starts looking at the wrong side). After I change it to -0.2 (after lots of tweaking), it seems to be working “better”, but it’s honestly doesn’t make much of a difference. If I leave it at 0, I’ll get almost the same result. Any ideas? Thanks for your time.

Code (similar to Ben’s)

[Tooltip("In ms^-1")] [SerializeField] float speed = 35f; // it's really m/s: meters ^ s-1 = meters/s
[Tooltip("In ms")] [SerializeField] float xRange = 25f; // how far the ship can go left or right (position is ALWAYS RELATIVE TO THE CAMERA!)
[Tooltip("In ms")] [SerializeField] float yRange = 12f; // how far the ship can go left or right (position is ALWAYS RELATIVE TO THE CAMERA!)

[SerializeField] float positionPitchFactor = -1.3f;
[SerializeField] float controlPitchFactor = -20f;
[SerializeField] float positionYawFactor = -0.2f;
[SerializeField] float controlRollFactor = -20f;

float xThrow, yThrow;

// Update is called once per frame
void Update()
{
    ProcessTranslation();
    ProcessRotation();
}

private void ProcessRotation()
{
    float pitchDueToPosition = transform.localPosition.y * positionPitchFactor;
    float pitchDueToControlThrow = yThrow * controlPitchFactor;
    float pitch = pitchDueToPosition + pitchDueToControlThrow;

    float yaw = transform.localPosition.x * positionYawFactor;

    float roll = xThrow * controlRollFactor;

    transform.localRotation = Quaternion.Euler(pitch, yaw, roll);
}

private void ProcessTranslation()
{
    xThrow = CrossPlatformInputManager.GetAxis("Horizontal"); // how far we're "Throwing" the stick, e.g. 1 is 100% to one side, -1 is -100% to the other side (assuming the stick is centered)
    float xOffset = xThrow * speed * Time.deltaTime; // speed at THIS FRAME

    yThrow = CrossPlatformInputManager.GetAxis("Vertical"); // how far we're "Throwing" the stick, e.g. 1 is 100% to one side, -1 is -100% to the other side (assuming the stick is centered)
    float yOffset = yThrow * speed * Time.deltaTime; // speed at THIS FRAME

    float rawNewXPos = transform.localPosition.x + xOffset;
    float newXPos = Mathf.Clamp(rawNewXPos, -xRange, xRange);

    float rawNewYPos = transform.localPosition.y + yOffset;
    float newYPos = Mathf.Clamp(rawNewYPos, -yRange, yRange);

    transform.localPosition = new Vector3(newXPos, newYPos, transform.localPosition.z);
}

I don’t remember the exact value I used for this lecture, but what I see is that the multiplication is correct, so there’s nothing wrong with the calculations.

In the video we can see that your minimum and maximum X position value is -25 and 25, this means that if you want your ship to rotate slightly you have to multiply by small values like 2 or even 1.

The reason you can’t use 5, probably, has something to do with the distance between your camera and the ship, the farther your ship is from the camera the more X distance it can cover, meaning you’ll have to multiple by smaller amounts.

1 Like

I can see now. I completely lost it after a while and I thought things were breaking apart, rewatched again and everything made sense. I played a little more with the values and settled on the ones I really liked. Thanks for the input!

1 Like

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

Privacy & Terms