#💻┃code-beginner

1 messages · Page 477 of 1

late burrow
#

from very begining i wanted get json as jobject but they giving me some trashy jtoken which cant be used for anything

obsidian granite
#

How can I calculate where I need to apply a force and with what force to stop a spin?

late burrow
#

i use jobject but jobject["thing"] magically turns into jtoken

zenith cypress
#

Of which you can just keep keying into, look at the second link. What's the problem?

late burrow
#

i cant get raw text from these

#

and arrays

zenith cypress
#

Because you have to cast it?

#

Again, look at the second link

#

It does both

late burrow
#

i specifically not used a single different object for json

#

everything was built on jobjects

#

they seem to have everything

#

so for example im right in the point where i want get string from, why tostring() gives me both variable name and its value

#

i want separate these

verbal dome
obsidian granite
#

i know calculating moment of inertia is a multivariable calculus concept iirc

#

i know that i want to have the acceleration just be opposite the angular velocity

verbal dome
#

Worth mentioning that you can also directly modify angularVelocity if needed

obsidian granite
frank flare
#

how do I check if not

Vector3.Distance(item1.position, item2.position) < 20
obsidian granite
#

in code you can check the inverse of any boolean expression with the ! operator
for example, !true is equal to false

#

but in this case you don't even need it

frank flare
obsidian granite
#

why not just make it a greater than or equal to sign

frank flare
#
if (!(Vector3.Distance(item1.position, item2.position) < 10))
                    {
                        Debug.Log("big distance");
                    }
obsidian granite
#

ok man

#

inversting an entire condition looks uglier than >=?

#

i mean you do you but readability takes a hit there

winter blade
#

guys, can I extract a c# code file from a builded game?

obsidian granite
#

i don't recall

little bone
#

is anyone here willing to hop in a DM call with me and teach me how to actually code because the youtube videos that i watch really do not help me one bit

languid spire
little bone
#

yeah i know

obsidian granite
little bone
#

i kinda just want to learn some of the basics

obsidian granite
#

of which language?

#

c#? python? c++? c? asm?

little bone
#

c#

obsidian granite
#

c# for unity or c# in general?

little bone
#

c# for unity

obsidian granite
#

ok so what are you having trouble with

willow scroll
little bone
obsidian granite
#

speaking of c#, i gotta learn .NET, apparently that's what's big nowadays

obsidian granite
little bone
#

i know

obsidian granite
#

look at yt videos, if there's a concept in them u don't get, feel free to dm me

willow scroll
obsidian granite
#

is it convention to use var in things like enhanced for loops in c#?

#

i never used auto when i was learning c++

#

but whenever i see yt vids, everyone is using var to declare variables

languid spire
#

I hate var, it adds nothing and takes away a lot of readability

obsidian granite
#

i don't get why, in a statically typed language, you would choose to not explicitly declare the type of any given variable

willow scroll
languid spire
#

I'm with you on that one

obsidian granite
#

also, why does c# have like hungarian notation sorta for its interfaces?

#

idk what the term would be

#

them prefacing their interfaces with I

willow scroll
#

I stands for Interface. This way you differentiate them from methods

languid spire
#

Like a lot of the MS C# conventions, they are holdovers from the old C and C++ days, Totally pointless in this day and age of competent IDE's

obsidian granite
willow scroll
languid spire
foggy yoke
#

Hi, how can I play animations from a script?

foggy yoke
#

ohhhhhhhh

#

thanks

frigid quartz
#

I want to use a "Lobby Data" scriptable object to store variables like Max Players, and share this lobby data on all sorts of different objects that need it. Currently, I have the LobbyDataSO referenced in my GameManager, and made the GameManager a singleton, so that LobbyData only needs to be changed in one spot to be reflected across everything else.

Is there a better way to do this though? Should I just make a serialized private _lobbyDataSO variable in every script that needs it and drag and drop for each?

rich adder
frigid quartz
# rich adder I mean you could but if its on a singleton already, why not just reference it fr...

Because, I think I want to do away with the singleton. Right now I'm inheriting from a base "universal" Singleton script, something I just copied off a YouTube video, and its causing some errors, I know I could fix this pretty easily but I'm also seeing an opportunity to refactor and decouple things.

Also, one day, I intend for the game to be multiplayer and have different lobbies, and different game manager's specific to each lobby - I don't know enough yet to know if the singleton will be a problem or not, but I assume so.

#

Does it make sense to just set up a "LobbyManager" class and then have everything else just do a "FindAnyObjectOfType<LobbyManager>" to automate referencing it? Maybe I could also define default values where needed incase of LobbyManager being null?

rich adder
rich adder
frigid quartz
gloomy iris
#

Unity.Mathematics.quaternion does not have a UnityEngine.Quaternion.RotateTowards equivalent anywhere in Unity.Mathematics... right?
If I want to do incremental rotation without any overshoot towards a target value I have no choice but to "implement" that myself?
Or am I just doing something fundamentally wrong?

cosmic dagger
#

Quaternion.RotateTowards is a regular method from the UnityEngine namespace . . .

gloomy iris
#

So is that the intended way to use Unity.Mathematics.quaternion ? every time I'm missing something I should convert it to a UnityEngine.Quaternion and convert it back again to a Unity.Mathematics.quaternion ?

#

That sounds wrong

cosmic dagger
#

oh, you're looking for a similar method within Unity.Mathematics. i'm unsure if they have one. i don't use that namespace . . .

#

i thought you confused using the Unity.Mathematics.quaternion namespace with the regular Quaternion . . .

gloomy iris
#

Sadly not 😭

brave compass
cosmic dagger
brave compass
gloomy iris
#

Rider could

cosmic dagger
#

Oh, a little late about that, haha . . . 😅

gloomy iris
#

I already made an adapted version of it I just wanted to know if I'm missing some intended way instead. Thanks 😄

frank flare
#

what way do you use to combine multiple stuff in an output?

#

like Debug.Log("rtgrg {position} wredgrfhmewrfg")

rich adder
wary gale
#

Hi, noobie here. I tried turning the child of a gameobject into a different gameobject stored within a variable. This is done in the script of the parent. I would appreciate your input!
My line of code:

gameObject.transform.Find("Item1") = Player.GetComponent<PlayerScirpt>().Item1;

wintry quarry
#

You cannot "turn a GameObject" into another GameObject

#

Can you explain what you're trying to do?

wary gale
#

Really?

formal sable
wary gale
#

Darn, okay i guess that explains it, i can find a workaround

wintry quarry
#

I have a feeling your= is just backwards

#

It should be Item1 = Find(.. whatever)

#

Not the other way around

wary gale
#

The child is an inventory slot that should become an item "picked up" by the player inside the player script

deft grail
#

Random.Range(1, 2) will only pick 1 always @formal sable

#

you would need to use 1, 3 to get 1 or 2, it says this in the docs for it

wary gale
#

But i think i can keep working from here. Thanks for your help

wintry quarry
#

not value = myVariable

#

if you want to change the hierarchy (change qwhich objects are children of which) then you need to be doing someObject.transform.parent = newParent or someObject.transform.SetParent(newParent)

#

that's different from assigning a variable

formal sable
deft grail
formal sable
#

Okay... Thank you

true stratus
#

idk what chat im supposed to go to but wehen i try to build my unity game halfway through of it building i get an error

#

and it dont show what errors

wintry quarry
true stratus
wintry quarry
#

Are you looking at the console window?

true stratus
#

yes

#

is there a way to show my errors

#

