#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 683 of 1

silver fern
#

I'm trying to figure out how to organize these character prefabs so I can try to actually write anything. So from what I gather, for each character there will be a prefab which contains the character stats, imports the controllers, and has attached components for each attack and ability

steel smelt
#

You seem to make a distinction between "importing" the controllers, and having attached components for attack and ability. This is confusing to me.

Do you not intend on having your controllers as components?

silver fern
#

I don't know. Wouldn't the controllers be separate for each prefab if I add them as components?

#

Or is adding the component the same as an import statement in script?

steel smelt
#

When you add a component, an instance of this class is created for you. The reason you make it a component(so a MonoBehaviour derived class) is because it makes it extremely convenient for this class to interact with the unity API.

Notably, it will have access to a managed transformation matrix via the transform component
magic methods awake/start/update/etc will be fired on this component, allowing convenient synchronization with other objects in your scene.

Now, if you create 1 controller class, and you add it to 20 objects, yes it is a bit like importing a library but with the exception that each instance can have per-instance data.

hexed terrace
#

character stats -> usually best as a scriptable object
model -> the various prefabs for the model
base prefab -> has all the controllers/ components on -> spawning just assigns the model prefab and relevant data

silver fern
#

awesome, thanks

#

and thanks everyone else too

toxic cloak
#

Hello guys can anyone point me to a resources or tutorial on how to connect ui buttons to new input system .Thank you

visual linden
magic knoll
#

Hey guys, i'm following a video of codemonkey to make a "kitchen chaos" game: https://youtu.be/AmGSEH7QcDg?si=xg9RQ5qcii3cWt-t&t=12141
To give some context, he made a Tomato and CheeseBlock prefabs, and their related ScriptableObject. I don't really understand/like that he make a reference to the prefab in the scriptable object, but also make a script attached to the prefab to reference the related scriptable object. Is there a better way to do this ?

๐Ÿ’ฌ This was a ton of work to make so I really hope it helps you in your game dev journey! Hit the Like button!
๐ŸŒ Course Website with Downloadable Assets, FAQ, Related Videos https://cmonkey.co/freecourse
โค Follow-up FREE Complete Multiplayer Course https://www.youtube.com/watch?v=7glCsF9fv3s
๐ŸŽฎ Play the game on Steam! https://cmonkey.co...

โ–ถ Play video
#

The fact that the prefab is referenced in the SO, and vice-versa it feels like something wrong ?

steel smelt
frosty hound
#

Things that exist in your scene need to have a MonoBehaviour to have some functionality. The SO reference is so that you can keep the "definition" of that object separated from the scene for easier modifications, mainly.

frosty hound
#

You can absolutely just put those same fields like, the name and such on the MonoBehaviour itself and skip the SO entirely.

magic knoll
#

Hmm ok good to know then. I'm new to this concept and was a bit lost ^^

frosty hound
#

It's a matter of organization (and preference), really.

#

But generally speaking, if you're defining the information of an object, such an items, characters, use SOs. It'll just be cleaner.

#

That way you don't need to have a prefab for each food, instead you can have a generic food prefab that you "dress up", with the contents that the SO has (icon, name, model reference, etc.)

magic knoll
#

Oooh

#

Like the SO is a kitchen object constructor ?

#

But in the video he does have specific prefab and SO for each food right now

#

Maybe he gonna refactor it later in the video

frosty hound
#

Just to save the time and effort of dynamically preparing the objects at runtime I imagine. I haven't watched his course.

magic knoll
#

I see. Thanks for help ๐Ÿ™‚

brave robin
toxic cloak
#

Is the old input system better if m targeting only one platform?

frosty hound
#

Depends if you also need multiple maps for gameplay.

brave robin
#

Fortunately it's not a huge undertaking to switch, especially if you don't sprinkle your input listening code across the whole project

toxic cloak
#

Yes like the new one is good if i have like humanoid controls n also some kinda car or boat controls but if it has only humanoid controls then is the old one better?

brave robin
#

If your game's needs are pretty simple then sticking with the old is totally fine, plenty of games shipped using it

toxic cloak
#

cz m new to the new iput system n having problems on hooking it with ui buttons

#

i mean i dont really know how to without making a script which in the end is same as the old input sys

brave robin
#

So if you press a controller button it should "press" a UI button?

toxic cloak
#

yes like move left button or move right button

brave robin
#

If the problem is that moving left and right isn't navigating a button menu properly, that's not specific to new or old

toxic cloak
#

i mean i have key mapped in the new input system for movement i want to have ui buttons for that but cant seem to understand how to hook them

brave robin
#

Though in the new input system there's a specific component you'll need to make sure it passes the actions to the event system for UI. There should be tutorials on using UI with the new input system

toxic cloak
slender nymph
brave robin
#

Oh, so you want to press a UI button and it acts as if you moved left on the controller?

toxic cloak
#

i mean is there a new input system way of hooking buttons

brave robin
#

Ah, that's different. Whatever code is listening for the input action reference needs to also be linked into the OnClick unityevent of the button

slender nymph
toxic cloak
brave robin
#

None, its the same work flow to make a UI button do something in this case

toxic cloak
#

yes thats all the answers i need thanks i was wondering if it makes the work easier if i use the new one on this specific task

worldly jacinth
#

Hello im completly new to coding and i would like to know why some lines are blue, green and white, and how you can change them if you can change them ?

naive pawn
#

the color of text, colors on the left of the line, underlines, etc

worldly jacinth
#

For example im following a old tutorial were the line "using UnityEngine", "using" is blue, so is my line, but the "UnityEngine" is white in the video and green in my code. I was wondering why

#

i copied the same script but some of the words are in different colors than the video

#

and i have a error message so i suppose it has something to do with the color not matching?

slender nymph
#

the actual colors used in the syntax highlighting are dependent on your theme and/or IDE

worldly jacinth
#

so the colors do not matter ?

slender nymph
#

if you have an error in the code it is not related to the colors. but it should be underlined in red and if it is not that means your !IDE is not configured

eternal falconBOT
worldly jacinth
#

what does IDE stands for ?

#

i may be the problem indeed

naive pawn
frail hawk
#

IDE is the thing you are coding in

worldly jacinth
#

ok thanks

slender nymph
# worldly jacinth what does IDE stands for ?

you do know that google exists, right?
and a 5 second search will tell you it stands for Integrated Development Environment. aka your code editor (which should be more obvious from the bot embed directly above your message)

worldly jacinth
#

so visual studio in my case

slender nymph
#

considering you said that "UnityEngine" was green in your own code it sounds like you're using vs code not visual studio

naive pawn
frail hawk
#

but if he did not change the colors it indicates that his IDe is not configured correctly as boxfriend pointed out already

naive pawn
#

(he said the colors did change)

raven arch
#

Hello ๐Ÿ™‚

If I have a question regarding Skinned Mesh Renderer being invisible for me, is this the right channel? Or is "Animation" more correct?
Apologies if I wrote in wrong channel

naive pawn
raven arch
#

First time trying to animate my player object. Making a 3d game. Ive set animations, set the correct one as default and I can see it running when I start. Initially I had mesh renderer and my "skin" was showing but, animation wasnt playing. After googling, Ive read that its due to Mesh Renderer shows static skin and that I should use Skinned Mesh Renderer.

Cant get it to work. My character is just invisible.. Tried googling it and asked gpt and gemini, Ive done a lot of different steps including dragging my mesh on the scene and applying material which causes it to appear. Cant seem to figure out why its invisible on my player object

worldly jacinth
slender nymph
#

#854851968446365696
it just creates useless noise in the channels when you ask easily googleable questions instead of putting in the effort to actually find out the answer yourself

worldly jacinth
#

