#πŸ’»β”ƒcode-beginner

1 messages Β· Page 342 of 1

deft grail
#

for sure

misty coral
#

cuz rn I am calling lerp several times

deft grail
#

probably should be 1

#

if your taking a step forwards your moving your leg once, you dont do it 100 times while trying to do it once

pseudo frigate
#

im having an issue where when i change the float timeInterval to a smaller number, the reels on my slot machine dont spin faster in the editor, but if i build the game the changed value seems to actually affect the speed they spin, is that some bug with the editor or is there a reason for that behavior?

        while (spinTime[reelNumber] > 0f)
        {
            reels[reelNumber].localPosition = new Vector2(reels[reelNumber].localPosition.x, reels[reelNumber].localPosition.y - 21f);
            if (reels[reelNumber].localPosition.y <= -630f)
            {
                reels[reelNumber].localPosition = new Vector2(reels[reelNumber].localPosition.x, 630f);
            }

            yield return new WaitForSeconds(timeInterval);
        }
misty coral
#

Like I dont want to aim in at the same speed my gun sways back and forth

cobalt creek
#

how i make UnityWebRequest with button? Because once I change from public void to IEnumerator I no longer see on list of functions when I set function to run on click

deft grail
#

so you can set it in the button and also use a IEnumerator at the same time

cobalt creek
#

thank

#

wish i could do public void IEnumerator that make more easily

pseudo frigate
magic panther
#

I need help real quick: how can I have a value be one of two classes?

    public void Teleport(Player || Crate teleportedObject) {
        teleportedObject.transform.position = portalExit.transform.position + new Vector3(0f, portalSize, 0f);
    }
silk fossil
#

yo

#

when my charecter looks all the way up

#

or down

rocky canyon
#

cool UI!

silk fossil
#

it does this

#

and it makes movement weird

quick kelp
silk fossil
#

and jumping impossible

rocky canyon
#

the code that looks up and down should be moving a child object.. like a camera..

#

not the root /main gameobject

quick kelp
#

figured out my problem

silk fossil
#

oh

quick kelp
#

havent solved it yet

magic panther
quick kelp
#

the pickup code isnt referencing dont destroy objects

silk fossil
#

this is the code for moustmovment

#

so I would put that on camera

rocky canyon
#

like dis

rocky canyon
rocky canyon
silk fossil
#

wait so is the code I just sent just totally wrong

rocky canyon
#

u'd probably reference ur camera in that script

#

and apply the up and down rotation to the camera object

silk fossil
#

oh alr

#

a youtuber provided that script

#

i guess I did something wrong

rocky canyon
#

or have it on the camera.. and reference ur player gameobject and use it to rotate left and right

magic panther
quick kelp
rocky canyon
#

for example.. this script is on the camera..

quick kelp
#

player.transform.position = startPos;

this is the code i use to spawn the player in a new scene

rocky canyon
#

i rotate the transform.localRotation (camera) up and down..
and then i reference my player object.. to rotate left and right.. the controller.transform

silk fossil
#

so I can put the script onto the camera

rocky canyon
#

u can try it and see..

silk fossil
#

okay

rocky canyon
#

its better to learn how stuff works on ur own..

#

but thats my entire camera script

silk fossil
#

Ya that is true

rocky canyon
#

Freebie of the day!

silk fossil
#

but my teacher wants us to finsih the game by wednesday

#

so I am just too lazy too

#

figure out c#

quick kelp
cosmic dagger
magic panther
#
    public void Teleport(MonoBehaviour teleportedObject) {
        if (teleportedObject.enabled) {
            teleportedObject.transform.position = portalExit.transform.position + new Vector3(0f, portalSize, 0f);
        } else {
            Debug.LogError("Teleported object is not enabled");
        }
    }
#

could work

slender nymph
#

or just pass its transform instead of a specific MonoBehaviour. you only care about the transform in that method anyway

cosmic dagger
silk fossil
cosmic dagger
silk fossil
#

WAHOOOOOOOO

#

wait what the

#

I can do a 360 when I look down

quick kelp
#

ok did the debug log and the pickup portion in my inventory script is the problem

cosmic dagger
quick kelp
#

tldr i have 2 test items in a room
if i pick one up and leave the room without the other the pickup script work in destroying the game object but the itemdata doesnt show up in the second slot

hasty sleet
#

Did you change both the data and also the UI, or just the data?

quick kelp
#

its becuase the itemdata after i leave is now persistence and on dont destroy

hasty sleet
#

Step through with a debugger and see if you can verify after the line slot.itemData = itemData; that your slot's itemData was updated as expected.

#

I suspect you may be updating the data but not re-drawing it wherever you are expecting it to show up on your GUI

quick kelp
#

i'll run the debugger but the debug.log kinda confirmed my hunch

silk fossil
quick kelp
#

ddol cube i made did not register the log tho the seperate pickup script still did its thing

#

wait

#

i might have a fix

#

nvm my idea didnt work

rocky canyon
#

you need clamp the rotation for the vertical look

#

u could ask here someone might know how to do it

silk fossil
#

yo guys how do you clmp rotation for vertical look?

slender nymph
#

search "clamp camera" in here and you'll find plenty of examples

silk fossil
#

alr

slender nymph
#

also obligatory: use cinemachine

silk fossil
#

also

#

i learned java this year

#

would that help at all with unity

#

o c#

#

or c#

rocky canyon
#

not really.. i mean in a way yes..

#

b/c of "programming"

#

loops n whatnot

silk fossil
#

man

slender nymph
# silk fossil or c#

please finish a though before pressing enter. they have similar syntax, and the absolute fundamentals are the same, but the languages do work a bit differently

silk fossil
#

i see

#

so im cooked

#

nvm bro

#

that doesent even make sense what I just said

#

2 completly different language

rich adder
#

microsoft java 😏

magic panther
# silk fossil would that help at all with unity

As spawn camp games said, if you mean programming in general, it will a bunch if you're getting started with code. If you mean unity unity, then no. Unity operates in C#. I believe you ain't that cooked yet, I started learning unity a week (or so) ago and the C# part ain't that bad.

spare mountain
#

java and c# are very very similar

red siren
#

The principles are the same, for sure it will help

rich adder
#

indeed

magic panther
spare mountain
#

