#💻┃code-beginner

1 messages · Page 640 of 1

teal viper
#

Unity API is not thread safe. If you're not using unity API in the code you want to run on a background thread, there's no problem.

thorn holly
#

Oh sweet thx

hidden fossil
#

!code

eternal falconBOT
hidden fossil
#

no no i meant by like when i click it shifts my camera to the right and i cant move it back

teal viper
# hidden fossil does anyone know whats wrong with my camera script like when i click, it makes m...

Well, you're moving it here:

       else if(Input.GetMouseButton(0)){
            Vector3 direction = touchStart - Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Camera.main.transform.position += direction;

            Vector3 clampedPosition = Camera.main.transform.position;
            clampedPosition.x = Mathf.Clamp(clampedPosition.x, panLimitMin.x, panLimitMax.x);
            clampedPosition.y = Mathf.Clamp(clampedPosition.y, panLimitMin.y, panLimitMax.y);
            Camera.main.transform.position = clampedPosition;
        }

So it must be a bug in this logic/math

#

Step through the code or use logs to see all the relevant values at each step

#

And make sure they're what you expect

hidden fossil
#

oh i have another question btw

#

for my laser tower i set the color and new material to purple but how come the laser its shooting out is white?

#

line renderer:

teal viper
hidden fossil
#

oh

#

lemme check rq

teal viper
#

Can you pause the game when you see the white laser, select the object in the scene ant take a screenshot of the whole editor

hidden fossil
teal viper
hidden fossil
#

whats causing that

teal viper
#

Nothing. It's just configured to be white apparently.

hidden fossil
#

is it because its a prefab?

teal viper
#

I don't know. That's how you configured it.

hidden fossil
#

should i make a new material then and then replace it?

wet pivot
#

rb.AddForce(0f, 0f, 0f, ForceMode.VelocityChange);
This code should in theory stop my rigidbody from moving entirely right? My rigidbody is currently only affected by gravity and my movement and jump forces, yet running this line of code doesn't seem to do anything. I want my rigidbody to stop moving entirely when I let go of a key.

acoustic sequoia
#

hey everyone how do i prevent an action happing in my game through a UI click? I have a UI that's always on during gameplay, but if you click the toolbar, things happen in the game world

eternal needle
teal viper
hidden fossil
#

hmm the best idea rn would be to add a new material im asuming

wet pivot
eternal needle
hidden fossil
#

is it possible to change the color of a mobile/additives/particle new material in the inspector?

edgy tangle
wet pivot
#

lol i get ya

hidden fossil
#

nvm

pine heart
#

trying to make two ridgid bodies walk through each other if they collide from top, but also turn directions if colliding

hidden fossil
#

do you have to worry about errors unity sends in the console but it doesnt affect your gameplay?

pine heart
#

from left to right

#
   {
       if (other.gameObject.tag == "Player" && tag == "Stunned")
       {

           // Destroy(gameObject);
       }
       if (other.gameObject.tag == "Up" && other.transform.position.y - 1 < transform.position.y)
       {
           dir = -dir;
           rb.linearVelocity = new Vector2(8f * dir, 10f);

           //transform.position = new Vector3(transform.position.x, transform.position.y + 1/4, transform.position.z);
           tag = "Stunned";
           stuncounter = 10f;
       }

       if (other.gameObject.tag == "Enemy" || other.gameObject.tag == "Stunned")
       {
           dir = -dir;
           rb.linearVelocity = new Vector2(4f * dir, dropspeed);
         
           //other.rb.linearVelocity = new Vector2(movespeed * -dir, dropspeed);
           
           tag = "Stunned";
           other.tag = "Stunned";
           stuncounter = 10f;
           
       }

    
       //else
       {


           //Physics2D.IgnoreCollision(other, coll, false);


       }
       if (IsBelow())

       {
           //dropspeed = -4f;
       }

   }```
hidden fossil
#

use !code next time if its big blocks

eternal falconBOT
flat holly
#

i wonder how do i use UVS to script
like can i choose UVS script or normal C# script?

#

i dont know where to enable that

flat holly
#

ugh

#

yeah

#

i might say something wrong because all videos are kinda old

rich adder
#

visual scripting is okay for learning, not very scalable

#

but if you like learning with graphs it helps

#

the logic / components are the same

flat holly
#

yeah that looks better for me

#

i also want try node scripting

#

so how do i use it?

teal viper
#

Visual scripting is node scripting. Unless we're misunderstanding you

flat holly
#

yeah but i mean how do i get that screen, i dont know where to get the node screen like shader graphs

#

or theres something i can do to mono behavior scripts?

#

im sorry im so new to this 😔

teal viper
flat holly
#

oh thanks

flat holly
#

thank you so much now i see theres a visiual scripting there i can create

worthy haven
#

Is there a way to deform a mesh using Unity Spline tools. I have been trying to code deformation spline mesh use a C# script with Unity's Spline tools but any tutorials covering it are to vague or don't explain well enough for me to understand the system. As well as they are wanting to generate a mesh instead of using a premade mesh to instance and deform along the curve. I wanted this for castles walls. so i can bend them to the towers. I have created something similar in unreal but now that i move over to unity I can't figure it out.

teal viper
#

But you'll need to share the details of the tutorial and your current progress following it.

worthy haven
#

I was using this tutorial. But it created a mesh inside of useing a premade mesh and hides or changes code in between explanations. Which is very frustrating because it one and the only videos that go over the unity spline code.
https://youtu.be/ZiHH_BvjoGk?si=tZQAL7yUcTnW1mTC

Roads are more common in videogames than you might think so in this episode we'll look at how we can use Unity's new spline package to build out a tool that procedurally creates a road mesh along a spline, and ALSO handles intersections at the same time. While we're at it, we might even decorate it to look pretty using URP Decals too!

Get the p...

▶ Play video
sharp bloom
#

How would you implement a system where a bunch of gameobjects move randomly in 2 dimensions within a certain boundary?

#

My first thought was generating waypoints but I need to also stop the objects from colliding with eachother

digital kayak
sharp bloom
#

Just straight direction for now

digital kayak
#

oh ok

sharp bloom
#

Basically if they'd collide, they would pick another random direction

digital kayak
#

then create an empty game object or a raycast to see if anyone is near then change the direction to the opposite direction

sharp bloom
#

I did not do with raycasts though, just colliders

digital kayak
celest ridge
true siren
#

is this just how small banner ads are?

grand snow
#

what is this from?

true siren
#

just a empty untiy project i was using to figure out how to add ads into

eager spindle
grand snow
#

so whatever you were reading check again more carefully

naive pawn
eternal falconBOT
naive pawn
#

and what are you trying to achieve exactly? make it rotate to point to where the mouse is?

oblique torrent
#
void Update()
{
    float moveDelta = moveSpeed * Time.deltaTime;
    float rotateDelta = rotateSpeed * Time.deltaTime;

    movement = Vector3.zero;

    movement += Input.GetAxisRaw("Vertical") * moveDelta * transform.forward;
    movement += Input.GetAxisRaw("Horizontal") * moveDelta * transform.right;

    if (Input.GetKey(KeyCode.E))
      movement += moveDelta * transform.up;
    if (Input.GetKey(KeyCode.Q))
      movement += moveDelta * -transform.up;

when i press W and E together, the object moves foward and up, and when i press W and D together, the object will move forward and right
but when i press all 3 together, itll only move in 2 directions at a time
anyone know whats causing this?

#

i put Debug.Log statements and it doesnt even register that E is being pressed when i press W D and E together

#

when i changed it from KeyCode.E to KeyCode.LeftShift it worked 🤔

visual linden
teal viper
oblique torrent
#

oh

#

thats a shame

#

thanks tho

#

oh it actually works for other key combinations too

thorn trout
#

does unity not have splines in 2d?
I am using unity 6 and cant find splines inside package manager nor in components

#

btw not for animation

#

I want it in the world

hexed terrace
#

1- Not a code question, shouldn't be in here
2- There is no "2d" version of Unity, opening a 2d template is the same as opening a 3d template, just with 2d packages imported already

mystic ferry
#

In 2D you don’t get the Z-Axis.

wintry quarry
trail heart
hexed terrace
true siren
#

Does advertisment legact still work at the same effectivness as it used to? i could not get levelplay to work for the life of me

hexed terrace
true siren
#

oh frick wrong channel my fault ty

grand snow
livid arch
#

how do i give a rigidbody friction? i tried applying a physics material to their collision and setting the friction value to like 1000 and it didnt seem to work

slender nymph
#

note that for friction to actually take effect you must be moving the rigidbody in a physics friendly way

slender nymph
#

show the setup and the code

livid arch
slender nymph
#

well for one, !code 👇

eternal falconBOT
livid arch
#

arent all the code colors and the lines and other info the ide gives important?

slender nymph
#

syntax highlighting is important, which is why the options listed all offer syntax highlighting.

grand snow
#

we soo smart we dont need pretty colours 😎

livid arch
#

lol

slender nymph
#

but also with your giant vs code next to unity your inspector is shrunk down making the information in that harder to read

#

you also need to show the physics material

livid arch
#

is this how it works?

slender nymph
#

okay now show the object it should be colliding with to use that friction

livid arch
#

i need to settup stuff with the plane?

slender nymph
#

well without a material it should be using the default values which i believe are 0.6 for both. i wonder if maybe your friction is just way too high because that is a seriously unreasonable number for friction in your physics material

#

ah yeah, the docs say it is a value from 0 to 1 so 1000 obviously isn't correct

livid arch
#

i dont understand why i cant get any sort of response outta it

#

i did try lower values

#

negative feels like the wrong way to go

slender nymph
#

were those lower values also above 1? because 1 is the maximum it uses so anything above that is literally exactly the same

livid arch
#

nah i also did 0

#

theres just 0 friction, it moves like its on ice.

polar dust
#

have you tried giving both objects the physics material?

slender nymph
livid arch
#

every value does ice physics

slender nymph
#

well you've also got 0 drag on the rigidbody which is basically air resistance. and you are giving it a force of 10 which is kind of high for an object with a mass of 1

polar dust
#

for the sake of testing, try making a plane at a 30 degree angle, put a rigidbody sphere above the plane, and give both the material. if the sphere slows down, the material is working, and its likely an issue related to your code

#

if the physics material doesnt do anything in a test like that, then its a physics problem

livid arch
#

i want floor resistance

#

for the character to jump and stay moving till they hit the ground

slender nymph
#

you still need drag

livid arch
#

well, ill give it like 0.1 or something but i still wanna increase floor friction

slender nymph
#

okay and friction can only do so much with 0 drag and way too much force

livid arch
#

friction value doesnt do anything but drag does

cerulean topaz
#

Do I need to use Time.deltaTime for transform.Rotate(Vector3.up, angle) ?
I vaguely remember I won't - I don't know where I got this from though

polar acorn
hallow acorn
#

hey does using character controller functions in update instead of fixed update cause any problems?

rich adder
atomic holly
#

Hello, I want to use event Action in a class Ladder to call a method in an another class PlayerController but it doesn't work.
I want to add the method to my Action with the instance of the PlayerController class.
So, this a part of my code :
Ladder :

public event Action<bool> LadderEnter;

    private void OnEnable()
    {
        LadderEnter += PlayerController.Instance.ClimbLadder;
    }

PlayerController :

public void ClimbLadder(bool isOnLadder)
    {
        if (isOnLadder)
        {
            Debug.Log("On Ladder");
        }
        else
        {
            Debug.Log("Off Ladder");
        }
    }
polar acorn
atomic holly
atomic holly
# rich adder where do you invoke event?

Here:

private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            LadderEnter?.Invoke(true);
            Debug.Log("Player entered ladder trigger");
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            LadderEnter?.Invoke(false);
            Debug.Log("Player exit ladder trigger");
        }
    }
rich adder
#

you did it backwards

#
 private void OnEnable()
    {
        LadderScript.LadderEnter += ClimbLadder;
    }```
