#💻┃code-beginner

1 messages · Page 244 of 1

queen adder
#

all right thank you then

#

its my bad

jade quarry
#

can i ask how would I change the speed at which the thingy moved ? (using Speed)

vale karma
#

you should probably go through the absolute basics. these are quite simple coding concepts

#

like a tutorial from one of the big utubers, they explain really well the simplistic side of things

jade quarry
#

any recomendations ?

vale karma
#

do absolutely everything he suggests, do it twice, start changing things up, variable names, add things, recreate the wheel, and most of all complete it

jade quarry
#

aright thx

vale karma
#

np

summer stump
#

So just agent.speed

foggy lion
#

Is it possible to duplicate the current scene and then load into it through code?

teal viper
#

copy paste the scene file, add it to the build settings and load it through code

foggy lion
#

I also have a score counter that is related to the current scene

#

So I was hoping that it was possible to duplicate scenes through code

teal viper
foggy lion
#

Thats a shame

#

I guess I could use a int that isn't destroyed upon reloading the scene

teal viper
#

Yeah, it feels like you tried to approach the problem from an extremely weird angle

foggy lion
#

I do that a lot lol

radiant frigate
#

can i get a little help? im kinda struggling with 1 thing with the particle system

#

the issue is that it somehow does more than 1 cycle and more than 3-5 particles per cycle

#

(had to do a zip since it was to big for uploading it to discord)

foggy lion
#

Eh its fine for now

#

I need to go to bed any way huntershrug

#

I can always work tmro

teal viper
silent vault
#

Hello, if I want to make a multiplayer FPS game, what is the best method to use for bullet ? Physics bullet or simple raycast ?

teal viper
radiant frigate
teal viper
stuck jay
#

Physics bullet if your game is very low poly and has low resolution textures, otherwise use raycasts

teal viper
radiant frigate
#

so i should change it to 0 or 1?

frozen mantle
#

haven't opened VSCode in a while for my project, got this after updating, should i regenerate my project file or "upgrade" my project to an "SDK-style" project?

teal viper
radiant frigate
#

i want it to just happen once

teal viper
eternal falconBOT
teal viper
#

Also, this is really not a code question.

radiant frigate
#

true

#

i enabled that for testing and forgot to unable it

radiant frigate
frozen mantle
frigid sequoia
#

Ok, so this is kinda of a way too generic question, but when should I use events instead of, you know, have it build in the object script itself?

#

Cause I have been looking about it and I am not still sure what the advantage is supposed to be

frigid sequoia
# static bay What do you mean?

For what I know is meant to be sorta of listener of something happening and then sending like a pulse to several other scripts subscribed to it to do something in response, but I don't quite see the advantage of that over just, having the scripts be the listener themselves

static bay
frigid sequoia
#

I mean, I guess performance, but like how many simultaneous scripts you must have for this to be even noticiable?

frigid sequoia
verbal dome
frigid sequoia
verbal dome
#

Yeah

static bay
frigid sequoia
#

I am figuring "check for button to be pressed to open several doors"; you could have an event listener checking for the button press and tell all doors to open when is pressed, or you could have each door trigger when that specific button is pressed instead of using a event listener as intermediary

#

How much less is efficient is this supposed to be?

static bay
#

And how would these doors check if the button has been pressed?

#

Wait

#

When you say "EventListener", which implementation are you referring to?

#

A UnityEvent?

#

A C# event?

frigid sequoia
static bay
#

OnTrigger/CollisionEnter?

frigid sequoia
verbal dome
#

Why use collision detection etc. when you can just make the doors listen to the button's C# event?

static bay
#

For that door example I would literally just make some DoorManager script, give it a reference to all appropriate doors, have a method called "OpenAllDoors" and call that method through the Unity Button's OnClick event.

frigid sequoia
static bay
#

Is this a UI Button >_>

verbal dome
#

Like when it is physically pressed? Sure, but not related to events

static bay
#

Or some "button" gameobject in the real world?

verbal dome
#

I was thinking physical lol

#

(Ingame)

frigid sequoia
verbal dome
#

Sure, you probably want to detect the button press by physics or something.
But its not related to how you make the doors know that the button was pressed

static bay
#

Alright. Point is I would 100% make it so all your buttons or interactables or whatever work through events. You could end up with tones of buttons/levers/pressure pads that do all kinds of things when their conditions are met.

#

Use a UnityEvent specifically, and hook it up in the inspector.

frigid sequoia
#

Cause is seems kinda the same but with more steps

static bay
#

Ah, okay. So you're suggesting the doors check the state of the button every frame?

verbal dome
#

That would work. It just doesnt scale very well. For a small project its fine

#

Getting used to events is good tho

frigid sequoia
static bay
# frigid sequoia Yeah, pretty much, I am actually wondering now why do events only check for chan...

Ok now I understand. Like Osmal said it doesn't scale well. Lots of doors checking the state of the button every frame is sort of a waste. It's really not an fps problem until you get literally hundreds of doors, but the main issue with that set up, in my opinion, is structural.

A doors job is just to block the player, to open and close. How and when it opens/closes is irrelevant and not its job to figure out. Like I said before imagine if you instead wanted a lever to open the door. How are the doors going to know they need to check the state of a lever instead of a button? It's much better to flip it around. It's the button or levers job to notify the door that it should open/close.

frigid sequoia
#

But, yeah, I must say that project was kinda of a mess structurally

static bay
#

Let me get a code example for you. 1 sec.

#

Put this on your button.

public class Interactable : MonoBehaviour
{
    [SerializeField] UnityEvent onInteract;
    [SerializeField] UnityEvent stopInteract;

    public void Interact()
    {
        onInteract.Invoke();
    }

    public void StopInteract()
    {
        stopInteract.Invoke();
    }
}

And this for your door.

public class Door : MonoBehaviour
{
    public void Open()
    {
        //Handle your door opening logic.
    }

    public void Close()
    {
        //Handle your door closing logic.
    }
}
#

On the inspector of the Interactable you'll see slots.

#

Slot in the Door object, and call the appropriate functions. @frigid sequoia

#

Whatever triggers the button should just do a GetComponent for Interactable and then call one of those two functions.

#

Now anything in your game can work with any interactable if they work through that Interactable component.

silent vault
#

Is it possible to do with a raycast ?

teal viper
silent vault
#

Ok nevermind my question, I found a tutorial online, cool.

static bay
#

Like gravity pulling it down over time?

teal viper
#

That wouldn't be a line either. That would be an arc

silent vault
#

No, I'm talking about line of sight. Most tutorial about raycast will jsut tell you to raycast using the center of the camera. This might work in a FPS because the gun would be conveniently placed in the center too.

teal viper
#

You can raycast from wherever you want.

silent vault
#

But with 3rd person view, the bullet is not shot from the center of the screen, so the raycast need to be calculated differently. And most tutorial don't explain that

teal viper
#

Maybe look for tutorials that cover 3rd person shooting then.🤷‍♂️

silent vault
#

Yes indeed 😉

#

Looking one right now, thanks

static bay
#

You can define whatever start point you want for a raycast. If you're worried about the fact that the position of the muzzle doesn't match the sight line of the player...

#

ya all FPS need to deal with that