it'd definitely be much easier than going from python or js to c#

rocky canyon
magic panther
rich adder
#

dynamic vs static

spare mountain
silk fossil
#

yk my teacher is odd, taught us java the whole year, and our final project is to make a game in unity

rocky canyon
#

you can set the limit to whatever u want @silk fossil

rich adder
#

js -> ts -> c# easier than js -> c#

spare mountain
spare mountain
silk fossil
silk fossil
#

actaully tnx alot

rocky canyon
#

and just in case u dont know its wrapped in a name space..
if u want to reference this script anywhere you have to
add using SPWN; at the top.. or use SPWN.ControllerCamera as the reference type

silk fossil
#

i was just about to sleep without fixing that

slender nymph
spare mountain
spare mountain
#

I mean unity wasn't mentioned

rich adder
spare mountain
#

why were you guys given unity?

slender nymph
spare mountain
magic panther
spare mountain
rocky canyon
#

oooohhh noooo... my syntax script is broken! why tf is this SerializeField not colored... has to be b/c the comment above it

silk fossil
#

spawn camp games, if I get an A on this final project, it will be because of you lol

rocky canyon
#

πŸ’ͺ heck ya

magic panther
#

idk just kept unity in the back of my head the whole process

#

enough of that tho

spare mountain
#

most of the JS I've written is similar to what you'd see in java I suppose

magic panther
#

imma go learn react

#

nice talking with yall

rocky canyon
spare mountain
#

String in Java and string in C# throws my brain off

#

how am I meant to remember

spare mountain
#

I almost put bool on the AP java exam

rocky canyon
rich adder
rocky canyon
#

unrelated.. but i just noticed it soo i figured id mention it to 000000

silk fossil
#

trust me, if i were to do unity without a deadline, i would atleast get a better grasp of c#

rocky canyon
slender nymph
spare mountain
rich adder
rocky canyon
slender nymph
spare mountain
rocky canyon
#

is int Int

spare mountain
silk fossil
spare mountain
#

String is a reference type

rocky canyon
#

no no no, lol!

#

i dont mess with java unless i have to..

spare mountain
#

bool is boolean tho

rocky canyon
#

and then its usually javascript

silk fossil
#

String hello = "sjssjsjjs";

spare mountain
rich adder
#

=== πŸ˜΅β€πŸ’«

spare mountain
eternal needle
spare mountain
#

jk

rich adder
#

its been a while since i touch js

spare mountain
#

oof

#

===== when?

silk fossil
# spare mountain String is a reference type

wait yk how an array can be changed if it is in a parameter of a method and how primitive types cant, since string is not a primitive type, it should be able to be changed in a method as a paramater, but it doesent, Makes sense normally, but being a reference type does not

spare mountain
#

I would imagine it would

rocky canyon
# spare mountain I love javascript

my patsebin site i was using earlier is javascript.. but to be fair.. its a library i mainly copied and pasted.. any adaptation i had to do took weeks i think i remember πŸ˜„
i'll just stick to c# for now
~~
actually i think i shouldn't post that screenshot.. those are system type directories.. dont want ppl breaking into my pastebin site :D~~

silk fossil
#

n would not be changed

slender nymph
silk fossil
#

im pretty sure

spare mountain
slender nymph
#

when you modify a string it returns a new string

spare mountain
#

no that makes sense

#

that's also why string[3] = "e" doesn't work

eternal needle
#

There is also the ref and out keyword if you need to change/assign parameters

rocky canyon
spare mountain
slender nymph
silk fossil
rocky canyon
#

ahh, well today i learned.. i actually dont think about the internals of stuff too often.. i probably should more often

silk fossil
rocky canyon
#

mutable

silk fossil
#

its just weird

rocky canyon
#

see thats a new term for me

silk fossil
#

cause java werid

spare mountain
#

interesting

rich adder
#

mutated

spare mountain
#

I learned that a while back

eternal needle
rocky canyon
silk fossil
#

πŸ’€

rocky canyon
#

like when something just works.. i dont think about it until it doesnt

#

probably a flaw tbh

eternal needle
#

If you are making small games, there is definitely an art of just pushing the minimum working version.

rocky canyon
silk fossil
rocky canyon
#

ohhhh that makes sense

silk fossil
#

dont quote me tho cause I learned it in class while I was failing

#

but im pretty sure

rocky canyon
#

oh i dont.. i fact check almost everyone tbh

silk fossil
#

πŸ’€ good

#

it could cause a lot of problems if you dont

rocky canyon
#

yea, im aware of that.. when i first started learning i didn't.. i assumed anyone that published content knew what they were talking about..

#

then i slowly realized thats not the case

silk fossil
#

wait so in c# strings are just primitive, not refrence

slender nymph
#

strings are reference types

rich adder
#

strings are not primitive

silk fossil
#

do they just act like priitive then?

cosmic dagger
#

strings are reference types . . .

silk fossil
#

oh im cooked

rocky canyon
#

computers know numbers.. computers dont know words

silk fossil
#

got 7 people typing

slender nymph
magic panther
#

are strings really like objects in java

slender nymph
#

and their equality is overloaded to check the contents rather than reference equality

silk fossil
#

are they converting those nums to letters?

slender nymph
#

huh?

silk fossil
#

nvm dont answer

#

also why does .toString method only work 24% of the time in java

spare mountain
#

me and the homies all do (String)

rocky canyon
#

not sure.. Unity's ToString always works

rich adder
#

in c# pretty much every object has ToString

silk fossil
spare mountain
#

probably

silk fossil
#

you can type cast an int to a string

#

no way

rocky canyon
#

yes u can cast in c#

silk fossil
#

i could have saved myself from so many F's

cosmic dagger
silk fossil
#

wait wb in java tho

#

im pretty sure it don't work in java

#

never taught us that

rocky canyon
#

idk.. if we keep talkin about java ur gonna have to shift into another discord πŸ˜„

silk fossil
#

thats true

#

πŸ˜‚

cosmic dagger
silk fossil
#

ya mb

#

i need to sleep

#

tnx for help

rocky canyon
#

np πŸ€

silk fossil
#

expeically you @rocky canyon

#

gn

static cedar
#

Real.

eternal needle
rich adder
#

ya just using fluff words πŸ˜…

rocky canyon
#