#

if you need to insert PlayerController.Instance that also kind defeats the whole point of Ladder script being independent , why should ladder care about calling any method in other script, it should only care about Invoking the event, how other scripts handle it is a separate matter.

atomic holly
#

Why it isn't work ? Because, LadderScript.LadderEnter call the event action and PlayerController.Instance.ClimbLadder call ClimbLadder method. So, it will work in both directions no ?

polar acorn
#

If PlayerController is a singleton, I don't really know why you need an event at all

#

Seems more like you should just be calling PlayerController.Instance.ClimbLadder() in the OnTrigger methods

atomic holly
#

So, when are you using Action event ?

polar acorn
#

Events would be useful when you want this object to be agnostic to what is subscribing to it. Since this object already handles the subscribing, there's no benefit to it

atomic holly
#

What mean agnostic ?

polar acorn
#

Like, if you know that something is gonna care when something gets on this ladder, you'd make an event for like PlayerEntersLadder, and then other things can subscribe to it that this object doesn't have to know anything about. Like, if you wanted all your enemies to switch to ranged weapons when the player gets on a ladder, you could have an event that fires, and then whatever enemy script can subscribe to it and know "okay time to change weapons"

#

If the script with the event on it already has a reference to the thing subscribing to it, you should just call the function on it.

#

Events should be used for basically "one-way data flow", where managers send data downstream but never need to care about what uses it.

rich adder
sour fulcrum
#

"yo just letting anyone who this thing just happened if anyone cares"

a good example of an event might be a wave based game starting a new wave, where the wavemanager might not care who wants to know that a new wave just started but is still open to letting people know that it did happen if people are interested

polar acorn
#

Yeah, if your object doesn't care who gets the message, you should use an event.

#

If a specific object is meant to respond to it, you should just reference that object

sour fulcrum
#

Also worth pointing out in some cases it's totally valid for both to happen, where going off my example the wavemanager might have some direct handling of what happens when a new wave starts and informs strangers that it happened if anyones around to listen

atomic holly
#

So, we can use Action event just to let know other scripts that want to know this information but that's not obligate to get this action event ?

#

But, if you create an action event, it means you want to an other object get the information that the action happened ?

polar acorn
#

If you could imagine your object standing up on a pedestal with a megaphone and shouting into your codebase "Hey everyone, this thing happened" and then just leave, you can use an event for it

atomic holly
#

So, you will often use it if you want to do something to different objects and not a single one ?

sour fulcrum
#

You use it so the thing standing up on a pedestal with a megaphone doesn't have to explicitly tell the people listening

#

events keep both parties relatively seperate from eachother

rich adder
#

well except the subscriber always knows about the Invoker / Event raiser

#

its a 1 way instead of 2 way (bad tight coupling)

atomic holly
#

Why call a method by instance of an object is a 2 way so ? It just call a method but the object that call the method doesn't really have something in return

sour fulcrum
#

Another game related example would be in Minecraft when it's officially "day time" after a night. We don't want the class handling the time of day stuff to mess with:
setting all enemies on fire
making sure beds can't be used
firing off relevant achievements
make bees start leaving their hives
etc.
because all these things aren't really the time of day's scripts responsibility to mess with. Programming wise the sun shouldn't tell bees what to do or set zombies on fire (aztec wise tho idk).
For this reason the time of day script can just have an event saying "hey it's daytime now" and then the enemy class, bed class, hive class, achievement manager class etc. can handle their own responsibilities in response

rich adder
# atomic holly Why call a method by instance of an object is a 2 way so ? It just call a method...

if you're using a static Instance to call public method, if thats what you mean.. You are still doing a 1 way which is better than 2 way..the
(Player -> Ladder)
(Ladder -> Player)
This creates tight coupling which can be considered bad
if you ever destroyed Ladder, Player would also need to be fixed/modified thats why 2 way is generally bad
The bad practice in that though is why should a Ladder care about the player methods? it should only track its own state and others might want to be on notice about it

mint venture
#
        || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow))
        {
            engineSFX.Play();
        }
        else
        {
            engineSFX.Stop();
        }

can someone tell me why this isn't working, I added an audio source to the player, turned off play on wake, and there are no errors, why won't this work?

slender nymph
eager elm
#

I suggest you add a Debug.Log("Play") and "Stop" in those

mint venture
#

in my player controller script

polar acorn
#

If this is in Update, it's going to run every frame, and GetKeyDown is true the frame you press a button and false every other time

polar acorn
#

Put a Debug Log in each condition before you call the functions, you should see what the problem is

mint venture
#

ok

mint venture
polar acorn
#

So, you tell it to play, and then on the next frame, none of those button presses are true, so it stops

mint venture
#

ok, so where do I put it then?

polar acorn
#

When do you want it to stop

mint venture
#

when you're not pressing on one of the buttons

#

so if you're moving, play audio, if you're not, don't

polar acorn
mint venture
#
        {
            Debug.Log("Play");
            engineSFX.Play();
        }
        else
        {
            Debug.Log("Stop");
            engineSFX.Stop();
        }
``` It's not this then
polar acorn
#

You'll want to make a vector that contains both horizontal and vertical.
If that vector is not zero and the sound is not currently playing, play it.
if that vector is zero and the sound is currently playing, stop it.

mint venture
#

so this should be the variable?

mint venture
rich adder
#

just remove private

#

you can't add access modifiers to local variables
(assuming you're adding this in Update)

mint venture
livid arch
polar acorn
#

You can't check if a vector is equal to a float

rich adder
#

is your ide configured?

#

this should be screaming at you

mint venture
#

I don't get it, so I change the 0, to (0,0)

mint venture
rich adder
#

okay good

mint venture
rich adder
#

You should compare the vector2 to another vector2

mint venture
rich adder
#

if thats what you want to check

#

if(movement != new Vector2(0, 0))
but that silly so we can just use
Vector2.zero property
if(movement != Vector2.zero)

mint venture
#

so like this?

rich adder
polar acorn
mint venture
polar acorn
mint venture
rich adder
# mint venture floats like Vector2?

vector2 is a struct of 2 floats, so unity takes care of it for you
by float meaning
float someValue = 1

someValue -= 1
// this could be 0 but can also be somehow 0.0000001

so doing if(someValue == 0) is might come up false

#

floating point imprecision

polar acorn
#

Otherwise it will stop any frame that it did not currently start which means it will only ever play for one frame

mint venture
mint venture
#

for the else if

rich adder
rich adder
mint venture
verbal dome
mint venture
#

how do I call it, if it can't be called?

rich adder
rich adder
#

create the v2 variable as a member field but assign the values in Update

verbal dome
#

You could convert it to a property by using => but not sure if that's what you want

#

Probably better to stick to fields for now

rich adder
#
private Vector2 movement;
..
void Update(){
movement = new (Input. etcc.```
livid arch
mint venture
rich adder
verbal dome
#

So it's very unlikely that you hit the key exactly the moment you collide

rich adder
#

yeah you would need some type of spiderman skill to hit that

livid arch
verbal dome
#

This is also not valid C# cs if playerBody_Ragdoll.GetAccumulatedForce >= 0

livid arch
#

and i wanna get jumping to only happen when touching collision

#

does unity have like >=

rich adder
#

its methods need ()

livid arch
#

or is there a better way to write it

polar acorn
livid arch
#

so it does okay

rich adder
#

if its a camelCase variable its very likely to be a field

mint venture
rich adder
#

well look how you wrote and look at the docs

#

pertaining to how methods are used.

livid arch
#

cause im just trying stuff lol

cunning terrace
#

Hey! New to coding C#, working through the tutorial and asked to replace code. Opening the PlayerController file gives me this (attached). What am I doing wrong, how do I continue? I have no idea if that is even the right thing. I'd greatly appreciate help 🙂

rich adder
eternal falconBOT
livid arch
# rich adder pertaining to how methods are used.
    {
        var playerVelocity = playerBody_Ragdoll.GetAccumulatedForce();

        if (playerVelocity = UnityEngine.Vector3.Equals(0, 0, 0))
        {
            playerBody_Ragdoll.AddForce(playerMoveInput * 10, ForceMode.Impulse);
        }
        else 
        {
            playerBody_Ragdoll.AddForce(playerMoveInput * 10);
        }
    }``` i think this is better
#

cant really figure out how vectors are used in ifs tho

rich adder
#

= is assignment not comparison

livid arch
verbal dome
#

C# beginner courses wouldn't hurt

slender nymph
#

and if your !IDE is not underlining your errors in red then it needs to be configured 👇 because that first if statement contains a compile error

eternal falconBOT
rich adder
livid arch
slender nymph
#

it sounds like they want to probably compare its magnitude against a single value to determine if it is above a specific speed threshold rather than comparing an entire vector3 to 0

rich adder
livid arch
#

im saying if its defined that way cant it also be like undefined that way too

rich adder
#

wdym undefined?

#

are you talking about if the type can be inferred ?

livid arch
#

yea

#

sorry

livid arch
rich adder
#

yes then you probably want magnitude

livid arch
#

alright,

rich adder
#

which is a single number

rich adder
# livid arch sorry

also there is no type inference that can be done in an if statement, probably because you can override Equals in any type so anything goes
you can do (cat > cat) but if you wanted to can do (cat > dog) if you overrode the equality check for dog to be compatible with cat . The compiler doesn't know the type you want to compare cat with is cat ? or dog ? or something else
(i know its a stretch but I think you get the point lol)

slender nymph
livid arch
livid arch
slender nymph
#

very

#

stop what you are doing and go learn c# and unity

rich adder
#

dynamic language vs statically typed

slender nymph
#

also incredibly different syntax for many things

livid arch
rich adder
#

your IDE would should you these properties when using the . operator

atomic holly
#

Hello
Intelissense from Rider suggest me to change float by var in this case : float deceleration = _isGrounded ? stats.groundDeceleration : stats.airDeceleration;
airDecelration and groundDeceleration are float so why use var if I know the type of variable it will be in every case ?

slender nymph
#

rider will always suggest using var for local variables, it has nothing to do with the type. var is also not a special type, it's just a placeholder for the compiler to add the correct type so you don't have to. it's still a float variable, it's just using shorthand for the type in its declaration

atomic holly
#

But for the readability, it's better to direct tell which type is the variable no ?

rich adder
#

thats pretty funny prioritizing IDE visibility vs clear intent

slender nymph
atomic holly
rich adder
#

Imo its mostly better when the type is clear in the part after it, otherwise probably better to communicate the type

naive pawn
rich adder
#

although IDE does tell you the type

#

if you look at it without ide it can be confusing

naive pawn
#

in Vector2 a = new Vector2(); you say Vector2 twice
you can shorten it by inferring the type, var a = new Vector2();
or by inferring the constructor, Vector2 a = new();

rich adder
#

it could be an int or decimal or double for all we know on assumption (ofc in unity we mostly use float)

#

but does it matter there, probably not

tame tusk
#
ClientNetworkManager.LoadMainMenu () (at Assets/Scripts/Client/ClientNetworkManager.cs:279)
ClientNetworkManager.Start () (at Assets/Scripts/Client/ClientNetworkManager.cs:42)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <314938d17f3848e8ac683e11b27f62ee>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <844019a3a067481c8d9cb70c7a2ba447>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <844019a3a067481c8d9cb70c7a2ba447>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <844019a3a067481c8d9cb70c7a2ba447>:0)```

Genuinely wtf 😭  i do not understand why the nullreference happens 

