#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 421 of 1

quick fractal
#

What exactly is rotation.x += 10 doing? Seems like you're just overriding it later on. ๐Ÿค”

Another question, is Mathf.Clamp forcing it to be within 90 -> -90 or is that just the "allowance" for an if statement (if that makes sense)

rocky canyon
#

sounds like its probably ur loading stuff thats the culprit

rocky canyon
#

the second part just clamps it

stuck palm
#

trying to serialise a fixed point math library - why does it look like this?

quick fractal
rocky canyon
#

probably just an example

quick fractal
#

Ah

languid spire
rocky canyon
#

we tend not to post exact code that ppl can copy and paste w/o giving it a look first

#

and figuring out the logic bit on their own

quick fractal
raw token
#

I stared at this a bit a while ago, but nothing stood out to me. I would think to try and pinpoint exactly where the doubling occurs. I think it would be easiest by throwing a breakpoint at the top of LoadData() and stepping through it with the debugger, inspecting the values and lengths for data.items, Container, etc. But you could also sprinkle more logs around

quick fractal
#

Just call a function if it's within the clamp "limit"

languid spire
polar acorn
#

Start walking through your load data method. You start by looping through data.items and setting the corresponding index of Container to that item. That seems like a potential place to load the wrong things. Try logging i, Container[i].Id and database.GetItem[Container[i].Id]. See what gets loaded.

quick fractal
#

Implementing something that doesn't fit my use case would be pointless, asking a question is completely fair ๐Ÿ˜›

rocky canyon
#

the logic above it runs...
afterwards it gets clamped
if its in the limit. (its good as it is)
if its above the limit it clamps it back down to the closest limit
if its below the limit it clamps it back up to the closests limit
.. then the rest of ur code also acts normal

languid spire
rocky canyon
#

๐Ÿ—’๏ธ docs will be ur best friend..

#

every unity function will have a description.. and majority will even have an example snippet of code

quick fractal
#

I hope I'm not misunderstanding and I'm wondering if I can skip defining x & y & z in favour of just doing it once. But from all I've read I feel like this might work SquintEyes

polar acorn
final kestrel
#

I debugged if the container gets expanded somehow but in my load method its always the amount I set.

#

Thats got initialize item method in it

rocky canyon
#

quaternions are 4Dimensional..

#

the x is not the x u think it will be

raw token
rocky canyon
#

throw a debug first line of it and see how many times it logs

polar acorn
final kestrel
#

okay a minute

final kestrel
polar acorn
quick fractal
final kestrel
rocky canyon
#

if u debug transform.rotation.x and then debug transform.rotation.eulerAngles.x

polar acorn
rocky canyon
#

you'll see a difference

quick fractal
rocky canyon
#

we're just aware of them.. and use eulers instead

polar acorn
#

So each item in the list duplicates

rich adder
rocky canyon
rocky canyon
quick fractal
final kestrel
polar acorn
#

The highlight is a bit tough to see but that's adding elements to the Container list

final kestrel
#

Yes I found that line

#

Well good find. Now how can I fix it T_T

#

I should be adding them to the container elsewhere

#

I can do that in AddItem after Spawning new item

#

But it will be the same no? Since im calling add item.

polar acorn
#

Well, first off, what even is Container? That's not a very descriptive name

#

What should this list be?

quick fractal
final kestrel
#
[System.Serializable]
public class InventoryData{
    public int Id;
    [JsonIgnore]public Item item;
    public ItemType itemType;
    

    public InventoryData(int _id, Item _item, ItemType _itemType)
    {
        Id = _id;
        item = _item;
        itemType = _itemType;

    }

    public InventoryData(){

    }
    
}

Container is this. Where I hold my Save data

wintry quarry
#

Container is a list or array of those you mean

polar acorn
#

what is the actual purpose of this data

rocky canyon
final kestrel
#

So that I can save item types and item ids that sit in my scriptable objects

polar acorn
rocky canyon
#

altho.. u sure u want both conditionals to be less than?

#

b/c less than -30 is also less than 30

quick fractal
#

Ah no I'd want more than -30

#

Lmao

rocky canyon
#

obviously lol

final kestrel
#

List of ItemData

quick fractal
#

Less than 30, more than -30, got it

rocky canyon
#

well still 25 is less than 30 AND more than -30

polar acorn
rocky canyon
#

๐Ÿค”

polar acorn
#

I can see that it's a list of ItemData

#

But what is the point of it

#

Using words

quick fractal
rocky canyon
polar acorn
#

tell me what this variable is supposed to represent

quick fractal
#

I want it to trigger if it's inbetween 30 and -30 so if it were 25 that'd be good

timber comet
#

!code

eternal falconBOT
rocky canyon
#

< 30 && > -30 ?

quick fractal
#

Yes

#

I'm not great with numbers, you can probably tell lmfao

rocky canyon
#

ahah, no worries.. we all make minor changes like that all the time

final kestrel
# polar acorn tell me what this variable is supposed to represent

Well What I had in mind (and also after some research) I thought I could Make this Serializable data. Instead of Holding a list of my InventoryItem which are prefabs with ItemScriptable objects as public fields in it. I could Hold Id and ItemType to save and load in this container

green rampart
#

why is say "install queud"

timber comet
#

Hey guys i have a problem with this script: https://paste.ofcode.org/39CZBp5DMbEMzDp2GWPfA3U . Basically i want the movement to be following the rotation of the player, but for now the movement that the player does is "static" (it doesn't follow the rotation). Btw this script uses unity's new input system

final kestrel
quick fractal
#

Kind of a muddled mess but so is all the other code in my DLL so that's no different

polar acorn
hallow acorn
#

hey does somebody know if i can make a switch statement using ranges from for example 0 to 60?

#

per case*

green rampart
timber comet
hallow acorn
wintry quarry
quick fractal
rocky canyon
#

๐Ÿคฃ

quick fractal
#

I would imagine so

rocky canyon
#

thank goodness for "search" functions

hallow acorn
quick fractal
#

It was fine when there were only 4 things to look for, then teh game updated and added like 100 different items of the same type and I'm too lazy to look for a better method

final kestrel
hallow acorn
quick fractal
rustic valve
#

is there a way to know when the animation ends ?, to like do attack animation and then return to idle animation ? (I'm using GetComponent<Animator>().Play("name of the animation") )
to do it like: .play("attack") then .play("idle")?

timber comet
polar acorn
#

What should be in this list

#

What does it represent

#

Why did you make this list

#

What is it supposed to do for you

quick fractal
hallow acorn
quick fractal
#

I'm aware it's terrible

final kestrel
#

Help me extract data from it, data that will help me pull items from my database

polar acorn
#

what would your game fail to have if you just deleted the whole fucking list

final kestrel
#

I cant save and load

polar acorn
#

save and load what

final kestrel
#

the Inventory items

polar acorn
#

Okay, so it is the inventory

#

of items you are currently holding

#

is that correct

timber comet
final kestrel
#

Just the ids and types of the items.

#

I do not hold the Item itself in it because its a scriptable object

polar acorn
final kestrel
#

Yes

polar acorn
# final kestrel Yes

And presumably there's a real inventory containing those ScriptableObjects in a different variable, and this one is only used when saving and loading

final kestrel
polar acorn
#

Because those seem like completely different things

final kestrel
raw token
final kestrel
final kestrel
#

So I can store their ids and types

polar acorn
#

or just the one that stores IDs

final kestrel
#

Thats the item that gets instantiated

polar acorn
stuck palm
#

tried writing a custom property drawer, why does this happen?

polar acorn
final kestrel
polar acorn
final kestrel
#

Please excuse my ignorance but I cannot seem to place it in my head. What do you mean by Inventory variable.

polar acorn
#

not the IDs

#

the actual items

hallow acorn
#

does < or include the number or exclude it? and how is it with >?

wintry quarry
final kestrel
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName ="Item Database", menuName ="Inventory System/Database")]
public class ItemDatabase : ScriptableObject, ISerializationCallbackReceiver
{
   public Item[] items;
   public Dictionary<Item, int> GetId = new Dictionary<Item, int>();
   public Dictionary <int, Item> GetItem = new Dictionary<int, Item>();
    public void OnAfterDeserialize()
    {
        for (int i = 0; i < items.Length; i++)
        {
            GetId.Add(items[i], i);
            GetItem.Add(i , items[i]);
           foreach (var item in GetId)
           {
                GetId.TryGetValue(items[i], out int Id);
                Debug.Log(Id);    
           }
        }
    }

