156
News about the Unity engine and project showcases from Reddit. Made possible with @reddit2telegram (@r_channels).
Surprised how easy this steering trick was to implement.
https://redd.it/1omgkcm
@r_Unity3D
How do i prevent double jumping
so my player keeps double jumping if i spam W
my code:
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
public class newmovement : MonoBehaviour
{
[SerializeField\] private Animator walk_0;
public Rigidbody2D rb;
public Transform groundCheck;
public LayerMask groundLayer;
private PlayerRespawn playerRespawn;
private AudioSource audioSource;
public AudioClip jumpClip;
public AudioClip deathClip;
private float horizontal;
public float speed = 8f;
public float jumpingPower = 16f;
private bool isFacingRight = true;
[SerializeField\] float pitchVariance = 0.05f;
private float jumpBufferTime = 0.2f;
private float jumpBufferCounter;
private float coyoteTime = 0.2f;
private float coyoteTimeCounter;
void Start()
{
playerRespawn = GetComponent<PlayerRespawn>();
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
private bool isGrounded()
{
return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
}
private void Flip()
{
if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
{
isFacingRight = !isFacingRight;
UnityEngine.Vector2 localScale = transform.localScale;
localScale.x *= -1f;
transform.localScale = localScale;
}
}
public void Move(InputAction.CallbackContext context)
{
horizontal = context.ReadValue<Vector2>().x;
}
void Update()
{
if (Mathf.Abs(rb.linearVelocity.x) > 0.05f)
{
walk_0.SetBool("walking", true);
}
else
{
walk_0.SetBool("walking", false);
}
Flip();
if (isGrounded())
{
coyoteTimeCounter = coyoteTime;
}
else
{
coyoteTimeCounter -= Time.deltaTime;
}
rb.linearVelocity = new Vector2(horizontal * speed, rb.linearVelocity.y);
if (!isFacingRight && horizontal > 0f)
{
Flip();
}
else if (!isFacingRight && horizontal < 0f)
{
Flip();
}
if (Input.GetButtonUp("Submit"))
{
playerRespawn.Respawn();
}
}
public void Jump(InputAction.CallbackContext context)
{
// Handle jump input buffering
if (context.performed)
{
jumpBufferCounter = jumpBufferTime; // Set the buffer when the jump button is pressed
}
else
{
jumpBufferCounter -= Time.deltaTime; // Decrease the buffer counter over time
}
// Only jump if coyote time is active and we have buffered the jump input
if (coyoteTimeCounter > 0f && jumpBufferCounter > 0f)
{
// Apply the jump velocity (only once)
rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, jumpingPower);
// Play jump sound effect
jumpBufferCounter = 0f; // Clear the buffer once the jump has been executed
PlaySFX(jumpClip);
}
// Early jump cut-off (when the jump button is released while rising)
if (context.canceled && rb.linearVelocity.y > 0f)
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, rb.linearVelocity.y * 0.5f); // Cut the jump short
}
}
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.CompareTag("spike"))
{
PlaySFX(deathClip);
playerRespawn.Respawn();
}
}
private void PlaySFX(AudioClip audioClip)
{
float randomPitch = Random.Range(1f - pitchVariance, 1f + pitchVariance);
audioSource.pitch = randomPitch;
audioSource.clip = audioClip;
audioSource.Play();
}
public void Interact(InputAction.CallbackContext context)
{
// Handle jump input buffering
if (context.performed)
{
playerRespawn.Respawn();
}
}
}
https://redd.it/1omei5m
@r_Unity3D
Can't fit image to screen resolution
Hey guys, i want to learn unity to make 2D games but I'm getting absolutely furious over this....
So basically i want to create a scrolling background, i have a GameObject called Background which holds two images, a script moves both of those images in one direction and if an image scroll all the way across the screen it moves it to the right edge of the window, pretty simple...
The issue I'm having is i cannot make the image perfectly aligned with the size of my screen, I'm using a resolution of 360x640 and even when i set my grid snap to 0.0000000000001 i still cannot align the image.
I have no clue how I'm supposed to do this...
https://preview.redd.it/yi9jysat9itf1.png?width=310&format=png&auto=webp&s=6630d7946969a39bf7e713743de27c71027f09dc
https://preview.redd.it/55r779iz9itf1.png?width=1622&format=png&auto=webp&s=d38a444b2aff6296a16653fc208578cbc87e4360
This is extremely zoomed in, you can see the scale on the right side and it just doesn't make any sense to me at all. In godot i could easily make the image fit my screen.
Every answer i got from chatgpt was either some crazy long math equations done with code which doesn't even make sense, how could something so simple require code whatsoever.
Am i absolutely dumb or is unity just designed this weirdly ? Thanks for any help.
https://redd.it/1nzljb6
@r_Unity3D
One of the strangest mechanics you can use in my indie game is this one that makes any object turn into an NPC
https://redd.it/1nzo6oc
@r_Unity3D
Hollow Mine releases just in 3 days on Steam! Journey begins - October 9. Hit that wishlist button hard!
https://redd.it/1nzniil
@r_Unity3D
Animators are gone. Please help
I'm completely new to game development and unity.
I was working on UI's when this happened and I don't know what caused this.
And now all my animators are gone. I don't know if it's ok to save and reopen my project..
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Graphs.AnimationStateMachine.Graph.GenerateConnectionKey (UnityEditor.Graphs.Node srcNode, UnityEditor.Graphs.Node dstNode) (at <1e33adae5e6d4bdea86244c86781fc9d>:0)
UnityEditor.Graphs.AnimationStateMachine.Graph.GetEdgeInfo (UnityEditor.Graphs.Edge edge) (at <1e33adae5e6d4bdea86244c86781fc9d>:0)
UnityEditor.Graphs.AnimationStateMachine.EdgeGUI.DoEdges () (at <1e33adae5e6d4bdea86244c86781fc9d>:0)
UnityEditor.Graphs.AnimationStateMachine.GraphGUI.OnGraphGUI () (at <1e33adae5e6d4bdea86244c86781fc9d>:0)
UnityEditor.Graphs.AnimatorControllerTool.StateMachineView (UnityEngine.Rect position, System.Single zoomLevel) (at <1e33adae5e6d4bdea86244c86781fc9d>:0)
UnityEditor.Graphs.AnimatorControllerTool.DoGraph (UnityEngine.Rect graphRect, System.Single zoomLevel) (at <1e33adae5e6d4bdea86244c86781fc9d>:0)
UnityEditor.Graphs.AnimatorControllerTool.<SetupGUI>b__141_12 () (at <1e33adae5e6d4bdea86244c86781fc9d>:0)
UnityEditor.Graphs.AnimatorControllerTool.ScopedOnGUI (System.Action onGUIHandler) (at <1e33adae5e6d4bdea86244c86781fc9d>:0)
UnityEditor.Graphs.AnimatorControllerTool.<SetupGUI>b__141_10 () (at <1e33adae5e6d4bdea86244c86781fc9d>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <d6f576415dfd4add8f23aa1d383d68cc>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <d6f576415dfd4add8f23aa1d383d68cc>:0)
UnityEngine.UIElements.IMGUIContainer.DoIMGUIRepaint () (at <d6f576415dfd4add8f23aa1d383d68cc>:0)
UnityEngine.UIElements.UIR.RenderChainCommand.ExecuteNonDrawMesh (UnityEngine.UIElements.UIR.DrawParams drawParams, System.Single pixelsPerPoint, System.Exception& immediateException) (at <d6f576415dfd4add8f23aa1d383d68cc>:0)
Rethrow as ImmediateModeException
UnityEngine.UIElements.UIR.RenderChain.Render () (at <d6f576415dfd4add8f23aa1d383d68cc>:0)
UnityEngine.UIElements.UIRRepaintUpdater.Render () (at <d6f576415dfd4add8f23aa1d383d68cc>:0)
UnityEngine.UIElements.BaseVisualElementPanel.Render () (at <d6f576415dfd4add8f23aa1d383d68cc>:0)
UnityEngine.UIElements.Panel.Render () (at <d6f576415dfd4add8f23aa1d383d68cc>:0)
UnityEditor.UIElements.EditorPanel.Render () (at <e019b6f8bc824de1922b414eb1b0dbe6>:0)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <d6f576415dfd4add8f23aa1d383d68cc>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <d6f576415dfd4add8f23aa1d383d68cc>:0)
UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <d6f576415dfd4add8f23aa1d383d68cc>:0)
UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <d6f576415dfd4add8f23aa1d383d68cc>:0)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <fd268454062e4931ba4011422e690489>:0)
https://preview.redd.it/131dtxrt6itf1.png?width=1919&format=png&auto=webp&s=fdafbe36e8ed5b7b749f4491b0236143f5c8c353
https://redd.it/1nzkxwl
@r_Unity3D
The giraffe animation is done with just a few VERY basic key-framed animations, blended with wobbly physics(tm), IK for the arms and my hi-tech neck tech.
https://redd.it/1nzhvqe
@r_Unity3D
[Project ELYRA] Full showcase
https://redd.it/1nzdl5x
@r_Unity3D
Jump ramps for tanks
https://redd.it/1nzcleu
@r_Unity3D
Mini Simple Characters | Skeleton | Free Demo
https://redd.it/1nz2fjq
@r_Unity3D
This is How I Fixed the Projectile Movement in My Indie FPS Game, According to Rocket Science. (Before and After)
https://redd.it/1nz0ptw
@r_Unity3D
Good change?
Before
After
link to game : https://kvikster1ka.itch.io/retro-hoops
https://redd.it/1nz1gwb
@r_Unity3D
I have a scoring system but the scoring cant update the text mesh pro in the screen it only update the inceptor
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class Victim : MonoBehaviour
{
private static float head = 0;
public TextMeshProUGUI headText;
void Start()
{
head = 0;
headCounter();
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Border"))
{
Destroy(gameObject);
}
else if (collision.gameObject.CompareTag("Player"))
{
head -= 1;
headCounter();
Destroy(gameObject);
}
else if (collision.gameObject.CompareTag("Knife"))
{
head += 1;
headCounter();
Destroy(gameObject);
}
}
void headCounter()
{
headText.text = "Heads: " + head;
}
}
This is the code the victim spawning constantly
https://redd.it/1nyzkxf
@r_Unity3D
Brawlhalla Scythe Mechanic in Unity? (Active Input)
https://youtu.be/kqcA\_nKogjo?si=dQOBvuLt2\_Vz4SJu&t=105 (At 1:45 you can see the explanation and how it looks like)
Active Input means you can choose where to send the opponent after hitting/hooking them. I find it very satisfying and could greatly be introduced in a 2D game.
Does anyone have any idea how to do that? Or know a tutorial which could help me find a way to implement it in my game? Let me know! Please and thank you
https://redd.it/1nyw50z
@r_Unity3D
Why are they not colliding?
https://redd.it/1omg0h9
@r_Unity3D
My first game project and user interface — do you like it?
https://redd.it/1omdrus
@r_Unity3D
Is there a way to blend terrain layers smoothly?
https://redd.it/1nzsbip
@r_Unity3D
I'm creating a world of a grim post-Soviet town intertwined with gothic mysticism, vampire secrets, and the story of a 19-year-old young person with a troubled fate. This is my first project and an attempt to explore the life choices of people.
https://redd.it/1nzrfw1
@r_Unity3D
Ratchet Racers demo
https://blessedman.itch.io/ratchet-racers-demo
https://redd.it/1nzpc5f
@r_Unity3D
Our cozy demo is now available!
https://redd.it/1nzkze8
@r_Unity3D
Boss head stretches when near player
https://redd.it/1nzieuf
@r_Unity3D
HELP, Resident evil 4 like inventory system
I am a bad programmer and need help with starting on how to make an inventory system like in resident evil (Like a sword which is 1 wide and 3 height, or a pickaxe which is 3 long in middle and on top is 3 wide)
i need a tutorial on how to make this kind of inventory system, already looked through youtube but there arent any good tutorials, and chatgpt doesnt understand this.
i need this in my game
https://redd.it/1nze71k
@r_Unity3D
Question about the Unity Graph Toolkit: Custom Data
https://redd.it/1nzarox
@r_Unity3D
Terrain-Mesh blending done the easy way (with decals)
https://redd.it/1nyzl2c
@r_Unity3D
Mad Max Polski Fiat
https://redd.it/1nyv3xl
@r_Unity3D
What do you guys think about the idea of becoming detectives with your friends and solving a murder mystery game ?
https://redd.it/1nz2ahx
@r_Unity3D
To learn optimization methods and compute shaders, I wanted to simulate a 2d spring mesh, and see how much i can push it, here's 600k points with ~3mil springs.
https://redd.it/1nyy51q
@r_Unity3D
Pizzatown Hero, a bite-sized action-adventure game with an emphasis on wacky humor, is out NOW!
https://daveygamerslocker.itch.io/pizzatown
https://redd.it/1nyp83a
@r_Unity3D
Adding new content for my RPG Glaivestorm: player can now summon a weapon to help in battle and that follower weapon can become pretty OP
https://www.youtube.com/watch?v=QIAd6ai0_YY
https://redd.it/1nypsyi
@r_Unity3D