#πŸ’»β”ƒcode-beginner

1 messages Β· Page 370 of 1

quick pollen
#

is it actually inefficient

#

calling a velocity change every frame, even if it is the same?

verbal dome
quick pollen
#

i also want to have a way to clamp the rotation in a way

#

like once it rotates 180 degrees it stops

#

ill figure that one out tho

#

hmmm it doesnt remain in a circle

#

how could I make it so it rotates constantly without converging back? I need to use pi for that somehow but im not sure how

#

probably something to orbit right?

obtuse cove
#

Someone?

blazing flicker
#

Mornin'. im struggling with persistent data. can anyone point me to a tutorial that can help with player data being persistent across the game. like coins gems stats lvl inventory etc. ?

languid spire
# blazing flicker Mornin'. im struggling with persistent data. can anyone point me to a tutorial t...
Unity Learn

Do you want to know how to keep your data between scenes? How about between executions of your game? This recorded live session demonstrates how to do both. We will look at things like DontDestroyOnLoad, PlayerPrefs, and data serialization. Note that this tutorial is coding intensive. It is advisable that you understand datatypes and object-orie...

blazing flicker
#

Thanks. I will take a look at them. @languid spire Sorry.

night raptor
#

@languid spire nope, please no. Never ever use binary formatter, never, for anything. back then it was ok before the security risks weren't known yet

eternal needle
#

please dont suggest brackeys videos, they are horrible

night raptor
#

Don't know about his videos in general but that specific tutorial should have been removed a long time ago

eternal needle
night raptor
#

can't really disagree. I used to watch a lot of his tutorials but never followed any of them, just wanted to learn the concepts and implement things by myself

rare basin
languid spire
night raptor
#

and they definitely shouldn't. it's from 2014 so wasn't really a thing back then

languid spire
#

but anyway, whichever method of serialization/deserialization is used the concepts are exactly the same

rare basin
#

not a good tutorial to link to someone who's trying to learn

#

that tutorial should be removed by Unity

languid spire
rare basin
#

you are here long enough to know that most new people just copy/paste stuff from tutorials instead of actually learning ;p

languid spire
#

indeed, and using Binary Formatter in a locally developed learning project has no security implications whatsoever

night raptor
#

true, but I still see no reason to use it for anything, even JSON or something similar does pretty much the same without any real downsides besides human readable format

iron mango
#

i am trying to rotate a part of a turret towards the target, but only on the y axis, but for some reason this code rotates it on all axis? (y and z are constantly 90) idk why, i am very confused

Vector3 D = target.position - transform.position;  
Quaternion rot = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(D), verticalRotationSpeed * Time.deltaTime);
turretBarrel.localRotation = rot; 
turretBarrel.eulerAngles = new Vector3(0, turretBarrel.eulerAngles.y, 0); 
languid spire
# iron mango i am trying to rotate a part of a turret towards the target, **but only on the y...

not sure why you are setting the euler angles at the end.
my turret rotation code looks like this

        Vector3 target = Target.position;
        target.y = Turret.position.y;

        Vector3 targetDir = target - Turret.position;
        singleStep = turretSpeed * Time.deltaTime;
        Vector3 turretDir = Vector3.RotateTowards(Turret.forward, targetDir, singleStep, 0.0f);
        Turret.rotation = Quaternion.LookRotation(turretDir);
dim wharf
#

this piece of code runs in an Update(). How do I make it so it doesn't go past the for loop until it has finished looping?

#

sort of like a roadblock for the update

#

i can only think of booleans but could there be a better way?

ivory bobcat
#

It doesn't go beyond the loop until it finishes

dim wharf
#

Ohhhh that clears up something. The way I check for input must be wrong as it still traverses the list

ivory bobcat
#

Are you perhaps wanting it to wait for each input in the loop?

dim wharf
#

Yes

#

Do you know any solutions?

ivory bobcat
#

You could use a coroutine and have a yield instruction that would wait till the particular key is pressed.

dim wharf
#

Thanks!

ivory bobcat
iron mango
languid spire
iron mango
#

which is even more confusing

devout wharf
#

Is there any voice channel on this server?

#

I can't find it.

languid spire
devout wharf
#

Tell me.

languid spire
#

there is no VC on this server

frank zodiac
#
[SerializeField] private Rigidbody2D rigidbody;
[SerializeField] private InputActions inputActions;
[SerializeField] private float movementSpeed;
private float movementInputX;

public void OnMove(InputAction.CallbackContext context)
{
    Vector2 movementInput = inputActions.Player.Move.ReadValue<Vector2>();
    movementInputX = movementInput.x;
}

private void FixedUpdate()
{
    rigidbody.velocity = new Vector2(movementInputX * movementSpeed, rigidbody.velocity.y);
}

anyone know why it doesnt work??

#

i get this error

ivory bobcat
rich adder
frank zodiac
#

i cant assign it

#

whats that?

#

is there a doc for it

rich adder
devout wharf
#

Really

frank zodiac
rich adder
frank zodiac
rich adder
#

what is this supposed to show ?

frank zodiac
rich adder
frank zodiac
rich adder
#

You create a new instance of it

frank zodiac
#

new InputActions()?

rich adder
#

also dont name assets with the same name

frank zodiac
rich adder
#

not the same name? doesnt matter where it came from

frank zodiac
#

new InputActions()?

rich adder
weary steppe
#

not too sure if this is the correct place to ask this but i am on windows and i have other people working in linux and mac, but for some reason when they clone the repo Unity starts to throw errors becuase some libs are not loaded in, such as dotTween from demigiant and such, its weird because there is another person on windows like me and its fine for him to clone and do anything. any idea?

swift crag
#

perhaps those libraries didn't get included in version control

#

the other person may have just gone and installed things from the asset store after cloning the repository

slender nymph
#

there's also the possibility that the assemblies for those assets have been set to windows only for some reason

swift crag
#

bill gates strikes again

willow scroll
#

Why would you replace the code I've sent you with mine, if I have literally copypasted this code from the script you've sent to point it out?

#

The strangest thing for me is that you haven't even noticed the code is yours?

obtuse cove
weary steppe
#

i guess the only way to get around it is to create a package file which has these libs inside already as a wrapper, maybe that will work, i was thinking of writing custom editor scripts anyway so might just bundle all together

slender nymph
#

we've already told you the possible reasons for this issue, have you bothered checking any of them?

slender nymph
#

obviously yes, because these assets are just installed directly into your assets folder, they are not installed as packages. so there's nothing stopping them from being cloned correctly unless these files are not being commited to your vcs. or if they are only working on windows then that indicates that the assemblies are set to only include windows. all of this is something you can easily fix

cosmic oxide
#

Hey, I am trying to create a generic class but it gives me a message "no Monobehaviour scripts in the file, or their names don't match the file name". The message goes away as soon as I remove the type parameter. Can someone help?

slender nymph
#

right because you cannot specify a type parameter when adding it as a component via the editor. you need to inherit from the generic class in order to do so

#