#

definitely some solved solution out there

#

No wait you want a 3rd person.

silent vault
#

Yup indeed. This will solve my issue. I was using physics bullet but I'm worried with many players, it might slow down the server and moreover, the hit collision is a bit quirky when bullets go too fast.

static bay
#

Rockets and other slow moving projectiles are usually actual physics objects.

silent vault
#

This is called hit-scan weapons ? I didn't know

#

Yes, for rockets and projectiles, that would use real bullets indeed but that won't be hundreds of bullets flying around with such weapons ahha

static bay
#

Well that's more of a Shooter game term. Hitscan weapons usually mean there's no travel time with the bullet, which is what you'd get out of a raycast.

minor patio
#

...the reference is null...
...the reference is null..!
...THE GODDAM REFERENCE IS NULL!!!

static bay
#

Make it not null.

silent vault
static bay
silent vault
static bay
#

A real bullet would likely travel the length of the entire map in a handful of frames.

#

So fuck it.

#

Shits too complicated to actually simulate.

#

Let's shoot lasers instead.

silent vault
#

Indeed lol

#

I'll jsut have to look for a proper trail tutorial since i'd like to simulate a nice bullet trail like my current physics bullets leave behind.

frigid sequoia
timber tide
#

basically just render a line

static bay
silent vault
static bay
#

Events are still executed "during runtime".

silent vault
#

It would be a laser but I'd prefer a bullet representation

static bay
#

We're just not updating them "every frame".

frigid sequoia
static bay
#

Just one more example to really hammer home the advantages of events. Imagine a PlayerHealth script and a PlayerHealthUI script. How does the UI know to update the health? Sure, you could give PlayerHealth a reference to PlayerHealthUI, and update it whenever the health is changed, or make PlayerHealthUI check the state of PlayerHealth every frame.

#

Or.

#

You give PlayerHealth a event called "OnHealthUpdate" which takes in an int/float.

#

and call a method on PlayerHealthUI to update the visual.

frigid sequoia
static bay
#

Now PlayerHealth has no idea the UI exists, and PlayerHealthUI has no idea who it's getting its info from.

frigid sequoia
#

So I am guessing is kinda the same

static bay
#

And this is nice because you can easily cause more things to happen when the player takes damage.

#

Screen shake?

#

Blood splatter?

#

Scream noise?

#

Just slap it all into that health update event.

#

Nearby enemies can even subscribe to that event and increase their aggression when the player gets hurt.

#

Creating some type of swarming behaviour.

#

Point is, PlayerHealth as a class doesn't care/know about any of this.

#

It's just screaming "hey this value got updated', and whoever cares about that can do whatever in response.

frigid sequoia
#

I am just kinda having all that on the playerController takeDamage method, that's seems more organized though. Mine is kinda bloated

static bay
#

As you learn, you'll eventually start making smaller and smaller classes.

#

Each handling one thing, but working together.

hot wave
#

https://www.youtube.com/watch?v=7zfnxcKFaJg hihi UnityChanOkay I managed to make a code that follows holding directly from the cursor (not directly, it is intersecting but is a different story, still directly from the middle part form raycast), now I am not sure how to make something similar to this video, i have a feeling it is transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, ishouldputthecodehere); at the end, but instead of rotation, it is position i think, and 'ishouldputhtecodehere' says how fast or slow it could go there, maybe this is the one i need to change to copy the one in the vid? or more complicated?

Been wondering how to pick up items and stuff like you could back in Oblivion? Well here you go. Quick tutorial of how to lift items, dual wield weapons and magic, and also how to dash. And it seems I glitch the game a little showing it off. To much power!!!

Leave likes!!! It helps tons!!

Join The Cinnamontoastken Family - http://bit.ly/sr...

▶ Play video
#

i kind of want to put weight as well and mouse speed to affect the object

spring quail
#

Hey, so far I have 2 scenes on my project and I manage to make menu so the player can go from the scene "main menu" to the "level1" using "SceneManager.LoadScene(_mainMenu);". I put the same postprocessing on both scene but when I play and load a new scene, the postprocessing and light effect seems to disappear

#

My bad, postproceesing seems to work, it's only about lightning, don't know why

#

Oh ok I think I fixed it, it needed to generate lightning in the rendering lightning settings, and it creates a file that will store the lightning information and apply it while loading new scenes

stuck jay
#

Does Destroy(this) refer to the script or the GameObject?

keen dew
#

the component

stuck jay
#

I have a script called "HealthRegenOnCollision" that adds HealthRegeneration.cs on collision to the collider, functioning as poison, but I don't know how to prevent the object from adding more than one script so that there'd be only one poison HealthRegeneration script. The only solution I came up with is adding an if statement that prevents the object from adding the script if there's already a HealthRegeneration component. But I want both poison and health regeneration to apply.

hot wave
stuck jay
#

I already have the script, HealthRegeneration

#

Actually I think I found a solution

tall delta
# stuck jay I have a script called "HealthRegenOnCollision" that adds HealthRegeneration.cs ...

So you do want more than one HealthRegeneration on a gameobject. But not more than one type maybe? One way to solve this is to add an ‘type’ enum to the HealthRegeneration then make sure to never add more than one type at a time (or maybe you want to reset / increase the duration of type) if you come into contact with the same source again. You could also add a ‘source’ property to HealthRegeneration and track that the same source can’t add more than one component. As you can see there are many ways to deal with this, but it does depend on the game design.

hot wave
#

i think you could make a dictionary, or if else

#

but I am just a beginner, might not be the best solution

#

personally, I'll add public int itemType; in the health or poison thingy

stuck jay
#

Gonna tag this for the future, it might not work if I decide to implement a health regeneration status

stuck jay
tall delta
faint agate
#

In this clip, there is a bug where if I move too fast in the air. My camera does some kind of glitch, and it pushes up where I can see my body. any tips on why that is and how I can fix?

spiral narwhal
faint agate
#

one second

quick pollen
#

and I have the problem where I can't call the coroutine I want inside of a coroutine

#

I just get An object reference is required for the non-static field, method, or property 'MonoBehaviour.StartCoroutine(IEnumerator)'

#

which makes 0 sense

#

the main issue is that this is a class inside of the main class

#

and that class does not derive from Monobehaviour

languid spire
#

it makes perfect sense, your class does not derive from Monobehaviour

quick pollen
languid spire
#

so pass a monobehaviour as a parameter into a method that starts the coroutines using it

quick pollen
#

i cant really do that

#

idk what you mean by pass a monobehaviour as a parameter, for first

#

should I have a completely different script just for running a single coroutine

languid spire
#

say you have this

class MyClass : MonoBehaviour

void StartSomething() {
   burstPattern.StartSomethingElse(this);
}
and then in BurstPattern you have

void StartSomethingElse(MonoBevaviour mono) {
   mono.StartCoroutine(Shotgun(10));
}
quick pollen
#

actually before I look into this

#

what if I do this

#

just creating the IEnumerator inside of Update

languid spire
#

that makes absolutely no sense

quick pollen
#

so a completely new script

#

for that

#

basically 3 lines of code

languid spire
#

any mono script will do, I mean you must be calling StartCoroutine from somewhere coz it's not in BurstPattern

