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);
}
}