    public void OnBeforeSerialize()
    {
        
    }
}

The only place I have Item[] is here

polar acorn
final kestrel
#

in the database

#

other than here no I do not hold any Item[]

polar acorn
final kestrel
#
using UnityEngine;


[CreateAssetMenu(menuName = "ScriptableObject /Item")]
public class Item : ScriptableObject
{
    // public GameObject prefab;
    public int id;
    public Sprite image;

    public ItemType itemType;
}


public enum ItemType{
    Misc,
    Key,
    Weapon,

}

Yes all my items are based on this.

polar acorn
raw token
# timber comet yyes

rb.velocity is in world-space. To apply your input relative to the player's orientation, one solution is to multiply the player's directional vectors (which are themselves in world-space) by your input:

_rb.velocity = _movementKeys.y * tranform.forward + _movementKeys.x * transform.right + _rb.velocity.y * Vector3.up;
polar acorn
#

Then you can save or load that list of IDs as a simple string of JSON or however else you want to serialize it

#

and just call those functions to convert between them

#

Once the items are loaded, you do not need to keep a list of them around

stuck palm
#

what do you call the f in 0.432f? identifier or something?

rich adder
#

suffix ?

stuck palm
#

i know theres one for longs, L or whatever

final kestrel
polar acorn
stuck palm
polar acorn
#

Your database is good, that's already what it needs to be

#

You just need these functions somewhere. The database itself is a good place to put it

#

ItemsToIds and IdsToItems

summer stump
#

In terms of language, it is a suffix. In terms of its purpose in coding, it is syntactic sugar for a cast

final kestrel
#

Ah okay. I will do that in my database then! Thanks again.

tacit cypress
#

too afraid to ask and dumb enough to fail trying learning by tutorials, I feel stuck in some sort of loop that I can't escape, I'm not able to start developing by myself and can't do 1 single thing without watching a tutorial about how to, already 6 months of studying C# and Unity overall and I still don't know anything, started feeling like coding isn't my thing but at the same time I really really want to make some progress.

Watching all of you just answering each others questions and helping each other about things that I don't understand even though all the time I spent studying the engine, am I dumb? how do I start? I really could use some help.

Sorry for interrupting any important conversation about any topic, there's no need to answer, just looking for some tips or smth, thx.

spare mountain
#

!learn

eternal falconBOT
#

:teacher: Unity Learn โ†—

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

stuck palm
#

I'm trying to manually serialise a class, and every time i try to set a value in the inspector it immediately sets it back to what it was before. why is this happening?

stuck palm
# spare mountain let's see some code

i'm using the SerialisationCallBackReciever and a custom property drawer.

public void OnBeforeSerialize()
        {
            // Convert m_rawValue to double for serialization
            serialisedValue = m_rawValue / (double)Fix64Constants.ONE;
        }

        public void OnAfterDeserialize()
        {
            // Convert serializedValue back to m_rawValue
            m_rawValue = (long)(serialisedValue * Fix64Constants.ONE);
        }
spare mountain
#

welp we're out of my field of knowledge gonna leave this to someone else

stuck palm
#

appreciate your honesty

spare mountain
#

or is it just for fun?

ripe shard
# tacit cypress too afraid to ask and dumb enough to fail trying learning by tutorials, I feel s...

Some people answering competently here have a decade+ experience. So donโ€™t get discouraged if 6 months donโ€™t yet quite seem to get you anywhere. However most of them will not have learned their stuff via tutorials since they can at best give you an overview of something but you will learn nothing from them, as you have discovered. The key is to learn the principles behind the craft (theory) while also trying to apply those to a project and skip all tutorials except for said overview. Use books, structured courses and challenges you make for yourself. You only learn if you figure out the solution yourself. Tutorials fundamentally cannot help with that.

stuck palm
raw token
# tacit cypress too afraid to ask and dumb enough to fail trying learning by tutorials, I feel s...

I think it's very important to build foundational knowledge prior to seeking out tutorials for specific features. It's hard to glean knowledge from solutions presented to you if you are unable to understand a decent portion of it - the bits which are ancillary to the actual feature.

I think one of the best skills to develop early on is the ability to perform research on your own, outside of a tutorial. Especially where it comes to learning to read and understand official documentation. And be willing to ask when you don't understand what the documentation is saying :) . Then, when you don't understand what someone has done in a solution or why they are doing it that way, you can spend time to research it. You'll grow in all respects for asking questions and hunting answers rather than accepting things at face value.

I guess in short, don't pressure yourself to rush through things or achieve a feature or integration in short order. Accept that they will take more time starting out, and use that time to explore along the way - poke and fiddle with things just to see what happens. I've always found that once I have a basic idea of what's going on, that sort of exploration becomes pretty engaging and elucidating...

Answering questions has always been a big part of my own learning process as well, but that may be subjective. The repetition of simpler problems drives points home in my head, and more complex questions force me to study and explore and try to understand things which I wouldn't have otherwise, often leading to interesting insights. And if I say something stupid or incorrect, someone is (usually) around to correct me and help right my misunderstanding or oversight.

My recommendations in summary: work through a structured C#/coding fundamentals course, the Unity Learn Junior Programmer Pathway, and find a community in which you're comfortable asking and answering questions. Aspire to get to a place where the scripting docs and format make sense.

final kestrel
#

I was working on a seperate project just to test something while original project was open on my other screen. It took me an hour to realize that I was actually changing the other projects code and expect things to work on my other project T_T

hallow acorn
polar acorn
#

If GameOver is false when this object is first created, you start a repeating function

#

and nothing ever stops it

hallow acorn
#

oh

#

so what can i do about it?

polar acorn
#

You probably shouldn't use InvokeRepeating at all and make a coroutine instead

hallow acorn
polar acorn
#

The if condition only checks when that code runs. Update runs every frame. Awake runs once.

hallow acorn
polar acorn
#

or do you want to check for it every frame

hallow acorn
#

every frame?

polar acorn
#

So, then Update is where it should be

#

Your first one was in Awake. This one is properly in Update

hallow acorn
#

oh yeah ok this one is completely useless if i manage to disable the spawning lol

hallow acorn
polar acorn
#

You're changing a value that is no longer used anywhere

#

InvokeRepeating has already ran

hallow acorn
#

so yeah thats the reason?

polar acorn
#

Awake runs one time, when the object is first created

#

InvokeRepeating runs the given function with the given delay between them

hallow acorn
#

does this change if i use a coroutine?

#

and do i have to use it in update then?

polar acorn
#

You could very easily change the amount of time a coroutine waits

hallow acorn
polar acorn
#

If you want it to loop, it's going to need an actual loop somewhere

hallow acorn
#

for example

polar acorn
#

Well, there's a specific kind of loop that runs for as long as a condition is true

#

And since you want this to repeat until a specific condition happens, that's probably a good starting point

polar acorn
#

If your while loop has a yield in it then it won't be infinite

hallow acorn
ivory bobcat
#

If your while loop doesn't have a yield statement then prepare for the application to crash.

wintry quarry
#

well, only if it's an infinite loop

hallow acorn
#

still dont understand it where and how do i have this magic yield

polar acorn
#

Remember, code runs one line at a time

#

Yield tells a coroutine to wait for however long before resuming

hallow acorn
#

does this work pls tell me it works

    {
        while(projectile.GameOver == false)
        {
            LaunchPrefab();
        }
    }

    IEnumerator LaunchPrefab()
    {
        yield return new WaitForSeconds(Random.Range(spawnRate - 4, spawnRate + 4));
        Instantiate(projectilePrefab, transform.position, Quaternion.Euler(0, 0, 0));
        spawnRate /= IncreaseMultiplier;
    }
