r_unity3d | Unsorted

Telegram-канал r_unity3d - r/Unity3D

103

Unity3D news and project showcases from Reddit. Made possible with @reddit2telegram (@r_channels).

Subscribe to a channel

r/Unity3D

That was the only thing that didn't fit. Replaced the old building explosion with a new animation. Is level transition looks nicer now?

https://redd.it/1duh0uv
@r_Unity3D

Читать полностью…

r/Unity3D

Finally added quick movement of items in the inventory using Ctrl

https://redd.it/1duc8ll
@r_Unity3D

Читать полностью…

r/Unity3D

I'm trying to make a bullet prefab destroy once it collides with the ground, but I can't figure out why this isn't working.
https://redd.it/1duclpp
@r_Unity3D

Читать полностью…

r/Unity3D

How can i use the same slices for different sprites?

Im making customization for my game and its basically the same items but with different colors and so.

I sliced one of them and thougt it would be easy to.just copy the outlines as there is an actual function but as the slices are not exactly the same it looks off and doesnt corrextly fit.

Is it.possible to copy or import the actual slices to other sprites?

https://redd.it/1duaejp
@r_Unity3D

Читать полностью…

r/Unity3D

Animated pilot bodies inside the cockpit

https://redd.it/1du69br
@r_Unity3D

Читать полностью…

r/Unity3D

Bitwise function explained without math

In a Unity tutorial, you might encounter a line of code like this for spawning enemies:

if (((1 << collider.gameObject.layer) & _layerCannotSpawnOn) != 0)
{
// Prevent spawning in this area
}

This line checks if the enemy can spawn on a certain layer. The bitwise operation used here is highly efficient and allows checking multiple layers at once. But what does this mean?

First, remember that layers in Unity are represented as integers, 0 - 31, and you can have 32 bits in an int. Not coincidence.

The bitwise statement, I'm going to try to explain this to everyone and make it simple. I couldn't let it go after watching Sasquatch B Studios video. He inspired me. Thanks! But I'm tired and on my phone, so I hope this makes sense. Follow along.

The importance of this statement is its efficiency. It makes multiple checks at once. A LOT of checks. Don't worry about the exact numbers here - that's not the point. But in this spawning example, the effectiveness of this statement versus the complexity does not align. It's definitely correct but it's sooo overkill in how effective it is versus using an integer array representing LayerMasks, which is why you do it anyway. You'll see why it's effective.

Layers are represented this way because to do this with arrays would be too expensive. Ask ChatGPT about an array example. I'm going to make an analogy to arrays and the example with my design that got to me the "oooh" understanding.

(Ok, a little bit of number talk, but don't get hung up on it)
One integer can contain reference to 32 layers of 00010... This is like an array. Let's say you have four biome layers: town, village, castle, mountain, each representing part of 1111. Again, don't worry about calculating this, but this number can be represented as an integer, representing that set of all four layers active.

0101 represents another set of active layers, or layers to spawn whatever. This too is represented by a unique number that I'm not diving into the math for. It's not important. What's important is it can make any combination of layers to check in one line, super efficiently compared to any other methods, by representing it as bits.

One key represents a specific combination of layers, on or off. You can represent the entire array and all its possibilities in one number.

Think about it.

For this particular purpose it's overkill, but imagine a perlin sphere where you make LOTS of checks against layer masks. Lots and lots of checks. Then this becomes essential.

When this clicks, then you can start to read and understand the logic. The first step in thinking is that you are looking at bits for the digits, not ints for the 1 and 0 in the line.

Again:
( ( (1 << collider.gameObject.layer) & _layerCannotSpawnOn) != 0)

The 1 bit is pushed over << by the collider layer.

If this layer was 2 (binary 10 represents only the second layer active), then the operation 1 << 2 would result in 0100. (4 but it doesn't matter, try to ignore this.)

If this layer was 3 (binary 11 representing both first and second layer active), then the operation 1 << 3 would result in 1000. (6)

This is then combined via & with the second layer, _layerCannotSpawnOn, the unallowed layer here.

The & function compares the two "bit arrays" and spits out a new array that has an active bit only where the two were the same.

If the second layer was 0101 (meaning first and third are unallowed), then the & operation would compare 0100 with 0101 and spit out 0100. Not 0.

If the second layer was 1000 (fourth layer) then the return would've been 0000 or just 0.

This is then compared with != 0.

For a couple layers, the efficiency doesn't really show. But try creating a perlin map without bitwise operations. Specific noise needs to be applied to specific masks efficiently. That Key integer made up of bits is where the important power lies. You can think of it as two boolean flag arrays being compared with & and returning a new flag where the two overlapped. I'm not even mentioning the or |.

Once this clicks

Читать полностью…

r/Unity3D

upgrade.upgradePrefab.name + ": " + dependency.upgradePrefab.name + " is missing");
                return false;
            }
        }
        return true;
    }
}


