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
Animating Walk Cycle RESIZING???? For no reason????

Hello, I am VERY new to Unity and also new to coding. I am trying to get my player to walk around with walking animations. For some reason when I go to make the animations even though the sprite sheet components for the animation are the same size as my idle character sprite and the size that I want them, whenever I put them into the animation thing they get bigger??? By a sizable amount and then it makes the idle base one the same size and I can't figure out how to change it and I just have to keep redoing it! Please help I bed /(T-T)/

https://redd.it/1i7eego
@r_Unity3D
This media is not supported in your browser
VIEW IN TELEGRAM
I made a fully procedural 3D flamethrower (shader) with realtime lights in Unity (URP).

https://redd.it/1i7c60q
@r_Unity3D
Please help cant change X velocity

I am making my first game (2D platformer) this is the code I am using for movement I am currently working on wallJumping but when I am on the wall the X velocity just wont change the Y has no problem so it is clearly executing the line but the X velocity is just not changing.
BTW there are 2 codes

using UnityEngine;

// This class handles general movement physics for 2D objects
public class MovementPhysics : MonoBehaviour
{
Header("Movement Settings")
public float speed = 5f;
public float airSpeed = 2f;

Header("Jump Settings")
public float jumpForce = 7f;
public int doublejumps = 2;
public Vector2 wallJumpStrenght;

Header("Ground Check Settings")
public Vector2 groundCheckSize;
public Vector2 groundCheckOffset;
public LayerMask groundLayer;
public bool isGrounded;

Header("wall Check Settings")
public bool canWallslide;
public Vector2 wallCheckSize;
public Vector2 wallCheckOffset;
public LayerMask wallLayer;
public bool isWalledL;
public bool isWalledR;

// Private properties
protected Rigidbody2D rb; // Reference to Rigidbody2D component
protected int jumpsLeft;
protected bool isGravityDisabled = false;

public float inputX;

protected virtual void Start()
{
// Initialize Rigidbody2D and jumps
rb = GetComponent<Rigidbody2D>();
jumpsLeft = doublejumps;
}

protected virtual void Update()
{
// Get horizontal input for movement
inputX = Input.GetAxis("Horizontal");

// Check ground contact using OverlapBox
Vector2 checkPos = (Vector2)transform.position + groundCheckOffset;
isGrounded = Physics2D.OverlapBox(checkPos, groundCheckSize, 0f, groundLayer);

// Check wall right contact using OverlapBox
Vector2 checkPos1 = (Vector2)transform.position + wallCheckOffset;
isWalledR = Physics2D.OverlapBox(checkPos1, wallCheckSize, 0f, wallLayer);

// Check wall left contact using OverlapBox
Vector2 flippedwallCheckOffset = new Vector2(-wallCheckOffset.x, wallCheckOffset.y);
Vector2 checkPos2 = (Vector2)transform.position + flippedwallCheckOffset;
isWalledL = Physics2D.OverlapBox(checkPos2, wallCheckSize, 0f, wallLayer);

// Reset jumps when on the ground
if (isGrounded) jumpsLeft = doublejumps;

// Call depended functions
FlipCharacter(inputX);

// Handels Wall Slide
if ((isWalledL || isWalledR) && canWallslide)
{
if (!isGravityDisabled) // Only set gravityScale to 0 if it's not already 0
{
rb.gravityScale = 0;
isGravityDisabled = true;
rb.linearVelocityY = 0;
}
}
else
{
if (isGravityDisabled) // Only set gravityScale to 1 if it's not already 1
{
rb.gravityScale = 1;
isGravityDisabled = false;
}
}
}

protected virtual void FixedUpdate()
{
// Apply movement physics
Move(inputX);
}

// Handles horizontal movement
protected void Move(float input)
{
if (isGrounded)
{
// Ground movement: set the velocity based on input and speed
rb.linearVelocityX =input speed;
}
else
{
// Air movement: apply force to simulate air control, with some damping on x-axis velocity
float airControl = input
airSpeed - (rb.linearVelocity.x / 2);
rb.AddForce(new Vector2(airControl, 0));
}
}

// Handles jumping logic
protected void Jump()
{
if (isWalledR || isWalledL)
{
if (isWalledL) rb.linearVelocity = new Vector2(wallJumpStrenght.x, wallJumpStrenght.y);
else rb.linearVelocity = new Vector2(-wallJumpStrenght.x, wallJumpStrenght.y);
}
else
{
if (jumpsLeft > 0)
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce); // Apply jump force on the y-axis
jumpsLeft--; // Decrease remaining jumps
}
}
}