calling interactions like talking useless noise is crazy sad

#

but sure ok

lapis parrot
#

i understand that i need to use OnTriggerEnter2D and OnTriggerExit2D to make text appear when you walk close to the item's "range" but i have no clue how to correctly implement it and i've scowered the internet looking for a solution and can't find one

#

i know i explained that poorly

slender nymph
worldly jacinth
#

lmao

naive pawn
lapis parrot
#

not a clue or hint in the world

#

i am very new to c#

naive pawn
#

this doesn't have anything to do with c#

lapis parrot
#

i am also quite slow

#

wait so event triggers?

naive pawn
#

you need trigger colliders to specify the range to get those messages

naive pawn
lapis parrot
#

oh so a gameObject to specify the range

naive pawn
#

no, a trigger collider

naive pawn
lapis parrot
#

so i don't go to assumptions

lapis parrot
#

tyty

frail hawk
#

you could also use Vector2.Distance if you just want to do something while in range

naive pawn
#

in your case you would add a trigger on the interactable thing

worldly jacinth
#

i can't exactly tell what was wrong im my code but my project is working thank you guys !

orchid swallow
#

what is the checklist for Jump is not working?
spacebar is detected, but not working

frail hawk
#

Debug.Log your isGrounded

raven arch
orchid swallow
raven arch
#

How does your isGrounded check look?

orchid swallow
#

now it is forever check and in jumping mode, unable to move

lapis parrot
rocky canyon
# orchid swallow

u know the difference between OnTriggerEnter and OnCollisionEnter?

#

is there a trigger on the player?

#

odd setup i figured OnCollision would be enough

#

and check for ground

#

anyway.. put DebugLogs n collision and n ur if statements

#

print out what they collide with

polar acorn
# orchid swallow

Does this object ever pass through a trigger on an object tagged "Ground"?

rocky canyon
#

ya seems weird to me.. b/c the code is checking for ground.. which implies its on the player..

#

but then the POlygon collider of the ground..

#

isnt marked as isTrigger

naive pawn
#

probably because it should be OnCollisionX2D

frail hawk
#

nice catch, yeah i also assume they want OnCollisionEnter instead

split plover
#

okay i have to be doing something wrong ๐Ÿ˜ญ
how come every time i try to use the input system even if i follow a tutorial EXACTLY it says something comes out as null

naive pawn
#

-# gonna need some more info to go off...

polar acorn
split plover
#

This was more for testing but i literally copied code and only changed variables that i had to for it to work and it still didn't work

using System.Collections;
using UnityEngine.InputSystem;

