r/Unity3D – Telegram
r/Unity3D
264 subscribers
12.6K photos
15.6K videos
14 files
48K links
News about the Unity engine and project showcases from Reddit. Made possible with @reddit2telegram (@r_channels).
Download Telegram
An Update on Volumetric Fog using Shader Graph (Video and Download Link in Comments)
https://redd.it/1i5xbz2
@r_Unity3D
Need help with dashing systems and going through walls.

So I'm developing this 2D Roguelike where the player moves using transform.position (and I've tried using transform.Translate()) although it could use any similar function. NPCs use the NavMesh agent, so they're not having this problem.

Whenever I get enough movement speed boost (or I want the player to dash, haven't implemented any dash abilities yet due to this and I'm DYING to do it), the following scenario could happen when using transform.Translate or moving transfrom.position (sorry for the poor drawing):

https://preview.redd.it/354ww8ar17ee1.png?width=871&format=png&auto=webp&s=3da9f6b7b74f81cdfa3343ef6e71dab653578808

It can get through the wall. I want to make a system so that, no matter how long the dash is or how much the movement speed becomes, if there's a wall, no matter how thin it is, it won't let the player go through.

How can I achieve this?


https://redd.it/1i5xico
@r_Unity3D
Ignoring touch inputs through UI

I really know that I'm supposed to read documentation and going online to find answers that can help me before asking here, but I really can't find a solution anywhere.

I'm trying to make a very simple mobile game where the character moves from left to right following the user's finger input. But I also have a pause button always on the screen, and when the player touches it, the character moves in that direction before pausing.

I read many forums, and pretty much all of them suggests using EventSystem.current.IsPointerOverGameObject, but this returns true when touching in... well, everywhere. Is there something that I am missing? It seems like an issue so easy to solve but I can't find anything.


Thanks in advance.

https://redd.it/1i60c3h
@r_Unity3D
How to allow players to set custom sprites?

Im working on a peggle clone right now, and I was thinking about making a level editor where the player can set the background to be whatever they want. Does anyone have a tutorial on how I would go about doing this?

https://redd.it/1i618hp
@r_Unity3D
Question about mouse-based rotation.

Recently, I followed a tutorial that covered rotating a game object so that it would follow the player's current mouse position. The concepts all seem straightforward, but when I tried using the code provided in the tutorial's noscript, the player rotates in the opposite direction of mouse movement, as if it is trying to face away from the mouse.

The fix was easy, simply multiply my rotation value by -1, and the player follows the mouse as expected, but I want to understand why this is happening so I have a better understanding of what exactly I'm doing.

void FollowMouse()
{
// First we get the position of the mouse in WorldSpace
Vector3 mPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
// Then we get the rotation in radians by subtracting the player's position from the mouse position
Vector3 mRotation = mPosition - transform.position;
// Then we convert the radian rotation to degrees
float rDegrees = Mathf.Atan2(mRotation.x, mRotation.y) Mathf.Rad2Deg -1;
// Then rotate the player
transform.rotation = Quaternion.Euler(0,0,rDegrees);
}
Above is the code I used. See the declaration of the float rDegrees to see where I'm multiplying the rotation value by -1. Also, any other suggestions the community may have for improving this code would be appreciated.

Please be kind, I have limited programming experience, and this is my first attempt at doing much of anything in the Unity engine.

https://redd.it/1i660pd
@r_Unity3D
UI Componenets On Modern Phones

on most modern phones the front facing camera is part of the screen, how can i make the ui elements so that they are under the camera, or just make the entire game/app under that section so that nothing is being covered by the camera? any guidance would be appreciated

https://redd.it/1i69bh2
@r_Unity3D
Localization Helper

Hey!

I am using Unity's built-in localization tables to localize my strings and I have been pretty annoyed that Unity does not offer any tools to search for unlocalized strings. Instead you always have to manually create the localization entries and link them or use a custom prefab.

I created an editor extension to find all unlocalized strings within a scene and add the according string table entry all at once with custom settings. So all what's left to be done is hand-in the csv tables for translation.

The Asset is called "Localization Helper":

https://assetstore.unity.com/packages/tools/localization/localization-helper-305262

If you also forget to localize some strings repeatedly like me and need a tool like this, I would be glad to offer you a free version, since I need some testers and reviews. Just write me a PM!

BR

Processing img 3oi0z4amxaee1...