quick pollen
#

my main monobehaviour/class is PatternHandler

languid spire
#

and that tries to start WaitAfterStart ?

quick pollen
#

ig I can use that?

quick pollen
languid spire
#

so that where you need something like
burstPattern.StartSomethingElse(this);
to pass the PatternHandler as a parameter into a method on BurstPattern

worthy merlin
#

Is there even a point to regions. The one video I watched was suggesting it but honestly, feels like its useless. Why not comment above the text

languid spire
worthy merlin
#

oooooh

#

Ok I see it now. guess we are using that 😄

tall delta
quick pollen
#

I think I got it

languid spire
#

Except async methods cannot call Unity api's which Shotgun is doing

quick pollen
#
        internal void startWaitCoroutine(MonoBehaviour mono, float fireRate)
        {
            mono.StartCoroutine(Shotgun(fireRate));
        }
        internal IEnumerator WaitAfterStart(MonoBehaviour m)
        {
            yield return new WaitForSeconds(timeToStartCT);
            for (int i = burstCount; i >= 0; i--)
            {
                startWaitCoroutine(m, fireRateCT * i);
            }
        }```
#

this is in the class which doesnt have a monobehaviour

tall delta
quick pollen
#

then I do this in the monobehaviour class bp.WaitAfterStart(this);

languid spire
#

you could just have done

internal IEnumerator WaitAfterStart(MonoBehaviour mono)
        {
            yield return new WaitForSeconds(timeToStartCT);
            for (int i = burstCount; i >= 0; i--)
            {
                mono.StartCoroutine(Shotgun(fireRateCT * i));
            }
        }
quick pollen
#

oh

#

lemme try that

#

nothing happens

#

and i have no clue how to even debug it

#

SprayPattern rn is completely irrelevant

icy junco
#

i have a question about making a menu where you can choose ladout is it better if i put the ladout manager on the player prefab or make a new script and just put it in my scene

languid spire
#

not
bp.WaitAfterStart(this);
but
StartCoroutine(bp.WaitAfterStart(this));

quick pollen
#

omg im so stupid

#

i swear if this makes it work

#

it actually did

#

thank you!

#

I just need to figure out why it fired twice

wintry quarry
languid spire
quick pollen
#

well

#

90% basically

languid spire
#

rofl

quick pollen
#

it feels unconventional

languid spire
#

my middle name

quick pollen
#

because if PatternHandler derives from MonoBehaviour, and BurstPattern is a class inside PatternHandler, then why doesn't BurstPattern also derive from MonoBehaviour

#

or at least let me use the coroutine

languid spire
#

not the way c# works

#

BurstPattern does not derive from PatternHandler, it is a class private to it, that's all

quick pollen
#

yeah I get it

languid spire
#

you could if you could make PatternHandler a Singleton then you could do
PatternHandler.instance,StartCoroutine(..);

quick pollen
#

yeah, problem is its not a singleton

#

okay its working flawlessly

#

thank you!

#

I had some jank going on which triggered it to fire twice but i got it

languid spire
#

tbh I'm not a great fan of nested classes unless there is a really good design reason for them being so

quick pollen
#

i just dont want to hardcode patterns

#

so this makes it very easy and fast

languid spire
#

whether those classes are nested or not makes absolutely no difference

swift crag
#

(and that anything outside of the containing type has to refer to it as ContainingType.NestedType

hot wave
hot wave
#

I havent tried yet UnityChanOkay

swift crag
#

An enum is an enumeration type. It's a type with a specific set of values.

languid spire
# quick pollen idk if this counts as really good design reason

let me give you a good example of nested class usage :-
I have a Database class which is responsible for all database access
I have a nested Interface ITable which defines the access for a database table
I have 4 nested classes each implementing ITable
Now it makes no sense for any of those classes to be used outside of the Database class because it is only within that class that they can hold relevant data

swift crag
#

You literally enumerate all of the type's values

#
enum Season
{
    Spring,
    Summer,
    Autumn,
    Winter
}
hot wave
#

ah, it is like dictionary? UnityChanThink

swift crag
#

No.

stuck jay
# hot wave ah, what is enum?

To keep it short, special variable that you assign. Instead of making itemType 0, 1, 2 etc, you can make itemType equal to Heal, Damage, etc

swift crag
#

A dictionary is a data structure, not a type.

#

Season is a brand new type (just like declaring a class or a struct)

stuck jay
swift crag
#

Seasons and colors.

hot wave
#

aah, I need this UnityChanOkay

swift crag
#

Dictionary<Season, int> is a dictionary mapping Season to int

#
seasonDict[Season.Spring] = 123;
#

Season.Spring is a value of the Season type

#

Just like 0 is a value of the int type and "Hello!" is a value of the string type.

hot wave
#

is like, bookpages, then dictionary is like library?

swift crag
#

no, I would not say that

#

well

#

maybe

#

Dictionary<Key, Value>

quick pollen
swift crag
#

Key is like the words in the dictionary, and Value is like the definitions.

#

Dictionary<GameObject, float> stores a float for each GameObject key you give it

#

List and Dictionary are the two most common data structures I use.

#

Lists holds a bunch of things. Dictionaries store a value for each key.

languid spire
golden ermine
#

Hi guys, I have a problem with my Saving system in Unity. When I click on Save button it should make .json file with all game data saved and when I load the game from main menu it should just load me that data but for some reason it doesnt. Here is saving script: https://hastebin.com/share/efobihiduv.csharp and here is GameState script where I save all variables: https://hastebin.com/share/riniyipemi.csharp . Also in Saving script my Debug that says "save" doesnt appear but it worked before and I havent changed anything...

hot wave
#

thank you fen, lord UnityChanCelebrate

#

I will try adding them

swift crag
#

it sounds like your saving script isn't running at all if nothing is being logged

quick pollen
hot wave
#

maybe the code is unreachable in save UnityChanThink

#

ah, but it worked before?

golden ermine
# swift crag "but for some reason it doesn't" is very vague

Im very confused because my saving script worked 5min ago and I saved my game, then I loaded game from main menu and worked perfect, I tried again with different values(different player and cam pos and death count) I saved and loaded and then it loaded save values that I saved before. It didnt overwrite .json file and I dont know why. Then I deleted that .json file and now it wont even save nor load data...

languid spire
hot wave
#

like when I assign 10 as speed in script but set as 15 in unity, or diff case

quick pollen
#

oh, yeah that's valid @languid spire

golden ermine
#

oh okay, what should I do then

worthy merlin
#

Ok so my current heading recently broke in my code. Basically I am trying to get a 0-360 heading where it counts up clockwise and once it hites 360 it returns to zero.

To calculate heading I use:

currentHeading = rb.rotation < 0 ? 360 + rb.rotation : rb.rotation;

but it always goes into the thousands.

hot wave
#

not sure if it is what is causing it UnityChanThink or if that is the case

quick pollen
#

tho most of the logic is inside of those nested classes themselves

#

the only logic except those ones is just the update calling them

languid spire
golden ermine
quick pollen
# languid spire you still have a pretty hefty Update method which kinda gets lost in the mess
    void Update()
    {
        stunTime = EnemyStagger.StaggerInstance.stunDuration;
        if (Input.GetKeyDown(KeyCode.H)) phaseNumber++;

        foreach (BurstPattern bp in phases[phaseNumber].shotgunPatterns)
        {
            if (stunTime > 0f)
            {
                bp.activated = false;
                bp.burstCount = bp.burstsFired;
                bp.started = false;
                StopAllCoroutines();
            }
            else bp.activated = true;

            if(bp.activated && !bp.started)
            {
                bp.started = true;
                print("Test");
                StartCoroutine(bp.WaitAfterStart(this));
            }
        }
    }```
