#💻┃code-beginner

1 messages · Page 745 of 1

brave compass
#

It's the difference between asking for contact 0, and asking for all the contacts and then picking out just the first one and throwing away the rest.

tender mirage
#

i better get used to GetContacts then. thanks for the advise. i'll let the below get help now

floral garden
#

with the slider
how can I set a function that take a float or int , can I call it everytime I update the slider ? I forget how to do it

polar acorn
wintry quarry
#

fix this as digi said

#

Since it says 0 there right now it will always feed in 0 as the parameter

floral garden
#

hum

odd remnant
#

This worked nearly perfectly, but I think I want a SpringJoint, rather than a HingeJoint. It makes the object move in 3D rather than on a single axis. Thanks for the tip.

#

Now I'm deep in Spring Land, trying to figure out why this thing is CRAZY

#

The HingeJoint was a lot more stable, and tended to settle in the middle of the screen where the invisible grabber is. But the spring joint almost wants to remain constantly at motion.

formal swan
#

Hi! I'm trying to make a camera pan to the right when I click a certain button

near wadi
#

!learn

radiant voidBOT
near wadi
#

!code

radiant voidBOT
slim spade
#

Oh

#

Okay

civic gust
#

Hello. When moving in a specific direction and checking distance between object position and destination position to snap, how to not fly over the object?

Theoretical example:

bool isMoving;
float speed = 10;
Vector3 finalPosition;

private void Update()
{
    if (!isMoving)
        return;

    Vector3 direction = GetDirectionToPosition(finalPosition);
    transform.position += direction * speed * Time.deltaTime;

    if (Vector3.Distance(transform.position, finalPosition) <= 0.1f)
    {
        transform.position = finalPosition;
        isMoving = false;
    }
}

In the example above we can fly over the destination if our fps is low without snapping. Can someone help me with a good approach here?

slim spade
#

I'm sorry

near wadi
#

ACK

formal swan
near wadi
#

nevermind me. i thought i was in general chat

near wadi
slender nymph
formal swan
near wadi
formal swan
#

Ok thanks, wish me luck 👍

civic gust
slim spade
true pine
#

I never got any help on this

#

so I'm bumping it with some clarification

#

the reason the material's on a quad is because of the particles attached to it

#

its a prefab

#

so how can I orient it to face away from a surface it's on

civic gust
midnight plover
true pine
#

and how would I do that

#

I'm 100% doing something wrong here but idk what it is

#

it always faces towards positive Z

edgy sinew
#

Hi, is there a way to avoid Dictionary or Hashset lookup with State machines?

It seems pointless in state machines where all transitions from one state to another are pre-defined. Technically no lookup is needed, each state already knows the other states it goes to before program runs.
But how would that work then? I want to avoid reference nightmare on Awake() but also avoid runtime lookup.

// processed by state controller, Dictionary/Hashset lookup
public int nextStateHashedValue() {
    if (...)
        return hashOtherState1;
    return this.hashedState;
    // in the Controller, myStates[this returned value]
}

// return the new state directly (requires pre existing reference?)
public State nextState() {
    if (...)
        return ??????; // state member variable that has to be assigned in Awake()?
    return this state, but the instance, somehow???;
}

I've seen people do like, a bunch of addTransition(stateToSwitchTo, Func<bool> condition) on Awake() but I prefer to write the state logic by hand. So I have this dilemma.

#

⭐ TLDR;

if (nextState != 0)
    currentState = myDictionaryOfStates[nextState];
// etc```

```State nextState = currentState.getNextState();
    if(nextState != currentState) // or some kind of integer comparison whatever etc.
        currentState = nextState; // NO DICTIONARY OR HASHSET LOOKUP

How to achieve 2nd behaviour where no lookup is needed? Without reference nightmare of instances in Awake?

true pine
midnight plover
true pine
#

I'm not well-versed enough in this stuff yet

midnight plover
true pine
#

yes

midnight plover
#

and what does that raycast?

true pine
true pine
midnight plover
midnight plover
# true pine

I advice you google those types you are using like raycast and raycasthit and see, what the docs tell you about it. You shoot a ray, it hits something, what info does that hit point give you

true pine
#

that's over in this function

midnight plover
edgy sinew
#

I also want to avoid doing this in Awake.

myStateInstance1.stateToSwitch2 = myStateInstance7;```
#

But there's no way right? blushie

midnight plover
midnight plover
edgy sinew
#

I already gained some FPS and stability by switching to int lookup over string Keys

midnight plover
edgy sinew
#

Yes thanks for help. I'll just leave it that way, it's not worth ruining the code. I hoped there was another way

midnight plover
edgy sinew
silk night
#

oh nvm, my discord just didnt load properly while scrolling up 😄

silk night
#

you could probably do hundreds of thousands of lookups per frame without your fps dropping below 30

edgy sinew
silk night
#

at that point the editor is limiting your fps

edgy sinew
#

With string lookup it was like 240-320. Int lookup, 380 consistent

#

Yeah ofc

silk night
#

you are doing whats called premature optimization

edgy sinew
#

I can prob get more in build

true pine
edgy sinew
#

Yeah i am. I'm writing "the final code"

#

I'm on like version 40-50 of my scripts so... Yeah

#

I'm cutting out everythign I can, optimizing evrything I can

silk night
#

let me make this clear, nobody is EVER gonna write the final code 😄

edgy sinew
#

But they dooooo though

#

Maybe not modern unoptimized poopoo

#

Older games run like a Toyota bro

#

🥺

edgy sinew
#

There I'm only getting 180 FPS, so I'd like to support that level of machine too

true pine
edgy sinew
#

Still got a lot of game to add, so. Every optimization counts notlikethis

silk night
edgy sinew
twin atlas
#

Does anyone know codes for a unity game?

edgy sinew
true pine
polar acorn
polar acorn
edgy sinew
silk night
edgy sinew
#

bro gave homie his first error

polar acorn
true pine
twin atlas
#

Specifically there’s a game called BUILDNOWgg

midnight plover
edgy sinew
polar acorn
twin atlas
#

No

polar acorn
# twin atlas No

Then whatever you're about to ask is best asked to them, not us

silk night
midnight plover
true pine
edgy sinew
polar acorn
#

!code

radiant voidBOT
edgy sinew
#

Hasn't been clear to me and i've been reading all day ur posts

languid pagoda
#

is there a way to include a non unity c# project in the sln that unity generates?

edgy sinew
#

Are u trying to apply a decal onto a surface or something?

true pine
#

I've been following a tutorial that appears to be getting less and less useful as time goes on

midnight plover
true pine
#

and by useful I mean it's shit

edgy sinew
#

"a tutorial"? you mean you don't have 4 open at the same time?

odd remnant
#

If I'm making, say, 100 nearly-identical objects, with identical rigidbody and Box Collider settings - is there an easier way to do that than copy-pasting 100 prefabs? Say, if someone accidentally removed a rigidbody or collider component from one object, it'd be a pain in the butt to track it down.

edgy sinew
#

To check which info is the best? Which method is right for you?

true pine
#

ok hang on a minute

edgy sinew
true pine
#

damn

true pine
edgy sinew
#

Object Pooling allows you to have 100s of prefabs "ready to go" at anytime. Whenever one is needed, you simply "activate" it, rather than actual Instantiate and Destroy which are slow.

languid pagoda
polar acorn
true pine
#

how so

odd remnant
polar acorn
#

I would like to see the code, not the ads or their algorithmically chosen pastes

edgy sinew
true pine
#

hhhhh

edgy sinew
#

nvm looks like prefab variants was it

languid pagoda
true pine
#

why does it not preview what

edgy sinew
polar acorn
true pine
#

cos it needed a quaternion thing

languid pagoda
polar acorn
#

So, if your surface normal is straight up, you'd have a direction vector of 0, 1, 0, which is going to give you a rotation of one degree about the Y axis

edgy sinew
true pine
#

it goes to the right spot, texture and particles are just fucky

polar acorn
#

It's utterly unuseable

