#💻┃code-beginner
1 messages · Page 204 of 1
That thread suggests it's caused by an antivirus program
it's opening the .dll and screwing up Unity's attempt to modify the .dll
Omfg, it's stupid fecking Webroot screwing me up lel
Hi guys! Does somebody know how to make auto scalling? It supposed to looks like 2nd photo
No, only VS Code and Unity
ya the canvas has a setting for exactly that
Your RectTransform anchors need fixing.
check pins in #📲┃ui-ux tells you how to adjust to diff resolutions
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/UIBasicLayout.html
Give the UI documentation a read.
Adjusting the Canvas Scaler will also be important, yes
just type in the resolution u want it to scale to
in the game view you should probably preview it in the resolution u want..
if its not there u can create ur own presets..
Ya! I set it , but it doesn't work as I wanted to, I will try with reading ui documentation
Note that you hsould also test with a variety of resolutions in the game view. This'll make sure your UI works on various displays
I'll grab the game view and squish it like a stress ball
i am about to go insane
over fucking jumping
it just doesnt work
no matter what i try
the logic contradicts itself
me too
i screwed up my air velocity script and now bhopping gives me infinite acceleration
also how would i add a text overlay that can tell me my state, speed, etc
who the hell still uses antivirus
im not finding any helpful tutorials
windows has that feature of them too
lol u will be met with an unfortunate surprise later
true but at least their aint a stranger 😛
How does it "contradict itself"?
which blocks a total of 10% of viruses
I need to check somehow when I LAND
I literally havent used antivirus since windows 7 I havent gotten any since
but whats the difference between having landed
and being on the ground just overall
So check if you were airborne last frame, and are no longer airborne this frame
if ur not grounded u check again if grounded.. ^
that doesnt work because the grounded function of charactercontroller makes the grounded check flicker
I already told you how to fix that
it didnt work properly
Call .Move exactly once per frame, and make sure you have some downward movement even when grounded
then the character controller behaves properly
what downward movement
i technically already have gravity acting on it
but it just doesnt work properly
The downward movement I told you to add that you said you added but didn't work
You need to actually touch the ground, meaning you need to have downward movement, even when grounded. If you set the Y value of your move to 0 when you're grounded, then you didn't actually touch the ground, you hovered over it. Then next frame gravity kicks in and set it
then next frame you hover, and so on
gravity doesnt works properly?
CharacterControllers don't have gravity
And when people implement it themselves they often make the mistake of setting the vertical speed to zero when grounded, when they need to set it to a small negative value
something like -0.1f
just to keep in contact with the ground
Windows defender is amazing. There is no need for a separate antivirus
it still flickers tho
its not
huh interesting
It really is. Viruses kind of don't exist any more
I don't trust you, because you are objectively wrong
its always the last to get security updates
smth like malwarebytes is a level better at least
yeah for common malware
But really almost all malware gets stopped before it even reaches your machine
but get a funny usb stick plugged in or a directed attack and ur fucked
Just don't download free-bitcoin.pdf.exe and you'll be fine
At this point, receiving malware is a personal failing, not one of the machine
Malwarebytes doesn't protect from a sledgehammer to the motherboard either
its not #antivirus anyway
it has macro protection tho I believe so u cant have a chip run a macro when its connected
doubt
there are funny chips in things like edited chargers or USBs that run a macro the second they're plugged in
Ain't no anti-virus in the world that can protect from a hardware connection and user who clicks "OK"
u dont need to click OK
yeah anti-virus is not anti-stupidity
besides theres more money in Web hacks like CC numbers and identity
You really just need something that can stop air-dropped malware from unblocked ads since that's the only kind the average user will ever encounter
no one cares about your files anymore
people willingly upload their shit on cloud anyway
btw I did this and it didnt work
its still flickering
there is no protection from people who dont read the simple messages their computer gives them, which appears to be about 95% of current users
Yeah, people don't make viruses any more because just getting a password from a data breach and trying it on all the bank websites is easier
Share full !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
that's what Windows Defender is for
you don't need anything else, especially not something that breaks Unity
They are saying defender only blocks 10% of malware lmfao
nonsense
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
yeah surely Microsoft engineers only know 10% of created viruses
with better antiviruses you have a good chance to protect the PC even after the executable has been ran
Defender is actually one of the better pieces of MS software
stop talking about shit you have no understanding of
Windows Defender can do that
yes defender does ask if u wanna run an application from an unchecked source
that means it scanned it already and hasnt automatically trashed it
also heres the code
Nah that's UAC, built-in to the OS
You just clearly know little to nothing about antiviruses
did not grow up in the dark ages of viruses
Windows antivirus is really good, it used to be shit which is why people still think it is.
If it was good in the past, I wouldnt have destroyed 3 family computers
Looks good, at least for the isGrounded cycling between true and false. Try logging it before you call .Move, along with moveVelocity is it actually still flickering, and if so, what is the velocity on the frame before that?
I wont ask what you were doing to contract viruses in the first place
Trying to download angry birds free exe as a kid 
I literally downloaded games off of Limewire, I was basically juggling live grenades. Somehow I never permanently bricked a computer
I don't use CC but I also never ever heard anyone mention this which is surprising
Ah, silly, silly, children
lmao same and the replacement Frostwire r whatever it was called
Okay but how else was I gonna play Ultima in a town with no PC game stores
https://hatebin.com/yvyfghcuby
gravity works fine w/ a ground check when its structured correctly..
like digiholic mentions,
-
when its grounded you keep applying a downward force (something really small but enough to keep it grounded)
-
when you jump you cancel out the y velocity first so the player can move upwards (without being pushed down by the gravity it already had)
-
if its not grounded you add gravity to it to bring it back downwards.. (maybe a bit more than when ur just grounded
-
once it becomes grounded again it swaps back over to the small gravity force to keep it grounded
mummy or daddys credit card @polar acorn
? I had no issues with it
oh mb wrong person
It's because the most common tutorials for CC (Brackeys) include a custom ground check which is unaffected
Pfft look at mr moneybags over here with parents who qualified for credit cards
I fixed it
the flickering at least
im stupid and tired
but mainly stupid
welp, small victories are where its at
lol, I was maxing my own cards out on hardware and software long before you guys were even born
i maxed my first card out at TacoBell 😈
Yep, and the only reason I had a computer at all as a kid is because my mom snagged one on its way out to the trash from the school she volunteered at and we fixed it up.
didn't know they sold hardware
dam yall had CC growing up ?
Can I like get a gameObject by name but just withint the gameObject children?
yes but why would you
getting object by name is slow , inefficent and prone to break
If it's a child object you can probably just drag it in
So I don't have to assing the children GameObject in the inspector
never understood this..
why would you not.. you are literally ensuring the object and reference is there.
that is what you should be wanting to do
So it is simpler to manage other values on the inspector
I dunno, I was actaully trying to avoid using the inspector for this kind of things
if you're concerned about that visual space, things like [Header("Some category")]
wrong
The more over-engineered solution is not always the best. It ain't fancy but dragging in a reference is legitimately the best way to do it. Not at risk of losing a reference if something's renamed, proper type checking, less time spent spawning the object, faster runtime while it's going
it's pure upside
I assign references when it is even slightly ambiguous what the reference should be
If I just need a list of every single component of type X that's parented to me, no matter what, I will go ahead and use GetComponentsInChildren.
[Header("Attributes")]
[SerializeField] private float speed = 5;
[Header("References")]
[SerializeField] private Rigidbody2D rb;
[SerializeField] private Interactor inter;
[SerializeField] private NavMeshSurface surface;```
If there is ANY deviation from that case, then I assign the references or write some more complex logic to find what I need
I will basically never do this for a single reference, too.
because...just assign the damn thing!
see @frigid sequoia
neat
Ok, so I should be using the inspector assignment whenever possible then?
It should be what you favor.
Yep
I have to change a lot of things then, most of my stuff is searching for GameObjects with the playerController component by default
Æugh
hmm funny we were talking about viruses earlier
Due to a security vulnerability, the ability to insert FBX files has been disabled in 3D Viewer for Windows.
oof
Can anyone help me fix this My arms/guns are Showing through walls!
this is my Weapon Camera!
Not sure whats wrong at all
Yeah, my scripts look more like this xd
why are you using the base struct for Bool lol
i forgot you could do that
? I though that was just how the boolean look in when using it
okay, so a few things I don't enjoy here
Sry, I am like very new
just reference your NavMeshAgent directly
Same thing here.
You already have fields!
just boolwould suffice lol
Just mark them with [SerializeField] and set 'em up
Why are you getting a GameObject here? I presume you need something more specific
like a PlayerController
I almost never have GameObject variables. I only use them when I can use literally any game object
its okay in 1 script @frigid sequoia but then once you have many scripts doing this in start/awake then its a huge problem
System.Boolean is the..."true" name for boolean values, I guess
Like how System.Single is what you'd really call a float
They are though, this is the general parent class for all enemies XD
Okey I would recheck everything later, thx guys
its a bad habit to get into IMO
So for "Boolean" I just use "bool" then?
yup
What's the actual difference?
Nothing, but it's a lot more character to type each time
like int you wouldnt use Int32 even though it can work
more typing = less time eating pizza
Oh, ok, so it doesn't actually matter if I miss some here and there, is more that is just weird right?
For this case, yeah
like if someone's name is Bobby, but prefers Bob. You can use both but they prefer Bob (ok maybe bad example because computer processes it the same and has no preferences 😆 )
yeah no it just wont work
if (jumpCooldown > 0f) jumpCooldown -= Time.deltaTime;
if (windup > 0f && Input.GetKey(KeyCode.Space)) windup -= Time.deltaTime;
if (Input.GetKey(KeyCode.Space) && jumpCooldown <= 0f && !startedWinding)
{
windup = _windup;
startedWinding = true;
}
if (windup <= 0f && Input.GetKey(KeyCode.Space) && jumpTime > 0f)
{
startedWinding = false;
landed = false;
moveVelocity += jumpVec;
isBeingLevitated = true;
jumpTime -= Time.deltaTime;
}
if(_controller.isGrounded && !landed && !startedWinding)
{
jumpCooldown = _jumpCooldown;
landed = true;
}```
no matter what I fucking try
the windup goes 0
and nothing happens
it doesnt start jumping
it doesnt do jack shit
jumpcooldown shouldnt start before you fucking land
but it starts before you even start jumping
no matter what I fucking do
landing before u jump started?
I think you're overcomplicating this a bit. You want the jump to require you hold the button a smidge, and you want a certain amount of time on the ground before jumping again, right?
yes
but the problem is
the jump is weird
because the height depends on how long u hold it down for as well
so u need to wind it up
set how long u wanna jump by holding it a bit
well it doesnt even seem to go above 1.0
and then start falling once you either release the key or u run out of jump
the windup? yeah thats not meant to be
the problem is
before you even get off the ground
it already sets that u landed already
because its fucked
oh thought wind up is the distance u want to jump up
So, this seems a little bit complicated. I'd start by formalizing your rules. Things like "How long do you hold the button before a jump happens", "what happens if jump is released at this particular point in time" and so on
Is there a way to make the navmesh skip certain gameobjects?
From there you can start to "group" rules, and find repeated bits that can be extracted into external methods
- You hold the jump for
_windupamount of seconds before u actually jump (0.9s)
rn it doesnt even fucking matter if you release the jump key
because nothing happens if you press it
And what happens if you release it early
Do you cancel the jump entirely?
nothing happens if you press it overall
so yknow
i know thatll cause an issue
but I can just set a flag
if GetKeyUp the jump key then set the windup to be cancelled
So, release the button before a windup period is finished causes you to just cancel the whole thing, right?
So, this seems like a state pattern. From the looks of things you've got at least four states:
Windup, Jumping, Falling, Landing
You define conditions for when one becomes the other. Windup becomes Jumping if the button is held. Jumping becomes falling when you release it, or Landing if you hit the ground. Falling becomes Landing when you hit the ground. Oh, and a "neutral" state that windup goes to when you release the button, and landing goes to after the cooldown
Can still consider cleaning up the logic so you can more easily diagnose problems and adjust values in the future
i have no fucking clue how to
its my 3rd rewrite of the entire fucking jump script
Yeah, I'm explaining that part to you
You're making a fairly involved jumping system
no, jump becomes falling when you release it or you run out of jump
Ah, okay, so there's a time factor as well
windup becomes jumping if the button is held for the amount of seconds yes
for when you're in the air, yes
it really shouldnt be
all i fcking wanted was a windup and a cooldown
and ive been here for 4 hours
over this bullshit
And a contextual jump height
the contextual jump height worked before
and it shouldnt have any effect
Yeah, but it complicates the addition of the other things
So, first off, I'd recommend doing some reading on the State Pattern (also known as a "Finite State Machine" or FSM)
https://unity.com/how-to/develop-modular-flexible-codebase-state-programming-pattern
Because this is what we're going to be looking at. You're going to want to create the states outlined above, and have each state be responsible for checking the inputs, timers, and other variables to decide when to transition from one into the next
digiholic? I can't seem to be able to exclude objects from effecting the navmesh.. none of the forum posts seem to refer to anything helpful, can't find much on wiki
@quick pollen As an example, here's how you might code the windup state:
if (CurrentState == State.WINDUP){
if (Input.GetKey(KeyCode.Space){
currentWindupTime += Time.deltaTime;
if (currentWindupTime >= windupTime) ChangeState(State.JUMPING);
} else {
DoJumpCode();
ChangeState(State.IDLE);
currentWindupTime = 0;
}
}
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Im sorry I have to use this
how is this fucking null????
A vector cannot be null
I mean 0
sorry
but how tf is a constant that I set to be a fucking number zero
its literally here
Try logging _jumpHeight and jumpVec right after that line
whats the difference between me typing Mathf.Sqrt(_jumpHeight) and 4??
The sqrt of 2 is not 4
It is like 1.41
Well, for one the square root of 2 is about 1.414, not 4
no reason in logging _jumpheight cuz its readonly
imma log jumpvec
Do it anyway
Not like it'll break anything
You should be debugging a lot, and if its mysteriously changing to 0 then something is modifying it. Right click find all references to see what's affecting it
you know whats weird?
I tried logging moveVelocity
and appareantly I'm already flying
yet im on the fucking ground
im sorry
im too tired for the day
this shit is cursed
it should be flying up
after what I did
I literally wanted it to start flying up infinitely
but it doesnt
it stays on the ground
GameObject?
Do you have any code that actually applies moveVelocity to the players position or velocity? I cant find where you posted code above.
yeah its here
this is the only Move call in my script
why is it doing this
moveVelocity is like the sum of all the velocities that I want to apply
Debug it right before the move
everything became super choppy out of nowhere
A field? That would be referring to the variable in your script. A game object is an object in your scene, not a singular variable.
whats it doing again
i thought he was asking like how to have an object from the scene or smth inside a variable
If it's not very clear suddenly the movement (camera is unaffected) became incredibly slow and choppy
You tell us, what is the problem? I can see an issue but you should be looking at your errors for more information
I'm restarting my PC cuz it has an update and I wanted to see if that may have been a cause but I genuinely don't know how it happened.
Field is a common name for it, but people would understand if you said in a variable as well
Actually I turned it off since blue I had 255 standart naming rule violations messages let me turn it on again
You should be seeing these errors in your IDE
Has nothing to do with the blue messages
I'm not sure it really has a name
If you're talking about storing a GameObject in a variable, then yeah, it's a GameObject
It showed no errors?
but "object" just means "thing" -- you can store floats, ints, GameObjects, MonoBehaviours, Rigidbody, whatever
Then configure your !ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
That can be called caching
Usually in the context where getting that object is expensive, so you do it only once and store it in a variable
I use visual studio
If you're basing camera rotation over mouse input, but involve Time.deltaTime in the calculation, don't. That's what makes movement unstable. If your FPS fluctuates you'll get more or less sensitivity in a frame, which makes it feel inconsistent.
Mouse input is already independent of framerate, so you should not multiply by deltaTime.
It only says player doesnt exist in current context but I fixed it. still doesnt work
what should i replace here then
Yes so follow the instructions in the link. To be blunt, your code is nonsense and your IDE should be telling you that. Having a configured IDE is required to get help here
Read the last sentence of my message again.
Hi! I'm trying to make a Health Counter with hearts for a 2D game, but I don't know how to approach it.
I looked it up on the internet, but the only two options I've seen are, either making the Heart sprite tiled and cropping it accordingly to the health left, or creating a different sprite for every possible case and assining it manually.
None of them really convince me. Is there any other approach I could try?
do i just remove that deltatime part?
Yep
my man it does? I told you that It shows no errors? you want a screenshot?
How can I assing a reference to component that is not on the Object that I am looking in the inspector?
If you have no errors then it is not configured
it didnt fix it
the same way
lock the inspector first
just drag the object in
it instead just amplified my sensitivity like crazy and the movements still choppy
private IEnumerator TestCoroutine()
{
while(isAlive)
{
Jump();
yield return new WaitForSeconds(2);
}
}
would the code below be more optimized, because of caching, so it doesn't fill up GC by allocating new instance every iteration?
private IEnumerator TestCoroutine()
{
var waitDelay = new WaitForSeconds(2);
while(isAlive)
{
Jump();
yield return waitDelay;
}
}
Like I cannot drag from a child's component to the parents slot??
How?
OMG
Show a screenshot of the whole thing
I think I got smth right
just drag the gameobject itself in, it will get the correct component
its the movement itself, not the mouse sensitivity
Yep, though if you have multiple components of the same type on the same object, then you need to do the lock thing
This shows me literally nothing. You seem to just be ignoring my messages that if you have no errors then your ide isnt configured because it should be showing you errors in your nonsense code
thing is theres no errors listed so i gotta find it myself
Oh, ok
It doesn't if there are multiple valid slots to assing, I think
huh?
also if you right click the script and hit Properties you dont have to lock inspector to drag something inside
it pops out the whole window
Another thing to note is this only started after I implemented crouching
Like if I drag an object with for example a rb and a animator and I have slots for both, I don't think it assings it automatically
I know its nonsense thats why Im trying to fix it 😄
Is it possible to make Vector3.SignedAngle outputs oriented angles ? So it goes untill 360 and not 180.
Not sure when it does work when just dragging the whole or item or doesn't though
you have to drag the object into each slot, yes. but it will get the right component for each one when you drag it into the slot
Ok you've fixed the error from the first code you've shown. You shouldnt be trying to use static void main, it will not be the entry point of your program. You need to use monobehaviour and awake/start
could it have anything to do with this?
I told you I fixed that earlier
so is that all?
Is
if(ExampleGameObject){
}
the same as
if(ExampleGameObject != null){
}
?
are there no problems in update methods codes?
yes
the last 3 floats seem sus to me. I think there are some problems there but I couldnt guess what
and another note
and it just doesnt work
its not fps related
my fps seems stable, the characters movement itself is the only thing affected
What's sus about them, and did you write this code or is it from elsewhere?
seems sus based on my instincts
Your message about what you fixed was completely unrelated to the error about the method name. Also you havent said what doesnt actually work.
Are you using chatgpt? I told you about not using void main already
my closest friend sent me this code and said find out whats wrong
Tell your friend to start over from the basics and stop doing his work for him.
Substitute the final formula with the values and they'll immediately see what the issue is.
Does anyone have any idea why are these visual bugs happening? (Ignore the half made game)
this is a code channel
yes
You do know this is a Unity server right? The code you've sent seems to have basically nothing to do with Unity at all
Finally found out
well its c#
But it ain't Unity
!cdisc
Wait they changed the command for that hang on
it's !cs now
Join the C# Discord server, a programming server aimed at coders discussing everything related to C# (CSharp) and .NET. https://discord.com/invite/csharp
There we go
not like people talk there tho
okay so is it forbidden here to ask outside the unity library?
directly, yeah
If you're asking for help for non-unity code, you would be better served going to the discord about non-unity C#
Have you not been on that server? It's pretty dang active
Otherwise your answer here is going to be "Why isn't this a MonoBehaviour"
okay. got it
yeah. realized that.
well tbf i havent been there in a bit
but i remember one time the #chat being inactive for like 2 days straight
with only like 5 messages total
There are like 40 messages in a 10 minute period right now on the chat channel
But I've never seen it that slow personally
do they help with unity libraries there?
Well, for one, that's the off topic channel, which is already infinitely more active than the off topic channel here, which remains at a steady 0 posts per day due to not existing
this is frustrating
They'll probably tell you to ask the Unity server for anything Unity specific.
lmao gigachad tho
i dont even wanna get close to assembly
i already struggle with c++ plenty
Assembly Definitions are not Assembly
bro i genuinely dont understand this
tho i dont know where to go from mathematical shit at c++
out of nowhere the playermovement just stopped being smooht
got it. no outside unity library c# questions here and not unity library questions there. great
still, it has assembly in it so im scared lol
it isnt fps or camera based the movement itself is super choppy
maybe u have multiple Move calls
that can cause weird shit
are you certain that the issue is your player movement not being smooth and not the camera updating on a different time step from the player? hint: ||it's almost always the camera||
Well that's why I wasted my time trying to tell you about not being able to use Main..
i dont understand how implimenting crouching suddenly makes the camera update differently man
maybe the scale of the camera changes?
You don't have to understand, you need to debug. That will get you to the point of understanding
i haven't seen any of your code and you've not provided any actual details recently so i cannot say for sure what the issue is. but it's probably how you update your camera 🤷♂️
if u make crouching by halving the size of the player
jesus christ
yeah. sorry about that. Is there anything I can do to compensate for that?
allat for the dumbest solution
and the camera is parented to the character
10 bobux
let me write a free robux generator program
Is there a way for a cursor to follow your mouse position on a canvas in the worldspace?
u had issues figuring out main, we'll see about that lmao
Lol sorry i wasnt trying to make it seem like an issue. But more of a reasoning for why we dont deal with pure c# issues. There are differences which can result in massive confusion
id guess smth like raycasts
if ur mouse position is always in the middle of the screen
i mean the crosshair
It isn't always in the middle
well yeah
but if we're speaking generic shooter
actually i wont get into this cuz im tired and dont wanna waste peoples time
why not
There's no actual movement, the game is kinda like fnaf where you stay in one spot.
Like you want that mouse cursor to be where your crosshair is aiming?
Yeah pretty much
good. Ill still write a time machine program in the future and hit you up and give you your minutes back.
raycast then id say
Yeah Physics.Raycast, if it hits, convert that hit point into the screen object's local space. Then convert that into canvas coordinates
I guess.
Ok I'll try and do that
Or hmm might as well move the UI cursor into hit.point? Not sure how worldspace UI works
mmmm spacetime anomalies
have fun debugging the fucking universe lmao
@prime cobalt
especially after what has just transpired
Time.timeScale = -1
Windows XP <3
Nah the crosshair doesn't work like that
You might call me dumb for asking this but... Does this Event System do anything? Like I don't remember adding it, and it has been there for so long that I am scared of removing it and breaking something XD
Ahh its not locked..
yes, the EventSystem is used for your UI stuff and if you use any of its interfaces like IPointerEnterHandler
It lets you use UI
It is added automatically when you create a UI object for the first time
So it is added automatically with a Canvas?
Ok, I don't have to touch it at all them right?
I mean, I don't think that there is anything "interacteable" in that UI, can I remove it?
There is no reason to remove it
unless you've managed to create multiple event systems
Is fine to have it even if the interface is just a recount of score and health for example?
Yes. It won't blow up your computer.
I mean, it won't, but I though I was meant to keep stuff as simple as possible
that doesn't mean to immediately delete everything that you don't recognize or that doesn't immediately have a purpose
Simple as possible means leaving the event system
That sounds like a very vague question, there isnt often a "best" way to do a lot of things, since much of it depends on a lot of different factors - what are you looking for specifically? What do you need your objective system to do? What kind of objectives are you trying to make? How large/complex is this system? How do you plan to populate/create objectives? Do these objectives need to be saved or stored somewhere? Which part of the system are you having trouble with? If you havnt started anything yet or you dont have any specifics, then any "objective system" would probably be a good one, and thats not to sound harsh, just that theres many ways to approach problems and project setup and requirements play a bit part in that approach
I mean, the fact that Unity added it automatically pretty much answers your question; keep it . . .
ayy it works now, thanks
odd
if i make it so the horizontal speed matches on both a flat plane and a slope
i start to deal with bounce again
but if i dont add that bit
i stick to the slope like normal again
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
not sure which channel this is the most relevant for but building a dll for both runtime and editor but running into this problem where even though i explicitly reference the UnityEngine version of ScriptableObject in both the dll ExtendedLevel comes from and my editor script trying to reference it, it asks me to reference coremodule instead
Online I only found one post relating to this suggesting to just make two versions which seems a little psycho
You need to add the Unity assembly to your assembly to access Unity-specific types . . .
yeahh but i think the one i need for runtime use is different than the one i need for editor use
found this message online which im trying to follow up now
I was taught how to deal with it.
The dll can be solved by using the one in the following location.
UnityEngine.dll:
/[UNITY_EDITOR]/Editor/Data/Managed/UnityEngine/UnityEngine.dll
UnityEngine.CoreModule.dll:
/ [UNITY_EDITOR] /Editor/Data/Managed/UnityEngine/UnityEngine.CoreModule.dll
UnityEngine.UI.dll:
/ [PROJECT] /Library/ScriptAssemblies/UnityEngine.UI.dll
Functions and booleans are everywhere
Nothing suboptimal about those
You could use OnTriggerEnter to detect when you enter an area, for example
And then display some UI text that tells the objective
Ofc it's still missing the objective logic itself
You need to think about its arcitecture, yes
Booleans don't really cost anything
I would probably make the objectives into separate objects that get added to the player's list, or set as current objective
Not necessarily monobehaviours, could be plain C# classes. Or instances of a scriptableobject
Can't really give any detailed suggestions without knowing how your game works and how you want it all to work
Bools and functions are completely fine relative to performance. If you're trying to make something extendable/complex.. you can opt for other solutions.
Hi there, pretty noob in C#. I'm making a little shmup like where the player can move right/left and can fire a triple shoot. When the player flip on left i struggle a lot with the gizmos (fire points/origins of the bullets) that shoot up and down cuz there are not symetric at all with the player's right position/rotation. Have some advices or tips for flip correctly ? (i'm looking in quaternions or gizmos.matrix documentation but not sure at all) thx for ur time
for adding booleans:
the performance and memory cost is completely negligible. but the cost to your ability to manage the state of the whole machine is NOT negligible
and that is the main consideration
Depends. If you've got a simple clicker with three or four states... it's very managable.
Yeah, they are separate assemblies, so make sure you add the correct one, or both, if you need access . . .
hi could anyone briefly explain how line renderer arrays work please?
Maybe show more code.
How you should post !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
i mean just how that bit works
I get the rest
what is the bandPositions array for
It's not a standard thing, are you following a tutorial?
It's just an array, seemingly of transforms. It has absolutely nothing to do with line renderers specifically
I assume they are transforms
It's something you haven't shown us.
It seems to be using transforms as a source for the positions for the linerenderer. Presumably so they are easier to edit than adjusting position values in the inspector/code
if i put in an element 2 as one transform component (for example the center between the bands) how could i reference that
in a line of code where id set the bands index of 1 vertex to that element
Maybe lookup a tutorial
If you want element 2, you use the indexer [] of the array
So myArray[2]
like lineRenderers[0].SetPosition(1, bandPositions[2].position);
I'm not really understanding what you're wanting to do. Simply
. You'll immediately know if what you're doing is practical/doable.
4-5 booleans, ok.
19-20 booleans not ok.
It is part of a steadily increasing cost
does this mean the second vertex of the line would set to the position of element 3 in band positions
19-20 is still nothing
though i would look at if flags are better with that many
I would have as many booleans as I want, but keep them in their respective "Objective" classes instead of in the Player class for example
but not for perf reasons just for keeping it cleaner
it is when you have to juggle combinations of booleans being set true and false, while others change the flow for others being set true or false…
It’s part of why player movement scripts can get very complex
though really it sounds like you should just be using a fsm
i mean number of separate booleans within one class, not in a collection.
but like would worry about just keeping it clean and easy to understand
I'm a believer that OOP isn't a necessity in most cases.
We often get too worked up in design where the solution we're creating often becomes more redundant than necessary.
like at work the main character class and its support data structures like like 5 or 6 kloc
and its all still fine
we’re talking to someone who was worried about the performance cost of adding more booleans, and my point was that the only real cost is the cost to managing an increasingly complex machine
TIL what kloc is
thosand line of code
Yep I did google it 😄
Just make it readable.
yeah. it’s just a good way to handle simpler objects
but yeah anyone worry about performance, the order you do things is
make it work, make it clean then only make it fast if required after profiling
Yep. Nothing worse than coming back to your project and not knowing what's going on. Even worse if you work in a team
Whats the easiest way to tell an element of a prefab to move to the right a bit on a trigger?
Does it have a rigidbody?
And do you want it to actually teleport instantly
Why does my code Debug.Log() Blank!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainMenu : MonoBehaviour
{
public static MainMenu Instance;
public GameObject UICam;
public GameObject Menu;
public GameObject Play;
public GameObject ChangeName;
void Awake()
{
Instance = this;
}
public void OnNameChange(string _name)
{
Debug.Log(_name);
}
public void OnPlayPress()
{
Debug.Log("Pressed Play!");
}
}
UnityEngine.Debug:Log (object)
I have the Input detect On Value Changed with string set up to the Main Menu script to the OnNameChange function
It doesnt, and teleportant instantly is fine in this case
The parameter field is blank
E: Sorry maybe I misunderstand
they evente has a dynamic section as well as static
guessing you are expecting to pass data along in the event?
You can simply modify transform.position
wanting to send the Name from the text into the function
That'll move it to a fixed position on the screen though, won't it? The prefab is moving across the screen.
Only if you set it with transform.position =
You should add to it +=
So transform.position += someVector
Which is just shorthand for transform.position = transform.position + someVector
thanks
Newbie question. How do most people handle saving stuff in scenes? Like i have procedural terrain generation, Is simply deactivating the chunks to unload and save them sufficient or do i need a proper save system?
Or should i be finding a way to store the data to a file or something for long-term and just read off it to generate what i need? Completely new to this part tbh
You could either store all the terrain data in a file, or just use the same random seed to generate it again
You're talking about runtime, right? Not in edit mode?
Well my terrain is a 5 vertice, 4 triangle quad array with customizable height values by player and remove-able quads by player aswell to determine the world shape etc. And yes in runtime
Making them a prefab is an option?
That would be a lot of prefabs but do-able
Can't make prefabs in a built game
My mesh can generate off heightmap and i can save the heightmaps to use later, its intensive tho
If your map is customizable, then a hybrid of my first two suggestions could work too. Save only the changes that were made, and the seed.
When loading it, generate the map from the seed, then apply/replicate the changes that the player had made
So why does transform.position += Vector3(1, 0, 0); not work? It's teling me it can't be used like a method.
This() is a method
missing new
So how do I make it move to the right an exact amount?
what do you mean
you just create a vector with the value you want
transform.position += new Vector3(1, 0, 0);
new Vector3(0,0,0);
though in your example case you could just do transform.position += Vector3.right;
Well yeah, but that doesn't let me get it down to the pixel where it ends up
ur setting the position.. thtas what transform.position is.. its the
if you want to do it over time so it smoothly moves there, use a lerp
you can set it to be exactly anywhere u want it to be
use a variable.. use the variable instead of hardcoded magic numbers.. and u can just tweak the value in the inspector until it is exactly where u want it
or find a procedural way to get the point
Since this is called from OnTriggerEnter, you need to add an offset while taking into account the trigger's position
If you want it to be precise
Vector3 pos = transform.position;
pos.x = thatTrigger.transform.position.x + someFloat;
transform.position = pos;```
You are using OnTriggerEnter right? @thorn kiln
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("projectile"))
{
StartCoroutine(MyCoroutine(lowerPipe));
spriteRenderer.sprite = buttonPressed;
transform.position += new Vector3(2, 0, 0);
}
}```
(Sorry other josh that i pinged)
Im basically just changing a buttons sprite when I shoot it
In that case it looks correct. Just need to tweak the vector value to your liking
Could make a serialized Vector3 and tweak that from the inspector
Forget about this, I thought your trigger detection works the other way around
Well I want it to go from -5.01 to -2.23
So what is (-2.23 - -5.01)
Then just move the difference between the two values . .
It doesn't like decimals.
"Argument 1: cannot convert from 'double' to 'float'"
Hey guys, how would you store a local position y value at a certain frame? And use it later as a direction? Not sure if I'm precise...
2 also already moves it too far, so that's confusing
Use a float value, not a double . . .
What PC build would be the best for making games, under $400.
1.0 is a double
1.0f is a float
Not a code question
#1157336089242112090 maybe
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
{
if (ninjaTimeMB.NinjaIsShootPressed && arrowInstanceGO != null)
{
StartCoroutine(MoveArrowInstance(arrowInstanceGO));
}
}
IEnumerator MoveArrowInstance(GameObject arrowInstanceGOParam)
{
// Vector3 directionOfTheArrow =
while (arrowInstanceGOParam != null)
{
arrowInstanceGOParam.transform.Translate(Vector3.up * arrowSpeed * Time.deltaTime);
yield return null;
}
}```
cs goes on its own line
oh okay
Unless it's blocked somewhere else, this coroutine can start multiple times?
For multiple instances of arrows, no?
yeah but it never ends
Looks like for the same instance of arrow
Can't tell from this alone though
public static class StateChangeList
{
private static readonly List<IStateAction> _changeActions = new();
static StateChangeList()
{
SubscribeAll();
}
public static void Clear()
{
_changeActions.Clear();
}
public static IStateAction[] GetAll() => _changeActions.ToArray();
private static void SubscribeAll()
{
DrawService.OnCardDrawn += SubscribeDrawEvent;
}
private static void UnsubscribeAll()
{
DrawService.OnCardDrawn -= SubscribeDrawEvent;
}
private static void SubscribeDrawEvent(int ownerIndex, CardSO drawnCard)
{
Debug.Log("Ok");
_changeActions.Add(new DrawAction
{
OwnerIndex = ownerIndex,
DrawnCard = drawnCard
});
}
Why doesn't the subscription work? Ok is NOT printed to the console
also will run mulitple times on the exact same arrow
and will fight with the other coroutines over its position
the thing is, dont mix Update and coroutine if you dont know what it's doing
use transform.up
in this case, it will likely make the bullet very fast
Vector3.up is world
2.78f seems to just make the button disappear entirely.
transform.up is local up axis
oh dont use translate
Bad idea?
public void Translate(Vector3 translation, Space relativeTo = Space.Self);
says where?
the green axis in the scene view being world or local depends on your viewport settings
I have no idea what the issue was, I just saw the error about doubles and floats. You have to cast to float, as I showed
Okay, I think it's... going into the pipe? Not disappearing
code is not effected by that
If i press local, I get the axis I want in green
translate works in local space unless you tell it to use world space
Do you mind looking at a screenshot?
otherwise its just a matter of using local or world position
vector3.up is world up transform.up is local up
I can't figure out what number this thing is looking for me to tell it to determine how much to move to the right using a number I can easily find
The green axis of the transform in world space.
Do subtraction like we suggested
transform.up is the green axis of the transform in World Space, sorry but I don't get it
Trying to read the documentation but it's driving me crazy
transform.up is the local space green axis on a object
Here @thorn kiln Goddamnit I pinged the wrong josh again
Just calculate it with a calculator or something. Then put that value into a variable and use that variable in your Vector's x parameter
Vector3.up is world up
I mean, I tried. It should be looking for 2.78f to move it to where I want it to go. But that makes it disappear. If I do 2, it puts it mostly inside another object. So I don't know what number it's looking for, but it's not a number I seem to be able to find logically.
Make sure it only runs once
magic numbers 
I could keep messing with it until I find the exact number, but that seems woefully inefficent
I have been unintentionally summoned
Which is why you were suggested to make a serialized variable that you can tweak from the inspector
Either a float or just a Vector3
Sorry man I did it twice
Welcome to the josh meeting
You guys told me I should avoid to use references by name, is there a way of doing this without that, or this is fine?
Camera.main exists
How can I set which is the main camera?
reference the component instead of using GetComponent multiple times . . .
I mean, I am only using one, but just in case I wasn't
make your prefab be of the type you need from the start
what does the docs say about Camera.main
also you are calling GetComponent to see if something is null literally throwing away that reference then calling it again
hold it in a temp var, or use TryGetComponent
via a tag
It says that it takes the first camera it finds (?)
Yep, you can instantiate a prefab by its component. It will spawn the whole prefab @frigid sequoia
its the one marked with mainCamera tag
What do you mean by that?
Did you even read though?
read the entire first sentence of the description
but yeah all get components in that can be avoided as well as the camera find
instead of assigning showDamageUI as a GameObject type, use a FloatingDamageController type . . .
your showDamageUIPrefab you have as a GameObject, make it be the type of the component you want on the prefab. if you do that when you instantiate it returns that component reference on the instantiated prefab not the gameobject
Well I don't feel like I should have to. If the number is like, "1.86f", there should be a logical reason for that which I could figure out. Making a slider just feels like it shouldn't be necessary for something like this. I mean, it's doing what I want in a sense, just not in the exact way I want it to.
not in the exact way I want it to.
What exactly do you want
Nice progress btw
i would make FloatingDamageController have a field for FollowGameObject, then you can access that from the FloatingDamageController reference . . .
For it to move an exact amount. It's moving too far to the right and into the pipe.
Make an empty object at the position you want
Use that object's position in code
It does move the exact amount. Maybe it is getting called twice?
Empty object is an option too.
Thanks, Im basically done. Adding in a "pressed button" change was supposed to be a victory lap, and it's taken loger than even adding the high score function.
Another reason that I can think of why it moves more than you expect is that you have scaled the parent pipe
The pixels do look a bit streched horizontally
If I set it to 1.5f, it only goes in this much
So there's a magic number somewhere, I just need to know how to find it logically
You could also just make a serialized Vector3 and set its local position to that
The pipes and button are scaled, yes
I still think your pipe is scaled unevenly though
Yeah
That's why the localPosition when you were testing, doesn't match what you set the position to
There's not really going to be logic for it, it's a consequence of the art being how the art is. My recommendation is putting the object at the right place in the inspector and either copying that local position or making an empty object at that position
Because the local position gets scaled by the parent pipe's scale
That's literally what I understood from the first sentence, that it just tags the first camera it finds as main
If you want to keep the parent stretched/scaled, you can set the localPosition's X value to -2.23
What would that change? I mean I would still need the reference to the camera
Ok it's just that you said this 👆 which wasn't very clear
this will remove all of the unnecessary GetComponent calls . . .
you can reference the main camera at any time, that's not an issue . . .
How does one do that exactly
🤔 context?
this does not sound like a unity related question
Get the localPosition. Modify its x value. Assign it back to transform.localPosition
Reading from the guide I was told to check out instead of Unity Learn. One of the steps says create a new project in VS with Console App .Net Core but it's not showing
that doesn't sounds like a unity learn step 🤔
@thorn kiln Try to write the code for that, if you can't we can help.
It has to do with something else someone in here sent me a link for
So... what you are saying I should have a a reference on the showDamageScript to the FollowGameObjectScript and assign it manually from the inspector and reference that reference from this one so I don't need to use GetComponent?
ah yes "something else". surely you can look at your own computer screen and see what you are referring to. and also console apps are still not related to unity
If you're going to be rude don't bother replying. This is still part of beginner coding and I'm dealing with an issue that will allow me to learn how to code since I am using Unity
Oh, I'm not sure as I don't use VS but does the material you're checking out show any instructions for installing or setting that up?
my guy, you're asking about how to do something unrelated to unity in a unity discord. you won't even bother saying what the instructions you are following are because you clearly know it isn't unity related, hence your initial lie about it being from unity learn
It does, but again I followed all the steps up to and got stuck so figured I would come back and ask. I wish I could remember who it was I talked to that sent me the link for the site to go learn C#
Yes, that will help . . .
But if I'm asking in the wrong place point me in the right direction please lol
!cs
Join the C# Discord server, a programming server aimed at coders discussing everything related to C# (CSharp) and .NET. https://discord.com/invite/csharp
Knowing what you're talking about would help
Was it me, sending you to w3schools?
Ah, I see. I would ask in the C# discord then. They'll have better info since that isn't smth used for Unity . . .
hello. noob question, but how can i find all of the bones in my list of bones and print them out using a Debug.Log() statement? when i simply do Debug.Log(chain), it just prints out the reference to the list, "Kinemation.FPSFramework.Runtime.Layers.BoneRef" instead of actually printing the list content out. same with doing it with a foreach statement. anyone know?
Funny how I'm in the beginner code and not advanced. I'm just getting started learning and asking the community for help. Chill
Thank you.
Okay, finally Im done
What? I am chill, I'm trying to help. Please stop being rude
If you have a List you loop through it and get the name of each component
Aeth was completely chill there lol
Maybe you are just reading everything in an angry tone
if you want to print all of the contents of a list, you will have to loop through the list and either build a string using StringBuilder to combine all of them together, or print each individually
The way they said that was not very chill IMO but ok 🙂
I figured it was me that sent you somewhere, so I was trying to verify
How could it possibly read that way? But alright, I won't help. Best of luck
They don't know what material you're asking about. They asked if it was them who referred you and tried guessing which site (the material) you were reading from. By providing those details, we could have better assisted you. That's all they were pointing out . . .
They literally said "maybe know what you're talking about" that sounds pretty rude towards someone who is new to this stuff
Could have simply told me that maybe I'm not in the right place.
They mean it's better for us to know what youre talking about
Huge misunderstanding
I don't think you are in the wrong place. As many have asked, it would help to know specifically what you are talking about. Without knowing that, there is little we can do
Ok well sorry I guess if I'm overlooking it. Definitely seems like something I would say if it was being condescending
My bad
in gamedev and programming you will find a lot of people are fairly blunt in their language
its nothing against you or anyone
We can all still make efforts to not sound like a cunt. But this was just a misunderstanding
I'm just new and have gotten a lot of "hate talk" for not knowing what I'm doing so it just filters in as people being the same way
And... i've been blocked I guess...
Kinda shocking, I thought I was being the most helpful here lol
Then my apologies. Seems my filter isn't balanced right then
i only been loosely following but think people were missing context of what guide you were following asking for the .net console app stuff
Sorry, I've had to block too many people previously
Yeah, weird
I can't do that (?)
Am I missing something?
your prefab variable must be a FloatingDamageController too
what type is showDamageUiPrefab
I'm gonna regret asking this but... how would I make my highscore display "Highscore: {number}" instead of just a number?
pretty much exactly that but with a $ before the ""
printing them like this:
foreach (var item in myList)
{
Debug.Log(item.ToString());
}
string result = "List contents: ";
foreach (var item in myList)
{
result += item.ToString() + ", ";
}
Debug.Log(result);
does not seem to work, all it prints is several "Kinemation.FPSFramework.Runtime.Layers.BoneRef"
got blocked by bot
Oh, yeah, sure, thxs, that makes so much sense
I unblocked. I am sorry, just had too many people hate talking and assumed you were on that side of the fence
$"Highscore {highscoreVar}"
Note that you may need to re-assign that variable in the inspector after you change its type
what information are you trying to actually print? if the type you are trying to call ToString on does not override that method then it won't print anything special and you'll need to print the individual properties you want yourself
So it should be something like that isn't it?
i have a list of bones, private List<BoneRef> _leftHandChain = new List<BoneRef>();
i am trying to print out to see every bone in that list.
try it looks fine, should work as long as the prefab is the right type
IFormattable 😁
again, what info from each BoneRef are you trying to print. you will need to access those properties on that type to print them since it does not sound like the type overrides ToString to print any of that info
or if this is your own type, then go override ToString in that type to return a string containing whatever info it is you want to display
beautiful . . . 😢
BoneRef is a struct containing a bone Transform and a rotation Quaternion. i am trying to print the name of the bone. im sorry that i'm not much of a coder, i mostly do visual and other things.
is this a type that you created?
i don't understand your question, sorry
i guess thats no
did you or did you not type the code that defines the BoneRef struct
then override ToString in that struct and have it return the name of the transform
note that i am specifically referring to the code that defines BoneRef as a struct and its members. I am not referring to your list of BoneRef.
if it's a struct, how are you assigning them (the values) to the list?
I have been instantiating everything as a GameObject for a while now; this is way more effcient now....
Yeah, instantiating with a direct component reference is sadly not common knowledge
Among beginners I mean
wait you can override ToString without IFormattable ? huh TIL
sure, you can . . .
yes, it's declared on System.Object
There, I'm officially bloody done with flappy bird
I dont know why I always end up doing gamedev right before work, when I should be sleeping
inside the struct is smaller functions, like BoneRef, CopyBone, Slerp, and more. in the BoneRef component, i am simply taking public Transform bone; and assigning it to a boneRef variable that is required input when calling that function:
public BoneRef(Transform boneRef)
{
bone = boneRef;
Debug.Log(boneRef);
rotation = Quaternion.identity;
}
so do you have a field for the name?
or which name do you want to print
It could be worse: The other day I was "designing" my AI system in my sleep.
it happens 😦 I think ~~secretly ~~ subconsciously not wanting to go to work and do this to get paid
Yeah, I've had dreams like that
that would be fun . . .
i just want to point out that BoneRef is not a component
that's what i try to get them to understand . . .
i did not mean to write that, lol. im all over the place
if it's a struct, it has to exist on a Component or C# class . . .
im so tired im pretty sure ive made many errors already
now i'm confused?
about what?
from that, im trying to print the "bone" and have it actually show me the name of the bone instead of the namespace jumble
Hello, I am new to Unity and trying to get oriented. I'm trying to find where I go to write code that alters the geometry of a character. For example, if I want to take the current position of the character's vertices, do vector math on them, and then set a new position. The goal is to recreate some setups I have in Blender's geometry nodes within Unity (custom geo modifiers.) I know how to write the code for the logic, I just don't know where in unity I'd go for this sort of thing.
yeah ur printing the struct type
where is supposed to get name from, you have to specifiy
Every object in C# has a ToString function that you can override. Are you familiar with virtual/override?
no
override ToString and have it return the name of the bone
That looks like the right sort of thing. Thank you!
I am being kinda annoying now, but for this kinds of things is more efficient to check for the name of the object, the components in it, the layer or it doesn't really matter much?
oh no..
do not rely on gameobject names for logic. check for a tag or a component
Oh they even have a page for this specific case
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/how-to-override-the-tostring-method
hahah thats the page i just clicked on, thanks!
there are sooo many good guides in there surprisingly MS did an excellent job..compared to what it was lol MSDN
if you want to know all c# has to offer I suggest look through those
So I just repeat the bottom line and check if the object has the PlayerComponent? Can I not like combine that to use the GetComponent just one?
use TryGetcomponent when possible btw
saves you null check and ensures you only use component when it finds it
eg cs if(other.TryGetComponent(out PlayerController player)) { player.DoSomething(); }
So just that? That's so much less messy
gameObject and the <> are redundant
well depends if other is collider then its ok, but yeah if its Collision then you need .gameObject for example
see how the <PlayerController> is diff green more darkened
its telling you it can already Infer the type from the out type you passed
Oh, I though the other was just a reference to the collider and I needed to tell it to check for its GameObject
But it seems to let me remove the .gameObject
in TryGetComponent you only need the <T> part if you used var isntead of a typename after out
C# in alot of cases is good at infering the type arg from the method paramaters
yup and if you look at the docs, there is the method right here
https://docs.unity3d.com/ScriptReference/Collider.html
You can do it on all Components
if you use it on OnCollision it gives you a Collision type which isn't component so you would need the .collider or .gameObject
It is indeed a reference to the Collider
Why would it let me TryGetComponent from a collider if it just returns... the collider?
Seems kinda weird
wdym it returns the collider?
Collider is a component
All components are on gameObjects, so you can GetComponent from any other Component
So GetComponent from a component is the same than GetComponent from its GameObject then?
if its attached to the same object it works the same
correct
it looks for it on the gameobject that has that component you GetComponent from
now you are part of the elite . . . beginners . . .
both Component and GameObject have a GetComponent method . . .
Man, I am not progresing at all with this one project, but I am learning so much
is learning not progression?
Like I am looking at code from a month ago and I am like... wtf was wrong with me?
yeah that never stops, i been programming most of my life and still find that once and a while
same
I mean like tangible stuff, like if you show what I had 2 weeks ago and now is basically the same with some minor tweeks
i literally learned everything by doing the same concept/system over and over because i learned a different way and was curious . . .
I am fine with that though, the main goal I had with this one was to do something that was a bit bigger and problably a mess but get to know how doing something more than just a minigame is like
when you come back to project with more knowldge it will move a little further and old problems with move a little faster
there is no just knowing everything, its all a cycle of hitting a problem, doing research and learning about the problem then implementing something
also bigger things are just lots of small things combined
its like going from Play-doh to Marble Sculptures
Yeah, but I literally downloaded Unity like 3 months ago, so the part of making small things combine without everything falling apart is kinda of a challenge already xd
yeah 3 months is not a very large amount of time when learning a new skill
I have two objects that move within a GameObject, however I want the parent GameObject to follow the position as the children. I am going to be switching between these two children objects, how can I make the parent be at the same position as the children actively?
sounds like you probably need a better solution to your original problem
what is it you are doing, like what kind of game mechanic
making parent follow children goes against the whole parenting thing..
I am making a shapeshifting mechanic. The player can shift into another type of itself and when it does different abilities are opened.
Hi, curious about linking animation events between different game objects. My hierarchy is Player/Model with the PlayerController on player and the Animator on model. I've put my AnimationEventReceiver on the model which I have attached as an image. The functions JumpAddForce and SetCanMove are called by animation events in the animator. These events call the respective events JumpForce and Land and I pass the animationeventreceiver component to player controller which can then read the public events. I'm just getting into the event system and I'm not sure whether or not this is a good way of doing this?
move the parent object not the children
The shifts cannot be the same object as I want flexibility with the components
If the component is on the child of a gameObject, I cannot instantiate that component by that component right?
those can still be children objects, but just move the parent
the parent cannot position itself because the children will move based on the parent. try using constraints instead of parenting them . . .
you can, but it would only instantiate that child object, not the parent. and you cannot reference a prefab using one of its child object components
no has to be on the top level of the prefab
If I got the rb2D from the parent within my child would that work? Both children have their own movement system*
if its a complex prefab with many scripts alot of people have 1 kinda controller component to repersent the whole prefab that references stuff on the child objects
like i often have a component on the root of the prefab, i will instantiate that than call a init method on it to ask it to setup everything in the prefab
only thing i see wrong is not having a null check with Invoke SomeEvent?.Invoke()
other than that I pretty much do the same thing
ok thanks!
The DamageRecountCanvas has the followGameObject script (cause it is the canvas what should be looking towards the camera), but the Damage has the actual script that controls the whole thing, it works with an animator (and does other stuff like setting the text, or the size of it), and when the animator finishes the animation, it calls the method to destroy the whole canvas with an animation event, but it can only call it if they are in the same Object if I am not mistaken, so I don't think I can move them without remaking the whole thing
yeah animaotion events calls stuff on the same object
but that script could always have reference to a other script and call its methods when it gets a animation event
So I make a script with just a method to the destroy the GameObject to use mainly just as a command for animation events?
yeah could work
I literally just noticed that with SerializeField the references do appear in the script itslef, when inspecting it before attaching it to anything, it doesn't do that when they are just public but not serialized, or maybe I did and I was blind all this time
Public fields are serialized already. SerializeField does nothing to a public field
Maybe you did a property?
I mean, public always shows in the inspector when the script is attached, but I did not noticed that references could be directly set from the "script asset itself"
not that you should
I don't know if it is only when serialized
Ah yeah, you almost never want to do that (I have never once seen a reason to)
But yeah, it shows when public or SerializeField
Why would I want to set a default reference to the script?
Why would you want to? I dunno. I wouldn't want to
I have an array of ObjectA and an array of ObjectB. Each instance of ObjectB has a reference to an instance of ObjectA from the ObjectA array.
Setting aside that this I have something ass-backwards going on, given an instance of ObjectA, what is the fasted way to get the instance of ObjectB which has the ObjectA instance referenced? Seems like iterating over the array of ObjectBs and comparing each ObjectA instance can't be right...
I mean, all my enemies share a prefab that spawns coins when they die (and manages what kind of coins they should drop) , if I assing it on the script itself I don't have to assing it for every new enemy
Seems usefull, dunno
I use it currently for a script that each character has, when they take damage it will spawn a prefab showing the damage numbers. I find it useful because I dont need to assign it for every enemy and i can change it if i want for unique enemies
Other than that, I dont really use it
This might be a weird question, but how hard is something like sonics homing attack to code?
whats that
Instead of obfuscating what these are, just show the code because it's a lot easier to think of solutions when we know what's happening. There are a ton of solutions here
It doesn't let me assign a List of variants of the same thing though, it doesn't show even when serialized, weird
It's the move where sonic jumps on the air, then you hone in on the nearest target to attack
i mean thats obvious from the name, but I mean which way
Have you never played a sonic game?
I don't think there was such a feature in the classic 2d games
im old, i played sonic when it was 2D
But it's not hard, just get the direction to the target and move towards in the preferable way.
I also remember nothing like that in sonic
why not just share a video of mechanic