https://redd.it/1i6g870
@r_Unity3D
Help with additional hitbox causing traps to instakill :(

https://preview.redd.it/g863khgg6cee1.png?width=1402&format=png&auto=webp&s=2fde5fd7b5ff81ebb954b4f0de2a7ee6e42d6638

So i have an additional hitbox i added to my characters head. I want this hitbox to not physically collide with any terrain, but I do want it to receive damage, which is why I've made it a trigger.

However, for some reason adding the additional head hitbox this makes all my traps stop working (my character dies even if any of its 2 hitboxes collide with any "trap" tagged object, no matter the conditions.

For example, the trap to the right of the image should only kill the player when its activated and fire comes out of it, and the bear trap should only kill the player when its activated, has a delay of 0.5, and the player is still in its hitbox, however with the addition of the head hitbox to my character both of these traps instakill my player when it goes into the hitbox.

This instakill issue is the same with other traps. idk why but im like 99% sure its to do with my death noscript code.

Ive since removed all the code i did for the head collider (Code V2) to try and make it work and reverted to my old code. Currently all the collider does with my old code (Code V1) is not collide with any terrain (good), keep traps working normally with body (good) but have traps not kill player if touched by head (bad).

How do i fix plzzz been at this a while lol.

CODE V1 (OLD CODE) ----------------------------------------------------------------------------------

using System.Collections;

using UnityEngine;

using UnityEngine.SceneManagement;



public class Death : MonoBehaviour

{

private Rigidbody2D rb;

private Animator anim;

[SerializeField] private AudioSource deathSoundEffect;

private bool isPlayerAlive = true;



private void Start()

{

rb = GetComponent<Rigidbody2D>();

anim = GetComponent<Animator>();

}



private void OnCollisionEnter2D(Collision2D collision)

{

if (isPlayerAlive && collision.gameObject.CompareTag("Trap"))

{

Die();

}

}



public void Die()

{

if (isPlayerAlive)

{

isPlayerAlive = false;

rb.bodyType = RigidbodyType2D.Static;

anim.SetTrigger("death");

deathSoundEffect.Play();

StartCoroutine(RestartLevelAfterDelay(2f));

}

}



private IEnumerator RestartLevelAfterDelay(float delay)

{

yield return new WaitForSeconds(delay);

SceneManager.LoadScene(SceneManager.GetActiveScene().name);

}

}


CODE V2 (NEW CODE IVE SINCE DELETED CUZ TRAPS INSTAKILL BODY OR HEAD) ------------------------

using System.Collections;

using UnityEngine;

using UnityEngine.SceneManagement;



public class Death : MonoBehaviour

{

private Rigidbody2D rb;

private Animator anim;

[SerializeField] private AudioSource deathSoundEffect;

private bool isPlayerAlive = true;



private void Start()

{

rb = GetComponent<Rigidbody2D>();

anim = GetComponent<Animator>();

}



private void OnCollisionEnter2D(Collision2D collision)

{

if (isPlayerAlive && collision.gameObject.CompareTag("Trap"))

{

Die();

}

}



private void OnTriggerEnter2D(Collider2D other)

{

if (isPlayerAlive && other.CompareTag("Trap")) // Ensure traps are tagged as "Trap"

{

Die();

}

}



public void Die()

{

if (isPlayerAlive)

{

isPlayerAlive = false;

rb.bodyType = RigidbodyType2D.Static;

anim.SetTrigger("death");

deathSoundEffect.Play();

StartCoroutine(RestartLevelAfterDelay(2f));

}

}



private IEnumerator RestartLevelAfterDelay(float delay)

{

yield return new WaitForSeconds(delay);

SceneManager.LoadScene(SceneManager.GetActiveScene().name);

}

}



https://redd.it/1i6hdwt
@r_Unity3D
Newbie here: Are these what you use to make characters in a game?
https://redd.it/1i6isp9
@r_Unity3D
I finally got 1,300 wishlists for my puzzle game! It took a long time, and I almost gave up on this game. After updating the graphics and level design of my demo, and keeping up with posts on Reddit, I finally achieved it!
https://redd.it/1i6jgwp
@r_Unity3D
Newbie struggling

I'm new to all of this and was watching a tutorial for beginners. I'm trying to make a flappy bird Esque game, but for the love of God I can't make this stupid bird jump when pressing the spacebar. I tried using chatGPT for help but got even more confused.

This is the code I'm working with rn:

public class birdnoscript : MonoBehaviour
{
    public Rigidbody2D myRigidBody;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space)){
            myRigidBody.linearVelocity = Vector2.up *10;
        }
    }
}

Please help a brother out

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