public class BasePlayerScript : MonoBehaviour
{
    CharacterController controller;
    PlayerInput Playerinput;
    InputAction MoveInput;
    float BaseMovementSpeed = 5f;
    float SetMovementSpeed = 2f;
    float Velocity = 0.01f;
    void Start()
    {
        GetComponent<CharacterController>();
        Playerinput = GetComponent<PlayerInput>();
        MoveInput = Playerinput.actions.FindAction("Move");
    }
    void Update()
    {
        CharacterMovement();
    }
    void CharacterMovement() {
        Vector2 Movedirection = MoveInput.ReadValue<Vector2>();
        controller.Move(SetMovementSpeed * Time.deltaTime * new Vector3(Movedirection.x, Velocity, Movedirection.y));
    }
}```
split plover
split plover
split plover
#

oh sorry forgot to put that, its the controller.Move line

naive pawn
naive pawn
brave robin
orchid swallow
split plover
naive pawn
split plover
naive pawn
#

that's declaring the field, that doesn't give it a value

split plover
#

why did it work for the tutorial but not me then ๐Ÿ˜ญ

naive pawn
#

because it set it somewhere else lol

#

check your Start

#

you have a GetComponent that isn't being assigned to anything

split plover
#

no like, i LITERALLY copy pasted code

#

well i mean

brave robin
naive pawn
split plover
#

hey atleast this time it wasn't the input system

brave robin
#

GetComponent<CharacterController>(); that's missing an assignment there

split plover
naive pawn
#

it does not, no

split plover
brave robin
#

characterController = GetComponent<CharacterController>(); is what you want

naive pawn
#

do you know the difference between float x; and float x = 5;

split plover
raven arch
#

controller = GetComponent<CharacterController>();

split plover
#

why do i have to put "CharacterController controller;" at the top if im already getting the component and labeling it as controller in the start area?

naive pawn
#

because that's how c# works

#

you have to declare variables

#

this is, indeed, how most languages work

raven arch
naive pawn
#

the exceptions being js and python, as always

brave robin
split plover
#

I mean yeah i kinda thought that i was declaring it and setting it to controller in the same line

frail hawk
brave robin
#

You can't just say bob = 5 because you have not declared what bob is. Is it an integer? is it a float? is it an enum? compiler doesn't know

naive pawn
split plover
rich adder
#

declaring and assigning are two different things in the beginning everyone gets confused on

split plover
#

but yeah anyways thanks for pointing out my stupid mistake ๐Ÿ˜ญ

naive pawn
split plover
polar acorn
rich adder
raven arch
frail hawk
# orchid swallow

let instellisense do the work, if you type OnCollision it will give you the correct suggestion

polar acorn
#

You get the component in start, but it's gotta go in a box. You can't really hold water without a cup

naive pawn
split plover
#

anyways i am gonna go back to coding cause somehow i broke every single bit of code in my previous script so im rewriting all the code ๐Ÿ˜ญ

naive pawn
polar acorn
#

this works because you aren't calling a function in the assignment

polar acorn
#

You can't do CharacterController controller = GetComponent<CharacterController>() because you can't call a function outside of any functions

naive pawn
#

(a declaration and an assignment in the same line is sometimes called an initialization, or more broadly, a definition)

rich adder
#

even if you did
magicNumber = 3;
it has no idea what magicNumber is unless you declared it
but some types can be inferred such as
var myNumber = 40; then var is now a int

naive pawn
split plover
naive pawn
#

because c# is statically typed

#

it's a design thing

polar acorn
rich adder
#

its a good thing being statically typed

split plover
#

(im ngl im never touching statics unless i have to this was sarcastic)

brave robin
#

Nothing wrong with statics

split plover
rich adder
#

statics are like seasonings, you don't want to over do it

naive pawn
#

this is valid c#, just doesn't work with getting components because of how stuff is initialized

rich adder
split plover
raven arch
rich adder
split plover
naive pawn
#

it's the only seasoning that would make cereal taste bad

brave robin
#

We use statics all the time. Mathf is static

split plover
naive pawn
#

and that way is fish sauce

split plover
rich adder
#

Singleton walks in the room

naive pawn
polar acorn
brave robin
polar acorn
#

So, yeah, you're right. I thought you just couldn't do these UnityEngine methods in an initializer

split plover
naive pawn
polar acorn
#

Yeah, I had an intuitive sense that it wouldn't work and didn't actually question it after finding out that it did in fact not work

#

So I never considered why it wouldn't work

rich adder
split plover
brave robin
#

It's funny how code beginner often devolves into more advanced discussions because we get pedantic over someone simplifying an answer ๐Ÿ˜„

polar acorn
#

๐ŸŒˆโญ The more you know

split plover
split plover
rich adder
shell sorrel
split plover
rich adder
#

fair enough linkLOL

split plover
#

so realistically its ok for me to use keycodes for jumping because i don't like people who dont use space for jumping right

rich adder
naive pawn
#

realistically? your first game probably isn't going to get enough people for it to matter

shell sorrel
polar acorn
shell sorrel
#

then it can have multiple buttons and easier support for rebinding later on

split plover
rich adder
#

KeyCode / Numerical values are always faster than string lookup ofc

split plover
shell sorrel
rich adder
shell sorrel
#

or simply for accessibility reasons

naive pawn
#

statics make way more sense for symmetric stuff like that

split plover
shell sorrel
rich adder
shell sorrel
split plover
rich adder
#

the OG

split plover
shell sorrel
#

most of what i exposed is rearranged equations to expose more design friendly terms

#

instead of the actual physics of it

rich adder
rocky canyon
shell sorrel
rich adder
split plover
#

is the keycode for space Input.GetKeyDown(KeyCode.Space)

rocky canyon
rich adder
#

yeah I accidentally discovered it because you can't help it since it happens while you look one way while you press forward + strafe another

shell sorrel
rocky canyon
#

ya, it was a gem i wasn't even aware of.. ofc iwas in my Tween years

rich adder
#

quake with a gamepad! blasphemy

shell sorrel
#

a lot of engines were derived from or stole from early idtech engines

rocky canyon
#

i wasn't as professional of a gamer as i am now ๐Ÿ˜

rocky canyon
#

had the big printer port on it

shell sorrel
rich adder
#

COM connection

rocky canyon
#

found it

shell sorrel
#

remeber my first joystick i had to attach to the soundcards midi

rocky canyon
# rocky canyon

even had a little joystick u screw into the dpad ๐Ÿ˜…

#

with the gamepad i wasnt aware of all the movement mechanics u could unlock

#

like bunnyhoppin

rich adder
#

I had this one

rocky canyon
#

didnt know bout that until the very first time i seen someone speedrunning it

#

big as a house

#

lol

#

the "original DUKE"

naive pawn
# rocky canyon

too young to have seen this in person but every time i see a pic i feel like it could be disconnected along the diagonal and reconnected into a different shape lmao

shell sorrel
#

yeah i was big into QWTF, then Q3A and then TFC back in the day and learned all the movement tech

rich adder
#

back when microsoft made good hardware

rocky canyon
#

back when most hardware was still Beige

rocky canyon
#

i mean i remember it coming thru the com ports

rich adder
#

thats COM port yes

rocky canyon
#

back when u had to set up ur inputs before the game started

#

MsDOS games were the best

rich adder
#

midi usually is like a round thing looks like PS2 connector (not playstation, i meant he mouse)

shell sorrel
rocky canyon
#

im actually working on a rebind system like that

#

where u start eh game.. and then it asks u for each bind

#

so u can use any device

#

might be what i actually do today

shell sorrel
#

with the round plugs

rich adder
#

oh yea.I haven't played much with MIDI besides music

rocky canyon
#

for rebinds would u store that info in a data file to load? or would u do it every time u launch?

shell sorrel
#

the round midi ports are too big for a single height card

rocky canyon
#

im thinking like a fpv drone simulator.. where u can use rc remotes and etc

rocky canyon
#

any device

rocky canyon
#

got it ๐Ÿ’ช lol

rich adder
#

File.WriteAllText
boom done

shell sorrel
rocky canyon
#

this is what i got so far :).. lol

#

then it would go "Rebind Action: Blank: -> Bound to X -> Confirm

rich adder
rocky canyon
#

yup, back when PC's were magical

#

and my dad was a wizard

#

now its reversed ๐Ÿ˜„ and i help my father build his stuff

shell sorrel
rich adder
shell sorrel
#

USB did not exist yet

rocky canyon
#

with InputActionReferences

rich adder
rocky canyon
#

yup. and connectors had set screws

#

to bolt it to the pc

rich adder
shell sorrel
# rich adder dark times

also those round midis are still used, my audio interface has them and it can talk to my outboard gear via it

rocky canyon
#

i have vague information from a big-head around here that thats how they do it

#

so i figured id be a poser

rich adder
rocky canyon
#

its possibly Contrivance ๐Ÿ‘‡

brave robin
#

heh

#

There's so many ways to use the new system, it's a strength but also a learning curve

rich adder
rocky canyon
#

but for a universal rebind

#

where i could technically use anyinput

#

im not so sure

shell sorrel
#

really the hardest part about it is making a ui for it

brave robin
#

There's a helper in the new input system for rebinding, which makes it super easy. You turn it on and it listens for what the user does, and maps to that. And you can filter out certain inputs too

rich adder
#

I think there is a github project unity has for rebind example ?

rich adder
#

could've sworn i did see it

brave robin
#

I forget where in the docs it was, but searching through for rebind should find it for you. I tried it out once and it was very simple

rich adder
#

one thing you gotta give unity is eventually they do make decent utils classes to easily work with their new features

brave robin
#

I'm not sure how to save the rebindings in the player prefs, but it should be possible somehow

rocky canyon
#

that way theres no UI really..

#

unless ur meaning UI navigation rebinds

rich adder
brave robin
rocky canyon
#

niice

lapis parrot
#

followed this guy's tutorial (https://www.youtube.com/watch?v=OQ1dRX5NyM0) on enemy FOV and this ``` private Vector2 DirectionFromAngle(float eulerY, float angleInDegrees)
{
angleInDegrees -= eulerY;

    return new Vector2(Mathf.Sin(angleInDegrees * Mathf.Deg2Rad), Mathf.Cos(angleInDegrees * Mathf.Deg2Rad));
}
``` is showing errors, saying top-level statements must precede namespace and type declarations and the modifier "private" is not valid

In this video ,we're going to be taking the 3D Field of View system from my previous tutorial and converting it to 2D! Good huh?

Join me and learn your way through the Unity Game Engine, the C# language and the Visual Studio editor. Remember, if this video was useful then DROP A LIKE! ๐Ÿ‘

๐Ÿ’ฏ Want to help me out and allow me to keep making t...

โ–ถ Play video
shell sorrel
rocky canyon
#

ohh u mean that

rich adder
rocky canyon
#

yea, that will be a dedicated UI panel

shell sorrel
#

also if you want to support different sets for controller vs keys/mouse

rocky canyon
#

i hopefully get it setup where u can use 2 devices at once.. if u felt like it

shell sorrel
#

also the swapping of UI elements for controller vs keyboard mappings

rocky canyon
#

like bind ur Joysticks for movement..

rich adder
#

check your curly brackets, also make sure your IDE is configured @lapis parrot

rocky canyon
#

bind ur keyboard for jumping

#

etc

lapis parrot
#

alright

lapis parrot
brave robin
#

Also the rebinding supports multiple keys, like shift+F11 to do something

#

bind shift+alt+print screen to jump

rocky canyon
#

ohh

#

ill have to remember that caveat

#

wouldnt want that

brave robin
#

You can prevent it, the rebinding has filters

rich adder
rocky canyon
#

if i see a reason to need hotkey type stuff ill figure it out

#

i already made an Editor hotkey system but it uses the old input class

#

and nested ifstatements

brave robin
#

I think the big win with having a rebind system that accepts any input is accessibility devices will just plain work. If someone gets one of those special multi button controller for accessibility reasons, the system will just figure it out for you

short hazel
#

You can export rebinds to JSON and import them back later IIRC, there are methods on the input actions

rich adder
#

ahh nice so I assumed correct

rocky canyon
#

i have an RC controller.. and uses HDMI or w/e the basic periphial port thingy is..

#

but its inputs are ALL over the place

#

so a rebind system is about the only way i can remedy that

#

w/o manually hardcoding everything

rich adder
split plover
#

Is there a way for something to check if the controller is grounded once

rocky canyon
#

boolean flag?

#

*groundedOnce = true, false

#

it'd be the exact same way u do for multiple jumps..

split plover
#

i wanted to do a boolean flag but i don't know if i should make random boolean flags for anything i dont know how to fix without one

rocky canyon
#

canJumpAgain = true

rich adder
split plover
rocky canyon
#

well when u jump stop that

rich adder
#

hell before I learned a proper FSM everything was bool flags xD

rocky canyon
#

when u jump u should zero out ur gravity anyways

#

its the common way to do that... that way ur jump force isn't cancelled out by any of it

rocky canyon
split plover
#

well ig i'll just add a boolean for it

rocky canyon
#

its still a switch statement...

split plover
rocky canyon
#

1 step above if else chains

rocky canyon
#

ur controller would work based on states..

rich adder
rocky canyon
#

idle -> moving -> running -> attacking etc

split plover
rocky canyon
#

but ill keep dreaming for now

brave robin
#

Infinite Stateless Nonmachines

split plover
#

dont even ask how i did it i dont know myself

rocky canyon
#

we know.. we all been there

rich adder
rocky canyon
#

i have not..

#

those terms make me shiver

#

๐Ÿ‘ป

rich adder
#

its very similar to how statemachines work tbh

#

except its more like Animator

rocky canyon
#

well when i nail state machines then ill try out the behaviour tree

#

i still need to mock up a good one w/ Enter and Exit states and all that

rich adder
#

Unity lets you do custom nodes so its pretty powerful

rocky canyon
#

ahh so it is exactly like the animator

#

with transitions conditions and whatnot

rich adder
#

pretty much

rocky canyon
#

well.. i assume the conditions would be codebased but yea

rich adder
#

they have some premade nodes already too

rocky canyon
#

bookmarked ๐Ÿ’ช

rich adder
#

most of them do what you want

rocky canyon
#

ill give it a look thnks

rich adder
#

unity has this concept for behavior to "tell story" through action

#

so like "Enemy waits 4 seconds then moves to target"
rather than a bunch of variables and code clouding the whole thing

rich adder
# rocky canyon ill give it a look thnks

check out Llama academy he has a whole series on Behavior, its really good. Hopefully unity doesn't abadon this too cause I heard most of the team got axxed and now this project is kinda in limbo...typical unity shit lol

split plover
#

i just realized my code wasn't working cause i set a float to a bool what the fuck am i doing bro

rich adder
split plover
#

i didn't even need the bool for if the character was grounded or not i genuinly just fucking had the jump power as a bool

split plover
#

it was giving me errors and everything and i didn't even notice

#

i need to go to bed bro ๐Ÿ˜ญ

rich adder
#

are you looking at the error in Unity console or the actual IDE / code editor

split plover
#

there are errors in both ๐Ÿ˜ญ

rocky canyon
rich adder
#

ok good at least IDE is configured

rocky canyon
#

u shouldnt be able to even compile that

rich adder
split plover
rocky canyon
#

now studio is ๐Ÿ’จ

rocky canyon
#

when u save u code and click into unity,
that little progress bar is it compiling all the code

rocky canyon
#

if u have something that wont compile u get that error..
"Fix all Compile Errors before entering Play Mode"

#

umm this one?

split plover
#

oh

rich adder
split plover
#

i never notice it

split plover
rocky canyon
rich adder
#

bro got windows 40k

rocky canyon
#

hopefully it bakes cakes faster than lights

split plover
# rocky canyon

maybe next time i shouldn't ignore the "fix all compile errors" and i should think thats the reason my movement completely broke and not the fact my jumping wasn't working

rocky canyon
#

ur game wont even run w/ compile errors

rich adder
split plover
rich adder
#

it will give you a warning popup tho

split plover
#

i am way more dumb than i thought

rocky canyon
#

yup compile errors are errors in the code itself (like code that wont work at all)

#

runtime errors are code that works but may not work correctly

#

runtime errors will show during playmode in the console..

#

compile errors will not.. (b/c it cant compile to know whats wrong)

#

that why we then refer to the IDE

#

and let it help point out the errors

split plover
rocky canyon
#

ya, those would be runtime errors

split plover
#

makes sense

rich adder
#

Null Reference Exceptions for example

#

those only happen at runtime

split plover
rocky canyon
#

but that means the code compiled!!

#

so win win ๐Ÿ˜„

#

but then fail

split plover
#

i dont think im good at coding

rich adder
rocky canyon
#

5 years in and im still not good at coding

#

but i can make things happen!

#

just not Optimally

split plover
rich adder
rocky canyon
#

as long as their concerned it either works it doesnt

brave robin
#

Undertale is horribly coded. But a great game

rocky canyon
#

i would argue that Celeste is also coded horribly

brave robin
split plover
rocky canyon
#

from what ive heard

split plover
#

idk how much bad code affects performance so idk how much i have to focus on it

rich adder
rocky canyon
split plover
rocky canyon
#

thats the word around here

rich adder
split plover
brave robin
rich adder
rocky canyon
#

make it 150 and ill call it good

split plover
rocky canyon
#

ur entire class should never be that big

rich adder
#

also you can't make it illegible and confusing for you and your future self, thats what also makes good code

rocky canyon
#

if it is.. ur doing something wrong ๐Ÿ˜„

#

back when i first started i had a character controller that was 2500 lines long

split plover
split plover
#

that does sound like what im gonna end up having but

rocky canyon
rich adder
brave robin
#

My level builder editor tool is around 2000 lines, but its just editor code so I don't care

rocky canyon
#

i got it dropped down to 300

#

with the EXACT same functionallity

rich adder
ruby python
#

Is it at all possible to import/use an image larger than 16k via code? (ie. read the image directly from disk or something?)

split plover
#

So quick question for later should i make different selectable characters have my base player script as a parent or should i use the base player script and hope that 2000 lines of code doesn't break the game

rocky canyon
#

a level builder i wouldnt expect anything less than 500 lines

#

2000 lines wont break the game.. it might break ur sanity

#

u basically want to worry about readibility at first

#

make it readible.. make it understandable

#

dont shoot urself in the foot

split plover
rich adder
#

it just makes it difficult to debug if you cramm so many things in one spot

split plover
rocky canyon
#

we all have...

#

if we're doing it right

split plover
#

well i dropped a knife on my foot but basically the same thing since its an expression

rocky canyon
#

theres no way someone can forsee every issue or bug

split plover
rocky canyon
#

superhuman ๐Ÿฆธโ€โ™‚๏ธ

rich adder
#

You can only learn by making mistakes and correcting them

split plover
rocky canyon
split plover
rocky canyon
#

lol.. good thing we dont code with knives

#

ull be fine

split plover
#

anyways i am gonna go back to coding though since i have a lot more code to rewrite

rocky canyon
#

๐Ÿ€

split plover
#

have a good day guys im getting off discord for now

rich adder
rocky canyon
#

u do the same

rocky canyon
brave robin
rocky canyon
#

doctor, i dont need to go to therapy.. thats not what it looks like.. im just a bad coder

brave robin
rocky canyon
#

i figured thats abunch of classes

brave robin
rocky canyon
#

๐Ÿ‘€ i bet thats a crazy looking class

brave robin
# rocky canyon i figured thats *abunch* of classes

It is now, a lot of it got moved out into the base class. But I remember when all of the conditions for neighbours were in it, plus it was doing some funky bitmapping to generate the inspector icons, so that you didn't need separate texture assets

rocky canyon
#

i forget.. does that system support custom rules

#

or is it all just basic stuff

brave robin
rocky canyon
#

i have total respect for anyone building tilemap based games

#

not my cup of tea.. but impressive

#

sounds like that algorithm.. whats it called...

#

wave collapse

#

something

brave robin
#

My 3D dungeon crawler uses tilemaps to automate the arrangement of 3D assets in each cell of the map. Its super useful for that, but only that, as there's no 2D sprites

rocky canyon
#

wave function collapse

#

thats it

brave robin
#

that's for procgen, which isn't a requirement for most tilemap games

rocky canyon
#

ahh

brave robin
#

But it does use rules, so its related

rocky canyon
#

okay.. for whatever reason i think of the two as being similar

#

probably the most intimidating algorithm/function ive encountered so far

brave robin
#

The rules for wave function collapse are a bit more extensive, since you're not just determining what variation of a tile fits that position, but what other tiles are allowed to be near it

#

like shore can be next to water and land, but water cannot be next to land

fiery swift
#

Im returning to unity after a few years and ive tried to make a first person controller but I cant for the life of me get a camera controller that 1 is smooth (and not choppy/lagging behind) and 2 is compatible with the player (if I look in a circle and hold W down the player should move in a circle, not a straight line) could anyone please help me?

split plover
#

Quick question about Visual Studio Community 2022, Why does it keep telling me to make random things readonly?

rich adder
split plover
#

Oh

rich adder
#

micro-efficiency

#
  • prevents it from being touched accidentally from other places so its also a form of that
split plover
#

Yeah i dont really see much of a point in that but i might use it in the future if i ever have to i guess

rich adder
#

basically you're saying (in code) you can only assign it here (initilizer / constructor)

fiery swift
frail hawk
#

fine

rich adder
fiery swift
#

not really

rich adder
#

then why are you here lol

fiery swift
#

because idk how to fix it

rich adder
#

is there a specific reason not to use premade character controller

fiery swift
#

yup

frail hawk
#

i feel like the rb gives you much more control

rich adder
#

only kinematic

#

such as CC

fiery swift
#

yes but I want to use it because Im trying to preserve and move physics and momentum between different places like in portal

rich adder
#

imo Dynamic Physics based RB is less control because you're dealing with outside forces affecting it

rich adder
fiery swift
#

wdym

rich adder
#

pretty rare for characters to have dynamic physics based rb, thats usually done for Active Ragdoll type controllers

rich adder
# fiery swift wdym

things like momentum and velocity / acceleration can be easily coded but you're more in control of it rather than the physics system

fiery swift
#

but I want physics

#

the whole point is to make it realistic and physics based, it wouldnt be fair for the player if I could magically alter the characters velocity

rich adder
#

what specifically about physics though ? more things need to be considered with dynamic bodies especially the execution order of events and where certain thiings are called

rich adder
#

solutions like KCC exist for a reason lol

fiery swift
#

why comment on how I want to make my games? If you cant help me just say so, pretty unnecessary to slander my stuff if youre not going to help me

rich adder
fiery swift
rich adder
#

how's that slandering ?

#

using the word Realisitc in a video game is pretty hilarious, what does it even mean lol

fiery swift
#

okay maybe not slander, but not help either

polar acorn
#

Your statement is vague. "Realistic and Physics Based" describes basically nothing

fiery swift
#

i think you know what realistic means

polar acorn
#

It's a request for more information in order to answer

rich adder
#

i cant help if I dont understand the exact features you deem "Realistic" etc

polar acorn
#

Unity's built-in physics aren't "realistic", they "realist-ish". If you want realism you're going to be doing Kinematic RBs and computing the math yourself

fiery swift
#

dude youre acting like an ai who cant think for himself. I already explained this. preserving momentum and velocity is not the kcc's strong suit

fiery swift
polar acorn
#

KCC handles momentum quite well, actually. It returns the velocity as an out vector after doing any processing on it so you can store it wherever

fiery swift
#

well I dont think so ๐Ÿคทโ€โ™‚๏ธ so id rather use a rb

polar acorn
#

But you don't want to do those

rich adder
#

KCC is still a rigidbody, is just kinematic where the forces are done for you to have more control

#

i think you misunderstand Rigidbody is not necessarily dynamics only

fiery swift
# polar acorn But you don't want to do those

yes believe it or not, I dont want to recode my entire movement code. Id just like a camera controller, but now you two are making it about something else for no reason at all. Why keep up with this if youre not going to help?

rich adder
#

the movement code plays a big part on how the camera behaves
especially the jittering thing

polar acorn
#

I don't even know why I'm trying to argue with you about how better to phrase your own problem, if you don't actually want any answers I don't know why it would matter to me

naive pawn
#

@fiery swift could you summarize your constraints and goals

fiery swift
#

forget it

rich adder
#

very strange..

fiery swift
#

not really

rich adder
#

Mate you have the maturity level of a teen, look i get it but its not gonna get you anything to be that way to others who are trying to better understand the problem / possibly offer alternatives

sharp bloom
#

In few seconds in this clip, my camera script applies a weird "snap" motion. It always does this when I enter playmode once, but after that it works normally. What's up with that?

rich adder
#

get offended or thinking someone is being critical just by asking some question is a weird flex..

sharp bloom
polar acorn
#

if it only happens on startup, I wouldn't really worry about it

sharp bloom
#

Yeah I thought it might be something like that

rich adder
naive pawn
#

yeah it might be accentuated by Time.deltaTime

fiery swift
polar acorn
naive pawn
#

the reload domain actually occurs after some loading so the deltaTime is gonna be way bigger than normal

naive pawn
sharp bloom
# rich adder you should probably show the code as well
void Update()
    {
        PlayerMove();
    }

    void PlayerMove()
    {
        var inputDirection = gameInput.movementInput.normalized;
        Vector3 velocity = (transform.forward * gameInput.movementInput.y + transform.right * gameInput.movementInput.x);
        
        transform.Rotate(Vector3.up * gameInput.mouseDelta.x * Time.deltaTime * mouseSensitivity, Space.Self);
        transform.Translate(velocity * movementSpeed * Time.deltaTime, Space.World);
        float cameraTilt = Mathf.Clamp(gameInput.mouseDelta.y, -0.5f, 0.5f);
        
        playerCamera.transform.Rotate(Vector3.right * gameInput.mouseDelta.y * Time.deltaTime * -mouseSensitivity, Space.Self);
    }
naive pawn
rich adder
sharp bloom
#

Okay got it

#

Thanks

fiery swift
rich adder
#

spoiler alert : Movement is related to the camera

naive pawn
# sharp bloom Okay got it

it won't solve the issue (it wasn't really an issue to begin with, just first-frame things) but that's just a latent issue that happened to make the effect stronger (and it'll make mouse input inconsistent with different framerates)

fiery swift
naive pawn
rich adder
polar acorn
# sharp bloom Okay got it

You will probably need to change your math a bit, your mouse sensitivity number probably needs to increase

naive pawn
sharp bloom
fiery swift
naive pawn
rich adder
#

you should use a separate value you add onto

polar acorn
naive pawn
#

mouseDelta is the distance the mouse moved since the last frame

rich adder
rocky canyon
#

is it common to use a Struct to grab input / frame? and then read from the struct?

#

ive now seen this twice..

naive pawn
#

it seems to be a common thing in tutorials, ive seen it a lot of times

#

well, not a struct, but an intermediate class that grabs the input

rocky canyon
#

public struct FrameInput
{
    public bool JumpDown;
    public bool JumpHeld;
    public Vector2 Move;
}
rocky canyon
#

seems clean

#
        private void RotateCamera()
        {
            // get our input
            Vector2 inputValues = new Vector2(Input.GetAxisRaw("Mouse X"),Input.GetAxisRaw("Mouse Y"));
            inputValues *= lookSensitivity * smoothing;

            smoothedVelocity.x = Mathf.Lerp(smoothedVelocity.x,inputValues.x,1f / smoothing);
            smoothedVelocity.y = Mathf.Lerp(smoothedVelocity.y,inputValues.y,1f / smoothing);

            currentLookingPos += smoothedVelocity;

            // Clamp the vertical rotation to limit the angle
            currentLookingPos.y = Mathf.Clamp(currentLookingPos.y,-verticalLookLimit,verticalLookLimit);

            // rotate the camera on its X axis (up and down)
            transform.localRotation = Quaternion.AngleAxis(-currentLookingPos.y,Vector3.right);

            // rotate the player on its Y axis (left and right)
            controller.transform.localRotation = Quaternion.AngleAxis(currentLookingPos.x,controller.transform.up);
        }``` heres mine... as example / code review *putting myself out there*