polar acorn
#

Awake happens, checks the condition

#

enters the while loop

#

and then calls LaunchPrefab

#

and then calls LaunchPrefab

#

and then calls LaunchPrefab

#

and then calls LaunchPrefab

modest dust
polar acorn
#

and so on

hallow acorn
#

so do i have to put it in update?

#

๐Ÿ™

modest dust
#

Check the docs and think for a bit

polar acorn
ivory bobcat
hallow acorn
hallow acorn
modest dust
#

How to start it and loop it correctly

polar acorn
hallow acorn
ivory bobcat
#

It's pretty straight forwardcs void Update() { if (Input.GetKeyDown("f")) { StartCoroutine(Fade()); } } IEnumerator Fade() { Color c = renderer.material.color; for (float alpha = 1f; alpha >= 0; alpha -= 0.1f) { c.a = alpha; renderer.material.color = c; yield return null; } }

polar acorn
# hallow acorn i dont think i get it but do i have to put my yield on the end of the coroutine?

Let me explain to you how code flow works with coroutines.

Code runs one line at a time. An object gets created, then the Awake on it runs.

Whenever you hit StartCoroutine, the instruction pointer will jump into that coroutine function, and continue to run one line at a time until it hits a yield return, at which point it goes back to where the StartCoroutine was called and continues as normal. When the time is up, the instruction pointer jumps back in to the coroutine, the line right after the yield, and continues from there.

Whenever the code hits a while loop, it checks if the condition is true. If it is, then it enters the body of the loop (inside the {}) and runs it one line at a time. When it hits the end of it, it goes back to the loop condition and checks it again. If the condition is still true, it repeats. Whenever it checks the condition, and it is false, it will skip to the line after the loop body.

silk night
#

public void Main() {
  StartCoroutine(LoopCoroutine());
}

IEnumerator LoopCoroutine() {
  while (...)
    // Code here
    yield return new WaitForSeconds(1f);
  }
}
hallow acorn
polar acorn
#

instead of copying, learn what it's doing

ivory bobcat
#

Ah Digi's given a pretty thorough and lengthy explanation of the procedural process - how things are processed, line by line.

hallow acorn
#

oh wait. i have to put the loop in the coroutine?

modest dust
#

Yes, as all the examples in the docs showcase

hallow acorn
polar acorn
acoustic arch
#

yo im developing a building system for my 2D top down game that uses SetTile where you place down Wall tiles with a Tilemap collider, and each tile needs to have their indivisual currenhealth variable. How can I make it so that each Wall placed down has their own indivisual health using Tilemaps

possibly some sort of Wrapper for each tile

#

(is this even possible)

hallow acorn
#
    {
        LaunchPrefab();

    }

    IEnumerator LaunchPrefab()
    {
        while (projectile.GameOver == false)
        {
            Instantiate(projectilePrefab, transform.position, Quaternion.Euler(0, 0, 0));
            spawnRate /= IncreaseMultiplier;

            yield return new WaitForSeconds(Random.Range(spawnRate - 4, spawnRate + 4));
        }
    }

sth like that?

ivory bobcat
#

You're not acquiring certain info from the docs. You need to Start the Coroutine.

hallow acorn
#
    {
        StartCoroutine(LaunchPrefab());

    }

?

#

no

#

2 brackets to much (idk if thats how its called)

ivory bobcat
#

The basic get up is (without randomly guessing - pseudocode):cs Start/Update if(...) StartCoroutine(...) Coroutine while/for/loop stuff yield

ivory bobcat
#

Where the docs would discuss the specific details and illustrate proper syntax.

hallow acorn
#

ok ill go to sleep ill try again tomorrow

fading mountain
#

hey guys. Im working on a 2d platformer and want the sound effect for running to unpause when the player is on the ground & moving, and pause when the player is not moving, not on the ground, or both. This functionality is called in Update(). I know it needs if statements, else if, and else, but I can't get it right. This is my code so far. https://gdl.space/jowexetina.cs & the Audio Manager script: https://gdl.space/fucikedifa.cs

silk night
fading mountain
silk night
#

please convert the video to something we can watch in discord ๐Ÿ˜„

silk night
#

tbh it sounds like its toggling between playing and pausing pretty quick, you should add some logging to see how often it switches and then to figure out why the planned if statements fail

cinder crag
#

so im trying to make a text appear on the screen when the enemies start spawning but im not sure how can i deactivate it after activating it https://pastecode.io/s/3hqbsu2j (heres the enemyspawner script)

silk night
#

you would be hiding the text here and instantly showing it again but you just have to return the wait again and then disable the text

teal viper
cinder crag
#

okay it works and it disappears but i only want it to appear once and not repeat everytime it spawns an enemy

silk night
#

Then I would start a second coroutine that just does that and contains no loop

#

Unless you are working with DoTween or any other library that brings a delay functionality

copper matrix
#

i just stupidly followed a tutorial and i think i writed somewhere sth which was just an example name but idk what

copper matrix
#

why isnt the isDefend bool triggering

fading mountain
silk night
copper matrix
silk night
#

Yes, you are never setting that bool to true in your script

#

the internal property isDefend is not triggering the animator, do m_Animator.SetBool("isDefend", true/false);

fading mountain
#

@silk night apparently AudioSource.isPlaying doesnt differentiate btween paused and unpaused.

silk night
#

Well that would explain it ๐Ÿ˜„ I was a bit confused why you would have pauseOrUnpause as a function, toggling without knowledge of current state may have some uses but it mostly leads to bugs like this, rather have one pause and one unpause function and only call them when you are sure of the state

fading mountain
#

Ahh okay

#

thank you for your help ๐Ÿ™‚

cinder crag
silk night
cinder crag
silk night
# copper matrix

Put Debug.Log at the positions where it should trigger, if it does not trigger at all find out why, my wild guess is the shuriken has no Shuriken tag

silk night
silk night
# copper matrix

then lets go Logging, find out what is triggering and whats not

silk night
cinder crag
#

alrighty

#

thank you

silk night
# cinder crag thank you

Also you should make your function names more descriptive, like "ShowEnemiesIncomingText", might be a bit tedious to have longer names but imagine yourself in 3 months coming back and not knowing wtf EnemiesIncoming is ๐Ÿ˜„

copper matrix
#

btw this too if it helps

silk night
copper matrix
#
  1. F that, it happens so often
#
  1. now both animations are triggerd at the same time
cinder crag
copper matrix
#

so i added this

#

and this

#

and this happend

silk night
#

Looks like you accidentially reset your reference to the animator in your script, just drag it into the field again

wintry quarry
#

uhhh... what's the deal here

#

GetComponent in Update?
Trying to use it in Start before it's assigned?

#

to be honest it looks like you mixed up your Start and Update to me

silk night
#

oh wow, didnt even see that its switched ๐Ÿ˜„

copper matrix
#

oh fuck XD

silk night
#

well you are still trying to use m_Animator before you assign it

wintry quarry
# copper matrix

i mean you're clearly still trying to use it before assigning it...

#

do you understand how references work and how = works?

copper matrix
wintry quarry
#

x = 5; < this assigns 5 to x

#

now if we do Debug.Log(x) we see 5

#

references work the same way

#

m_Animator = GetComponent<Animator>(); this fetches the animator from our object and assigns it into the m_Animator variable

#

now we can use the animator

#

but... we can't use it before we do that, unless the variable was otherwise assigned.

#

and it also won't work if GetComponent<Animator> returns null for some reason, for example there not actually being an Animator there

copper matrix
#

now i did it and now the character gets invincible

#

invisible

#

not invincible

silk night
#

is there an error in the console?

copper matrix
#

nope

#

i think the animation i did changed the size

#

i found him here

cinder crag
#

https://pastecode.io/s/rebjcyj8 (WaveStartAndStop)