what happens if u ToString a gameobject?

#

does it return the ID?

cosmic dagger
#

it's a method of object. that makes sense . . .

rocky canyon
#

i'll give it a try in a moment

slender nymph
rocky canyon
#

word?

#

thats pretty damn cool

eternal needle
#

they overridden it to do that yes

rocky canyon
#

smart guys here @ unity

rocky canyon
#

when you've thought of almost everything πŸ™‚

#

soo im starting to realize theres alot of redundancy in unity's c#

final totem
#

When I'm colliding with a coin I want to increment a variable and destroy the sprite, is there a better way to do this instead of using tags and strings?

rocky canyon
#

well, don't compare a string.. use CompareTag instead..

#

if it has a Coin component u could check for the component

#

with a TryGet

cosmic dagger
rich adder
#

!code

slender nymph
#

!code

eternal falconBOT
cosmic dagger
#

!code

eternal falconBOT
rocky canyon
#

double kill!

slender nymph
#

double kill

rich adder
#

tripple

rocky canyon
#

triplekill!

rocky canyon
#

lol.. mobile guys can't read ur embed text

devout swift
#

wtf happened? lol wahahah

rich adder
cosmic dagger
#

and if the class is too large, it cuts off anyway (even for PC users) . . .

slender nymph
rocky canyon
#

mobile people can't see what u posted earlier

cosmic dagger
devout swift
rocky canyon
#

ya, its just protocol around here

rocky canyon
#

100mb limit for everything else..

devout swift
rich adder
slender nymph
rocky canyon
#

it should when it reaches its destination.. you can modify Stopping Distance on the agent itself

devout swift
slender nymph
rich adder
rocky canyon
#

when it gets to its destination u can make it wait a while before giving it a new one.. if thats what ur doing

devout swift
devout swift
rich adder
#

oh wait ur running it every frame

devout swift
#

Am i supposed to call it once?

#

not every frame?

rich adder
rocky canyon
#

ya, u should probably only set it once. and then wait until its stopped before setting a new one

devout swift
rich adder
#

I would use a coroutine or a timer then

rocky canyon
#

^ check if its @ its destination and if its stopped..

#

if its stopped for so long.. then give it its next destination

toxic frigate
#

so im trying to make an escape menu toggle after escape is clicked twice, a ui that is enabled by selecting another object needs to be disabled by pressing escape first, but i can't figure out how to do so

rocky canyon
#

theres lots of nifty ~~functions ~~ variables of Navmesh agent u can use..

#

pathPending remainingDistance stoppingDistance

rich adder
devout swift
#

Am I supposed to only call the setDestinaton once?

slender nymph
#

if it is a coroutine then yes, put everything inside of it into a loop and start the coroutine in Start instead of calling it every frame in Update

devout swift
topaz mortar
#

is there a smart way to have a whole bunch of items that affect your character without having to reference your Character object on each Item object?

rich adder
rocky canyon
#
    IEnumerator DestinationTimerCoroutine()
    {
        yield return new WaitForSeconds(X);
        SetNewDestination();
    }```
could call a coroutine once you've reached ur destination to wait for `X` amount of seconds, and then set a new one
rich adder
#

lookup the docs on Coroutine

#

looks like you already had this too
//yield return new WaitForSeconds(2f); // Wait for 2 seconds

rocky canyon
#

ya, looks like u were on ur way to making it work

rich adder
#

wasnt working because you probably were calling it every frame in update and confusing the navmesh agent

devout swift
#

It's my first time using the agent sorry. I'll try what you guys adviced me .

#

Thank you.

rich adder
#

np

spare mountain
#

navmesh isn't really AI is it?

rocky canyon
#

no..

rich adder
#

its just A* with some RVO

rocky canyon
#

its a pathfinding algorithm

spare mountain
#

thought so

devout swift
rich adder
cosmic dagger
spare mountain
#

that's why you run the coroutine once

rich adder
#

or just make Start the coroutine

rocky canyon
#

it effectively queues up a new instance of that coroutine every frame

rich adder
#

private IEnumerator Start()
no need to start coroutine

devout swift
rocky canyon
#
  if (!coroutineStarted)
        {
            StartCoroutine(MyCoroutine());
            coroutineStarted = true;
        }```
heres a jank way of making sure it doesn't run every frame πŸ˜„
#

then at the end of the coroutine u can reset the flag back to false

devout swift
cosmic dagger
devout swift
#

Thank you guys.

rocky canyon
#

well, i can't remember the last time i did

sacred lichen
#

Can someone please tell me what I am doing wrong? I even already did reimport all and still this issue persists.

#

It's workign for both move and jump but for some dumb reason it's not working for my interact button

rocky canyon
sacred lichen
#

thanks, i'll try and ask there

slender nymph
#

oh and save after commenting out those lines if that wasn't obvious

#

you don't want compile errors preventing unity from compiling any changes

rocky canyon
#

thats the worst thing ever.. when importing an older asset and 30% of it is broken..

#

but it takes u half an hour to figure out that 50% of it is actually broken

slender nymph
#

if it is still not working after that, then you are not using the correct type

rocky canyon
#

did u regenerate ur C# class?

#

or is that the method ur using?

#

not sure if theres a way to tell, just by looking at the code

cosmic dagger
rocky canyon
#

ohh, good eye

slender nymph
#

i'm pretty sure that's multiple separate screenshots stitched together because all of the tabs for both shown windows are identical

sacred lichen
#

^ yeah

rocky canyon
#

lol.. bamboozled

sacred lichen
#

couldn't fit everything hehe

sacred lichen
rocky canyon
#

any time u make an addition to ur actions u need to regenerate ur c# class

#

or else the references wont be created yet

sacred lichen
#

I see, I thought it was automatic. Thanks for lettign me know.

rocky canyon
#

ya, u would think it should be.

#

maybe it will be in a future version..

#

idk

devout swift
quick pollen
#

Hey! So here I have this test scene and this piece of code.
https://hatebin.com/cabnnztqnk

My main goal is to be able to have a list, which contains lists of "actions" and I want those actions to consist of 3 main parameters:

  1. the time it takes to start the action/movement
  2. the time it takes to arrive
  3. a position to arrive at

But for some reason this implementation I have doesnt work, it doesn't linearly go towards the position pointed out, and the time to arrive variable doesn't seem to affect how long it takes to arrive