this is essentially all my update method does rn
#

I just need to implement this same coroutine solution for the spraypattern too

#

which should be the exact same length

languid spire
quick pollen
#

I also added a StopAllCoroutines() because I use recursivity in one of my corotuines

#
        internal IEnumerator RepeatPattern(MonoBehaviour m)
        {
            yield return new WaitForSeconds(timeBetweenBursts + burstsFired * fireRateCT);
            for (int i = burstsFired - 1; i >= 0; i--)
            {
                m.StartCoroutine(Shotgun(fireRateCT * i));
            }
            if (loopPattern) m.StartCoroutine(RepeatPattern(m));
        }```
#

this is probably not the nicest way of doing it

#

especially because when a "phase" ends, all firing stops and everything

#

without that stopallcoroutines it just kept on adding more and more RepeatPatterns

queen adder
#

Oh....

swift crag
#

I'd suggest keeping a list of the relevant coroutines.

#

them you can just stop everything in the list

quick pollen
#

well, rn I only have 2

#

so yknow

languid spire
#
internal IEnumerator RepeatPattern(MonoBehaviour m)
        {
           while (loopPattern) {
            yield return new WaitForSeconds(timeBetweenBursts + burstsFired * fireRateCT);
            for (int i = burstsFired - 1; i >= 0; i--)
            {
                m.StartCoroutine(Shotgun(fireRateCT * i));
            }
            }
}
queen adder
#

Would that many coroutines going off be a perfomance issue?

quick pollen
#

it should be fine

queen adder
#

If it ever becomes a problem you can cache the WaitForSeconds

quick pollen
languid spire
queen adder
#

You dont have to new it up every time you start the coroutine, slight perfomance increase in case you ever need it

quick pollen
#

its basically to see if you only want a pattern to run once, or for it to have a delay and repeat once its done

languid spire
quick pollen
#

yes, thats why I used a StopAllCoroutines(); whenever the phase ends

languid spire
#

nasty, cowards way out

quick pollen
#

ikr

#

I could use some bool to check if the phase is going on or not

#

actually

#

i think i have that already

#

oh yeah i do

#

whoops

haughty tinsel
#

Hi I am searching for some help would anyone accept to help me ?

queen adder
#

You dont have to ask to ask. You can just state ur problem brother 🙂

quick pollen
queen adder
#

Ah i remember this

quick pollen
#

it shouldnt have fired those 3 at the end

signal cosmos
#

I have a question related to Zenject. I have a MonoBehaviour script and a service. Where should I implement the movement logic, and what should I do with the basic components (e.g., Rigidbody2D, etc.)? I'm not quite sure how to properly design this. Can you help me, please?

haughty tinsel
#

Thanks. I am doing a project for school but I don't really have the programming skills so I asked chatGPT but now I face a problem that ChatGPT doesn't help me to solve : My Coroutine never stops. I put some Debug.Log as you can see and only the "Desactivation" appears, not the "Reactivation".

haughty tinsel
#

No

swift crag
#

Deactivating a game object kills all coroutines on all MonoBehaviours attached to it.

#

Are you disabling a game object in DesactivateScript?

haughty tinsel
#

public void DesactivateScript()
{
Debug.Log("Desactivation");
peutSeDeplacer = false;
}

quick pollen
#

aw yep

haughty tinsel
#

I make a bool false

quick pollen
#

you deactivate it

swift crag
#

That does not deactivate a game object.

queen adder
#

What does the bool do?

quick pollen
#

oh wait

#

whops

swift crag
#

unless you use that boolean to deactivate a game object elsewhere

#

Share the entire script, please. !code

eternal falconBOT
quick pollen
#

i also dont get why u need a coroutine to change your scene

haughty tinsel
#

if (peutSeDeplacer && !enDeplacement)
{
DetecterDeplacement();
}

quick pollen
#

just send the full thing

#

instead of going on a wild goose chase message by message

haughty tinsel
#

Because my player is doing a weird thing when i change my scene. I think you would remake all my scripts but i Don't really have the time

haughty tinsel
swift crag
quick pollen
#

use a link from above

#

yea

haughty tinsel
swift crag
#

paste your code into the site

#

click the save icon

#

copy the URL of the page (which will have changed) and paste that here

haughty tinsel
#

okay thanks

swift crag
haughty tinsel
#

Sorry for the french variables/functions names

quick pollen
#

id guess it has to do with this

swift crag
#

SceneChanger is probably being destroyed.

#

It needs to still exist after the new scene loads.

quick pollen
#

ok nvm

haughty tinsel
#

It's for another thing

swift crag
#

StartCoroutine runs the coroutine on the object that called StartCoroutine

quick pollen
#

I can semi-understand french bbut also why tf have a function for a function that already exists

swift crag
#

If that object is destroyed, the coroutine stops.

haughty tinsel
quick pollen
#

thats the issue yep

swift crag
#

although it is a bit silly here

swift crag
#

You could even run this on the player object...

quick pollen
quick pollen
haughty tinsel
swift crag
#

Are there many SceneChangers in your game?

haughty tinsel
#

Yes

#

But 1-2 by Scenes

swift crag
#

What you can do is have the SceneChanger call a method on something in DontDestroyOnLoad

#

And that thing then runs the coroutine

#

Maybe call this the "Scene Controller"

haughty tinsel
#

The Scene Controller would stay on all scenes and just runs coroutines ?

swift crag
#

It would be in DontDestroyOnLoad

proven herald
#

I'm looking for a mathematical formula for failure rate based on times fired that would be easily tweakable, thoughts?

swift crag
#

So it would not be in a specific game scene.

swift crag
proven herald
quick pollen
#

oh nvm

swift crag
#

you could just use an AnimationCurve if you want to tweak it interactively

haughty tinsel
swift crag
#

DontDestroyOnLoad(other.gameObject);

haughty tinsel
#

Yes for the player doesn't get destroyed

swift crag
#

What you could do is check if a "Scene Controller" already exists

proven herald
#

maybe just like

shotsFired / likelynessOfFailure / 100 and then cap it

swift crag
#

If one doesn't, create a new one from a prefab and call DontDestroyOnLoad on it

#

You could also do this when the game starts

swift crag
#

This would be a good place to use FindObjectOfType.

SceneController controller = FindObjectOfType<SceneController>();

if (!controller) {
  controller = Instantiate(sceneControllerPrefab);
  DontDestroyOnLoad(controller.gameObject);
}

controller.ChangeScene(targetScene);
proven herald
swift crag
haughty tinsel
#

okay and the Coroutine is in this scripts ?

swift crag
#

now you have a 1% chance of failure at 500 shots

swift crag
haughty tinsel
#

okay thanks i'll test that

swift crag
#

you just need to make sure the object you run the coroutine on still exists

swift crag
#
player.StartCoroutine(...)
haughty tinsel
#

oh

swift crag
#

That might actually be the best way to do this

haughty tinsel
#

Okay

swift crag
#

As long as the player object is never deactivated

#

Find the player and start a coroutine on them

#

StartCoroutine is a MonoBehaviour method. You can call it on any MonoBehaviour.

haughty tinsel
#

Sorry but what's a MonoBehaviour ?

swift crag
#
public class SceneChanger : MonoBehaviour
#

It is the class you inherit from to make your own components.

haughty tinsel
#

Oh okay

#

Thanks

quick pollen
#

a is the likeliness of failure while x is the number of attempts

#

y is the chance of failure between 0 and 1 (100%, 0%)

haughty tinsel
#

I can't access the Coroutine which is on the player from SceneChanger

swift crag
#
player.StartCoroutine(ChangeScene());
#

It doesn't really matter where you got the coroutine from.

#

It matters who you give it to with StartCoroutine

haughty tinsel
#

I a

#

I am really sorry but I don't understand how to do it I get the error "'GameObject' does not contain a definition for 'StartCoroutine' and no accessible extension method 'StartCoroutine' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)"

grizzled zealot
#

I am trying to rotate a vector to match the gameobject's rotation. It should be Vector3 posOneAhead = transform.rotation*Vector3.up; but I get a compile error that I cannot multiply Quaternion with a Vector3.

wintry quarry
#

I suspect your error is coming from a different line of code.

#

Not sure what you are asking to fix, but also this isn't a code question.

tall delta
grizzled zealot
#

Basically, one step ahead of what it's facing now.

tall delta
#

posOneAhead = transfrom.position + transfrom.forward;

wintry quarry
#

or what simex wrote

grizzled zealot
wintry quarry
#

or TransformPoint(Vector3.left)

ivory bobcat
#

new position = position + forward * speed

haughty tinsel
#

@swift crag Are you here ?

ivory bobcat
swift crag
#

A component you put on the player object.

haughty tinsel
#

No

#

I have a tag

polar mica
#

Hey, i have a little question, I want to make a Ball Game and every ball should have its own float variable, but just use one script on a Prefab. And if i put the Variable up, all Balls get this Number, but i want that just one specific one has it. Can someone help at this?

swift crag
wintry quarry
#

you did something wrong

haughty tinsel
swift crag
#

Any of your components would work.

swift crag
#

also, if you don't want to run the coroutine on the player, you can just use DontDestroyOnLoad to prevent SceneChanger from being destroyed

#

and have it destroy itself when it's done

wintry quarry
# polar mica

this script doesn't look like it lives on each ball

#

this looks like a singleton

haughty tinsel
swift crag
wintry quarry
# polar mica

If it is on each ball it doesn't matter much because if your other code is using instance to access it, it's all only accessing that ONE instance.

rose galleon
#

Like this?
transform.position = new Vector2(dashPower, 0);

swift crag
#

Only classes that inherit from MonoBehaviour have that method.

haughty tinsel
swift crag
haughty tinsel
#

But the GameObject will stay between the scenes for some time

polar mica
wintry quarry
#

How and when are you trying to read the Value number and what are you trying to do with it?

frigid sequoia
#

I have been locked not knowing how to write on a method for a while. How do I... increase a value over time given the time and the value I want to increase but do it on a exponential rate?

wintry quarry
#

so something like:

float rateOfRateIncrease = 1; // acceleration in units/s^2
float rate = 0; // rate of increase in units/s
float currentValue = 0;

void FixedUpdate() {
  currentValue += Time.deltaTime * rate;
  rate += Time.deltaTime * rateOfRateIncrease;
}```
haughty tinsel
#