okay so im trying to make a button that starts a wave and stops it and i have multiple spawners in the scene in different locations and with different spawnrates but the problem is on how im referencing the enemySpawner script , is trying to gind a gameobject with the tag Spawner but since i have multiple , its just gonna get one of them , so i got 3 spawners and the WaveStartAndStop script will get the spawner 2 enemySpawner component , so how i can reference one script that is the same from all the spawners

wintry quarry
silk night
#

If they are, make the Property on the script a List<EnemySpawner> and then find the WaveStartAndStop in the inspector and fill the list with all EnemySpawners by dragging the gameobjects they are on onto the list

#

afterwards you can access the list with loops instead of a single spawner

cinder crag
silk night
#

Yeah then just do what i wrote ๐Ÿ˜„

cinder crag
wintry quarry
copper matrix
#

so im kinda frustrated rn because i my characters animation is teleporting me to another Position but i cant find anything to undo it

wintry quarry
#

Usually it's not a good idea to animate the root object with an animator though

#

it ends up doing this - overriding your controls

#

you generally want to only animate child objects

copper matrix
#

how do i do that

wintry quarry
#

Simple - instead of animating the root object in your scrubsheet, animate child objects instead

#

just make sure the bits that need animating are not on the root object

#

move any renderers etc to child objects

copper matrix
#

so i have it like that: Enemy GameObject has with all Scripts and Animations

#

and i should put Enemy in an Empty GameObject and split animations and rules?

silk night
copper matrix
#