using UnityEngine;
using System.Collections.Generic;

[System.Serializable]
public class WeightedUpgrades
{
    public GameObject upgradePrefab;
    public float weight;
    public List<WeightedUpgrades> dependencies;
}




https://redd.it/1du2tfu
@r_Unity3D

Читать полностью…

r/Unity3D

Now that’s fast charging!
https://redd.it/1dtwvf7
@r_Unity3D

Читать полностью…

r/Unity3D

Advice on Implementing Movement in a 2D Game Similar to Dofus

Hi everyone,

I’m working on a 2D game in Unity similar to Dofus as a side project. I know that creating a game of this scale by myself is a huge challenge and will take a lot of time, but I’m passionate about it and willing to dedicate the time needed.

I want to implement movement by clicking with the mouse, similar to Dofus. When researching, I found that one method involves using isometric tiles and isometric movement.

Here are my questions:

1. Is there a better method for implementing this type of movement, or should I stick with the isometric approach?
2. If I go with the isometric method, should the tiles themselves be isometric as well?

Any advice or resources you can provide would be greatly appreciated. Thanks in advance for your help!

https://redd.it/1dtsdz5
@r_Unity3D

Читать полностью…

r/Unity3D

Free Environment Sounds: birds, water streams, crafting, animals and more!
https://www.placeholderassets.com/treats

https://redd.it/1dtvjqt
@r_Unity3D

Читать полностью…

r/Unity3D

We made a First Person Horror Game in which you play as a Microwave. Do you guys think it's a good idea?

https://redd.it/1dtrvs3
@r_Unity3D

Читать полностью…

r/Unity3D

It's one of those days guys, hold me :(
https://redd.it/1dqqcuz
@r_Unity3D

Читать полностью…

r/Unity3D

It's like cutting butter with a hot knife

https://redd.it/1dqsz9p
@r_Unity3D

Читать полностью…

r/Unity3D

As a developer, when my disabled daughter told me she loved farm games with horses but found them too hard due to their objectives, I decided to create a game just for her. A game with no mandatory objectives, just to let her live and enjoy the game as she feels.

https://redd.it/1dqqjb7
@r_Unity3D

Читать полностью…

r/Unity3D

I can't use unity and I don't know why

Some time ago, I deleted a user from Windows 11 that had all the data for Unity. However, I copied everything from this user's folder into a new user account. After that, Unity wouldn't start any projects without giving this error: "Internal build system error. Read the full binlog without getting a BuildFinishedMessage, while the backend process is still running."

I searched on Google and found a few potential solutions:

* Delete the Library, Temp, and Logs folders.
* Run Unity as an administrator.
* Reinstall everything related to Unity.

I did all of these things. I even created a second new user and tried the whole process again, but nothing helped.

Additionally, while installing Unity's Editor, I encountered a validation error, so I downloaded the latest version (6000.0.7f1) from the archives.

I don't know how to fix this issue. If anybody has had this issue and successfully resolved it, please help.

Edit:I have few more issues , builtin packages like for 2d (Image components ) aren't visible in inspector and all objects that had them , have now blank script component, that can't be deleted