true pine
edgy sinew
#

speaking of Object Pooling - please get the Instantiate outta there ASAP 😭

true pine
polar acorn
true pine
#

I had no idea that was bad practice

true pine
polar acorn
#

If you look at the prefab with the transform gizmo on, which arrow is pointing in the direction you want the bullet hole to be facing

#

Like, is it the front you want to see it from? The top? Depends on the orientation of your prefab

true pine
#

well the direction depends on the angle of the surface it's hitting

polar acorn
languid pagoda
edgy sinew
# true pine I had no idea that was bad practice

nah ur fine, yeah it's very expensive to Instantiate and Destroy at runtime
Object Pooling is kind of like, having all the Lego pieces ready from the start of the program. And you just turn them on or off as needed, never creating or destroying from a memory standpoint.

true pine
#

Z axis apparently

languid pagoda
#

this code is awful sir please do not follow anymore tutorials from the same creator.

edgy sinew
#

Tried Debug.DrawRay? stonks

polar acorn
#

You might need a -direction instead depending on whether it's facing towards the Z-axis arrow or away

polar acorn
true pine
#

crazy, allat for a 1-line edit

polar acorn
#

It's not degrees, so Quaternion.Euler makes no sense

languid pagoda
#

Guys why are we trying to fix this code instead of advising him to start over?

 if (tags.Contains("modBurstFire"))
        {
            attemptingToFire = Input.GetKeyDown(KeyCode.Mouse0);
            if (canShoot && attemptingToFire)
            {
                burstBulletsRemaining = bulletsPerBurst;
                Shoot();
            }
        }
        else
        {
            attemptingToFire = Input.GetKey(KeyCode.Mouse0);
            if (canShoot && attemptingToFire)
            {
                Shoot();
            }
        }

like what is this atrosicity aint no way we are using tags for this.

edgy sinew
#

State pattern moment?

true pine
#

the hell is a state pattern

edgy sinew
#

State, Object Pooling, Coroutine...

#

This code needs a lot, and it's not even 200 lines

true pine
#

I'm just gonna go ahead and retire...

languid pagoda
#

Dont retire

#

just find better quality sources of knowledge

polar acorn
true pine
#

clearly the guy in the tutorial was mentally disabled or some shit

edgy sinew
#

With that kinda code, you might need an Intel i9 processor just to shoot some bullets around lol

#

So, give State and Object Pool a read. It's a beautiful thing, trust me

#

State especially. It's so easy, once you have it set up, to literally add anything you want

true pine
#

fuck this guy in particular

edgy sinew
#

You can probably add diving & swimming to your character in an hour, if you have animations ready

polar acorn
edgy sinew
#

18.9k subscribers? 😥

edgy sinew
polar acorn
#

But you won't end up making something actually good on your first go around. Or second or third

#

or, at all really

true pine
edgy sinew
#

@true pine in the URP sample projects they have decals

#

Should be easier to do than what you have currently

polar acorn
#

Sometimes you just need to step on the rakes until you figure out why you shouldn't be doing them

#

So just keep making stuff, honestly. Ship of Theseus this into something workable

true pine
#

never have been

midnight plover
#

A good skill to learn, never to late

polar acorn
edgy sinew
#

Never speak those words again, we're all at some point on that same ladder.

#

Maybe except for digiholic, he knows everything I think.

true pine
#

maybe

languid pagoda
# true pine maybe

its ok your next problem after solving this would have been "why does my firerate fluctuate with my fps"

odd remnant
#

And also, everyone has different interests and strengths. Expecting to be a solo dev out of thin air happens to 0.00000000000000000001% of the developer population. Most specialize in a specific area - programming, 3D Modeling, Animation, 2D/UI.

polar acorn
edgy sinew
#

(this is ragebait)

true pine
edgy sinew
#

Aye u can send stickers tho

#

Whoever designs these, I hope they're paid well

true pine
#

none convey the emotion quite the same as that one dog with closed eyes

#

chat done got quiet

languid pagoda
midnight plover
edgy sinew
#

it's wild enough with words ngl

#

gifs might be too much

slender nymph
polar acorn
true pine
edgy sinew
true pine
#

change the numbers, change the model, have some code that changes the text on the info card, update visuals/sounds, bam. new weapon

edgy sinew
#

Many ways to skin a cat or whatever they say

rocky canyon
#

more than one way*

true pine
nimble apex
#

putting "Sprites" inside SO isnt that expensive right?