it says error building player 3 errors but not what im supposed to fix

wintry quarry
#

and look at the full message

true stratus
#

most of them dont really give anything except saying something is wrong

wintry quarry
#

Show them all

true stratus
#

thats all

wintry quarry
# true stratus

Ok so that's one problem. You're apparently referencing this logo in your build which shouldn't be referenced.

true stratus
#

do i just delete the logo file?

wintry quarry
#

You have to stop referencing it wherever you're referencing it

true stratus
#

how

wintry quarry
#

You have something referring to it

true stratus
#

i started developing a few days ago

wintry quarry
#

make it not refer to it

#

You can right click it and find references

true stratus
#

these are the ones they floating around the map

#

do i delee em

#

delete

wintry quarry
#

wdym they're floating around the map

true stratus
#

in top right and in bottom u can see em

wintry quarry
#

those are gizmos aren't they?

true stratus
#

idk

wintry quarry
#

or is that an actual sprite

true stratus
#

their appart of my multiplayer thing

wintry quarry
#

you have to look at the things

#

and see what they are

#

Sprites?

#

MeshRenderers?

true stratus
wintry quarry
#

that's the asset

#

I mean the thing in the scene

true stratus
#

there for my vc

#

and my player spawner

wintry quarry
#

that's not referencing the logo no

#

You should right cllick on the logo asset

#

and Find References In Scene

#

but also this is maybe more of a VRChat question

true stratus
#

cuz i wanna test my new multiplayer build

true stratus
#

im looking for refrencses and it shows this

#

so they are refrences

#

@wintry quarry

#

help its stuck on this white build how do i turn it to normal

true stratus
frank flare
#

