jeudi 18 novembre 2021

Platform Positions Randomly Generated - Not Generating within possible range

Basically, the issue I have is that the platforms generate vertical however they go off to the top right (See Image). Therefore the player can't make the jump to the platforms, without me having to increase their speed and jump values. I'd like to make it possible for the platforms to be generated at a random range, that is possible to jump too.

Platform Generation Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlatformGenerator : MonoBehaviour
{
    public GameObject thePlatform;
    public Transform generationPoint;
    public float distanceBetween;

    private float platformWidth;


    public float distanceBetweenMin;
    public float distanceBetweenMax;

    // Start is called before the first frame update
    void Start()
    {
        platformWidth = thePlatform.GetComponent<BoxCollider2D>().size.x;
    }

    // Update is called once per frame
    void Update()
    {
        if(transform.position.y < generationPoint.position.y)
        {
            distanceBetween = Random.Range(distanceBetweenMin, distanceBetweenMax);

            transform.position = new Vector3(transform.position.y + platformWidth + distanceBetween, transform.position.x, transform.position.z);

            Instantiate(thePlatform, transform.position, transform.rotation);
        }
    }
}

Platform Destroyer Code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlatformDestroyer : MonoBehaviour
{
    public GameObject platformDestructionPoint;

    // Start is called before the first frame update
    void Start()
    {
        platformDestructionPoint = GameObject.Find("PlatformDestructionPoint");
    }

    // Update is called once per frame
    void Update()
    {
        if(transform.position.x < platformDestructionPoint.transform.position.x)
        {
            Destroy(gameObject);
        }
    }
}

Here is an image of what I'm experiencing. Image Detailing The Issue




Aucun commentaire:

Enregistrer un commentaire