so you could have a class like public class Foo : GenericSingleton<Foo> { } (you'll probably also want to constrain T to GenericSingleton type)

#

as an example, this is my singleton implementation. it is abstract because it isn't supposed to be attached as a component itself (not that it would work anyway since it is generic). behaviours that i have that are supposed to be singletons inherit from this

cosmic oxide
#

Thanks man

#

I am gonna try it out

willow scroll
whole lark
#

Hi Im trying to follow an old tutorial from Brackeys "MOVEMENT - Making an RPG in Unity (E01)" But in the newer versions I cant find this option, does someone know how to find this?

https://www.youtube.com/watch?v=S2mK6KFdv0I&list=PLPV2KyIb3jR4KLGCCAciWQ5qHudKtYeP7&index=2 (3:43)

Let's set up the environment! We'll also make the player move, and the camera follow him.

● Sebastian's channel: http://bit.ly/1O4svpW

● Download the Assets: http://bit.ly/2u4rcEX
● Download the Project: http://bit.ly/2uecCew

❀️ Donate: https://www.paypal.com/donate/?hosted_button_id=VCMM2PLRRX8GU

Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·...

β–Ά Play video
final kestrel
#

Anyone here use odin inspector? Should I consider getting even though I'm a beginner?

swift crag
#

You no longer bake a navmesh for the entire scene. You add a NavMeshSurface to an object and then bake that

whole lark
swift crag
#

I think the default settings for a NavMeshSurface just grab all level geometry, so it'll match how the old scene-wide bake worked

whole lark
swift crag
#

what version of unity are you using?

whole lark
#

do you think that might be the problem?

swift crag
#

a version that old will still have the scene-wide Bake option

#

show me your Navigation window

#

if you can't find that; it's just Window > AI > Navigation

whole lark
fringe plover
#

Hi, need help with List<GameObject>.
Cant show code rn...
Im making mid play savjng to let player continue playing if he exit, just simple data (pos of object and some script stuff)
All objects are in list, but when i try to save list while player is doing smth it says that collection was modified..
i tried using try/catch, and restart saving corotine, but it stops itself if i use StopCorotine()...
What should i do? I also tried to save data from objects and then pass it to saving script, didnt help, same error but in passing method...

burnt vapor
#

Don't add/remove things from the list while it is in a foreach or another loop

#

The enumerable underneath assumes the collection is the same.
If you need to modify data, use a separate collection and replace the list with that one instead when you are done

barren vapor
fringe plover
#

List stores GameObject, i tried storing script too, but Object/Script can be destroyed mid saving, which will lead to same error

burnt vapor
#

So don't destroy it

#

Or make a list with only the relevant content to save

#

Either way don't modify the content

polar acorn
fringe plover
polar acorn
#

you'll need to use an indexed for loop and manually change the iterator if you change the list

#

@ whoever deleted that question just now
Quaternion.identity is the Quaternion representing the default orientation

frank zodiac
#

thanks

fringe plover
violet glacier
#

I have a gameobject that has an animation with keyframes that change alpha, how come when I change the alpha of the spriterenderer in inspector or in code, it doesn't apply?

slender nymph
#

show code

lethal bolt
#

Does anybody know why the enemy Car dosent move an floats?

slender nymph
wintry quarry
ruby python
#

@lethal bolt it looks as though you have a big cylinder collider, so it's using that to 'place' it.

stuck palm
#

whats the difference between a list and a linkedList

ruby python
# lethal bolt Yes............

Okay well the bottom of that collider needs to be 'inline' with the bottom (wheels) of the van, that should move it to the road surface.

swift crag
lethal bolt
#

Yes

ruby python
#

What is that collider used for?

swift crag
#

the truck model appears to be positioned above the object with the agent on it

lethal bolt
#

I fixed Collider

slender nymph
lethal bolt
#

But he just rotates around

swift crag
#

but they do provide efficient insertion and removal

violet glacier
swift crag
ruby python
swift crag
#

this includes every property animated by any state

swift crag
#

you can't make it stop writing by just leaving the state whose clip sets the alpha

willow scroll
slender nymph
swift crag
#

If you want to overwrite what the animator does, you can do it in LateUpdate.

swift crag
ruby python
# lethal bolt

Okay there's nothing there that's actually moving it, just giving it a target. Can you show you NavMeshAgent settings please?

ruby python
#

Oh wait, sorry, misread. Can you show the 'Enemy' script please?

lethal bolt
#

Its not much

ruby python
#

okay, sorry 1 sec, looking at a few things at the same time. lol.

lethal bolt
#

lol

ruby python
#

Okay so is it pointing at the 'target' correctly?

burnt vapor
#

Considering you usually don't add content in between, you should probably just stick to Lists

lethal bolt
#

Yes. Until i collide with it

burnt vapor
#

So it takes longer to do that

ruby python
ruby python
#

Hmmm......okay, it looks like it's being generated a little 'high' (intersecting the wheels), try moving your van 'up' quite a bit so it starts 'above' the navmesh plane (it should snap back down when you press play)

lethal bolt
stuck palm
ruby python
#

Awesome. No probs. Yeah anything that goes onto a nav mesh has to be able to 'look down' and see the navmesh, so if it's a little low it won't see it. Surprised it didn't throw an error if honest.

stuck palm
dense root
#

In a pokemon style game where there is grass you can encounter enemy pokemon is it better to put the CheckEncounter function in the player movement script or on a grass script itself?

frosty hound
#

You check what kind of tile you're on and you act on that. That should be the responsibility of the player, not the grass.

ivory bobcat
dense root
#

Great responses, much appreciated

dense root
#

I'm setting direction in the Update function yet it calls it over and over again as expected, what's a way to avoid this so as soon as Direction is set it just sets it once?

        SetDirection(movement);
        Debug.Log(direction);
    }

    private void SetDirection(Vector2 movement)
    {
        if (movement.x == 0 && movement.y == 1)
        {
            direction = "Up";
        }
        if (movement.x == 0 && movement.y == -1)
        {
            direction = "Down";
        }
        if (movement.x == 1 && movement.y == 0)
        {
            direction = "Right";
        }
        if (movement.x == -1 && movement.y == 0)
        {
            direction = "Left";
        }
    }
slender nymph
#

i'd like to suggest you use an enum for the direction rather than strings. you'll have compile time checking for things like misspellings instead of relying on you remembering how you spelled something since capitalization actually matters when it comes to comparing strings

dense root
#

Okay thank you I'll rewrite that

ivory bobcat
void thicket
stuck palm
#

whats the difference between this and just a normal equals?

slender nymph
#

that is creating a get-only property

stuck palm
#

i see

ivory bobcat
obtuse cove
void thicket
willow scroll
#

Have you even tried check whether it's called? It's not going to be called since your Collider2D has its isTrigger disabled

#
  • The OnTriggerEnter2D method happens for the object if it has its isTrigger enabled.
  • The OnCollisionEnter2D method happens for the object if it has its isTrigger disabled.
  • In both cases, the Rigidbody2D must be added to the object with the method.
  • The collider it collides with must also have a Collider2D
  • The isTrigger of the collider it's supposed to collide is doesn't matter.
dense root
#

I'm not sure I like how enums default to a value, for example when I am setting player direction it defaults to left even though input has not been received yet. Technically it should be null if I am understanding my own code correctly. Should I have it default to down? SInce the player is positioned that way at the start?

slender nymph
#

create a None member for the enum, or whatever you want as the default should be the first member

languid spire
slender nymph
#

also enums are value types so they are never null

dense root
#

Ohh thank you so much

meager sentinel
#

How do i install Visual Studio Code IDE?

eager spindle
#

I mean a sprite is normally facing down by default

eager spindle
polar acorn
eternal falconBOT
#
Visual Studio Code guide

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

https://on.unity.com/vscode

meager sentinel
meager sentinel
#

did it like 4 times

eager spindle
#

Use normal visual studio 😴

#

if you really can't get it to work

meager sentinel
#

and my pc doesn't support it

willow scroll
willow scroll
meager sentinel
willow scroll
#

Have you been coding with no errors showing up all this time?

dense root
#

Hard core mode

willow scroll
willow scroll
meager sentinel
#

2022 but i also used 2020

#

neither worked

willow scroll
polar acorn
slender nymph
# meager sentinel 2022 but i also used 2020

if you cannot figure out how to get vs code configured using the guide the bot posted, then you should consider just switching to visual studio. it's just as easy to configure, but with less steps that are easily fucked up or forgotten. and it also is less likely to just stop working

polar acorn
#

The packages and plugins have definitely changed since then

meager sentinel
#

at least for me

#

and it goes to like 1 fps

ivory bobcat
#

Follow the guides once more, you can only try - as mentioned, things have changed with VSC.

willow scroll
meager sentinel
dense root
#

How do you all feel about this gray area autocomplete that I think is relatively new? Invaluable? Fools gold?

slender nymph
dense root
#

Do any of you turn it off?

swift sedge
slender nymph
#

i have turned it off because of how often it just gets in the way

polar acorn
#

I tend to just hit escape if it's suggesting something dumb

#

I probably tab about as often as I escape so it's fair to leave on

swift sedge
#

i dont think the specific unity API helps it much

eager spindle
#

if vs is lagging because your pc doesn't have the power then it'll be very hard to use unity

meager sentinel
eager spindle
#