// Flips the character's sprite based on movement direction
protected void FlipCharacter(float input)
{
if (isWalledR) transform.localScale = new Vector3(1, 1, 1); // Flip right
else if (isWalledL) transform.localScale = new Vector3(-1, 1, 1); // Flip left
else if (input > 0 || isWalledL) transform.localScale = new Vector3(1, 1, 1); // Flip right
else if (input < 0 || isWalledL) transform.localScale = new Vector3(-1, 1, 1); // Flip left
}

// draw shit boxes
protected virtual void OnDrawGizmosSelected()
{
// Only draw gizmos if this is not the exact class (derived)
if (GetType() == typeof(MovementPhysics))
return;

// Draw Ground Check Box
Gizmos.color = Color.green; // Set color for ground check
Vector2 groundCheckPos = (Vector2)transform.position + groundCheckOffset;
Gizmos.DrawWireCube(groundCheckPos, groundCheckSize);

// Draw Wall Check Box (Right)
Gizmos.color = Color.red; // Set color for wall check (right)
Vector2 wallCheckPosRight = (Vector2)transform.position + wallCheckOffset;
Gizmos.DrawWireCube(wallCheckPosRight, wallCheckSize);

// Draw Wall Check Box (Left)
Gizmos.color = Color.blue; // Set color for wall check (left)
Vector2 wallCheckPosLeft = (Vector2)transform.position + new Vector2(-wallCheckOffset.x, wallCheckOffset.y);
Gizmos.DrawWireCube(wallCheckPosLeft, wallCheckSize);
}
}

using UnityEngine;
using System.Collections; // Add this for IEnumerator and Coroutines

