#💻┃code-beginner

1 messages · Page 545 of 1

thorny basalt
#

For simpler issues you can typically just reread the code. If you can’t find where your bug is by reading it you likely have to refactor for readability. Testing via debug.log can also help.

For more complex issues, unit tests can sometimes help.

elfin isle
#

ty guys lmao

thorny basalt
#

NP.

charred spoke
#

Don’t forget the most important thing…using the debugger to step through your code and see what happens.

rocky canyon
#

anyone know what the easiest/best method of removing these broken installs?

rich adder
#

reinstall windows lol

naive pawn
#

uninstall windows lol

rocky canyon
#

🇫

#

i guess regex it is

shadow rain
#

does anyone know how to fix this?

rich adder
#

omg unity

#

which intern did this

rocky canyon
#

ill never trust unity vc or plastic

rich adder
#

same problem within the hour, its gonna be one of those lol

#

better patch quick

#

plastic sucks anyway

shadow rain
#

what should i do tho?

rich adder
#

try remove VC package?

shadow rain
#

nvm

#

its all good

#

i just reopened unity and it was gone

silver forge
verbal dome
verbal dome
# silver forge

Okay so CharacterController will not work with Rigidbody. Both will try to move the character = 💥

#

You need to pick either one

silver forge
#

oh yeah

#

forgot to remove that

#

damn i'm stupid lmfao

#

tysm

rocky canyon
flat sphinx
#

?
as in var thing = GameManager.us?

cosmic quail
wintry quarry
flat sphinx
naive pawn
#

it wouldn't be faster

flat sphinx
#

to type

naive pawn
#

it could be more convenient

#

but i mean, intellisense is a thing anyways

#

if you're using the same method in a bunch of places, it could make it more convenient

flat sphinx
#

ehhhh i mean it would work

#

i dont like bridges tho, still have ptsd over a mountain of shitcode built on it

#

do have a bit of a skewed outlook since to me less wrappers == cleaner code

verbal dome
flat sphinx
#
//set stuff up
GameManager.us.do_x()
GameManager.us.do_y()
GameManager.us.do_z()
GameManager.us.do_w()
verbal dome
#

What's wrong with that

#

If the issue is that it does GameManager.us repeatedly, I would assume that the compile probably optimizes that

flat sphinx
# verbal dome What's wrong with that

lets take an example from my code
so im doing golf, and one of the things i needed to do was a sick ass animation of every element floating away when the ball goes into the hole

#

now i could do some

void OnColliderEntry(gameobj){
  if(gameobj.hastag("ball")){
    var gm = GameManager.us;
    us.yeet_map()
    us.load_new_map()
    us.spawn_ball()
  }
}

ball whatever code

#

but realistically all of it should be in us.load_map()

#

the hole handling loading the map aside

verbal dome
#

Agree

flat sphinx
#

now im not saying "dont have functions that do a lot of stuff"
but if you're calling a bunch of stuff on a diff class perhaps said class should have a proper handler for that

verbal dome
#

Yeah. And ideally you'd make these private: yeet_map, spawn_ball etc.
So you can't even call them accidentally

flat sphinx
#

ehhh that one is up to preference imo

#

i personally dont like the modifiers since all that ends up with is me having to correct a private to a public when some new usecase pops up

#

even if said usecase is nonexistent

verbal dome
#

But yeah worrying too much about encapsulation just slows down my iteration speed tbh.

flat sphinx
#

yuh

wintry quarry
flat sphinx
wintry quarry
#

less wrappers == cleaner code
Basically the entirety of using a high level programming language and a game engine is to introduce layers of abstraction to simplify the code you need to write

#

Not sure how this is any different tbh

#

Wrapping things is how you make things clean in programming

flat sphinx
#

wrappers as in f.e

#
public bool drop_item_on_floor(){
  return move_item_internal(...)
}
#

or getters or setters that only just return the var

wintry quarry
#

that's a wrapper that doesn't seem to add anything though, which has no purpose

wintry quarry
flat sphinx
wintry quarry
#

not in any meaningful way

#

the property lets you have a different access modifier on the getter and setter

flat sphinx
#

neither do getters

wintry quarry
#

this one just makes a private method public

wintry quarry
wintry quarry
#

yes it does

flat sphinx
#

idk if its a me issue

flat sphinx
#

oh

pallid nymph
flat sphinx
#

well what if i need to mock a var

flat sphinx
#

i shouldnt have to, but what if i do

wintry quarry
flat sphinx
wintry quarry
#

how so

flat sphinx
#

say im doing chess and i need to mock a piece being in x place
and lets say you have a setter on the piece holder whatever that updates the hud
the mock would erroneusly update the hud

#

well, update meaning "place a piece on the hud"

#

board whatever

wintry quarry
#

You wouldn't call that setter in that case.

flat sphinx
#

yeah, you'd just assign to the var directly

wintry quarry
#

Are you arguing against any accessors with side effects at all?

flat sphinx
#

and reset after

wintry quarry
#

because that way leads to madness

flat sphinx
#

in this case setting

wintry quarry
#

That's a huge mistake and inviting way more bugs than the other way around

pallid nymph
#

my usual approach is - make everything private by default, if necessry expose something

wintry quarry
flat sphinx
#

~~the 6 remaining times are in an engine where access modifiers are through an optional lint omegalul ~~

pallid nymph
flat sphinx
flat sphinx
#

obviously if you're doing a library throwing privates at eveything is prefered

pallid nymph
#

even in personal projects... you can't randomly change many variables from the outside without breaking something, so exposing them makes no sense... make methods that would keep the object in a valid state instead 🤷‍♂️

#

it's just easier to work with, because in a month you wouldn't strictly remember what's what, and which variable you can modify safely

pallid nymph
#

so, while it would work and it's not a strict requirement for a solo project, the moment you're not doing solo it would be, so it's better to get used to it 🤷‍♂️

flat sphinx
#

both public var access and functions that dont leave the program in an undefined state

violet pagoda
#

Which programming language does Unity use?

pallid nymph
#

C#

violet pagoda
#

Is programming only possible using C# or are there alternatives?

flat sphinx
violet pagoda
#

Sorry if I am asking too many questions I am new to using Unity and learning game development on it

flat sphinx
#

no worries

forest summit
#

ive been constantly trying to get this sdk to work, ive tried reinstalling vs code and my computer. I checked my system variables and manually assigned its path. Yet it still doesnt work, if anyone can help that would be awesome

vital olive
#

Hey, I am new to unity and I am acutally working on a Flappy bird game, Do anyone know why my pipes are behind the ground in 3D view but in front of the ground in 2D ?

slender nymph
#

this is related to 2d sorting. your sorting layers determine what is drawn on top. and your z position determines where in the 3d view they appear

rocky canyon
#

^ this.. u can actually have all ur 2d objects BEHIND something and have them all render in front of it.. using sorting layers

vital olive
#

Thanks I will read this html file

late abyss
#

why is my "LogicScript" not blue?

short hazel
#

Do you have a class named LogicScript in your project?

#

I don't see it in the script list in VS

#

I see a NewBehaviourScript, which is the default script name when you create one, did you forget to rename it?

rich adder
rocky canyon
#

aren't u a comp-sci major? that had to learn c++ and python? im sooo confused..