pallid nymph
#

mm... I think the usual approach to inputs is to have 1 class that does stuff (say character movement), and another one that gets the inputs and converts them to whatever the first class needs... idea being that if you wanna do AI, it won't use inputs, but it'll tell the same class that does things what to do

rocky canyon
rocky canyon
#

i always use private variables Vector2s and bools

#

but never did it with a struct

rich adder
#

yeah this is mainly why I just make methods that accept a value rather than referencing input classes

#

public void Move(vector2 input)
this can come from player Input, AI etc .

naive pawn
#

yes this is a mistake that i realized a few days ago lmao

rocky canyon
#

just odd to me... thats all

naive pawn
#

my player controller is tightly coupled with input and i had to make a "mirror" kind of enemy with a completely separate script lol
had to then sync some changes that affected both

rocky canyon
#

i guess if i wanted to use the input from another class it'd make more sense

pallid nymph
#

if you just use the struct as a replacement of a few fields - it's almost the same, so up to you I guess (I wouldn't bother with a struct unless I wanna be sending those around together as one thing)

rich adder
rocky canyon
rocky canyon
#

lol

naive pawn
# rocky canyon

thonk not that it matters, but wouldn't a class be increasingly more performant as the amount of input actions grows

#

not one every frame, just one that has fields reassigned to

