#💻┃code-beginner

1 messages · Page 374 of 1

mystic steeple
#

I don't want the coroutine to be running every 0.05 seconds or what not

ivory bobcat
#

Have you verified that it's yielding non stop - no your eyes or it running slow does not verify this.

mystic steeple
#

Bro my eyes verify it

#

Literally the FPS verifies it

ivory bobcat
#

Does it operate more than once per frame? Print the number of iterations before the yield statement is called.

#

Alright, I can't help you since you aren't willing to debug 👋

mystic steeple
#

k bye

#

So if anyone else wants to explain how to yield my coroutine properly, let me know please. Thanks

grave frost
#

is this the same code you still have?

mystic steeple
grave frost
#

so you only do one pixel per frame then since you yield return null every time that method is called

mystic steeple
#

sec

#
    private IEnumerator FillWithinPaintedAreaCoroutine(int x, int y, int maxX, int maxY)
    {
        if (x < 0 || x >= maxX || y < 0 || y >= maxY)
        {
            yield break;
        }

        if (Map.instance.GetBiome(x, y) == (Biome)_type)
        {
            yield break;
        }
        
        Map.instance.SetBiome(x, y, (Biome)_type);
        UpdateTile(x,y);

        // Recursively fill neighboring pixels
        yield return FillWithinPaintedAreaCoroutine(x, y + 1, maxX, maxY); // up
        yield return FillWithinPaintedAreaCoroutine(x, y - 1, maxX, maxY); // down
        yield return FillWithinPaintedAreaCoroutine(x + 1, y, maxX, maxY); // Right
        yield return FillWithinPaintedAreaCoroutine(x - 1, y, maxX, maxY); // left
    }```
#

The yield null part was removed too, everything in that block

#

What does "yield return" do exactly? I think understanding that would help a lot

timber tide
#

so you want yield till end of an extended amount of frames?

mystic steeple
#

Yeh basically, I want it to fill as many in 0.2 seconds as it can

grave frost
#

yield return returns a value from the iterator

mystic steeple
#

Right now it seems to yield on every single tile, from my recordings

timber tide
#

stopwatch usually accurate but I hear coroutines may not

#

so unless you do it per frame basis, I don't think you may get the exact times you want

hallow delta
grave frost
#

does yield break wait a frame in this instance @timber tide, since it will be yield breaking out of one of the yield returns. Or does unity only wait a frame when its null?

timber tide
#

but instead of using stopwatch, just try wait for seconds for the heck of it

mystic steeple
#

And I don't yield anywhere else

mystic steeple
grave frost
#

mao I think the problem is that it's too slow not that it should be slower

mystic steeple
#

^ Yeh basically, because it does 1 tile every frame, it's being bottlenecked by needing to run all the Unity / renderer stuff every frame

#

So my tile generation is locked to my FPS (basically)

hallow delta
grave frost
#

what's your fps?

mystic steeple
#

sec, I'd need to add some code for that

timber tide
#

right, then you need to do it by frame time then

grave frost
mystic steeple
grave frost
#

there's a stats button you can click in the game view

mystic steeple
#

Ohh

grave frost
#

just send a screenshot of that

mystic steeple
#

Yeh my bad, see I generally make tools to create game stuff inside play mode 😅 So I forgot about the unity stats

#

sec

#

so yeh, 120 fps

#

with dips when it hits the end of a line

#

So the coroutine is yielding 120 times per second

timber tide
#
float waitTime = 0.20f;
float elapsedTime = 0f;

IEnumerator YourCoroutine(float waitTime)
{
  while (elapsedTime < waitTime)
  {
      elapsedTime += Time.deltaTime; //whoops how did I miss this
      yield return null; 
  }
}```
Basically just an update loop ;p
#

oh, but you may want to wait after you do a line then do the wait?

#

Not sure of the requirements

mystic steeple
#

Would I need 2 coroutines? Seeing as my current coroutine is a recursive loop?

grave frost
timber tide
#

I think you need a bool that says once you're done -> then wait

mystic steeple
mystic steeple
grave frost
mystic steeple
#

I'm just not sure how I get my recursive loop into a while...

mystic steeple
grave frost
#

i meant yielding once per frame sorry

mystic steeple
#

Well it has to yield once per frame? Otherwise it'd not be running?

#

That's how coroutines work no?

grave frost
#

i don't know, as far as I know it shouldn't yield once per frame unless yield return null is called.

mystic steeple
#

Don't coroutines naturally block a frame until it either yields or finishes?

ivory bobcat
timber tide
#

coroutines are just update loops, but they allow you to pause execution

#

and return to where it has left off sometime later

mystic steeple
grave frost
#

Coroutines are just code eexecuting, you can execute as much code as you want in one frame. Yield return null tells it to wait a frame. You can yield return other things that tell it to wait for other things too, like yield return new WaitForEndOfFrame() and yield return new WaitForSeconds(2f).

#

what I'm saying is you don't have a yield return null so I'm unsure as to why it's waiting a frame to continue the work.

mystic steeple
#

So the thing is, that coroutine is exactly just the code I showed you... Other than the 1 time it's called

mystic steeple
timber tide
#

only thing that will lock the frames is if you don't return in a while ;p

grave frost
mystic steeple
timber tide
#

oooh huh

#

why can't ya just do it in an update loop and just use a timer variable ?

mystic steeple
#

Not sure how I'd write that though...

#

Seeing as it's independent and just kinda chains on itself to check all blocks, I feel that would be a pain to keep track of in normal code

#

How do I keep track of what blocks need to be checked?

#

It seems complicated

mystic steeple
#

That's why I made it a coroutine in the first place

#

Sorry, I initially misunderstood your question

#

The game would freeze for like 8 seconds and then error

timber tide
#

so at what point is the recursion done such that you can get to the next frame

mystic steeple
#

Erm... instead of calling them like

" yield return FillWithinPaintedAreaCoroutine(x, y + 1, maxX, maxY); // up
yield return FillWithinPaintedAreaCoroutine(x, y - 1, maxX, maxY); // down
yield return FillWithinPaintedAreaCoroutine(x + 1, y, maxX, maxY); // Right
yield return FillWithinPaintedAreaCoroutine(x - 1, y, maxX, maxY); // left"

Should I be calling them as their own coroutines?

#

Or would that cause issues? I duno

#

I feel like that'd be bad hehe

grave frost
#

I guess it waits a frame because enumerators return null once they're past their end, so it returns null once when you break? You might be able to make it faster, just remove the yield breaks and instead check the inverse of what you want and put the recersive functions inside that. So maybe try:

    private IEnumerator FillWithinPaintedAreaCoroutine(int x, int y, int maxX, int maxY)
    {
        if (!(x < 0 || x >= maxX || y < 0 || y >= maxY)
              && Map.instance.GetBiome(x, y) != (Biome)_type)
        {

          Map.instance.SetBiome(x, y, (Biome)_type);
          UpdateTile(x,y);

          // Recursively fill neighboring pixels
          yield return FillWithinPaintedAreaCoroutine(x, y + 1, maxX, maxY); // up
          yield return FillWithinPaintedAreaCoroutine(x, y - 1, maxX, maxY); // down
          yield return FillWithinPaintedAreaCoroutine(x + 1, y, maxX, maxY); // Right
          yield return FillWithinPaintedAreaCoroutine(x - 1, y, maxX, maxY); // left

        }
    }
mystic steeple
#

yield break*

#

Rider says it breaks by default, it doesn't return null

grave frost
#

I don't think you need yield break like this, but perhaps yield break is causing the enumerator to return null to the coroutine, which causes it to wait a frame.

mystic steeple
#

Also I do like the code change in general, a lot cleaner

#

I will give that a go

#

No, still acts the same

#

I don't get it...

grave frost
#

There's no way that waits frames

timber tide
#

I feel like you should figure out how to get it to work in update because stackoverflow usually implies it's not exiting at all.

grave frost
mystic steeple
#

I think stackoverflow is more that it just didn't exit soon enough, not that it doesn't exit at all

timber tide
#

idk, I've done some large freaking binary trees in c# that took minutes and never really gotten that error

mystic steeple
#

Did it have a massive recursive stack? Because the stack will be tracking each one of those calls

grave frost
#

it could be caused by something they're doing in one of those other functions if they're recursively calling this forever and creating new structs, since those won't leave the stack if it's just created in a local function like that.

timber tide
#

haven't tried anyting too heavy computated with unity though so maybe there's more to it

mystic steeple
#

Would it matter what my function call returns?

#

UpdateTile is void... SetBiome is void too

#

nvm

grave frost
#

For exmaple, I believe this code:

  
  List<Vector3> list = new();

  while(true)
  {
    list.Add(new Vector3(0, 0, 0));
  }
}
```could potentially cause a stack overflow, if the vectors don't move to the heap. I'm not sure if they would or not in this case. So I think it depends on what's happening in those other functions as to why there's a stack overflow exception.
mystic steeple
short hazel
#

Correct, happens when methods call themselves over and over, without an exit condition

mystic steeple
#

Yeh

#

SPR2, by any chance... can you see why this coroutine keeps constantly yielding and waiting for the next frame?

    private IEnumerator FillWithinPaintedAreaCoroutine(int x, int y, int maxX, int maxY)
    {
        if (!(x < 0 || x >= maxX || y < 0 || y >= maxY)
            && Map.instance.GetBiome(x, y) != (Biome)_type)
        {

            Map.instance.SetBiome(x, y, (Biome)_type);
            UpdateTile(x,y);

            // Recursively fill neighboring pixels
            yield return FillWithinPaintedAreaCoroutine(x, y + 1, maxX, maxY); // up
            yield return FillWithinPaintedAreaCoroutine(x, y - 1, maxX, maxY); // down
            yield return FillWithinPaintedAreaCoroutine(x + 1, y, maxX, maxY); // Right
            yield return FillWithinPaintedAreaCoroutine(x - 1, y, maxX, maxY); // left
        }
    }```
grave frost
mystic steeple
#

Interesting

#

I remember when I left a debug log in this system by accident when debugging something and I ended up with Unitys debug taking up 15gb of ram lol

timber tide
#

Ah, ok so theres a 1 MB limit to recursive calls apparently, but there's ways around it in c#

mystic steeple
#

Like this?

grave frost
timber tide
#

it would require using Thread class to get around which probably not a good idea anyway with unity

mystic steeple
timber tide
#

so you'll need to spread out the calls through the frames it seems

#

or do partial recursion

grave frost
# mystic steeple

I guess, I don't see your debug log code. But if it's just inside that if statement, then yes. So i'm very unsure as to why that is yielding a frame, I don't think this should yield a frame it should just forever call this method. Perhaps unity's coroutine system has some sort of recursion limit that's causing this? It shouldn't be yielding every frame like that.

mystic steeple
# grave frost I guess, I don't see your debug log code. But if it's just inside that if statem...
    private IEnumerator FillWithinPaintedAreaCoroutine(int x, int y, int maxX, int maxY)
    {
        if (!(x < 0 || x >= maxX || y < 0 || y >= maxY)
            && Map.instance.GetBiome(x, y) != (Biome)_type)
        {
            Debug.Log($"Valid Tile : {Time.frameCount}");
            Map.instance.SetBiome(x, y, (Biome)_type);
            UpdateTile(x,y);

            // Recursively fill neighboring pixels
            yield return FillWithinPaintedAreaCoroutine(x, y + 1, maxX, maxY); // up
            yield return FillWithinPaintedAreaCoroutine(x, y - 1, maxX, maxY); // down
            yield return FillWithinPaintedAreaCoroutine(x + 1, y, maxX, maxY); // Right
            yield return FillWithinPaintedAreaCoroutine(x - 1, y, maxX, maxY); // left
        }
    }```
#

It's just inside the if

#

In the video you'll notice when it gets to the end of a line the FPS drops a lot from like 120 to 30 or something

#

That must be where it called 17 times in 1 frame

#

And then it cycles down again, so yeh it is yielding each frame while generating tiles

#

It has to be "yield return FillWithinPaintedAreaCoroutine(x, y + 1, maxX, maxY);" this then?

#

But I don't understand why the end one runs so many times...

#

Sorry guys q.q

#

And I appreciate the help

grave frost
#

no that wouldn't do it. It has to be because it's recursive. Any recursive algorithm can be implemented without recursion.

mystic steeple
#

How would I convert it to a while loop? Velion_Think

timber tide
#

Store work in a data container then to next calls on them

mystic steeple
#

Recursive IEnumerator calls seems to be no beuno

timber tide
#

I avoid recursion when I can haha

mystic steeple
#

Guys how about I move the tile set stuff into a new function that isn't IEnumerator

#

Basically split the function in half and call that instead

grave frost
#

I would maybe use a HashSet to keep track of what coordinates you've visited:

IEnumerator Start() {

  HashSet<(int x, int y)> visited = new HashSet();
  int loopWaitCount = 0;

  while(someCondition)
  {
    if(!visited.Contains((x, y)) /*&& conditions*/)
    {
      // do stuff
      visited.Add(x, y);
      
      if(++loopWaitCount >= 60)
      {
        loopWaitCount = 0;
        yield return null;
      }
    }
  }
}
#

@mystic steeple maybe something like that?

mystic steeple
#

Yeh, I've just developed a bit of brain fog

grave frost
#

since you mentioned keeping track of what you've visited before would be hard, this does that

icy panther
#

Hey guys! working on my mutliplayer game and i'm wondering if there is some sort of way i can keep my player in a specific "square" or area in the game and not move beyond it.

#

my player uses a rigidbody and box collider

mystic steeple
icy panther
#

thats my question

mystic steeple
#

You're moving using physics?

icy panther
mystic steeple
#

Okay I'm not too familiar with physics... but it depends on how your out of bounds works? You can either have a box collider in the areas you're not allowed in (This is better for more advanced shapes, you can have a trigger collider in front of your player and if it enters out of bounds, you can set velocity to 0?

or if it's more primitive shapes like a cube exclusively, you could also just get your position, add like +1 to the direction you want to move and see if that is out of bounds by just doing a simple if comparison

icy panther
#

hm, ill try a box collider.

mystic steeple
#

Just remember to be careful not to get your character stuck.. Either

  1. Make sure a player can rotate when their movement would be out of bounds (So you can move to a valid rotation)
  2. Have your trigger box collider independent of the player, so it checks where you want to go, rather than where you are facing. Depending on your rotation be careful that they can't jimmy through out of bounds by rotating though
icy panther
#

maybe to make it simple

mystic steeple
icy panther
#

ill put box collider walls

mystic steeple
timber tide
#

if you stick to unity's methods of movement and collision, it's less code you need to write

#

network transforms do a lot of work for you

mystic steeple
#

I just default to mine because it stops walking animations into walls 😅

#

But yeh you could just ignore me completely and just only have the box collider walls catshrug

#

benefit to my approach is that you can just stop animations if they can't walk there

icy panther
#

figured out a solution

#

since my games a ball game

#

only the ball can pass through these specific barriers now

#

everything else including players will not be able to pass through walls

zinc shuttle
#

need help with audio, i want to add a pop sound when the ball is destroyed

which script i do create and where do i attatch it, i tried some methods but not working as i wanted it to be

grave frost
#

Perhaps you want a reference to an audio clip and audio source. Then in the on destroy method of a monobehaviour, call audioSource.PlayOneShot(audioVlip).

verbal dome
#

Just make sure that you dont destroy the audiosource too

#

Can also use AudioSource.PlayClipAtPoint which spawns a separate temporary audisource object

zinc shuttle
#

!code

eternal falconBOT
zinc shuttle
#

using UnityEngine;

public class Audio_ball_pop : MonoBehaviour
{
 public static AudioSource SRC;
 public static AudioClip popAudio;

public bool isPlayed;

void Start()
{
    isPlayed=true;
}
void FixedUpdate()
{
    if(Ball_mechanism.canPlayAudio==true&&isPlayed==false)
    {
        SRC.clip = popAudio;
        SRC.Play();
        Debug.Log("i played audio");

        isPlayed=true;
        Invoke("delayedPlay",2f);
    }
}
     public void delayedPlay ()
     {
       isPlayed=false;
       Debug.Log("i SET the isPlayed to false");
      
     }


}



#

i tried using this, it worked but i cant stop it after once its started.
the invoke in 1st code doesnt work for some reason

iron mango
#

yeah i still can't solve it ._.

modest dust
#

What exactly is Ballstart and Ballend? And where is that instance of Ball_mechanism located, what is it attached to?

zinc shuttle
modest dust
zinc shuttle
#

yes

modest dust
#

The first one being collision.gameObject (the other ball) and the second one being Ballstart (ball with this script attached)?

zinc shuttle
#

let me explain

frank zodiac
#

how can i start a coroutine from another script

zinc shuttle
#

i have 9 balls each balls has this script attached, when a same ball collide(1ball collide with 1ball makes a different 2ball)

and its working pefectly unless i add audio in between the script

silent vault
#

Does anybody have any solution for this ?

modest dust
frank zodiac
#

thanks

zinc shuttle
#

i need some alternative to add a pop audio when this ball is destroyed

silent vault
# silent vault Does anybody have any solution for this ?

I've read online it's due to the dropdown having its own inspector window.
https://gamedev.stackexchange.com/questions/189856/unity-inspector-not-showing-variables-of-custom-component-that-inherits-from-a-b
But I don't know how to override this window

modest dust
silent vault
#

Basically, I just want my new dropdown editor to use the old dropdown editor and jsut add a toggle in it.

silent vault
#

But I can't figure out how to create a component window

modest dust
# zinc shuttle yes

Then, wouldn't it be easier and more intuitive to just use the gameObject property instead of referencing it? Unless the component is on a child GameObject of the whole ball

silent vault
modest dust
#

And with now knowing that, the delayed Invoke doesn't work because you destroy the component responsible for the Invoke

zinc shuttle
#

so what can i do, where do i put the script, and will the collision still works?

modest dust
#

Basically, instead of using some weird static bools here, make yourself a BallManager

#

Give me a few seconds, I'll give you an example of what you could do

silent vault
silent vault
#

Nevermind x4, I've just went ahead and copy/pasted DropdownEditor in the packages list and added my toggle lol. That worked this time.

modest dust
# zinc shuttle ok

Could be, more or less, done like this

// Ball.cs file
public class Ball : MonoBehaviour
{
  // No need for any of these to be public and exposed to other scripts, only needs to be accessible via this script and the inspector.

  // If the Ball script is located somewhere under the whole ball object use _root, otherwise just use the gameObject property inherited from MonoBehaviour.
  [SerializeField] private GameObject _root; 
  [SerializeField] private GameObject _biggerBallPrefab;

  private void OnCollisionEnter2D(Collision2D collision)
  {
    Destroy(_root);
    Destroy(collision.gameObject);

    Vector3 spawnPos = collision.gameObject.transform.position;
    Instantiate(_biggerBallPrefab, spawnPos, Quaternion.identity);

    BallManager.OnBallMerged();
  }
}


// BallManager.cs file
public class BallManager
{
  private static BallManager _Instance;

  [SerializeField] private AudioSource _audioSource;
  private int _score;

  private void Awake()
  {
    _Instance = this;
  }

  public static void OnBallMerged()
  {
    if (_Instance != null)
    {
      _Instance.OnBallMerged_Implementation();
    }
  }

  private void OnBallMerged_Implementation()
  {
    // Now increase score here, play a sound, call Invoke, etc
  }
}
zinc shuttle
#

so this script handels all balls at once or do i need to attach it to every ball

modest dust
#

You call a static method, there isn't anything to attach

#

Just make one BallManager, attach any audio sources, clips and other stuff you may want to it and that's it

frank zodiac
#
IEnumerator TypeText()
{
    float timer = 0;
    float interval = 1 / charactersPerSecond;
    string textBuffer = null;
    char[] characters = line.ToCharArray();
    int i = 0;

    while (i < characters.Length)
    {
        if (timer < Time.deltaTime)
        {
            textBuffer += characters[i];
            gameObject.GetComponentInChildren<Text>().text = textBuffer;
            timer += interval;
            i++;
        }
        else
        {
            timer -= Time.deltaTime;
            yield return null;
        }
    }
}

can someone explain what this code does? what is textBuffer and timer?

verbal dome
lavish magnet
#
    public void AddWeaponFromCollection(string weaponName)
    {
        foreach (var child in weapons)
        {
            print("Found: " + child.name + "in Weapons. We are attempting to add:  ' " + weaponName + "'.");
            if (child.name == weaponName + "(Clone)")
                return;
        }
        foreach (var weaponData in gunCollection.allGuns)
        {
            if (weaponData.gunName == weaponName)
            {

                GameObject newWeapon = Instantiate(weaponData.gunPrefab, transform);
                weapons.Add(newWeapon);
                newWeapon.SetActive(false);
                break;
            }
        }
    }
``` My guns get instantiated, but that 'print' never goes through??
modest dust
lavish magnet
#

weapons List is not empty

zinc shuttle
#

it takes 2 gameobjects _root and _biggerBallPrefab
how does this works for all the 9 balls?

frank zodiac
#

real question: is chatgpt reliable for coding

modest dust
lavish magnet
#

when its wrong (a lot)

frank zodiac
lavish magnet
#

Why that over videos or docs/

verbal dome
modest dust
verbal dome
frank zodiac
lavish magnet
#

I just reimported my unity project 😭 ?

lavish magnet
verbal dome
#

Then this function is not running

verbal dome
#

How are you showing the letters? Coroutine?

lavish magnet
#

did chat gpt write tht

verbal dome
frank zodiac
frank zodiac
#

its connected to a player input and maybe the input is running 3 times

#

because it happened to me before

verbal dome
#

Why is your coroutine/ienumerator local 🤔

#

Not sure if that matters, just unusual

frank zodiac
#

BEFORE