that shld work fine tbh, more ram would be appreciated but nonetheless

#

watch the number of tabs you have

slender nymph
#

why does everyone always throw their GPU info out when that info is entirely irrelevant

#

your GPU is not going to impact the speed of your IDE in any meaningful way

swift sedge
#

the CPU will

#

it has to work out all of the intellicode stuff first

dense root
#

That's their point

eager spindle
#

ram is pretty important, with just OS and chrome on the 8gb is completely gone

slender nymph
swift sedge
#

yeah, thats irrelevant

slender nymph
#

yes and that was the entire point of what i was saying

polar acorn
#

So you have people with some beastly 1400 dollar graphics card and then they have like, an i3

swift sedge
slender nymph
#

guys why does notepad take 6 years to open this 1.3gb file? i have a RTX 3090 and a billion gigs of ram!
nevermind the fact i'm running an intel core 2 duo and have a 5 rpm hard drive

polar acorn
#

The system can only go as fast as its slowest part

swift sedge
#

the CPU relies on RAM, the GPU relies on the CPU and the VRAM that's inside the GPU body, etc, etc

meager sentinel
#

So this is what happens

#

visual studio code doesn't show the errors

slender nymph
#

!vscode

eternal falconBOT
#
Visual Studio Code guide

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

https://on.unity.com/vscode

meager sentinel
slender nymph
meager sentinel
#

when i search it no one of the people who have reported it get even answered

slender nymph
#

go to the output to see more details and maybe an actual error code or something that you can search for

ivory bobcat
meager sentinel
polar acorn
#

You got internet? Behind a firewall? VPN?

meager sentinel
#

I have ethernet

polar acorn
#

Any number of things could prevent your network from connecting to one specific endpoint instead of another

#

And we can't really know what your connection setup is like

meager sentinel
meager sentinel
polar acorn
#

Normally you'd know what kind of software your own computer is running

meager sentinel
#

Like software like OS?

ivory bobcat
ivory bobcat
#

Can you show your Unity package manager?

meager sentinel
#

It's all what yall say "just do the steps that the bot says" i did them million times

meager sentinel
meager sentinel
polar acorn
#

Your problems seem to stem from either:
A) Faulty hardware causing installations to fail
B) Software blocking connection to the language server

ivory bobcat
dense root
#

Sorry to interupt this editor thing but I have this issue where the player "walks" through the door (scene change), and then upon exiting to go back to the world their position has changed. Would the best approach be to store the position where player has walked and then re-position them accordingly on the second walk through to the world? Here's a gif to illustrate if my message was unclear

polar acorn
dense root
meager sentinel
polar acorn
#

So, you'd be able to see "The player's last exit is null" and put them in the middle, or "the player's last exit was house_front_door so find the tile marked house_front_door and place them there

slender nymph
#

yeah that would allow having multiple entrances/exits quite easily compared to just storing the last overworld position

timber tide
#

that may be a problem if there are multiple exits, so maybe just best to link exit one door to another

polar acorn
ivory bobcat
timber tide
#

could probably just do some gamemanager with a list of entrance/exit

dense root
ivory bobcat
dense root
#

OH like a dungeon

ivory bobcat
#

Further expanding on that, what if you were to re-enter from a different entrance?

dense root
#

There's only one door in my head, how would there be a different entrance?

slender nymph
#

sure for now you only have one door. what if later on you decide to add buildings with two doors though? those absolutely exist in pokemon

ivory bobcat
#

Supposed the village was an entire scene. If you leave north but return from the south, what would happen?

dense root
#

They would reppear north

stuck palm
#

is there a time.Time for when you load the scene?

dense root
slender nymph
#

did you look at the docs?

ivory bobcat
#

Or if you teleported and exited a poke center, should you use your last position.

dense root
#

@slender nymph docs for what?

slender nymph
stuck palm
dense root
#

Oh this is for your game, not mine πŸ˜‚

slender nymph
ivory bobcat
# dense root They would reppear north

So if you entered a bug forest from the south entrance and exited towards the north entrance. Keeping track of your last position in the particular scene would have you teleported back to the bottom entrance.

dense root
slender nymph
#

again, the suggestion for looking at the docs was not for you

dense root
#

Oh you tagged me so I was confused once again

slender nymph
#

i tagged you to say that your response of "no" when someone else asked if there was a time since scene load was incorrect

summer stump
meager sentinel
#

what just happened? I tried one of the errors i had solution i found on a reddit post and now this happens

#

and it loads normal visual studio

dense root
#

Thanks everyone for the suggestions, I'm going to review these messages and take notes on the better implmentation

eager spindle
#

never seen this before

#

need the full error

ivory bobcat
# meager sentinel

You need to remove the VSC Editor package if you're following the new VSC setup

#

Note: The Visual Studio Code Editor package published by Unity is a legacy package from Unity that is not maintained anymore.

meager sentinel
slender nymph
#

it's the engineering package group, just unlock that or whatever

ivory bobcat
lethal bolt
#

I want to make the Wheels rotate 30 to the rigth an 30 to the left but now they just spin in circles and i know the problem but i dont know the sulotion and i couldnt find it

ivory bobcat
lethal bolt
#

oh

ivory bobcat
#

For instance, you'd be able to clamp the value.

polar acorn
#

right now you're setting it to a specific value

rocky gale
#

(β•―Β°β–‘Β°)β•―οΈ΅ ┻━┻

swift sedge
#

like Dalphat said, you also need to clamp the value between -30 and 30, and after that you can just rotate it

rocky gale
#

Woooooo (β•―Β°β–‘Β°)β•―οΈ΅ ┻━┻

dense root
#

So I know I'm not doing this in the suggested manner but I figured I would do it simple first then smart later but here's my teleported function. For some reason the player is not being "put back" in the same spot as where they teleported from. Any insights?

private void OnTriggerEnter2D(Collider2D other)
{
    SceneManager.LoadScene(sceneToLoad);

    // We are storing the last position and name to be used later when we re-teleport back outside 
    lastPos = player.transform.position;
    Debug.Log("lastPos" + lastPos);
    hiraganaScene = SceneManager.GetActiveScene().name;

    // If scene is equal to HiraganaScene then we telepot back to HiraganaScene in the position described
    if (hiraganaScene == "HiraganaScene")
    {
        player.transform.position = lastPos;
    }
}
rich adder
ivory bobcat
#

Did you save last position?

dense root
#

Does lastPos not do the trick?

rich adder
#

you have to store it so the value isnt wiped

dense root
#

Oh the value is not persistent?

rich adder
#

maybe start with PlayerPrefs or DDOL

ivory bobcat
#

When the scene changes all objects in the previous scene are destroyed, along with their data.

dense root
#

I see, what and what is meant by PlayerPrefs or DDOL are these persistent data storage to be used game wide?

swift sedge
rich adder
#

PlayerPrefs is a simple storing system unity has built in

#

DDOL is not storage, its a DontDestroyOnLoad function you can add your object to a special scene that never gets destroyed between scene changes (this will require good system to pass references though or singleton)

ivory bobcat
#

Player pref and json are means of writing data to disk.

gaunt ice
#

using file system to store is overkill, static is enough in your case unless you expect player close your game and reopen it after switching the scene

dense root
#

PlayerPrefs seems like something I would need later on down the road when I want to save player states, right? I feel like I just need a static object like @gaunt ice is describing

swift sedge
ivory bobcat
#

~~He may need a state manager for different scenes etc but maybe that's too much for now ~~

rich adder
#

@gaunt ice I guess static could work but its a Noob trap

dense root
#

"noob trap" πŸ˜‚

rich adder
#

yes next thing you know you start making everything static πŸ˜›

#

"this is soo much faster"

#

why isn't everyone doing this

swift sedge
#

