Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[ad_1]

I am making a constructing sport in Unity and C#

I need to have the ability to scroll the display screen in all 4 instructions when in constructing mode.

In the meanwhile, I can rotate the digital camera and scroll the display screen left and proper, however it doesn’t matter what rotation the digital camera is oriented to, it at all times scrolls in the identical course. I.e. Beginning the sport the digital camera pans, left, proper as meant. But when I rotate the digital camera 90 levels, scrolling left now scrolls up and proper scrolls down.

I need the digital camera to pan left, proper, up and down based mostly on the digital camera’s rotation.
I nonetheless haven’t found out tips on how to pan up or down as this simply strikes the digital camera up and down, so I’ve commented this out for now.

I attempted scrolling relative to the cameras rotation however that did not work. You may see my makes an attempt within the replace operate.

I have been looking out to discover a answer however I’ve had no luck. This video reveals my subject.

utilizing System.Collections.Generic;
utilizing UnityEngine;

public class CamFollowPlayerScript : MonoBehaviour
{
    //----------- This script rotates the cam in isometric veiw

    
    public GameObject participant; // declare participant gameobject
    public Vector3 spinCam; // declare vector 3 for the digital camera
    public float camSpinSpeed; // declare float to carry the pace of the digital camera rotation
    public bool isCameraFollwingMouse;
    public Cursor mouseCurson;
    public float mSpeed; // Scale. Pace of the motion
    public Digital camera isoCam;

    public GameObject eastDirectrion;

    public Vector3 mRightDirection;// = 3.proper; // Path the digital camera ought to transfer when on the appropriate edge
    public Vector3 mleftDirection;// = Vector3.left; // Path the digital camera ought to transfer when on the appropriate edge
    public Vector3 mUpDirection;// = Vector3.up; // Path the digital camera ought to transfer when on the appropriate edge
    public Vector3 mDownDirection;// = Vector3.down; // Path the digital camera ought to transfer when on the appropriate edge

    non-public void Begin()
    {
        mSpeed = 5;
        camSpinSpeed = 20f;
    }

    non-public void Replace()
    {
       
        spinCam = new Vector3(Enter.GetAxis("VerticalIso"), Enter.GetAxis("HorizontalIso"), 0.0f); // spinCam is a brand new vector 3, taking the axis from the unity enter settings on the X and Y axis and 0 on the Z axis
        this.remodel.Rotate(spinCam * camSpinSpeed * Time.deltaTime); // rotate the digital camera utilizing the vector 3 from the spin cam, by the spinCamSpeed float by time.delta time. 

         mUpDirection = new Vector3(0,0,0); // Path the digital camera ought to transfer when on the appropriate edge
         mDownDirection = new Vector3(0,0,0); // Path the digital camera ought to transfer when on the appropriate edge
         mRightDirection = new Vector3(isoCam.remodel.rotation.x, 0, isoCam.remodel.rotation.z);
         mleftDirection = new Vector3(-isoCam.remodel.rotation.x, 0, -isoCam.remodel.rotation.z);

        if (Enter.GetKeyDown(KeyCode.M))
        {
            isCameraFollwingMouse = !isCameraFollwingMouse;
        }
    }

    void LateUpdate() // referred to as in spite of everything replace() strategies have been referred to as
    {
        if (!isCameraFollwingMouse)
        {
            remodel.place = participant.remodel.place;// 
        }

        if (isCameraFollwingMouse)
        {
            // Verify if on the appropriate edge
            if (Enter.mousePosition.x >= Display.width )
            {
                // Transfer the digital camera
                remodel.place += Vector3.proper * Time.deltaTime * mSpeed;
            }

            if (Enter.mousePosition.x <= 0)
            {
             // mm  // Transfer the digital camera
               remodel.place += Vector3.left * Time.deltaTime * mSpeed;
            }

            if (Enter.mousePosition.y >= Display.peak)
            {
                // Transfer the digital camera
               // remodel.place += mUpDirection * Time.deltaTime * mSpeed;
            }

            if (Enter.mousePosition.y <= 0)
            {
                // mm  // Transfer the digital camera
               // remodel.place += mDownDirection * Time.deltaTime * mSpeed;
            }
        }
    }
}

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *