#💻┃code-beginner

1 messages · Page 821 of 1

dreamy lance
#

also side question how would i set the "front" for the character so wasd follows the player moddle not the facing of the camera

#

thx

slender nymph
dreamy lance
#

oh ? u dont need to tell it wich side of the player modle is farward ?

slender nymph
#

you just rotate the movement direction appropriately

grand snow
#

^ We can rotate user input as needed (e.g. using the players rotation)

dreamy lance
#

new issue ive never had before my capsule colider is making my capsule flout ???

slender nymph
#

is that a child of the model or is it the parent?

dreamy lance
#

look like this the commponets are attached to the parent not the mesh its self

slender nymph
#

okay so that is the parent of the mesh. in that case make sure that you don't have any collider on the mesh as well and also check the collider for the ground object. you can also enable gizmos in the scene view to actually view what it looks like in the scene

dreamy lance
#

my only other colider in the scene is a flat plane lol

#

could it be the camera ?

#

also tested witht he box colider turned off ??? and still did it

#

AAH found it

#

thank you

#

that was scuffed

#

it was a player controler component cuasing problems

slender nymph
#

if you mean a CharacterController, then yes don't mix that with the Rigidbody

dreamy lance
#

lol

#

i jsut watched one of the most usless tutorials on the planet didnt relize i left that there

waxen adder
#

I've noticed intellisense is taking a painfully long time to initialize when opening a new script. Like, sometimes it takes 30 seconds for errors to pop up. Anyone else get this?

teal viper
#

Can happen in bug projects. What ide are you using?
And is that 30 sec after the script is compiled or including that time?

waxen adder
teal viper
#

Are you creating it via unity or the ide?

waxen adder
#

The script? Just opening it from unity. These are scripts being brought over from another project, so maybe that's something?

teal viper
#

Technically, unity needs to compile the script and add it to the csproj/sln files for ides to see them as real project scripts.

teal viper
waxen adder
#

Yeah exactly that. I have two projects open, and am dragging a script from one editor to the other (didn't even think that was going to work but it did lol)

#

On another note, has anyone ever looked at their code and gone "bruh, why did I make this so convuluted?" That's kind of me right now XD

sour fulcrum
#

Thats step one to making it good

vast matrix
#

For some reason this code is rotating the gameobject along the wrong axis and I have no idea why: ```using UnityEditor.ShaderGraph.Internal;
using UnityEngine;

public class PlayerCam : MonoBehaviour
{
public float sensX;
public float sensY;

public Transform orientation;

float xRotation;
float yRotation;

private void Start()
{
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
}

private void Update() 
{
    //Get Mouse Input
    float mouseX = Input.GetAxisRaw("Mouse X") * sensX;
    float mouseY = Input.GetAxisRaw("Mouse Y") * sensY;

    yRotation += mouseX;

    xRotation -= mouseY;
    xRotation = Mathf.Clamp(xRotation, -90f, 90f);

    // Rotate Cam and Orientation
    transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
    orientation.rotation = Quaternion.Euler(0, yRotation, 0);

}

}

teal viper
teal viper
vast matrix
teal viper
#

There's not much we can do about it unless you start providing more details/context.

vast matrix
#

Okay after a little bit of testing I realize now that the code only works in certain scenes

gilded harbor
#

Not sure if i'm doing this an efficient way, but i'm trying to have my game be able to read which 1 of 4 materials have been randomly selected to a gameobject. Though I don't fully understand what i've written, I have the random color changer working as intended, how do I make it so the game can actually detect which color has been selected? (preferably using my currently un-used bools)


    private Renderer ColorRenderer;

    public bool isblack;
    public bool iswhite;
    public bool ispink;
    public bool isyellow;
    private void Start()
    {
        ColorRenderer = GetComponent<Renderer>();

        if (PossibleColors != null && PossibleColors.Length > 0 && ColorRenderer != null)
        {
            ChangeToRandomColor();
        }


    }

    public void ChangeToRandomColor()
    {
        int RandomIndex = Random.Range(0, PossibleColors.Length);

        ColorRenderer.material = PossibleColors[RandomIndex];
    }

}
sour fulcrum
#

What do you mean by you don't fully understand what you've written

gilded harbor
#

I found out how to make the colors switch through google, i'm not very experienced in coding. It works, I just don't fully understand why it's working.

#

I loosely understand it, I think my current understanding of how arrays/libraries function is still lacking a bit. I just started learning to code a month ago

rich adder
#

what is even the point of those bools

#

also the method is public, if any other scripts call it and somehow ColorRenderer is null... you will get null ref anyway or if array is empty

final trellis
#

why is my regex only detecting the dark blue selection, but ignoring the light blue?

#

( i want it to do both )

brisk ibex
#

Where does target come from?

#

My LS doesn't seem to recognise it (I assumed it was a class member), just unity inject it directly into the method scope itself?

#

Or is my LSP setup just not detecting it?

sour fulcrum
#

inheritance

brisk ibex
#

So it is a class member and my LS isn't detecting it

#

weird

#

thanks

#

yeah that's on my end, I can see it in the docs 👍

sour fulcrum
#

in your defense when i googled it to double check it only gave me the api post for Unity 5.3's version for whatever reason lol

final trellis
sour fulcrum
#

(people here might not be experienced with regex)

naive pawn
#

do you need them to be detected separately?

final trellis
final trellis
naive pawn
naive pawn
#

lazy means it'll match as little as possible first, and it'll backtrack to consume more if it can't make a match

final trellis
#

now its not detecting the 2nd part

naive pawn
#

ah, your regex is not global.

final trellis
#

oh, there, but how do i make the first match go up until the next match?

naive pawn
#

perhaps make the regex end at a )?

#

not sure what exactly the goal is

#

you could also make it stop at the next comma or the end, like (?=,|$) but that might not work if the match is in the middle of another string

#

or maybe (?=\))

#

what's the overall goal?

final trellis
# naive pawn not sure what exactly the goal is

trying to take a string input, see if it has R(stuff1, stuff2), then extract it (which i've done)

my current goal, is to extract stuff1 and stuff2, which could be literally anything
the example input is R(R(0, 500), Y), to make sure the operations take nesting into account ( since stuff1 is also a R(stuff1, stuff2) thingy )

naive pawn
#

you probably want to not use matches then, since matches can't overlap
you could use capture groups instead

c# doesn't support recursive regexes, barely anything does, rip..

#

recursive nesting is kinda a hard thing to do in regex

naive pawn
#

if you can make the assumption that R( always begins one of these and they're always valid, you could write a parser relatively easily without backtracking

#

though the difficulty would depend on what exactly is allowed inside

final trellis
#

and then once it ends, extract the substring

#

and perhaps do something similar for the ,

sour fulcrum
#

It’s your game so if you think it’s what you want by all means continue but could be worth considering if players would want to do these typed expressions in the first place? I wonder if some sort of drag and drop / puzzle piece kinda system might be easier for you and them (im imagining stuff like scratch coding or human resource machine)

#

just throwing it out there no judgment however you go

final trellis
naive pawn
#

oof if it's user input then it's gonna need error handling too...

rigid phoenix
#

Hey guys i created a code and i can't post it github

#

How to post it

naive pawn
#

you're having problems with pushing to the repo, or what exactly?

#

or if you want to ask about code, you could use pastebin sites as well

feral mango
#

who up

#

need sum help rq

verbal dome
feral mango
#

trying to make this shotgun pickup system but its not working

naive pawn
#

gonna need to give some more info than that

feral mango
#

hold on pasteofcode loading rn

#

this is shotgun.cs

naive pawn
#

right no you have to say how it's not working

feral mango
#

literally nothings happening

#

like i start the scene go up to it and press e its like i never typed out the code in the first place

verbal dome
#

Did you add the script component to any object

feral mango
#

yea

#

on the object

naive pawn
#

the script you linked isn't checking for E

feral mango
#

thats the shotgun script

#

this the pickup script

naive pawn
#

...link the one with issues, man

feral mango
#

one refrences the other yall ain give me time to send the links 😂

naive pawn
#

you were supposed to do so before coming to ask, so all your info is consolidated in a single message

feral mango
#

ok

#

mb

naive pawn
#

do some debugging then, see which ifs are being reached

feral mango
#

so figure it out myself

#

ok

naive pawn
#

you don't seem to be changing hasBeenPickedUp anywhere

naive pawn
# feral mango so figure it out myself

...well, yes, that's what debugging is.
there's multiple steps there, you gotta figure out which step isn't working. we aren't sitting behind your shoulder, we can't do this part of debugging for you

once you identify which step isn't working, we can go from there

feral mango
#

If hasBeenPickedUp never gets set to true, the gun would never activate so im going to just figure it out myself

naive pawn
#

you did say nothing is happening so i assume Pickup is never being called, as that would cause some stuff to happen

feral mango
#

the problem is i cant figure out why

naive pawn
#

we can help you figure out the why. right now you need to figure out the what

#

add Debug.Logs in each if, see which are being reached and which are not

feral mango
#

yea give me a min lol

naive pawn
#

(also make sure you don't have errors hidden in the console tab)

feral mango
#

true i did disable errors because i turned off navmesh for testing

feral mango
#

but i cant use gravity so im not sure how i can make it a regular world object

verbal dome
#

Wdym can't use gravity? You can disable gravity on a non-kinematic rb

brisk ibex
#

Is there any sort of production assert in unity?

#

I know it's a game engine but there's also a lot of people doing non-games who that would benefit lol

keen dew
#

You can configure the asserts to be enabled in builds

brisk ibex
keen dew
#

yes

brisk ibex
#

Thanks

feral mango
#

i fixed it thanks anyway though

fossil sorrel
#

Hi everyone, I have been building an educational mobile game "Tappy mole" for kids, this game teaches kids social etiquettes by performing different fun activities like brushing teeth, eating healthy food, getting proper sleep, keeping clean etc.
One of the features in "Tappy mole" is voice playback system similar to the popular game "Talking Tom" where the game character records the player's voice and then plays it back.
There is once issue that is taking my night's sleep away. that is the recording is triggered by the game audio as well, so sometimes if the game sound is loud the mole records it and plays it back. I have tried many ways but couldn't solve the problem. I’d appreciate any guidance on how to tackle it.

My requirement is that the game should start recording if the loudness has crossed a certain threshold and it must ignore the game audio itself, so the infinite feedback is not triggered.

I have provided my audio input script and a screen recording of the game. in the video you can see that when I pick a soap, it makes a sound and the mole is triggered and starts listening.

thanks

midnight plover
fossil sorrel
obsidian cedar
#

how do i use lookAt in 2D?
so for example, i can make the player move to the mouse

midnight plover
fossil sorrel
midnight plover
naive pawn
obsidian cedar
naive pawn
#

which part exactly?

obsidian cedar
#

assign the up or right vectors

naive pawn
#

assign to transform.up/transform.right, depending on which one is the "forward" of your specific object

midnight plover
#

So things do not get cluttered up

midnight plover
obsidian cedar
naive pawn
#

not sure what you mean by that, could you rephrase

obsidian cedar
#

mm
i think i worded my question wrong from the get go
so i wanted to make a "dash", when on pressing space the player would look at the mouse, move fast to the mouse and then snap back into "normal" mode
i tried using this code, but it had almost the opposite effect

sour fulcrum
#

i dont think that's what you want to dbe doing

naive pawn
#

you could get a direction vector from the current position to the mouse position (after converting to the same space) and set the up/right vector to that

obsidian cedar
#

huh?
-# i am pretty slow, sorry on that

naive pawn
#

i'm not going to rephrase the entire message to be a paragraph long

#

please specify which part you don't understand

#

so i can elaborate on that specific part

obsidian cedar
#

how can ou get a direction vector from two positions?

naive pawn
#

subtract one from the other and normalize it, though for the usecase of assigning to transform.up/right/forward i think it normalizes it for you

#

adding/subtracting a vector geometrically looks like changing the origin
so if you have 2 positions A, B, then A - B looks like moving the origin to B - it's asking what A is from B's perspective, aka the vector from B to A

#

the magnitude of that vector is the distance, and the direction of that vector is, well, the direction

elfin pike
#
    {
        LevelCollection levels = new(new(),new());

        if (unlockedLevels != null)
        {
            foreach (LevelData level in unlockedLevels)
            {
                levels.unlockedLevelIds.Add(level.id);
            }
        }
        
//Add next level IDs
        if (nextLevels != null)
        {
            foreach (LevelData level in nextLevels)
            {
                levels.nextLevelIds.Add(level.id);
            }
        }
        string json = JsonUtility.ToJson(levels, true);
        File.WriteAllText(SavePath, json);
        Debug.Log("Save");
    }
    
    public void Load()
    {
        if (!Directory.Exists(SavePath))
        {
            File.Create(SavePath);
            return;
        }

        string json = File.ReadAllText(SavePath);
        LevelCollection levels = JsonUtility.FromJson<LevelCollection>(json);
        
//unnlocked level
        foreach (int id in levels.unlockedLevelIds)
        {
            if (allLevels.db.TryGetValue(id, out IdObject level))
            {
                unlockedLevels.Add((LevelData)level);
            }
            else
            {
                Debug.LogWarning($"Unlocked level with ID {id} not found");
            }
        }
        
//next level
        foreach (int id in levels.nextLevelIds)
        {
            if (allLevels.db.TryGetValue(id, out IdObject level))
            {
                nextLevels.Add((LevelData)level);
            }
            else
            {
                Debug.LogWarning($"Next level with ID {id} not found");
            }
        }
    }

    void OnDestroy()
    {
        Save();
    }```
#

I havent fixed issue from yesterday. this is presistant singleton and is only one who knows about that file. Still getting IO Sharing violation on path

verbal dome
elfin pike
#

It points at save call in on destroy. In save it points to writealltext

verbal dome
#

Does that happen when you call it from somewhere else, or only via OnDestroy, or both

#

Could put a debug.log in the start of the Save method to see if it's triggering twice or something.

elfin pike
#

@verbal dome Triggered once and works, if load isn't called

verbal dome
#

Didn't answer my first question

#

When Save throws the exception, was it called from OnDestroy or from somewhere else? Look at the stack trace in the console with the exception log selected

#

The exception means that multiple things are trying to read from/write to the file at the same time

#

@elfin pike So close applications that might have that file open, if doesn't work, restart PC

elfin pike
elfin pike
spice burrow
#
using Unity.VisualScripting;
using UnityEngine;

public class TimerAndCheckpoints : MonoBehaviour
{
    [SerializeField] float currentTime = 0f;
    [SerializeField] bool timerRunning = false;
    float numberOfLaps = 0f;
    float checkpointsPassed = 0f;


    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        timerRunning = true;   
    }

    // Update is called once per frame
    void Update()
    {
        if (timerRunning == true)
        {
            currentTime += Time.deltaTime;
        }
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.CompareTag("LapGoal"))
        {
            if(checkpointsPassed >= 10)
            {
                numberOfLaps++;
                Debug.Log("Time: " + currentTime + " secs");
                currentTime = 0;
            }
            else
            {
                Debug.Log("fucked up");
            }          
        }
        if (collision.CompareTag("Checkpoint"))
        {
            
            Debug.Log("went through a checkpoint!");
            checkpointsPassed++;
        }
    }
}```
Hi guys! I'm working on a small top down 2d racing game. It's a school project, nothing crazy. I'm trying to get checkpoints to work, but there's a big problem. I want the checkpoints to be prefabs so i can place them however i want (using the "Checkpoint" tag. Problem is, you could just go across the same checkpoint 10 times in order to pass many enough to finish the lap, and these checkpoints are meant to force the player to go through the whole track. Doesn't add up.
The easy way would be to give each checkpoint an identity so it knows which checkpoint in the order it is and check if its been passed. If it has already been passed, just make it not register anything until the next lap begins. However, i dont know how to do this with prefabs.......
#

TL;DR trying to make checkpoints using prefabs. cant figure out how to check if the player has already passed a specific checkpoint (in order to deactivate it somehow and prevent checkpoint spamming)

#

thanks for any help

keen dew
#

Them being prefabs doesn't prevent you from giving them ids

spice burrow
#

How would I do that?

keen dew
#

But you could for example add a script to the checkpoints that tracks if that checkpoint has been passed or not, and ignore it if it has been

keen dew
spice burrow
#

i don't even know what an id field is lmao

#

i get it tho

keen dew
#

"I dont know how to do this with prefabs" implies that you know how to do it if they're not prefabs

spice burrow
#

yeah

keen dew
#

well do it the same way

spice burrow
#

so i just do it the same way and turn it into a prefab with the script still attached

#

nice

#

chat i forgot how to reference a variable from another script in my script help ✌️

frosty hound
#

Use GetComponent to get the script on the target object. Then with that, you can access any public fields on said script.

rich gate
#

Hey ! I'm omega beginner on unity and i'm trying to make a first person controller camera player, but for some reason nothing works ( i'm sure i did something wrong but i can't understand why ) and when i try to copy a script nothing connects to it ( like some variables don't connect or something ) i'd be sooo grateful if anyone could help me 🙏

naive pawn
#

what do you mean by "connect" exactly?

rich gate
#

For exemple, my " monobehaviour " seems to not be linked the same way since it's not lighting up 😭 i assume lighting up means it works

hexed terrace
#

!vs

radiant voidBOT
# hexed terrace !vs
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

rich gate
#

I only coded in HTML and CSS before so i understand the logic a little bit but now i'm super lost

hexed terrace
#

You need to setup your Visual Studio ☝️

rich gate
#

oh alright i'll try that !

elfin pike
loud coral
#

uhh so just started learning on my own and i got a question so why is there f after the value? float myFloat = 0.58f;

polar acorn
loud coral
rich adder
#

its not a Unity thing

sour fulcrum
#

the reason why we use a f to indicate a float and not a d for double / why we don't just use a double instead of float lowkey comes down to arbitrary decision making stuff for reasons and whatnot

#

it just is what it is

polar acorn
naive pawn
sour fulcrum
#

we use floats, floats need an f

polar acorn
loud coral
#

why though? arent both like same?

rich adder
#

no

polar acorn
elfin pike
naive pawn
# loud coral why though? arent both like same?

no, floats are 32 bits, doubles are 64 bits
floats are "single precision" (hence why the .net type is System.Single)
doubles are "double precision", double the size of floats

there are halfs, quads, and octs too

rich adder
polar acorn
loud coral
#

tysm

sour fulcrum
#

the other two answers are good but just in normie terms for gaming we generally just either use int's for when we need to care about precise numbers and float's when we don't. the value of other number types is far more niche compared to other programming usecases (eg. banking stuff can't use imprecise numbers lmao)

naive pawn
#

you do have to keep width in mind a bit

#

if you need to handle precise integer values in the trillions you can't use an int

polar acorn
#

For most reasonable human-scale numbers float is fine

rich adder
#

idle games notlikethis

polar acorn
#

And since humans are meant to play video games, most video games use human-scale numbers

elfin pike
sour fulcrum
polar acorn
naive pawn
#

-# the other day i saw a video of someone scoring larger than graham's number in opus magnum...
-# (claimed to, at least. i did not watch the full video)

spice burrow
#
   private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.CompareTag("LapGoal"))
        {
            if(checkpointsPassed >= numberOfCheckpoints)
            {
                numberOfLaps++;
                Debug.Log("Lap " + (numberOfLaps) + " Finished! Time: " + currentTime + " secs");
                currentTime = 0;
            }
            else
            {
                Debug.Log("either fucked up the code or i didnt drive thru all the checkpoints");
            }          
        }
       
    }```
do you guys think having it be a OnTriggerStay function would be better? It sometimes doesn't want to register. (it's the checkered board.)
#

and yes i knwo the graphics are misaligned but honestly who cares, I'll fix it later

rich adder
#

how are you moving them

spice burrow
rich adder
spice burrow
#

The car isn't very fast though, so I don't see why it would miss the pad

rich adder
#

you're essentially teleporting by using Translate

spice burrow
#

yeah

rich adder
#

skipping the physics and let it catchup rather then the opposite (let the rigidbody drive the transform)

#

you need to move rigidbodies with their appropriate functions

#

AddForce or set linearVelocity yourself

spice burrow
#

Idrk if i would deem learning that as worth it since it's for a school project

#

I mean, it would help me with future projects I care about more if i learned it now buttt..... idk it seems kind of hard to learn

polar acorn
#

Well, it's the solution to your problem, so you have to decide if this problem is enough of a dealbreaker

#

Or if you can just live with it

rich adder
#

and literally takes like a few minutes.. there isn't anything extra to learn lol

swift crag
rich adder
#

in most cases the direction and speed passed to Translate fits exactly into linearVelocity (minus the TIme.deltaTime since physics has its own time)

#

the only difference is you're use Rigidbody component rather than Transform

shell valve
#

why is this showing rb is not assigned T_T

rich adder
spice burrow
#

right now what I'm doing is that i have 2 variables, one for steering amount and one for movement amount. if statements check what keys are being pressed, and the values of said 2 variables are changed accordingly. afterward, they get passed into the transforms.
at the beginning of the loop, they are cleared again so the car doesnt just keep moving forever

shell valve
rich adder
polar acorn
spice burrow
#

i do understand i could just switch out the movement variable with a similar one for linearvelocity

#

but i dont get how i would handle the turning

polar acorn
spice burrow
rich adder
#

you can technically still use that

polar acorn
spice burrow
#
using UnityEngine;

public class Driver : MonoBehaviour
{
    //creates´variables to be redefined later on.
   float steerSpeed = 0f;
  float moveSpeed = 0f;
float steerAmount = 0f;
   float moveAmount = 0f;
    float grassSpeedReductionMultiplier = 0f;
    float grassTurnReductionMultiplier = 0f;

    //makes another variable used to localize another script later on
    collisionscript collisionChecker;

    void Start()
    {
        //localizes another script containing the collision checkers
        collisionChecker = GetComponent<collisionscript>();
    }

    void Update()
    {
        //resets éverything so the car doesn't keep moving forward forever
        moveSpeed = 0f;
        steerSpeed = 0f;
        moveAmount = 0f;
        steerAmount = 0f;

        //checks if the car is touching grass (variable localized from the collision script) and reduces car speed accordingly
        if (collisionChecker.isTouchingGrass == true)
        {
            grassSpeedReductionMultiplier = 0.3f;
            grassTurnReductionMultiplier = grassSpeedReductionMultiplier * 2f;
        }
        else
        {
            grassSpeedReductionMultiplier = 1f;
            grassTurnReductionMultiplier = 1f;
        }

        if(Input.GetKey(KeyCode.W))
        {
            moveSpeed = 20.0f * grassSpeedReductionMultiplier;
        }
        if (Input.GetKey(KeyCode.S))
        {
            moveSpeed = -15.0f * grassSpeedReductionMultiplier;
        }
        if (Input.GetKey(KeyCode.A))
        {
            steerSpeed = 200.0f * grassTurnReductionMultiplier;
        }
        if (Input.GetKey(KeyCode.D))
        {
            steerSpeed = -200.0f * grassTurnReductionMultiplier;
        }
        steerAmount = steerSpeed * Time.deltaTime;
        moveAmount = moveSpeed * Time.deltaTime;
        transform.Rotate(0, 0, steerAmount);
        transform.Translate(0, moveAmount, 0);
    }
}

looks like this right now

rich adder
#

MoveRotation is better ofc but yeah for rotation it wont going to make a huge deal
Force/Velocity is def what you want though if you want accurate physics detections

spice burrow
rich adder
spice burrow
spice burrow
rich adder
#

but ideally you move the linearVelocity part to FixedUpdate

#

the rest can stay

sour fulcrum
#

this doesn't really matter but just a tiny easy thing to learn, if you see repetitive code like this give it a look for a sec and think about how you can avoid it, here you don't need to * by your reduction in each if you just do it afterwards (since you do it in all those options) eg.


        if(Input.GetKey(KeyCode.W))
        {
            moveSpeed = 20.0f;
        }
        if (Input.GetKey(KeyCode.S))
        {
            moveSpeed = -15.0f;
        }
        if (Input.GetKey(KeyCode.A))
        {
            steerSpeed = 200.0f;
        }
        if (Input.GetKey(KeyCode.D))
        {
            steerSpeed = -200.0f;
        }
        steerSpeed *= grassTurnReductionMultiplier;
spice burrow
sour fulcrum
#

Also no judgement, I'm only pointing this out because it will help you when asking for help and googling stuff, in your comments when you use the word localized your probably looking for the word referenced/references.

rich adder
#

!code

radiant voidBOT
spice burrow
#

im gonna be so real w/ u, i was SO sick of unity when I wrote those comments a few hours ago

#

i didnt even remember the word "reference" existed

#

ive usually used it before

sour fulcrum
#

ya no stress

#

learning is hard

spice burrow
rich adder
#

you need to switch the pivot to Local mode so you can see exactly

elder hearth
sour fulcrum
#

research online, specific questions here. if there's times where you are looking for just a general code review if you share stuff in a thread in code-general and make it easy to access and fairly focused people might spend some time checking it out

spice burrow
sour fulcrum
#

sounds dumb but just kinda comes down to figuring out what you specifically don't know and working from there

rich adder
spice burrow
#

yup

#

i know

rich adder
#

but sounds like you want to use transform.up

spice burrow
#

ive turned it around manually just bcuz i want it to start like that

rich adder
#

oh ok

spice burrow
#

so green is forward

rich adder
#

indeed. thats transform.up

#

basically thats your local facing direction compare to world Vector2.up

spice burrow
#

mhm

#

i can see that

#

so i just plug that in

#

hold on

#

i might just have ot read the documentation again

rich adder
#

yes the only difference why number worked different in Translate, because by default it moves in local mode to the object

spice burrow
#

thats what i like about it

#

and i reckon thats why my teacher recommended it as well

#

now that im getting deeper into this its kind of mid though

#

OH I GOT IT

rich adder
#

good thing its easy in unity

#

being able to just use/multiply the local transform cuts out a lot of the harder math

lethal gull
#

https://paste.ofcode.org/39ZUfFKzKwULbRHMEs9nmwz hello, when my player picks up an Object, I'm setting 2 bools to true, and then the player can eventually throw it back if he wants if the 2 bools are true, the throw works and sometimes it doesn't in build, so I've tried to find what the issue is in editor and one of the bool isn't getting set to true sometimes, why could this happen?

lethal gull
solar hill
#

how are we supposed to know a. which bool is the one not getting set back to true?

#

or false or whatever the issue was

#

you didnt provide much info apart from the code itself

lethal gull
solar hill
#

So send that script as well...

naive pawn
#

have you tried debugging to make sure it reaches that point? are you getting any errors?

is that boolean a property?

#

probably just something setting it to false right after, but it'd be nice to rule out other possibilities

lethal gull
lethal gull
lethal gull
solar hill
#

if something is changing that bool yes....

#

is it only getting set to true in this script you sent?

naive pawn
naive pawn
lethal gull
#

no functions or whatever

naive pawn
#

we don't know that

lethal gull
#

just one line

naive pawn
#

is it a property or a field

lethal gull
#

field

naive pawn
#

and i assume it's public?

lethal gull
naive pawn
#

is anything else assigning to that field

lethal gull
#

no..

solar hill
#

why not just send the script...

naive pawn
#

and how are you verifying that

lethal gull
naive pawn
lethal gull
lethal gull
frail hawk
#

one script for one bool , that doesnt look right to me

naive pawn
#

how have you verified that there's no code using this bool

lethal gull
naive pawn
#

have you tried a find in project or making this field private and see what errors come up

lethal gull
naive pawn
#

and you only ever set it to true?

lethal gull
naive pawn
#

do you only have one instance?

lethal gull
#

wait, by instance you mean only one variable with this name?

#

or like many scripts

naive pawn
#

instance of this component

lethal gull
#

I think I'll firstly try to organize everything better, because that code has so many useless lines and debug everything

solar hill
#

I would argue debugs are the least useless part of it

lethal gull
frail hawk
#

you could also use an event to set the other bool to true whenever you set the first bool true.

solar hill
lethal gull
frail hawk
#

well you said only one of them works so no idea what you ment by that

lethal gull
lethal gull
naive pawn
polar acorn
#

You are possibly setting the bool on the prefab and so the one in your scene is unaffected

lethal gull
lethal gull
#

if it doesn't help, I'll just use only one bool, having 2 bools was kinda useless

#

I've found the problem @naive pawn @polar acorn @solar hill @frail hawk

#

I was setting the bool outside the Raycast if statement, so even if I didn't throw the Object, the bool was getting set to false

frail hawk
#

someone once said, never underestimate the power of debug.logs

naive pawn
spice burrow
#

is there a way to set the current forward/backward velocity of my player object to 0 while leaving the velocity in other directions unchanged?

naive pawn
#

gonna need some more context

#

an rb? forward/backward in world or local space?

spice burrow
#

local space

#

as in transform.forward

#

yes, its an rb

#

im gonna get the code real quick

dense mountain
#

I need help with a bug with one shot audio. Whenever I reload the scene it constantly prints errors about the audio source being deleted. I tried calling donotdestroy when it starts, but the error still happens and it ends up breaking other logic.
(https://paste.ofcode.org/q6uSfJiqgajytJhGJDk7J5)

#

is there a way for me to make the code I send collapsable or smth btw I feel bad because of how large it is

naive pawn
radiant voidBOT
spice burrow
naive pawn
#

are there terms there you don't know?

#

(i don't know how much you know, so if there's some part you're unsure of, say so and i'll grab resources or explain)

spice burrow
#

well i dont know how to transform it into local space nor how to transform it back or how to assign it back into the rb

naive pawn
spice burrow
#

i do understand what you mean, though.

naive pawn
#

if you don't do that then nothing will change, since Vector3 is a value type

dense mountain
naive pawn
#

no need to mask it, but fyi the mask format is [text](link)

spice burrow
dense mountain
#

does it work now?

naive pawn
#

yeah

#

oh yeah discord is a bit weird with pasting links. if you have text selected it turns into a masked link using your selection, instead of just replacing the selection. it's kinda jank, i don't really like it either...

naive pawn
dense mountain
naive pawn
#

i'm not saying to do that, i'm asking for info about the current setup lol

#

so when you scene reload you do get a fresh player object and audiosource from the scene, yeah?

#

ah i see

#

you've leaked an event listener

#

you never unsubscribe to jump.action.started, so whenever that fires after reloading the scene, Jump on the now-destroyed player fires, trying to access the also-destroyed audioSource

#

since you subscribe in OnEnable, you should have unsubscribe in a matchingOnDisable

#

(and to be clear, assuming the player/audiosource are in the reloaded scene, you don't need either to be DDOL here)

dense mountain
agile mesa
#

i wanna change the volume override values from code, it works but doesnt reflect in the scene

naive pawn
agile mesa
#

the code runs cause when i select the volume profile i can see the values changed, but they dont reflect in the scene

#

and yes its the profile used by the urp asset

naive pawn
#

ohhh i was thinking audio volume lmao

sour fulcrum
#

Might need that always refresh thing ticked on top right of scene view?

agile mesa
#

it was the first i checked but no

sour fulcrum
#

Psycho solution but does turning the component off and on via code when you change the values help?

agile mesa
#

not the component but it works if i turn off and on the override

sour fulcrum
#

Close enough

agile mesa
#

maybe i should use the override function instead of changin the value directly

naive pawn
#

i mean, that seems quite opinion-based

#

fair

solar hill
formal lily
#

hey guys, i really wanna get into coding but dont know shit, can anyone teach me?

radiant voidBOT
naive pawn
#

there are also c# courses pinned in this channel

prisma shard
#

Is it normal for learning C# to get more depressing as it goes on. I originally felt comfortable up to like a mid-intermediate section. But things keep advancing and getting more and more confusing and its starting to make me heavily procrastinate studies

prisma shard
#

Because i know next lecture session is going to be a bunch of convoluted BS that i will only partially understand

naive pawn
#

sounds like it's going at a pace faster than you're comfortable with, i guess?

polar acorn
keen acorn
naive pawn
#

perhaps try reading in your own time, see if a different resource can help it click

prisma shard
naive pawn
#

or if there's a specific concept you're stuck on, feel free to ask (though, if it's just general c# it may fit better in the c# server)

naive pawn
formal lily
prisma shard
naive pawn
#

go back to the first one where you feel your understanding is incomplete. research so you understand more. go from there

polar acorn
#

You don't have to be told by a teacher

naive pawn
#

learning isn't a QTE or a limited time event

prisma shard
#

Like some C# sections were designed poorly by microsoft

naive pawn
#

(without more specific questions we can only really give generic advice)

polar acorn
keen acorn
# formal lily im aware, but im way better 1 on 1

I don't wanna push this course too much, but I'd say the cs50 lectures and problem sets are pretty darn effective at teaching programming fundamentals, I'd say it'll help you specially if you prefer 1 to 1 explanations. Give it a go

prisma shard
#

I know this is a fallacy because programmer "language" and language language is different. But i found immersing myself in russian/etc was much more beneficial even if i didnt understand what was going on in the grammar etc. I was just wondering if it might be beneficial with C# even though the logic is different. I just wasnt sure

polar acorn
formal lily
keen acorn
keen acorn
naive pawn
naive pawn
solar hill
#

why would quality be censored 🧐

keen acorn
#

Same question here, maybe it was because i added a *

#

Ooh, my bad, "please complete sentences with full context"

polar acorn
#

The bot doesn't like doing the "one word*" replies because people keep using it instead of just editing the post

solar hill
#

yeah you cant just do "..." or something like that

polar acorn
#

You can just press up arrow and edit your last message if you make a typo

vast falcon
#

Hi

scarlet skiff
#

so if i understood things correctly, the way lists work u can quickly look up a value based on index, but you need to loop through the whole list and check each value to be able to get the index of a certain value (if it exists in the list). is there a list-like data type that has a quick look up where u can find both the index based on a value u have and the value you want based on the index you have

ivory bobcat
#

Are you more concerned about performance or ease of access?

scarlet skiff
#

actually also currently i have a list of vector2 so maybe indexOf might not work cuz of float point imprecision?

rich adder
#

vector2 has approximate for == / Equals

ivory bobcat
#

What task in particular are you using the list to accomplish?

scarlet skiff
#

node positions for an a* pathfinder

#

making a nav graph

rich adder
#

cant you just use dictionary or hashset ?

scarlet skiff
#

i thought about dictionary but i was unsure if it does work that way, like a fast look up in either direction

rich adder
#

dictionary doesnt have indexes though

ivory bobcat
#

Why not both?

scarlet skiff
#

i thought it worked just like a list but except of having just int index you can index things with differentdata types

scarlet skiff
scarlet skiff
rich adder
#

you could do that too, not sure if its optimal

grand snow
#

An index is an offset from the array/list start which is why access by index is fast

#

its literally "pointer to array + (type size * index)"

#

In simple terms, quick maths

rich adder
#

at some point the dictionary does lookup faster too iirc

scarlet skiff
#

oop didnt mean to reply

scarlet skiff
grand snow
rich adder
#

I think indexOf still uses loop in backend. anyway

grand snow
#

It does, no magic

scarlet skiff
grand snow
#

Dictionary uses hashes and bags to do faster lookups compared to just looping over everything

grand snow
ivory bobcat
# scarlet skiff yea i realized maybe just making two lists would solve this but i was just curio...

If the object knows where it's at on the grid (x,y), you can use a dictionary to lookup its own position quickly; given the object.
At the same time, you could use a multidimensional array or list to manage the object relative to its grid position.
You'd simply need to update both its grid position and stored position when making changes to position. This is more for ease of access as using more collection does include additional expenses in memory allocation. Actual performance in speed would vary but should correlate with the respected collections.

You're better off using what you're comfortable with.

rich adder
#

but yeah dont use floats as keys lol

grand snow
#

Im a int index = x + y * height; guy

scarlet skiff
# ivory bobcat If the object knows where it's at on the grid (x,y), you can use a dictionary to...

but dictionary would mean we are using vector2 as key and that would lead to floati mprecision, no?

also its not a grid based system, sort of, its based on world position, to do it grid based would require me to rewrite a bunch of my current system, which hey, if its better ist better, might as well get to work, i mean the pathfinder does use a unity tile map as its like base when searching/placing nodes, so could js use that, but during pathfinding we constantly recalculate the path, distance calculations, moving targets, we would then be doing a lot of CellToWorld() calls, i think have an effecient way to just do a reverse lookup might be the best way, maybe since its grind based i should move the tile maps up and right by 0.5 tiles, and make the list a vector2int, that way the center of the tile always lands at number that doesnt require floats

#

althought actually i do node placements at half tiles too so floats will still be needed

#

maybe storing the number *10 then diving by 10, avoids floats then?

#

which would allow using the disctionary concept from before

grand snow
#

previous comments about float/double still stand

scarlet skiff
scarlet skiff
grand snow
#

You could also try using reduced precision positions stored as int or long or even a custom struct with your own stable hash code

#

But these are not very beginner friendly

scarlet skiff
grand snow
#

something like Mathf.RoundToInt(x * 100)

stiff pendant
#

is there a help channel

grand snow
stiff pendant
#

oh ok so i have this problem where it wont move my ball (dont mind the model

rich adder
#

!vsc

radiant voidBOT
# rich adder !vsc
<:error:1413114584763596884> Command not found

There's no command called vsc.

rich adder
#

!vscode

radiant voidBOT
rich adder
#

& did you check the console tab in unity for errors ?

#

hmmm.. you never call ProcessInputs anywhere...

gilded harbor
#

I know the solution to this is probably long, so if someone could just point me in the right direction i'd appreciate it: I'm trying to make it so two gameobjects get a random material selected on keypress, and I want to make sure they don't both get the same color. I'm new to coding and am having a very hard time figuring out what i'm doing wrong. Where specifically can I look to help myself understand what i'm doing wrong in this part of my script?

    public Material[] PossibleColors;

    //private Renderer ColorRenderer;

    [SerializeField] public GameObject LeftCube;
    [SerializeField] public GameObject RightCube;


    private void Start()
    {
        if (LeftCube != null && PossibleColors != null)
        {
            Renderer LeftColorRenderer = LeftCube.GetComponent<Renderer>();
            if (LeftColorRenderer != null)
            {
                int LeftRandomColor = Random.Range(0, PossibleColors.Length);

                PossibleColors.material = PossibleColors[LeftRandomColor];
            }
        }
    }
cosmic dagger
gilded harbor
rich adder
cosmic dagger
#

focus on the random material selection. do you know how to get a random value from a collection (list, etc.)?

rich adder
#

you can make it simple enough where you toss what you have in array into a temporary list then just remove the item you already chosen for object 1, if you random rangethe list again you guaranteed not to grab an already chosen color

gilded harbor
#

If i'm understanding this correctly, I think so. I have a Material[] array and am later calling it using Random.Range(0, X.Length)

gilded harbor
cosmic dagger
rich adder
gilded harbor
rich adder
#

also you should configure your IDE if this is not underlining red
PossibleColors.material = PossibleColors[LeftRandomColor];

#

array has no such property .material

#

put the result directly into your object1 or a variable

gilded harbor
#

Okay i'm going to try toying with that a little bit with a new script to see if I can get the jist of it. Google gemini is giving me some good solutions but it just feels like i'm copying and pasting rather than being given actual explanations

cosmic dagger
rich adder
cosmic dagger
#

@gilded harbor to avoid returning the same number, you can implement different tactics. i would think of how to check or avoid getting the same number . . .

#

nav mentioned copying the array to a list, then using the copied list and removing the first index returned (from the list). this avoids selecting the same index again as it is no longer in the list . . .

rich adder
#

I'd recommend to brush back up on c# basics like array, lists, loops etc

#

but yeah cause as mentioned, there are different ways to solve this (like anything in dev :P)

cosmic dagger
#

if you want to avoid creating a copied list, you could simply check if the second returned index is the same as the first, then offset by +/- 1 to return a different value (index) . . .

gilded harbor
#

Yeah I have this book i try to reference a lot but it's not fully committed to memory. So, ToList, IndexOf(), Contains() might also be good places to brush up on? This book I have isn't specific to unity but it is c#

rich adder
#

the Unity bits come after, yeah just normal basic c#

#

unity just has some concepts about the engine like GameObject or Inspector / components
but none of those change anything about how c# works . So you're just essentially dealing with an API code wise

gilded harbor
#

Okay gotcha. Thanks so much, this channel is always so helpful. Every time I think i'm starting to be more fluent in this I get hit with a new challenge and this is always the best resource.

#

I'll definitely do a little more digging in this book in those areas

rich adder
#

this channel has good resources pinned if you prefer interactive or tutorials on these

gilded harbor
#

The biggest problem underlying every roadblock I hit is not knowing where to even look, being pointed in the right direction is super helpful. i'm starting to understand what people are talking about when they say tutorial hell

cosmic dagger
#

unity is just an API; most of the challenges come from solving problems, like, how to connect one thing to another, how object A affects object B, etc . . .

cosmic dagger
gilded harbor
hallow bough
#

if I am trying to create a basic first person 3d projects, what are some useful websites or resources i can use other than videos/tutorials? in the past i’ve done some basic games, but I want to truly understand everything from the ground up.

-# btw I can’t always respond, so to anyone replying, if you don’t mind pinging me, that way i can keep track of the message

naive pawn
#

there's a lot of stuff you could go into, so it depends on what you're interested in

#

there was a website about vector math and such with diagrams but i can't seem to find it...

#

oh damn i found it
a bit less complete than i remember though. so ig nvm

stark burrow
#

When attaching debugger to unity it asks about session and recompiles which takes a long time with burst especially. Is there way to make that iteration speed faster?

rustic trail
#

Heyo, i’m currently working on my first real game and give myself new challenges. I want to have some sort of base from which i can start missions etc. Simular to games like darkest dungeon or hades etc.

Since i never worked with data between scenes i do not really have an idea where to start or what is the term/technology i need to look into. So whats the term/technology behind such logic? Is is persistent data?

sour fulcrum
#

DontDestroyOnLoad & Additive Scene Loading are terms you can look into

elfin pike
#

last thing to fix is id not saving in scriptableObject, it resets with new session.

midnight plover
elfin pike
midnight plover
elfin pike
sour fulcrum
#

idPreview is, is that saving?

elfin pike
sour fulcrum
#

ok

#

but like

#

idPreview is the only thing there that can be saved

#

(you can probably fix and simplify this just by adding [field: SerializeField] to id which will save id and show it in inspector)

midnight plover
#

private setter on your id will not serialize and therefore reset everytime

midnight plover
#

you can also use , HideInInspector behind your serializefield to not show it but still have an accessable public value "ID"

sour fulcrum
#

You can just add the field SerializedField directly to the property

naive pawn
#

unity doesn't use the setter

#

it uses reflection to get the backing field directly (since SerializedField needs to be applied to the field)

midnight plover
naive pawn
#

to be pedantic, SerializeField is an attribute. "property" is a specific term in c# so the distinction is important.

midnight plover
#

ah my bad, yeh, attribute, absolutely right. so the attribute should fix swortechs issue in this case.

sour fulcrum
#

Yeah, with the additional field: part so it correctly serialises the backing field

balmy pendant
#

guys how to get a direction to Torque the rigidbody, between 2 rotations, current one and desired one, just like with position doing target.position - transform.position, how to do the same but with quaternions???

verbal dome
#

Quaternion.Inverse is probably helpful here

#

For getting a difference between quaternions

#

Though it's probably easier to calculate the angle difference per each axis (X, Y, Z) with Vector3.SignedAngle and use those for your torque force vector

balmy pendant
#

thank you Osmal

#

you are a true hero

rancid tinsel
#

Any idea what it is this time? Again 0 changes but it seems the line endings are the same this time as well - also isn't allowing me to undo the "change" (it doesn't disappear)

silk night
grand snow
#

Sometimes got does this but when I stage such a change/file it realises and goes away

#

You can always discard the changes/reset it

grand snow
rancid tinsel
#

Thanks a lot!

elfin pike
#

idk, if my issue is for coding or input system. i have singleton which has ActionReference ```void OnEnable()
{
BackInput.action.Enable();
BackInput.action.performed += Back;
}

void Back(InputAction.CallbackContext context)
{
    switch(CurrentState)
    {
        case GameState.Playing:
            Session.Dispose();
            SetState(GameState.LevelSelect);
            break;
        case GameState.LevelSelect:
            SetState(GameState.MainMenu);
            break;
        case GameState.MainMenu:
            #if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
            #else
                Application.Quit();
            #endif
            break;
    }
}

void OnDestroy()
{
    BackInput.action.performed -= Back;
    BackInput.action.Disable();
}```, but i have issue after switching from [Playing] to [Levelselect], action doesnt work. Maybe, PlayerInput change something in [Playing] state scene
midnight plover
elfin pike
midnight plover
elfin pike
#

debugged more and PlayerInput disables it

#

doesnt matter where i try to enable action, it only can be enabled in update().

midnight plover
elfin pike
#

time scale only affects physics

naive pawn
#

timescale affects anything that uses deltaTime or fixedDeltaTime

#

if you have hold inputs set to scaled time (if that's a thing) they'd be affected - but it shouldn't have an effect on input actions as a whole

elfin pike
#

but in my instance it doesnt effect input

midnight plover
#

Okay, it was just a test, because it CAN affect it. So as you disable the input system on your gameobject, I guess, you are not using a DDOL pattern for the input script you pasted, right?

midnight plover
elfin pike
#

i dont know who disables my action

elfin pike
#

thanks Osmal for ruining my free day

midnight plover
#

So if you remove the OnDestroy and OnEnable part entirely and just enable it on awake or start, does it work then?

naive pawn
#

why are you using OnEnable and then OnDestroy? sounds like that could leak listeners

#

you generally should use symmetric messages, so OnEnable/OnDisable, or Awake/OnDestroy

elfin pike
#

because VScode and unity gives warnings.

midnight plover
elfin pike
midnight plover
naive pawn
elfin pike
#

can we stay on topic

naive pawn
#

this is on topic

elfin pike
#

playerInput class disables my action

naive pawn
#

having improper messages can contribute to various issues

midnight plover
elfin pike
midnight plover
elfin pike
midnight plover
elfin pike
#

or i can call from player gamemanager instance and switch state

midnight plover
midnight plover
elfin pike
#

im using unity playerinput

midnight plover
elfin pike
#

yeah

midnight plover
# elfin pike yeah

So my guess is, that the playerinput , whenever it loads, creates a new version of your input class and therefore you lose your gamemanager one. So you could also just use a second input action set for the player and one for the entire game.

elfin pike
#

but it works, while playerinput exist

scarlet skiff
#

my computer shut off while i was away and im unsure if i had unsaved code or not, does any1 know what the blue lines on the sides mean, or the little red traingles, or why in the explorer there are ⛔ typa signs?

elfin pike
scarlet skiff
hexed terrace
#

unsaved changes in VS are yellow lines

#

VS doesn't do auto saves, if VS closed and you had unsaved changes.. they have been lost. It does not matter if you have version control, it makes no difference in this situation.

scarlet skiff
#

so whats tge blue lines

hexed terrace
naive pawn
# scarlet skiff

they're version control change indicators, both in the gutter and in the left side of the scrollbar

#

the red triangles are deleted lines, green are added lines, blue are modified lines. try clicking them, they should show what changed

naive pawn
hexed terrace
#

how so?

naive pawn
#

the styling is different, they seem to be a separate set of features

hexed terrace
#

styling is because it's for an older version.

naive pawn
#

it's also saying the blue is supposed to be reverted changes but that certainly doesn't make sense in this screenshot, and it makes no mention of the red triangles

hexed terrace
#

because the question on the post didn't ask about red triangles 😄

naive pawn
#

the same presentation is used in vscode for source control features, for example

hexed terrace
#

I don't really care though, I did a 2 sec google .. they seem close enough to me, but couldn't care less to find out further.

naive pawn
#

so why are you arguing against me then lmao

hexed terrace
#

A dicussion != argument lolollololollol l 😄

naive pawn
#

i agree, but you have not been discussing, only deflecting.

hexed terrace
#

fs chris.

naive pawn
#

seriously though.. you say you googled it for 2 seconds, found something "close enough", and when disputed you deny every point i make

naive pawn
naive pawn
lapis sierra
#

hey guys why th is this not working
it doesn't indentify actions

naive pawn
lapis sierra
#

wdym

naive pawn
#

i mean what i said

#

if you have a type named PlayerInput in the same namespace, you'll be referencing that instead of the inputsystem one

#

try hovering over PlayerInput and see what namespace it says it's from

lapis sierra
#

bro dont abondon moi

naive pawn
#

..i gave you instructions on what to do

#

if there's part of that you don't understand, say so
i can't read your mind - if you ask for clarification on a certain part i'm happy to oblige

lapis sierra
#

guys plssss

#

guys heelppp

naive pawn
silk night
polar acorn
lapis sierra
#

what

silk night
polar acorn
# lapis sierra what

You were given a very clear answer, an explanation on how to do it, and even something to check to get that information and you've just ignored it

lapis sierra
#

i didn't understand and said wdym and i got impatient so i said bro don't abandon me so ye

naive pawn
#

not sure what it is then

naive pawn
lapis sierra
#

wait what

polar acorn
lapis sierra
#

can you show me pls where

polar acorn
#

If you want help you should actually read the replies you get

#

I don't know what else you could want

naive pawn
lapis sierra
naive pawn
lapis sierra
#

yes

#

i asked wdym

naive pawn
#

that message was AFTER you asked

#

that was clarification

distant saddle
#

Hello , i'm planning to make an equivalent to mario kart "ghost" but in a 2D platformer (meat boy style) ,basically when you finish a level , if you retry it , a ghost who copy the movement you had done will appear , do you have an online tutorial who show how to do it ?

lapis sierra
#

so like

#

can you clarify what you mean now plssss

naive pawn
#

do you just not understand a single word of what i said

#

if there's part of that you don't understand, say so
i can't read your mind - if you ask for clarification on a certain part i'm happy to oblige

#

do you know what hovering is?

naive pawn
distant saddle
lapis sierra
naive pawn
#

in fact with the extra replay keyword, there's one using super meat boy as the example

distant saddle
naive pawn
proper peak
#

I've been scratching my head for a while for this... how do you assign a Slider with code?
I was trying something like this

naive pawn
lapis sierra
naive pawn
#

hovering is when you put your mouse over something

naive pawn
lapis sierra
#

so there isn't something called hovering on discord

naive pawn
#

hovering is a computer term

lapis sierra
naive pawn
naive pawn
#

those were literally AFTER you asked for clarification

lapis sierra
#

ok so can you clarify the clarification

near wadi
#

this person is either a troll. or simply incapable of the level of computer skill required to work in Unity.

lapis sierra
#

cuz i dont understand

frosty hound
#

If you continue to act this way, then make a thread at the very least so you're not flooding this channel with more noise.

polar acorn
lapis sierra
#

but i was asking what he meant

proper peak
lapis sierra
#

or she

naive pawn
frosty hound
lapis sierra
frosty hound
#

Heres' fine

naive pawn
# proper peak i dont get why i keep getting this error though. Also what do you mean by serial...

serialized references are when you drag stuff into fields in the inspector. they're generally much easier and safer than using Find
like right now, you have expSlider as a serialized field (because it's public, one of 2 ways to have it be serialized)

if you drag an object into that slot in the inspector, that'd be a serialized reference (and you wouldn't need to do expSlider = ... in code)

what i'm recommending is basically that, but instead of GameObject, you would have Slider instead, so you wouldn't need the later GetComponent either - you would have direct access to the slider

naive pawn
runic basalt
#

I have roughly 200 objects in the ceiling of an environment with more being added throughout run time, and I have a vehicle that we drive around in the environment. I need to know if there is ever a time when there are none of those objects above the vehicle. Would it be more efficient to add trigger colliders to each of those objects and a bounding box above the vehicle that does uses a Physics.OverlapBox to check the layer the objects are on to see if any are within the box, or would it be better to add bounding boxes to sections of the objects, using the encapsulate function to grow the boxes around any newly added objects, then do a check if we are within any of those boxes. There are about 20 of the boxes, for reference.

naive pawn
#

is it 20 boxes total that you're checking, or the 200 objects? i'm a little confused

runic basalt
#

20 boxes. Each box has a group of the objects. But if we did it with just one box over the vehicle, we would just use the Physic.Overlapbox to check the objects directly.

naive pawn
#

so your question is between 20 boxes or 200 objects?

#

those are both pretty small numbers. you should focus on a working and maintainable solution first, and then worry about perf if there are perf issues

lapis sierra
#

.actions problem in c#

naive pawn
#

i think a boxcast or indeed overlapbox against the individual objects would be sufficient as a starting point, then go to more complex optimizations only if necessary

proper peak
naive pawn
#

UnityEngine.UI is the one for the default ui canvas, buttons, sliders, etc

#

i don't really know anything about uitk other than "it exists" so i can't describe that one to you

#

ugui is unity gui, uitk is ui toolkit, in case that helps with further research

proper peak
naive pawn
#

ime there's always a better way to get direct references than with Find, but i'd require more context to determine how for your case
Find is ultimately based on magic strings that you write yourself so it's always one of the worst options in a given scenario imo

#

(if you have other stuff to worry about for the time being i'd understand, no pressure to change right away, but i encourage changing eventually)

proper peak
#

yea I did hear that before about using find as not very efficient. I will have to research on better ways when optimizing

fickle rose
#

So Im trying out the visual scripting, and I have made a simple script, but I dont know how to put said script on an object. How would I do that?

naive pawn
fickle rose
#

alr thanks

pseudo summit
#

Why does it say RandomRangeInt cnt be used from a monobehavior construction what does that mean

#

also using UnityEngine.Random doesnt exist in vscode for some reason

#

Someone help with this please

naive pawn
pseudo summit
keen dew
#

You can't call functions in field initializers. You have to set the value in Awake

naive pawn
#

specifically you can't call instance methods of the current class

#

what are you trying to do?

pseudo summit
#

Ok how do i just choose between two numners 1 and 2 when the game starts

polar acorn
#

Then do it in start

pseudo summit
#

Ok

#

thanks it worked

acoustic maple
#

I've coded so when a collision happens, it adds a force in a direction. How do I make that the opposite direction of the collision?

pseudo summit
#

So uh up till now i did OnTriggerEnter2D(Collider2D collision){BoundaryHit = True} to stop the object from mvoing any further and now ive went and did ther shit and suddenly it just doesnt work anymore

acoustic maple
pseudo summit
#

How do i make it so an object with a rigidbody2d not get flung away by another thing

pseudo summit
rich adder
polar acorn
kindred prairie
#

hey i wann add animation to my script but im unsure where to put it and when i go on a youtube vid it doesnt work it gives error codes
i can move normaly but i want to do a animation for example moving right and left and up and down

rich adder
#

use something like a Blend tree

kindred prairie
#

ya but i gotta add stuff

rich adder
#

"stuff"

kindred prairie
rich adder
#

You meerly control the parameters

kindred prairie
rich adder
#

Ok so you already have the blend tree then you need to control the parameters only through script.

kindred prairie
#

but on visual studios im unsure what to put

#

can i send what i got currently

rich adder
#

ok

#

👇

radiant voidBOT
kindred prairie
kindred prairie
rich adder
#

its pretty clear

kindred prairie
#

so i post my code in there

rich adder
#

You post it with one of the links provided yes

kindred prairie
#

i got it in one how i send it to you

rich adder
#

save and it should generate the link, send the link in chat

kindred prairie
#

thats all i see

rich adder
kindred prairie
#

got that one working

rich adder
kindred prairie
#

so what do i add

rich adder
#

start with the basic , do you know how to add reference to the Animator ?

kindred prairie
#

could u please explain what you mean refrence

#

thats what it shows on unity

#

sorry if i sounding dumb or so

rich adder
kindred prairie
#

i was watching a tutorial but when i do the animation part other videos have different codes thats why im confused

#

so you saying u want me to make a component aka the animator

rich adder
rich adder
#

scripts on gameobjects ARE components

kindred prairie
#

i think i understand that lol

#

right

polar acorn
rich adder
#

you're skipping through a lot of the basics tbh you should start simpler

kindred prairie
#

do u want me to send the two videos i used

#

or was using

rich adder
#

eh not really interested in the videos cause I already sent an example from the docs on how you control parameters through code

#

you just have to study it a bit

kindred prairie
#

i did make these

#

on the animation part

rich adder
#

right. and those are Parameters as per link I sent

kindred prairie
#

yes

rich adder
#

you Control those through code

kindred prairie
#

okay

#

now im understanding you

rich adder
#

did you click the link I sent at all ?

kindred prairie
rich adder
#

thats to learn about referencing
I;m talking about the Animation Parameters one, the documentation

kindred prairie
#

im currently reading that one right now

rich adder
#

it pretty much explains how the process works and has example code

#

don't just copy and paste the code, see how those relate to what you have so far and you mash those in

kindred prairie
#

ok ill give it ago

#

sorry for being a pain

rich adder
#

nah its fine no worry
just make sure you read it

kindred prairie
#

i will just sometimes confuses me with different codes lol

rich adder
#

yes it happens if you're skipping through many things to get here.
doesn't hurt to brushen up on basics first before taking such tasks

#

tutorials can be okay to show the process but its better if you understand why and how certain code is used

kindred prairie
#

Okay I learned all movement and that it was just confusing how to add the animation to the same script lol

#

Because you can make a script all organised can’t you

#

In the different sections or so

rich adder
#

I mean you can, but in the beginning doesnt have to be.

kindred prairie
#

Ok

rich adder
#

you can put comments or regions

kindred prairie
#

As I’m making a table top game

rich adder
#

start with commenting code so you know why that line is there

kindred prairie
#

Okay

rich adder
kindred prairie
#

Ok so the stuff I did in the blend tree once I add the code for that it will use the animator to animate right?

rich adder
kindred prairie
#

Ahhhh that makes a bit more sense

#

Just reading this doc you sent then I’ll try and do the code part and that

#

And I can ask you if I need extra help

#

If that’s okay?

rich adder
#

sure you can post here any further questions you have

#

I'll most likely be here or someone else will answer anyway

kindred prairie
#

Ya I will do I will do it slowly so I can understand stuff better

#

Thank you again for the patience you have with me

pseudo summit
rich adder
sour fulcrum
#

@marble hemlock there's many ways but that is one of them yeah

#

save stuff is a deep rabbit hole so there's always going to be a "better" way

#

at the very least maybe just for kinda general vibes maybe store it in a scriptableobject that is referenced by a singleton?

#

in general good to have data on so's vs. monobehaviours

marble hemlock
#

mmm i will try that
it'll unfortunately have to be in like 4 days because im going to be away from the desktop but the idea has been plaguing me since yesterday

#

just been writing down ahead of time what i would put on it, since i'd then after sort of model the other scripts based on that "masterscript" thats tracking the overall progress of the entire game

#

going to continue writing for now though

kindred prairie
#

i forget how to close the brackets

#

these } the keybind

rich adder
kindred prairie
#

i wanna put the end on it

rich adder
#

SetBool has two params and InputAction is a class you need from the Input namespace

kindred prairie
#

these are the current errors im getting

rich adder
#

always start with the top error first

#

the first two should be able to correct the rest

sour fulcrum
kindred prairie
#

says no overload for method setbool takes 1 arguments

polar acorn
kindred prairie
solar hill
#

oh

kindred prairie
rich adder
sour fulcrum
polar acorn
solar hill
rich adder
#

and and yes the brackets at the end

kindred prairie
polar acorn
sour fulcrum
solar hill
#

have you never added "{}" these before?

#

you did... in your if statement

rich adder
#

poorly pasted code you don't understand :\

kindred prairie
rich adder
#

oh and that moveInput - context.ReadValue is wrong

#

thats probably meant to be assignment

polar acorn
rich adder
#

you're literally using SetBool correctly the second time but not the first time , you can just compare the two and its obvious whats wrong

kindred prairie
#

is the line 29 wrong setbool

rich adder
#

considering its underlined red, yes..

#

tbh the longer I look at this code the worse it gets

kindred prairie
#

would it be getbool then

rich adder
#

why would it be GetBool

sour fulcrum
#

where did you get this code

polar acorn
rich adder
#

are you trying to Read the value or Assign it

polar acorn
#

In words, not code

short hazel
#

Hmm it's using both input systems at once as well

kindred prairie
#

so basically i want it so i can animate walking left right back and forwards and when not moving it goes into a idle animation

rich adder
#

line 29 doesn't have any purpose on this if you're gonna do everything in the Move method anyway

kindred prairie
#

so should i remove the line 29

polar acorn
#

What is that line supposed to do

#

Individual lines have meaning, you know

kindred prairie
#

tell it im walking

rich adder
#

you're mixing two inputs systems and its gonna be more confusing

kindred prairie
#

okay

polar acorn
kindred prairie
#

setting one

swift crag
#

to be fair, it could be either :p

#

oh, no, it's definitely just setting here

#

i misunderstood!

kindred prairie
#

So would it be set then

rich adder
#

seems you're trying to do the same thing in different places in multiple ways

kindred prairie
#

so what would u do to fix it

rich adder
#

pick one way to do it

kindred prairie
#

could u explain what you mean

rich adder
#

the move method you have there, from the new input system. You are already setting the bool in animator to true or false depending on inputs

#

assuming you correctly run that method

kindred prairie
#

but i was trying to say when i start walking my animation starts and if i stop walking then i go into idle mode

rich adder
#

so do you have it set in animator that way where "isWalking" controls if walking or idle depending on true/false

kindred prairie
#

let me send pics

#

they from idle to walking

rich adder
# kindred prairie

right so what do you think based on what I asked, do you think you have it correct?

kindred prairie
#

i think i dont have it correct

rich adder
#

why do you think that?

#

you want it from Idle to Walk when "isWalking" is true.

kindred prairie
#

maybe the isWalking is getting confused and doesnt know if its true or false

rich adder
kindred prairie
#

maybe yes

rich adder
# kindred prairie maybe yes

ok so yes?
so now what would you want in the code to say "Hey I'm moving, isWalking in animator should be true"

brave token
#

hey, i want my sphere to roll when you look downwards and i don't know how to do it with Vector3. can anyone help?
here's the mousemovement script

using UnityEngine;

public class MouseMovement : MonoBehaviour
{
    public float mouseSensivity = 100f;

    float xRotation = 0f;
    float yRotation = 0f;

    //public float topClamp = -90f;
    //public float bottomClamp = 90f;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * mouseSensivity * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensivity * Time.deltaTime;

        xRotation -= mouseY;

        //xRotation = Mathf.Clamp(xRotation, topClamp, bottomClamp);
        yRotation += mouseX;

        transform.localRotation = Quaternion.Euler(xRotation, yRotation, 0f);
    }
}
kindred prairie
rich adder
kindred prairie
#

so it needs to be true

rich adder
kindred prairie
#

so would line 29 need the true part then

rich adder
#

don't be randomly guessing

kindred prairie
#

im sorry

rich adder
#

how do you want to tell the Animator you are indeed walking, what condition would set it true for example..