prime goblet
#

i'm trying to get this vehicle to abruptly change from acceleration to deceleration (or otherways) but i'm not sure how to make it more abrupt.

    void FixedUpdate() {        
        if ((goingSpeed > 0 && YInput < 0) || (goingSpeed < 0 && YInput > 0)) { // gets triggered when the player switches
            goingSpeed = Mathf.MoveTowards(goingSpeed, 0f, dccSpeed);
            print("change from acc/dcc dcc/acc");
        } 
        else if (Mathf.Abs(YInput) > 0.1f) { // gets triggered if the player is just holding
            goingSpeed += YInput * (driveSpeed / accSpeed);
            print("going forward/backward");
        } 
        else { // triggered when the player releases all forward input
            goingSpeed = 0f;
            print("stopping vehicle because no input");
        }
        
        goingSpeed = Mathf.Clamp(goingSpeed, -driveSpeed, driveSpeed);
        
        // Driving
        float motor = goingSpeed;
        
        wheel3.motorTorque = motor;
        wheel4.motorTorque = motor;
        
        wheel1.steerAngle = steerSpeed * XInput;
        wheel2.steerAngle = steerSpeed * XInput;
    }

notably it barely ever prints the change print statement, and making goingSpeed = 0 does not really do much in terms of doing lots of slowing

magic panther
#

My project cannot compile because these two functions use AssetDatabase. They're meant to grab a file from the Assets folder, without the need for a Resources wrapper folder.
Class with both functions (GetRuleTileByCodename and GetSpriteFromPath): https://hastebin.com/share/maxunijaqu.csharp

How can I change the functions to preserve the functiionality but remove AssetDatabase from it?

rich adder
#

oh and streaming assets ig if you don't consider that IO

magic panther
#

I don't understand

rich adder
#

AssetDatabase is part of Editor classes, you cannot use Editor classes in a build

#

alternatives are the ones stated above

untold raptor
#

has anyone here worked on motorbike physics before? or more on the wheels part of it. I need help with setting up my bike properly. Im running into the wheel bouncing when torque is added to the wheel collider and the suspension bouncing all over the place

fair badge
#

What collider are you using?

untold raptor
#

wheel collider

magic panther
rich adder
magic panther
#

But what I need are specific files of any kind, for now a RuleTile and texture. I don't know what to do, as theyre in separate folders. Some in Graphics > Backgrounds > 00 > 04.png, some in Game > Tilesets > StoneBricks > StoneBricksRuleTile.something (.RULETILE? .asset?)

#

for example*

rich adder
magic panther
#

I'm unsure how to decide what folders to move to a Resources wrapper

#

do I include Prefabs? Scripts?

rich adder
#

i personally don't like using it and just go for Serialized references or SO containers.
but generally just whatever you're loading now with AssetDatabase

untold raptor
#

gpt isnt helping me at all rn hence why i came here

rich adder
magic panther
rich adder
fair badge
meager gust
# untold raptor wheel collider

just letting you know the physx wheel colliders (default in unity) are awful garbage. Its difficult getting them working for a 4 wheeled car, let alone a balancing motorcycle

fair badge
#

Otherwise you can use Assets like:Realistic Motorbike Controller

rich adder
#

raycasts are the answer

meager gust
#

@untold raptorYou should look into getting better "wheel colliders" off the asset store, or building your own if you're interested. Building your own is actually pretty simple.

rich adder
#

you just have to juggle creating your own friction

untold raptor
#

oh boy 😄

meager gust
#

A lot of people don't realize that cars in video games are actually just hover crafts 😉

#

the wheels are 100% visual

untold raptor
#

this has gone from simple drag and drop to create my own physics lol

meager gust
#

nah its not that advanced

rich adder
#

You dont have to make your own physics, just use for example: a raycast to create up and down suspensions instead of relying on wheel col

untold raptor
#

so just scrap the colliders in a whole cos they are trash?

rich adder
#

99% they are trash

untold raptor
#

gotcha

meager gust
#

Yes, basically what navarone is saying.
Send a raycast down from the wheel position. Think of this raycast as a spring. How much is your "spring" actually compressing? (between 0% and 100%)

#

then just add force upwards

#

proportional to the "compression" amount

rich adder
#

I have a 2 wheel game but I use 4 rays on that but you can probably force it to only work on 2, I just never bothered

keen cargo
#

alrighty i'm back at it again with the gap issue - i've got some progress with it as now only ONE tile has the flickering gap, and it's always the first tile that gets moved that causes this

another interesting point is that the flickering can only be seen when the tiles are moving

I have checked that the tiles are on the same ordering layer ( having different ordering layers doesn't change anything), and that the Z axis is also the same

I've also tried deleting the tile and putting it back in case i messed something up

here's the code:

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class LevelScroller : MonoBehaviour
{
    public Sprite sprite;
    public Transform[] tiles;
    public float scrollSpeed;
    public float tileHeight;
    public float pixelsPerUnit;

    // Start is called before the first frame update
    private void Start()
    {
        tileHeight = sprite.bounds.size.y;

        for (int i = 1; i < tiles.Length; i++)
        {
            tiles[i].transform.position = new Vector2(tiles[i - 1].transform.position.x, tiles[i - 1].transform.position.y + tileHeight);
        }
    }

    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < tiles.Length; i++)
        {
            tiles[i].transform.Translate(Vector2.down * Time.deltaTime * scrollSpeed);

            if (tiles[i].transform.position.y < -tileHeight)
            {
                float highestY = GetHighestTileY();
                tiles[i].transform.position = new Vector2(
                    tiles[i].transform.position.x,
                    highestY + tileHeight);
            }
        }
    }

    float GetHighestTileY()
    {
        float highestY = tiles[0].transform.position.y;
        for (int i = 1; i < tiles.Length; i++)
        {
            if (tiles[i].transform.position.y > highestY)
            {
                highestY = tiles[i].transform.position.y;
            }
        }
        return highestY;
    }

}
untold raptor
#

im picking up what your putting down. after the hovercraft analogy, that really helped me understand what i need to do now

rich adder
#

there are multiple good videos on youtube that explain the math behind it

#

A detailed look at how we made our custom raycast-based car physics in Unity for our game Very Very Valet - available for Nintendo Switch, PS5, and Steam.
BUY NOW!! https://toyful.games/vvv-buy

~ More from Toyful Games ~

▶ Play video
meager gust
#

float springCompression = 1 - (hitDistance / raycastLength);
is basically gonna be the heart of the equation

rich adder
#

such a good vid

untold raptor
#

thanks man

tribal edge
#

Wait that's not you

#

Didn't you make a video on a car controller a while back though? Or an asset?

rocky canyon
#

i mean i actively use that tactic

#

so i approve 👍

meager gust
#

a little bouncy but yeah good example

rocky canyon
#

can even play around with the center of mass

#

i imagine doing a bike would be relatively easy

#

esp comparing it to unity's wheel colliders 🤢

meager gust
#

the difficult part about the bike is just keeping it upright

untold raptor
#

honestly making my own wheels sounds kinda fun

rocky canyon
untold raptor
#

would u say using a mesh collider better than using any other? (with convex)

meager gust
#