https://redd.it/1dqj5xv
@r_Unity3D

Читать полностью…

r/Unity3D

Vegangsters, the idea for the game came up one day at university when we thought of bringing together the mechanics of Slay The Spire and Child Of Light, but with criminal vegetables and we are very happy with the result.
https://redd.it/1dufw84
@r_Unity3D

Читать полностью…

r/Unity3D

We made the first trailer for our third-person Diablo-like ARPG. What do you guys think?

https://redd.it/1dubbnu
@r_Unity3D

Читать полностью…

r/Unity3D

My character won't move if I have animations on but if I don't have animations on it will move

So basically I asked the unity forums/discussions for help but there was no response so I have come to reddit to ask for help. I was using a tutorial of BlackThornProd's Youtube video and my character could not move except if I unticked the animations from my player. The first photo are my background settings and the last 2 are my player settings.

https://preview.redd.it/3aylz5eyr9ad1.png?width=672&amp;format=png&amp;auto=webp&amp;s=905e268ba1853f67e10ed2d8f8d74a3a675e44cb

https://preview.redd.it/ncsjd6eyr9ad1.png?width=649&amp;format=png&amp;auto=webp&amp;s=a975b121773ad976fc5bdea50269d9292c0df07a

https://preview.redd.it/fihtm5eyr9ad1.png?width=676&amp;format=png&amp;auto=webp&amp;s=7172ea3897c04a19fa58f6f494cdc1ec85e96577

Here is my code provided even though it is exactly the one from the tutorial:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;



public class PlayerController : MonoBehaviour

{

public float jumpForce;

public float speed;

private Rigidbody2D rb;



public Transform groundPos;

private bool isGrounded;

public float checkRadius;

public LayerMask whatIsGround;



private float jumpTimeCounter;

public float jumpTime;

private bool isJumping;

private bool doubleJump;



private Animator anim;



private void Start()

{

anim = GetComponent<Animator>();

rb = GetComponent<Rigidbody2D>();

}



private void Update()

{

isGrounded = Physics2D.OverlapCircle(groundPos.position, checkRadius, whatIsGround);



if (isGrounded == true && Input.GetKeyDown(KeyCode.Z))

{

anim.SetTrigger("takeOf");

isJumping = true;

jumpTimeCounter = jumpTime;

rb.velocity = Vector2.up * jumpForce;

}



if (isGrounded == true)

{

doubleJump = false;

anim.SetBool("isJumping", false);

}

else

{

anim.SetBool("isJumping", true);

}



if (Input.GetKey(KeyCode.Z) && isJumping == true)

{

if (jumpTimeCounter > 0)

{

rb.velocity = Vector2.up * jumpForce;

jumpTimeCounter -= Time.deltaTime;

}

else

{

isJumping = false;

}

}



if (Input.GetKeyUp(KeyCode.Z))

{

isJumping = false;

}



if (isGrounded == false && doubleJump == false && Input.GetKeyDown(KeyCode.Z))

{

isJumping = true;

doubleJump = true;

isJumping = true;

jumpTimeCounter = jumpTime;

rb.velocity = Vector2.up * jumpForce;

}



float moveInput = Input.GetAxisRaw("Horizontal");

rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);



if (moveInput == 0)

{

anim.SetBool("isRunning", false);

}

else

{

anim.SetBool("isRunning", true);

}



if (moveInput < 0)

{

transform.eulerAngles = new Vector3(0, 180, 0);

}

else if (moveInput > 0)

{

transform.eulerAngles = new Vector3(0, 0, 0);

}



}



}





https://redd.it/1du9wgr
@r_Unity3D

Читать полностью…

r/Unity3D

What do you think of this level design? It’s supposed to be the rebel’s hideout in our game.
https://redd.it/1du9oiz
@r_Unity3D

Читать полностью…

r/Unity3D

it's easy. But it took 90 minutes and an entire day's worth of ChatGPT tokens to understand this.

I know it's very abstract but I wanted to keep it simple without getting into number details everyone keeps getting bogged down on.