[field: SerializeField] public Sprite Icon { get; private set; }```

i mean something like this
languid pagoda
true pine
#

...had a realization that maybe the particle effect and the bullet hole texture shouldn't be connected to one object, cos if I shoot something with physics, the bullet holes just kinda chill in the air

edgy sinew
# true pine see I never knew these existed

So, you have some base "Equippable Thing" class... then you have a "Fireable" that is not only equippable, but also can be aimed & fired... a "Throwable" that can be thrown rather than fired... Etc

slender nymph
languid pagoda
edgy sinew
#

So when you go to equip a new item...
You're not equipping a firearm, or throwable
You're equipping EITHER of those things, and the computer will allow either to fill the slot

#

Then you just have different behaviour depending on what's equipped ...

#

This is called Polymorphism

true pine
#

yeah, the idea was for a ranged slot, a secondary that can be anything, and a melee

edgy sinew
#

So, like every shooter game ever basically 🙂 mine included (WIP.. can't even shoot yet)

true pine
edgy sinew
#

I might have a video that explores some valuable strategies.

#

Haha me too. It's always <popular game> but with <your spin on it> remember that

languid pagoda
#

I personally take a different approach but this a very solid way to do it.

true pine
#

I've been getting ideas for the greater majority of 2 years

#

slowly building the concept of this game

edgy sinew
#

Composition instead?

true pine
#

I just want the game to be popular enough to get its own community, doesn't need to be some award-winning legendary game

edgy sinew
rocky canyon
#

but its unique, never been done before

edgy sinew
#

Lol

#

But, I'd work 10 hours a day doing something I love, even if it's average money

true pine
#

yea

nimble apex
#

mine is stardew valley but with more multiplayer element, making it like a party game in endgame

#

so yeah, the formula still works

edgy sinew
#

need the spiderman pointing at each other GIF

rocky canyon
#

mine is a FPS but you're playing only with the minimap 😉

true pine
#

I wanna take my time but I kinda can't cos it's only a matter of time before I end up doing 9-5 slave labor

nimble apex
#

and remember, no matter what games ur trying to make, u only succeed when u can build the whole thing out 🤣

languid pagoda
rocky canyon
#

9-5 slave labor is super common.. alot of us fall in that category.. you have to do ur 5-9 after the 9-5

edgy sinew
winged ridge
#

If it helps I'm on 11pm-7am then coding

rocky canyon
#

👀 ☝️ see

true pine
edgy sinew
#

Learn state, object pool, inheritance, polymorphism, at the minimum trust me

#

Or you're gonna end up with code that is very hard to upgrade, change, maintain, improve

true pine
edgy sinew
#

SRP too, single responsibility principle

nimble apex
#

im more of a minecraft fan rather than roblox lol

languid pagoda
rocky canyon
edgy sinew
#

I'm saying, just to have a character moving around, pick up items, maybe use them, put them back

#

That's already gonna be hell without the strategies I mentioned

nimble apex
#

i like interfaces more rather than virtual/override now

edgy sinew
#

Then you wanna turn it into a full game? Yeah no. Not without those patterns

#

I had like 3,000 lines in my Player_Controller.cs, now it's all separated by responsibility ...

true pine
edgy sinew
#

Camera related stuff, animation related stuff, interacting with nearby items stuff, etc

rocky canyon
#

learn, input class, save system, menu/pause/exit system, and settings system
alot of this stuff is put off way too long

edgy sinew
#

All separate scripts, separate configurations, only accessing each other when needed

true pine
#

ok yall making a huge list for me here

nimble apex
edgy sinew
#

You best be writing down a TODO list

rocky canyon
#

lmao.. the more the merrier 😄

edgy sinew
#

I wish someone told me this when I started

winged ridge
true pine
edgy sinew
#

Well, @rocky canyon did but I didn't listen

rocky canyon
#

it happens 😄

true pine
#

how should I prioritize this stuff exactly

rocky canyon
#

just get familiar with the engine first..

edgy sinew
#

Well movement is #1

#

The main thing is to not dig yourself into a hole... "Tech Debt" it's called

true pine
#

movement is mostly ironed out already

edgy sinew
#

Dirty code, 3,000 line files

nimble apex
#

the hardest part is to pack ur code to make it look more precise and tidy

true pine
#

I don't have very many issues or things to expand upon there

true pine
#

making it exist/work first

winged ridge
edgy sinew
#

If your Update function ends up looking like this... You're probably doing fine and you can build a whole game

void Update() {
    readInput();
    checkIfGrounded();
    calculateNextPosition();
    calculateNextRotation();
    moveToNextPosition();
    // etc
}

See how it's English? It's step by step? Someone who's not a developer could probably get the idea.

#

So when you revisit some part of the code, oh guess what, it's in freaking plain English what is happening

edgy sinew
# true pine making it exist/work first

I usually do "make it exist/work" or "find out if it's even possible to do this in this way", then "OK it's possible let's make it clean and easy to work with."

#

DRY, ETC - two great programming principles.

#

It's tempting to just "keep going" but that's how you make a spaghetti mess.

rocky canyon
edgy sinew
#

You wanna add jetpacks to your game in 2 hours? Or you want it to take 8 hours and always bugged?

#

Yes. Learn and experiment, then determine the best way to accomplish the thing, and clean it up

rocky canyon
nimble apex
rocky canyon
#

getting laughed at.. and roasted for my else-if chains

edgy sinew
#

Okay that's enough gold in the chat. Cya later Homies uwu

true pine
rocky canyon
#

practice..

#

exposure

polar acorn
winged ridge
#

Ask it on a date

rocky canyon
#

just take a bit of time to look thru the engine..

#

the menus..the components.. the settings

edgy sinew
#

Want some more advanced videos? You'll be exposed to more complex stuff.

#

It's important to know, how much you don't know.

true pine
winged ridge
true pine
#

this a good list?

edgy sinew
true pine
#

in order of importance

rocky canyon
#

kinda hard to do that when u dont know what words to use

true pine
rocky canyon
#

avoid Code-Monkey until ur more experienced 😄

midnight plover
winged ridge
#

One of the best ideas is to have scripts related to feature: so player movement should be in one script
Enemy movement in another
Combat in one script etc and block it off in modules (allows you to share your modules between units)

true pine
#

HOLY FUCK THIS IS SEB LAGUE

#

I KNOW THIS GUY (kinda)

#

I'M SAVED

rocky canyon
#

awesome! yea hes great

#

no - nonsense just info

nimble apex
#

theres gotta have something more to split

midnight plover
rocky canyon
#

nah.. its all relatively the same..

#

code doesnt change..

#

velocity is now linearVelocity..

#

thats about it 😄

midnight plover
#

yah well, you are right. if its just about coding and not unity UI setup stuff

edgy sinew
# true pine this a good list?

DRY, ETC (Clean Code principles)
FixedUpdate vs Update (if you need Physics, that's a rabbit hole to go down Tbh but it's solvable)
Minimizing garbage allocation (eventually)

rocky canyon
#

i used it as a crash-course basically

winged ridge
#

A good test to do is take the unity modules or vector etc, mathf.abs and all of those methods and write your own to use instead

rocky canyon
#

^ i was guilty of this ALOT when i first started

#

writing out my own logic and then someones like why not use "thisClass.ThisFunction();"

#

i was always like.. u gotta be kidden me

#

still happens.. just not as often anymore

nimble apex
#

and we improve from these little hints

#

bit by bit

#

and now im obscessed with linq queries

winged ridge
#

Writing your own logic allows you to understand how the methods work and the code behind it.

edgy sinew
# true pine thank you so much, anything but the jackass I was watching before

https://www.youtube.com/watch?v=jSauntZrQro
https://www.youtube.com/watch?v=NsSk58un8E0
https://www.youtube.com/watch?v=YR6Q7dUz2uk
https://www.youtube.com/watch?v=YdERlPfwUb0
https://unity.huh.how/lerp/wrong-lerp
https://youtu.be/qPQkFYt7smk
https://www.youtube.com/watch?v=QzMIi2gKB1A

These videos will show you some of the more tricky/complex stuff that can be done in Unity. Remember even great channels like Jason Weimann make mistakes, and even have multiple videos for same topic.

nimble apex
# nimble apex and now im obscessed with linq queries

it really compress ur iterations, u might need 3 foreach loops to do stuff, but if u can write a correct query, u can do something like

foreach(int element in numbers.where(x=>.....).select(x=>...))```

instead of 
```cs
foreach(....){
  ->  foreach(....){
      ....
edgy sinew
#

git-amend another great channel. Would you look at that, his latest video is about decals lol

odd remnant
#

Can anyone speak to their experience either splitting out or combining functions? I have this Grabber class that allowsme to pick up items, and I want to add the ability to bring items closer or further from the camera using the scroll wheel. I could see us making two functions - one for bringing the item closer, and one for sending it further. Or we could make a single function that takes the Scroll Wheel value as a parameter, and then moves the object based on that parameter.

Any thoughts?

polar acorn
edgy sinew
#

Why do we need 2 functions? This can be done in Update() with SmoothDamp or however you like

odd remnant
#

Not quite. The Player Class manages the input from the scroll wheel. When the scroll wheel moves, it calls a function in the Grabber Class. Either one of two functions - decrease distance/increase distance, or a single function: ChangeObjectDistance.

#

And the distance that the object moves will be a variable that I'll tweak to make a smooth movement feel to it.

grand snow
#

thats worse 😆

nimble apex
#

lol

grand snow
#

probably fine when not done too much all the time

odd remnant
#

You're saying the scroll value alone would suffice?

grand snow
#

sorry talking about linq myself

odd remnant
#

Oh, haha

grand snow
edgy sinew
# odd remnant You're saying the scroll value alone would suffice?
float epsilon = 0.08f; // Snapping distance
void Update() {
    if (Mathf.Abs(desiredItemPositionFromScrollWheel - currentItemPosition) > epsilon)
        currentItemPosition = Mathf.SmoothDamp(...) // or however u like
    else // Probably not great to assign this every frame, maybe check equality first too
        currentItemPosition = desiredItemPositionFromScrollWheel; // Snap to exact desired value
}
#

I'm curious if it can get more efficient than this, assuming the scroll wheel should be read every frame.

#

There's no need to overcomplicate. Doesn't matter where you call the functions (WHEN probably matters though), where the data is stored, how you read the input. Get access, and do what's needed. Or if nothing is needed, do nothing

midnight plover
#

Thats some dangerous advice there 😄 "Doesn't matter where you call the functions"

edgy sinew
rocky canyon
edgy sinew
#

Why? it only provides delta rather than an absolute value?

midnight plover
rocky canyon
#

i can't remember.. it was a zoom on a top down strat camera..
and i was doing audio clicks w/ it..

#

i cant remember the exact issue.. but it took me a while to get it worked out where it smoothly worked.. (didn't overshoot) and the audio sync'd up nice and pretty

edgy sinew
glad shore
#

How can i get this option on the material i want to put the shader on, i dont want to have multiple shaders with just a texture difference

rocky canyon
#

proper naming of classes/methods/and variables help out tremendously

#

they can almost replace comments if they're good

languid pagoda
#

is there a way to add an external project to the solution that unity generates?

rocky canyon
#

ofc' i use xml summaries now

edgy sinew
rocky canyon
#

camel case functions... ewww

edgy sinew
#

I'm a huge advocate for code that speaks for itself. Plain English, as much as possible

rocky canyon
#

😛

true pine
#

I prefer this

rocky canyon
#

its your code..

polar acorn
glad shore
edgy sinew
#

check_if_grounded() notlikethis

#

ew

languid pagoda
rocky canyon
edgy sinew
rocky canyon
#

lets go! lmao

#

i'd be happy.. but probably wouldnt use em

true pine
#

idk who would

#

unless it's a device to help them remember stuff

rocky canyon
#

they show up in my comments sometimes

languid pagoda
rocky canyon
#

just for quick reference..

#

// 🎮 Input for example

#

but very rarely

true pine
#

uh unrelated but how would I change my mouse controls in the editor

#

I wanna swap middle mouse and right click so it's more like blender

rocky canyon
#

i didnt know u could open two solutions in one window

#

or if rather

languid pagoda
#

no i mean like I have an asp.netcore app that I use for authing players who logged in. I open that in one visual studio instance then another visual studio for my unity project.

#

I would love to be able to attach the asp.netcore project to the solution unity generates but its not looking like its possible

slender nymph
#

unity doesn't even support nuget packages, of course it won't support completely separate projects

midnight plover
edgy sinew
# odd remnant Not quite. The Player Class manages the input from the scroll wheel. When the sc...

Any news here? I wanna help but you haven't posted any code. And what you said wasn't relevant to the solution I posted - doesn't matter if you have delta scroll position or absolute scroll position, that code works fine.
And if you aren't using either of those, please educate us on how you get scroll wheel input.

Maybe use a Curve for smoothness. Something like, difference in position vs. max distance to move this frame perhaps. SmoothDamp is usually good enough but I use Curves cause they're fun.
Here's a simple ScriptableObject class so your Curves don't reset when you exit Play mode.


[CreateAssetMenu(fileName = "CurveAsset", menuName = "Scriptable Objects/CurveAsset")]
public class CurveAsset : ScriptableObject
{
    public AnimationCurve curve;
}```
Hope this helps. I didn't mean to be rude when I said it sounds like things are being overcomplicated.
languid pagoda
edgy sinew
#