single lined raycasts make icky wheels. <-- afaik the physx implementation does this

rocky canyon
#

heres some bouncy

rocky canyon
#

but for arcade type stuff 1 ray is plenty

outer marsh
#

hey guys im making a pixelated 2d cool game and im looking for a scripter i curently just made sprites

rocky canyon
#

which would u do?

meager gust
rocky canyon
#

like i could picture two different setups that could work..

meager gust
#

nah, no multiple raycasts

#

sweeptest is raycasting basically an entire mesh

#

physx handles it behind the scenes

rocky canyon
#

ohh interesting..

meager gust
#

ill show you how nice this looks one sec

rocky canyon
#

oh yea, thats noice

meager gust
#

same operation, just sweeptest replaces raycast

untold raptor
#

that suspension flexing is amazing

meager gust
# rocky canyon

I did actually try this also (both examples), but the gaps between the raycasts caused serious issues

#

you'd need like tens of thousands per wheel to make it viable

untold raptor
#

well i done something wrong here 😂 gotta add some stuff to stop it from turning into an oppressor

verbal dome
#

A low center of mass helps with stabilization

#

You can manually modify Rigidbody.centerOfMass

rich adder
#

also make sure mass is not like 1 or something, these things are pretty heavy usually and have decent amount of mass

#

nver had good luck with mass below 1000 with suspensions

untold raptor
#

gotcha

keen cargo
rich adder
keen cargo
#

got that

rich adder
mint flint
#

hi

keen cargo
#

yep, one sec

mint flint
#

im new

rich adder
#

Hi new

mint flint
#

haha no, im GALADIXO

short hazel
#

I'm dad

keen cargo
keen cargo
# verbal dome Missing context here

so i have this system where tiles are placed on top of each other to simulate an infinite scrolling level

before i had an issue where each tile placed left a 1 pixel wide gap inbetween the tiles, i got past that except for now this only one tile that leaves a flickering gap

rich adder
# keen cargo

huh normally the ortho size of camera is grayed out when pixel perfect is active

keen cargo
#

ah it's because the ortho is the same size as the pixel perf

#

just increased its size

rich adder
#

I mean normally pixel perfect controls the ortho size

keen cargo
#

ahh

rich adder
#

maybe its urp/unity6 thing

keen cargo
#

yeah i could update to unity6 as well

#

it's currently on 2022 LTS

#

and everything is backed up on github in case that screws it up

rich adder
#

hmm i think its more to do with using BRIP instead of urp the camera

#

did you check out the scene view?

#

does the same thing happen if you zoom in

keen cargo
#

yep

#

happens both scene & game view

meager gust
keen cargo
#

i've also tried sprite atlas, sprite material with the pixel snapping turned on, nothing is changed

#

one part that i have definitely noticed is when the LateUpdate() is changed to FixedUpdate(), the gap turns larger

#

but it's ONLY for that tile

#

you've got to be fucking kidding me

#

i just fixed it

#

i just moved the translate part of code after the if function

#

i mean it MAKES SENSE, since code goes top to bottom, it'd do the translate first and then the if

#

and since my pc is a good boy, it did the translate + if really fast, making the tile overlap and flicker at that one little point

swift crag
#

Order-of-operations can be very important

#

within a function, between different objects...

proper needle
#

im 15 and new to unity, why doesn't my key glow

#

if any1 knows

knotty hawk
proper needle
rich adder
proper needle
verbal dome
proper needle
rich adder
#

check camera component make sure PP is on and you have a Volume with a profile

proper needle
rich adder
proper needle
rich adder
#

yes screenshot the Camera component

proper needle
#

is this what ur talking about

rich adder
proper needle
#

ok i see

#

do i need anything else

rich adder
proper needle
#

i went into gameobject

#

idk if im doing this right

rich adder
proper needle
#

which one do i choose

#

or just box volume

rich adder
#

Global, sorry

proper needle
#

oh

#

thanks

rich adder
#

create a new profile make sure you got enough bloom

proper needle
rich adder
proper needle
#

i see

#

is there anything i missed

#

my key still doesn't glow

rich adder
#

make sure volumetric is enabled on the light2d

#

and what is your values for bloom

#

actually Iirc for 2D lights all you need is the Volumetric option instead of sprites

proper needle
rich adder
#

you still need PostProcessing/bloom for glow in sprites n stuff tho

proper needle
#

thanks

#

my textures look like this now

#

any1 know what happened

rich adder
proper needle
proper needle
rich adder
rancid tinsel
#

how on earth does OnDestroy() work

#

I thought I understood it but clearly not

flat sphinx
# rocky canyon

goddamnit now i wanna make a wacky racing game with cars bobbing like that

swift crag
#

The error is happening because you're trying to access the gameObject property of your MonoBehaviour-derived class

#

Trying to access this property on a destroyed object is invalid

#

If you really want to know if your own object is valid, you'd do if (this)

rancid tinsel
#

but how can the object be destroyed if im accessing it in OnDestroy()

rich adder
swift crag
#

Is this happening as the game exits?

#

I'm pretty sure that the object only becomes invalid sometime at the end of the frame, normally

#

But I know that this changes when exiting Play Mode

rancid tinsel
#

i managed to fix it, i think the sounds were parented to the object that was being destroyed

#

or something like that

swift crag
#

If you destroy a game object, all of its child game objects are also destroyed

rancid tinsel
#

is there no way to "cancel" a destroy btw?

swift crag
#

No.

#

If you don't want to destroy an object, don't call Destroy on it

rancid tinsel
#

seems weird that all children are just doomed for destruction and cant be unparented or anything

verbal dome
#

You can unparent them before you destroy the parent

swift crag
#

If you want to play an audio clip as a thing is destroyed, consider this..

#

I believe this is 3D-only, since it doesn't let you set the spatial blend

#

so it would be inappropriate for a 2D game where you don't want to spatialize audio

rancid tinsel
rancid tinsel
latent glade
#

is there a way to have a Bot know what path to a player has no obstacles without Raycast? I know how to use raycast and I have used it a lot, I just want to know if theres another way

meager gust
#

navmesh

latent glade
#

ok ty

latent glade
#

Should I use Unity AI navigation because its newer (less than a month old)?

slender nymph
#

unity ai navigation is navmesh. and it is not less than a month old lmao

latent glade
#

mb the version is less than a month old

meager gust
#

@latent gladehttps://docs.unity3d.com/6000.0/Documentation/ScriptReference/AI.NavMesh.html

#

if you want to steer rigidbodies, you'll want to extract the path and steer the rigidbody using addforce to each waypoint

latent glade
#

so in a platformer, could I still use linearvelocity for the x value?

meager gust
#

yes, you can steer with velocity

#

the important part is that you don't natively use the rigidbody as a navmesh agent

#

because unity will forcefully override it's transform, which bypasses the physics engine

latent glade
#

ok thank you

slender nymph
latent glade
slender nymph
#

navmesh does not work with 2d out of the box.

latent glade
#

wdym out of the box? the camera?

slender nymph
#

no, i mean that navmesh does not work with 2d. there are assets that allow it to, but it does not work with 2d by default

meager gust
latent glade
#

oh ok

meager gust
#

as in, it only works with 3D 🙂

latent glade
slender nymph
#

