My ship is completely out of position..Again

So this is my code.

[SerializeField] float PositionPitchFactor = -5f;

    void Start()
    {
        
    }

    
    void Update()
    {
        ProcessTranslate();
        ProcessRotation();
    }

    private void ProcessRotation()
    {
        float pitch = transform.localPosition.y * PositionPitchFactor;
        float yaw = 0f;
        float roll = 0f;
        transform.localRotation = Quaternion.Euler(pitch, yaw, roll);
    }

    private void ProcessTranslate()
    {
        //Movement
        //Horizontal
        float xThrow = CrossPlatformInputManager.GetAxis("Horizontal");
        float xOffset = xSpeed * xThrow * Time.deltaTime;

        float rawXPos = transform.localPosition.x + xOffset;
        float ClampedXPos = Mathf.Clamp(rawXPos, -82.5f, -61.5f);

        //vertical
        float yThrow = CrossPlatformInputManager.GetAxis("Vertical");
        float yOffset = ySpeed * yThrow * Time.deltaTime;

        float rawYPos = transform.localPosition.y + yOffset;
        float ClampedYPos = Mathf.Clamp(rawYPos, -335f, -325.5f);

        transform.localPosition = new Vector3(ClampedXPos, ClampedYPos, transform.localPosition.z);
    }
}

and heres a video

This was on exactly 3 minutes into the lesson that this happened when Ben tried it out that this happened to me. My hands are up on this one because the only logical thing i can think of thats the problem is my hard coded values but i havent found a solution for that yet

Hi Jayy,

If you suspect the hard-coded value to cause the problem, comment out those lines and test your game again. Maybe you could comment out both methods in Update().

This way you can figure out if there is a problem with the circuit or with your script.

k so i did both and it only positions itself way off the circuit when i have the rotation code but i cant tell why

Also my rotations are completely at zero but then when i hit play my x is -135. anoher thing is that when im rotationg my ship with the tool bar it changes its x,y,z position instead of actually rotating it. idk if that matters

Found it it looks like its the pitch factor. When i have it to zero my ship is on the screen and if i put any number is put in for the pitch factor my ship just changes position

Forget everything i just said up until now lol. The root of the problem looks like the object itself. i made an empty object and put my ship in it so it looks like thats maybe why since my code is attached to the playership and not the ship itself.

My playership is a prefab so i need to take my ship out of my playership prefab trying to work out how to do that right now

Alright so it was my prefabs i got it all fixed now lol sry for all the long replies i just had a rubber duck moment if i remember that being what ben said in the beginning of the course. thanks again

Great job on fixing this yourself. :slight_smile:

What do you mean by prefab? In your second screenshot, I can see that the child (ship) has got a huge offset. The values in the Inspector are local variables relative to the respective parent. Was this what you meant?

Nah it was on purpose to show you the difference between the emtpy object i attached my ship to and the actual ship itself and ty.

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

Privacy & Terms