Https://www.gamedev.tv/courses/1313665/lectures/32190448

I still didn’t understand , can any one explain me with diagrams

{
 switch (side)
        {
            case 0:
                // Left
                spawnPoint.x = 0;
                spawnPoint.y = Random.value;
                direction = new Vector2(1f, Random.Range(-1f, 1f));
                break;
            case 1:
                // Right
                spawnPoint.x = 1;
                spawnPoint.y = Random.value;
                direction = new Vector2(-1f, Random.Range(-1f, 1f));
                break;
            case 2:
                // Bottom
                spawnPoint.x = Random.value;
                spawnPoint.y = 0;
                direction = new Vector2(Random.Range(-1f, 1f), 1f);
                break;
            case 3:
                // Top
                spawnPoint.x = Random.value;
                spawnPoint.y = 1;
                direction = new Vector2(Random.Range(-1f, 1f), -1f);
                break;
        }

        Vector3 worldSpawnPoint = mainCamera.ViewportToWorldPoint(spawnPoint);
        worldSpawnPoint.z = 0;

        GameObject selectedAsteroid = asteroidPrefabs[Random.Range(0, asteroidPrefabs.Length)];

        GameObject asteroidInstance = Instantiate(
            selectedAsteroid,
            worldSpawnPoint,
            Quaternion.Euler(0f, 0f, Random.Range(0f, 360f)));

Need Help !!
I am conffused as the Tutor is sayingg to take (-1f , 1f ) where if we use ViewPort screen is left with 0,0 to 1,1. then how and why the tutor using Negative 1f ? why this Negative ? please Explain me… m stuck to understand.

Vectors are used both as a position in space (spawnPoint), and as a direction of travel (direction).

In this case, our position needs to be between 0 and 1 in the x and y axis, since 0,0 represents the lower left and 1,1 represents the upper right side.

The direction of travel is a bit different, however. In the x axis, moving in a positive direction means you are moving towards the right hand side of the screen, and moving in a negative direction means that you are moving towards the left hand side of the screen. Similarly, a positive y means you are moving towards the top of the screen, and a negative y direction means you are moving towards the bottom of the screen.

1 Like

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

Privacy & Terms