While this concept might seem complex at first, once understood, it becomes a powerful tool in your game development arsenal, allowing for efficient checks and operations across multiple layers or flags.

Now that you understand how to read it and what it does, go back and look at that line in your own code or go watch more videos. 😁

https://redd.it/1du5nlh
@r_Unity3D

Читать полностью…

r/Unity3D

IndexOutOfRangeException:Index was outside the bounds of the array ??

Hello, following a course on a 2d platformer and the instructor isnt around to ask questions.

The issue im having is i keep getting the following error and its effecting my scene when im trying to test in scene.

"IndexOutOfRangeException:"Index was outside the bounds of the array"

What is happening, is that all my audio SFX arent working properly (jump, damage, death etc) music is playing, but sound effects are null and for whatever reason its not letting me double jump anymore either, just a single jump.

Last night, this all worked fine in scene, but is no longer working today when im trying to continue to build. I removed everything I tried to add which wasnt much. Just an object and still the same issue. Closed and rebooted apps.

However, say if i start from the main menu screen scene and play, no issues are happening in that scene and the game is functioning normal.

I dont get it.

Thanks for any input in advance.

https://redd.it/1du3hpu
@r_Unity3D

Читать полностью…

r/Unity3D

Having an issue with dependencies in my upgrades manager.

Hey! So I have an upgrade manager that spawns upgrades at the end of a round. 3 random upgrades get spawned with each of them being assigned certain weight, meaning how rare they are. I tried implementing a dependency system where you require to have a certain upgrade before another one is even being considered to spawn. Currently, the upgrade that is assigned the dependency works as intended, it doesn't spawn. The issue is to do with the dependency upgrade not spawning at all. Could anyone let me know what's wrong with it? Thanks!

using System.Collections.Generic;
using UnityEngine;

public class UpgradeManager : MonoBehaviour
{
    public List<WeightedUpgrades> upgradePrefabs;
    public int numberOfUpgradesToSpawn;
    public Vector2 startPosition;
    public float distanceBetweenUpgrades;

    private List<WeightedUpgrades> spawnedUpgrades = new List<WeightedUpgrades>();

    public void SpawnUpgrades()
    {
        spawnedUpgrades.Clear();

        for (int i = 0; i < numberOfUpgradesToSpawn; i++)
        {
            GameObject selectedUpgrade = GetUniqueUpgrade();

            if (selectedUpgrade != null)
            {
                Vector2 spawnPosition = new Vector2(startPosition.x + i * distanceBetweenUpgrades, startPosition.y);

                GameObject spawnedObject = Instantiate(selectedUpgrade, spawnPosition, Quaternion.identity);
                Debug.Log("Spawned: " + spawnedObject.name);

                // Find the corresponding WeightedUpgrade and add it to spawnedUpgrades
                WeightedUpgrades spawnedUpgrade = upgradePrefabs.Find(upg => upg.upgradePrefab == selectedUpgrade);
                spawnedUpgrades.Add(spawnedUpgrade);
            }
        }
    }

    private GameObject GetUniqueUpgrade()
    {
        List<WeightedUpgrades> availableUpgrades = new List<WeightedUpgrades>();

        // Prioritize upgrades with dependencies met
        foreach (WeightedUpgrades upgrade in upgradePrefabs)
        {
            if (!spawnedUpgrades.Contains(upgrade) && AllDependenciesMet(upgrade))
            {
                availableUpgrades.Add(upgrade);
            }
        }

        if (availableUpgrades.Count == 0)
        {
            // If no available upgrades with dependencies met, try to spawn upgrades without dependencies
            foreach (WeightedUpgrades upgrade in upgradePrefabs)
            {
                if (!spawnedUpgrades.Contains(upgrade) && upgrade.dependencies.Count == 0)
                {
                    availableUpgrades.Add(upgrade);
                }
            }
        }

        if (availableUpgrades.Count == 0)
        {
            Debug.Log("No available upgrades due to dependencies.");
            return null;
        }

        float totalInverseWeight = 0f;
        foreach (WeightedUpgrades upgrade in availableUpgrades)
        {
            totalInverseWeight += 1f / upgrade.weight;
        }

        float randomValue = Random.Range(0f, totalInverseWeight);
        float currentWeight = 0f;

        foreach (WeightedUpgrades upgrade in availableUpgrades)
        {
            currentWeight += 1f / upgrade.weight;
            if (randomValue < currentWeight)
            {
                Debug.Log("Selected upgrade " + upgrade.upgradePrefab.name);
                return upgrade.upgradePrefab;
            }
        }

        return null;
    }