#

I didn't use any tutorials for this so this might also contribute to it being faulty

#

Slerp seemed to be the best way to do it

#

and it actually when the list only has 1 element

spare mountain
#

does it do the same thing with a basic Lerp?

quick pollen
#

well

#

Lerp makes it very jittery

spare mountain
quick pollen
#

whoa wtf

#

with Lerp it no longer does the curves

spare mountain
quick pollen
#

but I don't understand why

spare mountain
#

me neither

quick pollen
#

also the TimeToArrive is still broken

#

I have one where the timetoarrive is 5 seconds

#

it arrives in 2 seconds

#

and waits for 3 more seconds

spare mountain
#

that's why slerp isn't working @quick pollen

#

slerp isn't what we thought it was lol

quick pollen
#

yeahh I just readt about it

#

it uses directions not transforms

spare mountain
quick pollen
#

ty for that

#

but the timetoarrive is still broken

spare mountain
narrow girder
#

Why cant i add an image in elements?

quick pollen
#

but it arrives in 2 seconds

willow scroll
spare mountain
quick pollen
#

basically completely ignores the calculation

narrow girder
willow scroll
quick pollen
#

this should be the formula for finding the clamped time to arrive

spare mountain
#

the way lerp works is that it finds a point in between x and y at point t

quick pollen
#

One Minus, so it starts from 0 and goes ot one, not the opposite

spare mountain
#

when would clampedTime be changing?

quick pollen
spare mountain
quick pollen
#

timeToArrive -= Time.deltaTime;

spare mountain
#

ah

quick pollen
#

right before it

#

I posted the script

#

if u want to take a closer look

spare mountain
#

yeah I just couldn't be bothered to go back

#

1 sec

spare mountain
quick pollen
willow scroll
devout swift
quick pollen
#

I have these values for timeToArrive

spare mountain
willow scroll
#

timeToArrive should just not be smaller or equal to 0

quick pollen
#

ah

#

okay

spare mountain
quick pollen
#

it isnt

willow scroll
#

The server didn't allow me to say "smaller*".

quick pollen
#

the one from the list is the constant value

#

also the one I use to divide the current timeToArrive to get a clamped value

spare mountain
#

okay I opened your code so I can just check

#

so timeToArrive initializes to the value and then decreases

#

got it

quick pollen
#

yeah

#

but for some reason sometimes it just doesnt

spare mountain
#

so it should increase from 0 to 1 that makes sense

spare mountain
#

see what it's equal to

#

clampedValue I mean

#

or whatever it's called

quick pollen
#

I can try

#

but it used to be okay

spare mountain
#

you used to use slerp

quick pollen
#

i was thinking maybe its using wrong values

quick pollen
spare mountain
#

yup

#

this is not the place to ask that

#

check here

quick pollen
#

what the fuck?

#

clampedTime works perfectly

spare mountain
#

lmao wym?

quick pollen
#

but it still doesnt do the correct position

spare mountain
#

how can you tell?

quick pollen
#

like it takes around 5 seconds to go from 0 to 1

spare mountain
quick pollen
#

it takes visibly more time

spare mountain
#

okay wait

quick pollen
#

which is good

#

but the movement is still not okay

spare mountain
#

output the value of the lerp

#

versus the output of the clampedTime

#

see what it's giving you

quick pollen
#

waittt

#

im seeing an issue

spare mountain
#

what is it?

willow scroll
#

It's not about Unity, especially about code, is it?

quick pollen
#

I had the statement with if (!calculatedPositions)

#

but I didnt set calculatedPositions to true....

#

so it kept on updating the selfPos

spare mountain
quick pollen
#

which would indeed make it independent of time

spare mountain
#

lol

#

welp you live you learn

quick pollen
#

fuuck

#

I fucking knew about this being an issue

#

hence why I created calculatedPositions

willow scroll
devout swift
quick pollen
#

thanks still!

#

also

#

once I ran out of elements, I get this error

#

which would make sense

willow scroll
quick pollen
#

except that I have conditions set up so it disables the script once it runs out of elements

spare mountain
quick pollen
#

so I don't get why I still get errors

#

maybe its syntax, hold on

devout swift
willow scroll
quick pollen
#

okay fixed it, now it only does it once

#

and for that I have a fix too

willow scroll
#

So you're trying to stop it in Update

devout swift
willow scroll
#

Should've read about them first, actually

devout swift
quick pollen
#

ayyy works

#

tysm @spare mountain and @willow scroll

spare mountain
#

np man

#

gj

willow scroll
#

Coroutines are used when you need something do be done in the specific periods of time. In certain circumstances, a better way when dealing with Time.timeDelta in Update

quick pollen
#

this is actually for some bullethell stuff

#

so you know, its important that the positions and times are correct

willow scroll
quick pollen
#

I don't want to create impossible patterns unintentionally

quick pollen
#

so you know

#

more than nothing, which I appreciate

willow scroll
quick pollen
#

btw are Coroutines frame-independent? like does something happen in x amount of time even if the game is running at a low fps?

rocky canyon
#

yes

#

1 sec is always 1 sec

willow scroll
#

If you have a character which should be moved e.g. 3 times a second, you use a Coroutine, because of the time being calculated more easily there

quick pollen
#

I experienced that if Time.deltaTime is too high, sometimes things can happen later or earlier than wanted

willow scroll
willow scroll
devout swift
quick pollen
# rocky canyon 1 sec is always 1 sec

thanks!
I have 2 implementations in my code where I create projectiles
one uses coroutine timing, other uses fixedDeltaTime
I was kinda wondering which one would be the best for when you need perfect and frame-independent timings

willow scroll
#

So the Coroutine is limited to the maximum of 1 / Time.deltaTime calls per second

quick pollen
willow scroll
#

And the specific WaitForSeconds won't work exactly as expected, as the time waited depends on the game itself

willow scroll
quick pollen
#

kinda interesting

quick pollen
#

wouldnt it call a coroutine 300 times per second?

willow scroll
quick pollen
#

oh

#

sorry yeah

willow scroll
quick pollen
#

but isnt it the same with update?

willow scroll
#

Yes

quick pollen
#

or what about FixedUpdate?

#

its technically worse because its clamped, isn't it