ive tried adding more debugging things but just cannot figure this out (yes MainMenu is added to build and all the gameobjects are configured correctly) 

    [SerializeField] private string mainMenuSceneName = "MainMenu";

```    async void Start()
    {
     
        if (SteamAPI.IsSteamRunning())
        {
            p2pSessionRequestCallback = Callback<P2PSessionRequest_t>.Create(OnP2PSessionRequest);
            await ProcessSteamPlayerInfo();
        }
        else
        {
            Debug.LogWarning("Steam is not running. Using PlayerPrefs data if available.");
            ProcessPlayerPrefs();
        }
        
   
        LoadMainMenu();
        
        Debug.Log("Client Ready");
    }```
```private void LoadMainMenu()
{
    Debug.Log($"Scene name to load: '{mainMenuSceneName}'");

    if (Application.CanStreamedLevelBeLoaded(mainMenuSceneName))
    {
    string sceneName = mainMenuSceneName;
    Debug.Log($"Loading main menu scene: {sceneName}");
    SceneManager.LoadScene(sceneName, LoadSceneMode.Single);
    }
    else
    {
        Debug.LogError($"Scene '{mainMenuSceneName}' is NOT in build settings or misspelled.");
    }
}```
rich adder
#

nor is it posted in its entirety to be able to paste it and get 1:1 line match

cosmic dagger
eternal falconBOT
tame tusk
rich adder
#

btw dont crosspost

#

stick to 1 channel

tame tusk
#

wait sorry hold on

#

so if i initialize my mainmenu scene could the null reference be from something inside that actual scene

#

its not just saying that the null reference IS the main menu scene like it doesnt exist rather it could be something inside

rich adder
#

whatever is on line 279 in ClientNetworkManager.cs is null

#

other then that we dont know why if we dont even know whats on that line and what to check

tame tusk
#

i will see what context is needed

#

and line 42 is LoadMainMenu();

rich adder
#

it would throw whatever Error you wrote there

#

NullReferenceException implies something was trying to get accessed on a null object

tame tusk
#

can i attach as file

tame tusk
naive pawn
#

use the links given

tame tusk
#

ok

polar acorn
# tame tusk https://paste.myst.rs/iod3poy5

That line wouldn't throw a NullReferenceException. It might have changed since you've added or removed code. Try clearing the console, then get the error again and see what the line number is

tame tusk
#

thats what i mean yea i dont understand how its throwing errors...

just cleared console and its still the same