// This class handles player-specific input and extends MovementPhysics
public class PlayerController : MovementPhysics
{
Header("Input Settings")
public string horizontalAxis = "Horizontal"; // Input axis for horizontal movement
public string jumpButton = "Jump"; // Input button for jumping

Header("snap Settings")
public float snapDuration; // Duration for snapping
public float snapThreshold; // Threshold for triggering the snap
private Coroutine snapCoroutine; // Reference to the snapping coroutine
private bool isSnapping = false; // Flag to check if snapping is currently active

protected override void Update()
{
//debug
Debug.Log($"Horizontal Velocity: {rb.linearVelocity.x}, Vertical Velocity: {rb.linearVelocity.y}");

// Capture player input for movement
inputX = Input.GetAxis(horizontalAxis);

// Trigger jump when jump button is pressed
if (Input.GetButtonDown(jumpButton))
{
if (isSnapping)
{
StopCoroutine(snapCoroutine);
isSnapping = false;
}
Jump();
}

// Call base class to handle physics logic
base.Update();

// Start snapping when jump button is released and player is still moving upwards
if (rb.linearVelocity.y > snapThreshold && !Input.GetButton("Jump") && !isSnapping)
{
// Start
Please help cant change X velocity

I am making my first game (2D platformer) this is the code I am using for movement I am currently working on wallJumping but when I am on the wall the X velocity just wont change the Y has no problem so it is clearly executing the line but the X velocity is just not changing.
BTW there are 2 codes

using UnityEngine;

// This class handles general movement physics for 2D objects
public class MovementPhysics : MonoBehaviour
{
[Header("Movement Settings")]
public float speed = 5f;
public float airSpeed = 2f;

[Header("Jump Settings")]
public float jumpForce = 7f;
public int doublejumps = 2;
public Vector2 wallJumpStrenght;

[Header("Ground Check Settings")]
public Vector2 groundCheckSize;
public Vector2 groundCheckOffset;
public LayerMask groundLayer;
public bool isGrounded;

[Header("wall Check Settings")]
public bool canWallslide;
public Vector2 wallCheckSize;
public Vector2 wallCheckOffset;
public LayerMask wallLayer;
public bool isWalledL;
public bool isWalledR;

// Private properties
protected Rigidbody2D rb; // Reference to Rigidbody2D component
protected int jumpsLeft;
protected bool isGravityDisabled = false;

public float inputX;

protected virtual void Start()
{
// Initialize Rigidbody2D and jumps
rb = GetComponent<Rigidbody2D>();
jumpsLeft = doublejumps;
}

protected virtual void Update()
{
// Get horizontal input for movement
inputX = Input.GetAxis("Horizontal");

// Check ground contact using OverlapBox
Vector2 checkPos = (Vector2)transform.position + groundCheckOffset;
isGrounded = Physics2D.OverlapBox(checkPos, groundCheckSize, 0f, groundLayer);

// Check wall right contact using OverlapBox
Vector2 checkPos1 = (Vector2)transform.position + wallCheckOffset;
isWalledR = Physics2D.OverlapBox(checkPos1, wallCheckSize, 0f, wallLayer);

// Check wall left contact using OverlapBox
Vector2 flippedwallCheckOffset = new Vector2(-wallCheckOffset.x, wallCheckOffset.y);
Vector2 checkPos2 = (Vector2)transform.position + flippedwallCheckOffset;
isWalledL = Physics2D.OverlapBox(checkPos2, wallCheckSize, 0f, wallLayer);

// Reset jumps when on the ground
if (isGrounded) jumpsLeft = doublejumps;

// Call depended functions
FlipCharacter(inputX);

// Handels Wall Slide
if ((isWalledL || isWalledR) && canWallslide)
{
if (!isGravityDisabled) // Only set gravityScale to 0 if it's not already 0
{
rb.gravityScale = 0;
isGravityDisabled = true;
rb.linearVelocityY = 0;
}
}
else
{
if (isGravityDisabled) // Only set gravityScale to 1 if it's not already 1
{
rb.gravityScale = 1;
isGravityDisabled = false;
}
}
}

protected virtual void FixedUpdate()
{
// Apply movement physics
Move(inputX);
}

// Handles horizontal movement
protected void Move(float input)
{
if (isGrounded)
{
// Ground movement: set the velocity based on input and speed
rb.linearVelocityX =input * speed;
}
else
{
// Air movement: apply force to simulate air control, with some damping on x-axis velocity
float airControl = input * airSpeed - (rb.linearVelocity.x / 2);
rb.AddForce(new Vector2(airControl, 0));
}
}

// Handles jumping logic
protected void Jump()
{
if (isWalledR || isWalledL)
{
if (isWalledL) rb.linearVelocity = new Vector2(wallJumpStrenght.x, wallJumpStrenght.y);
else rb.linearVelocity = new Vector2(-wallJumpStrenght.x, wallJumpStrenght.y);
}
else
{
if (jumpsLeft > 0)
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce); // Apply jump force on the y-axis
jumpsLeft--; // Decrease remaining jumps
}
}
}

// Flips the character's sprite based on movement direction
protected void FlipCharacter(float input)
{
if (isWalledR) transform.localScale = new Vector3(1, 1, 1); // Flip right
else if (isWalledL) transform.localScale = new Vector3(-1, 1, 1); // Flip left
else if (input > 0 || isWalledL) transform.localScale = new Vector3(1, 1, 1); // Flip right
else if (input < 0 || isWalledL) transform.localScale = new Vector3(-1, 1, 1); // Flip left
}

// draw shit boxes
protected virtual void OnDrawGizmosSelected()
{
// Only draw gizmos if this is not the exact class (derived)
if (GetType() == typeof(MovementPhysics))
return;

// Draw Ground Check Box
Gizmos.color = Color.green; // Set color for ground check
Vector2 groundCheckPos = (Vector2)transform.position + groundCheckOffset;
Gizmos.DrawWireCube(groundCheckPos, groundCheckSize);

// Draw Wall Check Box (Right)
Gizmos.color = Color.red; // Set color for wall check (right)
Vector2 wallCheckPosRight = (Vector2)transform.position + wallCheckOffset;
Gizmos.DrawWireCube(wallCheckPosRight, wallCheckSize);

// Draw Wall Check Box (Left)
Gizmos.color = Color.blue; // Set color for wall check (left)
Vector2 wallCheckPosLeft = (Vector2)transform.position + new Vector2(-wallCheckOffset.x, wallCheckOffset.y);
Gizmos.DrawWireCube(wallCheckPosLeft, wallCheckSize);
}
}

using UnityEngine;
using System.Collections; // Add this for IEnumerator and Coroutines

// This class handles player-specific input and extends MovementPhysics
public class PlayerController : MovementPhysics
{
[Header("Input Settings")]
public string horizontalAxis = "Horizontal"; // Input axis for horizontal movement
public string jumpButton = "Jump"; // Input button for jumping

[Header("snap Settings")]
public float snapDuration; // Duration for snapping
public float snapThreshold; // Threshold for triggering the snap
private Coroutine snapCoroutine; // Reference to the snapping coroutine
private bool isSnapping = false; // Flag to check if snapping is currently active

protected override void Update()
{
//debug
Debug.Log($"Horizontal Velocity: {rb.linearVelocity.x}, Vertical Velocity: {rb.linearVelocity.y}");

// Capture player input for movement
inputX = Input.GetAxis(horizontalAxis);

// Trigger jump when jump button is pressed
if (Input.GetButtonDown(jumpButton))
{
if (isSnapping)
{
StopCoroutine(snapCoroutine);
isSnapping = false;
}
Jump();
}

// Call base class to handle physics logic
base.Update();

// Start snapping when jump button is released and player is still moving upwards
if (rb.linearVelocity.y > snapThreshold && !Input.GetButton("Jump") && !isSnapping)
{
// Start
the snapping coroutine
snapCoroutine = StartCoroutine(SmoothSnap());
}
}

// Coroutine to smooth out the upward velocity when the jump button is released
private IEnumerator SmoothSnap()
{
isSnapping = true;

// Store the initial vertical velocity
float initialVelocityY = rb.linearVelocity.y;
float elapsedTime = 0f;

// Gradually reduce the vertical velocity
while (elapsedTime < snapDuration && rb.linearVelocity.y > 0)
{
elapsedTime += Time.deltaTime;
float dampFactor = Mathf.Lerp(1, 0, elapsedTime / snapDuration); // Damp the upward velocity
rb.linearVelocity = new Vector2(rb.linearVelocity.x, initialVelocityY * dampFactor);
yield return null;
}

// Ensure the velocity doesn't stay positive once snapping is done
if (rb.linearVelocity.y > 0.1f)
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, 0);
}

isSnapping = false;
}
}