PS - not sure if [SerializeField] and public are equivalent 👌 experts chime in

midnight plover
midnight plover
rocky canyon
#

public fields are accessible outside the class

edgy sinew
#

Oh last note, with a Curve make sure to have a minimumAmountToMoveThisFrame clamp or it may never resolve, just keep doing float math

slender nymph
odd remnant
#

Thanks for the feedback though, it helps in the next step of this.

languid pagoda
#

Im using visual studio not vscode. So its an asp.netcore webapi player sends credentials to webapi and then gets a token back in return that is used to verify if authenticated. both the web api and the unity project rely on some POD classes, so I have a visual studio solution with the webapi and a "shared" dll that is referenced by both unity and the webapi. It is currently under development so when I build the shared dll it executes command in visual studio to copy the dll to the plugins folder in unity. Only problem is you cant just copy it in like that it fails every time unity is preventing it. So anytime I need to make changes to shared.dll i have to go into unity delete the existing one then copy the freshly built one from the output directory to the plugins folder. Its annoying and inefficient

edgy sinew
# odd remnant Lol, you didn't exactly answer the question I was asking, but you did propose so...

AFAIK the question you had was to use 1 function or 2 - the answer I gave was none at all and to just use variables (desiredPosition, currentPosition) with every-frame checking (if in the right state) as I wrote out (Events wouldn't save much FPS unless the scrolling won't be happening every frame when object equipped)

There's a great video from Toyful Games about Springs, that could be worth looking into as well. That's where I first saw this kind of "set the DesiredValue when needed and the per-frame code just handles it" But there can be issues with overshoot.
https://www.youtube.com/watch?v=bFOAipGJGA0

Meet the BEST Game Feel method you've never heard of! Very Very Valet is available now for Nintendo Switch, Steam, PS5, and Epic Games Store
https://toyful.games/vvv-buy

~ Ryan Juckett's Excellent Spring Code ~
https://www.ryanjuckett.com/damped-springs/

~ More from Toyful Games ~

  • Physics Based Character Controllers in Unity - https://www....
▶ Play video
silk night
edgy sinew
#

It's not my goal to know your exact use case 🙂 - hope the knowledge helps even if it's not exact to your case.

odd remnant
#

and this:

edgy sinew
#

Uh huh.

#

Yeah please give it a try "DesiredPosition" and "CurrentPosition", with the every-frame if (different < epsilon) that I wrote

#

I literally see nothing that doesn't make this the optimal and simple solution

#

SmoothDamp already does some epsilon stuff internally so that's optional

silk night
edgy sinew
#

Done ... Then in Update, check if any change is needed... Dead simple

edgy sinew
#

Guys i just got validated by SpawnCampGames

odd remnant
edgy sinew
#

The smoothing algorithms legend himself 🔥 Ahhhh today is, a day

edgy sinew
rocky canyon
#

i have 1 for almost everything, position, rotation, scale, and more

edgy sinew
#

i wish SmoothDamp was more configurable so i didn't have to use Curves

rocky canyon
#

now i want to spring a color 👀

languid pagoda
silk night
odd remnant
#

Vengeful, I'm working on it. I'm not even turning your suggestion down - I'm learning how to use it.

#

I just don't have an instant response to you because I'm working through new functions I've never used before.

edgy sinew
#

Just seemed like what I said got shot down that's all. Yes trust us, this is the way. It's not even my knowledge, I learned this from the people here lol (and YouTube videos confirm.)

languid pagoda
# odd remnant and this:

Personally I would do the two method idea, that way later if I want to execute it manually instead of via the scroll wheel I have that ability. If you know for a fact you're never going to do this vengefuls suggestion is the best way

edgy sinew
#

It can hard to achieve some behaviour, whilst having the computer do as little work as possible. That's what we're here to teach about though

glad shore
#

is there a easier way or do i have to turn it into an array

Animator[] _oldAnimators = _oldDoors.ToArray();
_oldAnimators[0].Rebind();

_oldDoors is a list of Animators

odd remnant
cosmic dagger
odd remnant
#

We're getting into "How much user customization do you want to give the player" territory. And admittedly, thinking about potential accessibility controllers...maybe I'm wrong.

cosmic dagger
edgy sinew
#

For example in most games, movement is affected not only just by the player control, but how much items are in their inventory (weight), debuffs, etc.

rocky canyon
#

Over Cucumbered

rocky canyon
edgy sinew
# odd remnant Yeah, I'm mulling it over. I think the only way the player will do this is by sc...

The BOTTOM LINE is that you always have, some desired item position and some current "Item position based on scroll (& other factors)" right? So that system ONLY does that 1 thing

This is called Single Responsibility Principle. Where you get the inputs from, what extra modifiers and logic go on top of that, that's all cool. But the system, is the system

You shouldn't have to change the actual system, to add more or different functionality

rocky canyon
#

but yea, good example..
lots of things in a game can be affected by different mechanics
a + b is a really nice mindset to have handy for alot of things
and its clean b/c u don't have to toggle off that functionallity.. just set it to 0 to ignore it..
a + 0 = a

#

Moar Modular

edgy sinew
#

In other words, when an item is equipped, the game always brings the ItemCurrentPosition towards the ItemDesiredPosition, smoothly.
How those are calculated, how much change happens each frame, what kind of controller the user uses, is all separate and unrelated to the main item-relocating system itself.

rocky canyon
#

u can do the same thing with multipliers.. but using 1 instead of 0

edgy sinew
#

Are events really that good or is Unity just checking if the event was fired every frame 🥹

#

I need more FPS 🥹

rocky canyon
#

yes.. events are everything..

#

i actually need to rewrite almost all my code to use them more often

#

Update()s for the Birds

edgy sinew
#

Is firing 60 events a second better than checking a value 60 times a second

rocky canyon
#

probably..

edgy sinew
#

Noooo stop

#

Nah then everything would be on Events

#

It can't be

rocky canyon
#

lol.. if ur checking a value against another value isn't that 2 checks?

#

🐔 and the 🥚

rocky canyon
edgy sinew
#

