Ok so, I’ve redone my scene a bit. Took out some trees, made the animation track straigher, and changed the ball (enemy) movement to align better.
When I constraint the camera it’s off… My ship looks a little titled to begin with (probably can be fixed with a small rotation), and my position numbers do not align in the viewport to match with the 7 and 10 X.Y range. I’ve tried to modify it to work, but it still is not matching correctly (see video). Also, I still do not understand why the ship will sometimes jump offscreen when I start the game, and I have to re-click the play button again to actually make it start where it is supposed to (every time I go into play mode this happens).
I’ve tried contraining the ship at 2 and 3 and it still does not match. I’ve moved my camera back to have more room, and it still does not work as well…
Also, I do not know why my ship is not scaled like his. If I make it 111 on xyz it is huge, so it is at a .2,.4,.2 right now (don’t know if that is having an effect on the constraint or not…)…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControls : MonoBehaviour
{
[SerializeField] float controlSpeed = 10f;
[SerializeField] float xRange = 10f;
[SerializeField] float yRange = 7f;
// Update is called once per frame
void Update()
{
ProcessTranslation();
ProcessRotation();
}
void ProcessRotation()
{
float pitch = 0f;
float yaw = 0f;
float roll = 0f;
transform.localRotation = Quaternion.Euler(pitch, yaw, roll);
}
void ProcessTranslation()
{
float xThrow = Input.GetAxis("Horizontal");
float yThrow = Input.GetAxis("Vertical");
float xoffset = xThrow * Time.deltaTime * controlSpeed;
float rawXPos = transform.localPosition.x + xoffset;
float clampedXpos = Mathf.Clamp(rawXPos, -xRange, xRange);
float yoffset = yThrow * 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);
}
}