https://redd.it/1i7g70k
@r_Unity3D
This media is not supported in your browser
VIEW IN TELEGRAM
Such simple mechanic like object breaking can add so much to the game.

https://redd.it/1i7gk4x
@r_Unity3D
This media is not supported in your browser
VIEW IN TELEGRAM
Basic mechanics for a cute soft-body physics game – what do you think? 🙂

https://redd.it/1i7kejc
@r_Unity3D
This media is not supported in your browser
VIEW IN TELEGRAM
Have you ever spent way too much time on a little thing for your game only to then scrap it and forget about it? Just found and finished this chemical flask shader for our escape room game. Last time I worked on it was probably a year ago...

https://redd.it/1i7m7r2
@r_Unity3D
Media is too big
VIEW IN TELEGRAM
I needed to add splitters and mergers to my farm product automation game. And I thought, why just 3 in and out?! What do you guys think? I hope it will work well logistically (needs some tests)

https://redd.it/1i7ki53
@r_Unity3D
Story looping back issue with Ink

Hi, I'm running into a bug when using Ink in my project, where at the first chance the player can select from choices, the dialogue panel closes. The console is printing Debug messages I wrote showing that for some reason, after the player makes their choice, the story is looping back to the main knot rather than proceeding.

I don't think it's an issue with my Ink noscript because it runs fine in Inky.