pallid nymph
rich adder
rocky canyon
#

ya, if i were to grow the struct i'd probably just swap to the input system anyway

#

events > pollin

brave robin
#

struct is more performant until you need to copy a very large one

rich adder
#

true dont make it too big

rocky canyon
#

coo.. coo..

naive pawn
rocky canyon
rich adder
#

but maybe you can create smaller structs, I see thats what unity does a lot

rocky canyon
#

and those get loaded in at menu screen

rich adder
#

struct within struct

naive pawn
rocky canyon
#

structception / structursive

brave robin
#

I do use some large structs, but because I'm less concerned with speed and more about garbage, because I use and throw these structs away at a fast rate
As classes they'd spew garbage constantly

pallid nymph
#

generally the performance considerations should come after profiling and detecting issues... everything else is kinda guesstimates, it really depends on usage

naive pawn
#

yeah to be clear i'm talking about like 3 extra MOVs

#

nothing that matters, just theoretically

rocky canyon
#

-# ai 2cents

eternal needle
#

there isnt really a reason to use a struct there. you dont really need structs in many cases at all

rocky canyon
#

cool cool.. thats all i was really wondering about...

eternal needle
#

yours falls under a few of those categories but does not "logically represents a single value"

rocky canyon
#

i dont see it very often.. but when i do its liek chris mentioned.. and its usually in tutorials