or just copy everything to the system clipboard blushie (I'm joking btw)

dense root
#

This guy lol

polar acorn
dense root
#

Okay I'm going to use static for now, but I appreciate you all pointing me all in the right direction for the future.

rich adder
#

"the power of static, in the palm of my hand"

slender nymph
dense root
#

What does that translate to in my game? The new scene is definitely still loading just not the position being changed.

slender nymph
#

i never said it isn't loading at all. but it has not loaded by the time that code you are using to assign the position has run. because the scene load does not happen until the next frame

dense root
#

Oh I see, so in a noobie nutshell the scene is asynchronous and not matching up with the frames. Therefore it can cause "frame stuttering" as described. What is the solution to this?

slender nymph
#

no that is not at all what i'm saying. that part of the description is irrelevant

#

there, i edited the quote, ignore what is crossed out and read it again

ivory bobcat
#

Maybe have your player in the new scene update it's own position or something from the new scene update the player's position

dense root
slender nymph
#

oh my god, all i am saying is that all of that code in the method after the LoadScene call is still happening in the same scene because the scene has not changed yet

dense root
#

Oh my god now I understand

#

So even if I fix the issue with static it still won't load position correctly because the aforementioned code is happening at the previous scene

slender nymph
#

yes, but if you just let the player in the new scene assign its position from that saved position then it will be prefectly fine

dense root
#

So are you telling me to put lastPos = player.transform.position in my next scene?

ivory bobcat
#

Reminder that static data persists between scenes (everything really) - they belong to the class and not instances of the class.

gaunt ice
#
private void OnTriggerEnter2D(Collider2D other)
{
    SceneManager.LoadScene(sceneToLoad);

    // We are storing the last position and name to be used later when we re-teleport back outside 
    lastPos = player.transform.position; <-this line
    Debug.Log("lastPos" + lastPos);
    //some codes
}
slender nymph
dense root
#

I am so confused because I am "cheating" by doing the ghetto trick of checking for the Scene Name and then assigning player.transform.position = lastPos; which as I understand will just change the position of the player once they are in our HiraganaScene

slender nymph
#

remember how i already told you that the scene has not changed by the time you check the scene name?

dense root
#

Let me draw this out with crayons and I'll get back to you

slender nymph
dense root
#

I do not lol

gaunt ice
#
queried scene change
lastPos=player.transform.position;
if(some bool that is probably false){
  player.transform.position=lastPos;
}
median vapor
#

Ive stated a new project and i got stuck on rotation and Quaternion. Camera has a like topographical view on the player and the camera follows an object that is a child of the player. The issue is that i wanted the player obj to rotate towards towards the cursor.My idea of doing that was by sending the ray from the camer thro the cursor (variable "pozicijaMisaUSvijetu") and then initiating one vektor towards the point of the the contact i got from the RayCast (hitInfo) and one from the playerObj forward. Trom then on calculating the angle diffrence between them and setting the obj rotation with quaternion slerp.
Player curently spins not around his own axi, he on the axi around some unkown point
Peice of the code responsible for this:





    void fun_rotacijaIgracaPremaMisu()
    {
        Vector2 movment = new Vector2(horizontal_Input,vertical_Input);
        movment.Normalize();
        Ray pozicijaMisaUSvijetu = Camera.main.ScreenPointToRay(pozicija_Misa);
        if (Physics.Raycast(pozicijaMisaUSvijetu,out RaycastHit hitInfo))
        {
                Vector3 vektorDoPozicijePresjeka= transform.position - hitInfo.point;
                Vector3 usmjerenostIgraća =  transform.position + Vector3.forward;
                Debug.DrawLine(transform.position, usmjerenostIgraća,Color.red);
                Quaternion test1 = Quaternion.Euler(0,MathF.Atan2(vektorDoPozicijePresjeka.y,usmjerenostIgraća.y) * Mathf.Rad2Deg,0);
                transform.rotation = Quaternion.Slerp(transform.rotation, test1,0.5f);
        }
    }

Screenshot shows the POV of the camera (player shuld be in the middle of the screen)
PlayerObj has the script attached to it and has rigidbody
Player(Child of PlayerObj) is the capsule and has a box collider

noble charm
#

yo

magic crown
#

ok so small question i'm trying to do an if(lookingDirectionInput > new Vector2(0,0)) it do something, they are both Vector2 value but only problem if statement don't suport "<" with vector2 for some reason! any idea how i can go around this?

#

i don't want to use == cause i'm gonna do some other things with it and == wouldn't work

summer stump
slender nymph
#

what do you think that is supposed to do? because it doesn't make a whole lot of sense to compare which Vector2 is bigger

magic crown
late burrow
#

when i setpositions for linerenderer is there any significant performance difference if i use array of 2 vectors vs 1000 vectors

slender nymph
#

use the profiler if you have performance concerns

late burrow
#

we already confirmed that profiler lies

slender nymph
#

i don't know who "we" is, but what would make you think it lies?

late burrow
#

1 performance on pc is completely different than on phone
2 pc has lots of random garbage that doesnt occur on phone as well

polar acorn
rich adder
#

esp iOS has a good one

polar acorn
late burrow
#

what about no

#

phone debugging is bad

#

i just wanted to know if theres difference

#

everybody start mashing "try it yourself"

#

i dont wish to code for next week just for answer

rich adder
#

yes no much better to ask random people on discord arbitrary performance values

violet glacier
#

Do people usually do unit testing or other testing for unity?

frosty hound
#

Just give them an arbitrary answer so they go away for another few days

polar acorn
frosty hound
polar acorn
slender nymph
#

dang nav, should've kept your answer up so that they could have chosen their favorite of the two

rich adder
summer stump
eternal needle
dense root
#

Am I reading this correctly? When I enter the house despite the scene changing to House001 it actually enters the if statement anyways at the moment the player collides. Is this the asynchronous behavior we were talking about?

rich adder
slender nymph
#

and the frame will not end in the middle of a method

eternal needle
swift crag
#

I don't know how I'd unit-test my game

#

I'm more interested in fuzz testing

eternal needle
#

The only thing I'd consider making tests for is like my item system to ensure formulas are correct. Other than that, if I made a mistake somewhere then it's likely not noticeable

rich adder
swift crag
#

then i let the game run for a while and see if anything errored out

#

as well as if I've got obvious leaks/performance drops

#

I also write editor extensions to scan for things like missing references (after annotating fields that are allowed to be null)

rich adder
swift crag
#

(something I'm trying to do less and less as I start adding content, but...you know)

eternal needle
swift crag
#

one thing I do need to do is better test weird filesystem problems

#

I don't know how people get some of these errors...

eternal needle
swift crag
#

I've heard of this being called "soak testing" before

#

Can't find too many people talking about the idea

#

Punch Out!! on the Wii has a mode where it just plays the entire game automatically

#

(with cheats enabled so it doesn't have to play well)

dense root
#

that's an amazing game

swift crag
#

it seems very well put together

dense root
#

IIRC you couldn't save so you had to beat the whole thing in one go

swift crag
#

you're thinking of the NES game

#

that used passwords

dense root
#

Oh right

swift crag
polar acorn
dense root
#

I think when I was a kid I didn't know the password system and just played it through till I got it

rich adder
#

ahh passcode checkpoints/saves. Dark times

sour plinth
#

hey guys can i get some quick help

rich adder
swift crag
#

if you ask a question, perhaps!

sour plinth
#

yeah i was about to say if you can go there lol

swift crag
#

that problem is also not a code problem

dense root
#

Alright... so I think I'm getting a bit warmer here but the player is still refusing to move back to the same spot. Am I still not taking into account for the async scene loading?

private void OnTriggerEnter2D(Collider2D other)
{
    SceneManager.LoadScene(sceneToLoad);

    // This scene is set to the current scene 
    thisScene = SceneManager.GetActiveScene().name;

    // We check this scene for HiraganaScene in order to set the lastPos
    if (thisScene == "HiraganaScene")
    {
        lastPos = player.transform.position;
    }

    // If we have entered the house then we set hasEntered to true
    if (thisScene == "House001")
    {
        hasEntered = true;
    }

    // If we are in the HiraganaScene AND we have previously entered the house then we set player position
    if (thisScene == "HiraganaScene" && hasEntered == true)
    {
        player.transform.position = lastPos;
    }
}
rich adder
#

make your House an actual object that stores its Entrance point as a Trasform/Vector3.

#

then you just lookup the coordinate from that object

 public class Building : MonoBehaviour{
        public Transform entrancePoint;
    }```
eternal needle
slender nymph
#

they latched onto the phrase "semi-asynchronous behavior" from the LoadScene docs that talks about how LoadScene does not actually load the scene until the next phrase

#

so they are ignoring everything about how the rest of the code in that method is running in the same scene still despite having been told several times that the new scene has not loaded yet

dense root
#

Oh I think I'm starting to get it... thisScene is the previous scene... right?

#

So when I teleport the first time, thisScene is still Hiragana001 and then when I teleport out of the house thisScene is House001

rich adder
#

using scene names for this is horrid

swift crag
#

yes, because nothing happens until the end of the frame

dense root
#

Jesus that was hard for me to comprehend lol

slender nymph
dense root
#

Huh? It's blank lol

slender nymph
#

man fuck hastebin that's the least intuitive share site

#

at least changing the extension can fix the syntax highlighting though

dense root
#

Okay after a short review I see what you're literally drawing with crayons fo rme lol

rich adder
#

ever since topal changed it went to shit

dense root
#

I like GDL Space

rich adder
#

yeah I liked it to the point I've made a .NET version of it as pet project

#

maybe we can use it some day πŸ˜›

valid epoch
#

This code is giving an error that line 19 "type or namespace spike can't be found." Spike is another script that will be on the prefab instantiated on the line above. I've done this tons of times with other scripts and components so I'm not sure why it's not working in this instance specifically.
https://pastebin.com/1xArQD16

deft grail
#

double check the script name and class name

wintry quarry
#

Or it's in a namespace or another assembly.

rich adder
valid epoch
#

wow I just didn't rename it correctly, oops. Thank you!

dense root
#

So for my player to change position back to the correct spot is this the correct logic to implement? Rather than my previous approach of trying to actively set the positions and create a lot of confusion for myself.

* When the player enters the new scene, set their position using the scenePos
#

Basically set the tile position for the entrances and then manually set those positions based on where the player enters and exits

slender nymph
#

you should keep a collection of entrances and exits so that each entrance can reference some exit so you can always get the correct position from the exit point

swift crag
#

yeah, you should try to make this a little more...structured

slender nymph
#

you won't need to care about the player's previous position, you just need to know what entrance they are going through so that they go to the correct exit point

dense root
#

Right right, thank you for the insights

swift crag
#

I used ScriptableObjects for this kind of thing

#

each save point got a SO that had its name and its position

#

(i copied the actual position of the save point into the SO with a script, but you can just set it manually)

#

for "paths", like going through a door, you'd have a pair of SOs that reference each other

dense root
#

I see, I've used scriptable objects before but I'm still a bit unconfident with them. I'll definitely try it out with this use case though

rich adder
#

πŸ₯²

swift crag
#

the minor X-factor here is that you need to know which entrance to use

dense root
#

That's pretty similar to what we're discussing, right? Store the point as an object and then use that point to teleport

rich adder
#

pretty much

dense root
#

As you can tell I'm a slow learner πŸ˜‚

rich adder
#

much easier if the buildings track their own points

#

less stuff for your player code to worry about

swift crag
#

That is why I'm a fan of the idea of having an "entrance" object.

When you go through a scene transition, you would store the entrance you used in the game controller (a singleton). After the new scene loads, you'd ask that object for the corresponding entrance in the new scene.

#
[CreateAssetMenu]
public class Entrance : ScriptableObject {
  public Entrance otherSide;
  public SceneField otherScene;
  public Vector3 position;
}

You could put the destination scene in there too

dense root
#

Right right I am starting to see your points

swift crag
#

Each doorway would have an Entrance reference

#

and each Entrance would reference another Entrance

dense root
#

Thanks for the sage advice all, much appreciated

rich adder
#

OOP πŸ’ͺ

swift crag
#

instead of storing a position to take you to

#

it's not the end of the world

cosmic dagger
lament jungle
#

how can I watch for hits on my 3d mesh object?

rich adder
#

what are you trying to do

lament jungle
#

I mean

#

I want my mesh to be "Clickable" using OnMouseUpAsButton

#

but it does not really work

#

when I click nothing happens

rich adder
#

only one method works built in on MB that use collider

lament jungle
#

i forgot to add a collider

#

thanks πŸ™

vernal crow
#

I made it so that when the mouse hovers over The object the script is applied to it scales up a little and returns to original size after the mouse exits the collider area im just wondering how i can add range? ex: 5 meters away not interactable 1 meter away interactable.

eternal falconBOT
vernal crow
#

Ah man

#

I thought I followed it this time

polar acorn
#

!screenshots

eternal falconBOT
#

mad No

Be mindful, if someone requests your code as text, don't send a screenshot!

vernal crow
#

Woopsie

polar acorn
#

If you want to increase the area OnMouseEnter detects, you'll need to increase the area of the collider

vernal crow
polar acorn
vernal crow
#

Thank you I will follow the rules if I come back

ember tangle
#

How do I instantiate a UI GameObject as a child of a canvas? Normal Instantiate is not working.

ember tangle
#

it wont take my canvas reference as a argument in the Instantiate function.

#

oh man

#

I should learn how to read, i fixed it

#

Instantiate(prefab, canvas.transform) is how, right?

summer stump
ember tangle
#

yeah I was trying to pass just canvas rather than canvas.transform for some reason

sterile radish
#

currently, the way this script works is by checking if a timer has reached its intended value allows the player to click a bar. during the timer trying to reach it's intended value, this bar fills up based on the timers current time and the max time. how can i reverse this so that the timer starts and the bar starts to fill up only after the player has clicked?

this is my script:
https://hatebin.com/sjtdhyygvp

timber tide
#

Easiest way is to just flip a bool when your user does an Input.MouseDown or w/e input you're using so that for each sequential update will now go into that section of code.

#

The idea is already on that code, just gotta move the bool logic around.

snow oriole
#

Anyone know a cool tutorial to learn hitboxes/hurtboxes for a 3D action game?

#

Please ping me if so ty

sterile radish
teal viper
snow oriole
#

This is the beginner channel so I thought it'd be a given that I don't know much atm

summer stump
timber tide
#

You can use as many as you want and flip them on and off at will

dense root
#

Oh my gosh, for those who were helping me out before. Thank you. The player now correctly goes back to the desired position when exiting the door. Celebrate good times

rich adder
summer stump
dense root
#

On it!

keen pecan
#

Does anyone know where to find the "NavMeshSurface" component? I only see NavMeshAgent and NavMeshObstacle

slender nymph
#

Do you have the Ai navigation package installed?

keen pecan
#

Like under package manager unity registry?

slender nymph
#

Yes

keen pecan
#

I dont see it as an option

slender nymph
#

What version of unity are you using

keen pecan
#

How do i check?

rich adder
#

look at your appbar?

keen pecan
#

3.5.1

rich adder
#

thats hub

keen pecan
#

Oh wait i see

#

2021.3.9f1

rich adder
#

you have to add package by name

keen pecan
#

Is it just "AI"?

slender nymph
#

You may also want to consider updating to the latest patch for that version, you're missing like 2 years of bug fixes and stuff

keen pecan
#

under Packages: Built-In

slender nymph
#

no, that's the older built in stuff that the AI Navigation package was improving upon. i'm also fairly certain that the navmesh surface component was introduced in the AI Navigation package as part of the new work flow

keen pecan
#

Gotcha so I have to update unity itself

slender nymph
#

well you should update. but you can just install the AI Navigation package by name. a simple google search will tell you how to do so

keen pecan
#

Oh gotcha

#

So is it technically 3rd party or just not autobuilt in but still provided by unity?

slender nymph
#

it was just experimental still in the version you are using so it was not visible in the package manager

keen pecan
#

This is wrong, right?

slender nymph
#

you update the editor with the hub, not through that menu

#

updating requires downloading the newer version

keen pecan
#

I guess I dont have the editor downloaded somehow

#

But I guess I'll download Unity 6 preview

slender nymph
#

yes, this is the window you use to select which version of the editor you would like to install. if you just want to update to the latest patch then get the 2021.3 version listed right there

#

i do not recommend migrating an in-progress project from 2021 to unity 6, you may run into a few issues with API that has changed as well as a few other features that have changed

keen pecan
#

Gotcha I just started it so no trouble to reset

#

So is the editor where I actually make the game? Sorry if this sounds stupid but right now I know the hub and unity itself is the editor the same or different?

slender nymph
#

"unity itself" is the editor. it's literally called the unity editor

keen pecan
#

Ok gotcha so 2022.3.31 is the most recent patch? There's no 2023 or 2024 patch?

slender nymph
#

2022.3.31 is the most recent patch for the 2022 LTS release, yes. Unity 6 is the version that was 2023 but was renamed as they are moving away from the slightly confusing year naming scheme

keen pecan
#

Gotcha, do you know why it reccomended 2022 and not unity6 then? because its a preview?

slender nymph
#

yes, 2022 is the most recent LTS version where LTS stands for Long Term Support. in other words that version is going to receive patches for about 2 years (we're a bit more than a year into that cycle). unity 6 preview is the preview version before it becomes an LTS version, when it becomes LTS later this year it will likely receive the (Recommended) marking in the hub

keen pecan
#

Gotcha thank you so much this was insanely helpful. I guess one more question, what do you recommend for current projects when Unity 6 becomes LTS?

slender nymph
#

it's usually best to just stick with the latest LTS unless you need specific features from a different version or i guess don't want to be beholden to the pricing update that comes with using unity 6

unkempt carbon
#

hi guys can someone explain to me:
myBool = !myBool;

im not sure why its needed in a code for say a toggle switch

slender nymph
#

it assigns myBool to the opposite of itself

cosmic dagger
unkempt carbon
slender nymph
#

! is the "not" operator. if myBool is true then myBool = !myBool; assigns it to false

#

so if myBool is true, then myBool = !myBool is saying "myBool is assigned to not true"

unkempt carbon
slender nymph
#

no because the next time it would then say "myBool is assigned to not false"

#

and what is the opposite of false?

summer stump
cosmic dagger
cosmic dagger
slender nymph
keen pecan
#

Instead of saying (if bool = false, set bool = true) and (if bool = true, set bool = false) you can say bool != bool for the same result

sour fulcrum
#

very silly question but is there a way i can hide most of these projects in my solution without actually removing them?

slender nymph
#

probably not. although you don't really need most of those projects loaded so you can just delete the csproj file for them

#

doing so should speed up your load time for visual studio too

sour fulcrum
#

oh neat

#

debatably that's a very efficent way of hiding them

vast mountain
#

hey would anyone be willing to give some 1-1 lessons about making a first person character?

#

im kinda new to this whole coding thing and i cant find any good tutorials

teal viper
#

Private tutoring is not cheap

slender nymph
vast mountain
#

idk how much i have yet i dont get payed till friday

dense root
#

So I'm writing a collision with the grass for random encounters in Pokemon yet I don't know how to call the Collider2D of the LongGrass, how would I go about calling that collider to be checked for collision?

private void CheckForEncounters()
{
    battleTimer += Time.deltaTime;

    if (battleTimer > waitTime)
    {
        if (Collider2D col && longGrassLayer == "LongGrass")
        {
            Debug.Log("Collider2D Triggered");
            if (Random.Range(1, 101) <= 10)
            {
                Debug.Log("Encountered a wild pokemon");
                battleTimer = 0;
            }
        }
    }
}
spare mountain
dense root
#

When it's triggered is what my thinking was going into it

spare mountain
#

you're defining a new collider and checking if it's not null

#

it will always be null

#

unless I'm misunderstanding something

eternal needle
spare mountain
#

checkforencounters isn't the oncollisionenter method

dense root
#

I guess my question is how do I handle collision from the Player object, I know there's an OnTriggerEnter2D function but it needs to be called from the Grass itself

spare mountain
#

so long as one has a trigger collider

#

you're not using it though

#

you're using your own method

dense root
#

The problem with using OnTriggerEnter2D is that it's going to call this no matter what

#

I need the conditional for it to be LongGrass

spare mountain
dense root
#

Something like OnTriggerEnter2D(LongGrass)?

spare mountain
dense root
#

Ahh

#

Makes perfect sense

spare mountain
zinc shuttle
#

https://youtu.be/QbwgQSwMSGM?t=310

i am making a game similar to this, but having same issue(when the fruit collide its making infinite loop and crashes the unity),
how can i fix that?

Head to https://brilliant.org/CodeBullet/ to start your free 30-day trial, and the first 200 people get 20% off an annual premium subscription.

Twitter: https://twitter.com/code_bullet
Patreon: https://www.patreon.com/CodeBullet
Discord: https://discord.gg/UZDMYx5

Art created by @Dachi.art https://www.instagram.com/dachi.art

β–Ά Play video
zinc shuttle
#

how do i paste code

spare mountain
eternal falconBOT
zinc shuttle
spare mountain
#

you need to summon one object total

zinc shuttle
#

ok

spare mountain
# zinc shuttle ok

you could do this by comparing age or Y-level or using some central script that takes the average of their positions

zinc shuttle
#

how can I do that?

spare mountain
zinc shuttle
spare mountain
zinc shuttle
#

ok

eternal needle
#

that "average distance" is wrong, to get the average point you sum up everything then divide by the number of elements. In this case looks like 2 is always the guaranteed number
so (a + b) / 2

spare mountain
eternal needle
#

the formula you wrote is wrong, thats all.

#

"one position minus both positions' distance" doesnt even make sense, its just (a + b)/2

zinc shuttle
#

can i use the invoke method to invoke the collision after few delay after the first collision?

spare mountain
#

to find the average distance you just divide the distance by the number of elements, sure, you're correct
to implement the position they'd be at you could honestly just lerp though

spare mountain
spare mountain
#

also you can't tell which is the first or second collision

#

they all look the same

zinc shuttle
spare mountain
zinc shuttle
# spare mountain can you elaborate?

what my original code does is when 2 similar balls/fruit collide it makes many balls, and when i attach script to every ball it creates infinite loop

spare mountain
eternal needle
# zinc shuttle can i use the invoke method to invoke the collision after few delay after the fi...

theres no need for this, and no. you dont control when the collision events are sent. You may receive a collision event and then do logic after a delay with a coroutine (or invoke but really its worse).
I feel your setup is probably logically flawed though because from the code, im not entirely sure why you're trying to destroy Ballstart instead of teh current game object. I would have a single prefab stored on the script, which is the next fruit that should be spawning. A simple solution to your problem could just be storing a bool on the script like "isBeingDestroyed" and then set both to true on the first collision. Return early if isBeingDestroyed.
Then do the rest of your spawning/destroying logic

zinc shuttle
spare mountain
#

such an odd way to go about it

eternal needle
#

if ballstart isnt the current game object, then thats an issue

zinc shuttle
zinc shuttle
spare mountain
dense root
#

So I am trying to workout what would be a better way to do battle encounters than the system I have currently since it only collides once (not while walking as intended) and appears to not ever actually enter battle sequence... any suggestions?

private void OnTriggerEnter2D(Collider2D collision)
{ 
    // Check for Long grass tag to begin the battle encounter
    if (collision.CompareTag("LongGrass"))
    {
        // Set timer
        battleTimer += Time.deltaTime;

        // Check for timer for timing of encounters
        if (battleTimer > waitTime)
        {
            // If number occurs, then battle occurs
            if (Random.Range(1, 101) <= 10)
            {
                battleTimer = 0;
                Debug.Log("Entered Battle Sequence");
            }
        }
    }
}
eternal needle
spare mountain
#

also onTriggerEnter runs once

dense root
#

The grass

spare mountain
#

you're looking for OnTriggerStay

#

I believe

dense root
#

Ahh

#

Thank you

spare mountain
#

np

spare mountain
#

not just once

#

it's almost guaranteed to execute

eternal needle
# dense root Ahh

well OnTriggerStay here might be weird, because in pokemon you have to move around not just stay in the grass. One fix could be giving smaller colliders but more of them. Otherwise you'll want to just do some checks to see if you moved a certain amount

rocky gale
#

if i have a method that i want the enemy and player both able to use whats the best way to do that

spare mountain
#

I'm sure there's a better way to do it tho

severe shard
#
 
    void Update()
    {
 
        if (Input.GetKeyDown(KeyCode.Tab) && !isOpen)
        {
 
            Cursor.lockState = CursorLockMode.None;
            inventoryScreenUI.SetActive(true);
            TopBar.SetActive(true);
            isOpen = true;
            //Opend ui behaviour should be here
            Debug.Log("Sucessfuly opend inventory");
            if(Input.GetKeyDown(KeyCode.E)){
                Debug.Log("Go To Next Screen");
            }
        }
        else if (Input.GetKeyDown(KeyCode.Tab) && isOpen)
        {
            Cursor.lockState = CursorLockMode.Locked;
            inventoryScreenUI.SetActive(false);
            TopBar.SetActive(false);
            isOpen = false;
        }
    }

Hello i just started programing in unity and im having a hard time understanding why this does not print Go To Next Screen it does print sucessfuly opend inventory so my error should be in these lines

 if(Input.GetKeyDown(KeyCode.E)){
   Debug.Log("Go To Next Screen");
  }
spare mountain
#

GetKeyDown checks if it was pressed this frame

rocky gale
dense root
spare mountain
severe shard
rocky gale
spare mountain
spare mountain
dense root
#

Check it out, runs just as intended perfectly. Even when I sit in the grass the battle encounter doesn't trigger

spare mountain
#

just get a reference to your script

eternal needle
spare mountain
#

or make some central script

spare mountain
#

weird

dense root
#

I can take more screenshots if you dont believe me

spare mountain
#

take a video

rocky gale
spare mountain
eternal needle
spare mountain
#

depends on your use case

severe shard
# eternal needle πŸ€·β€β™‚οΈ if you're ok with the player standing still and it working then sure. Depe...
    void Update()
    {
 
        if (Input.GetKeyDown(KeyCode.Tab) && !isOpen)
        {
 
            Cursor.lockState = CursorLockMode.None;
            inventoryScreenUI.SetActive(true);
            TopBar.SetActive(true);
            isOpen = true;
            //Opend ui behaviour should be here
            Debug.Log("Poop");
        }

        else if (Input.GetKeyDown(KeyCode.Tab) && isOpen)
        {
            Cursor.lockState = CursorLockMode.Locked;
            inventoryScreenUI.SetActive(false);
            TopBar.SetActive(false);
            isOpen = false;
        }

        if(Input.GetKeyDown(KeyCode.E) && !isOpen){
         Debug.Log("Go To Next Screen");
        }
    }

I just moved the input.getkeycodedown out of the other if statement is this fine or are there any advantges to using GetKey?

spare mountain
eternal needle
spare mountain
#

what you've done checks if you press Tab or E separately

dense root
#

Yup still not triggering even while standing still

spare mountain
eternal needle
#

look at every single time the method is called

spare mountain
#

if it works then it doesn't really matter tbh

eternal needle
#

it will, because its behaviour different from what they think is happening.

spare mountain
#

possibly

#

I agree in principle

dense root
#

It's not because I'm looking at the debug log, you just refuse to believe it's working

eternal needle
#

you refuse to add more debugs, and really i havent even seen the updated code but if you simply changed OnTriggerEnter2D to OnTriggerStay2D then this doesnt do what you think it does.

spare mountain
#

I agree

severe shard
# spare mountain possibly
        if(Input.GetKeyDown(KeyCode.E) && !isOpen){
            //Logic For Screens
            if(inventoryScreenUI.activeSelf == true){
                Debug.Log("Inventory Was Open");
            }
            else{
                Debug.Log("Inventory Was Not Open");
            }
        }

How can i check if a ui element is active i tried searching online but this does not print anything?, No Console errors either

spare mountain
dense root
#

I can open source the project if you want to debug it yourself πŸ˜‚

severe shard
eternal needle
spare mountain
severe shard
spare mountain
#

your .activeSelf should work fine

#

so long as you're enabling and disabling the gameobject

severe shard
severe shard
# spare mountain that's just a gameobject

another quick question since i switched from lua to c for my projects

lets say i have a topbar and i have refrenced it in my gui script

Do i have to create a public varible to edit the content label or could i do something like in lua
topbar.Contentlabel.text = "string"

or do i have to create a refrence for each thing im edeting

spare mountain
#

so long as you have some reference to modify (and so long as your var isn't read only) you'll be fine

eternal needle
# dense root I can open source the project if you want to debug it yourself πŸ˜‚

in response to your deleted message
i am saying that this behaviour is unexpected, and you dont know what its really doing. You may run into a case where suddenly your logic doesnt work but youve changed no code. Which leads many beginners to the common "it was working before i changed nothing!!". It was flawed from the start, thats why.
Try this, put a wall near the grass and keep walking into it, as in your location isnt changing. I suspect itll enter the battle sequence. Now honestly i dont remember if you could do that in pokemon, but i dont recall it being a thing.
Another thing, how do you plan to customize the walk distance needed to get a new roll at entering a battle sequence? You cant, because you didnt even define this behaviour to happen in the first place.

severe shard
spare mountain
severe shard
spare mountain
#

0 is the first child

#

not 1

#

oh wait

#

not GameObject.GetChild

#

Transform.GetChild

dense root
severe shard
spare mountain
#

np

dense root
#

What's your proposed solution?

eternal needle
# dense root Okay so you're right about the battle sequence triggering when the player runs i...

this is something you could honestly keep if you're not trying to make a 1-1 clone. But besides that, this whole thing is because your rigidbody is sleeping. Its not calling OnTriggerStay2D while sleeping, but while moving against a wall its awake.
You could look more into what pokemon actually does, but its likely very different and would require change to your movement system. You could simply check if the player has moved by a certain amount before doing a new reroll, store the last position when you roll for an encounter.

teal viper
spare mountain
dense root
#

I'm using tiles

teal viper
#

It doesn't matter if you're using tiles or not

#

The movement is discreet

#

You move between 2 points always.

severe shard
#
  private GameObject contentLabel;
  contentLabel = TopBar.transform.GetChild(2);
  contentLabel.SetActive(false);

Assets\Scripts\Gui\InventorySystem.cs(84,32): error CS0029: Cannot implicitly convert type 'UnityEngine.Transform' to 'UnityEngine.GameObject'

teal viper
#

When you reach the destination point is when events should be triggered

dense root
#

Okay sorry give me a second there are two solutions being proposed here I need to decipher the proposals

spare mountain
eternal needle
#

if its not a 1-1 clone then honestly OnTriggerStay is fine there

dense root
#

I want to be as faithful to the original as humanly possible so I'm open to suggestions on how to improve it

teal viper
teal viper
dense root
severe shard
teal viper
severe shard
#

i tried using .text

dense root
#

@teal viper yeah I'm not using a grid based movement system yet

dense root
#

That's beyond my current comprehension

spare mountain
#

tons of info online

teal viper
severe shard
spare mountain
#

this should help

severe shard
eternal needle
# dense root That's beyond my current comprehension

i dont mean to deter you also, but consider kinda going in your own direction. Id say grid based movement could be worth implementing, if thats what pokemon does. You dont really need to clone pokemon though, like this clearly isnt gonna be something you sell as your own original idea. Theres not really a reason to spend tons of time rewriting massive parts of your code, when you could make something that works and move onto new things.

dense root
#

I think the movement feels close enough that it wouldn't be harshly judged if it didn't move in a perfect square everytime they moved

#

But then again if I want it to feel like the original it's a point of contention...

#

Very grateful for the feedback and insights. I need to revisit the drawing board

zinc shuttle
eternal needle
zinc shuttle
eternal needle
#

you dont want a static bool, because this means the bool is associated with the type Ball_mechanism. So this means every single item isDone or isnt done at the same time. You want this bool associated with the instance of the ball. Meaning one ball should specifically store if its done (meaning being combined i guess?). After you do this, that invoke also isnt needed

eternal needle
#

theres definitely more issues here, like line 33 you REALLY shouldnt use the find functions here. You already know which object to destroy, its passed to you with (Collision2D collision) and then you destroy the current game object too.
After you make isDone to not be static, meaning every ball has its own isDone value, you now also want to set it to true on the other object you are about to destroy.

zinc shuttle
#

wait, when I removed static it started to break again, I guess in every collision of any ball it reset the bool and stops further collision, is that right?

zinc shuttle
eternal needle
# zinc shuttle wait, when I removed static it started to break again, I guess in every collisio...

the bool is being used as a way to know if its already been combined into another ball. This is the order that the logic should happen
The balls collide, collision event sent to one ball:
That ball checks if its already been combined into a new ball, check if the other ball has been combined. If both arent combined, combine them, and set the bool to true for both objects. Destroy both objects, spawn new ball.
Collision event sent to 2nd ball:
The ball checks if its already combined, it sees that it has been. Do nothing

zinc shuttle
#

how do i know what collision ball is going to collide, like what method i could use

eternal needle
#

maybe look into more c# basics, because im not sure if you know really how to set a bool on another object

zinc shuttle
#

ok i will try

drowsy oriole
#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.VR;

public class ColorAddUp : MonoBehaviour
{
public ColorPureBlue ColorPureBlue;
public ColorPureGreen ColorPureGreen;
public ColorPureRed ColorPureRed;
float RedAddUp;
float BlueAddUp;
float GreenAddUp;
void Update()
{

    RedAddUp = ColorPureRed.PureRedValue;
    BlueAddUp = ColorPureBlue.PureBlueValue;
    GreenAddUp = ColorPureGreen.PureGreenValue;

    Color myColour = new Color(RedAddUp, BlueAddUp, GreenAddUp);
    PhotonVRManager.SetColour(myColour);
}

}

spare mountain
#

strings are not floats

drowsy oriole
#

so make red add up a string?

#

same with the others?

spare mountain
#

Color doesn't take in 3 strings

eternal needle
#

this is surely some AI suggested code.. why do you need a ColorPureBlue along with other colors? Literally just define it using a number

spare mountain
spare mountain
#

lmao

drowsy oriole
#

i turned them all to floats

eternal needle
#

dear lord, do some basic c# first and save yourself the headache

spare mountain
#

πŸ’€

drowsy oriole
#

just tell me what to do

#

please

spare mountain
#

you changed "them all" to floats... where?

drowsy oriole
spare mountain
#

πŸ’€

drowsy oriole
#

Im stupid

#

really

#

really

spare mountain
#

you're going to have so much more trouble if you don't learn C# first

eternal needle
eternal falconBOT
drowsy oriole
#

reeeeeeeeeally stupid

drowsy oriole
eternal needle
#

best way to not get help is to demand help

drowsy oriole
#

please tell me what to do

spare mountain
#

it'd be like saying "float string e"

drowsy oriole
#

NO

spare mountain
#

'public' is not a type

drowsy oriole
#

its not supposed to be a variable

spare mountain
#

I know

#

it's a script

drowsy oriole
#

BlueAddUp Is a variable

spare mountain
#

a different one

#

sure

drowsy oriole
#

Im trying to get that variable to equal a value in a script

spare mountain
#

you're trying to convert apples to oranges

drowsy oriole
#

yep

#

wait

#

no

spare mountain
#

first of all you're doing weird script stuff

#

but whatever

eternal needle
spare mountain
#

ColorPureRed.PureRedValue should be a float

eternal needle
spare mountain
spare mountain
#

sorry typo

drowsy oriole
#

You mean ColorPureBlue.PureBlueValue is a FLOAT

#

my brain is dead

spare mountain
#

it needs to be a float

drowsy oriole
#

even more than it was 2 seconds ago

spare mountain
#

go configure your IDE though

drowsy oriole
#

ok

eternal needle
drowsy oriole
#

Ill brb ima go configure the ide but

spare mountain
#

wait

drowsy oriole
#

delete them?

spare mountain
#

I was looking at the wrong thing

#

1 sec

#

sorry ignore that

spare mountain
drowsy oriole
spare mountain
#

did you save your file

drowsy oriole
#

yes

spare mountain
#

okay go configure your IDE and you'll see where the issue is

drowsy oriole
spare mountain
#

configuring your IDE will help a ton

drowsy oriole
spare mountain
#

I'm going to bed

drowsy oriole
#

Plz help

#

@elfin cedar

burnt vapor
#

@drowsy oriole This server requires you to have a properly configured !ide in order to be helped. Until that time stop spamming the server and please look into getting that working.

eternal falconBOT
burnt vapor
#

Especially in your case the issue can be omitted by having your editor set up correctly.

#

And please don't spam random users. Helper is a user, not a role you can ping

drowsy oriole
#

i didnt know

#

he had his name as helper

#

this server dont got a helper role

burnt vapor
#

Because there is no need to. The whole point of these channels is helping

queen adder
#

Vector2: How to get green when i have red, white, and blue? The length of yellow line varies as well

#

yellow line is perpendicular to the long line

astral falcon
queen adder
#

length of yellow line is a variable, controllable

astral falcon
#

thats another infromation than "varies" πŸ˜‰

modest dust
#

Look up how to calculate a line perpendicular to another line and passing through a point (the point being white)

eternal needle
#

Hopefully that is even perpendicular in the first place, otherwise this question doesnt make sense

topaz mortar
#

Is it bad to make functions like these and Update() for example async? I wonder what consequences that has, especially for Update?
public async void OnDrop(PointerEventData eventData)

astral falcon
#

Update wont wait for it to finish, so you just start that function on every frame. Whatever the function itself does might overlap with a more recent run of its code then

topaz mortar
topaz mortar
#

not actually sure if I do it in any of my Update fuctions, but the OnDrop is another weird example

topaz mortar
astral falcon
#

Taking of car wheels does not scream at you it cant drive. It wont just work

topaz mortar
#

ok good to know

#

kinda expecte that yeah

#

so I guess it's the same for stuff like OnDrop?

#

well maybe not πŸ€”

astral falcon
#

Depends on where it gets called. If its a single call method, it might be also working as async.

topaz mortar
#
{

    // Equip the dropped item
    public async void OnDrop(PointerEventData eventData)
    {
        // eventData.pointerDrag is the gameobject being dropped
        if (eventData.pointerDrag == null)
        {
            return;
        }

        // Get our item
        Item droppedItem = eventData.pointerDrag.GetComponent<Item>();
        if (droppedItem == null)
        {
            Debug.Log("No dropped item.");
            return;
        }

        droppedItem.dragged = false;
        await droppedItem.EquipItem();
    }

}```
astral falcon
#

Why exactly are you awaiting at all when the equipitem is not yielding anything afterwards ?

#

What Unity Version are you using btw

topaz mortar
#

because EquipItem() does server calls and needs to await the replies

#

2022.3.10f1

astral falcon
#

I just cant find the OnDrop method in the docs for that version

topaz mortar
#

IDropHandler

#

at the top

astral falcon
#

latest version supported 2019.1 ? Hm, im confused

topaz mortar
#

well it is working πŸ˜›

#

is there another method I should be using instead?

astral falcon
#

What is OnDrop actually doing?

void thicket
#

To an oblivion

astral falcon
astral falcon
#

πŸ˜„ you were faster

topaz mortar
astral falcon
#

Okay, so its a onetime call, id say,just try to await something simple and after a second, call a dbeug log and see if it works then.

#

you can always call another async function from the not async OnDrop too

topaz mortar
#

it just feels safer this way, but yeah could test if it actually works

#

it needs to work in EquipItem though

#

so I'm afraid if I don't use await to call EquipItem, that won't await stuff either

astral falcon
#

Await is literally awaiting the other function to finish. So its just preventing your OnDrop to continue while Equipitem is not finished. If you dont await it, it will just call that function which will do whatever its supposed to do and ondrop will finish on its own

topaz mortar
#

that's what I get when I remove the async & await

astral falcon
#

Its right there what will happen. Its not an error, just a hint for you that it will continue the CURRENT method (OnDrop) without waiting. If you do not need to wait, ignore it

topaz mortar
#

the green underline kinda triggers me lol

astral falcon
#

I can tell πŸ˜„ Then just make your ondrop async and see if it works.

#

So the unity core will have its wiggle line somewhere but wont show it to you πŸ˜‰

topaz mortar
#

also get in in unity console:

#

I can do _ = too

astral falcon
#

Double trigger! πŸ˜„

topaz mortar
#

but not sure what the effect is

astral falcon
#

Try OnDrop async