Hi guys,
I am working on my own take on Argon Assault (love the course, by the way!)
I have a strange problem with the control scripts! I can get the X Axis movements to work fine, but EVERY time I try to implement Y axis movement, I get strange behaviours such as the ship not keeping up with the camera…
here is the script…if someone can spot the glaring error, I’d surely appreciate it!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class gyroplayer : MonoBehaviour
{
[Tooltip(“In meters per second”)][SerializeField] float speed = 4f;
[Tooltip(“In meters”)] [SerializeField] float xRange = 10f;
[Tooltip(“In meters”)] [SerializeField] float yRange = 3f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float xThrow = CrossPlatformInputManager.GetAxis("Horizontal");
float yThrow = CrossPlatformInputManager.GetAxis("Vertical");
float xOffset = xThrow * speed * Time.deltaTime;
float yOffset = yThrow * speed * Time.deltaTime;
float rawXPos = transform.localPosition.x + xOffset;
float clampedXPos = Mathf.Clamp(rawXPos, -xRange, xRange);
float rawYPos = transform.localPosition.y + yOffset;
float clampedYPos = Mathf.Clamp(rawYPos, -yRange, yRange);
transform.localPosition = new Vector3(clampedXPos, clampedYPos, transform.localPosition.z);
}
}