naive pawn
rocky canyon
#

or github code

pallid nymph
rich adder
#

structs are must if you're doing Netcode

#

they are optimal to send over the wire

#

you don't want to be sending reference types over the wire

#

RPC did not support class types

pallid nymph
#

I'm 97% sure you can extend it (implement some interface or something) to handle classes... but also my approach is: just go with what's easiest, until you have a reason to be "smart"

eternal needle
pallid nymph
rocky canyon
orchid swallow
#

why is yvelocity not resetting to zero?

pallid nymph
#

That is zero... kinda ๐Ÿ˜„

#

no idea what and how is setting it.. but yeah, that's (most likely) 0 with a bit of float imprecision

naive pawn
#

if i had to guess, it's the amount of gravity that can be applied within 1 tick
but that's kinda a poor guess without actually seeing code

naive pawn
#

!code

eternal falconBOT
naive pawn
celest holly
#

is there a really easy work around to get enemies to follow a predefined path instead of calculating rays around them all the time? im trying tomake a pacman ghost ai but it would be so much easier with a path

naive pawn
#

-# i mean if you re-implement the original AI that'd probably be easiest, with everything being on a grid and such

rocky canyon
#

true story..

#

good watch regardless ๐Ÿ™‚

#

if u use normal pathing it wont be similar to the original.. it'll be soo much more predictable

naive pawn
rocky canyon
#

classic AI

#

i think everyone should know the ghost's rulesets

naive pawn
#

well, maybe skip the skewed randomizer lol

rocky canyon
#

well i take that back. (normal pathing would be fine)
but u'd still want waypoints and some kind of behaviour tree

#

to have the ghosts move unique from each other

wise cairn
#

how do i fix this?

rich adder
wise cairn
#

what is new input class and how do i use it, i'm just doing what i saw on the unity essentials guide

rich adder
#

most tutorials still use Old if you want to use new there are guides to do so, and documentation. Having it on both you can learn a bit of new one

wise cairn
#

how do i use the new one

wise cairn
#

thank you

wise cairn
rich adder
wise cairn
#

where is that, very new to unity sorry

rich adder
#

yes make sure to google as well for these.
Edit -> Project Settings -Player

wise cairn
#

oh lmao i just found it right before you sent that

#

am i blind i can't find input handling ๐Ÿ˜ญ

#

nvm

spiral oracle
#

why doesn't this work, doesn't Transform have a position property?

#

bruh I forgot the index

#

nvm

polar acorn
lilac fractal
#

Hello friends, I come for humble guidance once more.
I'm making a game that uses projectile physics to interact with enemies.

Projectiles have weight, bounciness, and speed
Enemies have weight as well

I've set these up as custom fields either in scriptable objects or monobehaviors, but I'm sitting here looking at the fact that some of these concepts are mirrored - projectiles and enemies have RigidBody2D which has weight.. and now I'm learning about PhysicsMaterial2D, which has its own bounciness.

Since my game IS physics-based, I'm somewhat thinking I'm hurting myself by recreating physics concepts, and I should use the built-in stuff.
What do you think?

spiral oracle
sour fulcrum
lilac fractal
#

no reason to believe it doesn't work for me

#

plus I don't have to worry about keeping my scripts & editor in sync

nimble apex
#

lets say i have a room list for players to join, currently its 50 at maximum, ofc i need to refresh it at a constant rate , maybe 30sec or so, what ways u guy recommend, performance wise

  1. destroy and respawn
  2. object pooling it and do 1
  3. store them in a list in first invocation and then modify the element in the list (which is what im trying to do)
#

3 for me should be the cheapest method among others

teal viper
eternal needle
nimble apex
#

ok i think i gonna do 3

nimble apex
#

๐Ÿ‘

pallid nymph
#

Isn't this out of game? Performance is unlikely to be particularly important.

faint sluice
#

Hello, has anyone faced the issue where when building for Android just stops at first scene? Like there's no errors or anything but build just freezes and in task manager it says editor not responding

#

It just shows "building scene 0" endlessly

pallid nymph
faint sluice
#

Even cancelling doesn't work, have to restart the editor

pallid nymph
#

It's a file... somewhere ๐Ÿ˜„

#

Ask Google, I don't remember the exact location

faint sluice
cursive cipher
#

In unity I am using HDRP 17.0.4. My project is a flight simulation and terrain is from cesium. I have implemented volumetric clouds in my scene. Since it is unity then I have to origin shift the whole environment. But the volumetric clouds are not origin shifting properly as they are jumpy each the origin is shifted.

Below is my script that I have implemented for origin shifting the whole environment including clouds.