ClientNetworkManager.LoadMainMenu () (at Assets/Scripts/Client/ClientNetworkManager.cs:279)
ClientNetworkManager.Start () (at Assets/Scripts/Client/ClientNetworkManager.cs:42)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <314938d17f3848e8ac683e11b27f62ee>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <844019a3a067481c8d9cb70c7a2ba447>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <844019a3a067481c8d9cb70c7a2ba447>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <844019a3a067481c8d9cb70c7a2ba447>:0)```
polar acorn
humble marsh
#

In my code, i have a thing that sets an item to the values of another item, then assigns the other item to the original item's ref.

currentitem.setitemvalues(otheritem);
other = currentitem;

other is a item that was passed to the method using a ref keyword. Why does Visual Studio assume this is an unessecary assignment? I am using the item in a ton of places where the other item comes from.

tame tusk
polar acorn
humble marsh
#

i'm dumb, deleted ref keyword in method declaration

#

sorry for the dumb question.

tame tusk
# polar acorn Are you sure the code has been saved and recompiled? Save it again, then restart...

oo the error changed

ClientNetworkManager.LoadMainMenu () (at Assets/Scripts/Client/ClientNetworkManager.cs:275)
ClientNetworkManager.Start () (at Assets/Scripts/Client/ClientNetworkManager.cs:42)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <314938d17f3848e8ac683e11b27f62ee>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <844019a3a067481c8d9cb70c7a2ba447>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <844019a3a067481c8d9cb70c7a2ba447>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <844019a3a067481c8d9cb70c7a2ba447>:0)

Line 275 now

polar acorn
rich adder
#

275 on ClientNetworkManager

tame tusk
#

SceneManager.LoadScene(sceneName, LoadSceneMode.Single);

rich adder
#

yeah that would not throw a null

polar acorn
#

Can you show your build settings?

#

Where you've got your scenes added?

tame tusk
#

😭

polar acorn
#

...huh

#

It's in there

rich adder
# tame tusk 😭

what is the name set in the inspector
[SerializeField] private string mainMenuSceneName = "MainMenu";

polar acorn
#

Pretty sure it doesn't care about the folder, just the actual file name

tame tusk
#

yea

rich adder
#

hmmwth is going on then lol

polar acorn
#

Are there any other errors in the console before this one?

tame tusk
#

one error

#

and one warning about version control

polar acorn
#

...huh

tame tusk
#
using UnityEngine;
using Steamworks;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using System;
using UnityEngine.SceneManagement;
public class Init : MonoBehaviour
{
    [SerializeField] private GameObject _serverGo;
    [SerializeField] private GameObject _clientGo;
    void Start()
    {
        if(SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null)
        {
            Console.WriteLine("Server Build");
            Instantiate(_serverGo);

        }
        else
        {
            Debug.Log("client_build");
            Instantiate(_clientGo);

        }
        Destroy(gameObject);
    }    



}
#

clientgo is a prefab

#

and attached is clientnetworkmanager

#

just for init context

polar acorn
#

Okay, just throwing things at the wall at the moment, comment out the SceneManager.LoadScene line and run it again. Obviously, it won't change scenes, but does it still throw the error?

tame tusk
#

no errors at all (debug logs still saying loading mainmenu) but it isnt actually loaded

#

notlikethis literally

polar acorn
#

Right, that's what I would expect to see if everything went as expected

#

but things have not gone as expected so I just wanted to see if it didn't do something wacky just because it's haunted or whatever

rich adder
#

just for shits and gigs, could you try loading that scene by Build Index ?

polar acorn
#

Yeah, for now, hard-code it to load scene 1

tame tusk
#

alr sec

rich adder
#

SceneManager.LoadScene(1, LoadSceneMode.Single);

polar acorn
#

Keep all the code as-is, just change the LoadScene to load 1 instead of the parsed string

tame tusk
#

int sceneIndex = 1;

#

then SceneManager.LoadScene(sceneIndex, LoadSceneMode.Single);

#

or how does loading by index work

polar acorn
rich adder
#

storing it in the variable makes no difference

#

it takes both types int and string

polar acorn
#

Don't change anything else

tame tusk
rich adder
#

wut

tame tusk
#

then if i try to run it ignoring that it asks to fix all compiler errors

rich adder
#

is this a custom scenemanager ?

polar acorn
# tame tusk

Then that would mean you are not calling Unity's SceneManager

tame tusk
#

using UnityEngine.SceneManagement; no?

polar acorn
#

I have no idea what the shortcut key is for VSCode, but go to that LoadScene and see if you can go to implementation

#

On VS it's F12

rich adder
#

just hold Ctrl and click it

verbal dome
#

What does it show when you hover on it

#

Or ctrl click

tame tusk
rich adder
#

should be no errors

tame tusk
#

network

#

scenemanager

#

oh

rich adder
#

yeah thats some custom thing

polar acorn
#

Ah, so not the Unity SceneManager

tame tusk
#

i thought ive been using it the whole time 😭

polar acorn
#

Looks like NetworkManager has a variable named SceneManager, and that variable is null

#

So rather than calling a static function on the class SceneManager, it's calling a function a variable of that name

#

and that variable is null, hence the null reference

rich adder
#

why wasnt ambiguity using UnityEngine.SceneManagement;
and NetworkSceneManager

#

weird

polar acorn
#

Because it's not a type ambiguity, like if you had two classes with the same name

#

one of them is a class, the other one is a variable

rich adder
#

AHhh yes that makes sense

polar acorn
#

and if they have the same name, C# assumes you want the variable

#

It's so you can do something like public NetworkManager NetworkManager

tame tusk
#

i have literally been staring at this error for hours 😭 gone through multiple stack overflows

polar acorn
#

You shouldn't do that

tame tusk
#

holy

polar acorn
#

but it can

sick trout
#

I have moved to Unity from Godot, I had bigger expectations from Unity, but Unity for me is too slow (building time etc. and is more complex)

tame tusk
#

yupp

rich adder
#

and now you learned about inspecting Definitions lol

sick trout
#

Still I'm learning it

tame tusk
sick trout
#

mainly because of multiplayer

sour fulcrum
#

building times are pretty chill but the compile times can be pretty cooked yeah

rich adder
sick trout
#

because in Godot, I have to setup custom TURN Servers etc. but in Unity I have Unity Relay and other Unity Services

rich adder
#

that will improve compile time greatly

sour fulcrum
#

sure but also i heard they we're moving to new shit like 2 years ago

rich adder
#

being stuck in such an old implementation of .net doesnt help

sour fulcrum
#

i don't doubt it tbh but also im hesitant to lean on the assumption they are on track

rich adder
#

rumors say Unity 7 but who knows..

#

maybe next year 🤞

sour fulcrum
#

until rumours say Unity 8 😛

sick trout
#

why Unity has so long compiling time etc.

slender nymph
#

are you actually experiencing long compile times, or is it the domain reload that happens after compiling is finished that is taking long?

sick trout
#

I can test for you really quick

slender nymph
#

yeah i'm willing to bet it is domain reloading that is taking long and not the actual compile. they are separate steps (though domain reloading will always happen after a compile, there is no way around that)

rich adder
#

if you're feeling brave use Assembly definitions to shave a few seconds

sick trout
#

Why not only the scripts

slender nymph
#

your scripts are assets and when you save them it needs to refresh them to recognize changes so that it can compile. but domain reloading is not the same as asset refresh

rich adder
#

the entire editor is like scripts lol

#

make changes -> assets refresh -> compiles so it can be ran

sour fulcrum
#

though you can disable domain reloading on entering play mode

rich adder
#

yeah the name threw me off in the beginning I thought domain reload was before entering play

#

but its has both after script change and before play, lucky the before play can be skipped

hollow dawn
slender nymph
sour fulcrum
#

ye

rich adder
# hollow dawn I have never used lerp before how can I use it when crouching and standing back ...

there are literally dozens of tutorials . this shows proper lerp
https://www.youtube.com/watch?v=-XNm7dPVVOQ

Welcome to part 4 of this on-going first person controller series, int this episode we're going to be covering how to crouch and stand effectively while also amending our movement speed WHILE we're crouching and also taking into consideration any obstacles above us before we stand back up!

Join me and learn your way through the Unity Game Engin...

▶ Play video
verbal dome
#

Instead of capsule.height = newHeight; you would Mathf.Lerp capsule.height towards newHeight

#

Or MoveTowards

slender nymph
#

👆 also i'd recommend using MoveTowards if you are changing the scale or whatever rather than Lerp so that you don't have to care about how much time it takes and just need to have the speed you want it to take

rich adder
#

You also need to adjust the center offset while you do that

hollow dawn
#

I'm soo loving the new input system, shocking how easy they made it to add controller support.

green copper
#

The exact same shader is applied to the brick wall, the placard, and the telegraph

the telegraph has the unlit shader in the first image and the same Lit shader as everything else in image two

Any idea why it's filled with the Light of God?

green copper
#

Oop, right, will move it

rocky canyon
#

for me it was b/c the object was scaled to 0 on one axis

#

and then it made it turn into w/e that is

sterile radish
#

hi, my script below shakes the camera by moving it in random spots in a square for a given period of time. however, it shakes more violently if the camera is more zoomed out. how can i fix this so that the camera shakes at the same inputted strength regardless of how zoomed in it is?
https://paste.mod.gg/gykqbtrtpkwk/0

rocky canyon
# rocky canyon

still cant explain what im seeing ^ but atleast i figured out how to replicate it

green copper
#

thank you!

#

I didn't notice because it was a sprite but the Z scale was zero!

rocky canyon
#

ya, took me a minute to figure out why it was happening myself

#

thought it had something to do with post processing.. but it seems it happens regardless if u have post processing toggled on or off..

#

or the skybox and every other combination.. (didn't matter)

#

Back at Unity: "Hey guys! I got an idea.. Instead of showing a console log or something letting the user know they've accidently scaled their object to zero.. lets instead have the object emit a God Ray that blows out the user's entire screen!"

verbal dome
rocky canyon
#

Obviously thats a less likely reason.. but its fun to think about 😄

verbal dome
#

Resulting in a NaN/super bright (or dark) pixels

rocky canyon
#

that's probably correct

sharp bloom
#

Shouldn't this prevent "null reference" error?

#

I could have sworn I have done it like this before

eager elm
sharp bloom
#

Shouldn't be possible

polar acorn
#

What line has the error

sharp bloom
#

Ah nevermind I had forgotten the script in some random place in my scene

#

That was the instance that was giving the error

#

lol

mental rock
#

I've made a very simple test platformer and I've only just noticed that the FPS drops significantly when my player is in motion... is there a usual culprit for this?

sharp bloom
#

How are you moving your character?

#

Something is probably just getting called way more often than expected

jolly moat
#

I have an animation event on the last frame of my player's swing animation. Most of the time it fires the FinishSwinging() perfectly, but occasionally it will not call that func. The code looks fine and I can swing like 80 times before the anim parameter isSwinging gets set to true and then never gets updated again. FinishSwinging() is what sets isSwinging back to false.

It seems like the problem has been narrowed down to the anim event function. What can I do about this?

rocky canyon
mental rock
rocky canyon
#

so say u shake the camera 1 unit when ur zoom level is default..
so lets say u then zoom out 2x as far.. to make it look the same you'd shake the camera .5 units

mental rock
#

I'm going to try experiment a little

sharp bloom
sharp bloom
jolly moat
sharp bloom
#

StateMachine comes with predefined events like OnStateExit, OnStateEnter etc.

rocky canyon
sharp bloom
#

I feel your pain with the collision problems

mental rock
jolly moat
#

Thank you @sharp bloom and @rocky canyon

mental rock
sharp bloom
#

It's bc the math involved in that is quite complicated

#

But I'm talking about these things here

mental rock
#

isnt that for dynamic rigidbodies?

rocky canyon
mental rock
#

i should mention that its a 2d platformer and i'm wanting to have complete control over movement

sharp bloom
#

Oh right, so you're not using physics

mental rock
#

yea

#

is my only hope to somehow improve the effiency of the raycasts?

rocky canyon
# mental rock i should mention that its a 2d platformer and i'm wanting to have complete contr...

https://www.youtube.com/watch?app=desktop&v=3sWTzMsmdx8&ab_channel=Tarodev this guy helped me a ton getting a 2d platformer to feel good

Source & game: https://github.com/Matthew-J-Spencer/Ultimate-2D-Controller
Extended source: https://www.patreon.com/tarodev

Learn how to build an amazing player controller.

This Unity character controller is built using custom physics and incorporates all the hidden tricks to make it feel amazing. 2D player controllers can be difficult to get ...

▶ Play video
rocky canyon
#

i used it to reverse engineer it..

sharp bloom
#

So that they only check for certain objects like walls etc.

rocky canyon
#

once you have that information in hand.. then continue

sharp bloom
#

Ye code would be nice

#

Trying to learn this stuff myself

rocky canyon
#

aren't we all 💪

sharp bloom
#

One of the dumbest performance issues I had was caused by my mouse's extremely high polling rate

#

Spent a quite while trying to figure out that

rocky canyon
#

i hate that ur mouse's DPI is independent of the game-engine..

#

i'll accidently toggle mine to a higher speed and it'll destroy the feel of my platforming

sour fulcrum
#

i mean mouse dpi is independent of games 😛

rocky canyon
#

and i tried to write some code to compensate for it.. but apparently you can't get the DPI from ur mouse in unity

rocky canyon
#

lol

sour fulcrum
#

I think your trying to fix a problem that doesn’t really exist

sharp bloom
#

I mean don't games just have like "mouse sensitivity" setting

#

Just a simple multiplier

sour fulcrum
#

usually at best it’s handled by mouse sens yeah

rocky canyon
#

nah.. never had an actual problem.. other than my fat finger pressing my mouse button unknowingly..

#

it was more of me trying to see if i could..

#

and the experiences along the way

#

lol

#

i just never know when to quit lmao

mental rock
# rocky canyon https://www.youtube.com/watch?app=desktop&v=3sWTzMsmdx8&ab_channel=Tarodev this ...

https://github.com/Matthew-J-Spencer/Ultimate-2D-Controller/blob/main/Scripts/PlayerController.cs damn is this really all you need for collision detection and movement?

GitHub

A great starting point for your 2D controller. Making use of all the hidden tricks like coyote, buffered actions, speedy apex, anti grav apex, etc - Matthew-J-Spencer/Ultimate-2D-Controller

sharp bloom
#

Ye it uses raycast masks

#

But honestly they aren't even that expensive (raycasts in general I mean)

rocky canyon
#

if you can make it work.. and make it solid.. i say why not

#

its usually all about how cheeky you can be behind the scenes and what u can get away w/ to keep ur game performant

#

but also fun and visually engaging

rocky canyon
mental rock
#

i must be doing something horrendeously wrong then to have it lag my game so much 😭

rocky canyon
#

^ bottom panel.. Find your Hiearachy and after finding a decent spike you can pause/click the spike and investigate

#

PlayerLoop will show all the scripts that are running and how long they're taking and how much garbage they're creating

mental rock
#

I'm actually really confused now

#

I was just playing the game in-editor, and it was reaching an average of around 14ms main while i was moving around

#

but then suddenly it dropped down to 4ms

#

and stayed that way

#

I stopped the game and restarted and its still only 4ms(???)

rocky canyon
#

interesting

mental rock
#

is it the overhead of the editor?

rocky canyon
#

not sure.. the more editor thats exposed the more it'll slow the game..

#

for example if u test w/ a maximized game view.. it'll play alot faster than if u play in a tiny docked window

mental rock
#

trust me i only have an incredible, barebones level right now

#

im mostly just trying to refine movement

rocky canyon
#

disable ur movement code or disable the player and then test..

#

see if its still cooked..

#

if it is its not the movement code.. but if it clears up.. then u can be sure that it is

mental rock
#

like i said the fps is fine right now

#

i dont know if a game as barebones as this should take up 4.5ms though

#

idk what the baseline is, with all the overhead considered

rocky canyon
#

no..

mental rock
#

i see

rocky canyon
#

thats not right at all..

mental rock
#

what is it typically lmao

rocky canyon
#

a smaller scene usually runs at like 500+ fps

mental rock
#

oh dear

#

doesnt really explain why it went up to 13ms while the player was moving earlier though

#

very strange

#

when the player is still, its still 4.5ms average also

rocky canyon
mental rock
#

i suppose the 13ms was a freak incident until I catch it happening again but if a game like this should be running at 500fps, I'll have a look to see why

rocky canyon
#

this scene is playing around 100 fps w/ movement, enemy movement, post processing, particle effects, animations, music etc etc

mental rock
#

damn

#

im getting about 230 average

rocky canyon
#

well.. thats not too bad..

mental rock
#

it wouldnt be too bad if it was also a fully fleged game lol

#

but its literally just that barebones scene with no special effects

#

i can only assume its my poor use of raycasts for collisions

rocky canyon
#

i used to never pay attention to the FPS until it was i started building bigger levels and then i'd notice it was really low.. like 30fps.. and then it was too late to figure out what it was that was causing it..

#

i would have to restart.. that was years ago.. now i pay attention to teh FPS like everyday

mental rock
#

yeah thats how im feeling rn with how much i have in code

rocky canyon
#

after i implement something i'll look

mental rock
#

im very beginner so i dont know the proper practices

#

i wasnt expecting to get very far so i didnt really set any good baseline either

rocky canyon
#

it got soo bad i built my own frame-counter with a little bar that ping-pongs back and forth..

mental rock
#

right now i have 2000 lines of code in my PlayerController.cs which is literally the only significant script

rocky canyon
#

if the bar doesn't sync up with the Timer something is wrong.. and i instantly stop and go look thru my code

mental rock
#

it handles everything except audio and camera movement

#

does stacking everything into one script effect fps also

rocky canyon
#

its only after a few trial and errors until u start to get the feel for it

rocky canyon
mental rock
#

yeah ive been trying to compartmentalise everything slowly but its been proving quite an issue

#

im wanting to have enemies and other entities so im going to try move everything that a living entity would have (movement features, collision detection, etc) into a script that the player and enemies can both inherit

#

somewhere along the line, the player starts to just fall through the floor

#

i just stopped and restarted the game and now its 9ms

#

im so confused

rocky canyon
#

thats no beuno.. (make the floor a big cube) j/k thats just a band-aid fix lol

mental rock
#

oh i did just enable deep profiler, that probably didnt help with the increase in ms lol

rocky canyon
#

you can get a decent baseline for your PC by running an empty scene (one of the Create New Scene ones) w/ just a camera and a light

#

and then go from there

mental rock
#

thats a good point, i'll go try that now

#

if its something like 1000fps ill cry

rocky canyon
#

mines 515 😈

mental rock
#

lmfao

#

I guess it really was just an incredibly odd coincidence

#

thats.... annoying

#

good job im getting a whole new PC on friday

sterile radish
# rocky canyon so say u shake the camera 1 unit when ur zoom level is default.. so lets say u ...

hi, i tried to implement this but i got the same issues so i think im doing it wrong.
the default size of the camera is 5
the scale factor is just the current size of the camera divided by 5 (so if the curr size was 10 the scalefactor would be 0.5)
however, this isn't working for me and the issue still persists. why is this? here is my code:
https://paste.mod.gg/hyyfbyplnzwb/0

mental rock
#

another restart and its back to lagging when the player moves

#

so confusing

#

-# and its gone again

sharp bloom
#

A good rule of thumb that I learned in university is you should be able to describe what the class does in one sentence

mental rock
#

the sentence in question

#

oh

#

lmao

#

i should've guessed

sharp bloom
#

I have those massive cs files on some of my older projects and I cringe every time I look at my old code

granite ore
#

Hey!
I'm looking for tutorials or examples where you create small interactive tasks attached to 3D objects.
For example: dragging the mouse over a surface to "clean" or "scratch" an area, cutting the top off a soil bag and pouring it into a pot, or any mini-tasks where you interact directly with objects using the mouse.

Does anyone know any good tutorials, assets, or tips for building these kinds of simple object-based interactions in Unity?

queen adder
#

i got here circle collider 2d and in the cube to and for some reason they wont collide the circle and the cube

frosty hound
#

You have no rigidbody on either of these objects?

queen adder
#

do i need to have one?

frosty hound
#

Rigidbodies are what actually handle the physics of an object

queen adder
#

oh oaky like i just wanted to make a shooting system bc am new and practicing and tried to see if my bullet work and i dont really get it why need rigidbody on it but thanks 🙂

frosty hound
#

What part of it don't you get?

queen adder
#

like why does it need to handle like if just have the box collider

#

i dont really needed any physic

frosty hound
#

When two things collide, that is called physics.

queen adder
#

oh lol okay yeah am dumb

proper needle
#

I'm trying to save game data, but for some reason the folder is being denied

teal viper
proper needle
#

i tried to run as administrator

#

that didnt work

teal viper
#

Well, a simpler fix would be to not write to the users folder. Aside from that, I'm not sure.
How are you creating the path? Or is it just hardcoded/selected manually?

proper needle
#

i followed a yt tutorial

#

bc i suck at unity

teal viper
#

Well, did you not understand the code?

proper needle
teal viper
#

You should read and understand the code fully.

#

Then we can talk.

proper needle
#

i didnt hardcode it

#

its selected automatically

#

i cant change it or anything

#

@teal viper

teal viper
#

I don't see it in your screenshots

proper needle
#

the beginning

teal viper
#

Share the !code properly:

eternal falconBOT
proper needle
#

the this.datadirpath=datadirpath

#

same with datafilename

#

cs

teal viper
proper needle
#

whatever

#

it works tho

teal viper
#

That's not correct way to share code. Check the big !code blocks part.

eternal falconBOT
proper needle
#

bruh it does the same thing

#

when i use pastemyst

#

this is what i get when i use them

teal viper
proper needle
#

when i use one of the large code block things it makes a text file

#

like it doesnt do anything different

teal viper
#

Your code is pated as a file

teal viper
proper needle
#

oh i share link

#

here

teal viper
# proper needle https://paste.mod.gg/szhvjrrdlxdw/0

Great, but it's still the same issue: this is just assigning the value in the class. I want to see where you pass it in.

    public FileDataHandler(string dataDirPath, string dataFileName) 
    {
    
        this.dataDirPath = dataDirPath;
        this.dataFileName = dataFileName;
    
    }
#

Share the code where you create the FileDataHandler instance.

proper needle
#

i think this is what ur talking about

#

@teal viper u still online?

teal viper
proper needle
#

yes

teal viper
queen adder
#

hi so i tried to make a script that follow the player like for zombie am testing on a cube with rb and boxcollider and for some reason i can just push it away and it will be gone forever anyone know how to fix
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class ZombieScript : MonoBehaviour
{
public float moveSpeed;
public GameObject go;
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
    if(go.transform.position.x > transform.position.x)
    {
        transform.position = transform.position + (Vector3.right * moveSpeed) * Time.deltaTime;
    }
    else
    {
        transform.position = transform.position - (Vector3.right * moveSpeed) * Time.deltaTime;
    }
    if(go.transform.position.y > transform.position.y)
    {
        transform.position = transform.position + (Vector3.up * moveSpeed) * Time.deltaTime;
    }
    else
    {
        transform.position = transform.position - (Vector3.up * moveSpeed) * Time.deltaTime;
    }


}

}

proper needle
#

it does it automatically

teal viper
proper needle
teal viper
#

I can't help you much if you don't know the very basics of working with unity.

eternal falconBOT
proper needle
#

yeah i think so

teal viper
proper needle
queen adder
# teal viper !code

oh okay sry also i thinked i fixed it i put the mass of the "zombie" to 10000

proper needle
#

is this what ur talking about

teal viper
#

Did they not show how to use the script?

proper needle
teal viper
proper needle
#

In this video, I show how to make a Save and Load system in Unity that will work for any type of game. We'll save the data to a file in both a JSON format as well as an encrypted format which we'll be able to toggle between in the Unity inspector.

IMPORTANT: For WebGL games, because WebGL can't save directly to a file system, a different meth...

▶ Play video
#

This was the tutorial i used

#

imma check back in a few mins

teal viper
eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

proper needle
#

ah i see

#

lemme check

teal viper
proper needle
#

IT WORKS

#

thanks

sacred cradle
#

why can i not do this?

meshRenderer.material = new Material();
rocky canyon
sacred cradle
#

how do i add a shader?

sacred cradle
#

thanks

#

how do i find it from recources

rocky canyon
#

no clue 😬 lol

sacred cradle
#

alright

rocky canyon
#

did u read the Description?

#

do you need to create a new material?

sacred cradle
#

yes

rocky canyon
#

could u not create a mock material and just modify that

sacred cradle
#

true

#

good idea

rocky canyon
#

that way it'd be easier to reference

#

just a thought

green jackal
#

Not sure if this the proper place to ask but I'm having an issue where the rotation of my player object is incorrect, wondering if anyone can help?

wintry quarry
green jackal
#

Of course, I'm essentially making a game with objects similiar to diep.io but in 3d, basically a puck with a gun, before clicking on play it sits in the scene just fine like so

wintry quarry
green jackal
#

Custom 3d model imported from blender

wintry quarry
#

you need to go back and re-export it with the proper orientations for Unity

green jackal
#

Gotcha, thank you

wintry quarry
#

Search for Blender Unity Export settings to see how people do it

green jackal
#

Orientation has been fixed, or at least the axis' point in the right direction, but the issue persists

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour{

    [SerializeField]
    private float movementSpeed; 
  
    void Start() {
        
    }

    void Update(){
        HandleMovementInput();
        HandleRotationInput(); 
    }

    void HandleMovementInput ()
    {
        float _horizontal = Input.GetAxis("Horizontal");
        float _vertical = Input.GetAxis("Vertical");

        Vector3 _movement = new Vector3(_horizontal, 0, _vertical);
        transform.Translate(_movement * movementSpeed * Time.deltaTime, Space.Self);
    }

    void HandleRotationInput ()
    {
        RaycastHit _hit;
        Ray _ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(_ray, out _hit))
        {
            transform.LookAt(new Vector3(_hit.point.x, transform.position.y, _hit.point.z));

        }
    }
}
#

This is my code and the result when I hit play

wintry quarry
wintry quarry
wintry quarry
#

Is this a singular object, or are there children? Also is your tool handle rotation set to local?

sturdy flicker
#

yo i rlly need some help. years ago i wanted to develop a game, so i looked up for lots of tutorials on unity and c#. but i felt like i was learning nothing. i could follow the tutorial and understand it quite well, but when trying to apply it, i blanked. so i laid it off bc it got hella confusing. a week ago i was looking for some old files and i saw my old pixel art assets, so i tought i might as well give coding another go. but again, i feel so frustratad because i really cant see the way trough it. if anyone could please help me, or give some insights or guidance on where to start, how to actually learn to learn, i would be really grateful 🙂

wintry quarry
#

I would say... try something different from how you used to do it

green jackal
wintry quarry
#

If it's set to global you're not actually seeing your object's rotation

#

you're seeing the world axes

sturdy flicker
wintry quarry
green jackal
eternal needle
wintry quarry
wintry quarry
#

keep trying 👍

sturdy flicker
#

should i buy a book or smt

wintry quarry
eternal needle
# sturdy flicker should i buy a book or smt

you shouldnt need to buy anything for this, even if its an online book or course. most of what ive seen from online courses have been pretty much worse than the free content that exists

sturdy flicker
#

i really felt like i was the problem lol

grim jungle
thorn holly
#

Spent hours today trying to figure out what was wrong with my procedural generation when it was integer math 🤦

#

(Rounding down to zero)

wintry quarry
#

Learning to debug more efficiently can cut those hours down

thorn holly
#

Yeah I need to remember to start at the source and work backwards to where it goes wrong

wintry quarry
#

you can also use a technique called bisection. Where you start from the beginning and the end, and work your way to the source of the problem by cutting the problem space in half at each step. It's like a binary search for debugging.

thorn holly
#

Oh smart

#

So like log at the midpoint (say it’s m), if it’s an expected value log at the midpoint between m and the end, otherwise log at the midpoint between start and m?

wintry quarry
#

yep

worn spade
#

anyone know how i can avoid this?

#

my normal fix is urp lit for rendering, but doesnt work all the time and it becomes white, whats the work around?

wintry quarry
#

not the shorts

worn spade
#

all white

wintry quarry
#

looks correct

#

Anyway I didn't want to see the preview

worn spade
#

pink/white by default

wintry quarry
#

I wanted to see the inspector

worn spade
wintry quarry
worn spade
wraith condor
#

How do I create a menu bar in unity's ui toolkit?

#

I am not talking about a main menu, I am talking about a menubar like in windows, mac and linux

wraith condor
#

ok I posted it in there

livid arch
#

is there something i need to do for it to be recognized?

#

might be following an outdated tutorial

teal viper
#

You're probably using it in a wrong place.

#

Which is what "does not exist in the current context" usually imply.

rich adder
#

made into a field UnityChanLOL

eternal needle
#

think about the logic you'd be doing. if the distance cant go under 0 lets just say its 1 for this case
if ( 1 < -1), will this ever be true?

queen adder
#

Oh yeah I just realized, no.
My bad, should of thought more

eternal needle
tidal quest
#

Can any of you help me with trying to play audio based on a player's location?

hexed terrace
#

!ask

eternal falconBOT
eternal needle
tidal quest
#

Any Unity experts around who are willing to commit into looking into my problem, whatever that may turn out to be, even if it's not actually related to Unity or if someone who doesn't know anything about Unity could actually answer my question?

#

Basically im trying to make audio play based on the players location withinthe world, ive looked at numerous tutorials online ajnd can't find anything that will help me, though on paper it seems an easy thing 🙂 sorry, for asking the question poorly the first time.

eternal needle
tidal quest
#

also im very new to this, so again im very sorry if i've asked poorly or come across the wrong way english isn't my first language !!

#

do you have any good youtube recomendations for audio? Ive tried a couple and don't think their methods will work the best for my game. 🙂

eternal needle
tidal quest
#

if you have the time, i can dsicord call and show and descbbe what i'm tryig to do, as i really am poor when it comes to typing english XD

eternal needle
eternal needle
tidal quest
#

okay thank you !!

naive pawn
tidal quest
#

bruh im still stuck

#

let me try screen record and send over, if that is okay?

#

I FIXED IT
YESSSSSSS HOLY CRAP

sour cape
#

anyone know why i get this sort of burst of sound assigning an audio clip in unity, even with playonawake off, its ruining the experience of the game

proud glen
#

is there any better way to do player movement

frosty hound
#

What kind of question is that?

proud glen
proud glen
frosty hound
#

Sure is up there. You need to identify what you think you don't like about your character and how you would want to fix it before anyone can even begin to advise on it.

proud glen
#

and eliminating bhopping

frosty hound
#

All you did here was throw up some presumably working code (given that you likely got it online) and expect someone to answer your vague question.

proud glen
#

well ive got playermovement.cs now i need to fix bhopping

#

limit the jumping*

proud glen
#

sorry if that sounded rude

#

i want to eliminate bhopping

frosty hound
#

Create a counter, which increases by 1 everytime you jump. Before allowing a jump, check if it's less than the number of jumps you allow.

Reset the counter to 0 when you are on the ground.

proud glen
#

thats a silly question...

#

sorry im being stupid

#

ill stop

frosty hound
#

Where you're actually doing your movement.

honest haven
#

ok so if i add a recipe i.e for items and the make and canel pops up and i press cancel with my mouse they all go back. but if i use a controller to press cancel the first item does not go back and remains in the first slot of the crafting slots. why would it only work for the mouse ? https://paste.mod.gg/fdmsmlqakmhy/0

lethal orchid
#

is this a place where i can ask help, or is there another channel?

queen adder
#

anyone can help me for some reason its giving me an error and idk what i did worng

honest haven
#

you need assign it.

queen adder
#

yeah i did

honest haven
#

ls is empty

queen adder
lethal orchid
#

how would i get this error done? there's no clear place on where i can fix this

#

its only telling me this, but there is no "settings" in edit

honest haven
queen adder
#

i relized what was wrong i had a box that needed the money assigned sorry my bad

naive pawn
lethal orchid
#

i see "project settings" but not "settings", also in there there is no "input" but "input manager"

#

and in there i see fire1 fire2 and fire3, but thats mouse 1 2 and 3, but they are configed and the error is saying fire with no number

hexed terrace
#

are you using the new input system or the old

lethal orchid
#

im really new to this, all i know is the version, thats why im here asking for help

lethal orchid
#

ok, so why is there 3 different fire thing but im still getting errors

naive pawn
naive pawn
lethal orchid
#

my problem is that i dont see a "fire" and i dont know what im supposed to do

#

or do i change fire to fire1 in the code?

hexed terrace
lethal orchid
#

see now its like its pressed all the time, its the !thing_i_wanted_to_happen

#

so like in a better direction, but not the "correct" thing

hexed terrace
#

show your !code

eternal falconBOT
lethal orchid
#

just ctrl + a + ctrl + v?

hexed terrace
#

eh? read the bot msg.

lethal orchid
#

which one do i do

hexed terrace
#

Which one what?

lethal orchid
#

links to services ig?

hexed terrace
#

just use whichever link you want

#

that's why there's a list and not a single one, or a big msg saying "use this one"

lethal orchid
#

so all work nearly the same

hexed terrace
#

what you currently have, should fire a single bullet when your mouse button is down

lethal orchid
#

yes, but the things i "apparently" have but dont work is mouse detection and following + firing on click

hexed terrace
#

you don't need any mouse detection, fire1 is bound to mouse1

#

in your input settings in project settings

#

following + fire on click

explain what this is better

hallow acorn
#

hey does somebody know why i suddenly cant reference values from my animator even tho it worked perfectly yesterday?

eternal falconBOT
verbal dome
#

Wdym "reference values from the animator"?

hallow acorn
verbal dome
#

That code alone means nothing so you'd have to show more

hallow acorn
#

but it worked with the parameter i tried it yesterday with

polar acorn
hallow acorn
#
anim.speed = 1;
anim.idling = true;```
the first line works, but for the second i get the error"animator does not contain definition for  ´idling´ " even tho the value exists like this in my animator tab
verbal dome
#