public void OnInteract()
{
    if (isInteractable)
    {
        dialogueBox.GetComponent<DialogueBox>().StartDialogue(dialogue);
    }
}

AFTER

public void OnInteract(InputAction.CallbackContext context)
{
    if (context.performed)
    {
        if (isInteractable)
        {
            dialogueBox.GetComponent<DialogueBox>().StartDialogue(dialogue);
        }
    }
}
#

when i changed it to after it didnt work

#

anyone know why

verbal dome
#

I thought that should work

#

Theres also context.started, maybe thats worth a try

frank zodiac
#

oh ok thanks

verbal dome
#

Put it in a paste site instead: !code

eternal falconBOT
frank zodiac
#

use hatebin

#

.com

frank zodiac
queen adder
frank zodiac
queen adder
#

i jst did

frank zodiac
#

copy and paste the link here

#

remember to click the save button

#

top left

verbal dome
queen adder
verbal dome
#

You tell us 🤔

queen adder
#

and i keep getting the fgpPrefab is not assigned in the FGPSpawnerWithGap script!
UnityEngine.Debug:LogError (object)
FGPSpawnerWithGap:Start () (at Assets/scripts/FGPSpawnerWithGap.cs:19)

error

stark hedge
#

just checking if u dragged in the prefab into the inspector

queen adder
#

i did

stark hedge
#

i seee

queen adder
stark hedge
#

unless im misunderstanding something

