Topic: Limit how high a character is hit

Is there a way to limit how high a character is hit?

Characters are hit so high that the camera reveals the the camera color beyond the height of my 2D background's artwork.

Share

Thumbs up Thumbs down

Re: Limit how high a character is hit

No you can't limit how high a character goes.
You could limit how high the camera goes, custom code is needed for that tho.

Share

Thumbs up Thumbs down

Re: Limit how high a character is hit

FreedTerror wrote:

No you can't limit how high a character goes.
You could limit how high the camera goes, custom code is needed for that tho.

Yeah, that's what I need. I need to limit how high the camera goes. Where can I go to look up how to do it?

Share

Thumbs up Thumbs down

Re: Limit how high a character is hit

You could just check if the camera's Y position is greater than a certain value.

I didn't test this code

using UnityEngine;

public class Test : MonoBehaviour
{
    private Transform myTransform;

    [SerializeField]
    private float maxYPosition;

    void Awake()
    {
        myTransform = this.transform;
    }

    // Update is called once per frame
    void Update()
    {
        if (transform.position.y > maxYPosition)
        {
            myTransform.position = new Vector3(myTransform.position.x, maxYPosition, myTransform.position.z);
        }
    }
}

Share

Thumbs up +2 Thumbs down

Re: Limit how high a character is hit

@FreedTerror: It works great! I attached it to my camera!  Thank You!

Share

Thumbs up +1 Thumbs down