but isnt the animator the thing which changes the gameobject which is connected to it :(

wintry quarry
silk night
#

Animator is just the control center of animations

wintry quarry
#

it all depends what you set up in the scrubsheet

silk night
#

yeah what praetor said ๐Ÿ˜„

wintry quarry
#

with the keyframes

copper matrix
#

too many words i dont understand ngl

wintry quarry
#

FOr example this animation clip is animating many child objects

#

you can see the paths to the objects on the left side

#

and the keyframes on the right

silk night
#

Your animator is like a control center
It can contain many animations and control when to play which one

Any animation can change the root object (where your animator is on) or any object below it

copper matrix
#

so the Animator is like Photshop Animator and i add components like pictures to it (childs)

wintry quarry
#

Not familiar with photoshop animator >_>

silk night
#

so your player would technically still be on the original position, just some image gets moved around

copper matrix
#

but my player is moving

#

like its hitbox and everythign

silk night
#

yeah thats why you should animate a child object of the player, not the root

copper matrix
#

didnt change a thing on my main character and now he just disappers

#

i have many scripts which delete him but none of them are instant on the field

#

by removing the box collider i stopped it

crisp anvil
#

Any idea why this always return's the same value?

    {
        float x = Random.Range(MapManager.Instance.MapX, MapManager.Instance.MapXMax);
        float y = Random.Range(MapManager.Instance.MapY, MapManager.Instance.MapYMax);
        Debug.Log($"Generated Random Position: x={x}, y={y}");
        return new Vector3(x, y, 0);
    }```
void Start()
{
    MapXMax = GameMap.cellBounds.xMax;
    MapYMax = GameMap.cellBounds.yMax;
    MapX = GameMap.cellBounds.x;
    MapY = GameMap.cellBounds.y;
    Debug.Log($"MapManager Started, MapXMax: {MapXMax}, MapYMax: {MapYMax}, MapX: {MapX}, MapY: {MapY}");
}

MapManager Started, MapXMax: 32, MapYMax: 18, MapX: -38, MapY: -36

#

this is constant valve that is always returned
Generated Random Position: x=-16, y=-36

ivory bobcat
coarse hatch
#

How come on a MonoBehaviour, i can reference a prefab with a ComponentType

[SerializeField] private MyPlayer PlayerPrefab; and i can use the inspector to search prefabs that have the component, but i can't do the same thing from a scriptable object, the same kind of SerializeField just doesn't come up with anything.

ivory bobcat
coarse hatch
#

I'm not looking for scene objects, i'm loooking for prefabs at the asset/project level

#

I make an empty game object, add any monobehaviour to it let's say "MyPlayer"

Then i can make it into a prefab into my assets folder.
I'm able to find it from the inspector on game objects or drag it into MyPlayer typed properties on Monobehaviours, but not ScriptableObjects

rich adder
coarse hatch
#

yes

crisp anvil
# ivory bobcat log the instance's value of map x and map x max before using it with random rang...
Generated Random Position: x=-16, y=-36
Spawning LightningStrike at (-16.00, -36.00, 0.00)
Instantiated LightningStrike(Clone) at (-16.00, -36.00, 0.00)
Distance to player: 42.70246
    private IEnumerator SpawnWeatherEffect(GameObject prefab, int count, float effectDuration)
    {
        for (int i = 0; i < count; i++)
        {
            Vector3 position = GetRandomPosition();
            Debug.Log($"Generated Random Position: x={position.x}, y={position.y}");

            Debug.Log($"Spawning {prefab.name} at {position}");
            GameObject effect = Instantiate(prefab, position, Quaternion.identity);
            Debug.Log($"Instantiated {effect.name} at {effect.transform.position}");

            activeWeatherEffects.Add(effect);

            if (currentWeather == WeatherState.Thunderstorm)
            {
                float distance = pathFinder.GetDistanceBetweenGameObjects(Game_Manager.instance.player.gameObject, effect);
                Debug.Log($"Distance to player: {distance}");

                AdjustWeatherEffectBasedOnDistance(effect, distance);

                AssignThunderAudio(effect);
                AdjustThunderAudioBasedOnDistance(effect, distance);

                StartCoroutine(DisableSpriteAfterTime(effect, effectDuration));
            }
            else
            {
                StartCoroutine(DestroyAfterTime(effect, effectDuration));
            }

            yield return new WaitForSeconds(0.1f);
        }
    }
ivory bobcat
#

Log the arguments that you're using with Unity Random

#

If it's (-16,-15), you'll only get -16

crisp anvil
#
Random.Range with mapX: -38, mapXMax: 32, mapY: -36, mapYMax: 18
Generated Random Position: x=-30.97226, y=-13.01677

every time i play the scene and hit my hotkey to run the script it changes the position, It has to be something with my Coroutine?

ivory bobcat
#

Maybe consider showing us the Get Position function

crisp anvil
#
    private Vector3 GetRandomPosition()
    {
        float mapX = MapManager.Instance.MapX;
        float mapXMax = MapManager.Instance.MapXMax;
        float mapY = MapManager.Instance.MapY;
        float mapYMax = MapManager.Instance.MapYMax;
        Debug.Log($"Random.Range with mapX: {mapX}, mapXMax: {mapXMax}, mapY: {mapY}, mapYMax: {mapYMax}");
        float x = Random.Range(mapX, mapXMax);
        float y = Random.Range(mapY, mapYMax);
        Debug.Log($"Generated Random Position: x={x}, y={y}");
        return new Vector3(x, y, 0);
    }```
ivory bobcat
#

That would be where you're getting the (-16, -36) from

ivory bobcat
crisp anvil
#
Random.Range with mapX: -38, mapXMax: 32, mapY: -36, mapYMax: 18
Generated Random Position: x=-20.58329, y=-30.5786
Spawning LightningStrike at (-20.58, -30.58, 0.00)
Instantiated LightningStrike(Clone) at (-20.58, -30.58, 0.00)
Distance to player: 39.93124
Assigned Thunder Audio to LightningStrike(Clone) at position (-20.58, -30.58, 0.00)
Random.Range with mapX: -38, mapXMax: 32, mapY: -36, mapYMax: 18
Generated Random Position: x=-20.58329, y=-30.5786
Generated Random Position: x=-20.58329, y=-30.5786
Spawning LightningStrike at (-20.58, -30.58, 0.00)
Instantiated LightningStrike(Clone) at (-20.58, -30.58, 0.00)
Distance to player: 39.93124

this is two Instances of the instanitation

ivory bobcat
#

So the positions are fine and everything works as expected

crisp anvil
#

but wouldnt this from the coroutine
for (int i = 0; i < count; i++)
{
Vector3 position = GetRandomPosition();

call a different postion for each iteration through the loop?

ivory bobcat
#

What's the issue here?

#

I'm pretty sure it is

#

Chances are, all of your objects are the same object if they all share the same values

#

You'll need to provide more information if you aren't wanting us to guess

crisp anvil
#

They are the same object, But wouldn't this
GameObject effect = Instantiate(prefab, position, Quaternion.identity);
update the positon of the object? they are all currently spawning in the same location.

ivory bobcat
#

How are you determining that the positions are all the same?

#

Show logs for each object being instantiated and the position they're given

crisp anvil
#
Random.Range with mapX: -38, mapXMax: 32, mapY: -36, mapYMax: 18
Generated Random Position: x=-20.58329, y=-30.5786
Generated Random Position: x=-20.58329, y=-30.5786
Spawning LightningStrike at (-20.58, -30.58, 0.00)
Instantiated LightningStrike(Clone) at (-20.58, -30.58, 0.00)
Distance to player: 41.34794

Assigned Thunder Audio to LightningStrike(Clone) at position (-20.58, -30.58, 0.00)
Random.Range with mapX: -38, mapXMax: 32, mapY: -36, mapYMax: 18
Generated Random Position: x=-20.58329, y=-30.5786
Generated Random Position: x=-20.58329, y=-30.5786
Spawning LightningStrike at (-20.58, -30.58, 0.00)
Instantiated LightningStrike(Clone) at (-20.58, -30.58, 0.00)
Distance to player: 41.34794

Assigned Thunder Audio to LightningStrike(Clone) at position (-20.58, -30.58, 0.00)
Random.Range with mapX: -38, mapXMax: 32, mapY: -36, mapYMax: 18
Generated Random Position: x=-20.58329, y=-30.5786
Generated Random Position: x=-20.58329, y=-30.5786
Spawning LightningStrike at (-20.58, -30.58, 0.00)
Instantiated LightningStrike(Clone) at (-20.58, -30.58, 0.00)
Distance to player: 41.34794

Assigned Thunder Audio to LightningStrike(Clone) at position (-20.58, -30.58, 0.00)
Random.Range with mapX: -38, mapXMax: 32, mapY: -36, mapYMax: 18
Generated Random Position: x=-20.58329, y=-30.5786
Generated Random Position: x=-20.58329, y=-30.5786
Spawning LightningStrike at (-20.58, -30.58, 0.00)
Instantiated LightningStrike(Clone) at (-20.58, -30.58, 0.00)
Distance to player: 41.34794```
ivory bobcat
#

Well, during this function all of your calls to Get Position are returning the same values

frigid schooner
#

hello anyone can help me with respawning?

summer stump
frigid schooner
#

I have python programming background and im new to unity and C#. I am following youtube tutorials on making a 3D fps game. I am trying to figure out the falling/dying + respawning part right now.

ivory bobcat
frigid schooner
#

I tried some forums and it didnt work

#

This is the code for my trigger

summer stump
frigid schooner
#

Yes, the logs are called, and the position of the camera and player seem to be updated. but in the render I just fall through the trigger

summer stump
#

The respawn trigger has a rigidbody? Odd.
What does the player have

frigid schooner
#

player have rigidbody

#

trigger has rigidbody and box collider and I checked the box IsTrigger

#

im not sure what I did wrong, but from what I understand, player.transform.position is the variable that holds the player position, transform is the category and position is under the transform category. By setting it to equal the respawn point I can teleport to the respawn point. I also tried setting it to a vector3 and it also didnt work

#

The camera should follow the player right? would it be that im just setting the gameobject player to respawn but the camera falls through?

frigid schooner
crisp anvil
ivory bobcat
stray thorn
#

i keep gettig an error idk where the problem is

#

my ide is configured it should underline the error

#

it only comes up when i run the game

summer stump
#

Controller is null when you try to access it

raw token
#

Is the script you've shared Assets/Character.cs?

stray thorn
#

yea

raw token
#

The class name should be Character rather than Example - the name of your MonoBehaviour should match the name of the file

summer stump
#

Unless it is editor version 2022.2+
Still good practice though

raw token
summer stump
stray thorn
#

so how do i fix

summer stump
#

Make sure controller is not null at that time, use a debug.log

stray thorn
#

man i started literally last night idk any of these words

summer stump
summer stump
eternal falconBOT
#

:teacher: Unity Learn โ†—

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

summer stump
#

Debug.Log specifically should be something you know already. Often it is taught VERY early in a course

stray thorn
summer stump
# frigid schooner

Your player IS moving it looks like. So perhaps something else is setting the position back
Is there a CharacterController on the player along with the rigidbody?

frigid schooner
frigid schooner
summer stump
summer stump
#

You have to disable it, teleport, then re-enable it

#

Otherwise it IMMEDIATELY resets the player position to where it was last

frigid schooner
#

wait I dont get it can you explain why

summer stump
#

Btw, a rigidbody and CharacterController should never be on the same object.
There are some times where a KINEMATIC rigidbody is ok, but that is kinda niche.
You could actually justify the trigger area having the rigidbody to get around this issue forgot that OnTriggerEnter does work with CharacterController
Only OnCollisionEnter does not

summer stump
frigid schooner
#

oh i see

#

thanks for the insight

#

what should I do now?

summer stump
frigid schooner
#

cuz im still relatively new, and I just followed some youtube guy and did CC

#

can you show me the code to disable the CC?

summer stump
#

MyCCReference.enabled = false
transform.position = whatever
MyCCReference.enabled = true

frigid schooner
#

sorry i dont understand ...

#

do I have to reference the CC as a serialize field?

#

or do I just do use the player in the serialize field and use
player.CharacterController.enabled = false;

summer stump
#

TryGetComponent is better, so I'm gonna show that. It will likely introduce something you don't know, which is the out keyword. That is basically just a second return. TryGet returns a bool telling you if you actually found the component, but you also get the reference "out"

if (other.TryGetComponent(out CharacterController cc) 
{
  cc.enabled = false;
  cc.transform.position = respoint.transform.position;
  cc.enabled = true;
}
frigid schooner
#

does this work

summer stump
#

Yes, I would validate the collision though. Either check if cc is null before using it, or check the tag or something (or both)

#

Because right now this will run that code on ANY collider that enters the trigger area

frigid schooner
summer stump
frigid schooner
#

yes

summer stump
#

Ok and what is not working?
Do you get any errors?

frigid schooner
#

the name cc does not exist in the current context

#

do I have to use a type like int / float ? what type is cc

summer stump
#

Oh of course. That is simply not how you declare a variable.

#

You need to include the type on line 19

#

CharacterController cc =

#

By the way, your ide is not configured.
!ide

eternal falconBOT
summer stump
#

Third link โ˜๏ธ

frigid schooner
#

whats the use to config the ide

frigid schooner
summer stump
frigid schooner
#

ok thank you

summer pilot
#

Trying to make it so players cannot sprint while crouched, instead of doing this:

if (isRunning)//If player IS holding LShift
                {
                    if (!isCrouching)
                    {
                        playerSpeed = runSpeed;
                    }
                }
                else//If player is NOT holding LShift
                {
                    playerSpeed = walkSpeed;
                }

Can I just do:

if (isRunning)//If player IS holding LShift
                {
                    (!isCrouching)
                    playerSpeed = runSpeed;
                }
                else//If player is NOT holding LShift
                {
                    playerSpeed = walkSpeed;
                }
summer stump
summer pilot
#

i know i can do stuff like that in javascript, but idk if c# works the same

summer stump
summer pilot
summer stump
#

It will set playerSpeed to runSpeed whenever you hold left shift. Whether crouching or not..

summer pilot
summer stump
#

Just combine them

summer pilot
#

oooo, smart

#

thank you

#

!code

eternal falconBOT
summer pilot
summer pilot
#

horizonal is left to right

#

right?

rich adder
#

yeah that would be Horizontal

summer pilot
#

oh..

#

spelling mistake

#

my bad

rich adder
#

strings ๐Ÿ™‚

#

you good

summer pilot
#

wish vscode would underline that LOL

rich adder
#

impossible

#

the compiler has no idea if the string is valid for it or not

#

it just knows Oh its a string, good to go

summer pilot
#

well i did that any my player is just flying straight into the air LOL

rich adder
#

btw you should not move transform.positions with any physics objects

#

including character controller

summer pilot
#

oh

#

what should i do?

rich adder
#

use their built in movement methods

#

for CC you have .Move for example

summer pilot
#

so instead of transform.position i should be using characterController.Move?

rich adder
#

yea

#

not saying thats fixing whatever you said was broken, but if you want collisions to actually work properly then absolutely

summer pilot
#

so something like this?

characterController.Move(transform.position + playerMovement.normalized * playerSpeed * Time.deltaTime);
rich adder
#

you can remove transform.position

summer pilot
#

do i not need to grab the current position?

rich adder
#

no

#

cc.move tracks already where it is, this is local movement

summer pilot
#

ahhh

#

well, player still flies in the air. not sure why

summer pilot
rich adder
rich adder
#

oh it might be jump strength

#

i just noticed you added that in

summer pilot
rich adder
#

yeah but right now you're telling to Keep flying up 7 units at time every frame

#

thats not setting your jump height

summer pilot
#

oh

rich adder
#

look at the example i sent for CC.Move it shows how you have to make gravity(create/track vertical velocity) if you want jump to work

summer pilot
#

ill give that a try

#

thank you

summer pilot
fierce geode
#

Is it true that programming your animations for UI is better than using Unity animations. I heard that animation updates every frame even when finished or something similar which makes it bad for performance

fierce geode
#

Though that's my uneducated guess.

rich adder
summer pilot
# rich adder it checks if there is any movement

yeah, i did basically exactly what that says (adding my own variables in some places) and it's still sending me flying

    void Update()
    {
        if (!PauseMenu.GameIsPaused)//Checks if the game is NOT paused
        {
            Cursor.visible = false;
            Cursor.lockState = CursorLockMode.Locked;

            playerIsGrounded = characterController.isGrounded;
            if (playerIsGrounded && playerVelocity.y < 0)
            {
                playerVelocity.y = 0;
            }
            float x = Input.GetAxis("Horizontal");//Left->Right
            float z = Input.GetAxis("Vertical"); //Forwards->Backwards
            Vector3 move = new Vector3(x, 0, z);
            characterController.Move(move * Time.deltaTime * playerSpeed);

            if (move != Vector3.zero)
            {
                gameObject.transform.forward = move;
            }

            if (Input.GetKey(KeyCode.Space) && playerIsGrounded)
            {
                playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravity);
            }
            playerVelocity.y += gravity * Time.deltaTime;
            characterController.Move(playerVelocity * Time.deltaTime);
        }
    }
}
summer pilot
#

sure thing!

rich adder
#

gravity should be negative no?

summer pilot
#

welp

rich adder
#

put -17 instead of 17

summer pilot
#

no longer flying

#

but im not moving

#

im rotating on the axis

#

just looking left/right

rich adder
#

remove the transform.forward = move

#

if this is fps

#

a lot of this needs to be changed

summer pilot
summer pilot
#

yup

#

i was using player speed (set to 0 by default)
i swapped to walkSpeed and it works

olive lintel
#

ik I just deleted allat

#

sorry ๐Ÿ’€

thorn lake
#

I need some help:

While using 2022.3.ff1, I typed the following in an if statement:

Keyboard.current.leftArrowKey.isPressed

Originally, people needed to include

using UnityEngine.InputSystem;

to get it to work but it looks like that namespace is no longer necessary.

With or without that namespace, I get the following error whether or not I have the Input System package installed:

Error (active) CS0103 The name 'Keyboard' does not exist in the current context Assembly-CSharp

I looked online but am having trouble finding a correct solution. So far the solutions have been to add the namespace but those are outdated or to add the Input System package but that didn't work either

mint remnant
#

this error looks like its from VS, did you check the references for all valid assemblies?

thorn lake
#

Yes, it's from VS.

did you check the references for all valid assemblies?
^ This is new language to me. What do you mean by this?

mint remnant
#

in the solution panel you will find all hte assemblies, see if any show a warning icon first

rich adder
thorn lake
mint remnant
#

no, over in the solution panel

rich adder
#

its called Solution Explorer

#

its in the View tab

rich adder
#

why are you still on vs2019

mint remnant
rich adder
thorn lake
eternal needle
#

i was gonna say, do you have the input system installed in unity?

thorn lake
#

I do

mint remnant
#

another question is does the error actually show up in unity as it tries to compile it

rich adder
thorn lake
#

After re-adding the "using UnityEngine.InputSystem;" code back in after adding the Input systemit seems to be working now....? I'm not sure if it just needed time or what. I had turned VS off and on again and it didn't solve it earlier so I'm not sure why it's working now

mint remnant
#

keep in mind Unity and VS are seperate, it could fail to compile in VS and yet work in Unity if for soem reason your assemblies aree't the same

thorn lake
#

Maybe I hadn't tried all 4 combinations of having the Input package, not having it, having the namespace, not having the namespace until now?

eternal needle
#

couldve just been a small bug, but most likely user error. The comments you read on that tutorial arent true though because Keyboard is under UnityEngine.InputSystem

rich adder
#

yes that dude is talking nonsense

rich adder
#

putting new input system inside UnityEngine would defeat the whole point of using packages

#

they're made so they dont have to update/release the whole app to fix 1 thing related to inputs

thorn lake
#

It must have just needed time to fully integrate the Input package because only a moment ago did Unity have the popup saying to Enable backends or something for keybaord input

rich adder
#

regen project files sometimes can help

thorn lake
#

uh oh, after restarting after enabling backends it's making me enter w/safemode.

....wait, nvm. It's just bc I re-commented out the namespace to test something ๐Ÿ˜…

rich adder
#

did you save with compile errors?

eternal needle
#

surprised the unity learn site is even using Keyboard.current

thorn lake
#

I had done this tutorial a few years ago and it used something like that back then too. Can't rmember if it was exactly the same. They've changed it.

#

Thanks for the help you guys

#

Mainly am doing this tutorial to remind myself how to make a 2D Player Controller and have it interact with colliders.

I'm guessing there's already some player controllers like this in the Asset Store but was only seeing ones for platformers.

#

It's good for me to redo this though. I'm super green again despite programming all through college haha

spiral glen
#
        var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);```
anyone know why this code makes it so the 'looking of the mouse' is like... wrong?
#

it's turning based on the mouse

#

but my mouse is to the right and it's looking up

#

if my explanation is off I can record a video of it rq

#

I tried to find a video to explain how to make it but each video has a similar issue of the character not looking at the mouse

eternal needle
spiral glen
#

sure give me a minute or honestly three

#

I realized the camera was on the player which could of caused the issue but it still wasn't

#

It's like 90 degrees off

#

I fixed it by removing 90 from the angle

#

idk how it works but it does

#

mb

eternal needle
# spiral glen

click on the object you have, its red arrow is likely pointing towards the mouse, which is the "right"

#

You could also just change the object so its facing right to begin with, rather than up

spiral glen
#

I mean, I fixed it by just minusing 90 degrees from the angle

#

I guess it's kinda the same deal as making it start as right instead of up

supple wasp
spiral glen
#

what

eternal needle
supple wasp
#

It's not that the screen looks very big

spiral glen
#

ah

#

I have a big monitor ๐Ÿ™‚

#

only one though which sucks

#

worst part is I'm going to college soon so getting a second monitor would be worthless in two months

supple wasp
spiral glen
supple wasp
#

My laptop has 4 ram with a 2.30ghz Pentium inside t4500 processor but it is WELL MADE GARBAGE

spiral glen
#

I have a computer and I don't remember the stuff inside it

supple wasp
#

That's why I had to change to the "old" laptop so to speak, it's been with me for 1 year, well 1 and a half of this year.

spiral glen
#

I forgot to clean it for 3 years which almost caused it to get set on fire

#

smelt like smoke

eternal needle
#

just saying, off topic isnt really allowed in this server

supple wasp
#

If true...

spiral glen
#

on topic, for an attack delay, lets hypothetically say a punch, would using a coroutine be good for the punch animation of the punch or is there a better way?

supple wasp
#

As you say

spiral glen
#

๐Ÿ‘

eternal needle
spiral glen
#

well I just made it

hallow acorn
#

so tried for a good amount of time and im afraid of infinite loops so does this work properly or am i stupid? ```using System.Collections;
using UnityEngine;

public class CanonMain : MonoBehaviour
{
public GameObject projectilePrefab;
public float spawnRate;
public Projectile projectile;
private float increaseMultiplier = 1.05f;

void Awake()
{
    StartCoroutine(LaunchPrefab());

}

IEnumerator LaunchPrefab()
{
    while (projectile.GameOver == false)
    {
        Instantiate(projectilePrefab, transform.position, Quaternion.Euler(0, 0, 0));
        spawnRate /= increaseMultiplier;

        yield return new WaitForSeconds(Random.Range(spawnRate - 4, spawnRate + 4));
    }
}

}```

rich adder
eternal needle
hallow acorn
eternal needle
rich adder
hallow acorn
worthy tundra
#

its long to explain my problem in words so i illustrated it.
my enemy script has logic for seeing the player (the enemy can only fire if the player is in line of sight).

i do this using a raycast

Physics.Raycast(eyes.position, transform.forward, out hit, distanceToAttack + playerSightRange, playerAndBlockLayers);

eyes is a transform where the "face" of the enemy should be, playerAndBlockLayers is a layermask that includes the enemy layers, the player layer and the ground / obstacles layer

the system works fine when the player is standing but the moment the player crouches suddenly the raycast goes through walls and the enemy cannot have line of sight with the player

why

rich adder
hallow acorn
eternal needle
worthy tundra
eternal needle
rich adder
#

fun fact: new physics debugger tab has now "Casts" you can see all types of casts

eternal needle
# worthy tundra dw i fixed it lol

still, read my advice. Use debug.DrawRay to visualize your raycasts. your problem came because you assumed whats happening rather than knowing for real. And the assumption was wrong

hallow acorn
worthy tundra
#

problem is the enemy object is locked on Y rotation so it couldnt rotate the transform.forward whent he player was crouching, so i just changed to the eyes which can rotate as they please

worthy tundra
#

oh right wait i didnt use drawray

#

bruh im stupid lol

eternal needle
#

gizmos? and if you saw the raycast then you would see it wasnt pointing downwards and going through the player

#

which is what your drawing had

worthy tundra
#

yeah im stupid lmfao

eternal needle
#

step away from the code because its likely just confusing you more. Do it with real numbers and see what these values lead to. Maybe plot it on desmos if you know how

hallow acorn
#

but if my spawnrate is 13 and it keeps getting divided by 1.05, it should work if i set the 4 to half of the spawnrate for example

eternal needle
hallow acorn
#

also why doesnt it stop when GameOver = true;? i tested it and gameOver is actually true so why doesnt my while loop stop?

rich adder
hallow acorn
rich adder
#

the one on the instance

hallow acorn
#

it says true

rich adder
#

in the inspector?

hallow acorn
#
        if (explodingTime <= 0)
        {
            GameOver = true;
            particle.Play();
            StartCoroutine(Wait());
            Debug.Log(GameOver);
            aud.Play();
        }
hallow acorn
#

yeah it is

rich adder
#

and if you click Projectile it takes you to the one that says true?

hallow acorn
#

wdym?

#

i click on the clone which is exploding and it says true for 0.6 seconds untill it gets deleted

rich adder
eternal needle
#

Some simple debugging really is gonna show you why all this is happening

rich adder
#

what did you link in the inspector in public Projectile projectile; this isn't what ur spawning btw

#

I would rewrite this whole thing

hallow acorn
#

wait i linked the prefab but the prefab doesnt change does it?

rich adder
#

you need the gameover from the instance

#

but in the while loop it wont make sense

#

since you have to create it first

hallow acorn
eternal needle
rich adder
#

that too

rich adder
hallow acorn
rich adder
#

first use a Global gameover bool

#

not the one on bullet

#

have bullet only affect whichever script has that public bool gameover (ideally you wuld use method instead of directly touching a public var)

hallow acorn
rich adder
eternal needle
#

Imma be honest, if your goal is just to publish the bare minimum that runs, you shouldnt be using game jams to learn. You clearly are ignoring basic debugging steps as well, something I know that you've done for the spawn rate before in a past convo.

#

This isnt the way to learn, this is just struggling but on a deadline

rich adder
#

gamejam is good practice, not so much learning if you're pressed on time

hallow acorn
eternal needle
rich adder
#

but I would follow bawsi's advice here

#

debugging should be your #1 priority

#

plan out your loigc a bit more before putting any code

native hill
#

im not sure if this is the right channel soryr

rich adder
#

โฌ

eternal falconBOT
native hill
#

thank you

rich adder
native hill
#

yeah

#

i think so at least

rich adder
#

btw for future no need to put multiple classes in 1 link that can get confusing if we're looking for speicifc lines

native hill
#

oh alright sorry

rich adder
#

np

#

can you show rigidbody settings rq

native hill
#

yeah, give me a second

rich adder
#

oh yea Kinematic wont go anywhere unless specifically told to

#

also should not use Translate to move rigidbodies

native hill
native hill
#

what should I use?

rich adder
#

I mean you're running unity on the pc, it can handle a screenshot

native hill
#

i tried opening snipping tool and it was super slow Iโ€™m using Boot Camp so Iโ€™m not sure if the controls are the same but Iโ€™ll give it a try

#

itโ€™s a super old mac

rich adder
#

why not run unity natively?

#

it runs very well on macos

native hill
#

alright I turnt off kinematic and and my body Is shaking a bunch and stuff

native hill
#

I didnโ€™t think Iโ€™d ever use unity

native hill
#

hold on Iโ€™ll record

hallow acorn
native hill
#

I might redo the code for player movement

rich adder
hallow acorn
rich adder
#

yeah they can be overused because they are so easy to use

#

but then it just becomes a mess of singletones instead of properly injecting components

harsh pecan
#

having this glitch dk why can anyone help

rich adder
#

it tells you exactly whats wrong
using Camera.main without camera tagged in scene wont work

hallow acorn
#

why doesnt it recognise setActive?

rich adder
languid spire
rich adder
#

it should be capital S

#

wonder why VS not correcting you on that

#

my keyboard is shitting bricks notlikethis

languid spire
#

this is not the first one

hallow acorn
rich adder
languid spire
#

it wont do setActive does not exist

hallow acorn
harsh pecan
rich adder
rich adder
#

only gameobjects do

#

canvas.gameObject.SetActive

#

if it wasn't showing up, it didnt exit ๐Ÿ˜›

hallow acorn
#

that worked ty

harsh pecan
#

how do I make charecter show up un mirror

#

no navarone went to bed

rich adder
harsh pecan
rich adder
#

because you didn't write code to do it UnityChanLOL

true heart
#

i have a function that takes a range/int and uses that to find all the tiles/vector2s around a position that are in range, it then puts that into a list called inrange2 then it sends that list to another function. the issue is im using 2 for loops one inside another to find where all these positions are and it seems to be crashing my game. the range given is always 2

keen dew
#

The second loop is missing the i++ part

true heart
#

ohh i might be slow

#

ty man

#

i was losing it

languid spire
true heart
#

oh ya true

rancid tinsel
#

can you use navmesh to make agents find new paths if the current one is blocked by another navmesh agent?

#

or would I have to code that feature myself?

crisp lantern
#

anyone got any idea why the Character Controller Component likes to flicker isGrounded? really awesome

idle ginkgo
#

is there any short cut or plugin to implement wait for seconds

#

like the whole i enumerator thing

#

just for adding wait for seconds

queen adder
#

i love unity

rancid tinsel
idle ginkgo
#

ok

rancid tinsel
#

also keep in mind, if you are planning on changing the game speed at any point with a speed up button etc but you want the wait for seconds to remain the same, use WaitForSecondsRealtime

idle ginkgo
#

oh ok thanks

sleek gazelle
#
if(!revived){
                        deathScreen.SetActive(true);
                        lastChance.SetActive(true);
                    }
                    else{
                        deathScreen.SetActive(true);
                    }
                    finalScore.GetComponent<TextMeshPro>().text = Score.ToString();
#

finalScore is a child of deathScreen, why does it say me object reference = null?

#

Maybe I can't change components of a gameobject I just activated in the same frame?

#

I need help please

#

And when I do Debug.Log(finalScore) it write "FinalScore (UnityEngine.GameObject)"

broken cargo
open harbor
#

Hello ๐ŸŒŽ

sleek gazelle
#

It worked

#

Ty

broken cargo
# sleek gazelle It worked

FYI, TextMeshPro is not the component that you are using here. That's why you got a null ref. TMP_Text is an abstract class for all Text components in TMP

sleek gazelle
#

Ok thanks

#

I'll try to remember that

rancid tinsel
#

is there a way to check which navmesh surface a navmeshagent is on currently?

languid spire
rancid tinsel
#

and that did the trick lol but i hate using workarounds like that

queen adder
#

@slender nymph
#๐Ÿ’ปโ”ƒunity-talk message

  1. I have UnityEvent(s) in my Singleton. This is due to Project needs, i wont change it to static or anything else. It must be serializable, in scene without any references to other scene object. I need to unregister events.
  2. You are right but not works as i mentoined.
slender nymph
#

if the intention is just to unsubscribe from the unityevents, why not just do that in OnDisable? And also if you are lazy loading the singleton with no way to check if it is valid outside of the singleton then you'll need to implement some way to check if it is valid if you need it to not lazy load in these situations

#

and if you need further help then you'll need to show the actual code

queen adder
#

Still, the execution order is off. No point at using OnDisable in this case

slender nymph
#

you need to stop relying so much on the execution order

queen adder
slender nymph
#

i gave you a suggestion as to how and you said there was no point. so at this point until you show code, i'm not going to bother providing any other advice since there's "no point" in following it apparently

teal viper
#

There's no point in trying to help Wilhelm

queen adder
slender nymph
eternal needle
#

what part of the execution order is "off". I looked in the other channel you posted it, and your screenshot only shows a bunch of logs saying "OnDestroy.." which just sounds more like you arent aware of the order

queen adder
#

Everyone has the right to argue about something. Okey okey i will show the code wait a second

teal viper
eternal needle
queen adder
slender nymph
#

so suddenly your issue is happening because of Awake? are you just going to change what the issue is until someone tells you something that you like instead of helping diagnose the actual issue?

queen adder
#

Okay lets stop digital abuse and be real. Do you think the code itself has any problems?

slender nymph
#

how could i know when you can't even get the actual issue straight? not only that, but even if the issue were still somehow related to OnDestroy and an instance being created there, you didn't show real code that is affecting that, you showed your singleton implementation, but not the code where the issue is actually happening.

queen adder
#

I exactly sent every single piece of code that creates the problem. It is in the link. I just prettied a little to make easier to read for you

copper matrix
#

what did i do wrong

#

better view

slender nymph
copper matrix
eternal falconBOT
teal viper
queen adder
# slender nymph no you didn't. you showed your shitty little test class which has nothing to do ...

Come onn i said from the beginning, my problem was execution order. You just wanted the code. Accessing a singleton from TestBehaviour.OnDestroy() triggers an error sometimes but as i said, it happens randomly. I cant give you an example that always happens. My exact problem here is execution order, not the singleton. I asked why would Execution Order does not respects? I actually testing while we are talking.

slender nymph
#

Accessing a singleton from TestBehaviour.OnDestroy() triggers an error sometimes
but you're literally not doing that in the code you provided

hallow iris
queen adder
burnt vapor
#

The error indicates what line of code has this issue

#

To fix, either ensure it stays in bounds using a check or fix the actual index

#

Idk what the index is supposed to be so can't help you there

ivory bobcat
slender nymph
burnt vapor
ivory bobcat
#

Where either 0 index for card types is out of range or the index result cast to int is out of range

burnt vapor
#

I'd say you log the index that you try to access and figure out why it's not the value you expect, or it's bigger than what the array allows

hallow iris
queen adder
burnt vapor
hallow iris
burnt vapor
# hallow iris

So does "chaos card" add a new card index that you try to retrieve here?

#

Because I assume your array just needs to be one index bigger

eternal needle
ivory bobcat
# hallow iris how can i fix this?

Check if the card type array has at least one element - index 0.
Check if the card colors array has an index greater than the value acquired from card types of index 0.

burnt vapor
#

Just to somewhat spoonfeed

queen adder
burnt vapor
#

cartType has 7 entries, cardColours has 6
So as I mention, your array is too small

hallow iris
#

thanks

#

u are a life saver

burnt vapor
#

Well I just want you to understand the point of the error and what to look for, so hopefully that makes sense

ivory bobcat
slender nymph
#

as far as we know there's no actual error. it's just that their singleton gets recreated when accessed from OnDestroy sometimes. but they won't show the actual code that causes that to happen

slender nymph
#

nor will they listen to advice about how to prevent it

eternal needle
#

Cant imagine you'll get any better response from the people who will just tell you the order works as intended

#

Hell, I submitted a ticket for something that's actually a bug and the response back was "bug identified, will look into this" followed by "it's intended"

inland narwhal
#

Guys i created a runtime terrain sculptor script with chatgpt but lowering just working on raised areas
i gave dozens of correction instructions but it just couldnt fix, what can be the problem ?
It just dont makes lowering under Z 0 position
I started to think problem is not script sided

eternal needle
languid spire
#

omg, is this the future of programming? 'GPT didn't develop the code I wanted even though I asked it a lot, please help me'

scenic saffron
#

why not working?

ivory bobcat
languid spire
slender nymph
# scenic saffron why not working?

also unrelated to the actual error, but this will just assign this object's transform to the variable because GetComponentInChildren checks itself first

inland narwhal
slender nymph
#

just drag the reference into the inspector and remove that line entirely

eternal needle
stray thorn
#

does anyone know how i can use occlusion culling on a terrain and the trees and grass painted on it?

slender nymph
#

this is a code channel

stray thorn
#

where should i ask

slender nymph
stray thorn
inland narwhal
#

i even used few scripts from gitthub
default flat areas of terrain not being lowered

#

lowering code is just doing opposite of raising code

languid spire
#

man, you are in the wrong server. we do not debug code for you that you cannot/willnot debug yourself

inland narwhal
#

lol so what's this channel for ?

languid spire
#

to help people help themselves

inland narwhal
#

ridiculous

languid spire
#

really? What is 'ridiculous' is your sense of over entitlement

inland narwhal
#

entitlement ? yeah sure

fickle plume
#

Also if you are looking to argue about it, find another server. You already have a warning for off-topic.

inland narwhal
#

Sure, I have no business left here already, never got help or progress

languid spire
tepid summit
#

how do i reference a parameter in a script?

languid spire
tepid summit
#

sorry

#

shouldve specified

#

im talking about animation

copper matrix
#

what is the easiest way to let a prefab change at the hierachie thingy

languid spire
copper matrix
#

(if i have my enemy on the field he can change the healthbar but as a prefab i cant connect the healthbar to the enemy script

glossy turtle
fickle plume
languid spire
copper matrix
glossy turtle
#

That code looks simple but generating such logic in seconds by an ai. Thinking who wrote such ai Steve. That's marvelous.

languid spire
fickle plume
tepid summit
#

i get what to do though

#

just wanted to point it out

modest dust
#

It's not a static method

#

It's called from an instance

languid spire
#

dont tell me, report the documentation, there is a button at the bottom of tjhe page

modest dust
#

m_Animator in the example

tepid summit
#

i saw