you can google it. but there is a free version of that asset

woven dust
#

just make a 2d game in 3d 🧠

meager gust
#

"AI" shouldn't be all too difficult for a 2d platformer in the first place tbh

#

you could probably just make something yourself

latent glade
#

Yeah I was thinking about that

meager gust
#

navmesh is typically for more complex problems. Like a character finding his way out of a room

latent glade
#

Would raycasts be a good way to do it or would that slow the game down too much?

meager gust
#

raycasts aren't a problem for performance unless you're doing tens of thousands of them

latent glade
#

alright sounds good

grand rose
#

what does this mean?

wintry quarry
# grand rose

device is an InputFeatureUsage<float> so its TryGetFeatureValue out param will be a float

#

but you used a bool

#

i.e. bool isPressed

swift crag
wintry quarry
#

no

swift crag
#

device is presumably an InputDevice

wintry quarry
#

oh - maybe

wintry quarry
#

I'm not that familiar with XR stuff, I was imagining TrtGetFeatureValue being an extension method with device basically as the first param. But that makes sense too

#

yeah that makes more sense

#

Basically this one is being called, but your out param is a bool @grand rose , so it's not happy

#

or the other way around - it thinks it's the bool version but you provided InputFeatureUsage<float> Either way it's a mismatch.

swift crag
#

yeah, it's trying to figure out some way to coerce the things you provided into something that exists

north kiln
#

Also, surely !ide

eternal falconBOT
swift crag
#

ah, yes, i didn't notice the missing error in the code editor

wispy coral
#

hey yall im kinda confused that when i create a script it doesnt come with the using System.Collections; and using System.Collections.Generic lines

wintry quarry
#

Those would have come from a file template.

#

Unity 6's file template doesn't have those

wispy coral
#

Oh i see

steep rose
#

the easiet thing to do is to just add whatever you need when you create it

wintry quarry
#

You can and should be using a fully configured IDE that automatically adds using directives as needed.

wispy coral
#

I was following one of the unity courses and the guy created a script and it came with those

wintry quarry
#

ok, well, it's not important.

#

But you should really try to use the same version of Unity as the tutorial you are following

#

or you will see lots of little differences that might confuse you if you are a beginner.

wispy coral
wintry quarry
#

Rider is best IMO

wispy coral
#

ill give it a shot

#

how heavy is it on performance?

steep rose
#

Visual studio is slow

wintry quarry
#

That's a really vague question. Rider is fast, after it does its initial indexing.

steep rose
#

I have not tried rider yet

#

VSC is pretty fast as well but it all comes down to personal preference

wispy coral
#

alrighty

steep rose
#

choose which IDE you want to use

wispy coral
#

im used to the vscode interface so idk if rider is quite different

#

also i barely know how to code

steep rose
#

You will learn them over time

wispy coral
#

I see, thanks

#

also last thing, is rider user friendly?

steep rose
#

you would have to use it to make your own judgement, or look at reviews of it

wispy coral
#

got it thanks

wintry quarry
sonic hull
#

😭

#

oki, I'll reopst it, tyty

crisp olive
#

/*who knew programming was this much fun

#

Just learned Prefix (++x) and Postfix (x++) operations Lets goooooooooooooo*/

vocal urchin
#

Is there by chance a quick and easy way to get all Vector3Ints within a circular 2d bounds? 🙂

wintry quarry
wispy coral
#

can you use vscode for commercial gain? im just kinda confused about rider's licensing

wintry quarry
#

Rider is free for non commercial use

#

paid if for commercial use

#

VSCode is free

wispy coral
#

lets say i want to release a game on steam for free would that qualify as commercial use?

wintry quarry
#

no

#

if you don't plan to make money, it is not commercial

wispy coral
#

i see

#

as long as i dont get monetary benefit from it its fine

#

nice

vocal urchin
wintry quarry
vocal urchin
#

I'm seeing that bounds include a contains method

wintry quarry
#

If you mean Bounds, that will not tell you if it's in a circular area.

Bounds is the AABB of the collider

#

Assuming you're talking about a CircleCollider2D

#

Basically it's a rectangle

vocal urchin
#

Ahh I could just measure the distance from the radius

#

center

#

using the radius

wintry quarry
#

yes

wispy coral
#

im not sure what to use between rider, vs2022 or vscode

cosmic dagger
#

if you can get/use Rider, go for that . . .

wispy coral
#

i like vscode but i dont want to be having problems down the line

wispy coral
wintry quarry
#

Nothing is going to happen with licensing fees

teal viper
#

You can always switch to another ide🤷‍♂️

wintry quarry
#

Rider has the best Unity integration, that's why I recommend it

wispy coral
#

i see

teal viper
#

I'd just stick with visual studio as a beginner.

cosmic dagger
#

yeah, the integration is ridiculous . . .

vocal urchin
#

got a little circular fog of war going now. thanks praetor!

wispy coral
#

what im curious is that if i keep using vscode that it will be lacking in some aspects

#

i like the plugins and themes for it

wintry quarry
#

VSCode tends to break with its Unity integration randomly

#

at least in my experience

#

and then you waste time trying to figure that out

#

Also last I checked there was no functional debugger for it.

wispy coral
#

is there not a more lightweight version of rider?

wintry quarry
#

This is your choice to make

teal viper
wintry quarry
#

we can't make it for you

wispy coral
#

i see

wintry quarry
wispy coral
#

ill go for rider

#

see how that plays out

#

thanks so much guys

wintry quarry
#

You can always change later

wispy coral
#

youre right

#

ill see if my system can handle it with other windows open

#

and if it can ill keep it

crisp olive
#

fog of war ahhh

eager spindle
#

based on my personal experience vscode is ok, im using it now because my visual studio installer bugged out. just that the autocomplete can be subpar.

#

in this case it recommends a visual studio namespace before recommending unity's ui namespace

cosmic dagger
#

i believe that's in alphabetical order . . .

eager spindle
#

if theres a way to remove this namespace from being recommended/prioritising unity's namespaces to be recommended ill gladly take it

undone depot
#

is there an easy way to reset a variable if it remains unchanged for a bit?

cosmic dagger
#

use a timer: once expired, check if the variable has the same value since the timer started, and reset (if true) . . .

wintry quarry
#

basically yes - write a little code.

cosmic dagger
#

i take it you mean, "remains unchanged," after it has been changed, no?

rich adder
undone depot
#

ill do the timer thing

wintry quarry
#

Basically i'd do something like:

  • Make a property to change it which also sets a timer. Only set it through that property so it always sets the timer
  • In Update, check if the last change was over some threshold. If so, "reset it".
regal wing
#

Me and a friend are fairly new with Unity, we're trying to make a 2D platforming game
Here we've ran into a problem that we've tried searching for solutions online but haven't managed to find one so far
In the video you can see that there's random audio icons everywhere and the referenced script on the behavior is missing, problem is we don't know what said script is because it's listed as unknown
Does anyone know how to fix this? Thanks (If I chatted in the wrong channel let me know I just joined this server and have read the rules)

wintry quarry
#

you can disable them by disabling gizmos in general, or that specific gizmo

#

As for the warning - check all the objects in your scene and check all your prefabs

#

one of them will have a broken component on it.