topaz mortar
#

What's a simple way to do local avoidance in 2d with Vector2.MoveTowards?
Is there any way to find an available path to the left or right of an obstacle?
Or do I just throw out several linecasts until I don't hit an obstacle, then move that way?

#

Or is it possible to do a ShapeCast and then calculate the best new target position from that?

eager spindle
#

pathfinding

#

a whole topic of research

eager spindle
#

It's a little difficult to explain over discord, you might want to look into pathfinding in 2d

topaz mortar
#

that's not what I want to do at all ... my units know where to move, I don't need pathfinding
I want them to go around moving obstacles on the way (this is called local avoidance)

what this means for my game is, my units are moving to a fixed point with Vector2.MoveTowards, this works
but other units are also moving to that point and back, around it, ...

I just need a simple way to make them move left or right a bit, so they look like they're avoiding each other (read: not all my units are stacked on top of each other)

#

doesn't need to be perfect at all

eternal needle
# topaz mortar that's not what I want to do at all ... my units know where to move, I don't nee...

if we're talking about some arbitrary obstacles, then this is an issue with your pathfinding. they shouldnt be trying to move into arbitrary unknown obstacles in the first place.
Otherwise its entirely up to you how this avoidance should work while making sure its still going to be on a valid path after taking a detour. If you want it to just move left or right, consider changing the direction based on the normal of the surface infront of it. theres no guarantee this is a valid path though

#

it would also be very easy to draw up cases where this fails entirely

topaz mortar
#

yeah that's exactly what I'm asking, how do I "change the direction based on the normal of the surface in front of it"? I don't really know what that means or how that works

#

I've looked up some tutorials, but none of them work with Vector2.MoveTowards

#

and I'm extremely bad at understanding the logic/math behind movement

eternal needle
eternal needle
topaz mortar
#

the tutorial I watched just made the unit move forward and adjusted the rotation

#

which doesn't work for my game

topaz mortar
topaz mortar
#

yes

#

hence the Vector2 ๐Ÿ˜›

median hatch
#

why not raycasting?

eternal needle
topaz mortar
#

I'm using raycasts now to detect if another unit is in front, then move the target a bit to the left, but it's very hard to figure out where to move the target

delicate portal
#

Hey, I added two more lines to the manifest.json file
"com.unityfx.outline": "0.8.5", "com.unityfx.outline.urp": "0.5.0",
And I got this error:
What did I do wrong?

north kiln
topaz mortar
topaz mortar
topaz mortar
#

Currently I'm using raycasts with a loop that moves the end location left a bit each time, but that's obviously bad

glad ibex
#

How do I get a list of vertices of a mesh that touch another (specified) mesh

median hatch
#

idk if thats what youre doing already

topaz mortar
#

it's not moving towards an enemy, it's moving towards a fixed point on my map
but other units often cross paths and I don't want them all stacking on top of each other
but the units would, after adjusting their path, still have to move to the initial location

#

my unit are spawned in a building, then they move towards a resource on the map, they harvest the resource and then run back to their spawn building to deposit
a building can have several units, so right now they're all stacked on top of each other, I just want to make it look a bit better

#

and have it work with other buildings & units too

sour fulcrum
#

why do you think this isn't pathfinding

topaz mortar
#

you can call it whatever you want, but I have set checkpoints on my map and I'm using Vector2.MoveTowards to move between the checkpoints

sour fulcrum
#

the vector2 movetowards part here doesn't matter for your question

median hatch
#

and add each enemy as an "obstacle"

topaz mortar
#

A* is terrible for stuff that constantly moves around

median hatch
#

what else then?

#

make your own pathfinding algorithm?

sour fulcrum
#

I've had a good experience with Unity's navmesh agent avoidance stuff in a 3d context

topaz mortar
#

I'm working with Quantum, it doesn't support any of that stuff ...

median hatch
#

Quantum?

topaz mortar
#

it's a multiplayer framework for unity

median hatch
#

it doesnt support A*?

sour fulcrum
#

what doesn't it support

topaz mortar
#

A* doesn't solve my issue ... I have 100s of units moving around, they know where to move so I don't need A*
I need local avoidance to avoid other units crossing a units path

eternal needle
# topaz mortar wdym you don't see how MoveTowards has nothing to do with it? It's how my units ...

Because it doesn't matter if they use MoveTowards. Maybe reread points i said above. This is just a method to manipulate a vector. The function Vector2.MoveToward is NOT moving the transform.

Anyways the main answer to this is what is still what I said initially. #๐Ÿ’ปโ”ƒcode-beginner message
You either fix the pathfinding or modify your movement vector based on the normal of what your physics casts hit

median hatch
topaz mortar
median hatch
#

creates this bubble around the object

topaz mortar
#

quantum 3 doesn't support moving objects with navmesh

median hatch
#

and you set the radius so other objects move a certain amount around them

#

not saying to use navmesh

#

im saying you can do something similar

sour fulcrum
glad ibex
#

How can I get a list of vertices of a mesh that touch another (specified) mesh?

eternal needle
topaz mortar
eternal needle
topaz mortar
eternal needle
sour fulcrum
burnt vapor
#

I'm confused how it's Bawsi's problem when you don't know the terms

#

I wanted to say that I would personally Google these terms as is done with plenty of other things, but this was already pointed out

chilly prism
#

how do i make an object constantly rotate in the z axis in unity

#

i want an object to constantly spin

#

nvm i figured it out

sharp bloom
naive pawn
#

it's not really a new phenomenon

fickle plume
# topaz mortar maybe trying to help ppl in a beginner channel is massive overscope for you

First of all, don't snap at people trying to help you.

Second, using pathfinding like A* or even more rudimentary one will certainly make collision avoidance much simpler.
But if you are using a naive approach and just want an object take evasive actions you were advised already, raycast the obstacle, and if it has a meaningful shape that can help to figure out which way to star avoidance, start turning that direction. If you are dead set to using MoveTowards method, you'll have to give it an arbitrary point to move towards for several frames to clear the target.

sharp bloom
#

I had that kind of naive collision avoidance in one of my previous school projects, and honestly while it was easy to initially implement, it was horrible to expand on and had bugs all the time (objects getting stuck, overlapping with each other etc.)

#

Now I would bite the bullet and implement a proper pathfinding algorithm right away xd

fickle plume
#

Yes, it will get very messy when more objects are introduced.

#

To manage traffic you need to act on some amount of data, can obstacles clear eventually, how long would be to go around and is it worth it, etc.

eternal needle
#

I did try to bring that up from the start. #๐Ÿ’ปโ”ƒcode-beginner message
It did seem like they were asking about going around another AI but I had doubts since the movement seemed purely based on going towards an end point

eternal needle
# sharp bloom Is it just me or why does this seem to happen constantly now in this channel? Be...

It definitely has been happening for awhile. Anything that isnt a direct solution to a problem leads to more frustration. Maybe relating to the same mindset a lot have with "its just this ONE problem then I'm done!". Beginners also seem to take realistic advice as a personal attack a lot of time. Being told a feature isnt realistic (usually multiplayer) does seem to get a lot of hate back

acoustic belfry
#

Hey, what negative differences have using an Int and an Enum State for States apart of readability. Cuz now realizing i have found some good uses for Int Method but im not sure if is a good idea

naive pawn
#

enums are just integers with names

#

the main benefits of having an enum are the type name and each member's name
enum members show up as a dropdown by name in inspector fields as well

eternal needle
eternal needle
#

There isnt really a reason to use ints as states imo because you're not going to be doing any math on them anyways. Any negative effects (if we're talking performance/memory) would be almost 0 in relation to the whole rest of the game

acoustic belfry
naive pawn
#