willow scroll
#

Coroutines have nothing to do with FixedUpdate

quick pollen
#

I'm just asking about ways of timing things

willow scroll
#

FixedUpdate is called in a fixed timestep, which is 50 times per second by default

#

Can always be changed for the project via settings and via code

quick pollen
#

what I basically want is stuff to happen exactly when I want them to, independent of update time

willow scroll
quick pollen
#

I had issues where projectiles would spawn further out or closer in, depending on framerate

#

which caused some huge issues when creating patterns that required really small and precise numbers

willow scroll
quick pollen
#

at first I called it off as a float point error, but I found it to be consistently incorrect at lower framerates

#

as an example?

#

what limitation?

#

you mentioned the fixed timestep

#

but that feels like more of an upside than anything

#

because you have full control over it

topaz mortar
#

Is Resources.Load the only way to load a sprite for an object if all I have is the sprite name/location?

willow scroll
slender nymph
willow scroll
quick pollen
#

I know, the problem wasn't exactly low overall framerate, but on lag spikes

#

yes I know "just use DOTS 4head" but I don't feel like tackling that just yet

topaz mortar
willow scroll
quick pollen
#

lemme see if I have a good video

slender nymph
willow scroll
topaz mortar
slender nymph
#

You could throw all of the relevant sprites into a collection on a ScriptableObject and build a dictionary from those sprite references and access it from there, that might be better than using Resources.Load. otherwise Resources.Load would likely be the easiest option if all you're sending is the name or location of it

topaz mortar
#

going with Resources.Load sounds a lot easier
it's probably slower? but I'm not loading new items constantly anyway, maybe like once every 10 seconds or so

#

I'm working with the Fantasy Heroes megapack from the unity store, it actually has a SpriteCollection built in, could I use that?

#

The structure of that asset is way too complicated for me though

slender nymph
#

yeah, seems like that asset is going to initialize that collection as a singleton on startup anyway so you may as well make use of it

topaz mortar
#

Oh awesome, did not know that!

slender nymph
#

do you perhaps have your own class called SpriteCollection?

topaz mortar
#

I think the class is correct?

#

at least that's the folder of the asset

slender nymph
#

according to the documentation that should be correct πŸ€·β€β™‚οΈ

topaz mortar
#

yeah, this asset is both heaven and hell lol

#

the graphics and possibilities are amazing, but it's structured so complex and not the best docs

slender nymph
#

check what properties that class has to see if perhaps it is named something different

narrow girder
#

Should I make everthing into a prefab?

willow scroll
narrow girder
# willow scroll No.

My friend created a game manager that overall sees the update of the code but I have a hard time to reference it or even connect the scripts so the ui works such as the life image one

willow scroll
#

For a GameManager, you would usually use Singletons

#

And make it DDOL, usually

quick pollen
#

its only going to contain this one boss, as kind of an introduction to the game idea

#

and if it turns out to be liked, ill continue

narrow girder
#

is this some sort of bug ? is there a fix to it?

slender nymph
#

you very likely have an infinite loop in your code if it gets stuck there forever

narrow girder
slender nymph
#

!code

eternal falconBOT
slender nymph
#

you can also attach your debugger while the editor is frozen and break all, that will allow you to inspect the main thread to see where it is getting stuck in an infinite loop

keen dew
#
Debug.LogError("Infinite loop detected in maze generation.");
UnityEditor.EditorApplication.isPlaying = false;

This isn't enough to exit an infinite loop. It would have to throw an actual error or break the loop with break or return

narrow girder
#

Sometimes, when I first open the project and then run it, it works. But when I try it a second time, it doesn't work anymore

slender nymph
onyx tusk
#

I have this code & i don't understand y isKingDefender is still false after setKingDef(vector, move)

slender nymph
#

are you actually calling that method anywhere?

slender nymph
#

i mean, i don't see you calling setKingDef anywhere in the code you've shown

slender nymph
#

have you verified that code is running?

#

and that it is affecting the objects you think it is?

onyx tusk
#

debugger says that it entering herec# foreach (ChessVector def in defs) { Figure.setKingDef(def, j); }

onyx tusk
narrow girder
#

is this normal in unity?

eternal needle
slender nymph
# onyx tusk uhhh, idu u

step into the method call and make sure that the object being modified is the same one you've been looking at

eternal needle
#

oh i see above you are using it with false, though the logic is really quite hard to follow.

eternal needle
onyx tusk
onyx tusk
polar nova
#

Anyone have an Idea how to make a Hitpoint system? I've been trying to add one to my Tower Defense for quite some time now but I can't figure out how to do so. I want the enemies to do as much damage to the tower as they have hitpoints.

eternal needle
eternal needle
#

hitpoints at the end of the day is just a number. but if you're having issues with specific code or a specific problem then you should share that

slender nymph
#

so it is correctly assigning true to that variable then. so however you were checking before was either faulty or something else is assigning it false again

onyx tusk
#

yes

willow scroll
#

Also have more scripts, which should be Singletons and have them access each other

onyx tusk
polar nova
slender nymph
onyx tusk
slender nymph
#

have you verified that the objects you are looking at are the same object?

onyx tusk
#

wait

#

i added debug.log() for this, checking

lavish magnet
#

Is their anyreason this doesnt move my player continously upward? The debug.Log goes through correctly, but the players position stays the same, is the code wrong? or is their an outside source?