Thanks Fen it was the problem you were thinking but i, now, have another problem

languid spire
#
value += increment;
increment *= increment;
swift crag
#

An exponential function's rate of change is proportional to its current value.

haughty tinsel
#

https://gdl.space/iconamidaz.cpp I changed my script and now I have this problem : "NullReferenceException: Object reference not set to an instance of an object
SceneChanger+<AttendreChangementScene>d__5.MoveNext () (at Assets/Scripts/SceneChanger.cs:53)"

wintry quarry
#

then:

void FixedUpdate() {
  float rate = someRatio * currentValue;
  currentValue += rate * Time.deltaTime;
}```
buoyant rune
#

i literally dont undestand why it doesnt work

wintry quarry
#

Have you added any logs to make sure any of the code is actually running?

buoyant rune
#

havent added logs no

wintry quarry
#

that's step 1

#

add logs in OnTriggerEnter. Log the object you collided with. log its tag. Log whether it has the Health component on it. etc.

frigid sequoia
polar mica
languid spire
worthy merlin
#

How do you get a rigidbody Velocity to convert to a Vector3 slerp. I need the Vector2 velocity value to become its 3rd argument

wintry quarry
wintry quarry
wintry quarry
haughty tinsel
wintry quarry
worthy merlin
#

So my goal is to make the Main Camera follow my player object. While I got the player down it is struggling to keep up with its velocity, so I wanted to make it follow the player by matching the players velocity

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

public class CameraFollow : MonoBehaviour
{
    public Vector2 FollowSpeed;

    public AdvancedPlayerMovement status;
    public Transform target;

    // Update is called once per frame
    void Update()
    {
        FollowSpeed = status.currentVelocityRaw;
        Debug.Log(FollowSpeed);
        Vector3 newPos = new(target.position.x, target.position.y, -10f);
        transform.position = Vector3.Slerp(transform.position, newPos, FollowSpeed*Time.deltaTime);
    }
}

wintry quarry
haughty tinsel
#

Okay Fen I am really sorry for the waste of time but it didn't fixed my problem to have a coroutine...

wintry quarry
#

not position vectors

swift crag
worthy merlin
wintry quarry
haughty tinsel
#

But the Coroutine activates ect it's not the problem. My Player does the weird thing anyway

wintry quarry
#

Vector3.SmoothDamp would be good

worthy merlin
#

Cinemachine 👀

wintry quarry
#

but yeah - use cinemachine

swift crag
#

Cinemachine solves most of your camera problems for you.

haughty tinsel
wintry quarry
#

you will get this behavior in a few clicks with cinemachine

worthy merlin
#

roger

frigid sequoia
quick pawn
#

I have a question - I've tried to hardcode a value into a script for turnSpeed, but it's not updating outside of the script. Is it because it's set to public and you can edit it from the gui?

worthy merlin
#

The one downside of youtube tutorials, they don't provide alternatives

haughty tinsel
#

@swift crag Could I add you, I could show you what the weird thing my player does

swift crag
#

No. Just describe the problem or record a video.

haughty tinsel
#

okay

wintry quarry
#

If you want to hardcode it, don't serialize it

quick pawn
#

Ok. Are there any security issues with making variables public/is it a bad practice? Or will whatever my scene settings are set to be the ones pushed out when you compile and publish a game?

#

I've always been taught to set variables to private and put a setter/getter to change the variable

wintry quarry
#

Yes the settings in the scene will go out in the build

haughty tinsel
#

@swift crag My game is not beautiful I know but the problem is happening the second time i take a scene changer

quick pawn
wintry quarry
night mural
swift crag
#

yes, it's a design issue, not a security issue

haughty tinsel
swift crag
#

You will need to explain.

quick pawn
#

Ok, thanks for your help @wintry quarry @swift crag

haughty tinsel
#

The first time it spawns normally but the second time after spawning it moves to its ancient position and I don't understand why

haughty tinsel
swift crag
#

Maybe it's always putting you where you were supposed to appear in the old scene

#

like you're positioning the player before you change scenes

haughty tinsel
#

Okay but if in my scripts i put the ChangeScene before the player positioning it doesn't change anything

spiral narwhal
# haughty tinsel What should I do ?

New to the convo, but I believe Fen means that you have something like this pseudo code:

SceneManager.LoadScene(...)
MovePlayer(...)

Check if the behaviour you happen after loading the scene is in a Start method

haughty tinsel
#

You want my script ?

spiral narwhal
#

Sure

haughty tinsel
languid spire
# haughty tinsel https://gdl.space/ezobidahif.cpp

OK, lets look at this

private void ChangerScene()
    {
        // Charge la scène
        SceneManager.LoadScene(Scene);

        StartCoroutine(AttendreChangementScene());
    }

what do you expect of the game object running this script when that code executes?

haughty tinsel
#

It loads the scene

languid spire
#

and then?

haughty tinsel
#

And the start the coroutine

spiral narwhal
#

Why is the code in French

haughty tinsel
languid spire
#

but it does not exist anymore because you've just loaded a new scene

haughty tinsel
#

No i changed this so the gameObject stay in the scene

#

but it doesn't fix the problem

languid spire
#

so this is on a DDOL object?

haughty tinsel
#

DDOL ?

languid spire
#

Dont Destroy On Load

haughty tinsel
#

yes

#

I destroy it after with Destroy(gameObject);

languid spire
#

Ok, and when you destroy a game object you also destroy it's coroutines

spiral narwhal
#
  1. You have made it DDOL on TriggerEnter, if colliding with a player. Usually this is done in Awake
  2. Why do you need to DDOL your objects in the first place? Why don't you perform whatever AttendreChangementScene does in Start?
haughty tinsel
#

yes but the coroutines have already been done

languid spire
#

unlikely

buoyant rune
swift crag
#

my understanding is that the coroutine is completing properly

#

the player is just appearing in the wrong place?

haughty tinsel
haughty tinsel
swift crag
#

I originally suggested just making a SceneController that is created once and handles all of the scene changes

swift crag
quick pollen
spiral narwhal
#

Oh it's used to load another scene? I thought it reloaded the current scene

haughty tinsel
#

I can give you the script but the spawn point is the position of the exit point

spiral narwhal
haughty tinsel
spiral narwhal
#

It is used to reload the scene?

haughty tinsel
#

No to change the scene

haughty tinsel
#

to load another one

spiral narwhal
#

Okay, yes then you do need DDOL

quick pollen
spiral narwhal
#

You want to keep the scene changer, and something else?

quick pollen
#

this is 3d but its the same idea

haughty tinsel
quick pollen
#

I use this one for parrying projectiles

haughty tinsel
quick pollen
#

projectiles have a check in them, where if they touch an object with the "Shield" tag, they get parried

spiral narwhal
haughty tinsel
#

My problem is the player moving to its ancient poisition when i change the scene

spiral narwhal
#

So where do you set the position after loading the new scene

buoyant rune
haughty tinsel
polar mica
#

The Ball falls down and hits Walls. Everytime the Ball hits the Wall, the variable should add 1 and save it, like a cache. When it is on the Ground the Cache should add to a Money System, which i already have. But if i spawn 2 Balls the Value gets reset

spiral narwhal
spiral narwhal
haughty tinsel
languid spire
quick pollen
#

effect

haughty tinsel
quick pollen
buoyant rune
haughty tinsel
buoyant rune
#

if thats what u mean

spiral narwhal
#

Okay this is way too much code I don't even understand the language of, so basically I would do this:

  1. You want something to remain after loading, you use DDOL on Awake
  2. Whatever exit you take stores whatever variable you need in the DDOL object
  3. Unity's Start method is called when the scene reloads
  4. You use the variable you set to position the player wherever you like
quick pollen
#

it just uses Raycasts

spiral narwhal
buoyant rune
#

i just dont know how to implement it

haughty tinsel
quick pollen
#

basically it draws a line from the enemy forward, and checks if the line touches the player

languid spire
quick pollen
spiral narwhal
quick pollen
#

howd you add the enemy attack script if you cant add the player attack script tho

quick pollen
#

whats telling your character to start the attack animation

#

which part of the code

swift crag
buoyant rune
#

within my player controller script

#

when i left clcik it plays the animation

spiral narwhal
buoyant rune
quick pollen
spiral narwhal
#

So what happens afterwards and what is supposed to happen?

buoyant rune
haughty tinsel
haughty tinsel
languid spire
haughty tinsel
swift crag
quick pollen
languid spire
quick pollen
#

or that chatgpt knows how to code

#

it just fetches information from the internet

spiral narwhal
quick pollen
#

do that with the hitbox

quick pollen
#

lemme link it for u

spiral narwhal
#

Just joined the convo ^^

quick pollen
#

the enemy uses a raycast

buoyant rune
quick pollen
#

all good :)

quick pollen
buoyant rune
#

oh okay

haughty tinsel
#

So nobody wants or know how to solve my problem ?

rich adder
spiral narwhal
#

The problem is you wanting to code a video game without knowing how to code

rich adder
#

even worse, its for school

spiral narwhal
#

If you wanted to learn, sure...

#

But you don't even want that

rich adder
#

they apparently don't want to do their own school work

buoyant rune
grizzled zealot
#

I want to implement a snap-to function where another game object gets snapped into a grid and then glued to another (FixedJoint2D). In the OnCollision2d function, I update the position of the transform and then immediately add the FixedJoint2D. It seems that I have to give the gameObject one more frame to update before adding the FixedJoint. How can I do that?

rich adder
haughty tinsel
#

It's not that I don't know how to code I know some basics just not for C# In Unity and for bugs I don't know where it comes from some code of theses cripts are made by myself

rich adder
haughty tinsel
#

I just wanted help by someone who knows more than me

quick pollen
spiral narwhal
#

Then why code your game in C# and Unity in the first place? I'm so confused

haughty tinsel
#

with Unity Learn

quick pollen
buoyant rune
#

yep did that now

quick pollen
#

goodgood

spiral narwhal
#

So you do want to learn. Then learn, that's what I said ten minutes ago. It's no good trying to get us to magically get your AI code to work. If you truly want to learn, go to YouTube and learn. I'm sure there are great materials pinned somewhere here as well

buoyant rune
spiral narwhal
#

That's the last I'll say in regards to that

rich adder
quick pollen
#

that one draws a Square in front of the enemy, and if it finds the player inside of it, it tells it to get hit

#

its not great from what I can tell, based off of the fact that it'll deal damage to the player even if the square hits a wall or the ground
actually not even that, but if it hits a wall or the ground you'll get an error in the console
it doesnt check if it hit the player, it checks if it hit anything

haughty tinsel
#

I am wrong okay, i maybe shouldn't have asked ai to do it but when I came here to ask questions it wasn't for the firt problem i faced. I solved other problems by myself and ChatGPT was not helpful for everything. I came here after hours of thinking and searching but nothing worked

rich adder
quick pollen
#

oh wait am i being stupid

#

why is this a thing

spiral narwhal
quick pollen
#

isn't this something that should be in Start or serialized?

rich adder
#

not for a raycast hit

quick pollen
#

oh I think I get it yeah

#

but itd be simpler to check if the touched object is the player or not, if it is, return true, else return false

#

o well

buoyant rune
#

I think for now i;ll keep it hjow it is

quick pollen
#

but sure I suppose

#

tho for player attacking id suggest using the trick I said above

haughty tinsel
# rich adder not for a raycast hit

First you need to know that I didn't have to make a game it could be anything that people would see to sensibilize them to something in link with food/health. I chose to make a game because It's what I want since i am a child and I thought that i could do it with the help of an AI it wouldn't be that difficult. And it is not my only problem is this one otherwise I would probably have finished.

quick pollen
tall delta
rich adder
iron hull
#

Hey lads, so im trying to spawn a bunch of rigidbodies ontop of eachother in a circle radius and have them push out of each other, is there a way to get rid of these overlaps someway through settings or would i be better off coding it? hmjj

haughty tinsel
quick pollen
#

I'm still in high school, they dont teach us jack shit

#

yet u can still learn

rich adder
#

sounds like you need a simpler project

haughty tinsel
quick pollen
spiral narwhal
#

You said it yourself, you have severely underestimated the amount of work making video games entails. Choose something else for your project

rich adder
haughty tinsel
quick pollen
haughty tinsel
buoyant rune
quick pollen
buoyant rune
#

oof

grizzled zealot
#

What is a good way to make a rigid connection between two gameobjects that also transfers rotation? Using FixedJoint2D is ok, but it doesn't transfer rotation to the other gameobject.

buoyant rune
#

uk teaching for computer science at least before university is really bad

rich adder
quick pollen
rich adder
#

it wouldd literally go over your head anything we try to fix

spiral narwhal
rich adder
#

for example.. Comparing floats with == will never yeild a good result

#

floats are not precise

#

therefore are diffcult to get a == to work

#

all those clearly wasnt explained by spambot :

quick pollen
haughty tinsel
quick pollen
#

isnt your problem with like scene loading or smth

haughty tinsel
#

No

quick pollen
#

also what math

spiral narwhal
#

Oh sorry I interpreted that "they don't teach us" as such

haughty tinsel
quick pollen
rich adder
#

or just use Mathf.Approximately or >= | <=

haughty tinsel
quick pollen
#
        // Prints 10
        Debug.Log(Mathf.RoundToInt(10.0f));
        // Prints 10
        Debug.Log(Mathf.RoundToInt(10.2f));
        // Prints 11
        Debug.Log(Mathf.RoundToInt(10.7f));
        // Prints 10
        Debug.Log(Mathf.RoundToInt(10.5f));
        // Prints 12
        Debug.Log(Mathf.RoundToInt(11.5f));
spiral narwhal
#

Now we're back to mouth feeding haha

quick pollen
#

i think the IDE also tells u in a nutshell what some functions and such do

quick pollen
rich adder
#

they have no idea what they want

quick pollen
#

i could kinda guess

#

more info never hurts tho ig

haughty tinsel
quick pollen
haughty tinsel
#

I think my problem is that the player has not finish its movement when it collides the Scene changer so the scene is changed but the player still move from where it spwaned to where it should moved

quick pollen
#

tho I have to go to tournaments and such to actually get to be taught the "not braindead" stuff

#

like this is the first time I actually got a bit stuck on a lecture in informatics

#

there's also Backtracking which fucks with my brain

#

its a simple concept I just can't visualize it in code

gaunt ice
#

you probably know you have to understand recursive first

public dfs(State state)
```what you have now, and what you can do next
grizzled zealot
#