(int)enumValue

#

that's what a cast is

burnt vapor
#

Also note that enums don't define a clamp of numbers. If your enum goes to 5 you can still define 6 and it will be valid. There is absolutely no security here

trail heart
naive pawn
burnt vapor
acoustic belfry
#

I mean cuz this also means i can make a flexible function for detect states

I mean.

If i need an animation event or external script to change this script states, if i used INT i could just change it. But i dont know what to do with this

burnt vapor
#

Or just various operations in general involving enums. Modern .NET has massively improved its performance, it's really bad in Unity

naive pawn
#

it's just a single bitwise operation you can very easily write yourself

burnt vapor
#

That's my point...........

naive pawn
#

you made it out like enums can't be used at all lmao

eternal needle
#

I have a sneaking suspicion an enum would never cause a performance issue in relation to literally anything unity related.
This feels like a bit of an exaggeration

naive pawn
#

"very very very very very basic support", "it's really horrible"
when it's just a & with a name that's missing lmao

burnt vapor
#

It is if you excessively use it like many other things. It won't matter if you just use it once in a while

burnt vapor
#

or you only read half of it

acoustic belfry
#

And also a function in the Enemy base that puts a delay (wait until timer =< 0) and then changes state. Is hard to do so if the base doesnt havd the state.

But each enemy has it own stayes

naive pawn
north kiln
#

It's totally fine if you just avoid the bad APIs that box, which is very easy to do with some basic knowledge

burnt vapor
#

Enums and their functionality have bad performance in Unity, because it's not optimized. That's the whole point I am making

#

HasFlag and such

naive pawn
#

and HasFlag is more optimized?

burnt vapor
#

Point is that you should just write your own API instead because you don't have all the edge cases being covered

naive pawn
#

it's a single bitwise operation, it's not gonna matter
HasFlag would be less optimized with the function overhead lol

#

performance is nowhere near a concern for this

north kiln
#

HasFlag doesn't box in modern .NET, that's the only enum API I'm aware of that sucks in Unity

acoustic belfry
#

But guys. What i should do?

eternal needle
burnt vapor
acoustic belfry
#

So i better use Int then?

burnt vapor
#

No

#

You can just write your own methods instead

eternal needle
#

I do wonder how many thousands of times id need to call it to see a performance issue

#

Per frame

naive pawn
burnt vapor
#

No it exists, yes

#

I mean that like LINQ in Unity, there is a point to be made about performance

naive pawn
#

about GC?

north kiln
eternal needle
glad ibex
acoustic belfry
glad ibex
acoustic belfry
#

Also how u would do the animation thing?

burnt vapor
#

You don't really have functions in C# because a function is always part of a class, making them a method.

trail heart
acoustic belfry
eternal needle
burnt vapor
acoustic belfry
#

Atleast for what i been told is similar to call another script function

burnt vapor
#

Anything with a body of code that gets invoked is a method (or a property)

acoustic belfry
#

I thought those were functions ..

#

Or You mean

Default functions

burnt vapor
#

You can call them functions, everybody will understand what you mean with that

eternal needle
burnt vapor
#

But C# doesn't really have functions, because functions are not part of a class instance like what we have in C#.

acoustic belfry
#

Oh

burnt vapor
#

Like C, that language has functions I believe

#

Because you don't put them in a class

#

The term is very broad, you can just call them the same. I only mention this because you thought they were different here, but in C# they are the same pretty much

#

But the true name would be methods

sharp bloom
glad ibex
naive pawn
trail heart
#

It's possible to do boolean intersections in code, but rarely worth the trouble especially every frame

burnt vapor
#

If you Google it now you will also have half of them saying they don't exist in C#, and half saying they do exist in one way or another

naive pawn
trail heart
# glad ibex Thank you very much

The effect was really popular a few years ago (mostly thanks to HL:Alyx's bottles) so there probably are assets and implementations that are ready to use as is, not just as reference

glad ibex
sharp bloom
#
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(BoxCollider))]
public class Projectile : MonoBehaviour, IDamageDealer
{   
    public float damage { get; private set; }
    public SO_ProjectileConfig config;

    public void DealDamage(float damage, Idamageable target)
    {
        target.TakeDamage(damage);
    }

    private void Start()
    {
        damage = config.projectileDamage;
    }

    private void OnCollisionEnter(Collision collision)
    {
        if(collision.gameObject.TryGetComponent<Idamageable>(out Idamageable newTarget))
        {
            DealDamage(damage, newTarget);
            Debug.Log("damage dealt!");
        }
    }
}

I put this together to create lots of different types of projectiles. It works but I feel it could be a bit more modular still. I have to "manually" create the prefabs with this script attached.
I wonder if there is a good way to spawn the projectiles at runtime with different prefabs, but still using this same script. I hope this makes sense lol.

I thought maybe just change the mesh of the object, but that messes up the materials also.

spice mist
eager spindle
#

set the clear mode to Background and fill it with a solid color

spice mist
#

should i change the opacity of color?

#

still happening

naive pawn
sharp bloom
cosmic dagger
#

You're issue is creating the individual prefabs with the script from the editor?

sharp bloom
#

I'm making this needlessly complicated tbh

cosmic dagger
#

What you have is fine. The only thing the script needs assigned is the SO . . .

sharp bloom
#

I'm not sure if that's even needed

#

I could probably just set the damage value etc. directly

cosmic dagger
#

You can create a list of SO_ProjectileConfig attached to a separate SO class. When the projectile prefab is spawned, randomly select a SO_ProjectileConfig from that list to assign a different one . . .

#

It's similar to what I do (have done before) . . .

sharp bloom
#

Oh didn't think of that

#

Could be nice

sour fulcrum
#

I usually have 1 profile prefab in this context and then the scriptableobject is in charge of spawning it and giving it the data that might make it different etc.

cosmic dagger
#

That is also another option. The SO can have the actual prefab that is spawned as a field. When you select the random projectile to spawn (based on the SO_ProjectileConfig), access the field to instantiate that prefab . . .

sharp bloom
cosmic dagger
#

Yep . . .

#

You need an Init or custom method on the Projectile script with a SO_ProjectileConfig param that assigns it to the field on the Projectile. This happens during the instantiation . . .

sour fulcrum
#

This isn't the best but for a bunch of prototypes i've done something like

public abstract class ContentBehaviour : MonoBehaviour
{
    public abstract ScriptableContent Content { get; }

    public abstract void Initialize(ScriptableContent content);
}

public abstract class ContentBehaviour<T> : ContentBehaviour where T : ScriptableContent
{
    public T ContentData { get; private set; }
    public override ScriptableContent Content => ContentData;

    public override void Initialize(ScriptableContent newData)
    {
        ContentData = newData as T;
    }
}
public abstract class ScriptableContent : ScriptableObject
{
    public abstract ContentBehaviour PrefabObject { get; }
}

public abstract class ScriptableContent<T> : ScriptableContent where T : ContentBehaviour
{
    [field: SerializeField] public T Prefab { get; private set; }
    public override ContentBehaviour PrefabObject => Prefab;

    public T SpawnContent()
    {
        Prefab.gameObject.SetActive(false);
        T newInstance = GameObject.Instantiate(Prefab);
        Prefab.gameObject.SetActive(true);
        newInstance.Initialize(this);
        newInstance.gameObject.SetActive(true);
        return (newInstance);
    }
}
#

This puts the scriptableobject in complete control of spawning new content and the function it uses to do so injects into the newly spawned prefab asap

#

(i turn the prefab asset off and on between instansiating it in order to delay the awake call until after the so is in the instance)

sharp bloom
boreal night
#

Anyone have tips on how to get started on coding or any resources I can use to help guide me on my journey.