Whoops.. Any explaination for this?

So I tried to make the same thing Rick made. But, in a different way.
But when my player ship moves up to the clamped position, it moves the ship forward.
Does anyone have an explaination for this behavior? THX! :smiley:
[Footage of my dumbdumb bug:]

My code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
[SerializeField] float playerspeed = 10f;
[SerializeField] float positionPitchFactor = -2f;

void Update()

void MovePlayer()


void ProcessShipRotation()
    float pitch = transform.localPosition.y * positionPitchFactor;
    float yaw = transform.localPosition.x * positionPitchFactor;
    float roll = 0f;

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

void PlayerInputMove()
    float XThrow = Input.GetAxis("Horizontal") * playerspeed * Time.deltaTime;
    float yThrow = Input.GetAxis("Vertical") * playerspeed * Time.deltaTime;
    transform.Translate(XThrow, yThrow, 0f);

void ClampPlayerShipInScreen()
    Vector3 clampedPos = transform.localPosition;
    clampedPos.x = Mathf.Clamp(clampedPos.x, -5f, 5f);
    clampedPos.y = Mathf.Clamp(clampedPos.y, -2f, 8f);
    transform.localPosition = clampedPos;


Im not sure, but didnt we lock the position in that part of the course? so the ship couldnt move forward and back? been a while since i did argon assault

Hi Matijn,

Welcome to our community! :slight_smile:

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?

Make sure that the timeline does not animate any child game object. Only the PlayerController is allowed to move the player (= the child).

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

Privacy & Terms