#
Instantiate(fgpPrefab, new Vector3(transform.position.x, bottomFGPPosition, 0), Quaternion.identity);```
#

oh i see nvm

#

u want one on each spot

queen adder
#

yes

#

smth like this

verbal dome
stark hedge
#

oh true

verbal dome
#

@queen adder type t:fgpspawnerwithgap in your scene hierarchy search

#

It will search by that type

queen adder
#

its only in

stark hedge
verbal dome
#

How about when playing? Is something spawning more of these?

stark hedge
#

so this has FGP on it. by any chance is it spawning itself

#

if it's spawning itself at runtime, then it wont be assigned in inspector

queen adder
#

the fgp script is the movement of fgps

verbal dome
#

Does fgp have the spawner script on it?

queen adder
fierce geode
#

Hi, dumb dumb here. How does friction work? Like, I had it so that it was just an inverse force against the velocity so that if the player lets go of the controls, it applies the inverse until it reaches zero

Which is been working fine so far, until my character had to go through a loop, and I think when the character starts falling downwards due to gravity, if the gravity isn't strong enough, the friction cancels out the gravity and my character starts accelerating through the loop.

#

i dont think thats how friction is supposed to work

#

should I just disable friction above like 90 degrees?

stark hedge
#

the logerror is on start, and nothing is affecting the reference

queen adder
verbal dome
#

Instead of having to download

stark hedge
#

i already downloaded the virus

#

yeah at the end of that video, id pause the editor (next to play button) and check objects with the script

queen adder
stark hedge
#

u can legit just go in file explorer and change the extension

#

itll convert

#

if u dont see extensions, go file explorer -> view -> file name extensions

#

(theres also an obs output setting to just output mp4)

queen adder
#

discord only gives me the download option to view stuff so idk if its visible for yall or if yall have to download

stark hedge
#

osmal means turn the video into mp4 then upload to discord again

queen adder
stark hedge
#

so the fgps that are being spawned also have the spawner script on them

#

and the spawner script is running the spawn logic

#

is that intended?

twilit sundial
#

is this not the right way to use a variable with a scriptable object

queen adder
#

nope

stark hedge
twilit sundial
#

yea

verbal dome
# queen adder nope

The fgp's do have the spawner script on them though. Exactly what I was asking, but you said no

twilit sundial
#

im gonna use counter because ill need to reference it in different scripts

stark hedge
twilit sundial
#

it doesnt seem to wanna do calculations or assign the variable maybe

queen adder
twilit sundial
#

i get this error

#

i dont get any counting

stark hedge
#

so theyll have spawners as well

verbal dome
queen adder
#

so i should delete the script from the orig prefab?

twilit sundial
#

i get the text on screen but i dont get a counter

mystic steeple
#

Okay so other than me messing up my logic somewhere and creating a pretty bad leak, I think I've figured out how to fix my problem

My coroutine works

verbal dome
stark hedge
queen adder
#

deleted it and it still spawns 2

twilit sundial
verbal dome
twilit sundial
#

huh

verbal dome
# twilit sundial

Ok it's assigned here, but do you have another LogicScript in the scene perhaps?

twilit sundial
#

ah

#

not sure

#

this

#

and this

verbal dome
stark hedge
#

by the way, if youre using a ScriptableObject for kinda "global" variable, it might be easier to make a static class for it

twilit sundial
#

yea but that wont really be global will it?

stark hedge
#

it would

#

u can reference it from anywhere and across scenes

twilit sundial
#

how would i have the information the same on all types of it

verbal dome
#

Do you need to assign different CounterVariables for different objects?

twilit sundial
#

no just the one

stark hedge
#

ya that sounds like a static situation to me

twilit sundial
#

i see

twilit sundial
#

like what osmal said

stark hedge
#

theres only one type of a static class

#

no instances

#

so if u do int number = 5;

twilit sundial
#

wait yea

verbal dome
#

I mean if you needed different versions of CounterVariables, then ScriptableObject would make sense. But you dont

stark hedge
#

that will be 5 whenever ANYTHING references it

twilit sundial
#

oh

stark hedge
#

ScriptableObjects are good when u want instances of something without having to put them on objects

twilit sundial
#

yea

#

i thought you could only use static variables once per script that was my mistake

verbal dome
#

ScriptableObjects are also handy as a sort of 'config'/'settings' asset. But as it's the same for each object, you could reference it in a manager (singleton) class instead of each object

eager spindle
#

this is more of a c# question but does .net optimise divisions? like for example variable / 4 gets converted to variable * 0.25

twilit sundial
#

yea ill keep that in mind 😅

eager spindle
#

does this happen in il2cpp?

twilit sundial
#

is it because it doesnt need sterializewefewgf?

verbal dome
#

It's not a big deal tbh

twilit sundial
#

oh amazing

stark hedge
#

i sterilize my scriptableobjects

verbal dome
#

Just saying that SO's have their place when it comes to stuff like this

twilit sundial
#

yea gotcha

#

wow ive never learnt anything so fast in my life

stark hedge
#

what about putting ur hand on the stove as a kid...

twilit sundial
#

no i still do that

stark hedge
#

ah

mystic steeple
#

@timber tide @grave frost Okay I got it working 🙂 Your suggestions and advise helped me come up with a new system! Thankies

tender stag
tulip tendon
#

hi, i want to make 3d horror game using users1 long tutorial, but i have some issues.. do you think someone could help me a bit.. i would be really happy

tender stag
#

for the animation events

#

but it doesnt show up on the list

#

why

#

its not private

mystic steeple
#

I duno the commands in here

#

!ask

#

!justask

#

Maybe this server doesn't have it...

mystic steeple
twilit sundial
#

0 issues but there arent calculations in the output

ivory bobcat
twilit sundial
#

when it updates

#

unless i need the script to be somewhere

#

not to my small knowledge

stark hedge
#

is it monobehaviour

twilit sundial
#

yea

ivory bobcat
#

I'm guessing you're not getting the yo outputs?

twilit sundial
#

can i use prefabs like that

#

not getting the yo calculation ones

#

so 5 1 and 2

stark hedge
#

Start() and Update() are methods on monobehaviour that are called on an object in the scene

ivory bobcat
stark hedge
#

so yeah Start() and Update() will only be called if an object with that script is in the scene

twilit sundial
#

with that knowledge

#

i do not have anythign that calls the money method

ivory bobcat
twilit sundial
#

no😭

ivory bobcat
#

Well if you want it to run, you'll need to call it

twilit sundial
#

how do i get another script in here

#

wait no

#

thats a script

#

oops

#

wait no that will do its an onbject

stark hedge
#

Class : MonoBehaviour

means it's a type of monobehaviour, it inherits it. monobehaviour is what allows scripts to be put onto GameObjects

#

they act as components

#

so youd do add component

twilit sundial
#

ah

#

oops wrong one

mystic steeple
#

You have 2 on it now, btw you can just drag scripts onto objects

stark hedge
#

yea if u want 2 of the same class on one object

mystic steeple
#

gameObject.AddComponent<ScriptName>() to do it through code

twilit sundial
#

yea i come from roblox so im used to everything being sub optimal

#

im getting there though!😎

mystic steeple
#

Well the foundation and basics are transferable, so you still have a leg up

#

Just gotta learn the ins and outs of the software really

twilit sundial
#

yea

#

this is really cool though

#

so much more flexible

mystic steeple
#

So yeh just remember that if it derives from Monobehaviour, it needs to exist inside your scene

twilit sundial
#

ill attempt to remember

queen adder
#

Any idea why I'm getting an object instance error when I'm defining it and referencing its field from another class?

languid spire
#

At a guess, the gameobject already has a CharacterControllor attached

verbal dome
#

Was thinking the same

#

Wdym by 'from another class' though?

ivory bobcat
wintry quarry
hearty perch
#

Me and a friend are new to making games and are trying to use Version Control to work on the project together.
We've managed to send/share assets, is there a way to share the scene too?
Like I've created the player movement, but when we use VSC it only shares the scrips etc., not the small level including the player I've already build.

stark hedge
#

im unfamiliar with VSC is that just short for version control

#

or vs code?

#

idk

stark hedge
#

are u using github

hearty perch
#

I am not

stark hedge
#

which version control

hearty perch
#

Should I?

stark hedge
#

i think GitHub Desktop is verrrrry user friendly

#

i recommend that

hearty perch
#

And that would allow me to share everything?

#

Including the scene

stark hedge
#

yerp

hearty perch
#

Great

stark hedge
#

basically version control tracks which files to share, so i guess with the one u were using, it wasn't tracking wherever the scenes were being saved

#

with git, that stuff is handled with t he .gitignore file which u can configure in like notepad

#

u just add the paths it should IGNORE

#

and not share

#

like editor settings, big build files,etc

hearty perch
#

Ahh ok

stark hedge
#

github will even have a template for u

hearty perch
#

I was using the build in Version Control from Unity DevOps

stark hedge
#

oh yea idk anything about that

hearty perch
#

I'll take a look at github, thanks for the advise

ivory bobcat
stark hedge
#

with github u get a nice dropdown with a gitignore template so when it makes the repository itll add the gitignore

#

yea the one thing about sharing scenes, making ONE CHANGE to the scene will count as a change to the whole thing

#

so if u both make even a single change, it will likely conflict

hearty perch
#

Ahh ok

stark hedge
#

while github desktop makes merge conflicts less scary, it's still nicer to just avoid them altogether

hearty perch
#

We're mostly working on the project at different times, or on call so that should be ok

stark hedge
#

by not working on the same files at hte same time

#

sounds good

ornate spoke
#

Hey, how do I make the code check if a gameobjects position isn't equal to a certain y value

willow scroll
ornate spoke
#

aha, thank you

languid spire
willow scroll
stark hedge
#

yea do like < 0.01f or mathf.approx

willow scroll
#

Forgot about it

ornate spoke
#

alrighty

willow scroll
swift sedge
ivory bobcat
#

!vc

eternal falconBOT
#
Using version control in Unity

Unity Version Control

git Git

Get the latest .gitignore file from here. It should be placed at the root of your Unity project directory.

silent vault
#

Is it possible to add a listener in the first position to make sure this method is called first ?

wintry quarry
rich egret
#

Someone have any tutorial to make Shine effect on text?

naive pawn
# hearty perch Yup

that's VCS, btw. version control software
distinct from VSC, visual studio code

timid fulcrum
#

hey, i have this code and the effect spawns at 0,0 instead of bulletOrigin's position, anyone have an idea why?

slender bridge
wintry quarry
dense cargo
timid fulcrum
#

my bad on the naming, but its the muzzleflash fx

wintry quarry
#

Shouldn't you be spawning that unrelated to a raycast?

timid fulcrum
wintry quarry
#

Maybe you referenced the wrong thing

timid fulcrum
#

1 second im checking again

#

seems right

timid fulcrum
wintry quarry
#

Just because your variable is named bulletOrigin doesn't mean it's referring to that pictured object

timid fulcrum
#

tha's the log

wintry quarry
#

then it looks good

#

so what makes you think the effect is in the wrong place

wintry quarry
timid fulcrum
#

well, its in the floor instead of barrel's end

wintry quarry
#

looks like not 0

#

Based on your log, your issue has nothing to do with this code, since the log is showing clearly it's not spawning at 0,0

#

So the problem is elsewhere

#

perhaps other code, or perhaps some setting in your VFX

#

perhaps an animator or something

timid fulcrum
#

i'll check those stuff again

#

okay, so the effect itself is set somewhere to 0,0

#

even if i move the effect gameobject, it stays at 0,0

#

im checking why

wintry quarry
timid fulcrum
#

vfx graph

wintry quarry
#

Ok yeah something is wrong inside the graph then

#

maybe it's using world space positions instead of local

timid fulcrum
#

yep, i created a new one and it moves

timid fulcrum
karmic river
#

Guys, my code returns an error when the bird dies. But it doesn;t return the error when the bird dies from the pipe heads.

#

So basically there's an audioSource returning this error

ivory bobcat
wintry quarry
# karmic river

Yeah looks like you're trying to play the source and it has no clip assigned

karmic river
karmic river
#

While the pipe head death occurs when player collides witht he head of th pipe

karmic river
ivory bobcat
#

I'm assuming you're doing extra stuff that are different between the two death events

karmic river
#

I mean a sound playing but it is there in both death events

karmic river
ivory bobcat
#

Show some code: bird death with and without pipe

karmic river
ivory bobcat
karmic river
#

not the whole pipe

#

The console says that the error is on the last line of code

#

AudioGameOver.Play()

ivory bobcat
#

Where do you call Game Over?

karmic river
ivory bobcat
#

I'm assuming all deaths call Game Over but something likely is different between the one that has the error thrown and the one that doesn't - could be a state or whatever.

karmic river
#

In the second case it returns error. In the first case it returns error at when the bird hits the pipe body

#

and doesn't return the error when bird hits the pipe head

ivory bobcat
#

The only difference I can immediately see is that one occurs during the physics frame (fixed update) and the other during the regular frame (update)

karmic river
karmic river
ivory bobcat
#

Can you show the stack trace for the error?

karmic river
karmic river
ivory bobcat
#

Is there more to the stack trace? Anything cutout from below?

karmic river
#

There is also this

ivory bobcat
#

Hmmm normally they'd tell which function had called game over and whatnot

#

right

#

Can you show your bird script? How to post !code

eternal falconBOT
ivory bobcat
#

Click a link, paste your text, click the save button somewhere on the site, copy and paste the url here

karmic river
ivory bobcat
#

So that ought to be an Update method and not Fixed Update

#

You cannot query input correctly in Fixed Update

karmic river
swift crag
#

the error is in LogicScript, not BirdScript

karmic river
swift crag
#

the most recent method is on top of the call stack

#

(hence it being a stack)

karmic river
ivory bobcat
#

That isn't the point. You should not acquire input in the Fixed Update method. Other than that, it's stating that your source for your audio player is null or has become null.

swift crag
#

The error isn't caused by reading input in FixedUpdate, but it's definitely something you should change

swift crag
swift crag
karmic river
#

It still gives the same error

ivory bobcat
#

It was originally Update but they had changed it to fixed update (not sure why) because I had mentioned that the two calls were mainly different with regards to when they were called #💻┃code-beginner message

ivory bobcat
karmic river
karmic river
ivory bobcat
#

Which object lit up in the scene?

timid fulcrum
#

hey, i have another question.
I don't know why but my player shoots from 2 locations.
i specified the Ray to come out of the camera on the player, but it seems that there are 2 cameras, and although i see 2 camera gizmos, i can't find the second one

karmic river
ivory bobcat
#

An object in the scene should flash yellow if the object hasn't been destroyed or the scene hasn't changed etc

swift crag
#

it sounds like the context object is missing when the error happens

karmic river
#

With the getComponent thing'

ivory bobcat
#

What? 🤔
What happened to the object?

swift crag
#

think about why the object might have suddenly disappeared...

karmic river
ivory bobcat
#

I'm only aware of you setting the game over screen active and playing the audio. Are you destroying or doing something to the bird?

karmic river
karmic river
#

I am only disabling it's movement

swift crag
#

well, here's something interesting to me...

#
AudioGameOver = GameObject.FindGameObjectWithTag("Bird").GetComponent<AudioSource>();
#

This runs in addScore

ivory bobcat
swift crag
#

But what if you've never gained any score?

#

searching for AudioGameOver in addScore doesn't make sense.

#

You don't use it there.

ivory bobcat
#

Are the pipes and bird present from the very beginning? If so, consider referencing through the inspector rather than searching the hierarchy.

swift crag
#

The pipes are probably spawning in over time

#

I'd just move the audio off the pipes entirely!

#

and off the bird, too

timid fulcrum
#

why not making an audio manager?

swift crag
#

or just slap some audio sources on the same object as LogicScript and call it a day

ivory bobcat
swift crag
#

Code that takes advantage of a coincidence (you usually get points before you lose the game) can fail randomly like this

sick jay
#

In a 2D game, does a Raycast2D hit a collider that is higher or lower in the z axis?

ivory bobcat
# karmic river

Move the audio and audio game over assignment statements into a Start method. They really ought to initialize those fields on start rather than when you acquire score.

wintry quarry
ivory bobcat
wintry quarry
#

public ContactFilter2D myFilter;

sick jay
#

I have a raycast that is checking if a tile with a collider in the game has a "Walkable" tag, but i also have an object on top of it(closer to the camera) with a collider tagged "Interactable". so it would hit the interactable tagged object instead of the walkable

ivory bobcat
#

Should probably consider filtering by layers and whatnot rather than just accepting the nearest.

karmic river
#

Thanks for the help I'll apply this when I get back to my PC

sick jay
#

https://gdl.space/eqehufivaw.coffeescript
i have some code here that checks if the collider has a specific component attached set to null, but im not sure if its working the way i want it to. if the hit object has the "weaponName" assigned(meaning its a weapon) it works fine, but if it has the other two in the else if's it doesnt work and gives a null reference exception. im pretty sure it means that it doesnt find a "weaponName" for the first check because it doesnt have one, but i thought that that would just mean its null and should just go to the next else if statement

ivory bobcat
#

Maybe log what you hit?

#

Make sure to include a comma and the component/gameobject to have it become highlighted in the scene.

swift crag
#
Debug.Log("Testing", someObject);
#

e.g.

sick jay
#

oops

#

RaycastHit2D hit = Physics2D.Raycast(raycastStart, target, 1);
Debug.Log("Hit object:" + hit);

swift crag
#

hit is not a unity object

#

you can't use it as the context

#

on the other hand, hit.collider is a unity object

ivory bobcat
#

After verifying that you've hit something, check what you hit.

#

It should have a property to access what you hit.

sick jay
#

it does hit the Chest, which is what im trying to test

#

but it doesnt give a debug log saying "Collectible is a chest!" meaning it stops at this part of the code:
" if (hit.collider.GetComponent<Collectible>().Weapon.WeaponName != null)"

ivory bobcat
#

Likely you've got an nre there

sick jay
#

im pretty sure this statement doesnt work

#

yeah

#

i mean to check if it even has a component like that

ivory bobcat
#

An error will stop the execution of the remaining code

sick jay
#

but if it doesnt to move on

#

i dont mean to check if that component has a value of null, i just want to check if the hit.collider has that component

#

how do i do that

swift crag
#

sounds like you want TryGetComponent

#
if (something.TryGetComponent(out Collectible collectible)) {
  // collectible is non-null in here
}

// collectible might be null out here
ivory bobcat
#

You need to verify if it's got the collectible component first before attempting to access the weapon or weapon name

sick jay
#

if its gotten this far in the code it will always have the collectible component

#

well at least right now

#

but thats good for the future i will change it

#

not every interactable will be a collectible

scenic saffron
#

How do i make a Vector that is only for direction with a custom length that stays the same no mater how long the original vector was?

ivory bobcat
scenic saffron
#

dosent work

ivory bobcat
#

Or why you feel it doesn't work or wouldn't work etc

scenic saffron
sick jay
#

So the Collectible will always have one of three scriptable objects as of right now. i just need an if statement that checks which one it has, because it will never have more than one

ivory bobcat
scenic saffron
#

i have changed literally nothing and now it works, thx i guess

sick jay
#

Im gonna move all the code out of where it was previously into a new void to make it easier to read, does this work?
CheckInteractable(hit);

private void CheckInteractable(RaycastHit2D hit);

ivory bobcat
#

Not sure, maybe - beauty is in the eyes of the beholder.

sick jay
#

it seems to work, but i still need to figure out how to do an if statement that checks correctly if the component has a weapon, chest, or accessory

scenic saffron
#

why cant i set rotation to a vector?

swift crag
#

because transform.rotation is not a Vector3

ivory bobcat
swift crag
#

consider transform.eulerAngles (and maybe show us what you're actually doing here)

ivory bobcat
#

Quaternion does have a static Euler method though - to create Quaternions using euler values.

scenic saffron
ivory bobcat
#
transform.rotation = Quaternion.Euler(...);```
swift crag
#