late abyss
#

I don't know how I didn't assign the variable.

#

I thought I did everything I was supposed to do

#

It's the audiosource variable GameOver

rich adder
wintry quarry
#

nothing in your screenshot seems particularly relevant to the error, which is presumably in a different script.

late abyss
wintry quarry
#

Like not saying None in these slots

#

(this is an example from my game)

#

Here's how it looks unassigned

#

Note that you didn't even provide a screenshot of the inspector

late abyss
# wintry quarry

I'm going to have to get back to you later. I was tampering with my own game and now I can't make the bird fly anymore

austere ice
regal wing
#

Should I make a thread for this btw? To not clog up the channel

wintry quarry
#

Disable them with this

austere ice
versed girder
#

Hey i'm looking for some help with something - if anyone has experience making xcom like games !

royal lodge
#

who can help me?

#

i need to know how to start a script

#

please i need someone who can help me

teal viper
eternal falconBOT
#

:teacher: Unity Learn ↗

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

teal viper
eternal falconBOT
#

:teacher: Unity Learn ↗

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

royal lodge
teal viper
#

750+ hours is all the content on the platform. Not just the beginner tutorials.

teal viper
royal lodge
#

bro huh?????? where can i create a script

teal viper
royal lodge
royal lodge
#

where tf is script?

teal viper
prime goblet
eternal falconBOT
#

:teacher: Unity Learn ↗

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

prime goblet
#

again, you don’t need to do all 750 hours

gloomy cosmos
wicked cairn
prime goblet
wicked cairn
#

They will realize that eventually.

silent falcon
#

Hi,I would like to ask a question, assuming that orange and blue are two UIDocuments, and their Panel is the same. I now want to place the blue one at the bottom of the screen. How should I do it?UnityChanHuh

#

orange is startup and blue is dialog

frail hawk
silent falcon
#

Thank you, I will go to the corresponding group to ask.

lyric rapids
#

Hi, I can't understand what causes my game to freeze.
I followed this tutorial https://www.youtube.com/watch?v=QTSWm1RsvzY and as far as I can tell I have everything exactly the same.
As I read online if I enter infinite loop whole editor should freeze, that's not the case.
I also don't get any errors in the console (well, I was getting one, people online said it was due to the lack of subscription to the Unity Version Control so I deleted this package completely but it didn't solve anything)
Here is my code: https://paste.ofcode.org/cfHdGctDZqyMFwMeWtjAM2
If smoothTransition is true, then my character moves by .20 (instead of 1) or rotates by 10 (instead of 90)

In this video we make a super simple first person controller for a grid based dungeon crawler style game. This style of game has been around since almost the beginning of video games, though there's been something of a resurgence of late.

The reason I'm making this video is because I am taking part in Dungeon Crawler Jam 2021, a game jam where ...

▶ Play video
#

It works as expected if smoothTransition is false

rocky canyon
#

i dont see anything in code that could freeze anything..
test to see if its actually freezing?
debug.log in the update for example would be a really simple indicator

languid spire
rocky canyon
#

ohh true!! if those conflict w/ each other or toggle back and forth. the logic might be stuck in an endless update loop..

frail hawk
#

the if (true) triggers me

rocky canyon
#

(not technically frozen) but just not doing anything useful lol

#
if (targetRotation.y > 270f && targetPosition.y < 360f)
{
    targetRotation.y = 0f;
}
else if (targetRotation.y < 270f && targetPosition.y > 0f)
{
    targetRotation.y = 270f;
}``` throw an else in there
#

that way only 1 of those can be true at a time

lyric rapids
frail hawk
#

then at least use a variable there.

lyric rapids
rocky canyon
#
if(eventually){
}```
#

its still an issue..

  • targetRotation.y > 270f && targetPosition.y < 360f is true, so targetRotation.y is set to 0f.
  • Now, targetRotation.y < 270f && targetPosition.y > 0f is true, so targetRotation.y is set to 270f.
#

brrrrrrrrrrrr

languid spire
lyric rapids
rocky canyon
#

just one less thing u have to worry about

languid spire
#

also add some debugging

naive pawn
#

do you perhaps mean <= 360 instead?

rocky canyon
#

tomato tomato?

naive pawn
#

not for floats

rocky canyon
#

ahh tru tru

lyric rapids
#

ye he right but still not the actual problem, its something in here but can't understand what

transform.position = Vector3.MoveTowards(
                    transform.position,
                    targetPosition,
                    Time.deltaTime * transitionSpeed
                );
                transform.rotation = Quaternion.RotateTowards(
                    transform.rotation,
                    Quaternion.Euler(targetRotation),
                    Time.deltaTime * transitionRotationSpeed
                );
naive pawn
#

i mean of course it is since that's the part that will differ between smoothTransition on/off

rocky canyon
#

what if u used a little margin of error? b/c it could be that it never really reaches the target?

#
if (Vector3.Distance(transform.position, targetPosition) < 0.01f)
    transform.position = targetPosition;
else
    transform.position = Vector3.MoveTowards(
        transform.position,
        targetPosition,
        Time.deltaTime * transitionSpeed
    );

if (Quaternion.Angle(transform.rotation, Quaternion.Euler(targetRotation)) < 0.01f)
    transform.rotation = Quaternion.Euler(targetRotation);
