Forum begins after the advertisement:


[Part 10] 2 Errors I’m confused about

  • 31 August 2023: We recently fixed a bug where our Patrons were not getting their titles displayed properly on their posts.

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 10] 2 Errors I’m confused about

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #11906
    Luke
    Participant

    (1) So, for the first issue, whenever I collect XP gems, only the first collect of the type is collected. This is really confusing because before part 11, it worked perfectly.

    (2) This error happens during the upgrade screen, but it appears that the onclick event is deleted before it can be used and I don’t know why. The code is the exact same(I think) and I can’t find console errors.

    Help would be appreciated!

    (if the answer is in part 11 I will eat my hat.)

    #11907
    Terence
    Keymaster

    Hi Luke, I’m taking over the project from Xavier, so bear with me if I’m not very well-informed about some parts of the codebase.

    For (1), is the collision detection done using OnTriggerEnter2D()? If it is, you can do put something like Debug.Log(name + " pick up triggered") on the function to see if the function fires for the pickups that are not working. The line prints the name of the object as well, so you can tell which object is being triggered. If certain pickups are not triggering, pause the game during play and check if they have a) a collider and b) a Rigidbody2D. Those 2 are needed for collisions to register.

    For (2), will you be able to clip a video of this happening with something like ScreenToGif and post it on Imgur? Then you can embed it here.

    #11908
    Terence
    Keymaster

    Here is ScreenToGif’s download link: https://www.screentogif.com/downloads

    #11910
    Luke
    Participant

    I’ve tested out the Debug.Log solution and I think the reason is because it is destroyed before it hits the player. Still not solved.(I could be wrong on this.)

    (btw u can use print() instead of debug.log)

    #11911
    Terence
    Keymaster

    Is there any script that is calling Destroy() on your GameObject? That is the only thing I can think of that is destroying your object before it hits the player.

    #11912
    Luke
    Participant

    The error might be in onTriggerEnter2D for this code:

    void OnTriggerEnter2D(Collider2D col)
        {
            if (col.gameObject.TryGetComponent(out ICollectible collectible))
            {
                Rigidbody2D rb = col.gameObject.GetComponent<Rigidbody2D>();
                //rb.velocity = Vector2.zero;
                //rb.angularVelocity = 0;
                collectible.MoveToPlayer();
                collectible.Collect();
            }
        }

    Also I’ve recorded the other error, but I don’t know how to embed.

    #11913
    Luke
    Participant

    The error might be in onTriggerEnter2D for this code:

    void OnTriggerEnter2D(Collider2D col)
        {
            if (col.gameObject.TryGetComponent(out ICollectible collectible))
            {
                Rigidbody2D rb = col.gameObject.GetComponent<Rigidbody2D>();
                //rb.velocity = Vector2.zero;
                //rb.angularVelocity = 0;
                collectible.MoveToPlayer();
                collectible.Collect();
            }
        }

    Also I’ve recorded the other error here.
    The Error

    #11914
    Luke
    Participant

    I solved the issue where you could dodge pickups using the movetoplayer function above, complicated.
    if that causes an error welp that’s it.

    #11915
    Luke
    Participant

    I solved the issue where you could dodge pickups using the movetoplayer function above, complicated.
    if that causes an error welp that’s it.

    #11916
    Luke
    Participant

    Nvm, the second error was because I decided to put removeUpgradeoptions after applyupgradeoptions. Fixed!

    #11920
    Terence
    Keymaster

    Hi Luke, glad you managed to fix the issues!

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below:

Save Soil

The Save Soil Movement

Poor farming practices and policies across the world have led to the degradation of agricultural soils in the world. This has led to the loss of nutritional value in our food over the years, and it will affect our food production capabilities in the coming decades.

Learn more about Save Soil →