onyx tusk
#
    public static void setKingDef(ChessVector vector, Moves saveKingMoves, bool isDef = true)
    {
        chessBoard[vector.x - 1, vector.y - 1].mover.isKingDefender = isDef;
        chessBoard[vector.x - 1, vector.y - 1].mover.saveKingMoves = saveKingMoves;
        Debug.Log($"{GetFigure(vector).figure.name} {GetFigure(vector).mover.isKingDefender} {isDef}");
    }```
willow scroll
# polar nova I have my Tower set as an endpoint. So like the last waypoint for the enemies to...
    1. Have a script, which manages the variables needed. I would assume, it should be a singleton GameManager
    1. Have a script on every Enemy, which compares its position with GameManager.endPoint in Update. I don't know a lot about your game, but this should, probably, be a float, Vector2 or Vector3, depending on the axes you want to be included.
    1. When the Enemy's position is larger than the endPoint, update the GameManager.towerTakeDamage boolean, or how you want it to be called. This boolean has to be accessed in the Tower script too. The distance check is also possible.
willow scroll
lavish magnet
#

That function is in Update Btw

willow scroll
#

This is what makes sense, right

#

Log the ascendSpeed variable and how much your position gets changed

languid spire
lavish magnet
#

my ascend speed goes up every frame i hold space too

#

ascend speed reaches like 400+ and i dont move an inch

languid spire
lavish magnet
onyx tusk
# onyx tusk wait

ok, this screen says that here linec# col.ForEach(i => Figure.setKingDef(i, null, false));
running after c# foreach (ChessVector def in defs) { Figure.setKingDef(def, j); }

willow scroll
# polar nova I don't understand

I have written a few sentences for you, and don't seem to understand what exactly you don't understand.
I have assumed, that this should be straight forward. Consider asking well-structured questions about the implementation if you want me to assist you further.

slender nymph
lavish magnet
#

yes I do

#

Yes

languid spire
lavish magnet
#

CharacterController

slender nymph
#

that's why. you cannot modify the position of a CC without either disabling it or moving via the CC

languid spire
#

then do not use transform.position

void thicket
# lavish magnet It goes up every frame\

Generally you want to multiply dt to acceleration too. Anyways if the position is not changing it is likely that you are overwriting it somewhere after that code.

lavish magnet
willow scroll
languid spire
#

charactercontroller.move ?

languid spire
sand gate
#

!forums

eternal falconBOT
#

:speech_balloon: Unity forums β†—

Have a question that requires a more detailed explanation? We suggest using the Unity forums to ensure your question is answered more effectively.

kindred halo
#

Is there any way to stop taking input during the time when calling or running a function except for the input that is on hold?

languid spire
kindred halo
languid spire
fossil tree
#

hello my problem is the next i have a prefab script called explosion and i try to access to a other object called score for use a variable on in i have try to make something like that but im really bad for reference something someone can explain me how that work ```using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Reference : MonoBehaviour
{
public Score score2;
// Start is called before the first frame update
void Start()
{
explosion expl = score2.GetComponent<explosion>();
expl.score = score2;

}

// Update is called once per frame
void Update()
{
    
}

}```

kindred halo
languid spire
stuck crest
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class MainManagerScript : MonoBehaviour
{
    public  event EventHandler OnStart;
    public  event EventHandler OnEnd;

    public void StartGame()
    {
        
        OnStart?.Invoke(this, EventArgs.Empty);
    }
public class GameTimer : MainManagerScript
{
    [SerializeField] private Image timerImage;
    [SerializeField] private TextMeshProUGUI timerText;
    [SerializeField] private float matchTime = 5;

    private bool isStart;
    private float originalTime;
    private void Start()
    {
        OnStart += StartHandler_OnStart;
        originalTime = matchTime;
        timerText.text = "";
    }

guys why is this not working after i removed the static

fossil tree
teal viper
teal viper
stuck crest
teal viper
stuck crest
fossil tree
teal viper
stuck crest
teal viper
teal viper
fossil tree
teal viper
stuck crest
#

it was working when it was i added static to the event

teal viper
fossil tree
teal viper
polar nova
#

https://gdl.space/bavizafibe.cpp I have this script and a different script for the damage. It should work but I dont really know why health is not getting set to maxHealth when I start up the game

fossil tree
#

the line 25 is if (hit.collider.gameObject.tag == "Player")

stuck crest
polar nova
#

yes

#

should I set it in the code?

stuck crest
#

mb

teal viper
teal viper
stuck crest
#

it isnt subscribing to the event?

teal viper
#

At least nothing is subscribed at the moment when you try to invoke it

stuck crest
#

but why does it subscribe when its a static event

#

im confused

teal viper
stuck crest
#

ok

waxen adder
#

What do you guys prefer doing when implementing gravity? Manipulating the transform directly, or using rigidbodies/forces?

gilded breach
#
    public GameObject H2O;
        
    void Update()
    {
        if(Input.GetMouseButtonDown(1))
        {
            SpawnCard();
        }
    }

    void SpawnCard()
    {
        Instantiate(H2O, new Vector3(3f, 0f), Quaternion.identity);
    }
}```


srry probably very dumb question but how do I check if while clicking you are clicking a GameObject (the card deck)? Everything else works but now I can click everywhere on the screen to spawn the GameObject H2O copy
void thicket
waxen adder
fossil tree
#

and my question is how can i say my score is = to my Score object its a prefab so i cant drag and drop

kindred halo
waxen adder
#

Hmmm. Maybe not since the colliders need to be marked as triggers for some reason (wait i might be misreading it lol)

void thicket
# waxen adder What do you mean by physical mechanism? Something like jumping?

Sure. Rigidbody supposed to be general solution for physically accurate case, but player character tends not to be physically accurate thus CharacterController exists for alternative solution. For simple games it could be direct transform move, or case like particles you would want a fomular that you can just directly calculate position from time.

languid spire
teal viper
# fossil tree i dont know
  1. It means that something on that line is null. You should debug log all the references on that line to see what it is. Assuming that's the correct line.
  2. If you need to reference something in the scene from a prefab, you'll need to assign the reference at runtime, ideally, when/where you instantiate that prefab.
young fossil
#

Hey guys. Is it common practice to use properties in Unity?

willow scroll
kindred halo
teal viper
languid spire
waxen adder
young fossil
#

A lot of YouTubers, Forum posts and Unity docs all use public fields

gilded breach
teal viper
young fossil
waxen adder
kindred halo
teal viper
void thicket
willow scroll
gilded breach
young fossil
#

Thank you guys. Also does Linq have any obvious disadvantages?

#

Like performance overhead

#

Or maybe incompatibility with Unity

teal viper
waxen adder
young fossil
#

Sorry, what is GC allocations?

void thicket
teal viper
#

Garbage collector. It allocates temporary memory basically, that needs to be disposed. GC is thought to be detrimental to performence, but it really depends.@jack.hk

young fossil
#

Ahhh gotcha! Thanks

void thicket
#

But if you know the logic behind it then it will be very useful tool

gilded breach
waxen adder
gilded breach
#

it does, a 2D box collider. Srry if the question is stupid lol, I just started

waxen adder
#