does it mean something important? (I decided to go on and don't have these stuff now)

rich adder
#

i think

#

should not be issue unless it keeps happening

#

you cuold try just deleting the library folder and rebuild also

frank flare
#

it's ok

#

this is the project that took me 1 month

twin bolt
#

I need help. I'm trying to set up dropping items on the ground, only issue is that using triggers is not working, since there may be carpets on top of wooden/marble floors. I'm thinking Raycast's, but if the item could be constantly rotating, that will cause issues.

tranquil zealot
#

hey guys! so im trying to make it so that when i press space, a bullet is instantiated and is moving in the direction of my players current rotation, any tips? this is top down 2d btw

keen dew
#

Which part of that do you not know how to do?

rich adder
tranquil zealot
rich adder
tranquil zealot
#

but the rotation is dynamic, not just up left right or down

late burrow
#

whats the expected way of going one step down of jtoken and reading its childs

main karma
#

I tried using it and just debugging whenever it hits and it seems it never calls it, any ideea why?

livid grail
#
cs
Debug.Log(360/100);

Why does this give me 3 instead of 3.6?

short hazel
# late burrow whats the expected way of going one step down of jtoken and reading its childs

JToken is abstract and may refer to anything in the JSON payload. "hello" is a JToken for example.
You need to type-check and base your logic on that. If the token is an array, loop through all its elements (which you'll get as JTokens too!). If it's an object, loop through its properties' values (which will also be JTokens)

if (tok is JArray arr)
  // use 'arr' your array
else if (tok is JObject obj)
  // use 'obj' your object
short hazel
livid grail
slender nymph
#

but is NumberAmount a float or an int

short hazel
#

360 and/or NumberAmount must be a float

#

It does not care about which variable you'll be putting it into

#
float result =  3 / 10;

Gets evaluated as:

  1. Compute the result of 3 / 10: it's 0
  2. Convert that value to a float: still 0
  3. Put the value in the result variable
#

By forcefully telling it that either operands of the division are floats, you convert to float first, then perform the division

livid grail
#

I solved it by simply delcalring 360 as a float

rotationAmount = 360f / NumberAmount;
#

number Amount is a int

#

but it all works as intended now, thanks!

slender nymph
potent olive
#

would anyone know why the sprite isn't able to be created? I doubt it has anything to do with rounding or not being perfectly divisible, since the width works fine, but the height refuses to slice at any value other than 1. (note that the input field doesnt update when theres an error; the number of rows IS getting correctly set to 2, i have tested it)

slender nymph
#

!code

eternal falconBOT
late burrow
#

i dont see way to go futher down

short hazel
#

That's a property. Determine its C# type and you'll be able to get either the key or value

late burrow
#

i mean everything in json is string isnt it

willow scroll
#

It's only shown as a string

short hazel
#

The serializer parses the string and gives you some JTokens, which is the high-level representation of the string

late burrow
#

so i cant even get raw string from json?

willow scroll
#

json is already a raw string

short hazel
#

Yes you can, by using the C# types, and going through the "syntax tree"

late burrow
#

i do have type but i dont see why would i need it when i just want .value of current jtoken

#

because it gives me both name and value

short hazel
#

Tokens don't have a value because they may represent more than just a value. They could represent an array and its contents, an object and its properties

glad wagon
#

I'm lost here. I have a player animator and it is getting very confuse now that I want to add a weapon system. Is it better to put all the gun controller and animations in the tank controller script and in the player animator or should I create another animator and scripts for guns?

late burrow
#

if they represent more how do i go step down more then

short hazel
#

By writing a recursive method, with the type checks in it

late burrow
#

or perhaps i did bad by writing everything in jobjects now its pain in ass to get anything out of json?

short hazel
#

You don't seem to understand that there are multiple elements in a JSON payload

late burrow
#

yes and i wanted pretty much universal access by thing["a"]["b"]["c"}

#

no arrays no anything just objects that hold more objects

short hazel
#

Unfortunaltely that's not how the serializer works

#

You either recursively go through the syntax tree, or deserialize the JSON payload into C# classes you make yourself, that conform to the structure of the JSON payload

late burrow
#

is there like any thing that allows me write data to nonexistent variables

#

like json

#

i can write but not read

short hazel
#

You cannot write to something that does not exist

potent olive
# potent olive would anyone know why the sprite isn't able to be created? I doubt it has anythi...

heres the code:

public void SplitSpritesheet()
    {
        int spriteWidth;
        int spriteHeight;

        spritesInSpritesheet.Clear();

        spriteWidth = spritesheet.texture.width / rowsInt;
        spriteHeight = spritesheet.texture.height / colsInt;

        for (int i = 0; i < rowsInt * colsInt; i++)
        {
            Vector2 bottomLeft = new(0, spritesheet.texture.height - spriteHeight);
            Vector2 topRight = new(spriteWidth, spritesheet.texture.height);


            Sprite splitSprite = Sprite.Create(spritesheet.texture, new Rect(bottomLeft, topRight), new Vector2(0.5f, 0.5f));
            spritesInSpritesheet.Add(splitSprite);
        }

        characterPreview.sprite = spritesInSpritesheet[0];
        charAspectRatioFitter.aspectRatio = (float)spriteWidth / (float)spriteHeight;
    }
willow scroll
potent olive
#

it should just be an mp4 recorded with obs, maybe restart your discord? idk

short hazel
#

Works for me, try restarting

To be confirmed, but seems like an off-by-one error? Error message suggests that the bottom right point of the rect is at Y 1066, which might be 1 too many for an image that is 1066px high (where coords would go from 0 to 1065)?

potent olive
#

i've tried subtracting 1 from the height, width, and both, but that doesn't seem to work. let me restart and then record a video

willow scroll
potent olive
#

OH

willow scroll
#

Since it takes position and size, not corners

potent olive
#

yep, that fixed it

#

my bad!

willow scroll
#

(float, float, float, float) might be better to use in your case

potent olive
#

(to be fair im a bit surprised that theres no overload for the construtor to take two corner points lol)

#

thanks for the help!

wheat coral
#

I want to make a script by which my game object can throw balls towards my bat in curve direction

long jacinth
#

void OnTriggerEnter(Collider other) {
        if(other.gameObject.tag == "DestroyPlayer")
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
    }```
#

why doesnt this work i put it on the player and its not reloading the scene

#

my player has a character controller and capsule collider

rich adder
potent olive
#

alright, i have another issue. i'd like to make it so that, when refreshing the TMP inputfields through this method, it doesnt trigger the functions set in the unity inspector. however, the code i have below still ends up triggering the function set in the inspector. Is there any way to fix this?

    public void RefreshFields()
    {
        charNameInput.text = currentAnimContainer.name;
        print(currentAnimContainer.name);
        rowsInput.text = currentAnimContainer.spritesheetRows.ToString();
        print(currentAnimContainer.spritesheetRows);
        colsInput.text = currentAnimContainer.spritesheetCols.ToString();
        print(currentAnimContainer.spritesheetCols);
    }
short hazel
#

Yep you have a SetTextWithoutNotify(string) method usable on the text, which will change the text without raising the event

potent olive
#

oh awesome

#

works perfectly, thanks :3

storm heath
#

!docs

eternal falconBOT
meager sentinel
#

Nope, i dint (sorry for answering so late haha)

rich adder
#

I can barely remember what i ate yesterday sorry

meager sentinel
rich adder
#

good so we're on the same page, show setup again or something we can prob figure this out in a few minutes lol

rich adder
meager sentinel
#

yeah

#

smth

#

well not bullet colliding

#

i guess something else

#

or the shoot script is indirectly affecting with the character

#

bullet is set on trigger

rich adder
#

affect in what way

meager sentinel
#

it like pulls the player to the wall, seriously.

#

If you are fast enought you can get the enemy to pull you to the other wall and if you just get in enemy distance you will get pushed into any wall

rich adder
#

are you like applying the forces on the player maybe 🤔

#

is player rigidbody ?

meager sentinel
#

yes

#

and i know it is the enemy because if i get the range higher it also starts pulling into the wall without even moving

#

is it related to the player being rigidbody?

#

like rigidbody controlled?

rich adder
#

applying force to players rb instead ?

meager sentinel
#

and it doesn't make a mention to the player

#

so i dont think so

#

I will see which one of the 2 scripts causes the problem

rich adder
meager sentinel
#

seems that the problem is the bullet script

meager sentinel
#

and i dont have video software

#

so i cant record

final pelican
rich adder
#

jesus why does a bullet need to have a reference to the player

#

well you have this rb = playerObject.GetComponent<Rigidbody>();
but doesnt seem to be anything so should be ok

meager sentinel
#

stills happening

rich adder
#

no shite, that line of coding isn't doing anything

#

changing/remove it wont change your current issue

rocky canyon
#

to me theres nothing to me thats gonna make sense why it doesnt display the BG if its docked and maximized

#

but it does when its undocked and maximized.. (same screen size)

#

and that Button error magically went away when i started lookin for it

rich adder
#

is just happening in teh editor right?

#

the old GUI method should still work okay.. I just heard people shouldnt built anything runtime with it. Much better to use UI or UIToolkit

meager sentinel
#

I guess the problem isn't the bullet script as i thought

#

since even after disabling everything it contains it stills does the same

rich adder
#

its not unless what you sent isn't the current script

#

check your movement script

#

is it only when enemy?

rich adder
meager sentinel
brazen mortar
#

Hi there!
I have this code for updating the rotation of a cinemachine3 camera based on the script from the unity example.
My version uses an external script(TouchField) to give me a vector2 for the x and y input from the player.

however the unity scripts returns a float that seems to be based off some kind of conditional statement but i'm not sure how to tell it x or y?
https://gdl.space/yucafotece.cpp

and a link to the unity example code below
(https://docs.unity3d.com/Packages/com.unity.cinemachine@3.0/api/Unity.Cinemachine.CinemachineInputAxisController.InitializeControllerDefaultsForAxis.html#Unity_Cinemachine_CinemachineInputAxisController_InitializeControllerDefaultsForAxis_Unity_Cinemachine_IInputAxisOwner_AxisDescriptor__Unity_Cinemachine_InputAxisControllerBase_Unity_Cinemachine_CinemachineInputAxisController_Reader__Controller_)

rich adder
# meager sentinel yes

when does it happen particularly, also could you just use the built in windows recording with windowsKey + G

#

or dl OBS

meager sentinel
meager sentinel
steep rose
rich adder
#

shareX is also pretty compact

meager sentinel
rich adder
steep rose
meager sentinel
steep rose
#

if your pc cannot run oCam then im not sure what you can do

meager sentinel
polar acorn
steep rose
#

very vague meaning "output"

meager sentinel
polar acorn
steep rose
rich adder
#

if its not working as predicted you messed up somewhere

#

work your way back to what you did while it was still working

meager sentinel
#

thing is i forgot what i had before

rich adder
meager sentinel
sage peak
#

Can someone please explain to me whats the difference between a Public float and a Private float

rich adder
polar acorn
rich adder
#

maybe this Rigidbody rb = Instantiate(projectile, transform.position, Quaternion.identity).GetComponent<Rigidbody>(); and even this is messed up cause i told you you can remove GetComponent if you're already spawning as RB @meager sentinel

meager sentinel
#

but i dont think so

#

since i added the // and stills happens

sage peak
meager sentinel
#

i dont know if i deleted something accidently

rich adder
polar acorn
#

If a variable shouldn't be edited from another script, make it private

sage peak
#

Oh, okay, thanks a lot! <3

rich adder
#

look up "Encapsulation"
its one of the basic principles of OOP

polar acorn
#

That way you don't end up with stuff breaking in ways you don't expect

meager sentinel
rich adder
#

i doubt its that code, did you try disabling it

meager sentinel
rich adder
#

well nothing is touching the player on this script 🤷‍♂️

meager sentinel
#

i tried making this one myself and well, you see how that went out.

rich adder
#

it can range from simple follow stuff to complex algoritms/systems like GOAP

rich adder
brave shore
#

Hello fellas, i'm having an issue with my project and i'm afraid to ask for help in the wrong place. Do I just post my issue here?

wintry quarry
brave shore
#

Yes of course 😄

wintry quarry
#

then post it

eternal falconBOT
meager sentinel
#

i have been stuck in this for 3 months

rich adder
#

and never use Transform/Translate to move rigidbodies

steep rose
#

as they will ignore collisions ^

#

best use Addforce() or Velocity to move them

brave shore
#

Okay, so my issue is, i have currently two scenes in my project. In one, when I create a simple square and give it a boxcollider2D, and a script just to test the OnMouseEnter() method, all happens well and I get my Debug.Log("...") message. But when I do the EXACT same thing in my other scene, the mouse is not recognized and I get no Debug.Log message. For now I only want the Square in the second scene to also recognize the mouse entering its collider.

Attached are the inspectors of both squares, and the script on both of them.
I would immensely appreciate some help, as this is stalling my entire game. Thanks so much!

wintry quarry
#

Shouldn't you have your console window open though?

#

It's not actually open afaict

brave shore
#

Oh i just didn't clear it yet, it is not recognizing the mouse on the purple scene

spiral oak
wintry quarry
brave shore
#

I fiddled with it and I ticked the "both" option

spiral oak
nocturne iron
#

my friend gets this error which doesnt let him enter the project without going into safe mode

System.NullReferenceException: Object reference not set to an instance of an object.
at ApiUpdater.MovedFromOptimizer.Program.CollectMovedFromTypeNamesFromAssembly(String assemblyPath, StreamWriter outputFile, IAPIUpdaterListener logger)
at ApiUpdater.MovedFromOptimizer.Program.RealMain(String[] args)
at ApiUpdater.MovedFromOptimizer.Program.Main(String[] args)

does anyone know a fix?

wintry quarry
spiral oak
#

Oh

wintry quarry
brave shore
#

Okay, I will learn more about it. Thanks so much! I will share if it worked as soon as I implement it

spiral oak
#

No idea how to fix it though

nocturne iron
#

ah

rich adder
#

probably a bad asset causing it

rich adder
valid needle
#

Hey guys, im VERY new to the whole coding aspect of unity, and wanted to make a NavMesh Agent go from one point to another, and when it reaches the end, it gets Destroyed. I attempted it and got an error stating the following:

error CS1061: 'GameObject' does not contain a definition for 'collision' and no accessible extension method 'collision' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)

and

error CS1501: No overload for method 'Destroy' takes 0 arguments

The script is shown below

#

Any way around this?

wintry quarry
#

you made that up
there is no such thing called "collision" on a GameObject, which is what your error is telling you.

steep rose
#

not just any random "collision"

eternal falconBOT
wintry quarry
#

Also Enemy.Destroy() is likewise nonsense, GameObject doesn't have a Destroy() method

steep rose
#

Destroy(gameobject);

#

is the right way to do that

wintry quarry
#

in this case - Destroy(Enemy);

steep rose
#

best configure that ide 😅

valid needle
#

ah, i see. apologies this is my first time giving this a shot, and i decided to wing it. thanks for the help though 🙏

steep rose
#

you know when you configured it correctly when it starts to roast you

wintry quarry
rich adder
#

yeah you dont want to just wing it without a base foundation

wintry quarry
#

likewise the whole agent.GetComponent<NavMeshAgent>() line doesn't do anything and is pointless.

steep rose
#

1000% configure that ide, I know it sounds like we are harping at you but we are trying to help 😅

steep rose
rich adder
valid needle
rich adder
valid needle
#

got an issue again. The script works perfectly, except for the part where its meant to collide with an objcet tagged endofpath. when it moves to it, it treats it as if it doesnt have a collider at all, and just goes through it

deft grail
valid needle
rich adder
#

navmesh agents dont collide with anything

#

they're using a mesh to navigate, their transform is written by component

valid needle
#

shoot, that explains that then

rocky canyon
#

i tie a rigidbody to mine to use for collisions and stuff

steep rose
#

you could make your own navmesh agent

#

ive seen people do it before

rocky canyon
#

turn off gravity and stuff and and let it just follow the agent

valid needle
rich adder
#

lock it or make it kinematic

valid needle
#

didnt seem to do anything 🤔

rich adder
#

putting a rigidbody wont do anything except give you OnCollision and OnTrigger method depending on collider type

#

the transform is still being " teleported "

hasty tundra
#

Im trying to have it setup so that when upper is assigned, instead of having to specify which part of the enum i want to reference, having to have a seperate line of code for each instance, that i could potentially have it setup to where i can put a variable such as an integer where [ManageSkillTree.WeaponDataType.Gun] is, so that i could change the variable to call a different instance instead of having to have a million very similar lines of code.

rich adder
steep rose
#

if you have an enum, why not just use said enum?

#

im not sure I follow

hasty tundra
valid needle
rich adder
#

if you want it to stop somewhere you SetDestination to it

#

or agent.Stop

valid needle
hasty tundra
valid needle
#

didnt really think about that actually. this was just what i originally had in mind. it works just fine now since i unchecked the kinematic option, so i got that working

steep rose
#

bear with me

valid needle
rich adder
#

you care about performance putting a rigidbody on a nevmesh agent is not performant at all (esp dynamic one since they're figting for control of position)..also wait till you spawn a bunch

hasty tundra
rocky canyon
#

anyway, for the rigidbody method to work like that
it needs to be a child of the navmeshagent.. (locking it in the x, y, z position [the local position])
now the rigidbody gets moved around b/c the navmesh is moving around..
then your detection logic would check against that rigidbody (the now child object) and not the actual navmesh agent

that said, Navarone's method is better for this.. if the only goal you have is to despawn them when they reach the end of the line
you could check distance.. once distance between you and the destination is low enough (you've made it -> despawn/destroy it)

valid needle
rocky canyon
#

no worries.. gotta learn somehow.

steep rose
rocky canyon
#

my favorite way is experimenting

valid needle
#

which is exactly what im doing at the minute. its honestly pretty fun to be completely honest 😅

hasty tundra
steep rose
hasty tundra
#

i have a way around the issue, but its brought up another issue in the way

hasty tundra
#

if i want to return something that isnt a simple value, what would i have to put as the identifier / where the underscores are?

rich adder
#

still confusing what you're asking tbh as I have no clue how this system supposed to work

rich adder
#

object ?

cosmic dagger
hasty tundra
#

Well T isnt working..... neither did object

rich adder
cosmic dagger
#

@hasty tundra it's hard to say anything else because we don't know what data you're trying to return or what you're actually doing (at the moment) . . .

cosmic dagger
hasty tundra
hasty tundra
rich adder
cosmic dagger
rich adder
#

but we still need to know more

cosmic dagger
#

CheckTower doesn't sound like it would returns smth . . .

rich adder
#

yeah confusing name for its current purpose

cosmic dagger
#

hmm, i guess it could, if it was a bool . . .

rocky canyon
#

yea i was about to say.. i have many CheckInstance() that returns bools

rich adder
#

I always prefer prefixing my bools with Is

rocky canyon
#
    private void CheckInstance(object instance,string instanceName)
    {
        if(instance == null)
            Dbug.Error($"Check{currentSector} - {instanceName} is missing! Unable to proceed.");
    }``` nvm im a liar.. its a void
rich adder
#

or has if Im checking for something although usually that returns an object with an out

cosmic dagger
#

i can see returning a bool with an out param, but i would prefix Is, Has, or Can . . .

hasty tundra
#

Thats the best explination i can give

cosmic dagger
#

i bet you i have a CheckSomething in my code base. i wouldn't be surprised . . .

rich adder
#

wait nvm nvm

#

what does that object returned

cosmic dagger
hasty tundra
rich adder
#

*methods not voids lol

hasty tundra
cosmic dagger
# hasty tundra

so upper is set to a skill from the Skills dictionary using the ManageSkillTree.WeaponDataType enum as a key, right?

#

but instead, you want to pass in an int, like in WeaponUpg and use that as the key? is this correct?

hasty tundra
#

basicly yeah, but dont worry anymore, ive found a workaround that works just as well 👍

cosmic dagger
#

an enum is just readable ints. you can cast them to their integer equivalent . . .

ember tangle
#

Is this the best way to declare a singleton using monobehaviour? Is there a better way? ```public class Foo : MonoBehaviour
{
public static Foo instance { get; set; }

private void Awake()
{
    if (instance != null && instance != this)
    {
        Destroy(instance);
    }
    else
    {
        instance = this;
    }
}

}```

slender nymph
#

I personally prefer this way, then you just inherit it like Foo : SingletonBehaviour<Foo> and it has all the setup (and even lazy-loads if you want that behavior), and other objects cannot modify the Instance property

tribal pendant
#

is there a way to do a "planecast" in 3d unity?

slender nymph
#

depends on your definition of a planecast

tribal pendant
#

like a 2d plane

rich adder
tribal pendant
#

yeah but from what i've seen boxcast doesn't ask forr all of the measuments in the 3 directions

rich adder
#

3 directions ?

#

wdym

tribal pendant
#

it asks for the center of the box and the half extents

slender nymph
#

yes, and?

tribal pendant
#

it doens't ask for the depth longness or wideness

slender nymph
#

what do you think the half extents are?

rich adder
#

make a new vector3 with half the measurements

tribal pendant
#

oh wait i'm stupid, i tought it was just a float for half extend and not a vector3

#

so sorry

rich adder
tribal pendant
#

thanks

#

it's 4 am here and i'm starting to feel it

#

should go to bed

rich adder
#

learned the hardway never good idea to code tired

vestal adder
#

im trying out the new input system and the docs say to do " moveAction = InputSystem.actions.FindAction("Move"); " however there is no definition for actions in InputSystem

vestal adder
#

thanks i diddnt think there would be one for that in particular

rich adder
#

yeah cause its so complex 😅

#

at first.. they have like 3-4 different ways to get inputs

#

I would suggest just using the Player Input asset

#

then the OnMove for example from your Move action

vestal adder
#

i am used to the original input method but id like my game to be on lots of platforms

#

the player input asset?

vestal adder
#

i dont know about it

rich adder
#

all you do is plop that component on your gameobject

#

use a script to use any of the messages displayed at bottom

#

so if you have a Move action, this componnet automatically calls OnMove method in your script when move keys are pressed

vestal adder
#

nice

#

okay that sounds good thanks ill look into it

rich adder
#

yeah Imo much easier than using weird strings n shit

sturdy forum
#

how would I attach an inventory ui to the front face of a simple 3d object like say a cube or to something a bit trickier like the screen of a tablet and be able to bring it out or put it away at the press of a key or button like say tab on a keyboard or circle on a playstation controller

rich adder
glad wagon
#

I tried to use a weakpoint Layer in the collider but is not working

glad wagon
versed light
#

i have this code in my editor script:

        private void OnSceneGUI()
        {
            Debug.Log(Event.current.type);
            if(Event.current.type != EventType.Repaint)
                return;

            var asset = target as AreaBlueprint;
            DrawUtility.Draw(asset.Perimeter, Color.white, 5);
        }

but i never get any logs, when does this actually get called?

rich adder
glad wagon
rich adder
glad wagon
#

yes

rich adder
#

use a script that references the shootOrigin and do something like shootOrigin.transform.LookAt(target.collider.bounds.center)
(you would need two rays, one that finds target while you point and another for the actual shoot

#

that should fix your shootpoint

versed light
#

does OnSceneGUI not work for scriptable objects? thats my only guess for why its not working atm

rich adder
#

OnSceneGUI is an editor only func

#

try using [ExecuteInEditMode] maybe

glad wagon
#

idk if the collider is using the layer correctly

#

I put include layer

#

but nothing changes

versed light
#

it doesnt seem to execute for them

#

maybe because SOs are not considered "in the scene" but then not sure how you draw gizmos to debug data in a SO

rich adder
versed light
rich adder
cursive seal
#

Anyone know why vsstudio isn't showing me unity stuff as auto complete

slender nymph
#

!ide

eternal falconBOT
velvet bolt
#

Is it common/will work to put multiple short scripts on one player? Like "playerMovement" and "playerCollisions"? Or will that cause issues?

rich adder
#

and most cases ideal to do so, split different purposes into seperate script

velvet bolt
# rich adder why would it cause issues

I was thinking maybe calling start and update 2 times on the same object might cause issues. No real reason to back up that thought but still was a thought, thanks for the clarity tho!

hallow iris
#

So I have a question regarding procedural generation so I want to make levels to be procedurally generated much like rouge like games but I don't know how to go about it like which algorithms to use the next problem is that I want to pass a list of premade rooms that can be placed randomly through and the those will be connected through corridors and lastly I want to define like a exact section for the spawn and the boss room are or alternatively I want a set numbers of rooms that must exist in between the boss and the spawn room

#

Any form of help is appreciated like videos or forums

sullen perch
#

how do i add a fire rate to my script? im kinda new and this is for a school project that is due tomorrow. Pls help

rich adder
sullen perch
#

cant find any

#

what does that meen?

#

mean

rich adder
sullen perch
#

... ok

#

im stoopid

#

can u send link?

rich adder
#

what kinda lazy bum question is that

sullen perch
#

im at school and the internet blocks stackoverflow, can you sent a screenshot?

golden obsidian
sullen perch
#

k thx

rich adder
sullen perch
#

i did look, im just new so i didnt realy understand it

glad wagon
# rich adder i have no idea what that does tbh thats new

I had to change from layer method to make the script get the collider directly from the enemy game object. The problem is that it’s only identifying the first collider, and no matter what I do it don’t recognize the second

crisp stump
#

!ide

eternal falconBOT
fierce shuttle
# velvet bolt I was thinking maybe calling start and update 2 times on the same object might c...

Having lots of Updates can affect framerate, but it heavily depends on what those Update calls are doing, and Start may only cause conflicts with race conditions in your logic, since the order of Start is not predictable, you may not be able to have code in your collision script for example reference something in your movement script, if your movement script also needs to initialize the thing your collision script wants to reference that early - though Game Objects in Unity are entirely designed to have multiple scripts on them working independently, so as long as you handle your logic and understand the execution order of scripts, you should be fine - another option I usually do, is have scripts use a System.Serializable attribute and not inherit anything, then 1 MonoBehaviour can call a "OnUpdate" (or however youd prefer to name your functions), this way 1 Update can run the logic for multiple scripts

fierce shuttle
# sullen perch im at school and the internet blocks stackoverflow, can you sent a screenshot?

This sounds like a strange oversight on your schools part, im guessing this assignment is code related to your course, so its odd your school would block a code related website - although StackOverflow is not the only place to find examples, theres also the Unity Forums and many other blogs online, and the official Unity Docs which do have examples on using coroutines as its part of their API

eternal needle
fierce shuttle
#

Owow, I guess my highschool had it light, only the explicit NSFW sites and gaming sites like miniclip were banned

rich adder
#

show code

nimble apex
#

even if u can do the work, if its not taught by school , 0 mark

glad wagon
#

tbh idk what order he is considering

#

but in this case he is considering the bottom collider

#

(the bottom in the game, the first in the inspector)

#

ok, I kind of figured it out

#

he is using collider index to list the number of colliders in the game object

rich adder
gleaming forge
#

Hi. I'm trying to write a function to add to a Button.clickable.clicked and pass in a variable. This is in the Awake() of a script attached to a UI uxml
When I pass an arguement in I get "Cannot implicitly convert type 'void' to 'System.Action'"

playerTabButton0 = rootElement.Q<Button>("player0Tab");
playerTabButton0.clickable.clicked += showPlayerProperties(0);

private void showPlayerProperties0(int playerId)
{
    GameStateScript GameState = board.GetComponent<GameStateScript>();
    GameObject player = GameState.playerList[playerId];
}

How can I pass an argument into this function?

hollow sedge
#

Hello I was having a lighting issue where when I switch from my main menu scene to my game scene the lighting bakes itself and everything goes really dark is anyone able to help me out with this, I dont really know what I am doing.

ivory bobcat
eternal needle
#

if the button used an int, it would pass it as a parameter already

eternal needle
#

otherwise you can use the lambda syntax like
playerTabButton0.clickable.clicked += () => showPlayerProperties(0);

gleaming forge
eternal needle
gleaming forge
#

I've now got this problem. I have 4 buttons that each call the function with different player ids. When I click button 1 it prints 4 times with the id of each button

        playerTabButton0 = rootElement.Q<Button>("player0Tab");
        playerTabButton0.clickable.clicked += () => showPlayerProperties(0);
        playerTabButton1 = rootElement.Q<Button>("player0Tab");
        playerTabButton1.clickable.clicked += () => showPlayerProperties(1);
        playerTabButton2 = rootElement.Q<Button>("player0Tab");
        playerTabButton2.clickable.clicked += () => showPlayerProperties(2);
        playerTabButton3 = rootElement.Q<Button>("player0Tab");
        playerTabButton3.clickable.clicked += () => showPlayerProperties(3);
    }

    private void showPlayerProperties(int playerId)
    {
        print(playerId);
    }

When I click any of the other 3 buttons it doesnt print anything

#

Duh

#

Its querying only the first button

hallow iris
#

So I have a question regarding procedural generation so I want to make levels to be procedurally generated much like rouge like games but I don't know how to go about it like which algorithms to use the next problem is that I want to pass a list of premade rooms that can be placed randomly through and the those will be connected through corridors and lastly I want to define like a exact section for the spawn and the boss room are or alternatively I want a set numbers of rooms that must exist in between the boss and the spawn room

languid spire
hallow iris
languid spire
#

Everything uses algorithms, proc gen is generally based on one of the common maze algorithms unless you design your own

hallow iris
woven crater
#

why this is an editor script????

north kiln
#

Presumably it's in a folder called Editor, or it's under an Assembly Definition marked as Editor-only

#

But looking again your class is generic, you can't add generic classes directly to GameObjects; the error is just confusing if that's what's causing it

woven crater
#

anyway to work around?

#

i want to make a generic pool for scriptobject

timber tide
#

otherwise start digging into serialize references

woven crater
#

i see

queen adder
burnt vapor
#

Does it call the method at all?

queen adder
#

mine's pretty the same

#

except public

burnt vapor
#

Does it call the method at all?

queen adder
#

I had an old method ipreposscess thing that workdd in 2017, howecer that was deprecated and unity told me to use this instead

burnt vapor
#

Does it call the method at all? peepo_sleep

queen adder
#

i wouldnt ask if it is

burnt vapor
#

So the issue is that it's not destroying anything?

queen adder
#

yea

burnt vapor
#

Can you put a break point in the loop and see if there is anything even being destroyed?

#

And if so, what does it think it is?

queen adder
#

there's not even a log as well

#

it's 2022 if that matters anyway

burnt vapor
#

Also, verify it's actually not called by doing something that actually changes something visually

queen adder
#

lemme see, that would be dumb to set true by default

burnt vapor
#

Logs might get cleared

queen adder
#

so that's what killing the logs, dont make sense to defineit true by default

burnt vapor
#

It's probably there for a reason

queen adder
#

let me see if it actually destroys the things

burnt vapor
#

For now I'd check if it calls the method at all

queen adder
#

I see.. it is only being called once, only deleting active objects on my main menu, instead of each scene 🤮

faint lark
#

@wheat wave it doesnt require a parameter, this is the whole code

wheat wave
#

@faint lark why are you even using ToArray in the first place? it seems that r_33_list is already a list<int>, which the left side expects

faint lark
#

this code is from the guy that made this asset

#

its not mine

wheat wave
#

ok?

faint lark
#

i didnt write this code, i simply imported the package and i got these errors

wheat wave
#

removing the .ToArray and see if it works

wheat wave
faint lark
#

no

#

it seems that removing toarray removes the error

#

dunno if wuld brake its functionality

wheat wave
#

that's a question for the asset creator

faint lark
#

yeah i guess your right

teal viper
#

Either it's a very old code or a plain mistake in the code.

burnt vapor
#

You create a new collection which is accepted in the field/property. Unless you modify the list after this nothing will break that you caused

#

If that field/property is of a library then the author is the one who made the mistake considering they want you to pass a hard list type rather than a general interface

#

Nevermind, I would guess this is some tile based system and the point is to add/remove parts of the list. Regardless there should be an easier way to set this list.

safe sphinx
#

Can some one help me with codeing a weed growing system and planting

obsidian granite
#

those are pretty large systems

safe sphinx
obsidian granite
#

what specifically do you need help with?

safe sphinx
#

Just the whole thing

obsidian granite
#

well that doesn't give me much to work with, the only way i could help you with the "whole thing" is telling you exactly how you'd make a planting/weed growing system instruction by instruction

#

are you not sure on where to start?

safe sphinx
obsidian granite
#

all good

#

so describe all of the functionality you want out of this system

safe sphinx
#

But idk how to do that lol

obsidian granite
#

a seed bag that holds 10 seeds? are you making an inventory system?

#

because that's what it sounds like you're going to need

safe sphinx
obsidian granite
#

okay so you need help making an inventory then

#

my reccomendation would be create a scriptableobject of inventory items

#

and use whatever data structure you want to store

safe sphinx
#

Ok

sick storm
#

hi i am trying to make my bullets speed up when i press e and it is not working the bullets are prefabs and don't actually exist in the scene until i spawn them in from another script here is the code: https://gdl.space/oliruzegir.cpp

#

upon further inspection if i press e while the bullet has been spawned the code works

#

but i need it to work before it is spawned

formal sable
#

Why is there a delay when I press the LMB while running to make a hit? Can this be fixed?

I have unchecked "Has exit time" and the animation is broken
I tried to set the transition duration to 0.1, it didn't help... At the moment I was clicking on LMB, and as you can see, the animation is not working

languid spire
wintry quarry
#

The bullet script should get its speed from elsewhere, a script that always exists

#

A Singleton may be a good option for you

solar heron
#

Anyone got tips for me to get back into this game engine. i really wanna get back into this but i forgot scripting like everything. i used to code 2 years ago but took a massive break.

wintry quarry
#

Or just having the spawner set the speed

eternal falconBOT
#

:teacher: Unity Learn ↗

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

plain dagger
#

Quick question: If I want to make a group of functions globally accessible or accessible at my discretion without inheritance, is that when I should use an interface?

languid spire
wintry quarry
thorny basalt
plain dagger
#

Just a class that I can call from anywhere without messing with inheritance

I've been reading up on static classes since the first reply

thorny basalt
#

An interface is when you want to force classes to have a certain implementation. For example, ICloneable forces it to have the Clone function. That way you can have classes with certain implementations without establishing a relationship

plain dagger
#

Specifically I'm making an in-cutscene manager and I want to programmatically trigger events like "walk to location" or "trigger inputted dialogue box" using parameters

#

Then I realized it'd be useful for other situations that'll appear, and so I don't have to connect a bunch of scripts

thorny basalt
plain dagger
#

So I've heard

thorny basalt
#

It mostly comes to expanding your project though.

wintry quarry
wintry quarry
thorny basalt
#

Yeah. They can run into similar problems though

wintry quarry
#

"most people avoid singletons" is definitely not true lol. It's extremely popular, and useful.

plain dagger
#

I know that singletons have their haters at least

formal sable
wintry quarry
thorny basalt
#

Tells you why they are controversial

#

They are convenient but if used incorrectly can be devastating. Though if it is a simple project, you’ll be fine

zenith cypress
#

They aren't controversial, people just sometimes abuse them in weird ways.

wintry quarry
zenith cypress
#

Also depending on the api, you have no choice but to use singletons/static hell LUL (such as a lot of editor tooling)

languid spire
#

That article is frankly rubbish in a Unity context, for one thing it misses the point that a Singleton in Unity is serializable in the Editor and editable via the Inspector. Those are really the only reasons to use a Singleton over a static class

plain dagger
#

After a bit of reading, I think I might only need a static class over a singleton

#

I just need some simple implementation of functions, and I don't really want the script coupling

#

I will probably need to learn singleton design pattern at some point though

thorny basalt
languid spire
#

but why would you, that is definitly the road to Singleton hell

thorny basalt
#

You can also have a singleton descend from monobehavior

thorny basalt
languid spire
#

That is hardly specific to the Singleton pattern, abstract classes and interfaces deal with that situation very nicely

thorny basalt
#

Well, if you want it to be globally accessible, but yes, you are correct

languid spire
#

Realistically, if Unity serialized and made editable static classes 99.99% of people here would never even have heard of the Singleton pattern. It is a solution of necessity not of choice

zenith cypress
#

I think Odin has a window for that LennyThink

cosmic dagger
#

instead of the ScriptableObject architecture for representing individual values/data, just create a Singleton architecture where each data type is its own singleton. then you can access any variable from an instance, anywhere, yay! 😆

ivory bobcat
plain dagger
#

Totally not me using multiple architectures erroneously

thorny basalt
#

The Yandev way

plain dagger
#

Kind of unfortunate that game. I had heard that he had actually gotten a lot better with criticism and fixing his code until all the stuff happened

thorny basalt
#

All games have a little but of spaghetti

#

Celeste has a 6000 line player script

plain dagger
#

My game will indeed have spaghetti

#

It's simply tradition

quick fractal
#

I'm aware this will sound like an incredibly stupid question but how do I get the correct local(?) rotation of a specific GameObject? localRotation isn't what I'm looking for since the GameObject I'm checking is the main parent.

My issue is that if I set another GameObjects rotation to the original, I'm seemingly either rotated relative to world space or incorrectly rotated. This is all I'm doing for it.

public void Teleport (GameObject target); // Custom function to teleport the player
{
    Player.gameObject.transform.position = target.transform.position + target.transform.forward * 0.3f;
    Player.gameObject.transform.rotation = target.transform.rotation; 
}```
#

It's anything from perfect rotation to 180 degrees off, the position works just fine.

languid spire
#

wdym checking?
Also why not just

Player.gameObject.transform.forward = target.transform.forward; 
sullen zealot
#

Hello! How could i extract from a json file an array of classes
This is the json file:

{
  "Aaliyah Gray": {
    "pfpImageIndex": 10,
    "score": 7450
  },
  "Aaron Price": {
    "pfpImageIndex": 8,
    "score": 8175
  },
  "Abigail Baker": {
    "pfpImageIndex": 3,
    "score": 9600
  },
  "Adam Barnes": {
    "pfpImageIndex": 1,
    "score": 8125
  }
}

and this is the script:

using System.Collections;
using System.Linq;
using UnityEngine;

[System.Serializable]
public class User
{
    public int pfpImageIndex, score;
}
public class DataSaver : MonoBehaviour
{
    public void LoadLeaderboardsDataFirebase(string jsonData)
    {

        if (jsonData == null)
        {
            Debug.Log($"No data found");
            return;
        }
        User[] users = JsonUtility.FromJson<User>(jsonData)); // ik its wrong but how can i make it work
    }
}
languid spire
#

you would need another class that contained a User array and serialize/deserialize that class

quick fractal
brave compass
languid spire
brave compass
#

transform.rotation is always the correct world rotation. Setting it to another transform's rotation will always set it to exactly the same.

quick fractal
#

position + forward * -0.3

languid spire
#

so why mention it? My code is setting the rotation by setting the forward direction of player to target

quick fractal
#

because I just copied it from the code directly

#

I don't feel like that's a big deal lol

brave compass
#

You misunderstood Steve's suggestion as something related to the position, because it also uses transform.forward, but he was suggesting as an alternative to setting the rotation

#

Because setting transform.forward will change the transform's rotation.

wintry quarry
quick fractal
brave compass
quick fractal
#

Ah that makes sense, I'll try a combo of layouts, I'm just thinking about what would and wouldn't break with Player.gameObject.transform.forward = target.transform.forward * -0.3f

thorny basalt
echo ruin
#
    private void Update()
    {
        playerDetected = Physics2D.OverlapBox(doorPos.position, new Vector2(width, height), 0, whatIsPlayer);

        if (playerDetected == true)
        {
            Debug.Log("Space Passed.");
            if (Input.GetKey(KeyCode.Space))
            {
                Debug.Log("Key pressed.");
                GameObject player = GameObject.Find("Poppy");
if (player != null)
                {
                    Transform player_transform = player.GetComponent<Transform>();
    if (player_transform != null)
                    {

                        animator.Play("SceneFadeStart");
                        StartCoroutine(Wait());
                        player_transform.position = new Vector3(3.5f, 26, 3);
                        
                        
                    }
                }
            }
        }
    }

    IEnumerator Wait()
    {
        yield return new WaitForSeconds(1f);
    }```
I'm trying to make a screen fade before the player moves location. However, the player moves instantly just as the fade start. I can't seem to get the Wait() method to work. What am I doing wrong?
quick fractal
steep rose
languid spire
halcyon geyser
thorny basalt
brave compass
echo ruin
#

I will try that. Thanks for the help!

thorny basalt
brave compass
quick fractal
#

That seems like it would provide the best of both sides together

#

If that's hugely wrong I promise I'm not intentionally ignoring/disregarding any info, vectors just confuse me 😄

brave compass
#

I don't think it will fix your problem, because there's fundamentally nothing wrong with setting transform.rotation to match another transform's rotation. If it's not giving you the rotation you expect, then that means one of the axes do not match what you expect.

brave compass
#

Is target an empty transform? Are you placing it manually in the editor and rotating it, using just the transform arrows as reference?

safe sphinx
#

Hi I’m thinking on taking a course or trying to learn c# dose anybody have any suggestions

quick fractal
#

That shouldn't be able to change, which is why I'm really curious why it's giving me a weird behaviour

cosmic dagger
brave compass
#

If you look at both transforms in the scene view after the teleport, with Local handle rotation set, are you seeing the transform's arrows not matching?

queen adder
#

what is the savesystem used by the cinemachine called? The one that retains changes from runtime

thorny basalt
cosmic dagger
#

nah, they're talking about how cinemachine has a toggle to keep/persists your changes after play mode exits . . .

thorny basalt
#

Oh

cosmic dagger
#

i was just looking at it, but now i'm completely blanking . . .

thorny basalt
#

Then no, that isn’t player prefs lol

cosmic dagger
cosmic dagger
#

yeah, it's pretty dope . . .

final pelican
#

I don't get why my player won't move in any direction. It was working before, I didn't touch the code but when I go back to it, the player won't move again.

rich adder
#

at minimum show code, also screenshot console window clearly visible during playmode

fluid kiln
#

hi guys! working on a dialogue manager script and i was thinking, should i force code every "peculiar dialogue" in the game? as each dialogue will be weird in its won way, some having camera movements, screen fades and such.

rich adder
rich adder
final pelican
#

Right

rich adder
#

Im not seeing any debug logs in your scripts, that should be your first step

#

find out which script is running and which one isn't, debug some values like bools you have or any input floats

final pelican
#

It's in the PlayerMovement script. It's not picking up if the player is moving or not or displaying their destination

rich adder
final pelican
rich adder
#

start using logs

rich adder
fluid kiln
final pelican
rich adder
final pelican
#

Ok

rich adder
fluid kiln
spiral oak
flat gale
#

I have an object that whenever I start the scene my objects moves from where Inset the transform but I have no code or anything moving it, is there a way to fix this?

spiral oak
strong mica
#

Guys I need some help, I'm working on a timer UI and here is the code I wrote for the UI.

#

The code is fine but the UI is shaking when the millisecond updating

rocky canyon
#

should format it to only show soo many decimals..

#

and when those are 0, fill em in with 00

#

22.00
22.01
22.11 etc

#

and using a monospaced font helps

short hazel
#

They're doing it with the string.Format. So yep it's probably the non-monospace font

rocky canyon
#

yup, cant beat a good monospaced font where everything stays in line

strong mica
#

Any hint to limit the decimals to ms?

#

like make it starts from 00 instead 0

short hazel
#

There are no decimals, milliseconds is an int

#

And it will already use at least 2 characters due to the :00 format specifier

rocky canyon
#

if all thats true then the twitching probably is because for example 01 is shorter than 00 soo ur seeing a flicker.. use a monospaced font

tender stag
#

im trying to limit the speed of my player by adding an opposite force once he reaches the move speed

#

but it isnt working correctly

#

any better way of doing this?

#

maybe use drag

strong mica
rocky canyon
tender stag
#

i cant set the velocity

#

i need it to be fully physics controlled

#

i cant directly manipulate the velocity

rocky canyon
#

ohh <insert more math then>

#
   void ApplyForceWithLimiter()
    {
        float currentSpeed = rb.velocity.magnitude;
        if (currentSpeed < maxSpeed)
        {
            float speedDifference = maxSpeed - currentSpeed;
            float adjustedForce = forceAmount * (speedDifference / maxSpeed);

            rb.AddForce(transform.forward * adjustedForce, ForceMode.Impulse);
        }
    }``` something like this then perhaps
tender stag
#

i need to limit speed but also allow force being added, so i want to suddenly add a lot of force to push player to the side

#

then the speed limit wouldnt stop that force

rocky canyon
#

my code above wouldn't stop any force just scale it the closer to the max speed the objects moving..
soo forces would work as normal unless ur already at or close tomaxSpeed

final pelican
tender stag
tender stag
rich adder
tender stag
#

in my ApplyMovement i want to have an acceleration variable which is just how fast the player will build up speed

#

and in my CounterMovement i need to somehow limit the velocity to moveSpeed

#

whilst still allowing other forces to act on my player letting him to go beyond moveSpeed

#

as it was on the video u sent

lunar kelp
#

why cant i rename these materials?

short hazel
lunar kelp
#

oh ok

rocky canyon
# tender stag

https://paste.myst.rs/pirsidze something like this should work

  • first deal w/ movement directly from input
  • predict/project if the rigidbody will exceed speedLimit
  • scale if it does (so movement wont exceed it)
  • now anything else we can exceed that limit (only applies to input movement)
shell sorrel
silent valley
#

Hey, I'm trying to get a tree to spawn after i place down a sapling. for some reason. it always spawns so close to the mindelay. Even if i set the max to 100 and the min to 1. it'll always spawn around 1-1.5 seconds

wintry quarry
#

You need to change it in the inspector, changing it in the code won't do anything once it's serialized on your script.

#

wait also - you're starting the coroutine every single frame 😱

#

so basically what's happening here is every frame you're starting a random delay and then whichever one finishes first will succeed

#

and then the script is destroyed.

#

You should only start the coroutine once. For example do it in Start, or do it in response to something happening in the game.

#

Update runs every single frame.

silent valley
#

you are absolutely right. fml. Give me a sec

#

it works. just need to edit my code slightly to work with my system. Thank you

bold swallow
#
switch (true)
        {
            case (popualtion > 0 && popualtion < 20000):
                sr.color = colors[0];
                break;
            case popualtion < 50000:
                sr.color = colors[1];
                break;
            default:
                sr.color = colors[0];
                break;
        }

Is this not possible in C#?. I am getting an error "error CS0150: A constant value is expected"

#

on the lines with the "case"

bold swallow
#

looks weird but I think it should work, thanks!

weak cedar
#

which one would allocate more memory - a int[2] or a class with 2 ints

wintry quarry
short hazel
#

Prefer a struct with two ints if you want no allocations

thorny basalt
wintry quarry
#

which is almost certainly a class or a struct over an array, if the two numbers have different significances

autumn granite
#

can someone help me with what this means? i just followed a tutorial to do this, it was working perfectly the other day but i came back to check it again and now im getting this error

eternal needle
autumn granite
slender nymph
#

i also hope you realize that this guide just takes you through exactly what that last sentence of the error message is

#

nobody is "treating you like an idiot". but when you fail to read what is literally on your screen, it will be pointed out that the answer is literally on your screen

eternal needle
#

The regret must've kicked in fast for them after typing that.

frank flare
#

What's actually wrong with it? I tried messing a lot with that problem and there's literally 0 fix. I want the wheelchair face to be rotated to player but it does weird stuff instead of rotating exactly like LookAt (which works but I don't need that solution because it noclips)

Quaternion wantedRotation = Quaternion.LookRotation((Player.position - transform.position).normalized); // * 6f;
        Quaternion deltaRotation = Quaternion.FromToRotation(wantedRotation.eulerAngles, Player.position);
        Debug.Log(deltaRotation.eulerAngles);
        GetComponent<Rigidbody>().angularVelocity = deltaRotation.eulerAngles;

I have no clue what is quaterion and how it translates and no clue how to fix that problem and debug it

I tried tons of different solutions

daring depot
#

So what programming languages does unity support?

frank flare
#

you make scripts on it in C#

daring depot
#

😡

slender nymph
#

there are beginner courses to learn c# in the pins if you want to get started learning. otherwise, there's the infinitely inferior #763499475641172029 or you can use a different engine that supports your language of choice

daring depot
#

no visual scripting

#

i will have to learn c#

#

unreal engine doesn't support many languages either

#

nor does goDot

#

and the other engines aren't as powerful

frank flare
thorny basalt
daring depot
#

I need to expand my skill anyway because I can't cruise through life with lua and python

thorny basalt
daring depot
frank flare
slender nymph
daring depot
#

C# is industry standard anyway

thorny basalt
thorny basalt
daring depot
#

so what's private and public in C#

frank flare
daring depot
#

does unity have modules?

#

can I use modules that i can import/require

#

to organise my classes, utils, etc

short hazel
#

C# uses namespaces yes

frank flare
slender nymph
daring depot
#

so unity has a player instance

frank flare
daring depot
#

ohh

#

so we construct our own game object

#

so we make our own player instance

#

ah i see this makes sense

#

roblox hands everything to us, unity doesn't this is cool

#

gives a lot more freedom

daring depot
frank flare
daring depot
#

😭

#

alright

frank flare
eternal needle
daring depot
daring depot
#

does unity provide databases

frank flare
daring depot
slender nymph
daring depot
#

okay okay

frank flare
daring depot
#

brother

short hazel
#

Well there is, it's called your filesystem

daring depot
#

i can still host my own servers for roblox games