#πŸ’»β”ƒcode-beginner

1 messages Β· Page 696 of 1

frigid lark
#

welp

#

thanks lol

silk night
#

also look for gizmos πŸ˜„

#

they can help a lot

frigid lark
#

yeah docs have been kind of helpful but my adhd brain cant handle the big words lol

#

blueprints in ue5 are life changing

silk night
#

you can use bolt in unity

rough granite
silk night
#

yeah i guess

rough granite
frigid lark
#

honestly its probably best I learn c# and c++ respectively, looks good on the resume

#

or CV whatever people call it

silk night
mortal sky
#

Question, how would you programmers do a non-hardcoded inventory system?
For example, not having a enum of all items that exist (So you don't have to modify it every time).

I've been trying to use ScriptableObjects, which have been pretty useful all things considered, but I'm wondering if the use of C# interfaces would be useful in this situation as well - in addition to the use of ScriptableObjects. This is due to the fact that they would help with customizeable behavior and instance data.

silk night
#

yeah define each item as a scriptable object as base item definitions and everything else that is mutable like amount or any item attributes in extra properties of your item class

#

also give each item a unique identifier, might be auto generated uuid or your own string

mortal sky
mortal sky
silk night
#

you create a scriptable object for each item that holds data like icon, name, price, weight, whatever you need as base data for an item, also add a unique ID to that set of settings

then you can create a class "Item"
that can hold data like amount for example that can change during gameplay and the ID of the item so you know which scriptable object to access for your base item data

that item can then be used to represenent a slot in an inventory, to drop an item or whatever to pull the info from it

rough granite
#

not sure i would do exactly as terraria since their ID is the number order of implementation and i could get easy to lose track of the number you are on if you add a lot

mortal sky
silk night
mortal sky
#

My intuition is no.

wooden hill
# mortal sky Question, how would you programmers do a non-hardcoded inventory system? For exa...

i once did it (copying the idea from another...) with a .tsv file πŸ˜‚ but it's a bit rough...
SOs are good because you can easily combine all data there (unique id, icon, name, enum for like type maybe)
and don't have to rely on finding for example the icon in the files via Resource or having a List or whatever...

otherwise could also do something like
BaseItem -> Weapon -> Melee
BaseItem -> Weapon -> Ranged
BaseItem -> Clothing -> Armor or Cosmetics
For the generic c# class and/or the SOs to make it more specific and have special values

silk night
silk night
#

or you even have an itemmanager and only pull item data from there instead of saving the reference to the whole item in a monobehaviour

rich scroll
rough granite
mortal sky
cosmic dagger
silk night
mortal sky
silk night
#

but theres a lot of different architectures you can use for that, no solution is more right than another πŸ˜„

cosmic dagger
mortal sky
#

I do not question that, for sure.
I'm just in the pursuit of one that is good enough that doesn't make me regret it on the future.

silk night
#

and I think item systems are rather easy to find a written or video guide for, look through some and pick an approach you like

silk night
mortal sky
#

That does give me a sign of relief.

cosmic dagger
mortal sky
#

Hm. A dictionary created during runtime does sound like a good idea, I will take note of that.

silk night
#

^ that only works if your only mutable data is the amount though, if you have other parameters on your items like durability remaining for example you need a more complex approach (like a class holding more data)

ripe shard
grand snow
#

As long as you have a unique id for items that can be used both ends you will be good

cosmic dagger
#

Yes, this is for a simple item inventory. If you can have different versions of the same item, then you need a more complex approach . . .

mortal sky
ripe shard
#

an inventory is really just a container for meta-data associated with an instance of an identity token.

mortal sky
grand snow
#

not wrong, its any data that you need to store about some item (e.g. quantity, extra meta data)

#

it does help if you have many item types to seperate them out
e.g. weapon data, food data

cosmic dagger
#

For two of the same item with different stats, I just use a C# Item class holding a reference to the item ID, along with Rarity, ItemAttribute[] (stats) and other fields that are mutable to the specific instance . . .

frigid lark
#

ok im tryihng to implement this

#

my brain hurts

keen fiber
#

Is there a better way to do this? Kinda feel like this could get out of hand the more I add

#

And it's not great for having other weapons

teal viper
#

It sounds like half of them are redundant

keen fiber
#

If i dont do that then they just override each other

vestal cloud
#

What application do you use to open C# script...??

eternal falconBOT
wooden hill
#

one of these (click the links to get a guide)

vestal cloud
vestal cloud
#

what should i do..??

wooden hill
vestal cloud
#

like this box from vscode

rich adder
#

thats not vscode

vestal cloud
rich adder
#

thats visual studio

wooden hill
#

Yea it's not but vscode does have it too

rich adder
#

if they did it in VSC and did not appear, its probably not configured

wooden hill
#

did you set up your vscode according to the links?

#

!code

eternal falconBOT
wooden hill
#

i meant !ide

eternal falconBOT
wooden hill
#

click the VSCode link if you use that @vestal cloud

rich adder
vestal cloud
#

is this correct..?

rich adder
#

the steps tell u it is lol

vestal cloud
#

oh it's working now.. thanks.

#

it requires .net from microsoft

rich adder
#

yes vsc has weird issue where it doesnt install the required .net sdk 98% of the time

vestal cloud
wooden hill
#

worked on my machine β„’ (lucky)

vestal cloud
vestal cloud
wooden hill
vestal cloud
wooden hill
#

which tutorial?

vestal cloud
wooden hill
#

unity has !learn

eternal falconBOT
#

:teacher: Unity Learn β†—

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

vestal cloud
wooden hill
rich adder
#

yeah you should start with the basics before anything

rough granite
rough granite
wooden hill
rough granite
#

fair

#

not sure if working on 3 different game types at the same time is helping or not

frigid lark
#

how do i make a raycast not hit the raycaster

wooden hill
rough granite
wooden hill
frigid lark
#

ohhh

#

good idea

#

thanks

wooden hill
#

otherwise you could do a line cast and sort out the one's you don't want πŸ˜„

#

or i guess make the cast come just at the outside of your collider

rough granite
#

is there a place here for npc 2d ai?

wooden hill
#

coding i guess

#

(just use the free astar package)

rough granite
wooden hill
#

he has a pro version too... anyway a* (astar)

rough granite
#

i should say im using navmesh paired with a 2d asset port for it but they kinda stupid and just chase me

wooden hill
#

navmesh is 3d though? notlikethis

rough granite
rough granite
wooden hill
#

oh it's an asset u bought

#

never heard of that

rough granite
wooden hill
#

interesting...

#

why not A*? πŸ˜›

rough granite
#

does A* need a baked map?

wooden hill
frigid lark
#

the layermask isnt working

rough granite
frigid lark
#

why does life hate me

#

lol

wooden hill
frigid lark
#

yes lol

wooden hill
rough granite
rough granite
wooden hill
# frigid lark yes lol

then you figure out what's not working and then why... add debug logs as many as you need

frigid lark
#

its hitting the player :/

wooden hill
#

oh you said ages ago thats why

rough granite
#

said ages ago cause 8 months is ages for me :?

frigid lark
#

RaycastHit2D hit = Physics2D.Raycast(transform.position, _moveDir * 2.5f, whatIsMoveable);

#

this is it right?

wooden hill
frigid lark
#

whatIsMoveable is the layermask

rough granite
wooden hill
#

layermask = what should be included in the cast

wooden hill
frigid lark
#

ok give me a sec

wooden hill
#

that's like saying this variable named xhaba3729 is the layermask

frigid lark
#

just tryna make sure ive structured it properly

wooden hill
#

i have no clue where you set it

frigid lark
#

ive checked the docs and that what it says

wooden hill
#

you could as i said debug log everything including the layermask before that call

#

but probably you made it public and set in inspector?

frigid lark
#

yeah

wooden hill
#

or you use github issues

rough granite
wooden hill
#

we can't fix stupid 😦

#

what should they do

rough granite
#

idk 😭

#

just not that cause this is just easy to dodge

wooden hill
#

they're shooting or not

rough granite
#

they are

wooden hill
#

hmm yea then you'll have to play around with their ai

#

idk how you set their position

rough granite
wooden hill
#

but maybe take playerpos+ velocity into account instead of just playerpos

wooden hill
rough granite
#

:o didn't even think of that

wooden hill
#

now is your creative time

rough granite
#

how would i go about adding the velocity?

wooden hill
rough granite
#

how would i even get the velocity?

wooden hill
#

from the players rigidbody or whatever you use to move it

#

for a simple kamikaze enemy
you can take the player velocity as a vector then guesstimate where it can hit the player with it's speed

#

simple trigonometry (probably)

frigid lark
#

im tryna use debug.drawray but it doesnt work bruh

#

nvm

#

i needed to enable gizmos

rough granite
rough granite
wooden hill
#

yea you can

rough granite
#

this actually worked they got annoying

wooden hill
#

just added the velocity on top of position?

rough granite
frigid lark
#

are there seriously no voice channels

wooden hill
#

maybe even more annoying if you multiply velocity by random(1,10) and then add it

sour fulcrum
frigid lark
#

yeah it just helps a lot lol

wooden hill
#

you could even calculate the exact position where the enemy is able to collide with the player based on player's current velocity, enemy's max speed and both their positions...

frigid lark
#

ok can someone help me i cant upload videos and i cbf taking 20 screenshots? we'd have to take it to dms

rough granite
wooden hill
#

well more or less dunno about physics holding up exactly

wooden hill
#

to code it (idk if it's fun to play against)

rough granite
wooden hill
#

almost at the bullet hell

wooden hill
eternal falconBOT
rough granite
#

though im curious a really annoying thing is getting nocked back from the bullets, do most bullet hells have nockback when you run into enemies?

#

cause it kinda just stuns you and you end up dead

wooden hill
#

not really

wooden hill
rough granite
wooden hill
rough granite
#

no?

wooden hill
#

try this first before redoing all that

rough granite
#

oh well it would've just been checking the is trigger tag on the 7 weapons

wooden hill
#

although I'm not sure it works like i think rn

rough granite
#

poof and im done

#

i think?

wooden hill
#

yeah probably better

rough granite
#

kinda they deal damage but dont explode :/

faint agate
#

Hello on awake im adding listener to buttons. I would like to add 4 second to delay before action happens to all of them without having to create multiple coroutines.

wooden hill
frigid lark
wooden hill
rough granite
# faint agate

where would you like the delay? also use async / await its easier

wooden hill
#

or ctrl+click on the raycast method (idk if that's how you go to the method definition)

faint agate
wooden hill
frigid lark
#

sorry. thanks

wooden hill
rough granite
frigid lark
teal viper
#

Don't mess with the void. If you look into the void, the void will look at you.

teal viper
#

Point is, you can't use the word "void" in that context. It just means lack of return type.

wooden hill
#

isn't that blocking whole unity for 4 seconds though?

rough granite
#

at least i dont think so i use it quite a bit and my game doesnt freeze till it's done

wooden hill
#

alright thx

rough granite
#

yeah what i thought it's like putting it off to the side till it's delay is done

#

then it's called back to it

#

but if you had something after the SomethingToDo(); call it'll do that while waiting the 4 seconds

faint agate
rough granite
eternal falconBOT
wooden hill
#

but won't this be an issue when trying to access any unity stuff? since it's not on the mainthread anymore ... right?

wooden hill
# faint agate

you have to put your other calls inside a new method which you call using Invoke

sour fulcrum
rough granite
sour fulcrum
#

Nah

wooden hill
#

Nah?

rough granite
#

it aint jobs

sour fulcrum
#

Coroutines for one are fake async and never leave mainthread and async stuff is almost always thread safe(?) afaik?

rough granite
wooden hill
#

nah or afaik(?) which one?

sour fulcrum
#

Nah, afaik

wooden hill
#

... source?

sour fulcrum
#

i mean i can go google but as far as I know kinda puts myself as the source aha

wooden hill
sour fulcrum
#

that is my understanding

wooden hill
#

load data in background type

sour fulcrum
#

Sounds like they just need a single coroutine that takes in a time and a level value though, no?

rough granite
# wooden hill load data in background type

it doesn't work like jobs though it's all on the main thread it just tells the main thread to do something else (in the case of await Task.Delay(); ) until that delay is do then the main thread goes back to it

#

all it does is just pasue a task and go back to it later lol

wooden hill
#

i see

#

it works differently than i imagined

rough granite
#

did you read up on it :?

wooden hill
#

yea a little but probably not enough

rough granite
wooden hill
#

i mean if it's good

#

what i read also suggested a certain yt video

frigid sequoia
#

Hey, do I have an event call that I don't know of when changing the resolution?

#

Like I want a bunch of stuff to recalculate if the resoilution changes

eternal needle
frigid sequoia
#

I mean yeah, I could, but I don't want to be each frame checking if the resolution changed when the class doesn't even use an Update method

#

Seems like something that would come by default for stuff like the UI Layouts

eternal needle
eternal needle
terse silo
#

why do they work there?

#

like in the () of a method

#

are they one of those things that once you pick up and understand, you'll use it a lot?

eternal needle
frigid sequoia
timber tide
#

usually lambda is done just for shorthanding, but here there's quite a difference in creating a delegate (some function pointer) and doing it like this as you don't have the reference to cache if you want to unsubscribe the listener directly

eternal needle
bright zodiac
# rough granite it doesn't work like jobs though it's all on the main thread it just tells the m...

incorrect, async/await in c# will always be on threadPool thread, but the continuation can be(optionally) on any specific thread.
Note : Unity uses it's own singlethreaded custom SyncContext by default so the continuation will always be on mainthread (this does not apply to Task.Runor task factories).
if you're using plain c# (non unity), the continuation will be default to whatever last threadPool thread used

rough granite
bright zodiac
#

still your statement is terribly incorrect

rough granite
#

eh as i said I've just watched one video on the topic and read a bit Β―_(ツ)_/Β―

bright zodiac
#

aight cool

rough granite
#

Not like async / await has 2 threads running at the same time or freezing the whole mainthread until its done which is what i was getting at

bright zodiac
#

if it's blocking then it wouldn't be called async/await.. also they might not what you called thread here, those are threadPool thread in the case of async/await

terse silo
#

like what piece of code that is easier to read would do the same thing

#

what can i compare it to

eternal needle
#

the link i sent above has an example where they use it in the linq select method

int[] numbers = { 2, 3, 4, 5 };
var squaredNumbers = numbers.Select(x => x * x);
Console.WriteLine(string.Join(" ", squaredNumbers));
terse silo
#

okay ill try it out

#

oh interesting

#

im assuming x is just itself?

#

is it like a foreach statement condensed into 1 line?

eternal needle
#

its less about what the Select is doing here and more than you can pass in a method written in short form

terse silo
#

sick!

#

thanks for this, ive been meaning to get into lambda for a long ass time now

teal viper
ripe shard
fervent wind
#

I did better than yesterday! (past 2 days i only read at night time)
Today i read it early (4pm) and did more pages!
40/220 more to go~

#

I am still lazy but atleast its getting better πŸ’”

hexed nymph
#

Hello guys, I'm currently working on a online game and I created the online system using Photon 2, for now I created 3 scenes: the Character Selector that transits to the Create and Join rooms and then when you joined a room it transits to the Lobby (that I called WaitingRoom)
My ideia is choose your character that is saved on a Hashtable that I called "playerProperties" (the character named: playerProperties["prefab]") and then in the WaitingRoom asign the prefab's name to an already existing static class that has every prefab on it (for ex: PlayerStorage.P1Prefab, PlayerStorage.P2Prefab etc) but this doesn't work on the game. I have 4 spawn points (one for each player) and this spawns for example "PhotonNetwork.Instanciate(PlayerStorage.P1Prefab.name, etc...)" but the game does not spawn that so I think the problem is the WaitingRoom script
https://paste.mod.gg/hgdieealflvc/0

#

btw the P1Prefab and so on are GameObject variables

frail hawk
hexed nymph
#

ohhhh okok my bad

#

thanks!

wooden hill
hexed nymph
#

I don't think the problem is Photon but my code

#

but I'll try that eitherway

wooden hill
hexed nymph
#

ohhh! sorry I'll check that too πŸ˜…

waxen glacier
#

How can I stop my character from slipping off sharp edges ? I have a sphere at the bottom that checks for ground, and i've had to increase it's radius beacause when trying to jump on a cube i'd get stuck on the edge and not be able to move if I jumped on it perfectly. Now if I jump directly on the edge I instead slip off of it.

#

Also if I try to jump while being in contact with the cube's side it slows down my jump.

rough granite
waxen glacier
#

I think all I have to do to fix this is make it so if the character is grounded to manually set the vertical velocity to 0 so he doesnt slide off

#

but when typing rb.linearVelocity.y = 0 i get the following error : Cannot modify the return value of 'Rigidbody.linearVelocity' because it is not a variable

ivory bobcat
#

Linear velocity is a property and not a field (a method under the hood). The vector 3 returned from the property would be a value-copy and modifying it's y component is invalid.

#

Copy the vector, modify the copies y component and reassign the vector back to the property.

#
var velocity = rb.linearVelocity;
velocity.y = 0;
rb.linearVelocity = velocity;```
waxen glacier
#

works well thanks, I still have the problem with sliding off sharp edegs tho which probably means that I have to rethink my ground detection

#

It doesnt completely cover the bottom of the capsule which is probably the issue

#

Maybe I should use a cube to check instead of a sphere

terse saddle
tight fossil
#

How can I choose a random bool in a bool array that is false, ignroing any true booleans in it?

slender nymph
#

why do you need to choose one from an array if you just want false?

naive pawn
#

do you mean a random index

tight fossil
#

I have 10 bools that when each are true, all enable a different timer to a specific thing. A handful of these bools are activated at random whenever the player fails, until all are activated, to keep things interesting. I'm trying to make it so that when the player fails, 2 of these bools that aren't already true, become true, and have this recur with each subsequent failure.

rough granite
tight fossil
#

ah brilliant

#

thanks

silk night
rough granite
#

Just thought of the easiest way i would do it

naive pawn
#

it's not inherently bad but i think it's not great in this situation with potentially a small amount of options

rough granite
naive pawn
#

it may involve several retries, and it doesn't handle the case where there's only 1 or 0 options

rough granite
#

Maybe making a new array of only the false values then picking a random of those

naive pawn
#

might be better to just get all the false indices and choose from those

naive pawn
rough granite
#

Just different words

naive pawn
#

values and indices are separate things and you should consider the difference

rough granite
silk night
#
bool[] test = {true, true, false, true, true, false, false, false, true, false};
var allFalseIndexes = test.Select((e, i) => (e, i)).Where(e => e.Item1 == false).Select(e => e.Item2);
int choice = Random.Range(0, allFalseIndexes.Count);
test[choice] = true;
#

that should work

#

pseudo code as i dont have an IDE on hand πŸ˜„

naive pawn
naive pawn
tight fossil
#

i actually never left because i too saw that the loop might get stuck for a while ;v
I'll try and incorporate the pseudo code πŸ‘

eternal needle
#

You really dont need linq for this. Just loop through, store the index of all the false values.
Generate a random number between 0 and the length of this new array

silk night
naive pawn
#

extra garbage smh

eternal needle
#

I know what linq does. You dont need it there at all

#

Linq is not a replacement for a for loop

tight fossil
#

does Select require me to use a library of sorts? it says bool[] doesnt contain a definition for it

naive pawn
#

but yeah linq is overkill, doing the select just to get the index seems.. not great

naive pawn
eternal needle
#

Plus given the problem, (and what they said above) its pretty obvious linq is above their level

eternal needle
red igloo
#

I know im getting close to this but I wanted to ask how can I make it so when entering the green zone it adds the new camera which is a child of the new zone into the list. here is what I got so far. https://paste.ofcode.org/vr8d3PuXW77geiZ6xgsYWV

tight fossil
#

my first attempt i did try using a for loop, i just didnt know how to pick one of them at random AND ignore any that are already true

silk night
naive pawn
#
List<int> candidates = new(); // ideally a class member to avoid unnecessary garbage - if you do that, make sure to Clear the list as well

for (int i  0...yourBools.Length) {
  if yourBools[i] == false
    candidates.Add(i);
}

/* get random index from candidates */
```on mobile so skipping some stuff
red igloo
silk night
#

you already get the camera in the OnTriggerEnter function, now you just need to add it to your list property

tight fossil
wooden hill
eternal needle
naive pawn
tight fossil
#

its an int list i didnt see

naive pawn
wooden hill
#

it says zero allocation that's why i asked

#

tbh i really seldomly used linq so far

grand snow
#

sometimes linq is more convenient but most things can be done "by hand"

#

doing things like sorting to get the first/last thing however is always dumb and should not be done

silk night
#

yes that looks good

red igloo
silk night
ripe shard
silk night
wooden hill
silk night
naive pawn
silk night
#

I mean yeah, there are things that linq does which will always use allocs (which even zlinq does not prevent) πŸ˜„

ripe shard
#

To get linq to be zero allocation you loose the syntax niceness or need source generators

red igloo
ripe shard
#

basically you have to pass the context into the delegate through a structure to avoid the closure and branch execution on known, indexable collections

silk night
grand snow
# wooden hill don't quite understand what lazy evaluation means

When you do foreach(string id in collection.Select(x => x.id)), the IEnumerator essentially re-executes each "loop" to get the next thing (in this example, to get x.id)
This means that if collection is modified during the for each loop it will alter the results.

#

sometimes you need to do .ToList() or .ToArray() to evaluate it all at once

#

It kinda is, the end result of the enumeration is not fully "resolved"

red igloo
polar acorn
red igloo
#

when in the triggerzone its going to add a camera which is [1]

polar acorn
toxic cove
#

When I added a navmeshsurface to this and baked it it would set the walkable paths to the windows and other stuff and not the actually floor itself. I tried adding navmeshmodifiers and it still wouldnt do anything.

#

and yes I did re-bake it after adding the modifiers

timber tide
tight fossil
# naive pawn ```cs List<int> candidates = new(); // ideally a class member to avoid unnecessa...

I added this and it seems to be working, but then it starts messing up and i assume picking the same ones over and over, what do you think the problem is?

    {
        List<int> goodCameras = new List<int>();

        for (int i = 0; i < guy14MalfCameras.Length;i++)
        {
            if (guy14MalfCameras[i] == false)
            {
                goodCameras.Add(i);
            }
        }

        for(int i = 0; i < guy14CamerasToFUp; i++)
        {
            int r = Random.Range(0, goodCameras.Count);
            guy14MalfCameras[r] = true;
            goodCameras.Remove(r);
        }

        goodCameras.Clear();
    }```
naive pawn
#

Remove is by value, not by index

#

you want RemoveAt instead

#

also there's no reason to clear the list at the end there
you only need it if you cache the list instance like i mentioned

tight fossil
#

ah dammit, i even looked at it and went nah surely we're looking for the value 😭

#

yeah i added the .Clear at the end cuz i was getting desperate and thought maybe it was saving it somehow

naive pawn
#

i mean, i guess this can get confusing, since there's 2 layers of indices here lol

#

goodCameras's values are indices of guy14MalfCameras
r is an index of goodCameras

#

ah that's another issue

#

you're using r as an index into guy14MalfCameras as well

tight fossil
#

oh i thought i had to

slender nymph
#

you need to use goodCameras[r] as the index for guy14MalfCameras

tight fossil
#

so like this?

        {
            int r = Random.Range(0, goodCameras.Count);
            guy14MalfCameras[goodCameras[r]] = true;
            goodCameras.RemoveAt(r);
        }```
naive pawn
#

yeah sounds about right

#

though make sure to handle cases where guy14CamerasToFuckUp is more than goodCameras.Count

#

perhaps also add goodCameras.Count > 0 into the condition

tight fossil
#

oh whoops forgot to censor that

red igloo
#

How would I remove the camera that was added?

naive pawn
grand snow
#

Im not sure using tags to control this is a good idea πŸ€”

tight fossil
naive pawn
red igloo
#

here is the full script https://paste.ofcode.org/v9Bn34z6yq56jnTS6EHuvs . basically when I enter the green zone it adds the camera thats a child of the green zone into the list so I can use it and now when I enter the red zone I want to remove the camera that was added

ripe shard
naive pawn
grand snow
#

If it was me id have a trigger that just enabled a camera on entry and disabled it on exit and let the priority ensure its used when active.

#

but i get you have some other control to change cameras

#

(perhaps you can also use trigger enter/exit to add/remove the camera instead of 2 seperate ones?)

red igloo
red igloo
naive pawn
red igloo
naive pawn
#

so each part will only have 1 green and 1 red?

grand snow
# red igloo I am bit confused can you elaborate further?

Currently you are checking the tag of some other object your player enters which seems flimsy (tags are a bad idea for this)
It would be better if you had a script on some trigger collider that defines the area for some virtual camera to be usable. It can add its camera to the player on trigger enter, and remove on trigger exit.

naive pawn
#

just remove the last one added or remove the one at index 1, then

red igloo
hexed terrace
#

if anything, the way rob suggested is less hassle

#

on enter -> enable camera
on exit -> disable camera

grand snow
#

Its bad because its set up all jankily and is not easy to expand on in future
it presumes some tags are in use and some other component is a child to work.

red igloo
#

hmm, so wait I should have a separate script on the ontrigger colliders and what should be in the script?

grand snow
#

The script can have a serialized ref to the camera, it can use OnTriggerEnter + Exit to see if the object has the switch player script/player script. If so, add the camera or remove the camera.

red igloo
grand snow
#

Yes. instead of the player object doing it, the "camera trigger area" is doing that job instead

red igloo
waxen glacier
#

is there a way to assign a layer to only one face of a cube for example ? I only want the top face to have the "ground" layer so I dont run into issues where my ground detector collides with the sides and detects them.

grand snow
grand snow
waxen glacier
grand snow
#

because we expect a floor face to have a normal facing mostly upwards this should work

#

play around with the angle max though to suit your needs

waxen glacier
grand snow
waxen glacier
red igloo
grand snow
#

yea what you use to do the camera swapping functionality as I presume that is where you keep your list of usable cameras

#

I hope you can fill in that gap

red igloo
grand snow
#

nope

red igloo
grand snow
#

I have tried to explain the process a few times

#

If your "switch player camera" script is not on the player gameobject then instead you should have a serialized ref to that on this new trigger script

#

The process is still the same, when the player enters, add some camera. when the player leaves, remove some camera.

red igloo
#

Should it also have a reference to its own camera?

grand snow
#

how else can it add the camera?

red igloo
#

my bad lol just clarifying

grand snow
#

each instance has a ref to the camera it wants to add/remove

sharp needle
#

what .net version does unity support loading at runtime

#

if it even supports that

vestal cloud
#

What should i do....??

naive pawn
#

you can set input handling to input manager in your player settings (like the error mentions)

#

or you can use the new input system

vestal cloud
#

where.. is my player settings..?

naive pawn
#

it's in that same menu

#

there's also a search bar you can use

vestal cloud
#

oh it works now thank you!!

wooden hill
#

now that i think about it.. calling it "player" may be a bit confusing for newbies

vestal cloud
vestal cloud
#

finally my code works

vestal cloud
#

from the tutorial it was outdated... .

wooden hill
wooden hill
eternal falconBOT
#

:teacher: Unity Learn β†—

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

polar acorn
wooden hill
polar acorn
#

Yeah but there's not really a way to radically change the way input works going forward for the better without causing a ton of confusion

#

There's like, years of difficult-to-update video tutorial footage using Input.GetAxis and whatnot

wooden hill
#

True but why didn't they do it in unity 6.0 notlikethis

polar acorn
#

There's not really a clean way to un-teach people things, which is why most programs carry around their bad early decisions as an albatross for decades

wooden hill
#

Input.GetKey will always stay in my heart

red igloo
polar acorn
#

Like, what is the end result you're trying to achieve

red igloo
polar acorn
#

I didn't ask what Rob explained, I asked what you are trying to do

rough granite
polar acorn
red igloo
# polar acorn Like, what is the end result you're trying to achieve

Basically I have a cinemachine camera a child of the green zone when I enter the green zone it adds the camera into the list and then when I press R the camera changes to the new one and when I press it again it goes back to the main one. when I enter the red zone it removes the recently added camera. So this is going to be reuseable meaning I will be having more camera's/zones setup

#

I think rob was saying I should have a separate script attached to the collider and at that point whatever he said was confusing to me

polar acorn
rough granite
rough granite
red igloo
polar acorn
# red igloo yes you can optionally swap to

So, you'd put a script on the green box that has a reference to the camera it wants to add. When the player enters the trigger, it puts that camera in the list on the player that entered the trigger if it's not already there.

Likewise, the red box has a similar script that references the same camera, and removes it from the list of a player that has it if it's in there.

red igloo
polar acorn
#

instead of two different ones that both do something on enter and therefore have to check if the camera's already in the list

red igloo
polar acorn
#

They're both one sentence summaries of it, I don't think I did anything particularly different

#

I think you're just coming back to it after taking a few minutes off of thinking about it

naive pawn
rough granite
wooden hill
rough granite
#

No i know but why is it that I've only ever heard of unity chan here like never seen it in the app

naive pawn
#

a lot of things have mascots that are rarely used

#

nodejs has rocketturtle

wooden hill
rough granite
#

Unity's japanese?

wooden hill
#

but yea java has the duke (or the cafe)

wooden hill
hexed terrace
rough granite
naive pawn
waxen glacier
#

Here's a snippet a code from my current project, both the If statement and Switch are supposed to achieve the same goal, but is there a difference in performance between them ? Like is one method more efficient than the other or is it just a matter of preference ? Just to clarify i dont intend on using both, I'm asking here to know which one i'll keep.
https://paste.ofcode.org/BW2hBTtNjgCsSLmwkm7b97

wooden hill
naive pawn
#

use whichever you prefer or will be more readable/maintainable

#

performance just does not matter in this case

waxen glacier
naive pawn
#

only worry about performance if you a) start having perf issues, b) are developing for 50 year old hardware, or c) are doing something with millions of objects

rough granite
waxen glacier
naive pawn
#

it needs to be millions to start being an issue - and at that point i think you have other issues lol

waxen glacier
naive pawn
#

and maintainable! don't go around using magic strings and numbers everywhere lol

rough granite
#

Dont become like pirate software

naive pawn
#

don't become like yandere dev

waxen glacier
naive pawn
#

if you ever feel like "there should be a better way to do this", there probably is

night raptor
#

That's exactly why you should initially prioritize readability over micro optimization

naive pawn
#

or if you start repeating code a lot, that repetition can most likely be reduced

waxen glacier
naive pawn
#

there are a few things to avoid in terms of perf in unity, like not doing Find every frame/tick
if you abide by those you most likely won't have to worry about perf for a long while, until you have more experience at least

wooden hill
#

"clean code by Robert C Martin"
Just started reading that and seems good so far so maybe you can also read that when you got time πŸ˜›

waxen glacier
#

so the played cant sprint backwards for example

#

I'm trying to make a movement system that I'll be able to reuse for any of my future projects

timber tide
#

Eh, it's not too much of a problem. What you do want to watch out for is having too much depth in your statements and in which case you should be using a state machine

dull grail
#

How can i save Scriptable Objects to json? I've searched a bit about them and it look like all the changes i will make during runtime (e.g changing amount of item) will be reset on restarting. I know i can just store objects data in an array but it doesn't felt like a right approach with SO

I'm planning to store inventory items in SO and change they values if it's needed

waxen glacier
timber tide
#

It means if you find yourself creating too much if statements within your if statements then your logic may just be spaghetti and in which case you should look finding some way to group your logic via statemachine

waxen glacier
#

I want to avoid that

naive pawn
#

"depth" or "complexity" basically refers to how nested stuff is

if (a) {
  if (b) {
    if (c) {}
    else {
      foreach (var d in x) {
        if (e) {
          while (f) {
            // complexity = 6
          }
        }
      }
    }
  }
}
#

this "nested" complexity loosely correlates to actual complexity and can be a sign of the function doing too much

#

it also quickly gets unreadable

waxen glacier
#

not sure if the term is correct but I try to use Guard Clauses when I can

#

To avoid nesting statements

naive pawn
#

that is the term, yeah

frail hawk
#

it is correct yes

waxen glacier
#

nice

naive pawn
#

and yeah that definitely helps with making stuff more easily readable

mortal spade
#

i dont know why GameObject[] bounds = GameObject.FindGameObjectsWithTag("BlockBounds"); is returning null when there clearly are objects with the tag in my scene, i even adjusted the script execution order and added yield return new WaitForFixedUpdate(); to ENSURE that it calls after everything is loaded and its still returning null

timber tide
naive pawn
mortal spade
# naive pawn when/where are you doing the `Find`, and have you checked the tag to make sure t...
private List<float> distances;
    void Start()
    {
        StartCoroutine(Aligner());
    }
    IEnumerator Aligner()
    {
        yield return new WaitForFixedUpdate();
        GameObject[] bounds = GameObject.FindGameObjectsWithTag("BlockBounds");
        foreach (GameObject bound in bounds)
        {
            distances.Add(GetHorizontalDistance(transform.position, bound.transform.position));
        }
        // parent to closest bound
        int lowest = GetIndexOfLowestValue(distances);
        transform.SetParent(bounds[lowest].transform);
    }
timber tide
mortal spade
#

and also yeah i dont think it has blank spaces

naive pawn
#

(also not sure why you're saying WaitForFixedUpdate would wait for stuff to be loaded..)

naive pawn
dull grail
mortal spade
#

i dont see how else to ensure the other stuff is loaded

naive pawn
#

if you have a script on BlockBounds, go have it log gameObject.tag.Length or something

polar acorn
mortal spade
naive pawn
naive pawn
mortal spade
#

okay so what can i do instead πŸ’”

naive pawn
#

no, just being in Start already makes sure stuff is loaded

#

loading happens with Awake

polar acorn
polar acorn
# mortal spade

Okay, there's a bunch of errors there that I assume are because this isn't running, would it be possible to comment that out and make sure there's no errors running before them that might be preventing it getting set?

#

Or just scroll to the top

naive pawn
#

turning on collapse might help

mortal spade
#

i do have collapse on, the problem is i get the error from every object the script is on individually

#

also the top is just that error

naive pawn
#

ah.

mortal spade
#

i know it is not optimized but this is like the only solution i could think of after my initial one didnt work πŸ’”

polar acorn
#

Seems like it's a tag mismatch. Try removing the tag and re-adding it, paste in the text from inside of your string.

Or, find a way to not have to use Find at all

mortal spade
#

okay iwill try this

#

i also did try to not use find but i had a similar problem

mortal spade
polar acorn
mortal spade
#

yes

polar acorn
#

Can you show the full !code of this script?

eternal falconBOT
mortal spade
polar acorn
#

(And please don't use pastebin if I so much as hover my mouse over the page it turns my browser into one gigantic ad. I'm still stuck on Chrome at work)

mortal spade
#

oh my fault

mortal spade
#

every single instances gives me this

polar acorn
#

Sorry, I meant bound

mortal spade
polar acorn
mortal spade
#

so the issue is with the part after ..

polar acorn
#

The issue has never been related to the find not working

#

The issue is that distances is null

mortal spade
#

this makes more sense

#

holy shit is it because i didnt define the list beforehand

#

do i need to do like = new List

polar acorn
#

This is why you don't make assumptions - check everything

#

You could have logged the count of the list to see that it was getting populated

eager stratus
#

Say I have a fixed height and a fixed font size. How would I go about dynamically sizing the width of a text component so that it always has just enough space to display all the text in a single line?

frail hawk
red igloo
frail hawk
#

did you mark the collider as trigger in the inspector?

#

also make sure you gave the player the right tag "Player"

red igloo
frail hawk
#

it is a 3d envoirement right

red igloo
#

yeah

frail hawk
#

do you have any errors in the console and is the console active?

runic gust
#

Might be the wrong channel - does anyone use scrum for game development?

red igloo
#

I changed it and it works now

frail hawk
#

yeah totally not a coding question @runic gust

runic gust
#

alright ill ask terrain-3d

frail hawk
#

what does scrum has to do with terrain 3d anyways?

runic gust
#

if you gotta ask - dont worry about it

polar acorn
#

I don't think it really fits there either

runic gust
#

it was a joke because I dont think there is a proper channel to ask such a question

fierce shuttle
red igloo
polar acorn
#

Or do it in OnTriggerExit

red igloo
#

when I enter the ontriggerenter and then leave it the camera will be removed

#

which I dont want

#

I want it to be removed when going in the other ontriggercollider

polar acorn
#

Why do you need two

#

Why not have one trigger that covers the whole area you want the camera to be toggleable inside of

red igloo
red igloo
#

also theres another issue

#

when I enter the collider and when I jump out of it and press R to switch the camera's will switch but I cant go back to the main one when I am out of the zone

polar acorn
#

If you're in the new camera, exit it

#

then remove it

red igloo
#

I did this and it works perfectly now

astral citrus
#

Hi! Is there a guide how to create "simple" spell casting system? I feel I'm overcomplicating it, but a bit confused how to adjust it.
Basic idea - I have Turn Based RPG. Character have 4 spells. It could be fireball (projectile) or meele attack(without projectile).
Sequence of actions -> Select Character to move -> Select Target -> Select spell -> Cast Spell-> Casting animation + Damage animation (for mele almost at the same time) OR Casting anumation then Projectile then on hit Damage Animation + Explosion animation of projectile -> After damage taken and animations finishes next turn starts.

Truth to be told I'm not even sure how to describe what I have - there is Model(data) View(monobehaviour) Presenter(binds both).
There is BattleManager that handles logic for selection of unit and initiating casting(checks if target from enemy team, if action not yet in progress etc.).
There is CastingManger that gets data for source,target and spell and instantiate projectile, but projectile need to have callback on hit...
And all of this also uses Unitask on top of it, because I want all action to execute "at the same time" but I want all of them to finish before continuing further.

Could you help me please? I feel I just too deep in this code to see simplier solution.

timber tide
#

If it's turn based then can't it simply be some VFX? It's not like you need any physics besides some animation of particles

astral citrus
#

Yep, I don't use physics. The logic for visuals not that complicated, it's just feels too convoluted.
I'll try top cleanup and post some code maybe (just will be still a lot)

timber tide
#

I feel like all you need is some call to the skill animation -> await animation -> do damage

#

same can be said for any other type of action in these turn based games. They're just animations for the most part

#

So Animation + Timeline + Particle System

astral citrus
#

I do it like this at the moment

        private async UniTask HandleMeleeAttack(BattleUnitState source, BattleUnitState target, BattleUnitSkill skill)
        {
            var attack = source.Attack(AttackType.Melee);

            var targets = ResolveTargets(target, skill);
            var takeDamageTasks = targets
                .Select(battleUnit => battleUnit.TakeDamage(skill.damage))
                .ToList();

            takeDamageTasks.Add(attack);
            await UniTask.WhenAll(takeDamageTasks);
        }

and for range

        private async UniTask HandleRangedAttack(BattleUnitState source, BattleUnitState target, BattleUnitSkill skill)
        {
            await source.Attack(AttackType.Ranged);

            var projectile = Object.Instantiate(
                skill.projectilePrefab,
                source.ProjectileSpawnPoint,
                Quaternion.identity);

            projectile.Initialize(target, skill.damage);
            var processHit = projectile.Launch();

            await UniTask.WhenAll(processHit);
        }
#

I feel it's what your'e describing, or it's not?

timber tide
#

Yeah, but what I'm saying is you don't need a callback if it's all sequenced

#

If you're shooting a projectile, then you know the time it should take to reach the destination

zealous ridge
#

Can someone help me get started?

rich adder
eternal falconBOT
#

:teacher: Unity Learn β†—

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

astral citrus
zealous ridge
# rich adder !learn πŸ‘‡

I have checked that place I didn't check it completely but there are some questions I have that are left un answered

zealous ridge
#

I don't really know how to explain it that's why I haven't been able to google it or anything

rich adder
zealous ridge
#

ik

timber tide
zealous ridge
#

When I have to script where do I open the scripting place

timber tide
#

But those game abilities were purely cinematic and no variance between attacks so pretty much sequenced

rich adder
eternal falconBOT
zealous ridge
#

huh?

rich adder
#

pick any of these and configure it

undone wolf
#

has anyone used both grok and chatgpt to learn unity/c#? which worked out better for you?

zealous ridge
#

What are the differences why are there so many options?

rich adder
astral citrus
hexed terrace
#

!vs

eternal falconBOT
#
Visual Studio guide

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

β€’ Visual Studio (Installed via Unity Hub)
β€’ Visual Studio (Installed manually)

zealous ridge
#

When I install it do I have to set it up?

rich adder
#

well VS might run like crap if you have underpowerd pc or linux/mac (doesnt exist here)

rich adder
hexed terrace
#

yes, click the link and follow the instructions.

zealous ridge
undone wolf
rich adder
#

VS eats a lot of ram especially

wicked fiber
#

Hi! Im making a game where one object goes to another, offsets itself, than another follows onto that one. For this to happen though, I need the fixed update part of the scripts go in a particular order, otherwise an object will be left a frame behind. (I'll wait if I'm interrupting)

rich adder
ripe shard
rich adder
#

would be very careful/cautious with anything to do with "AI" you need to verify its not a hallucination and its difficult for beginners

timber tide
#

I'd just avoid copilot

wintry quarry
wicked fiber
#

ok

zealous ridge
#

CPU: 5 7600
GPU:RX 6750 XT
RAM:32 gigs of ddr5 at 6000 MT/s
@rich adder

rich adder
#

plenty of ram for VS to eat

rough granite
zealous ridge
#

I think I was told to use Visual Studio

rough granite
#

oh and you're worried about specs?

rich adder
#

Visual Studio is fine and usually already comes installed with unity hub

#

just need to configured

astral citrus
rough granite
#

i thought this was going to be like a how well would my pc run for substance painter with 4k textures

rich adder
#

otherwise you gotta pay (unless you're student)

rough granite
rich adder
#

duh

zealous ridge
#

I clicked the link for visual studio and I have clicked so many buttons already and more just keep appearing

rich adder
#

it has a few extra bells and whistles because of the $$

rough granite
rich adder
#

personally find it to be too opinionated

#

takes me more time turning crap off I don't need lol. I like the simplicity of VSC

zealous ridge
#

Do I get Visual studio 2022 or visual studio code?

astral citrus
rich adder
zealous ridge
rich adder
rough granite
ripe shard
rough granite
zealous ridge
#

So I don't even get Visual studio?

rich adder
#

get whatever you want lol

#

its not the tool that makes you skillful

astral citrus
zealous ridge
#

nav you can't say that to me I suck at making decisions and I don

#

't know the differences

zealous ridge
#

Send me link

sour fulcrum
#

A majority of people use visual studio community

rich adder
#

windows users*

sour fulcrum
#

I would argue both statements are probably true πŸ˜›

ripe shard
#

Visual studio gets expensive in professional use

rough granite
zealous ridge
#

Expensive? You gotta pay for this stuff?

rough granite
rich adder
#

no, don't be confused. They're talking about if you are in a company making certain amount

#

Sadly M$ has the same license for both VS/VSC

zealous ridge
rich adder
rough granite
rough granite
ripe shard
zealous ridge
#

What do I need

astral citrus
#

who knows -) but for first few month-years you probably can say so

ripe shard
#

everyone was a beginner, setting up yourself for success helps πŸ™‚

ripe shard
zealous ridge
#

So many buttons again

rich adder
zealous ridge
ripe shard
ripe shard
zealous ridge
#

Bruv I don't understand any of this stuff

#

I just see button and click button

ripe shard
sour fulcrum
#

dont ask AI

#

dumb thing to do

rich adder
#

this is like #1 thing you need to do with Development

#

research

zealous ridge
#

Do I want a desktop shortcut?

rich adder
#

com on lets not ask trivial questions

zealous ridge
sour fulcrum
#

google what a desktop shortcut is and see if you want one

rich adder
#

be a big boy/girl and start making your own decisions lol its okay to mess up

rough granite
ripe shard
zealous ridge
sour fulcrum
#

This server exists to actually help people

rich adder
#

"AI" for a beginner is pretty dangerous especially when they have no way to verify the authenticity of the information provided since they will not research

zealous ridge
#

Well I'm downloading something now so seems like I did something

rich adder
#

people are becoming dumber because "AI" tells them what it is with certainty and we all know its designed to give you what you want to hear, not always the truth

ripe shard
#

you are just patronizing beginners and assume they are all idiots, yet believe you are "smart" enough to be allowed to use AI on unknown subjects yourself.

sour fulcrum
rich adder
#

beginners don't know better if they don't research , thats literally 90% of learning

ripe shard
#

give them some credit, a person who cant use AI responsibly will fail either way, with or without it

sour fulcrum
#

And I atleast have made that assumption based on personal experience

rich adder
#

spoon fed answer from AI will not help them in any capacity

zealous ridge
ripe shard
sour fulcrum
#

There's a reason this server chucks AI dorks into a single space tucked away from all the real support

rough granite
zealous ridge
ripe shard
rich adder
ripe shard
rich adder
#

you learn critical thinking with researching / trial and error. easily to verify with other human responses. we all know AI just feed you "This is what it is" and most of the time its eeither partially wrong or hallucinated

#

ask the same question to "AI" it gives you different answers, sometimes its efficent if it nails it and sometimes its some over convoluted bs

ripe shard
sour fulcrum
#

"of what possible answers exist" is so fucking stupid honestly

#

google does this

#

google has done this

rich adder
sour fulcrum
#

I am actively studying with peers who just came out of high school right now and a majority of them are reliant on ai and said people are absolutely fucked when it comes to their actual education

#

it's brainrot

rich adder
#

most of us I assume started the traditional means "StackOverflow FTW " and research

zealous ridge
#

This thing wants me to buy a license what do I do

ripe shard
zealous ridge
#

It isn't giving that option tho

rich adder
#

You can use it for free for non-commercial use

#

or if you're a student you get it free as well not sure if that covers commercial use

rough granite
zealous ridge
#

I found the right buttons

rough granite
#

absurd terms who would want that

rich adder
#

well they can but they have to buy a license

zealous ridge
#

Now I have to choose a theme but they all look the same

rich adder
#

or just learning , and they want you to get hooked on it in hopes you do buy a license later on

sour fulcrum
#

Also like, I wonder how they prove you used Rider

rough granite
#

lol yeah same with unity's terms

rich adder
#

haha they do analytics for all your scripts/ projects

rough granite
#

but still not sure i'd want to use such an app

rich adder
#

idk what kinda blackbox magic if any to prove you are making money with that project

#

I rather not be the one to "fuck around and find out"

zealous ridge
#

Aren't these all the same????

sour fulcrum
#

Realistically they probably just don't check at all until they catch someone like the balatro dev under their cardboard box propped by a stick

#

then payout time

wintry quarry
rich adder
ripe shard
rough granite
sour fulcrum
#

it made money lol

rich adder
#

I assume they only care if you're actually making decent scratch (im not a lawyer)

zealous ridge
#

Next I need a build map what is that?

rough granite
zealous ridge
#

How does that work?

#

it has R 2 times

rich adder
rough granite
#

prolly logs the inputs so what nav said 😭

#

fast typer over here

zealous ridge
#

Is that inconvenient?

rich adder
#

thats usually for fast rename / across script

zealous ridge
#

These are the options

rich adder
#

stick to VS shortcuts, imo if you are looking at tutorials you might get confused

rough granite
zealous ridge
#

So Visual Studio?

#

Then I gotta choose some plugins

rich adder
#

this should probably be a thread if we gonna do this spoon feed stepbystep

#

crowding the channel for other potential questions

zealous ridge
#

What are these?

white raft
#

Is there a way to prevent a fast moving object to penetrate a wall?

rich adder
#

also not a code question

rough granite
eager elm
rocky canyon
#

adjust the collision detection/ use a bigger collider/ move w/ physics forces

#

or do a "validity check" pre-movement

rocky canyon
white raft
rocky canyon
#

try changing the collision detections first

#

Continuous is necessary imo if ur doing anything physics

rich adder
white raft
#

Thx but I already tested with continuous Dynamics

white raft
astral citrus
#

Earlier was asking about how to do things async with unitask (attack animation, create projectile, enemy take damage), was able to do it.
And each method now responsible for notifying others about if it's finished or not (and we can adjust animation now - for example trigger it "finish" earlier, so other action will follow)

        private async UniTask HandleRangedAttack(BattleUnitState source, BattleUnitState target, BattleUnitSkill skill)
        {
            await source.Attack(AttackType.Ranged)
                .ContinueWith(() => SendProjectile(source, target, skill))
                .ContinueWith(() => PlayEffect(skill.effectPrefab, target.Position))
                .ContinueWith(() => target.TakeDamage(skill.damage));
        }

I feel this is most flexible approach. Do you see any issues with it?

slate glade
#

is there an actual goood tutorial for recreating mario physincs/mechanics in unity? all the ones ive seen are either very outdated or control like garbage and not like actual mario

#

also id prefer if the tut actually taught instead of saying "type this here" i hate that it is a pet peeve of mine

frigid sequoia
rocky canyon
#

etc etc.. your odds of finding a (one size-fits all) tutorial are slim..

#

and if u find a tutorial where its "do this and this" and they're not explaining why.. then close it and move-along

slate glade
#

thanks twin

rocky canyon
#

code doesn't go out of style btw πŸ˜‰

#

the editor and stuff may change.. but logic is logic... and even 8 year old tutorials still work

#

theres always that case of a deprecated function or one thats been renamed..

#

a properlly config'd IDE will reveal the alternatives

#

or the newer version of said method for example rb.velocity is now rb.linearVelocity

rocky canyon
#

maybe i just haven't looked hard enough but lot of em are just basic platformer code and then they capitalize on "mario"

#

lol

#

i think mario may have Coyote time and jump buffering

#

those are two things u can also look into independently

#

oh, that Press Start perfect jumping tutorial may cover that

#

he's pretty solid imo and actually explains things along the way

slate glade
#

ok so i imported my sprite into unity and

#

the colors are all out of wack

#

this is what its supposed to look like

#

wait nvm

#

it was cmpression

naive pawn
slate glade
#

oh ok

#

thanks!

lucid narwhal
lucid narwhal
crisp token
#

Im getting this error specifically in build mode: probably about this script

rich adder
crisp token
rich adder
#

only POCOs are ok

#

its good practice to have separate files for each class anyway, less disorganized and costs next to nothing to do so

shell sorrel
#

regular C# objects and structs do not have this limitation and you can put many in a file or even nest them

#

not sure if its still a requirement but iirc the class name for a component or so also needs to match the filename so when you fix it i would rename the files to match

naive pawn
rough granite
#

me when i spend 30 minutes trying to test a function but forget to call it wondering why it aint working UnityChanDown

acoustic belfry
#

hey, how i can make this work via a raycast instead shooting a proyectile?

    {
        rifle_amount--;
        Vector3 mouseposition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        mouseposition.z = 0;
        Vector3 shootDirection = (mouseposition - transform.position).normalized;
        GameObject riflebullet = Instantiate(rifle_bullet, transform.position, Quaternion.identity);
        riflebullet.GetComponent<Rigidbody2D>().linearVelocity = new Vector2(shootDirection.x, shootDirection.y) * rifle_bulletspeed;
    }```
sour fulcrum
#

What exactly about this are you missing in your head here?

acoustic belfry
#

i mean

#

i originally made my player shoot a prefab proyectile, but then i decided to change it to raycast, the issue is i dont know how, i tried to follow a tutorial but it didnt worked, it didnt shooted a thing and didnt hurted the enemies

chilly wolf
#

Hello, I'm trying to set up mouse input to switch between 3rd person perspective camera and orthographic (isometric).

scroll up for third-person
scroll down for isometric

I’m using cinemachine and i made three scripts: CameraManager, CameraRegister, and CameraController. The input works, and the transition between cameras plays nicely. Weird part is that when i scroll down to switch to the isometric camera, the projection stays in perspective instead of switching to orthographic. Any idea why that might be happening?

sour fulcrum
#

Anyone know if GUIUtility.pixelsPerPoint is publicly accessible anywhere? or will I need to use reflection (its internal static float)

sour fulcrum
#

Well for example theres a public getter to it in another class but it's in the editor namespace

#

was curious if there was maybe others πŸ˜„

autumn osprey
#

Hey, I'm having some trouble with delegates and events in my project.

The intended behaviour: Whenever entering a game level, a singleton GameManager awakes and sets itself plus other important objects (ie the player) as persistent with DontDestroyOnLoad(). Whenever the main menu scene SPECIFICALLY is loaded in, the GameManager is meant to recognize this using an event, and delete itself plus all it's marked persistent objects.

Instead, this setup will strangely work the first time, then completely fail and allow the GameManagerand player to exist in the main menu every subsequent run.

Here is a video that shows the behavior and my entire GameManager script. Below I included the full script in text form.

public class GameManager : MonoBehaviour
{
    //Declaration of a singleton.
    public static GameManager instance;

    [Header("Persistent Objects")]
    public GameObject[] persistentObjects;

    private void Awake()
    {
        //If sceneLoaded triggers and this object is in the scene (theorhetically always possible after the first game scene), 
        // run OnSceneLoaded
        SceneManager.activeSceneChanged += OnSceneActivated;

        //If there is a GameManager already in the scene (global "instance" has a value attached) it destroys itself.
        if (instance != null)
        {
            CleanUpAndDestroy();
            return;
        }
        else
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
            MarkPersistentObjects();
        }
    }

    private void MarkPersistentObjects()
    {
        foreach (GameObject obj in persistentObjects)
        {
            if (obj != null)
            {
                DontDestroyOnLoad(obj);
            }
        }
    }

    private void OnSceneActivated(Scene lastScene, Scene nextScene)
    {
        //Determines if the scene is the main menu, and destroys all of this game manager's persistent objects if so.
        if (nextScene.name == "MainMenu")
        {
            CleanUpAndDestroy();
        }
    }

    private void CleanUpAndDestroy()
    {
        foreach (GameObject obj in persistentObjects)
        {
            if (obj != null)
            {
                Destroy(obj);
            }
        }
        Destroy(gameObject);
    }
}
wintry quarry
#

Even when the GameManager is a duplicate and is about to destroy itself

#

shouldn't this only happen in the else case in Awake, when this is the first GameManager?

autumn osprey
#

So, I want any duplicates to destroy themselves, and I also want the original to destroy itself whenever the scene changes to the main menu

wintry quarry
#

Yes... I can see that. That's not an answer to the question I asked though.

#

You still would only want to subscribe to the activeSceneChanged event in the else block of Awake

#

You also need to unsubscribe in OnDestroy

#

which you're not doing at all

autumn osprey
#

I didn't know unsubscribing was necessary if the object was destroyed honestly. never used delegates before today

wintry quarry
#

You need to unsubscribe when the event publisher outlives the event subscriber

#

which is the case here

#

otherwise the delegate on the destroyed subscriber/listener is still going to run when the event fires

autumn osprey
wintry quarry
autumn osprey
#

(im going to move it to the else section if it is a best practice's thing to be clear, i just want to understand the issue better)

wintry quarry
#

else only is running here when there is not already a singleton instance

digital parcel
#

yo sup

#

bro i wanna publish my game to app not just in unity learn

#

do you guys know how to do that

wintry quarry
digital parcel
#

u know when we download game from internet then u can find .exe file

sour fulcrum
#

@wintry quarry Just for closure did end up grabbing that value via reflection, works fine. Was interested in grabbing it because i'm interested in some runtiem GUI stuff and HandlesUtility.WorldPointToSizeRect is editor only but the only editor only part of it was grabbing that value πŸ˜„

digital parcel
#

and when u click it u got the game

wintry quarry
digital parcel
#

is that possible?

wintry quarry
#

Is building your game possible? Yes of course.