Pitch Factor

I dont know why my PositionPitchFactor and PositionYawFactor is not working… I dont see change when i run my code in Unity. I am following Ben’s code.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;

public class Ship : MonoBehaviour
{
[Tooltip(“In ms^-1”)][SerializeField] float xSpeed = 4f;
[Tooltip(“In ms^-1”)] [SerializeField] float ySpeed = 4f;

[Tooltip("In m")] [SerializeField] float xRange = 5f;
[Tooltip("In m")] [SerializeField] float yRange = 2f;
[SerializeField] float PositionPitchFactor = -5f;
[SerializeField] float ControlPitchFactor = -20f;
[SerializeField] float PositionYawFactor = -5f;
[SerializeField] float ControlRollFactor = -5f;




float xthrow;
float ythrow;



// Start is called before the first frame update
void Start()
{
    
}

// Update is called once per frame
void Update()
{
    controlsTransaltion();
    controlsRotation();
}

private void controlsRotation()
{
float pitch = transform.localPosition.y * PositionPitchFactor + ythrow * ControlPitchFactor;
float yaw = transform.localPosition.x * PositionYawFactor ;
float roll = xthrow * ControlRollFactor;

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

private void controlsTransaltion()
{
     xthrow = CrossPlatformInputManager.GetAxis("Horizontal");
     ythrow = CrossPlatformInputManager.GetAxis("Vertical");

    float xOffset = xSpeed * xthrow * Time.deltaTime;
    float yOffset = ySpeed * ythrow * Time.deltaTime;

    float xRawPs = transform.localPosition.x + xOffset;
    float yRawPs = transform.localPosition.y + yOffset;

    float xclamped = Mathf.Clamp(xRawPs, -xRange, +xRange);
    float yclamped = Mathf.Clamp(yRawPs, -yRange, +yRange);


    transform.localPosition = new Vector3(xclamped, yclamped, transform.localPosition.z);
}

}

Only ControlPitchFactor and ControlRollFactor is working. please help

Hi!

Try comparing your code to the lecture changes, here’s the link

If that doesn’t help try to be more specific, What do you mean by “PositionPitchFactor and PositionYawFactor is not working”? Is it not been read properly? Is it not being applied? Is it applied in unnexpected ways?

If you don’t know the answer of any of those question then try using “print” or “Debug.Log” to see what is going on within your code, try things like:

print(PositionYawFactor);

If your console tells you is 0 then there’s an issue with your variable not being set in the inspector. If it returns the correct value then it’s not being applied or applied in unexpected ways, if that’s the case just try tuning your values and see if that fixes the problem, if not, then there’s some problem with your math.

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

Privacy & Terms