I attempted the challenge and came up with what I thought was the answer, but it didn’t work, so I thought Ben would address the problem in the solution, but to my surprise, his implementation seems to be exactly the same as mine, but mine does this:
*no input is being pressed…
(For the life of me can’t figure out why this shows so small.)
On my actual monitor, to the naked-eye, it looks like the ship is constantly in both places at once, it’s just that the dropped frames and framerate of this gif show it sticking a few times.
Here’s my code. What am I not seeing that I did wrong?
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class Player : MonoBehaviour
{
[Tooltip("In ms^-1")] [SerializeField] float xSpeed = 10f;
[Tooltip("+/- value")][SerializeField] float xLimit = 3.9f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float xThrow = CrossPlatformInputManager.GetAxis("Horizontal");
float xOffset = xThrow * xSpeed * Time.deltaTime;
float rawXPos = transform.localPosition.x + xOffset;
float clampedXPos = Mathf.Clamp(rawXPos, -xLimit, xLimit);
transform.localPosition = new Vector3(clampedXPos, transform.localPosition.y, transform.localPosition.z);
}
}