I think it's something in my dialogue manager? I built it from a tutorial and I've done my best to understand it, but since I'm a beginner it's definitely a challenge. Thank you for any help anyone can provide. I'll attach my DialogueManager noscript as well as my Ink noscript.

[Here is the console log.](https://imgur.com/a/0B5P0vU)

FYI: In this dialogue manager noscript I removed any mentions of the tags, just to try to debug. So this noscript isn't doing anything with the choices at this point. I'm just trying to proceed through the whole Ink story.

-> main

=== main ===
Welcome to the platform.
Now that you're here, would you like an extra ability?
* [Yes]
Excellent, what ability would you like?
* * [An extra-high jump!] -> high_jump

* * [More speed] -> speed_boost

* * [Make me bigger] -> make_bigger

* [No]
Come on, choose an ability -> main


=== high_jump ===
#ability: high_jump
You chose high jump
-> END

=== speed_boost ===
#ability: speed_boost
You chose speed_boost
-> END

=== make_bigger ===
#ability: make_bigger
-> END

using UnityEngine;
using TMPro;
using Ink.Parsed;
using System.Collections.Generic;
using Ink.Runtime;
using UnityEngine.EventSystems;

public class DialogueManager : MonoBehaviour
{
[Header("Dialogue UI")]
[SerializeField] private GameObject dialoguePanel;
[SerializeField] private TextMeshProUGUI dialogueText;

[Header("Choices UI")]
[SerializeField] private GameObject[] choices;

private TextMeshProUGUI[] choicesText;

private Ink.Runtime.Story currentStory;

public bool dialogueIsPlaying { get; private set; }

private static DialogueManager instance;

private void Awake()
{
if (instance != null)
{
Debug.LogWarning("More than one instance of DialogueManager found!");
}
instance = this;
}

public static DialogueManager GetInstance()
{
return instance;
}

private void Start()
{
dialoguePanel.SetActive(false);
dialogueIsPlaying = false;

// get all of the choices text
choicesText = new TextMeshProUGUI[choices.Length];
int index = 0;
foreach (GameObject choice in choices)
{
choicesText[index] = choice.GetComponentInChildren<TextMeshProUGUI>();
index++;
}

}

private void Update()
{
if (!dialogueIsPlaying)
{
return;
}

if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log("Return key pressed.");
ContinueStory();
}
}

public void EnterDialogueMode(TextAsset inkJSON)
{
Debug.Log("EnterDialogueMode called");
currentStory = new Ink.Runtime.Story(inkJSON.text);
dialoguePanel.SetActive(true);
dialogueIsPlaying = true;

ContinueStory();
}

private void ExitDialogueMode()
{
Debug.Log("Exiting dialogue mode triggered");
dialogueIsPlaying = false;
dialoguePanel.SetActive(false);
dialogueText.text = "";
}

private void ContinueStory()
{
Debug.Log("Calling ContinueStory.
Can continue: " + currentStory.canContinue);

if (currentStory.canContinue)
{
dialogueText.text = currentStory.Continue();
Debug.Log("Displaying line: " + dialogueText.text);
DisplayChoices();
}
else
{
Debug.Log("Exiting dialogue mode from ContinueStory.");
dialogueText.text = "Press Enter to exit the dialogue.";
StartCoroutine(WaitBeforeExit());
}
}

private void DisplayChoices()
{
List<Ink.Runtime.Choice> currentChoices = currentStory.currentChoices;

Debug.Log("Total choices available: " + currentChoices.Count); // Verify the number of choices
foreach (var choice in currentChoices)
{
Debug.Log("Choice: " + choice.text); // Print each choice text
}

int index = 0;
foreach (Ink.Runtime.Choice choice in currentChoices)
{
choices[index].gameObject.SetActive(true);
choicesText[index].text = choice.text;
Debug.Log($"Enabling choice button {index} with text: {choice.text}");
index++;
}

for (int i = index; i < choices.Length; i++)
{
Debug.Log($"Disabling unused choice button {i}");
choices[i].gameObject.SetActive(false);
}

StartCoroutine(SelectFirstChoice());
}

private System.Collections.IEnumerator SelectFirstChoice()
{
Debug.Log("Selecting the first choice button");
// Event System requires we clear it first, then Wait
// for at least one frame before setting the current selected game object
EventSystem.current.SetSelectedGameObject(null);
yield return new WaitForEndOfFrame();
EventSystem.current.SetSelectedGameObject(choices[0].gameObject);
}

public void MakeChoice(int choiceIndex)
{
Debug.Log($"MakeChoice called with index: {choiceIndex}");

currentStory.ChooseChoiceIndex(choiceIndex);

// Log current path in the Ink story
Debug.Log("After making a choice:");
Debug.Log("Current text: " + currentStory.currentText);
Debug.Log("Can continue: " + currentStory.canContinue);
Debug.Log("Choices available: " + currentStory.currentChoices.Count);

if (currentStory.canContinue)
{
Debug.Log("Story can continue. Calling ContinueStory.");
ContinueStory();
}
else
{
Debug.Log("Story cannot continue. Exiting dialogue.");
StartCoroutine(WaitBeforeExit());
}
}

private System.Collections.IEnumerator WaitBeforeExit()
{
Debug.Log("Waiting for user input to exit...");
yield return new WaitUntil(() => Input.GetKeyDown(KeyCode.Return)); // Wait for user input
Debug.Log("User input detected, exiting dialogue");
ExitDialogueMode();
}

}






https://redd.it/1i7orux
@r_Unity3D
Why is this happening? I splice my player and it makes it HUGE?

So to get the pivot point at the bottom of the feet I always do this. Change to multiple then auto splice at bottom.

It has always worked until now. The player has a 5 PNG attack. Well PNG's 1-3 work fine.

But the last 2 are doing this: https://imgur.com/a/xDCYEX8

I have never seen this before and don't know how to fix or make it go away. Basically the red part I marked out is the actual PNG. But it seems to have made invisible spaces before and after.

So when the animation plays there are frames where you can't see anything. Very odd.

Anyone have any ideas?
The only workaround I could do is to not splice this attack and have all the pivot points be in the default center.
I could do this but IDK if it will cause problems in the future or not.

https://redd.it/1i7sfdm
@r_Unity3D
Why do my pixels render like this? (Using Cinemachine)

https://youtu.be/5811VzGaY_o

Why does my pixel art randomly stretch the pixels in animations? When viewing the sprites individually on the same character, the pixels are not stretched. The only thing the animations do is change the sprite, it doesn't change the scale or anything. Why is this happening?

My cameras are pixel perfect as well

https://redd.it/1i7snjf
@r_Unity3D
When I splice my PNG it turns into an animation?? wtf?

Hey, so I my spicing on 1 single PNG is messing up. Its the same size and the 5th png in a sprite sheet. Well they are all separate PNGs that I combine to make animations.

Anyway, for some reason it keeps making this 5th PNG a freaking animation when I try to drag it into the scene.

I have no idea why. Its the same size resoultion/etc as all the other PNGS. Something is going wrong when I splice it.

Any ideas?

https://redd.it/1i7u6yi
@r_Unity3D
It jumps very fast

https://preview.redd.it/f3g6soki5oee1.png?width=1126&format=png&auto=webp&s=e70b40cbc289bd5d79ca98c6bdfbf773609447ee

I have a character that I’m making jump, but the jump happens way too fast and doesn’t look natural at all. How can I make the jump feel smoother and more realistic? (I have a video, but I couldn’t figure out how to upload it to Reddit yet! :)) Thanks in advance for any suggestions!

https://redd.it/1i7v5uy
@r_Unity3D
Media is too big
VIEW IN TELEGRAM
First time doing voice acting for my horror game feedback is needed

https://redd.it/1i7v1n7
@r_Unity3D
As a child, I always loved looking at the goods in kiosks—there were so many, and I dreamed of being a seller one day. Years later, I partially fulfilled that dream by creating a game. What do you think?
https://www.youtube.com/watch?v=Gvlp8MHFWjE

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