ur gonna get in trouble asking those kinda questions around here!!! 😰

rocky canyon
#

and events are just easier to work with..

edgy sinew
#

That's true. started / performed / canceled are fast huh

rocky canyon
#

u can subscribe to em.. unsubscribe to em

#

no extra logic needed

edgy sinew
#

Nahhh subscribing and unsubscribing is expensive

rocky canyon
#

callbacks.. all that good stuff

edgy sinew
#

I've tried it before... No good

#

bool check faster imo

rocky canyon
edgy sinew
#

Ohh

rocky canyon
#

i haven't a clue how perfomative it would be

#

b/c i dont use em enough 🤣 edit: im going to start adding them into my codebase tomorrow ✅

edgy sinew
#

Need to make some tutorials of my own at this point

#

What I do know, i know well. Keep saying the same things every day in chat

rocky canyon
#

one of ur statements ^ just got stank-eye'd up there

edgy sinew
#

yeah i noticed. it's fine, i've tried it before lol

#

like when your character exits a Midair state, unsubscribe from jump? Yea get outta here

odd remnant
# edgy sinew The BOTTOM LINE is that you **always** have, some desired item position and some...

And I'm not. I'd been using current and target position in my update function.

Though I'm not sure how this:


if (Mathf.Abs(Vector3.Distance(targetPosition, grabberRigidbody.position)) > epsilon)
    grabberRigidbody.position = Vector3.SmoothDamp(grabberRigidbody.position, targetPosition, ref grabberSmoothVelocity, 0.1f);
else
    grabberRigidbody.position = targetPosition; // Snap to exact desired value```

would be more performant than this:

```Vector3 targetPosition = playerCamera.transform.position + playerCamera.transform.forward * grabbedObjectDistanceFromCamera;
grabberRigidbody.position = Vector3.SmoothDamp(grabberRigidbody.position, targetPosition, ref grabberSmoothVelocity, 0.1f);```
rocky canyon
edgy sinew
#

Maybe for "once or twice in 10 minutes" subscribe/unsub is fine

rocky canyon
#

it'd be more like im teleporting my player/loading a new scene/showing a cinematic
-# hold my input for a minute

odd remnant
midnight plover
eternal needle
rocky canyon
#

i didn't say it'd be an issue..

#

thats when i'd possibly unsubscribe from my InputHandlers()

edgy sinew
#

I found it takes too long to resolve, always. Especially if you modify params in anyway like the smoothTime

#

The 0.08f is just the closeness to trigger an exact-value snap

#

SmoothDamp does that internally but it's not customizable i think

#

I just use curves and epsilon or clamp with a minimumVelocity to ensure resolve

rocky canyon
#

Curve junkie over here lol

odd remnant
# edgy sinew That's fine, if you're OK with how SmoothDamp behaves

I'm about halfway to loving it. I'm noticing two strange things - when I rotate the camera and scroll the scroll wheel at the same time - the object doesn't get closer to the camera until it stops rotating - this screams "async" issue to me. And the second is that as I rotate the camera - even moderately-slow, the object is kinda jerky.

edgy sinew
rocky canyon
#

u could seperate the two..
zoom/pan w/ an outter gameobject wrapper..

#

and then rotate an inner

edgy sinew
#

Maybe the calculation is wrong, I didn't look deeply into it

odd remnant
edgy sinew
#

Yeah definitely. do you have Interpolate on?

#

Is the Rigidbody kinematic?

odd remnant
#

Yes, it is.

rocky canyon
#

golden rule with FixedUpdate() is don't have Input in there..

odd remnant
#

Interpolate though, I'm not sure.

edgy sinew
#

Physics is a whole topic

odd remnant
rocky canyon
#

yea don't poll for input in fixed

odd remnant
#

I don't.

rocky canyon
#

cool cool..

odd remnant
#

It's only performing the smooth damp movement to the target position.

#

But it seems like the camera movement and scroll wheel somehow aren't happening at the same time - and it's weird because when the camera is rotating SLOWLY, it's fine.

edgy sinew
#

I don't think you can just move Rigidbody like that

#

Maybe try Physics.SyncTransforms() after you directly set a Rigidbody transform.

#

I think with Kinematic Rigidbody, MovePosition and MoveRotation don't screw up the interpolation?

#

there's rules to it, I forget the exact details.

midnight plover
#

MovePosition work for both, but as we had earlier a case, its bad for like restricting player movement with walls or what not. Its more to like push things away while your character is moving

odd remnant
#

Hang on, new info - the above wasn't true. Whenever the camera (or maybe the mouse) moves, the scroll doesn't work - but when there's no mouse movement, the scroll "catches up" to the new location.

Physics.SyncTransforms() didn't fix it.

edgy sinew
#

You can also turn interpolate off, on a kinematic RB, and just set position directly in Update.

#

I'd recommend getting this working without Rigidbody first. Just a regular GameObject.

rocky canyon
#

i recommend that dozens of times..
i always tell people if things aren't going ur way or ur having an excessively hard time with something
break it into pieces.. and work on a single piece in isolation... all by itself.. nothing to go wrong but the code ur working on..
once u get it working and u add more and more to it you'll easily being able to pinpoint where the code goes rogue and stops working..

#

much easier than working out a full mechanic w/ lots of moving pieces all at the same time..
heck theres even times when i'll have something not work.. and i get it fixed just to realize i broke the thing that was already working..

that happens less often too when i go at it bite by bite byte by byte 🤪

edgy sinew
# odd remnant Hang on, new info - the above wasn't true. Whenever the camera (or maybe the mou...