Oh, cool, in that case, you should be able to use that OnMouseDown method. From the brief description it gives, I think you will be adding the function and its logic to the thing being clicked, so you shouldn't have to worry about clicking the wrong thing, because if you do, nothing will happen

gilded breach
#

is there anything else I have to do to make that work?

narrow girder
#

Hello, Should i connect this to my game manager or The canvas? when creating the game over screen?

willow scroll
waxen adder
willow scroll
gilded breach
#

thank you

willow scroll
#

Checking if the GameObject is clicked by the player?

willow scroll
#

It usually depends on whether you have a Collider

#

Do you?

gilded breach
narrow girder
gilded breach
#

2D box

narrow girder
willow scroll
#

Create a ray from your mouse position and enumrate thru the colliders hit in case you may have more than one object with a collider

gilded breach
#

how can I specify what collider should the ray consider?

#

dividing my colliders in layers?

willow scroll
# narrow girder game over script

Well, if you want to assign the logic to the Canvas's Button, add the script with the desired method to the seriaized onClick event

willow scroll
#

I forgot about it

#

You may use GetRayIntersection for a single object with layerMask parameter specified

gilded breach
#

this thing right?

should I then import the layer in the code or does the script autodetect the layer?

willow scroll
#

I would say, serialize the LayerMask and convert it to int in your code

topaz mortar
#

I want to do this:
Item newItem = JsonConvert.DeserializeObject<Item>(result);
But Item is a MonoBehaviour, any simple workaround?

eternal needle
#

Make your own class for the data you specifically want to save

willow scroll
#

I have messed it up

#

Simply use LayerMask.value variable to get the integer from the mask

#

@gilded breach

willow scroll
narrow girder
#

oh okay found it thanks

willow scroll
#

Global namespace means no namespace specified

gilded breach
willow scroll
languid spire
willow scroll
#

Consider configuring your !ide