I used transform.setParent(go.transform), but the two rigidbodies still behave independently. Is there something else I have to set to then make both behave in sync?

gaunt ice
#

yes

quick pollen
#

ah ok

#

whats dfs first things first

#

I know what recursivity means

#

I've been using it for a while now and I got comfortable with it

haughty tinsel
quick pollen
#

also I'm doing stuff in c++ so I'm not gonna get much into this topic

#

it was more of a thing to mention than an actual relevant issue

rich adder
gaunt ice
#

depth first search, since backtracking is travelling on the recursive tree

quick pollen
#
        internal IEnumerator RepeatPattern(MonoBehaviour m)
        {
            yield return new WaitForSeconds(timeBetweenBursts + burstsFired * fireRateCT);
            for (int i = burstsFired - 1; i >= 0; i--)
            {
                m.StartCoroutine(Shotgun(fireRateCT * i));
            }
            if (loopPattern && activated) m.StartCoroutine(RepeatPattern(m));```
I actually used recursitivity today, right here, so yknow
haughty tinsel
grizzled zealot
rich adder
quick pollen
haughty tinsel
rich adder
eternal falconBOT
haughty tinsel
#

Thanks

quick pollen
#

rn im looking into permuations without the formula

#

with divide et impera

#
    private static void permute(String str, int l, int r) 
    { 
        if (l == r) 
            Console.WriteLine(str); 
        else { 
            for (int i = l; i <= r; i++) { 
                str = swap(str, l, i); 
                permute(str, l + 1, r); 
                str = swap(str, l, i); 
            } 
        } 
    } ```
this is the method I see for it pretty often
haughty tinsel
gaunt ice
#

strings have length so the r parameter is redundant, just check if l>=.length

#

"a bit" out of topic

rich adder
quick pollen
#

oh wait

#

nvm yea ur right about that

#

that code is from geeksforgeeks

#

just wanted to show an example

#

ill try smth like "all paths from top left to bottom right in a 2d matrix"

haughty tinsel
rich adder
#

you have to show that VS is configured

haughty tinsel
gaunt ice
#

not divide and conquer
the all paths problem is divide and conquer and can be solved by dp. btw the topic should end right now,, not related to unity anymore

rich adder
#

you have a compiler error

haughty tinsel
#

Oh Thanks that's why i din't had the colors...

rich adder
#

right

quick pollen
haughty tinsel
rich adder
#

you can click here now it will show you where is the error

haughty tinsel
#

it was a semilicon if it's the right name ';' this thing missing

#

I don't have anymore

opal portal
#

hello there, donno if i should ask this here or otherwhere, but here's my question

im animating a gameobject with a position animation, but even when the animation is not playing, the gameobject (player) cant move through inputs with rb, is there anyway to prevent that?

swift crag
#

The animator will control every property that's animated by any state.

#

Maybe this would be a place to use root motion.

#

It pushes the animator's transform around instead of directly controlling it, basically

opal portal
#

oh nice

swift crag
#

I have not tried using this with generic animations before, though. Only with humanoid ones

#

But it sounds like the process is roughly the same either way

opal portal
#

gotcha, i'll give it a try, tnks

swift crag
#

alternatively, turning off the animator should make it give up its control

#

I want to say it will, at least...

opal portal
#

meh, i would prefer to make the movement manually with scripts or other way

#

but i think root motion will work

swift crag
#

or is it just there to make your character wiggle around

opal portal
#

nop

swift crag
#

Okay, then there's a much simpler fix

#

Parent the animated object to an empty

#
  • Player
    • Visual
opal portal
#

just like a little effect when swinging a sword

swift crag
#

move the Player around

#

the Visual can do whatever it wants

opal portal
#

but this wont let me move the collider, will it?

swift crag
#

Which collider?

#

The sword collider?

opal portal
#

the player collider

swift crag
#

Put the player collider on the Player object

#

(and the character controller / rigidbody)

opal portal
#

kk gotcha

#

well yeah makes sense xd

quick pollen
queen adder
#

Can we avoid GetComponent's Garbage(40B)?

rich adder
#

Serialize it in the inspector?

queen adder
#

Can't notlikethis

#

It is uh runtime object

quick pollen
rich adder
#

I use TryGetComponent which doesnt allocate when not found but idk if that would help here at all

queen adder
quick pollen
queen adder
quick pollen
#

is that like a youtube challenge

swift crag
#

it gives you an invalid unity object

#

actually, does it even produce garbage when it succeeds?

rich adder
#

yea thats wat im confused on (i havent tested profiled this myself)

queen adder
#

I did it for you, it does

rich adder
#

i recall also reading that the in-editor behavior is different than it does in build,
I could be wrong though. It was a while back

queen adder
haughty tinsel
#

Hi it's me again sorry for before and thanks at everyone who tried to help me I understood my mistakes and I won't use AI again. I'm here because I want to make a PNJ ask questions an let the player answer. At the end of the questions, the PNJ make a review of what is good or not according to the player answers. I'd be thankful for any help.

haughty tinsel
#

NPC

#

PNJ is in french sorry

rich adder
#

You would need to learn strings and maybe dictionary

#

and how to create a c# object

#

probably need arrays too

haughty tinsel
#

Hum okay thanks

quick pollen
haughty tinsel
#

personnage non-joueur yes

quick pollen
#

right mb lol

haughty tinsel
#

np

quick pollen
#

review of what is good or not according to the player answers
wdym here

rich adder
#

checking the answers against the questions

haughty tinsel
#

Hum I can explain but I found a video after posting this message that explains what I need sorry it's mb

quick pollen
rich adder
#

yes they would store all the answers then check them

haughty tinsel
quick pollen
#

lmao imagine
what's 1 + 2

  1. 2
  2. 3
  3. 1
#

2? ur stupid

haughty tinsel
#

So it gives advices based on the answers of the players

quick pollen
#

3? ur also stupid

#

1? ur gone

rich adder
quick pollen
#

four

#

i cant type the number 4 lmao

#

or maybe cast error

rich adder
quick pollen
#

in python its even more fucked tho

queen adder
rich adder
#

uh oh potty mouth

brazen rivet
#

What would be the easiest way to make a super simple system of 3 hearts. Something where I could easily add and remove hearts. The old way I used to do it was a hardcoded system, having each heart be its own GameObject, but that system really sucks.

quick pollen
spiral narwhal
#

int hearts

rich adder
#

for UI just use an Image component inside a horizontal stack

brazen rivet
wintry quarry
rich adder
#

the basic types are the best to learn first and foremost

brazen rivet
brazen rivet
wintry quarry
#

But yeah use the UI tools

brazen rivet
#

I'll check them out

wintry quarry
#

You don't need to manually position them

brazen rivet
#

Yeah that'd make life easier

#

I'll checkout the documentation and come back if I have any questions

rich adder
north merlin
#

why does this coroutine keep updating without stopping? void Start()
{
StartCoroutine("FindTargetsWithDelay", visionCheckFrequency);
}

IEnumerator FindTargetsWithDelay(float delay)
{
    while (true)
    {
        yield return new WaitForSeconds(delay);
        FindEnemy();
    }
}
wind raptor
#

Is there something equivalent to "Awake" that I can call for inactive components?

north merlin
#
    {
        StartCoroutine("FindTargetsWithDelay", visionCheckFrequency);
    }

    IEnumerator FindTargetsWithDelay(float delay)
    {
        while (true)
        {
            yield return new WaitForSeconds(delay);
            FindEnemy();
        }
    }```
#

why does this coroutine keep updating without stopping?

swift crag
#

yes, you can just do this:

StartCoroutine(FindTargetsWithDelay(visionCheckFrequency));
rich adder
#

You can call functions on script that is on disabled object, as long as you have the reference stored @wind raptor

swift crag
#

I would check the value of visionCheckFrequency

#

If it's serialized (i.e. not private), look in the inspector

north merlin
#

it does what i want but i just want to understand y

undone rampart
north merlin
#

the while true?

undone rampart
#

ye

summer stump
#

That means loop forever

north merlin
#

i take it unity defaults to false

rich adder
north merlin
#

typo

summer stump
rich adder
#

while loops have nothing to do with unity

#

its a c# thing

summer stump
#

while loops run when the condition is true

#

If you pass it true, the condition will always be true

brazen rivet
north merlin
#

thnx. iunderstand now

summer stump
#

I think you don't even want a loop at all, right? So remove the while entirely

rich adder
north merlin
#

no i want the loop. Its my ai vision

wind raptor
# rich adder You can call functions on script that is on disabled object, as long as you have...

I'd rather not require something else to call Awake on it if possible. This is my class.

public class PuzzleDetail : MonoBehaviour
{
    public static List<PuzzleDetail> Instances { get; private set; } = new List<PuzzleDetail>();
    private void Awake()
    {
        Instances.Add(this);
        Debug.Log(gameObject.name + " puzzle detail added");
    }

    public void Select()
    {
        foreach(var p in Instances)
        {
            p.gameObject.SetActive(false);
        }
        this.gameObject.SetActive(true);
    }
}

Is there not any function like Awake or Start that can automatically be called on startup?

#

Even if disabled/deactivated?

rich adder
summer stump
north merlin
#

I just wanted to know why it worked. If i understand it i can apply it

rich adder
#

if the object is disabled how do you expect anything from itself to run..

wind raptor
rich adder
swift crag
#

I do wish you could pass arguments whilst instantiating it

wind raptor
swift crag
#

C++ can do that! (it's mildly frightening)

queen adder
rich adder
wind raptor
#

Not a singleton. I have a reference to "Instances", not Instance.

#

GameObject is inactive

rich adder
#

you could potentially do that, just have the object be enabled and script itself is disabled

queen adder
#

That is what i am saying. A singleton can stay enabled and others can be disabled

rich adder
#

ah yeah you could use the attribute

queen adder
#

But be aware that attribute will work for static methods only

autumn tusk
#

set my cam to late update

#

i think whats going on is the scripts fighting with unity's physics engine

wintry quarry
autumn tusk
#

heres the crosshair code

wintry quarry
#

Something more is going on

autumn tusk
#

heres the shotgun code

wintry quarry
#

you have this thing as a child of the ball or something