ah, then you'll be very interested in...

rocky canyon
#

anyone know the best way to achieve a servo type motion using hinge joints?

swift crag
#
transform.rotation = Quaternion.LookRotation(transform.forward, Vector3.up);
rocky canyon
#

im not very versed on rotations w/ rigidbodies

swift crag
#

unless this is a 2D game, in which it's a bit different

swift crag
#

oh good

#
transform.rotation = Quaternion.LookRotation(Vector3.forward, transform.up);
rocky canyon
swift crag
#

assuming that the bullet is flying in its "up" direction

rocky canyon
#

w/ limits and whatnot

swift crag
#

the green arrow when you have it selected

swift crag
#

Quaternion.LookRotation is used to compute a rotation that looks in one direction with a second vector as the "up" direction

#

In 2D, the "forward" direction is pointing into the screen

#

So we ask for a rotation that looks into the screen (Vector3.forward) and with the appropriate "up" direction

#

also, I just realized that using transform.up is not very useful here lol

#

use the direction the bullet is flying

#

the code currently just makes the bullet point in the direction the bullet is pointing!

scenic saffron
#

i dont know how to get the direction the bullet is flying in

swift crag
#

well, is the bullet moving at all?

scenic saffron
#

yes

rocky canyon
#

depending on the direction its moving just use its local direction