else
    transform.rotation = Quaternion.RotateTowards(
        transform.rotation,
        Quaternion.Euler(targetRotation),
        Time.deltaTime * transitionRotationSpeed
    );``` something like this
lyric rapids
#

Will see gimme a moment

rocky canyon
#

would snap it to the desired positon and rotation when its close enuff

steep rose
#

does unity hang or is it just that nothing is happening?

naive pawn
#

this isn't SmoothDamp that asymptotes

rocky canyon
#

or Lerp or Slerp

#

im just spitballing.. as theres nothing really i see in there that would cause a "Freeze"

naive pawn
lyric rapids
rocky canyon
#

lol.. thats usually the case 😅

naive pawn
#

how is targetGridPos set?

rocky canyon
#

so its not unity freezing.. its:

the character becomes unresponsive after a brief moment

steep rose
#

where is your targetposition and rotation if any?

lyric rapids
naive pawn
#

they're set in MovePlayer

naive pawn
steep rose
#

you should probably send the entire script

lyric rapids
rocky canyon
#

nope, all thats still relevant

naive pawn
#

well ok you should probably debug AtRest

steep rose
#

also your IDE will tell you if something is deprecated

naive pawn
#

btw, why are you doing this in FixedUpdate?

#

would probably make more sense to do this in Update

steep rose
#

I was wondering that too

naive pawn
#

sidenote: in AtRest, you can just return the boolean instead of checking if the boolean is true then returning true

lyric rapids
# naive pawn btw, why are you doing this in FixedUpdate?

I'm a web dev who got assigned to make a game for university, I'm making buttons on the website go jumpy when u hover over them n give u directions on google maps to nearest pizza hut, its my first time with unity so i'm following tutorial

naive pawn
#
- if (x)
- {
-     return true;
- }
- else
- {
-     return false;
- }
+ return x;
naive pawn
lyric rapids
naive pawn
#

there's no relevant braces when you return a bool

lyric rapids
naive pawn
#

you should start trying to understand the logic

lyric rapids
#

I read thru that code, after it stopped working I tried to get whatever author of the tutorial had

naive pawn
#

and debug where the logic stops working

sage mirage
#

Hey, guys! I would like to know how to enable and disable my cursor when pausing and unpausing the game?

sage mirage
naive pawn
#

you could set it on awake/start on some central script

burnt vapor
sage mirage
#

I have here an issue you know when I am pressing escape button to resume the game I still view my pointer

burnt vapor
#

In the Unity editor pressing escape enables the pointer again. In build mode this behaviour doesn't exist

#

Something about not locking yourself out

sage mirage
#

Yes basically it is a different question

#

So, in the editor it is enabled everytime?

burnt vapor
#

If you press escape

sage mirage
#

I mean even if I resume the game yes

burnt vapor
#

I don't know if this behaviour can be changed

#

You can implement behaviour around this so it works properly in editor mode, but note in a build this is different

sage mirage
#

CursorLockMode.Locked also hides the hardware cursor. However, the cursor is only locked and hidden after you click in the Game view.

I can't really understand how this behave?

#

I mean locked and confined

#

I mean I see nothing in Game View

#

oh wait give me a sec

#

Yes I have tried them all but didn't notice the difference

#

The only thing that I have noticed is that when I have it Locked I can't interact with my UI buttons and anything in the game view but when it's none I can

zenith cypress
#

Locked: locks to center of screen
Confined: keeps cursor in the window
None: Isn't locked and isn't confined

sage mirage
#

So, when do I have to use those 3?

#

I mean when I want the cursor to be enabled then I am using none but when I want it to be disabled then locked?

#

I am going to test it right now

flat sphinx
#

how do i move an object programatically
first thought was obj.transform.position.Set(...) but that doesnt seem t owork

#

scrap that im being stupid

frail hawk
#

transform.position = new Vector3

flat sphinx
frail hawk
#

but it depends what you want, if you want physics you would not use that

flat sphinx
#

my issue was that i was setting it to itself

rough hollow
#

hey all working on a top down rpg game and cant figure out why my tiles are like making weird black lines when i am moving.. is this my pc issue or something else?

#

pay attention to the pond and the top of one of the trees

#

its like making lines in between my tiles

#

also not sure why the fps dropped a little bit into the recording (sorry)

zenith cypress
# sage mirage So, when do I have to use those 3?
Locked to center of screen + hidden -> Doom, Skyrim, any fps game really

Constrained + visible -> Civilization V, Path of Exile (it's a toggle here)

None + either visibility -> Random indie game off itch where you accidentally keep clicking other apps
flat sphinx
#

does setting position not affect children

rich adder
flat sphinx
rich adder
flat sphinx
#
                var old = map.gameObject.transform.position;
                old.Set(old.x, old.y + 2, old.z);
#

debug code

#

doesnt seem like the map is moving

#

probably am missing something obvious but am too tired to tell

rich adder
#

do you know what Set does?

verbal dome
#

You are modifying a struct in place

rich adder
#

why are you using that

flat sphinx
flat sphinx
rich adder
#

modified structs don't do anything lol

flat sphinx
#

im just doing what the holy editor tells me to do

rich adder
#

which one? I dont think i ever seen Set being used on V3 lol

verbal dome
rich adder
#

youcan do

var old = map.gameObject.transform.position;
old.y += 2;
theThing.position = old``` btw
verbal dome
#

Though you could just do transform.Translate(0, 2, 0, Space.World)

flat sphinx
verbal dome
#

Or transform.position += Vector2.up * 2

flat sphinx
#

no nvm it doesnt lol

#

cannot modify the return value of 'Transform.position' because it is not a variable

rich adder
flat sphinx
#

ah im still doing it inplace nv,

rich adder
#

position.y returns a property

#

so you cannot modify it directly

flat sphinx
#

so


                var old = map.gameObject.transform.position;
                old.y += 2;
                map.gameObject.transform.position = old;
