#Help

1 messages · Page 1 of 1 (latest)

unkempt gate
#

Im making a multidimensional platformer and i want the camera to move from a specific place to another when its orthographic and move back when its perspective

#

Even the rotation

glad lantern
#

This is not enough info

#

And I won't just give you code

#

Go program it

#

When you're stuck, ask

unkempt gate
glad lantern
#

I've no idea in which context you used lerping

glad lantern
#

Perhaps drawing it would help

unkempt gate
#
public class CameraScript : MonoBehaviour
{

    Camera cm;
    Vector3 startPos = new Vector3(0, 1, -10.5f);
    Vector3 endPos = new Vector3(-8, 4.5f, -7);
    Vector3 tempPos;
    float duration = 3f;
    float elapsedTime;
    void Start()
    {
        cm = Camera.main;
        cm.orthographic = true;
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            cm.orthographic = !cm.orthographic;
            if (cm.orthographic)
            {
                startPos = new Vector3(0, 1, -10.5f);
                endPos = new Vector3(-8, 4.5f, -7);
            }

            if (!cm.orthographic)
            {
                startPos = new Vector3(-8, 4.5f, -7);
                endPos = new Vector3(0, 1, -10.5f);
            }
        }

        elapsedTime += Time.deltaTime;
        float percentage = elapsedTime/duration;
        transform.position = Vector3.Lerp(startPos, endPos, Mathf.SmoothStep(0, 1, percentage));
    }
}
#

@glad lantern here

#

it also moves when starting the game

#

i dont want it to happen

glad lantern
#
if (cm.orthographic)
            {
                startPos = new Vector3(0, 1, -10.5f);
                endPos = new Vector3(-8, 4.5f, -7);
            }

            if (!cm.orthographic)
            {
                startPos = new Vector3(-8, 4.5f, -7);
                endPos = new Vector3(0, 1, -10.5f);
            }

The latter should be else

if (cm.orthographic)
            {
                startPos = new Vector3(0, 1, -10.5f);
                endPos = new Vector3(-8, 4.5f, -7);
            }

             else
            {
                startPos = new Vector3(-8, 4.5f, -7);
                endPos = new Vector3(0, 1, -10.5f);
            }
#

From what I understand you just want the camera to move up?

unkempt gate
#

and i want it to move only if i click space

glad lantern
#

Use this

unkempt gate
glad lantern
#

Probably idk

#

Look at the docs

unkempt gate
#

i want something that can be used in my own function

#

??

#

@glad lantern ?

#

can u help?

glad lantern
#

This

#

Try that

#

First

unkempt gate
#

Wdym

#

How

#

@glad lantern movetowards with every attributes same?

#

it moves a little

#

and when i click again it moves to the desired location

#

nvm

#

it just teleports

glad lantern
#

MoveTowards makes it teleport?

#

Did you read the docs?