This never worked. You are confusing this with Animator.SetFloat etc.

hallow acorn
#

ohhh i made an variable named speed but the code used another animator variable?

#

that makes sense thanks

torn jacinth
#

can anyone help how do I get the component of light2d intensity in script?

private Light2D globalLight;

void Start()
{
globalLight = GetComponent<Light2D>();

}

IEnumerator TriggerBlackout()
{
yield return new WaitForSeconds(3);
Debug.Log("Blackout Triggered!");
globalLight.intensity = 0;
}

hexed terrace
#

share !code correctly

eternal falconBOT
hexed terrace
#

and what's wrong with what you've done?

torn jacinth
#

when i'm starting the game the light intensity doesn't set to zero even the blackout is triggered

polar acorn
torn jacinth
#

in the update()

private bool blackoutStarted = false;

if (blackoutTrigger && !blackoutStarted)
{
blackoutStarted = true;
StartCoroutine(TriggerBlackout());
}

torn jacinth
#

yes this works Debug.Log("Blackout Triggered!");

but it doesnt set the intensity to 0

polar acorn
#

Whether or not it stays at zero, or if that's the light you're expecting to set, is a different story

#

Maybe show the full !code of the script

eternal falconBOT
livid arch
torn jacinth
polar acorn
livid arch
polar acorn
polar acorn
livid arch
polar acorn
#

A variable exists until it reaches a } that closes the scope it was created in

#

So you make a variable inside that if statement that ceases to exist when the if statement ends

livid arch
#

doesnt the public make it so it can be found in every scope?

polar acorn
#

Every scope inside the class scope can use it

polar acorn
#

unless that scope creates another variable with the same name

#

which you have done

#

So, if you don't want to create a new variable inside that scope, don't do that

#

Change the one that already exists instead

livid arch
hollow dawn
#

I was wondering how I would add lerp to my handling crouch? right now when I crouch it snaps to the new height same when going back to standing which I don't really like I want it to be smooth. I have never used lerp before so how would I do it in the most "simplest" way?

polar acorn
verbal dome
rich adder