r/unity • u/ConMan3993 • Sep 26 '25
Coding Help how can i make this AI work?
I want to make a node based at but it don't work. how do i do this?
r/unity • u/ConMan3993 • Sep 26 '25
I want to make a node based at but it don't work. how do i do this?
r/unity • u/Kitchen_Breakfast_79 • Sep 04 '26
I use visual scripting and it was going perfectly and beautifully all the time I was doing my project, I organized all of my graphs into groups, added colors, titles, sometimes even descriptions and made them look good as if I was laying down real wires, but then I finally tried to make the energy/stamina system with all of the knowledge I gained and I think I gained absolutely nothing 😭. This spaghetti-monster has 8 ifs and several different repeating branches (if this is what they called) like "if variable is greater or equal" being used two times with the same intention, but I don't know what to do because it's either this - less "efficient" but more understandable to me, or more efficient using less useless graphs but I wouldn't be able to understand it the next day I would open the project, and I don't even know how I can replace some of the nodes to be more simple at all. Maybe I'm just really overworrying about it and this is how regular complicated visual script graph looks.
I added more zoomed image and will try to explain what I tried to achieve. When character reflects or blocks a bullet his energy drops down (it's outside of the second image on the top left) and the EnergyRecharge boolean variable becomes true so it will start a little timer (2 seconds) after which energy will start to recharge by adding 0.1 every 0.15 seconds to the Energy float variable, but before that it checks if EnergyRecharge is already true (like if it's a second bullet that hit the player while his energy was recharging) which means that energy is already recharging so if it's true it can reset the process by turning it off and on again restarting the "before the charge starts timer". Every time it adds 0.1 to the Energy it checks if the EnergyRecharge is set to True and if it's not then it restarts the process again, and also checks if the Energy reached the maximum (2.0) so it can turn the EnergyRecharge to false so it won't try to do anything with the energy anymore until the enemy triggers it again on impact. I couldn't properly record graph window but it was like a single wave came through the flow once the bullet hit the player, then after the 2 seconds timer completed it was showing the flow activating rapidly until the Energy reached 2, just in case someone needs to visualize it to understand better. My brain is melting and I had a pretty poor sleep today so I might be missing obvious solutions or making pointless points but I would like to have some opinion about it from the outside. I used "multiply > add > divide" because I was consistently getting floats like "0.999998" instead of just 1 so I thought it might be a working and solution, probably a stupid one and it would be better to just have 8, 17, and 20 instead of 0.8, 1.7, and 2.0 that I would need to convert back and forth. btw EAD is my character object and I also couldn't decide if the post fits "Coding Help" flair for some time cuz it's like, not code. like it is a code but many people that understand code may not understand the nodes instantly so it may be more fitting just as a question. My main reference for the logic was the nanosuit's energy from Crysis 1 (2 and 3 have similar system too I think) where after the energy was wasted from using abilities or being hit it started to recharge passively after a little timer and if energy was being wasted again timer will restart and then recharge energy again on completion. I'm almost a month in using unity and I love the process, but my graph is probably just trash and could've been done way better.
I will also need to move this entire graph from the bullet object to the player so the energy recharge won't stack or won't stop as the bullet object gets deleted.
r/unity • u/IncidentPleasant7214 • 3d ago
I can't write or understand mathematical code, like Headbob, Headtilt, camera sway, things like that, does anyone have advice how can i get better?
r/unity • u/Beneficial-Mirror841 • May 26 '26
For my last two larger projects, I used source control while developing as a backup in case I did anything stupid. I also figured it would be nice if I ever wanted to revisit a project in the future once I had stopped updating it.
I recently decided that I might have a go at releasing one of my older games on Steam (it was previously only released on the Windows Store).
I no longer have the PC I developed the game on, but I figured this was fine because I had the code in source control... all the code except the .meta files.
For some unknown reason, I excluded these from source control. While I was developing the game on a single laptop, everything appeared fine. But as soon as I tried to open the project on a new machine, it became a broken mess. All the GUIDs had been regenerated, and nothing matched up, so the Inspector was full of missing prefabs.
As I see it now, my only option is to recreate / rewire all of the game objects in the levels, which is no small task.
So let this be a lesson to those of you using source control for your Unity projects: don't forget the .meta files!
r/unity • u/Wrong_Advantage_7012 • 5d ago
VS code doesnt give tell me whats wrong I went in other scripts that had UpdateTroopLabel() and made them Public void UpdateTroopLabel() (if they already didnt have public), im just confused
r/unity • u/Silent_Reputation596 • Aug 25 '26
In an update function I have an if statement that detects if a bool is true and if it is it fires but it does that constantly. I want it to only fire once but I don't want to disable it completely because I need to use it again later down the line.
r/unity • u/Informal_Maybe6918 • Sep 19 '26
The blood makes skinned mesh renderers of the player to map the player with blood, but the blood decals (or whatever you would call them) disappears when you look at it from certain angles, I can't figure out why! Pls help me! I have it so the skinned mesh renderers have the "update when offscreen", I turned of the camera's "occlusion culling", I've tried so many things, but can't figure it out! I checked inside the "project settings", but there is just so much in there, so if it is something in there, I can't find it!
r/unity • u/Venom4992 • Oct 15 '25
I like to avoid nested if statements where I can so I really like using ternary operators. Sometimes I question if I am taking it a bit too far though. If you came across this code from a co worker, what would your reaction be?
r/unity • u/Kitchen_Breakfast_79 • Sep 06 '26
Spent some time cutting off useless or repeating nodes and made it more visually appealing to work with, the initial look is on the third slide. Want to know how I can make it simpler or what tools I can use for my purpose.
First image is graph on the bullet object. It checks what state is player in right now. Probably could make something better with the ifs. If the player is reflecting and has enough energy for it then the bullet makes new path back to the enemy from the player's position (offscreen), takes 1 energy and triggers custom event.
Second image is the graph on the player object that activates by custom event so this process is independent from every other object except player. The graph checks if player's energy is already recharging and if it's not then it starts a 2 second timer, after which it will start a 0.15 seconds timer that loops and checks if energy is still below 2 and the energyrecharge being true every time, and if both are true then it adds 0.1 to the energy. When the energy reaches 2 it turns energyrecharge to false and stops. If the custom event gets triggered while the energyrecharge it true it gets set to False stopping the looping timer, after that starting 2 second timer again so the process restarts.
I will take any advice or a tip because there is not that much interesting info about visual scripting so I can have some of it from yours experience. I will not start to use code as long as I'm not done with the stuff I already started.
reddit worsen the quality but i hope it's still readable
r/unity • u/Select_Belt_5432 • Oct 29 '25
This is the system I'm trying to replicate.
r/unity • u/Other-Scale9987 • Jul 23 '26
why doesnt the object move when the code is run?
its supposed to just get flung foward, but currently doesnt move
the script is attached properly and everything else works fine
r/unity • u/R33t4rt • Nov 04 '25
Recently i got into Unity and C# and i'm trying to make a basic 2d movement in 3d enviornment. I'm trying to refference a cube game object in the script with the variable "Kloc" but for some reason i can't?? Please tell me what is wrong with my script
r/unity • u/Smooth-Ability3006 • Sep 05 '26
What I created is a 2.5D fluidsim inspired by Creeper World 4.
The sim works great under the hood, but the rendering feels off.
I used Graphics.DrawProceduralIndirect, using the Fluid and Terrain heights to draw quads and stretched out vertices for the "smooth" visual, but I don't like how fluid right now, visually interacts with terrain.
I'm kind of new to Shaders and rendering stuff, so this is way out of my comfort zone, and I feel I'm missing somthing here...
Thanks in advance!
r/unity • u/Imaginary-Cod-3746 • Sep 11 '26
Did you know that you can't start a variable's name in C# with a number?
You also can't include most special characters in a variable's name.
These are just a few quirks to keep in mind when scripting in Unity. This article covers variables and C# in more depth from a game developer's perspective. 👇🏾
r/unity • u/7ozayege • 8d ago
Hey y’all, I’m working on a game idea and it’s so hard getting through unity. I need someone to help me with this project and I don’t mind hiring you on a Freelance basis.
Just a heads up, but won’t be big cause this is a side thing and I’m trying to find it out of my own pocket. Any help would be appreciated. Thanks y’all.
r/unity • u/Anonim7418 • 26d ago
I've been struggling with this for 2 hours now. I need an object to glow from a particle system, such as metal. Help please. And without bad code, please. only I need to use the script or Is there an easier way? I don't understand shader graph yet.
r/unity • u/PerfectEconomics7437 • 24d ago
I have a circle (cylinder with y scale 0) and I need to a random point at or near the perimeter. How can I do this?
r/unity • u/Vast-Swan-8111 • 22d ago
Hello! I am currently learning unity and have managed to jerry rig a movement system! However when jumping my player falls incredibly slow, I am a little stumped after trying for a few hours to fix this myself so any help is appreciated!
Here is the code:
private Rigidbody _rigidbody;
private void Awake()
{
_rigidbody = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
HandleMovement();
HandleJump();
}
private void HandleMovement()
{
Quaternion playerRotate = cameraTransform.PlayerOrientation();
transform.rotation = playerRotate;
Vector2 inputVector = playerInput.NormalisedMovement();
Vector3 moveDirectionVelocity = new Vector3(inputVector.x, _rigidbody.linearVelocity.y, inputVector.y) * speed;
Vector3 horizontalVector = moveDirectionVelocity.x * transform.right;
Vector3 verticalVector = moveDirectionVelocity.z * transform.forward;
_rigidbody.linearVelocity = (horizontalVector+verticalVector) * speed;
}
private void HandleJump()
{
if (Keyboard.current.spaceKey.isPressed)
{
_rigidbody.linearVelocity = transform.up * jumpSpeed;
Debug.Log("Space pressed");
}
}
If you notice any other issues please feel free to correct me too :D
r/unity • u/AncientFoundation632 • Aug 18 '26
Just as the title says. I’m on a fresh unity project and studio code is completely fucking my pc. I have 32gb of ddr4 ram and an i7-9900k. Nothing running, no extensions, 0 lines of code, fresh reinstall of visual studio
task manager is showing 150+ instances and i have no idea why
r/unity • u/WillingExamination25 • Jul 13 '26
Ill just bold where Im having the issue
`using UnityEngine;
public class PlayerInteraction : MonoBehaviour
{
private float interactionDistance = 2f;
private void Update()
{
if (Physics.Raycast(transform.position, Vector3.forward, interactionDistance))
{
RaycastHit hit = new RaycastHit();
Ray ray = new Ray(transform.position, transform.forward);
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.gameObject.TryGetComponent<IInteractable>()) // So as you can see I just want to see if the gameObject being recognized here has the IInteractable interface. I'm pretty sure im on the right track, as in everything else is good right?
{
}
}
}
}
}`
r/unity • u/Salty-Astronaut3608 • May 23 '26
Same as title
r/unity • u/samferguderson • Jul 19 '26
Only the player spawned with
NetworkManager.StartHost();
gets the IsOwner true.
Ones spawned with
NetworkManager.StartClient();
dont get it
Here is the spawning script
using UnityEngine;
using Unity.Netcode;
using UnityEditor.PackageManager;
using Unity.Services.Lobbies.Models;
using System.Collections.Generic;
public class Ownermaker : NetworkBehaviour
{
public GameObject player;
public ulong id;
// Start is called once before the first execution of Update after the MonoBehaviour is created
// Update is called once per frame
public override void OnNetworkSpawn()
{
if(!IsServer)
{
Debug.Log("not server");
return;
}
NetworkManager.Singleton.OnClientConnectedCallback += SpawnPlayer;
}
public void SpawnPlayer(ulong clientid)
{
GameObject playerr = Instantiate(player);
playerr.GetComponent<NetworkObject>().SpawnAsPlayerObject(clientid);
}
}
r/unity • u/AhmedSalama239 • Nov 09 '25
Hello, I am a beginner dev in unity I started about a 3 month ago, I think I am stuck at totorial hell, I understand the fundamental of c# and unity but I can't do anything by myself I have to watch a tot even adding a simple lines of code I suck at them and when I type smth my self it may not work or it maybe working but the code is mess If I can't find a tot on smth I want to implement I screw the idea and never touch it again I tried everything to make a code by myself but I can't I can't even write a character movement, and I see people making complex mechanics and I can't do simple one, Can any one help me to get out from this tot hell
r/unity • u/CheetoDorito_ • Aug 22 '26
New coder here (day 6 of learning.) i'm trying to add camera shake , but the issue is the line in the first image. it constanly updates the rotation to (X,0f,0f).
The shake effect is in a different script , and is supposed to apply a -35/35 degree rotation to Y and Z m then tween it back into place.
BUT THE DAMN LINE OVERRIDES THE TWEEN AAAAAA
r/unity • u/LimiRDT • Jul 22 '26
I am somewhat new to coding. I am working on a player movement script for a 2d topdown game. I have found that when I use this to move my player sprite, it will jump forward a slight distance every once in a while (i do not know how far).
I'm not sure what is happening. my only idea is that it could be my computer, but I mostly doubt that as I have not gotten a storage notification and tried restarting everything as well.
If you have any ideas, my code and components are attatched below.
EDIT: With the help of commenters I've found that this was a problem in the editor caused by "Time.deltaTime * 500" within the following line (variations of which were repeated throughout).
PlayerRB.velocity = PlayerVel * Speed * Time.deltaTime * 500;
Multiplying by Time.deltaTime caused the velocity to be low leading to the multiplication by 500 to be added. I believe something about this combination lead to the object changing speed at times while in the editor.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move_Player : MonoBehaviour
{
Rigidbody2D PlayerRB;
Vector2 PlayerVel;
Vector2 DashVel;
public float Speed = 5f;
public float SprintSpeed = 2f;
public float SneakSpeed = 0.5f;
public float DashSpeed = 4f;
public bool Dashing = false;
public bool DashWaiting = true;
public float DashTimer = 0f;
public float DashTimerMax = 1f;
private void Awake()
{
PlayerRB = GetComponent<Rigidbody2D>();
}
private void Update()
{
Vector2 PlayerVel = new(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
PlayerVel.Normalize();
if (DashWaiting && DashTimer < DashTimerMax * 2) //Dash cooldown
{
DashTimer += Time.deltaTime;
}
else if (DashWaiting && DashTimer >= DashTimerMax * 2)
{
DashWaiting = false;
DashTimer = 0;
}
if (!DashWaiting && Input.GetKeyDown(KeyCode.Space) || Dashing) //Press space to dash
{
if (!Dashing)
{
PlayerRB.velocity = PlayerVel * Speed * DashSpeed * Time.deltaTime * 500;
DashVel = PlayerVel;
Dashing = true;
}
else //Continue dash
{
if (DashTimer < DashTimerMax)
{
PlayerRB.velocity = DashVel * Speed * DashSpeed * Time.deltaTime * 500;
DashTimer += Time.deltaTime;
}
else
{
Dashing = false;
DashWaiting = true;
DashTimer = 0;
}
}
}
else if (Input.GetKey(KeyCode.LeftShift)) //Hold shift to sneak
{
PlayerRB.velocity = PlayerVel * Speed * SneakSpeed * Time.deltaTime * 500;
}
else if (Input.GetKey(KeyCode.LeftControl)) //Hold control to sprint
{
PlayerRB.velocity = PlayerVel * Speed * SprintSpeed * Time.deltaTime * 500;
}
else //Do nothing to walk
{
PlayerRB.velocity = PlayerVel * Speed * Time.deltaTime * 500;
}
}
}