    private bool AllDependenciesMet(WeightedUpgrades upgrade)
    {
        foreach (WeightedUpgrades dependency in upgrade.dependencies)
        {
            if (!spawnedUpgrades.Contains(dependency))
            {
                Debug.Log("Dependency not met for " +

Читать полностью…

r/Unity3D

White lines between tiles

Hey iam having a bug when camera is moving (i have smooth camera movement that follows player) white lines apper between tiles and flicker anyway to fix it? thanks

https://redd.it/1dtz0k3
@r_Unity3D

Читать полностью…

r/Unity3D

We're a South African studio making a pixelart non-rhythm roguelite about a drummer that fights a corrupted metal band, called Metavoidal! You use your drumming techniques as your weapons, and music tracks as your powers

https://redd.it/1dtjgyp
@r_Unity3D

Читать полностью…

r/Unity3D

I'm developing a game in Unity about making a living in my home city!
https://redd.it/1dts32j
@r_Unity3D

Читать полностью…

r/Unity3D

Starting to write the story of my indie game.

https://redd.it/1dtpnis
@r_Unity3D

Читать полностью…

r/Unity3D

Hidden Object Game without colliders?

Hi!

I'd really appreciate some help or insight.

I want to create a hidden object game, but it means that if I use polygon colliders I will have to manually adjust them to all my sprites.


I was wondering if there's a way to automate it or even replace it altogether with another solution?

I saw some solutions online about using shaders but I'll be honest - as a beginner I'm still having a problem understanding the concept, and there are not many solutions available in the first place.

Thank you in advance!

https://redd.it/1dquazu
@r_Unity3D

Читать полностью…

r/Unity3D

Projectile Behavior not correct

In my game, most enemies can fire lasers (which behave fine) but only a few can fire torpedoes. All projectiles are spawned in the enemy controller script facing in the same direction as the enemy, but are then controlled by a projectile script that simply sets their velocity to transform.up * speed. With this being the case, torpedoes should behave just like lasers, simply facing in one direction and travelling that way. However, for some reason when the enemy boss (Novum Inceptor -- big red guy) shoots a torpedo, it spirals and points in weird directions and doesn't fly straight. Pausing the game and inspecting the fired torpedo shows a large angular velocity in the rigidbody, which could potentially be a lead. When a different enemy fires a torpedo, however, it behaves fine. Any thoughts? I'll try to attach videos of the torpedoes working and not working. Video Example

https://redd.it/1dqrk8c
@r_Unity3D

Читать полностью…

r/Unity3D

A Little Problem with Rotation and Images

I am making a little game for fun and it has a player alongside a watergun that spins around the players axis. I pulled the code from a link https://forum.unity.com/threads/solved-rotate-around-an-object-based-on-mouse-position.446461/ (Credits to PlazmaInteractive)
but I had a problem with the code (It was post #2 on that page).

I was moving the water gun to the left of my character and it no longer was right-side up, the image was upside down. I was wondering how I can fix this so it always stays with the water guns top right-side up without locking out the water gun's range of motion.

When it is to the left side of the character

&#x200B;

When it is to the right-side of the character.

Any help at all would be greatly appreciated, I want to make my first game. :)

https://redd.it/1dqq0c4
@r_Unity3D

Читать полностью…

r/Unity3D

I Made a Game WITHOUT Coding!
https://youtu.be/jLCZOaD2q4Y

https://redd.it/1dql7c6
@r_Unity3D

Читать полностью…
Subscribe to a channel