#

transform.right

swift crag
#

a rigidbody2d?

scenic saffron
swift crag
#

you can get the velocity from that component

karmic river
swift crag
#

i have no idea what changes you made, so i can't tell you much

#

show me your new code

karmic river
swift crag
#

i don't want to play 20 questions

#

share the entire script again

karmic river
#

!code

eternal falconBOT
swift crag
#

you're trying to find a pipe the moment the game starts

#

no pipe exists

#

why can't you just put these audio sources somewhere else?

#

like on the same object as the LogicScript

karmic river
#

thx

swift crag
#

and then, you can just directly reference the audio sources

#

instead of having to search for them through code

karmic river
swift crag
#

well, you still don't have Audio assigned...

#

Get rid of all of that GetComponent code. Drag the audio sources in directly.

karmic river
swift crag
#

You can stick them on child objects

rich adder
#

but yeah directly link is your best bet

karmic river
swift crag
#

you just...add them

rocky canyon
#

u just add them

#

u cant have but 1 audio listeners

#

but as many sources as u want

swift crag
#

you can then drag the individual components into the fields

karmic river
#

thx

#

The problem was solved 🙂

#

But the sound plays too late sometimes

rocky canyon
#

it might be that its finishing up the file..

rocky canyon
#
aSrc.Stop();
aSrc.Play();```
#

theres also PlayOneShot() which can allow them to overlap a bit

swift crag
#

PlayOneShot is appropriate for sound effects, yes

rich adder
#

some good options ^

swift crag
#

you give it an AudioClip

rich adder
#

use audacity and trim the end of the clip 😮
(dont)

sick jay
rocky canyon
#

i just heard of a program called Reaper imma start to try out

rich adder
#

ahh good ol reaper

#

good times.

rocky canyon
#

to avoid using GetComponent over and over

#

Rigidbody myRB = GetComponent

#

then u can just say myRB.velocity;

swift crag
#

using GetComponent constantly is almost always wrong

rocky canyon
hollow dawn
#

Why can't I open doors? I followed this tutorial: https://www.youtube.com/watch?v=oCv14L3Ew4w&t=823s&ab_channel=User1Productions and this is the script:https://paste.ofcode.org/bBYr2w3L8Txn5VTgTgzHxW even in his comments people are in the same situation any one know how to fix this?

EDIT :
YES I messed up sorry. change the transition bools to open on both and it will work !!

DOWNLOAD PROJECT FILES HERE:
https://drive.google.com/drive/folders/10BvUxAOeOxZac-GfecJWSFahuMB8bOo0?usp=sharing

▶ Play video
rocky canyon
#

start debugging..

#

make sure that ur logic that runs the anim is being called correctly

#

im assuming a raycast is being used.. or a trigger

#

make sure those are evaluated as true first..

#

then make sure ur script is communicating with the script that calls the animation..

#

lastly make sure the bools/triggers of the animator are being flipped on

hollow dawn
rocky canyon
hollow dawn
rocky canyon
#

i dont understand why u need two bools?

hollow dawn
#

one for open one for closed

rocky canyon
#

setbool open true would obviously mean closed is false

#

yea, no need for 2 bools.. just confusing

summer stump
#

Open being false means closed

hollow dawn
#

when the guy in the tutorial did it, it worked perfectly tho

rocky canyon
#

doesn't mean its right.

#

ur having issues right now arent you? lol

hollow dawn
#

yes

summer stump
#

Lots of bad tutorials out there 🤷‍♂️

rocky canyon
#

it isnt a very clear or smart way to do it imo

hollow dawn
#

its making me go insane

rocky canyon
#

does ur debugs run?

hollow dawn
#

yes

rocky canyon
#

on ur DoorOpens?

hollow dawn
#

look at the oic

#

pic

rocky canyon
#

its probably ur transitions

#

try removing 1 of the bools

#

and only using 1 like Open

#

u can set open to true.. -> have ur transition go from idle to open when its true..

#

have it go from open back to idle when its false

#

then u just need to DoorOpen -> open=true
DoorClose -> open=false

queen adder
#

Hello people

worthy merlin
#

I thought lists showed in the inspector? Any reason why my available weapons list doesn't show? The weapon variable is a class btw

queen adder
#

i have a error that i couldn't solve for a while and when i found a site talking about it, it said to remove the library file of your project, should i do it?

slender nymph
worthy merlin
queen adder
#

this is the error

worthy merlin
slender nymph
#

it is not serializable, you need to mark it as such or else the editor will not serialize it

worthy merlin
#

Thats with one of these right? [Serializable]

slender nymph
#

yes

worthy merlin
slender nymph
# queen adder so what do i do?

start by making sure you are looking at the first error in the console rather than the last. and if it isn't code related, ask in a relevant channel

summer stump
queen adder
slender nymph
#

okay this is a code channel. so if you need help with a non-code related issue then ask in a more appropriate channel. id:browse

queen adder
#

in this case, what is the appropriate channel in this server?

slender nymph
#

if only there were some way for you to view all of the channels and their descriptions so you could make that decision yourself

rocky canyon
queen adder
slender nymph
#

then you didn't look hard enough

sick jay
queen adder
#

then i shall look

rocky canyon
#
        if (Input.GetButtonDown("Interact"))
        {
            if (inReach && !isOpen))
            {
                DoorOpens();
            }
            else if(inReach && isOpen)
            {
                DoorCloses();
            }
        }```
also in ur code u might want to use a bool (within the script) to keep track if its open or not
summer stump
#

Not the best one though

willow anvil
rocky canyon
#

yes, b/c the door open and close functions set the isOpen bool to something different..

#

so if u dont use an else if.. the first one runs.. changes the bool.. then the 2nd one is also true all of a sudden

#

so it open and close all in 1 frame

willow anvil
#

pretty sure it would work just with else