eternal falconBOT
tranquil hollow
#
    {
        if(life <= 0)
        {
            this.enabled = false;
            colliderKeeper.enabled = false;
            range.SetActive(false);
            anim.Play("Die", -1);
            
        }
willow scroll
#

No this required for enabled

tranquil hollow
#

why the die anim dont play?

languid spire
#

because you've just disabled the script playing it

tranquil hollow
#

how can i fix it?

willow scroll
tranquil hollow
#

let me try

#

public GameObject range;

languid spire
tranquil hollow
#

is it correct?

willow scroll
languid spire
tranquil hollow
languid spire
#

then that is where you should start

tranquil hollow
languid spire
#

but that has nothing to do with your problem

topaz mortar
#

writing clean code is so hard for complex systems 😣

languid spire
gilded breach
#
    public GameObject H2O;
    void Update()
    {
        if(Input.GetMouseButtonDown(1))
        {
            LayerMask deck = LayerMask.GetMask("Deck");
            if (Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition), layerMask= deck));
            {
                SpawnCard();
            }
        }   
    }

    void SpawnCard()
    {
        Instantiate(H2O, new Vector3(3f, 0f), Quaternion.identity);
    }
}```

I kinda... made it work again but I don't get how the layerMask works tbh.

```Assets\Scripts\H2Odeck.cs(12,97): error CS0103: The name 'layerMask' does not exist in the current contex```

now it gives me this error but when I look on the Unity Documentation it says that it's one of the parameters I can give to the function
languid spire
#

but that is NOT how you pass a parameter and value

gilded breach
kindred halo
# languid spire they will be when you yield, yes

uhh
it didn't work as I thought
now im thinking if I could lock every axis of my movement vector
when I'm running that fuction expect for my last axis
that way even if any unnecessary input is given won't do anything
is it possible to do that?

languid spire
languid spire
kindred halo
languid spire
#

if you want to ignore input whilst the coroutine is running just tell your input processing code that

kindred halo
#

input manager doesn't seem to have anything like that

narrow girder
#

How do I stop the canvas from appearing when i run the game?

narrow girder
languid spire
narrow girder
upper gyro
#

why am i getting nullreference in a line with a CompareTag?

#
private void OnCollisionEnter(Collision other)
{
    if (other.transform.parent.CompareTag("Player"))
    {
        OnColliderContact();
    }
}
timber tide
#

parent is null

#

if you run into a null reference and you're doing multiple dot accessing operations, debug log from left to right

willow scroll
#

In this case it's not needed, neither other nor transform can be null

tranquil hollow
#

how can i fix it?

narrow girder
#

Hello, Why wont It wont load the game over screen. Even if i already added it the script to the canvas?

languid spire
rich adder
#

do people read anymore

queen adder
#

πŸ‘‹

wintry quarry
fresh dirge
#

hi im new so sorry if my question is not ok but i dont know what to do'

#

can someone help me with a problem im having with stopcorutine?
i tried anything , i meen i used invoke and changed the code like 200 times 😦

deft grail
languid spire
fresh dirge
languid spire
fresh dirge
#

i have a power -up called "speed_pepper"
if i pick it up it will last for 10 secnds an will stop the affect
but in that time if ill pick another pepper it wont reset the timer it stiil go by the original 10 sec of the first pepper
i tried to do stopcoroutinr and tried using invoke and cancle invoke and its stil donf work

languid spire
#

that does not explain what the problem is

fresh dirge
#

is there a spesific way to send code here?
or ill just copy past it?

languid spire
#

!code

eternal falconBOT
fresh dirge
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class speedpeper : MonoBehaviour
{

    /////// vars ///////
    
    


    private static bool is_peper_active;
    
    void Start()
    {
        
    }

    
    void Update()
    {
        peper_movement();
        
    }

    // trigger speed peper 
    public void OnTriggerEnter2D(Collider2D other)
    {
        UI_manager uI_Manager;
        uI_Manager = FindObjectOfType<UI_manager>();

        player player;
        player = FindObjectOfType<player>();

        if (other.tag == "Player")
        {
            if (is_peper_active == false)
            {
                uI_Manager.add_score();
                is_peper_active = true;
                player.player_speed = 9;
                transform.position = new Vector2(0,800);
                StartCoroutine("speed_peper_deactive");
                Destroy(gameObject,80);
                Debug.Log(is_peper_active);
            }
            else if(is_peper_active == true)
            {   
                uI_Manager.add_score();
                player.player_speed = 9;
                transform.position = new Vector2(0,800);
                StopCoroutine("speed_peper_deactive");
                StartCoroutine("speed_peper_deactive");
                Destroy(gameObject,80);
                Debug.Log("it works");
            }
            
        }
        else if (other.tag == "floor")
        {
            Destroy(gameObject);
        }
    }
    private void peper_movement()
    {
        transform.Translate(Vector2.down * 3.5f * Time.deltaTime);

    }


    //cancel speed peper buff
    private IEnumerator speed_peper_deactive()
    {
        player player;
        player = FindObjectOfType<player>();
        
        yield return new WaitForSecondsRealtime(10);
        
        is_peper_active = false;
        player.player_speed = 6;
    }


}

fresh dirge
languid spire
#

just post it all to a paste site

languid spire
narrow girder
fresh dirge
languid spire
deft grail
#

and that solution is also literally in the documentation for StopCoroutine

languid spire
#

yeah, instead of 'trying 200 code variations' try read the documentation once

fresh dirge
swift crag
#

you are going to have a very bad time if you do not take the time to read

languid spire
#

TL;DR; apparently that means, nowadays, any sentence of longer than 3 words

fresh dirge
# languid spire yeah, instead of 'trying 200 code variations' try read the documentation once

guys im new to this and im stuck on a problem that i have tried to fined a solution in a lot of places before i came to this server
its not that i had this and run to this server just to find an answer , i have reed the documentation but maybe from the frustration it slipped away from seeing it (English is not my first language if u didn't noticed) don't act this way to someone who is just trying to lern

#

u know what ill find it by myself

#

tnks for the help to someone new -_-

deft grail
languid spire
fresh dirge
swift crag
#

If you do not understand someone's suggestion, ask a question about it.

fresh dirge
languid spire
fresh dirge
eternal falconBOT
languid spire
fresh dirge
#

cos i read int the article that if i used an IEnumerator ill need an IEnumerator var

#

i tryd what u have sent dont be mistaken
but it didnt let my start it becuse i use IEnumerator

languid spire
fresh dirge
#

ok its fine

#

ill find somewhere else

#

tnks any way

swift crag
#

If you do not understand what the documentation is telling you, then you need to ask a question about it.

languid spire
#

I give up, apparantly OP would rather blunder around in the dark than just implement what he has been told

limpid coral
#

can i delete unity 2022 and use only the unity 6000

swift crag
#

You can uninstall it from the Hub if you don't need it.

#

Deleting shortcuts from your desktop will not do anything.

#

If you installed the editor manually -- without using the Hub -- then you'll need to uninstall it manually too

swift crag
#

You are also allowed to give StopCoroutine the same thing you gave to StartCoroutine.

rotund egret
#

The player is moving... alot..

fresh dirge
languid spire
#
Coroutine cor = null;
public void OnTriggerEnter2D(Collider2D other)
    {
        UI_manager uI_Manager;
        uI_Manager = FindObjectOfType<UI_manager>();

        player player;
        player = FindObjectOfType<player>();

        if (other.tag == "Player")
        {
            if (is_peper_active == false)
            {
                uI_Manager.add_score();
                is_peper_active = true;
                player.player_speed = 9;
                transform.position = new Vector2(0,800);
                cor = StartCoroutine(speed_peper_deactive());
                Destroy(gameObject,80);
                Debug.Log(is_peper_active);
            }
            else if(is_peper_active == true)
            {   
                uI_Manager.add_score();
                player.player_speed = 9;
                transform.position = new Vector2(0,800);
                if (cor != null) StopCoroutine(cor);
                cor = StartCoroutine(speed_peper_deactive());
                Destroy(gameObject,80);
                Debug.Log("it works");
            }
            
        }
        else if (other.tag == "floor")
        {
            Destroy(gameObject);
        }
    }
private IEnumerator speed_peper_deactive()
    {
        player player;
        player = FindObjectOfType<player>();
        
        yield return new WaitForSecondsRealtime(10);
        
        is_peper_active = false;
        player.player_speed = 6;
        cor = null;
    }

which is EXACTLY what I showed you to do

rich adder
rotund egret
# rich adder So what?

I dont have the actually main object still when you start it auto moves idk how to make it when to create the object it auto gives it a auto script that i have prepared for it

fresh dirge
swift crag
eternal falconBOT
languid spire
#

now who is being 'rude' in what way does just saying 'doesn't work' help either you or us?
expalain what you mean

fresh dirge
fossil gulch
#

Hey guys! I'm trying to keep my timer object from being deleted when I swap scenes, so I tried to add it to doNotDestroyOnLoad, but I doesn't work? I'm very confused.

Code:
https://gdl.space/okogoqiqim.cpp

#

it's not in DoNotDestroyOnLoad

languid spire
fossil gulch
lime mural
swift crag
#

"abstract coroutine"?

lime mural
swift crag
#

That is correct.

#

Notice that the return value of StartCoroutine is stored in the co variable.

lime mural
#

oh, wait, missed it

swift crag
#

this is a Coroutine object, and passing it to StopCoroutine will stop it.

#

The true branch does not save the result of StartCoroutine, so it is impossible to stop the coroutine you start there.

fresh dirge
#

a wait no

swift crag
#

Perhaps you should stop the coroutine before you even check if is_peper_active is true or false.

#

Also, I'm pretty sure it is not an error to pass null to StopCoroutine. It's also fine to pass a Coroutine that has finished.

fresh dirge
#

if i cant check whitin an if statement

swift crag
#

I didn't say to get rid of the if statement. I said to stop the coroutine before you do that check.

rotund egret
fossil gulch
#

thank you

lime mural
fossil gulch
#

ye that's what I did

#

and it works now

#

thanks!

fresh dirge
#

yea i understood i just dont know how it will check if its still active then

languid spire
fresh dirge
fresh dirge
#

its still don't work 😦

autumn tusk
#

i am so confused

#

my player completely disappeared after i changed some sprites around

#

basically i minorly changed some sprites in my assets using asesprite

#

and now all my player sprites have gone invisible

#

restarted unity, cut up my sprites, but for some reason theyre still invisible

swift crag
#

this is not a code problem

burnt vapor
#

This is a coding channel, delete this and use the proper channel please

limpid coral
#

sorry