```?
rich adder
#

its like trying to modify a method

#

yes but do you know why?

#

cause you're just changing the copy first

#

structs are copies

flat sphinx
#

had to do the same stuff with transform matrices back on [cursed engine]

naive pawn
flat sphinx
rich adder
#

yup thats just doing old.y = old.y + 2

verbal dome
#

Yeah a += b equals a = a + b

flat sphinx
verbal dome
#

Can't overload operators on existing types though 🤓

naive pawn
flat sphinx
naive pawn
#

also, += can't be overloaded

flat sphinx
naive pawn
#

assignment operators can't be overloaded in general

rich adder
#

there is slight difference ig.
reason+= events since they are immutable and cannot be assigned with =

flat sphinx
naive pawn
#

this has nothing to do with the engine lol

flat sphinx
#

language

#

w/e

verbal dome
#

I did recently see some C++ livestream where the programmer had to separately implement -=, += even after implementing + and -

#

(I think it was c++)

flat sphinx
#

newer versions at least added <=>

#

i personally steer clear of overloads in general, never results in anyhting clean

#

math stuff is typically already implemented for me

verbal dome
#

I don't think I ever needed to use them either

flat sphinx
#

same as properties

#

nothing you cant do with either of those that you cant through regular functions

naive pawn
#

i mean everything is just syntactic sugar for machine code

verbal dome
naive pawn
#

you never need to + stuff though, you could just Add

naive pawn
verbal dome
#

But yeah strings come to mind, its builtin tho

flat sphinx
naive pawn
naive pawn
#

for example, adding 2 stringbuilders together

flat sphinx
#

i guess you could argue for that in cpp land where everything is stapled on top of c

naive pawn
#

by "builtin" here do you mean builtin to the stdlib or to the language

flat sphinx
#

but you already have "" as a core part of the lang here (i think)

naive pawn
#

but either way, you might make your own string-based stuff and want to concatenate them without having to do "" + first because that's more expensive

flat sphinx
naive pawn
#

i have no idea what you're trying to say there

flat sphinx
naive pawn
#

no that's not what im talking about lol

flat sphinx
#

thats the only means i can think to make strings more efficient

naive pawn
#

im not talking about making your own strings

flat sphinx
#

hten what do u mean a string builder

naive pawn
#

i mean making stuff that's based on the concept of strings

naive pawn
flat sphinx
#

json and such?

naive pawn
#

uhh no?

#

like for example you wanted to make format strings, new FormatString("This is a number: %-3d") or something
and internally it was parsed in the constructor, breaking the string up into a list of nodes
then you could overload + to combine format strings by extending the internal list instead of having to reparse a new format string

flat sphinx
# naive pawn that's a separate line of thought lol

shrug what i read was you might make your own string-based stuff and want to concatenate them without having to do "" + first because that's more expensive
reasoned tha tyou meant "make strings more efficient" and by extension "doing your own string stuff"

naive pawn
#

no lol

flat sphinx
#

rip then lol

naive pawn
#

"" + might be unreasonably expensive for cases where you have an internal format that would easily make it more efficient
but like, the structure/overload doesn't have to specifically be for string efficiency

naive pawn
flat sphinx
naive pawn
#

yeah

flat sphinx
#

ah

naive pawn
#

just to recap; you of course, don't need the overload, but given its contextual usage, an overload makes a lot of sense

tiny vault
#

Hey guys, i have this field in an SO. public Transform[] teleportTarget; im trying to assign an empty gameObject to it, but all of a sudden it says type mismatch. If i then click the field and press delete, i can assign the empty gameObject, but it's deleted automatically whenever i run the game. Has anyone experienced something similar? And sorry if im in the wrong channel!

swift crag
#

You can't reference scene objects from an asset.

#

The resulting error is not very intuitive

frosty field
#

alright so i have this script: https://hatebin.com/mnzewoicug
and the thing is, that it works perfectly (except moving camera up and down but i dont care about it right now)
but unity suggest me to use Quaternion.Euler instead of EulerRotation and when i use just Euler for some reason rotatating on left and right doesnt work anymore, i just want to understand why

swift crag
#

did you read the warning message?

naive pawn
#

why not make the camera a child of the player so you don't have to manage the position and yaw separately

swift crag
frosty field
#

yeah but what does that mean

swift crag
#

it uses radians instead of degrees

#

these are two different units

#

2pi radians is a full circle; 360 degrees is a full circle

#

Also, this entire thing is bogus

#

Quaternion.EulerRotation(player.transform.rotation.x, player.transform.rotation.y, player.transform.rotation.z);

#

rotation.x is not your x-axis rotation in degrees (or in radians, or in anything else)

#

It's the X component of a quaternion (which has four values -- X/Y/Z/W)

#

It might have happened to work in some situations

naive pawn
#

also you could just transform.rotation = player.transform.rotation;

swift crag
#

yes, that's all you need to do to copy the player's rotation

naive pawn
#

really you'd need to copy the player's yaw only

#

ie, the rotation about the y axis

frosty field
naive pawn
#

so transform.rotation = Quaternion.Euler(0, player.transform.eulerAngles.y, 0), i think?

naive pawn
flat sphinx
#

i assume unity doesnt have such functions as "get the initial position of an object/state of a variable"

#

? ,

rocky canyon
#

var grabStartPosition = thing.transform.position

naive pawn
#

what, just reversing assignments?

#

that wouldn't work in general, no

flat sphinx
swift crag
#

Serialized properties are applied to the object when it gets created

naive pawn
#

prior to pressing play? no i don't believe there's any mechanism to do so

flat sphinx
swift crag
#

this isn't a C# thing

naive pawn
#

and it'd waste 2x the memory for something rarely used

swift crag
#

drag a prefab into a text editor and you'll see a bunch of YAML

flat sphinx
swift crag
#

this is all of the serialized data for that object

naive pawn
swift crag
#

unity applies it during object creation

frosty field
swift crag
#

I guess you could look at the values on the prefab, if you're using prefabs

#

But Unity isn't going to hang on to the data it applied during object creation

flat sphinx
naive pawn
#

no that's not how any of it works lol

#

if you want to both have the current and a previous value, you have to store both of them. simple as that. if you don't want to store them in memory, it's gotta be in storage, and you have to pull that storage back into memory later anyways

rocky canyon
#

is this still a continuation of array vs json?

swift crag
#

no

flat sphinx
flat sphinx
swift crag
#

this seems irrelevant

naive pawn
#

...because you already waste it?

flat sphinx
#

it is

flat sphinx
naive pawn
#

how is this a valid argument at all lmao

#

"the engine wouldn't waste it because the interpreter would be wasting it instead"

flat sphinx
naive pawn
#

alright i have no idea what you're even saying anymore 😂

flat sphinx
#

lets drop it

naive pawn
#

unity uses a sane language that doesn't use more memory than it needs to, and doesn't waste memory itself, so it doesn't have that feature

flat sphinx
#

: 3

naive pawn
#

what is it with you trying to make ridiculous points that have absolutely no basis lmao
seems like you just irrationally dislike c#/unity and you're looking for any excuse to shit on it for stuff that it's doing right 😂
why are you even here lmfao

tiny vault
flat sphinx
#

this convo isnt me shitting on unity
just asking if it has a feature im accustomed to

#

which i already assumed in advance it doesnt

swift crag
#

to answer the original question: you generally record initial state in Awake or Start

#

Awake is appropriate if you want to grab the value immediately after object creation (literally before the Instantiate call returns)

naive pawn
flat sphinx
#

but again

#

wildly off topi

#

c c

naive pawn
#

doesn't answer my question tho lol

flat sphinx
#

refer to the last comment

naive pawn
#

what, this?

: 3

swift crag
#

consider moving on

flat sphinx
#

^ ^

naive pawn
# swift crag consider moving on

im just curious what language has this behavior now lmao
since lemons can't bear to mention the name, im convinced they're just bs'ing at this point 😂

steep rose
naive pawn
swift crag
#

Consider moving on.

nimble mortar
#

Lets say I have a tilemap like this, what are different method I could use in order to connect the different section dynamically in code?

I would want to make sure I am connecting sections that are within a certain distance of each other and support rigid (straight lines / 90 degree angles) and more organic looking corridors.

swift crag
#

I'm confused by the example.

#

Is this six pre-defined spaces with a couple of obstacles in each one?

#

which you want to link together?

nimble mortar
#

yea, I am trying to figure out how I could connect these currently disconnect area in a tilemap dynamically

fickle plume
#

Just think what you want it to do and break it down to simple tasks. Treat each island as single array collection.
Find nearest island.
Find closest tiles to each other.
Start creating tiles in the nearest direction from them.
Create more tiles around each to create a "bridge volume"

severe onyx
#

is there a way to detect a collision between two objects with BoxCollider2D components if I'm moving one of them via transform.Translate? or do I have to use a rigidbody and move it with that?

naive pawn
#

one of them needs to have a rigidbody to handle the physics

severe onyx
#

one of them does but it's not the one Im moving

naive pawn
#

doesn't specifically matter how they're moved, though moving via transform on a GO with a rigidbody could cause problems

naive pawn
#

just gotta make sure they fix the collision matrix

severe onyx
#

these are the relevant components on the static and moving object respectively

naive pawn
#

a static rb doesn't itself trigger collisions

severe onyx
#

but OnCollisionEnter2D doesnt trigger when they overlap

naive pawn
#

you need a dynamic rb on one of the objects

severe onyx
#

oh I see

#

yup, now it works

#

ty

#

I dont really understand the purpose of a rigidbody on an object that never moves

naive pawn
#

yeah it might not really make sense to have that?

#

is the other object, without the rb, the player?

#

generally that's what's given the dynamic rb

#

then stuff like walls won't need rbs

severe onyx
#

nah it's a projectile

#

but I guess it makes sense to give that one the RB then

naive pawn
#

sure that'd work yeah

severe onyx
#

the other objects are the level constraints (invisible walls)

#

I thought I needed the RB on them to make sure they physically block the player moving through them

naive pawn
#

you could then set a velocity on the rb, set low linear drag, and just, literally fire and forget lol

severe onyx
#

I was worried about performance when there's dozens of projectiles on screen at once I suppose

severe onyx
swift crag
#

You put a rigidbody on something to tell the physics system that it's going to be moving around

steep rose
#

pool them

swift crag
#

I wouldn't even think about performance right now

#

a few dozen projectiles?

severe onyx
#

they despawn when leaving the visible area anyways so

#

or on hitting something, duh

swift crag
#

even if you spawn and destroy these very rapidly, it's not going to be particularly bad

naive pawn
steep rose
#

as long as that area is not huge and there are not hundreds of them you probably are fine

swift crag
#

Pooling is a good idea for when you have a very large number of projectiles, where the overhead of creating and destroying all of those objects gets noticeable

steep rose
#

if you need an abundance of projectiles you should most likely pool them

severe onyx
#

fair enough. just trying to be a bit more diligent about efficiency tha I usually am lol

swift crag
#

(you just recycle the same bullet objects)

severe onyx
#

aye, will look into that as well, ty

naive pawn
#

computers in general are fast

#

it really doesn't depend when the lower end of the scale is still in MHz

severe onyx
#

I mean anything even remotely measured in MHz does a silly amount of operations per second

naive pawn
#

i don't think anyone is gonna expect to run 3d games smoothly in kHz amounts of operations

severe onyx
#

this is a 2d game anyways

naive pawn
#

ah. definitely crossed wires lol, whoops.

#

yeah even less to worry about, then

severe onyx
#

I'll make sure to report back and blame you specifically if it ever runs choppily 😌

naive pawn
#

a drop in the bucket of me blaming all the problems in my own game on myself lol

severe onyx
#

jokes aside, thanks for the help

#

more than anything this is an exercise for me to explore all these questions and discover best practices

fickle plume
severe onyx
severe onyx
naive pawn
#

yeah

severe onyx
#

I swear I can read

naive pawn
#

could use AddForce

steep rose
#

even if you wanted to use translation, it would cause unreliable collisions when using a rigidbody

naive pawn
#

and then you would multiply a normalized direction vector by a given magnitude
there was a similar convo, it was either impulse or velocitychange

#

impulse would be mass-dependent, velocitychange would not

steep rose
#

so it's much better to use one of the physics methods for it

severe onyx
#

gotcha. physics stuff seemed overkill for what Im trying to do because I dont have any gravity or anything like that acting on it, but I suppose it makes sense for collision detection purposes

naive pawn
#

if the mass of the bullet doesn't matter (and is set to 1) then both would have the same effect, but you might want to use the bullet mass for stuff like, recoil or knockback, idk

fickle plume
severe onyx
#

I've been wondering a lot about Update vs FixedUpdate

#

FixedUpdate is recommended for stuff that needs to happen at a consistent real time frame regardless of the framerate, is that the idea?

naive pawn
#

right

#

Update = frame
FixedUpdate = physics tick

steep rose
#

use any rigidbody/physics based methods in it as it produces better results

naive pawn
#

and FixedUpdate has a specified tick rate that it'll process physics stuff by

steep rose
#

and is not framerate dependant

severe onyx
#

I remember learning to multiply stuff with time.deltatime way back in the day to account for framerate differences but this is discouraged for a bunch of reasons I take it?

naive pawn
#

no, that's fine

#

it's just more about, what makes sense where

steep rose
#

you shouldn't do time.deltatime in rigidbody (i.e addforce) methods as it does it already but in general it's fine

severe onyx
#

gotcha

real grail
# severe onyx gotcha

Good rule of thumb if you are messing with physics components like rigibody. Run it on FixedUpdate and do Time.fixedDeltatime.

prime goblet
#

you don't need that either

severe onyx
#

50hz is the standard polling for FixedUpdate yeah? and presumably this should be sufficient even for fast paced 2d games?

steep rose
naive pawn
#

some stuff in rb methods are inherently time-dependent, so they do stuff basd on physics ticks
but not all of rb methods are time-dependent

prime goblet
#

all physics uses fixed physics generally i think

fickle plume
steep rose
#

and this this

naive pawn
#

MovePosition, for example, just does the move in the next tick, so if you're using that as a replacement for transform.Translate, then you would add a time component to that

#

(or, i mean, you'd use MoveTowards.)

fickle plume
#

You would use Time.fixedDeltatime inside a coroutine that awaits fixed frames and you need to get that time frame, for example.

severe onyx
#

I ended up going with the velocity approach for the projectiles for now either way

#

assuming all the internal logic still happens on fixedupdate ticks but it is indeed nice to just "fire and forget"

naive pawn
steep rose
naive pawn
#

i mean, idk what you meant to talk about, since "rb methods" does encompass moveposition and friends

steep rose
#

ah right, I should have been more specific

cold pier
#

Hello everyone,
I start to create games and here’s my problem.

Every time I transfer my image and they cut them in 16x16 or 32x32 for example. I create my Palette then I insert and the images are small in the grid ( I'm french)

naive pawn
#

(not a code question)

slender nymph
cold pier
slender nymph
#

dang i was too slow lol

cold pier
#

Have a nice night and thank you

wispy coral
#

hey yall how do i make code thats not a bunch of if statements

#

is it just practice and more knowledge?

slender nymph
#

also don't be scared of if statements. they are perfectly fine

wispy coral
#

nice

#

thanks

flat sphinx
#

you can research guard clauses if you want

#

thats a p easy way to deshittify your code

cosmic charm
#

and here is the code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Clone_Skill : Skill
{
    [SerializeField] private GameObject clonePrefab;

    public void CreateClone(Transform _clonePosition)
    {
        GameObject newClone = Instantiate(clonePrefab);

        newClone.GetComponent<Clone_Skill_Controller>().SetupClone(_clonePosition);
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Clone_Skill_Controller : MonoBehaviour
{
    public void SetupClone(Transform _newTransform)
    {
        transform.position = _newTransform.position;
    }
}
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class PlayerDashState : PlayerState
{
    public PlayerDashState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName) : base(_player, _stateMachine, _animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();

        SkillManager.instance.clone.CreateClone(player.transform);

        stateTimer = player.dashDuration;
    }

    public override void Exit()
    {
        base.Exit();

        player.SetVelocity(0, rb.velocity.y);
    }

    public override void Update()
    {
        base.Update();

        if(!player.isGrounded() && player.IsWallDetected())
            stateMachine.ChangeState(player.wallSlide);

        player.SetVelocity(player.dashSpeed * player.dashDirection , 0);

        if(stateTimer <= 0)
            stateMachine.ChangeState(player.idleState);
        
    }
}
polar acorn
#

What line has the error

faint osprey
#

Debug.Log(shopRT.position.x);

im debugging my position in update just to check stuff and its not showing correctly to what it is in the inspector and i dont know why this is

#

it says my x position is -8.5

#

but in the inspector

#

its 33 for some reason

swift crag
#

That's because position is your world-space position

#

The inspector is showing you a local-space position

#

This isn't anything specific to a RectTransform, mind you

#

you'd see similar things with a regular Transform

#

Your local-space position is where you are relative to your parent. If you have no parent, then it matches your world-space position

faint osprey
#

if i change it to localposition.x

#

it says -927

#

which still isnt 33 tho

swift crag
#

Ah, the other issue is that this is anchored to the left side of its parent

#

you could check if this is why by anchoring it to the center and setting Pos X to 0

#

I'd expect a local position of zero, then

swift crag
#

It's 33 units to the right of its anchor, but that's quite a few units to the left of the parent Transform

faint osprey
#

thank you that makes a lot of sense

real grail