summer stump
rocky canyon
#
            if(myBool == true)
            {
                myBool = false;
            }
            
            if(myBool == false)
            {
                myBool = true;
            }```
#

this would be the alternative.. and this is wrong..

#

both if conditionals get run

#

the else if combats that

#

so only 1 set of ifs will run each keypress

#

ofc theres other ways to do it.. but i was working off of someone elses code.

#

which is odd.. since they followed a tutorial.. cuz ^ that doesn't make much of any sense to me

#

it would force the door closed all the time

rocky canyon
dense root
#

How do I edit the sprite physics? The handles that I'm seeing in the documentation aren't appearing

rocky canyon
scenic saffron
#

how to change only the z rotation of a Object

dense root
dense root
rocky canyon
#

just modify its z pass it its own x and y back to it

scenic saffron
#

but rotation is a quternion

rocky canyon
#

ohh rotation..

#

same thing u can use eulers

#

not sure how to do it with Quats

wintry quarry
#

For that you can use Quaternion.AxisAngle for example (or was it AngleAxis?)

rocky canyon
#

this is better

scenic saffron
#

ok ill try

wintry quarry
#

Or if the axis is one of the object's local axes, you can just use transform.localRotation or transform.Rotate

rocky canyon
#

say localRotation, around transform.up vs the Vector3.up

#

i get mixed up sometimes b/c of the way TransformDirection works

wintry quarry
#

localRotation is relative to the parent's rotation

wintry quarry
#

Rotate rotates around the object's own local axes

rocky canyon
#

i realized what i was talkin about lmao

#

yea yea.. so its independent of wether its local or global

#

what i meant was if rotating globally it would be transform.rotation = Quaternion.AngleAxis(30, Vector3.up);

#

but if u wanted to rotate it locally it would be transform.localRotation = Quaternion.AngleAxis(30, Vector3.up);

#

my question was.. if we change it to be local.. do we still use Vector3.up.. or would it then become.. transform.localRotation = Quaternion.AngleAxis(30, transform.up);

#

or would we still use Vector3.up

wintry quarry
#

VEctor3.up would be correct

#

transform.up is a world space vector

rocky canyon
#

okay thats what i was kinda thinking..

queen adder
summer stump
wintry quarry
#

Is there an error message? If so - copy it here exactly

queen adder
#

wait i misspelled i meant class of the script

wintry quarry
#

SHow us what error you're seeing

summer stump
#

Ok, now I am even more confused

queen adder
wintry quarry
#
  • Make sure you have no compile errors
#
  • Make sure the class and script name match
#

When you do that, it will work.

queen adder
wintry quarry
summer stump
queen adder
#

kk

summer stump
#

Have you gone through !learn yet?

eternal falconBOT
#

:teacher: Unity Learn ↗

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

summer stump
#

I'm hoping that is not ai code

wintry quarry
#

The fully qualified class names... not sure what they indicate haha

#

It does look kinda like AI code

#

with every line commented

queen adder
#

it is i downloaded unity 5 hours ago

summer stump
summer stump
#

Tutorials for learning unity

#

Do the essentials pathway and then the junior programmer pathway

sick jay
#

i have a script that is attached to a gameobject that can hold 1 of 3 different scriptable objects.
https://gdl.space/ogisaxopir.cs
i need this void to be able to tell which one it is. however, as it is now, it gives a NRE for any object that has something other than a weapon SO attached. how can i fix this? my current method is to check if a value stored in the SO is not null, but it doesnt seem to work if the SO itself is not there

swift crag
#

correction: you need this method to tell which one it is

#

it's not called a "void"

#

its return type is void, because it returns nothing

rocky canyon
#

jsut check if the SO is there first.. not if a value in the SO is there

swift crag
#

yes, you can check if the field has anything in it

rocky canyon
#

if its not there no need to check for the value

sick jay
#

apologies

#

i dont know why i didnt try that already

#

thank you

rocky canyon
#

if its there.. then go deeper

jovial forge
#

Sanity check

Debug.Log(transform.position.z);
Shouldn't this print the z position to the console?

frosty hound
#

Yes

jovial forge
#

And shouldn't it be a numerical value?

wintry quarry
#

those are numerical values.

sick jay
#

is it not those numbers shown?

#

right next to the time stamps

polar acorn
wintry quarry
#

btw based on this log looks like two different objects are printing their positions.

sick jay
#

unless your object is going back and forth between two similar positions rapidly

swift crag
#

[timestamp] (log message)
(method that caused the log message)

jovial forge
wintry quarry
swift crag
#

what is a timestamp but a numerical value thinksmart

rocky canyon
#

i need a sanity check now.. u are aware that 19.92768 is a number right?

#

lol

jovial forge
#

That's a fair jab lmao

swift crag
#

Google is on the fence

rocky canyon
#

lol.. nah bro its a bank

sick jay
#

Thank you world bank for keeping the very important data that 19.92768 is in fact a real number and not fake or imaginary

rocky canyon
#

tread lightly guys..

#

we might be in illuminati territory

sick jay
#

illuminati* is what i assume you mean

rocky canyon
#

yea. lol that ^ im not very familiar with it..

#

or am i? 🧐 lol

jovial forge
#
void Update()
{
    Debug.Log(transform.position.z);
    if(transform.position.z > top)
    {
        Destroy(gameObject);
    }
    else if(transform.position.z < bottom)
    {
        Destroy(gameObject);
    }
}

For some reason this is causing my game object to be instantly destroyed when it is instantiated.

top = 40
bottom = -10
Object is being instantiated at (0, 0, 35) or (0, 0, 0)

rocky canyon
#

interesting

jovial forge
#

If I comment out the else if statement, the object isn't instantly destroyed

polar acorn
wintry quarry
polar acorn
#

Yeah like that

jovial forge
#

This is the reason I am going through the Unity Learn course lol Trying to learn all of the little things with Unity

sick jay
#

Real quick, in a Raycast2D, the first vector is a position(in my case relative to the gameobject the script is attached to), and the second vector is a direction that begins at the first position? or is the second vector also a position relative to the gameobject?
ex in case of first question: to have the raycast start at (0,1,0) and point in the y direction, you would put Physics2D.Raycast( [0,1,0] , [0, 1, 0] )
ex in case of second question: same thing, but youd do Physics2D.Raycast( [0,1,0] , [0, 2, 0] because if they were the same spot it would result in no direction
(pretend the [] are a variable that points to a vector like that)

rocky canyon
#

just long enough to see whats happening w/o having to debug all the values

#

then u can switch it back to Normal

swift crag
#

So it's [0,1,0] and [0,1,0]

fervent abyss
#

hey does Unity Muse AI comes with unity pro?

swift crag
#

It works like DrawRay

sick jay
#

i got myself so confused for some reason thinking id put two points on top of each other and the raycast was just checking a position

swift crag
#

rather than DrawLine

sick jay
#

yeah

sullen widget
#

I put a sprite on this square but the sprite seems much bigger, how to fix?

rocky canyon
#

change the scale down to 1:1:1 to match the collider..

sullen widget
#

Just noticed that this is the wrong channel so thanks anyways for answering

rocky canyon
#

ive always wondered why we couldnt adjust a sprite independently of the scale

#

kinda like how image components work

sullen widget
#

No idea what i just did but now when i set the sprite to the block it shows scales are already 1:1:1

#

But it's still massive

rocky canyon
#

is it a child object of any other gameobject?

sullen widget
#

A plot is just a 2D Square Sprite in my case

rocky canyon
sullen widget
#

Thanks

dense root
#

What's the best practice for removing bounciness when colliding? I've read increasing the mass is one trick

eager spindle
#

youre moving the player with rigidbody?

#

you can use a physics material to remove bounciness

#

but i dont think bounciness is the issue here , asyour player is moving into the collider. the fastest way to do this is to do a raycast in the direction the player is moving at to prevent them from moving into the collider for that one frame

rocky canyon
#

could be able to crank up the collision detection to prevent u from entering the collider in the first place

#

whats happenin is the collider is pushing u back out of it

summer stump
dense root
vocal fjord
#

this might seem very stupid, but how do i enable/disable script components with c#?

#

I'm trying to make it so that when a user hits a button, an animation plays and then the script to play the sound of the button when the user presses it again doesnt work