I had the same issue when "picking up" a Rigidbody. (SetParent to Player's hand) - so basic huh? Unity tries to control the Rigidbody when Interpolatation is enabled. So i just had to disable that on pickup.

itemToPickUp.GetComponent<Rigidbody>().interpolation = RigidbodyInterpolation.None;```

FYI it's not great to `GetComponent<>()` at runtime. I'll be getting those references on Awake() eventually in a "ItemThatCanBePickedUp" script to avoid this.
#

Idk if that's helpful, it all depends what exactly you're doing with the Rigidbody.

glad shore
#

How can i tell if a animation has played(from a script) in an animator

rocky canyon
#

i mean. its not as bad as running a Get in Update() or soemthing 😄

#

atleast in urs is only when u pickup or drop something

odd remnant
#

Which happens in another class's Update class.

rocky canyon
#

well thats also a no-no
updating the same thing from fixed and update at the same time especially a Transform

odd remnant
#

Could that be the root of the issue? targetPosition is updated in the FixedUpdate step, and dependent on a variable whose value is changed in the Update step.

#

The transform itself is only updated in FixedUpdate.

edgy sinew
#

Yeah 100%

rocky canyon
#

oh, well if its depending on a value updated in Update() its possible its changing quite drastically compared to the last value Fixed() thought it was

edgy sinew
#

You should change the "desired position" in Update, but only ever move the object in FixedUpdate, towards that Vector3 desiredPosition

#

Unless you were to go the other route and remove Interpolation. Then you don't need FixedUpdate until you re-enable Interpolation

odd remnant
#

Interpolation is the SmoothDamp, right?

edgy sinew
#

First thing I'd try is to remove that last line of FixedUpdate, replace with MovePosition

#

No - Interpolation is a Rigidbody setting that tells Unity to approximate the position of a Rigidbody in Update. Why? Because FixedUpdate is not synchronized with Update

odd remnant
edgy sinew
#

An object moving at 50 FPS (fixed) will not look good if the game is at 60 FPS.

#

MovePosition has a speed to it too. But if your desiredPosition is smoothly calculated, you can just have infinity max speed.

odd remnant
edgy sinew
#

Screenshot of picked up object Rigidbody?

#

I g2g so let's get nitty gritty ASAP

#

please blushie

odd remnant
#

No worries, thanks for the help this far.

midnight plover
#

I think thats a good issue for a thread to talk about 🙂

odd remnant
#

I'll start one there, Thanks joer.

edgy sinew
odd remnant
#

LOL, that makes more sense. I was like wtf

#

My brain is melting out of my ears actually, so I'm gonna sleep on it and come back to it with a fresh pair of eyes.

#

Thanks everyone.

edgy sinew
#

With more pics & code 100% we will get it sorted out the issue 🗿 cya next time! Unity

winged ridge
eternal needle
winged ridge
#

In the list of calls it goes Update -> fixed update -> late update as per Unity documentation

eternal needle
#

i dont know where you got that info, but that list of calls is just wrong

polar acorn
#

They're separate loops. One of them is going to occur before or after the other simply due to the fact that Unity is multi-threaded, but the timings have nothing to do with each other. You shouldn't think about it being "before late update" because it isn't. It's called when it needs to be

edgy sinew
winged ridge
#

Unity themselves state physics should be calculated in fixed update

edgy sinew
#

That’s correct. The “order things happen” we were clarifying

fast relic
eternal needle
polar acorn
eternal needle
#

theres a reason its called the physics loop in the link i sent

edgy sinew
#

PhysX looks good Ngl. Real good

winged ridge
#

Right so if update is based on your frame rate calculation, then anything not tied to physics should be in it. Hence pre physics as I said, arguably could be post physics but then just use late update

edgy sinew
#

You can switch Physics to run on Update time too! lol

#

For non deterministic funk?

fast relic
edgy sinew
#

🐴

fast relic
#

some (visual) frames its called before physics, some after, some multiple times, some physics is called multiple times (because your fps is lower than the physics tick rate)

#

update is all over the place while fixed update is, well, fixed - it runs consistently (by default) 50 times a second

edgy sinew
#

Maybe a quantum computer in the future can run PhysX at 500 FPS (fixed). 0.002s kekwait

#

With 40 solver iterations

restive sentinel
#

Hi, is there a channel for shader help specifically or would it just be here?

winged ridge
#

Try the art-asset workflow section

restive sentinel
#

Okay, thanks

eternal needle
restive sentinel
edgy sinew
#

Yeah imagine 2 cars …
One stays at speed 40
One goes 35, 37, 42, 37, 32

#

Clear?

#

Sometimes they line up, or are close, sometimes not. That’s it

winged ridge
edgy sinew
edgy sinew
#

“FixedUpdate may happen less than once per frame at …”

#

That one?

winged ridge
#

I was wrong on the order though that I conceded.

eternal needle
edgy sinew
#

That is the only place it’s mentioned on that page, though. So you’d have to go to Physics API or FixedUpdate to learn more yeah

eternal needle
#

they show it this way because thats the execution order. as digiholic said, its not multithreaded so it technically does run in some order

winged ridge
eternal needle
#

you still arent understanding, what i wrote isnt the same at all compared to your original point (where the order was wrong still)

edgy sinew
#

There is no order. Physics runs on its own time lol

rocky canyon
#

u can see in the flow-chart how they loop back on themselves

winged ridge
#

And they take frame rate because a frame rate is a base calculation between 1 second and another, they are varied based on other factors

edgy sinew
#

“yield WaitForFixedUpdate” see that at the bottom?

#

Do you know what yield does

eternal needle
#

i dont think I can explain it anymore clear that fixed update does not use your frame rate

#

maybe reread some of the messages above because there isnt much value in us repeating the same points over and over

edgy sinew
#

yield is cool … framerate saver

winged ridge
#

This is getting nowhere on either side

edgy sinew
#

Dead Cells needs some of that Ngl

#

It’s getting to, you learning about yield hopefully ??

#

You think we’re playing here bro? You wanna know more or not

winged ridge
#

That loop does not state it goes back on itself it says when 1 process is finished it can go back and restart

polar acorn
ivory bobcat
#

If you have a frame skip of say, 2 seconds.. the fix update method would be called many extra times to offset the frame skip whereas update would only occur once

rocky canyon
#

if everything was consecutive you'd not have any of those loops returning back to a certain block

#

it'd only be at the very bottom

eternal needle
#

it really feels like they're trying to teach us here by saying "This is getting nowhere on either side". It's really hard to teach someone who won't accept that something is wrong

rocky canyon
#

i think theres some ego/argumentative nature here

edgy sinew
#

Always a little but, we’re here to learn more not say things are one way whilst being clueless

polar acorn
#

How it specifically works is that whenever it comes time to run FixedUpdate, it checks the clock time to see how much time has passed since the last one. If at least your FixedDeltaTime has passed, it runs FixedUpdate, then increments the internal physics clock by one of those deltas. If it's still greater than that fixed delta, it'll run again. And so on.

If your Update loop is very very very slow for a brief period of time (let's say you've done a non-async additive scene load of a massive scene file), it will run a full Update and then do potentially dozens or hundreds of FixedUpdates all at once

edgy sinew
#

Bro … this guy knows everything

polar acorn
#

If your Update loop is super clean and barely takes any time at all, it'll run dozens or hundreds of Updates before enough time has passed for one FixedUpdate

rocky canyon
winged ridge
polar acorn
#

(Unless you VSync or framerate cap it, at least. If you do then it does that "hold for time passed" schtick for Update as well)

edgy sinew
#

Least shameful screenshot

polar acorn
#

||The deal is called student debt||

rocky canyon
#

Update() and FixedUpdate() are running the same race...
they're neck and neck... only Update has super tiny strides

shell sorrel
#

also these concepts work about the same in all engines, and are very easy to test by making artfically slow updates

rotund root
#

I‘m trying to make a mini game called quantum connect 4, i already have rough idea how to make the turn taking & placing chips part, but i have no idea how to do the win checking (to check 4 chips lining up)/randomizing part

every time you press observe, enter observe phase, the chips have (30 or 70)% to turn into black or white chip (the result is random each time), if no 4 same chips lines up, the turns back to the original chip, if Player1 and Player2 both have 4 connected during observe phase, the player who pressed observe wins

polar acorn
edgy sinew
#

Hmm… how to search for vertical or horizontal or diagonal 4 in a row on a Grid

edgy sinew
#

There is a better algorithm than brute force right

rotund root
fast relic
edgy sinew
#

Same it’s just a connect 4 game

#

I’m sure there’s some super tricky fancy way to check though

shell sorrel
#

if the board only has a few hundred tiles the approach does not matter much

rocky canyon
#

wouldnt it be pattern recognition?

polar acorn
# rotund root I‘m trying to make a mini game called quantum connect 4, i already have rough id...

Naive way that is almost certainly not optimized but should work:

Loop through all pieces. Have each piece check each direction, and if it encounters a matching piece, check that direction from that piece. If you see another, do one more. If that one also matches, you've found four in a row! Otherwise, go back to the original piece and check the next direction. When you're out of directions, skip to the next piece.

#

Brute force it first until the game works, then you can go back and algorithmify it

edgy sinew
#

algorithmify 🗿

rocky canyon
#

ConnectFour, made by Crysis

shell sorrel
#

also doing it the simple way, you will likly realize simple ways to optmize later as you work

fast relic
#

don't prematurely optimize

winged ridge
shell sorrel
#

its easier to be clever when its readable and you already have it working and seen some patterns in what its doing

eternal needle
#

any alternatives would most likely be worse or just more complex

rocky canyon
#

best time to get those eureka moments and that dopamine hit

#

is painstakingly staring at ur ugly code afterwards

shell sorrel
#

also that grid only has 49 spots so no need to be clever, just get the game done

polar acorn
#

Normally, you'd only have to check the most recent piece, but since this one has some randomness to it you might need to check more often

edgy sinew
eternal needle
#

oh yea true, you'd have to check through the whole board anyways with their observe feature

edgy sinew
#

Is it “unsolvable” at least under some O(..)

polar acorn
edgy sinew
#

So there is a fast way? Whats it called

polar acorn
#

The thing could be O(n^n) and still run faster than a modern computer could run the rest of the game

edgy sinew
#

Lol. im just curious

rocky canyon
#

after googling im seeing the top results as the way that digiholic described

eternal needle
edgy sinew
#

Yes it has that minimum.

shell sorrel
# edgy sinew Lol. im just curious

even without going crazy on it, there are lots of ways of avoiding doing work and using previous steps to reduce work needed in later steps

shell sorrel
#

but non of that is avoiding checking the whole grid

#

its just making sure you do not check much more then once

rocky canyon
#

but also gets into the realm of what Bawsi said

edgy sinew
#

The bitboard is pretty fast apparently, whoever sent it before good one

winged ridge
#

You wouldn't need to check every single cell to know in connect four.. just the ones directly around it and store the state of the board...

edgy sinew
#

Bitwise stuff is quick always huh… any language any scenarios

winged ridge
edgy sinew
#

Layers in Unity work on that or? I know there’s some bit stuff going on

winged ridge
#

Yes layers are bitwise operations

fast relic
edgy sinew
#

Way to make me feel dumb i felt smart saying that

eternal needle
#

readability > 0fps increase optimizations

rocky canyon
#

i get nervous anytime bitwise comes up 😄

winged ridge
#

Why? It's not hard... Binary calculation is relatively simple

shell sorrel
#

Bit board mostly just reduces memory. Would only be a lot faster for certain operations

edgy sinew
#

Maybe it’s one of those “understand it fully once & then it makes sense forever”

rocky canyon
#

i think im better equipt to handle it now tho 😄

shell sorrel
edgy sinew
#

Yeah easier the 10nd time around right

winged ridge
#

Once you get hang of how binary works it's not too bad, I have had to sit down and write out as many numbers as I can using the 8 bits... I say had to I wanted to

rocky canyon
#

now im disappointed in myself 😄

#

i think using scratch paper and trying to visualize it a bit better would be useful

#

ill try that next time i tackle em

eternal needle
#

There really just isnt a great point in forcing it into code, especially if it hurts the readability of your algorithm. Other people dont wanna sit and try understanding it too

shell sorrel
#

Useful to visualize

winged ridge
#

You guys know about the cheat sheet for VSCode I'd hope

#

Like alt+shift+down copies your line down etc

rocky canyon
#

i know some of em

#

im not one of those guys that can code without my Mouse tho

shell sorrel
rocky canyon
winged ridge
rocky canyon
#

to select and jump around my script

#

copy paste things to other locations etc

edgy sinew
#

like those guys who just use their whole computer w/o mouse only keys

rocky canyon
#

like i said.. im not the guy that code without a mouse... some people know all the shortcuts

#

and jump around and do crazy shit

fast relic
#

nah that's insane lmao

rocky canyon
#

selecting MULTI lines.. copying pasting em dropping em down.. going back changing Types

#

etc

edgy sinew
#

ctrl shift K
delete selected lines (dont have to select the whole line)

fast relic
#

multiline select is very useful tho

edgy sinew
#

works on current cursor line too

winged ridge
#

Alt+down shift your entire code line down
There's one I think was shift+tab which changes your line from 4 spaces to 0 etc

shell sorrel
#

really i am one of those people that knows way too many vim motions and prefers cli apps for a lot of things. None of it matters, how fast you can input stuff is never the bottleneck.

rocky canyon
#

i still cant remember the bloody hotkey to format

edgy sinew
#

I mean the vertical blinking line like ur next typing position

rocky canyon
#

i just cut and paste the whole dang class

#

and let it format that way 😄

fast relic
#

ctrl a, ctrl x, ctrl v

rocky canyon
#

exactly 😉

fast relic
#

-# or just enable format on save

dry tapir
#

my god, i been following a tutorial on youtube and got stuck at the firsts tep >.<
i followed it to the T, and still it doesnt work. If anyone able to help heres my problem

i am trying to create a fnaf clone, one for halloween and im trying to set up a scroll function on office, ya know. So when player hover on the edges of the screen it moves to that side. but no matter what i do it doesnt budge at all!

heres the code:

using System.Collections.Generic;
using UnityEngine;

public class ScrollArea : MonoBehaviour
{
    public GameObject background;

    public float scrollBoundX;
    public float scrollSpeed;

    public bool left;

    private void OnMouseOver()
    {
        if((background.transform.position.x < scrollBoundX && left) || (background.transform.position.x > scrollBoundX && !left))
        {
            background.transform.position = new Vector2(background.transform.position.x + scrollSpeed, background.transform.position.y);
        }

    }
}
fast relic
dry tapir
#

oh... fack

winged ridge
fast relic
#

you need to i think implement IPointerOverHandler (or enter/exit)

#

and make sure you have an event system

shell sorrel
dry tapir
#

thanks guys

#

the tutorial i been following is very old then

winged ridge
dry tapir
#

lol

rocky canyon
#

eh, some people still use the old input system

edgy sinew
#

Maybe it’s from b4 the new input system came out

fast relic
#

i like the new one

rocky canyon
#

for now 😈

eternal needle
rocky canyon
#

rebinding was hella ez

eternal needle
#

Although the input system has existed for years*

fast relic
#

i like it being event/callback based

shell sorrel
#

new one is massivly better

dry tapir
#

im coming from renpy so yeah im lost as hell

shell sorrel
#

takes more setup to use and pushes you into better practices

fast relic
#

also i started with unity 6 so that was the default and might as well use it

winged ridge
#

To be fair.. the new input system is Unreal engines version just changed a bit

edgy sinew
#

Can’t really complain yeah. Do u guys recommend using the built in processor like scale Vector2 etc. deadzone
It’s possible to edit all that at runtime too right?

rocky canyon
#

i use both 🤫

shell sorrel
edgy sinew
#

Well I wouldn’t make a settings menu without dead zone support

shell sorrel
#

the scale can be used as a setting but i often also use it, when i have multiple input devices 1 bind that act quite differently

#

like mouse vs stick inputs for example i often need to scale one

edgy sinew
#

Oh yeah i have separate scale for mouse look / controller look

rocky canyon
#

wait

#

yall talkin like sensitivity multipliers built in?

edgy sinew
#

Hard to find online about “Unity new input system change deadzone at runtime”

#

Yeah those ones. I wanna change them at runtime too

edgy sinew
#

The more I let Unity handle stuff, the better I feel & the game runs

rocky canyon
#

hell ya

winged ridge
shell sorrel
# rocky canyon hell ya

you will still need some processing after depending on your game, but you can have your scale multipliers be per input device or per bind

rocky canyon
#

i might just get rid of my input class stuff

fast relic
shell sorrel
#

also stuff like normalize and invert and deadzones

edgy sinew
fast relic
#

yeah

rocky canyon
edgy sinew
#

It has invert? i do that manually …

shell sorrel
#

just be carful with normalize most people new misunderstand it and bugger there inputs up

rocky canyon
#

i dont know how many times ive written inversion code

#

oh yea im super familiar wiht normalize

#

altho i always forget about it until i go bak to the code

#

im like tf? Ohhh wait!

#

lol

shell sorrel
#

you can also just write custom processors for the input system

rocky canyon
#

thats pretty awesome to know..

#

but outside my wheelhouse for now

edgy sinew
#

Ahh ok this is the page i was looking for all along. Nice

rocky canyon
#

gotta focus switching things out and getting rid of some of my redundant code for now

edgy sinew
rocky canyon
edgy sinew
#

I’m so behind i dont have enemy AI even started

winged ridge
#

Pretty much everything in Unity can be redone if you wish, even without access to base code

rocky canyon
#

with only the new input system

fast relic
winged ridge
rocky canyon
#

i had a really smart one.. w/ senses and stuff but got corruptd

edgy sinew
#

If you can just hit me with some key words or things to look out for

fast relic
rocky canyon
#

behaviour trees

edgy sinew
#

I know navmesh is important. I already know state machines

rocky canyon
#

and become a master at the animator

edgy sinew
#

2D doesn’t have navmesh or

rocky canyon
#

nah u have to do a* or something

edgy sinew
#

Why would it, it’s just

winged ridge
#

I was meaning more what's your ai focus

edgy sinew
#

Yes

shell sorrel
#

there are many ways to do pathfinding

rocky canyon
#

i use a hybrid approach

shell sorrel
#

have done 2d with my own A* based on a tilemap or a quad tree

rocky canyon
#

with a navmesh and custom movement logic

edgy sinew
#

I mean basically it’s just the path finding that i don’t know yet

shell sorrel
#

never had a cause where A* on a mesh made more sense in 2d since you need a way to define that mesh

rocky canyon
#

a* a* a*

edgy sinew
#

State, detection with triggers etc, all chill

fast relic
rocky canyon
#

u need to be able to disable the navigation too

#

for things like knockback

#

or anything like that that would move it extra from the pathfinding

#

or u could bake it in i guess

winged ridge
#

I mean the senses idea mentioned was a good one to implement
Sound you just need footsteps decibels
Visual just use raycast
Guess you could implement smell too

edgy sinew
#

What 🤣

rocky canyon
#

senses/ sensor and a sensor array

shell sorrel
rocky canyon
#

ya

edgy sinew
#

I doubt sampling audio would be valuable

rocky canyon
#

for what?

edgy sinew
#

The computer knows where things are, how fast they’re moving (how much noise they’re making)

rocky canyon
#

u gonna build ur ai around the audio? lol

#

ohh that

edgy sinew
#

Nah lol i thought that’s what dragoon meant

rocky canyon
#

no.. that doesnt make sense

#

u could easily do that with proximity and volume levels

edgy sinew
#

Would be cool though. Maybe a quantum computer can do it

rocky canyon
#

cool idea tho..

winged ridge
#

No, I'm saying implementation of sound is easy for the ai

rocky canyon
#

it does remind me this guy made a full echo and reverb system

edgy sinew
#

I saw one guy who was just doing like… “anything that moves makes sound”
With materials and other params

rocky canyon
#

u could walk into a space and the audiowould start bouncing around and echoing

edgy sinew
#

Can’t find that anymore but it was sickkkk

shell sorrel
#

sound for enemy AI is just distnace, and tagging what actions are loud vs quite etc

rocky canyon
edgy sinew
#

Half Life kinda does that i think

shell sorrel
#

no need to overcomplicated it the user will never notice

rocky canyon
#

depending on what ur walkin on u change out the footstep sounds

edgy sinew
#

There’s a lot of math behind which sounds play

shell sorrel
winged ridge
rocky canyon
rocky canyon
#

itd be using materials is what ive seen in teh past

#

to decide the audio but yea if we're still talkin ai i said

u could easily do that with proximity

edgy sinew
#

Running the entire game thru a VST compressor real time lol

rocky canyon
#

so i agree with that part

edgy sinew
#

I wondered if Escape From Tarkov was doing that. That game sounds terrific

#

Nobody’s doing real time compression right … real time reverb, yes though ofc

shell sorrel
winged ridge
#

A reason to use audio is if you wanted to implement perks that adapt things It was mentioned using speed etc. which if you want it so you can perk and run but quieter, you don't want the calculation based on velocity rather than sound it makes... So checking against audio feedback helps
Physics material to define it's parameters

shell sorrel
#

so checking agaisnt audio directly would make game design very hard while keeping things sounding like how you want

#

like audio being triggered is really just invoking a event, so just provide what args are needed for other systems with that

winged ridge
#

Triggering fine, but getting the audio feedback after the variables have been altered based on your conditions (IE crouching, running, grass or broken glass.. etc.) just change decibels and effects and just check against that. The triggering audio sure event invoke

edgy sinew
#

Ngl the audio feedback idea does sound cool

#

Sounds computationally expensive too

shell sorrel
#

its not

winged ridge
shell sorrel
#

its just changing some properties of how something is going to play when it was going to play anyways

edgy sinew
#

Like, sampling an audio source from down the hall, 3 floors down

#

To find out how much of it reached bounced etc or

#

I don’t even know how complex Unity sound simulation is

shell sorrel
#

they are not talking about that though

edgy sinew
#

oh ok nvm then

winged ridge
#

That is what I'm talking about yes vengeful

shell sorrel
#

also defualt unity game audio is not that complicated

winged ridge
#

You mentioned AI I'm talking about a reactive ai based on sound output by your player etc

shell sorrel
#

no bounces are happing, its just how loud is sound, then there is a exp^2 falloff

rocky canyon
winged ridge
rocky canyon
edgy sinew
shell sorrel
#

but what i am saying is there are ways to get the exact same outcome that do not involve sampling audio listners

winged ridge
fast relic
#

they just fake it

shell sorrel
#

and are much much cheaper

rocky canyon
#

til u make it

shell sorrel
#

its not even faking it, its just realizing ai's do not care about the audio its self, just the conditions it was made with and where they are relative to it

rocky canyon
#

true.. lmao.. like the clicker zombies in that game.. they dont hear u walkin.. they just know ur way too fkn close.. lol

#

oh, n ur moving..

winged ridge
#

I do feel like we are in the wrong feed for these conversations

bright zodiac
edgy sinew
#

since the terrain is painted with the textures themselves

shell sorrel
edgy sinew
#

Oh fr? hm

#

I thought there’s more complex blending going on etc

shell sorrel
#

so in the case of a terrian or a mesh with vertex color used for different materials you would need to sample it

shell sorrel
edgy sinew
#

So by default it’s the same as dropping a material onto a cube

winged ridge
#

I'd say regardless of whether unity has it or not... Research how it works, try to replicate it, understand the maths and logic behind it, you'll implement it much better (even if you use unity version)

edgy sinew
#

I thought the terrain painting works like that underneath, green red yellow

shell sorrel
#

where you need alternate ways to know what the player is over

rocky canyon
#

u could simply use tags or layers as well if it was the case of an indoor space or walkin on meshs vs the terrain

winged ridge
#

Or a script that you have an enum attached to and just change based on that (get component rather than compare tag)

fast relic
#

get component is more expensive

winged ridge
#

How often do you plan on doing it is the question

edgy sinew
#

I’m hoping, with Procedural Terrain Painter, there’s some way to access the value at some xz location

#

Might not be idk how that thing works

fast relic
edgy sinew
cosmic dagger
edgy sinew
#

Nobody will complain if the sound switch is a few frames late

#

(Sometimes the update will coincide and be on time too)

eternal needle
winged ridge
#

Could just have the vectors plotted out stating that between xy and xy is this sound, etc

edgy sinew
#

or wait no Coroutine method would always wait exact same # of frames

eternal needle
#

a coroutine waits a certain amount of frames if you code it to do that. the same way you could do that in update or code it properly to use real time

edgy sinew
#

Oh, yeah. So it could line up with when person changes material they’re on

shell sorrel
#

its 1 frame you loop

#

but now are tieing stuff to exact frame rate which is not great

edgy sinew
#

Yeah im saying, something that for happens “exactly every 5 frames” - it would only be 5 frames late at the most & can other times be only 1 frame late etc

#

I can feel in Dead Cells that they do that for the flying eyeball monster. It looks laggy compared to other monsters

edgy sinew
shell sorrel
#

pretty standard stuff

edgy sinew
shell sorrel
edgy sinew
#

Ah, another “0% FPS gained”

shell sorrel
#

if its continous i would lean towards just a update method and counting frames

#

don't over think things

dry tapir
#

AI is completely frickin useless for unity coding, holy cow

edgy sinew
#

Everyone, cheer! Yay!

#

We won’t get beaten by the AI!

winged ridge
fast relic
dry tapir
#

public class HoverDetector2D : MonoBehaviour
{
    public bool isHovering = false;

    private void OnMouseEnter()
    {
        isHovering = true;
        Debug.Log("Cursor Entering " + name);

    }

    private void OnMouseExit()
    {
        isHovering = false;
        Debug.Log("Cursor Exiting " + name);

    }
}

it doesnt even tell me whats wrong with the script, nothing it does works

winged ridge
#

Unity have plans for it, all that can be said

slender nymph
fast relic
winged ridge
fast relic
shell sorrel
eternal needle