#💻┃code-beginner
1 messages · Page 756 of 1
When the function call for a collision happens add an if statement for if the tag is player and or if the tag is say asteriod
cus otherwise even if the spaeceship collides with other 2d objects, it's gonna create the same effect cus it can't differentiate betwenn 2d objects
will try that thanks
Thats what the tags are for...
You add a if statement inside the collision trigger to compare the collisions tag
This is a simple unity trigger or collision method that uses tags to check which object collided. I would definitely go over some introductory unity tutorials . . .
Yeah
i just did one tutorial, and i am adding up stuff on the game i got out of that
Remember, it's never a waste of time to watch tutorials. it's only a waste if you don't feel like working on projects anymore
it can be quite a powerful tool
dunno where that came from...
In my case it's easy to solve since i can just use inheritance and have the base method call init().
I was just wondering in the case of, for example a custom animation script that needs to have values defined in order to work properly. Such script can be created from multitude of sources, then i'd have to remember than i need to call Init() every time after addComponent / instantiate.
I was just wondering if there's a better unity pattern / technological solution (like forcing the creator to call init())
Use prefabs
then i have to make a prefab for every permutation & can't use random for example.
That's fine, but always look up how to do the things (you are adding up) on top of the first tutorial. It helps when we can see what you have done to determine what went wrong and where you are stuck at. Without anything, we can't do much but offer up tutorials for you to look at . . .
The truth is, in complex cases, there can be many of them.
You can call random in Awake
Yea i know, prefabs are a powerful tool. However, sometimes the creator (there may be a better term) will know what the values are
This works if the script is self-contained, if you require info from your creator, then it'd not work (for example a bullet needing the weapon that shot it to tell it how much damage it deals)
I have been in unity for many years and have never seen an alternative to Init methods.
I guess, my confusion is on what the "creator," is. Trying to figure out the core problem you need solved . . .
who is this "creator" you keep bringing up?
So u recommend me to look up stuff myself rather than ask here for guides?
refering to the script that instantiated the object / added the component
Fabric
ahh, not sure of how efficient it is but you can make the bullet a var
var Bullet = Instantiate(prefab);
//then call
Bullet.GetComponent<BulletClass>().DamageValue = DamageValue;
prefab can be MonoBehaviour also
yeah this one too learnt just yesterday but forgot
You can skip the get component if your prefab variable is of type BulletClass
Yes and no. You always want to try/test out what you want to do first. Then if you run into issues, or problems, that's where we can help. If you don't know where to start, then we can also point you to the right direction. For example, you should look up: check tag trigger method unity. This will help you check for certain objects colliding with each other . . .
yeah that's what i meant in Init() function, then you can force arguments.I just thought there is a better pattern (one that doesn't require me to remember to call the init()). But as @vital barn said, there isn't one
Ya, that's why I ask for guides and stuff because there's not much jargon out there, sometimes it's impossible to find the right resource to learn from...
Oh, there are a plethora of resources for unity. Any question you ask her, you can duplicate in google and find a resource for. That's literally what most of us do when people ask. We just copy/paste their question and return to results, lol . . .
I thought u guys had a list of guides hidden somewhere
Nope, but the core/beginner stuff are in the pinned messages . . .
People will store specific links they like in bookmarks, but everyone does that . . .
If you're looking for references on how to do a common pattern, chatgpt is extremely helpful as an alternative search engine. Just don't take everything it says as gospel
I found it extremely helpful when trying to learn how to write shaders, there is practically 0 good resources there
All guides are a retelling of documentation
I'm basically learning 90% of my stuff from youtube
I understand. I do the same thing. After instantiation, I'll call Init on the class. that's basically unity's way to having a constructor . . .
Is this correct or do I have the axis swapped again?
foreach(KeyValuePair<Vector3, Terrain> t in terrainTiles)
{
t.Value.SetNeighbors(
terrainTiles.GetValueOrDefault(t.Key + new Vector3(terrain.terrainData.size.x, 0, 0)),
terrainTiles.GetValueOrDefault(t.Key + new Vector3(0, 0, terrain.terrainData.size.z)),
terrainTiles.GetValueOrDefault(t.Key + new Vector3(-terrain.terrainData.size.x, 0, 0)),
terrainTiles.GetValueOrDefault(t.Key + new Vector3(0, 0, -terrain.terrainData.size.z))
);
}```
Pls use method in method
YouTube University is highly related. Mixed reviews: yes, bad teachers: yes, but you'll find gems everywhere. It's like any other school . . .
There's plenty of fantastic resources on shaders
Best "fix" i can think of to prevent bugs is to verify that the values were passed in the Start() function, then you'd at least have an exception if you failed at runtime. Better than debugging a conditional bug
What are you trying to do here?
It seems odd to me to add terrainData.size to a tile coordinate.
Are the keys coordinates, or world space positions? I would expect Vector3Int
writting shaders in code feels like a waste of time when we have shader graphs
more specifically if you disable the prefab before instansiation you can then run your init function on it then turn it on so it recieves Awake() with the setup done
the keys are the coordinates they are spawned in. Im trying to automatically create new terrain neighbors as needed
Found iit very hard to find. Some of them are like "yeah you just put this, idk why" and others are using old api.
Especially because you have hlsl + unity's own api that they bury under 5 feet of documentation and change it once in a blue moon
They're good for learning to do common things, but not api / functions. For that i found chatgpt to be way more helpful instead of digging in the documentation
I have absolutely no clue what youre trying to say
This is a survivor's mistake
However, they're very good to learn the basics of how gpu and shaders work
how so?
You should generally be dealing with grid coordinates until the last possible moment. I don't fully understand the context here but generally you want discrete, integer values for everything until you actually do the final translation to world space.
Unless you want something that can't easily be made using shader graph (laso you have no compute shader graph)
and a lot of stuff via shadergraph can be done very quickly in code
like any visual scripting
that doesnt answer my question if I got neighbor directions right or if I mistook the axis again
That has nothing to do with my question whatsoever to be exact
ShaderGraph is weak as hell compared to making real shaders
With a large number of nodes, ShaderGraph turns into mush.
maybe so guess i've just been too lazy to learn the shader language for it to be any fast to write
Well i didn't know the context of your question and about the previous axis stuff. I was just answering the "is this correct" question.
As for axes it's not really possible to know without knowing the conventions the rest of your code/system are using.
which is fair, just not the whole picture 😄
Its a unity method? Are my directions correct for whatever unity considers left right top and bottom?
How does my code matter when I literally ask is +x assigned as left correct or false
I'm having trouble with storing state data for a puzzle I am building....so I have a bunch of cubes on the screen (Cube_0_0 -> Cube_1_7). Each one has a material (0,1 is fine...or "red"/blue") which has to change, a size (which doesn't change) and a position (0-15). I started with seperate arrays for teh values but that wasn't working. Now I'm trying to get a dictionary working but maybe that isn't a good idea...I don't know. I just know, when a person clicks I have a cube GameObject to work with to do the movements/material changes and I've been trying to base things off name (Cube_0_0)....however I can't figure out how to get/set data with a string as an index. Any suggestions would be appreciated
Those directions are described in the documentation:
https://docs.unity3d.com/ScriptReference/Terrain.SetNeighbors.html
looks like you have some of them backwards (+x and -x)
Good idea. Didn't think of that
curious what application you use that has positive x be left
hey whicht are the best way to move a NPC in 2d Games? or whicht options do i have and whitch would u recommend me?`Rigidbody, velocity Change... i dont know maye CharacterController, Lerp, MoveThoward etc...
NavMesh
But 2D
does that exsits in 2d?
navmesh doesnt work for 2d
There is no "best" way overall. It depends on your game and how it should work
yeah this is why i also said "what would u recommend"
Fire Emblem enemies will move differently from Goombas
or what options do i have?
it depends on your game and how it should work
No 3d coordinate system I ever used before was y up either but here we are unity being weird
a basic Spoider that walks, Attack and have a Distrance Shoot mechanic
Oh I have had nightmares while interacting with devs who say to avoid gpt like the plague. I have stopped using it...
that doesn't really narrow anything down
I remember there are assets
You can't have strings as an index in an array.
What are you trying to do exactly that you want to group cubes by string?
Y-up is a very normal coordinate system
U can though? Just initialise an unordered map for it
y is always up... go to any math class that has a cartesian plane and it's x and y, with x being left & right, and y is up * down
y is not always up
Use a Dictionary with Vector2Int keys. Definitely not strings
RimWorld use NavMesh btw
This too
That is why I was trying to get a dictionary working. I'm just trying to store puzzle state. So the cubes get clicked on (changes materials) and get moved around. Unless I'm approaching this wrong, I'm just trying to get current cube state with cube.name
Meh, they're just burnt from people thinking it's some sort of an all-knowing god that don't question the slop it says.
It's a very good tool but nothing more than a tool
Not 3d a mean asset
yes there are but not by default
Maybe underneath rimworld is a 3D game, just forced top down so it appears 2D
It's not a problem.
yeah, but he has an array, so he'd need to change his data structure
right my bad beside blender when isnt y up
Oh, it's not dynamic I guess
lets say i dont wannt to use NavMash what else are ways to achive the NPC Movement
What's the puzzle?
That's the first step in knowing the correct data structure
@arctic arch @rough granite this might be of interest to you
first result with named axis. Any other named result is also z up
Custom nods of points
Ill never get why blender decided on z-up, its a strange choice
need to reasearch about that, never heard of
2d or 3d?
math does usually treat Z as depth, which can be either vertical or forwards
Hey guys, I have a small problem.
When I type things like Rigidbody, GameObject, or Destroy in Visual Studio, IntelliSense doesn’t show any suggestions or autocomplete.
Other C# stuff works fine, but Unity-specific classes don’t appear.
Does anyone know how to fix this?
!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
• :question: Other/None
@zinc cedar ^
You're building a node system of points and the NPC follows the paths you created in advance, but it's very inconvenient.
they are. that's just a sign that the IDE is unconfigured
either:
- implement your own a* with a limited depth if you're using tiles, but at that point just use a navmesh.
- raycast a circle around you and figure out which paths are not blocked, good for "random" movement.
Just know that anything else other than implementing a pathfinding algorithm / using a navmesh won't be able to effectively bypass walls @scarlet pasture
okay my bad
MonoBehaviour is from UnityEngine, for example.
literally do what youve been shown 3 messages above
(different person)
What?
Thanks!
You need the .csporj files.
I forgot how to do it, but there's a tutorial in google on how to setup vscode with unity (somehwere in the editor's settings you can give it it's default editor)
also restart the editor can also helps. i somthimes have the same problem
Dont use VSCode pls
VS2022 is better
but why?
visual studio community is just better for c#
even if i use Exansions?
Rider is even better
i'm loving vscode. Ur nothing but a hater
all the cool boys use EMACS
NeoVim is better than Rider
idk what you mean obviously the best is chatgpt
Us programmers love arguing about which IDE is best 😅
Notepad++ is king
If you're not spending 50% of your time configuring vim macros. Are you even a programmer?
I wanna know more abt that, I don't rly use macros
It took me a week to set up NeoVim.
like sometimes to go from one line to the other I need to press my arrow keys like hell
no IDE is objectively better than any other IDE. use what you want to use
thanks
HELLL NAHHH
unless you use notepad in which you can use whatever you use somewhere not here 😛
i.. unironically do code in notepad sometimes
even for unity projects
well, textedit, basically the equivalent on mac
That's why when they tell me that Rider is better, I say that it's just a code editor and I just use what I'm used to.
are you getting paid by the hour? 😛
Just start with defualt vim. It's not for everyone.
Essentially when you become proficient in vim sometimes you'll wish you could do something that you always do faster, hence macros.
I personally struggled a lot with following which mode i'm in. And some of it's default settings are just not that intuitive for me
i code in notepad++ whenever it comes to this one game i play where i mod it (officially supported)
no, i use it for scripts in a test project, because i don't want to deal with ide config for the separate workspace - and for those simple test scripts, i don't really need intellisense
Ended up using vim + vscode and making a lot of the default shortcuts i'm used to work there
surely vs code is just nicer tho?
Big boy flexing on all of us plebs
nicer for what exactly?
idk man just nicer in general 😄
im not using it in the context of large systems. intellisense and ide checking isn't really necessary
it's a more simplified view
Its not essential but man it really helps
vim tools sometimes help too
for actual projects, sure. i'm using plain text editors in simple "testing project" contexts.
really does, forced to use java & eclispe for school and their intellisense sucks
i have java assignments for uni rn and i wanna die
wait till you hear about jupyter
In languages im very comfortable with i can write without aid but it really depends
I make too many typos to write without autocomoplete
lmao didn't even mean to make a typo there. Hence exhibit a
and honestly worst part isnt even lack of a proper intellisense it's the fact half the keybinds do random crap (ctrl + d) deletes the line instead of duplicating it for example
Ctrl c v
Every IDE has it's own feel, most of whether X is good, is down to how you respond to using it.
Id say just test drive every IDE and you will find one that you like the most
Try punched cards. Best ide\
HEX editor is better
I've done this tons of times, but I use dotnetfiddle to create a script and save it, so I can load it when I get home. Ironically, since it doesn't have the Unity engine, I've gotten used to creating dummy classes for GameObject, ScriptableObject, MonoBehaviour, Transform, etc. to avoid the error messages and allow for testing . . .
unity kids complain about their IDE.
Real chads open up a game in IDA pro and create their own game via lobotimizing another
IDA pro can rewrite assembly?
(discord doesn't embed domains, it has to be a url btw. just add a https:// on there)
Of course, that's like half of it's use
but yeah ive done that with discord/notes on my phone quite a few times too ngl
I have a short question: Do all coroutine yield commands force them to continue in AFTER Update() when the yield condition is fulfilled.
For example, this one only continues after the async operation is done and after Update():
{
Vector3 offScreenSpawn = new Vector3(-100, -100, -100);
AsyncOperationHandle segmentOp = _trackSegmentRef.InstantiateAsync(offScreenSpawn, Quaternion.identity);
yield return segmentOp;
}```
I was fond of VSCode because creating snippets are easy (when I found out about them) . . .
It just doesn't seem to be possible in the free version.
AFTER Update()
no, some occur at different parts of the execution loop, like during the fixed time step or after rendering
Oh, I didn't even notice the error. I forgot the http stuff . . .
That's how they get ya, just like adobe
#💻┃code-beginner message these are the specific WaitForFixedTimestep or WaitForEndOfFrame, though. other yields are evaluated every frame, after update
see https://docs.unity3d.com/6000.2/Documentation/Manual/execution-order.html
that actually got me questioning, how does unity schedule it's coroutines? is it a separate thread/worker threads or the main?
it's all on the main thread
otherwise unity APIs wouldn't work - they aren't synchronized
only main thread . . .
so only burst can really multithread
after all Fixed Update/Update calls . . .
So async operation yielding does continue after Update
learnt that the hard way. And then a painful refactor ensured
Only special things that unity has made special apis usable in jobs can be done on other threads.
burst is an optional addition
or you use entities which is made with threading in mind
How does memory managment work in unity?
Do parallel jobs that use managed memory make requests to the main thread or do they do their own thing?
i think that's solidly out of the scope of #💻┃code-beginner
probably, just a question that came into my mind when reading the previous discussion
Unity restricts what is allowed to be used in jobs (even when not using burst) to only unmanaged types. ask in #1390355039272439868 if you have more questions about unitys job system
hi guys! once I'm logged in the Unity learn site, where do i have to click for the actual courses?
Not really a code question. but you can access the pathways from the big "Pathways" button at the top. otherwise you can browse individual tutorials using the big "Browse" button at the top. You can also see your learning progress using the big "My Learning" button at the top. You can also search the site using the convenient "Search" bar at the top.
tysm! and you obtain those points by just completing the pathway? and after that I made up my mind on what I wanna make there will be courses for what I want to learn specifically by browsing them? like if I wanna make a survival I can just browse that for tutorials on how to set it up
btw where can I ask those kinds of questions? Ik they aren't much about coding and I don't wanna mistake topic anymore!
tyy
DOTS handles multithreading best
hey does sombody know why vscode formats the code wrong. it only happens when i make a swich logic
what do you mean by "wrong"
what you mean? howso is it wrong?
perhaps show what you're talking about
Use VS2022
yeah no please stop with this
lol.. lazy answer
we do not need IDE elitism here
Ok
like that
what's the difference you actually care about here
the break being in the block vs outside?
the break
yeah that's the same formatting. the break being outside isn't exactly a formatting thing
it is a style thing - just not formatting
There's no difference in how these are behaving, they're doing the exact same thing
but why does it looks extremly wrong when i start to code it but if i finish it it regenratet hiself
Because until you finish it doesn't know what your statements look like
It can't know you're done writing a clause until you actually finish it
ahhhh so its a normal think, i thought its because of the color extanasion
other quastion can i make my Code editor only in Italic
i like that alot
not only syntax. Eveything
That sounds horrible
what no it sounds amazingf
i wanted that so bad bud i cant find a extansion for that
that wouldn't be an extension, would just be a font set via a theme
Is it the general convention to have multiple canvases instead of having multiple disabled gameobjects under one canvas?
there is actually also a italic exansion that enabled for all Color themes Italic
Italics-all-themes
the name of it
this is a code channel, perhaps ask #📲┃ui-ux or #💻┃unity-talk
In general, more canvases is better. Whenever something on a canvas changes, the whole canvas gets repainted, so having a lot on one canvas can actually compound into some significant performance loss. For performance reasons, the ideal UI has a canvas for every individual element, but that gets unwieldy really fast. So, try to strike a balance between having sensible groupings for your own sanity and not putting all your eggs in too few baskets.
make use of the settings.json
"textMateRules": [
{
"scope": [
"comment",
"string",
"keyword",
"variable",
"entity.name.type",
"entity.name.function",
"constant",
"storage",
"support",
"markup"
],
"settings": {
"fontStyle": "italic"
}
}
]
}```
then you can keep any theme you're already using (i think for the most part)
yessir!.. i just learned this the other day.. never knew 😬
thanks to: https://unity.com/how-to/unity-ui-optimization-tips @weak cedar heres some optimization tips for Canvases
heyyy, so i tryed to make movement in 2d and this is the code for left and right but my player does not move
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
!input
To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling
• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.
Thanks
??? where now
other settings
oki dokey
Also unity will restart after change
EZ
hey can sombody pls help me, i use this Gizmos and want t change the color the green when the enemy is on the Ground; ``` private void OnDrawGizmos()
{
if (!useGizmos || RayCastOrigin == null) return;
{
var c = Color.white;
if (isGrounded == false)
{
c = Color.red;
}
else if (isGrounded)
{
c = Color.green;
}
Gizmos.color = c;
Vector3 start = RayCastOrigin.transform.position;
Vector3 end = start + Vector3.down * GroundCheckDistance;
Gizmos.DrawLine(start, end);
}
}```
for me its lookin really good and i cant find the problem there
have you tried logging some relevant values
??? so i have somekind of error i do not know how to fix please help
-# btw, that could be simplified to if (!isGrounded) ... else ... rather than the else if, or even mroe so into a ternary
!code see the "large code blocks" section below
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
and do share the error please, we aren't psychic
okay i can make a tenery operator for this u right
var c = isGrounded ? Color.green : Color.red;
bro i understand sorry i just forgett that
oki dokey
wait does OnDrawGizmos updates himself even?
does the if even runned?
maybe i need to put it inside of onvalidade
well, that would be easily checkable with a few Debug.Logs
delete else
probably not
here
u right i gonna check, is even the raycast working
my bad bro forget to check that out first
if (!Grounded) and if (Grounded)
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
• :question: Other/None
@analog drift ^
- #💻┃code-beginner message
- pay better attention to the code you are copying
- ^ (see message above)
brb gtg eat
it worked
the gizmo only gets green if its on runtime
i thought i can use it even in the editor
for that case i need onValidate right?
yo may i ask what game/app u create right now?
2d Metroid Venia
nope, not what that message is for
OnValidate isn't for drawing gizmos
ahh i didnt understand u correctly, i thought u are angry at me haah
i mean, i did already say this
so what exactly can i do for this case? do u have a recommendation
my bad sorry
All gizmo drawing has to be done in either MonoBehaviour.OnDrawGizmos or MonoBehaviour.OnDrawGizmosSelected functions of the script.
https://docs.unity3d.com/ScriptReference/Gizmos.html
thanks g
what exactly are you using this for? it kinda seems like you'd want Debug stuff for this rather than Gizmos
that's for checking if you're in the editor (vs a build), not for checking if you're in edit mode (vs playmode)
i wanted to learn more about Gizmos
yeah i want to see the changes of the Gizmos while bein in the Editpr
not in the game runtime
why i want see it in the editor
its would look cool i think
ok no you're misunderstanding
gizmos only exist in the editor
the "runtime" you're describing is edit mode vs play mode
#if UNITY_EDITOR won't change anything, you've been in the editor the entire time, even in "runtime" (play mode)
at this point i just test it out on play mode gang 🥀
not sure if you can see stuff drawn by Debug in edit mode, but if you can, that'd probably be the solution
sure
what is a stray else
hey im not sure if this is okay to post it here but can sombody maybe tell me what this is? i have this along time
he means u else is placed wrong
This is fixed with 1 button
pls bro tell me
i got error
becasue of u else
there's an else there that doesn't have an if
configure your ide first. ^
this is a necessary step. @analog drift
ooohhh thank you for the info
hes ide is working, it show him a error
it's only showing basic c# syntax errors. it is not fully configured
it's syntax analysis, it's not properly configured. Input and Vector2 should be highlighted as types, and GetAxis should be highlighted as a method.
but now 2 error
yeah that's not how you were supposed to fix it
thank u
how then
What are you elseing
What is the condition you are intending to invert
@analog drift clearly you don't understand c# enough to fix the basic issues at this point. don't do random things hoping that'll work, that'll just waste a ton of your time.
firstly, configure your ide.
then, go look at what the tutorial is doing more closely.
what is a IDE (lol)
!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
• :question: Other/None
the app you're coding in
one of the above in the list
looks like vscode
Visual studio code
(note that visual studio code is not the same as visual studio)
click the vscode link above and go through configuring your ide
wait... what is the difference
completely different apps that microsoft named similarly for some reason. blame microsoft
They're different programs
if it's properly configured, Input and Vector2 should be green, and GetAxis should be yellow

thanks
oki dokey i have vscode

@naive pawn
what now @naive pawn
fix ur ide
but basically you have:
if(condition)
{
DoThing();
else if
{
DoOtherThing();
}
}```
when it should be something like:
```cs
if(condition)
{
DoThing();
}
else if(anotherCondition)
{
DoOtherThing();
}
else
{
// Neither Condition was met.. run else
}
or with a basic if/else like:
if(condition)
{
DoThing();
}
else
{
DoOtherThing();
}```
every opening bracket `{` must have a closing bracket `}`
and they must be locating in the correct place..
*pay more attention to the tutorial*
capitalization matters.. `Transform` is not the same as `transform`
also the structure / syntax of the code must be correct
having an IDE and configured will help greatly with these issues..
again, configure your ide. there are instructions here. click the link corresponding to your ide
thx
with the IDE ^ it'll tell you like here
comments are misleading (sorry)
b/c you can also use the if to check if a condition is false..
if(condition == false) or if(!condition)
and then the top portion would be if false and the second part would be the else true
It's probably worth trying to make neovim friends with unity
lol.. ngl, not sure how useful it is but coding inside the PowerShell looks pretty cool 😄
oki dokey i fixed it (you fixed it) (lol)
just jot down a note to urself..
and get that ide configured 😉
I'll try (this)[https://github.com/walcht/neovim-unity?tab=readme-ov-file]
why my eyes do this
b/c its toggling between the two conditions u wrote out
have you configured your ide or not
if so, share code - and do so properly this time
if not, go configure your ide
it is a requirement to get help here
configure it
how
ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
sry i am so dumb
oki dokey yup had it configured from the beninging
it's not configured
awwwww man
have you installed .net with the install tool
i thought its the extension
there are additional steps afterwards
lemme check
you've installed the .net install tool, correct?
lemme check
pls remind me that the name of the .net file is
send me a screene
im sooo sry i am so dumb

what is command palette🤣
ctrl + shift + p
it is downloading
Downloading .NET version(s) 9.0.306-global~x64 ............
lol why so many dots
Downloading .NET version(s) 9.0.306-global~x64 ..........................................
lol
it's the progress bar
I need some help here. i'm using contacts to check if the player hit the ground and not the wall to properly set the state
but then this causes a bug where oncollision enter and exit trigger at the exact time when they're suppose to trigger like different sides of the same coin.
private void OnCollisionEnter2D(Collision2D collision)
{
//Get contact point
Vector2 contactPos = collision.GetContact(0).normal;
//If player touches ground
if (contactPos == Vector2.up)
{
//Fire event
playerEnterGround.Invoke();
isGrounded = true;
}
//Kill speed if hitting wall
if (contactPos == Vector2.right)
{
blockedDirection = "Left";
}
else if (contactPos == Vector2.left)
{
blockedDirection = "Right";
}
}
private void OnCollisionExit2D(Collision2D collision)
{
print("collisionExit triggered");
//Fire event
playerLeaveGround.Invoke();
blockedDirection = "None";
isGrounded = false;
}
would you ever be on top of the wall? if not, perhaps consider making that a different layer
Layer?
also, you shouldn't use magic strings. do you need blockedDirection in general? dynamic rigidbodies can handle that on their own
I don't really like how the character sticks to a wall if you keep the momentuem up
physics layers, to define the wall and ground as separate layers
then you can use a layermask to check if you collided with the ground
you can reduce or remove friction to solve that
i see. that sounds pretty practical, although i'm using tilesets.
ah, yeah im not sure you can set different tiles to different layers.
Yeah, the inbuilt tilesets can have some limitations, so i've heard.
but it can also be pretty powerful
if used correctly.
in the past when ive been working in 2d sidescroller contexts with tilesets, ive just used a cast for the ground check
why taking so long to install
yeah, sadly i havn't gotten into raycast yet, although that should definitely be in my todo list.
lol dead chat
yeah we do not need this spam
lol
What do you expect us to say? "Wait faster"?
ok
so sounds like your internet wasn't able to download it within 10 minutes?
it's worked for me the 3 or 4 times ive had to configure vscode, and ive instructed using this to quite a few other people having trouble configuring
should i try again
Pretty sure you can click the box with the red X and see the full error
it's saying there was a pop-up prompting you to install .net, did you get that
👍
lemme check
or if your internet isn't super good such that you'd expect an install to take more than 10 minutes, then increase the timeout as the output says
i guess that's just because it doesn't have .net
If fails again, try this https://dotnet.microsoft.com/en-us/download
wait
you couldve just.. said whatever you were going to say without making me wait
sry where do i increase the timeout
in settings, search ".net install timeout" and increase the value, it's in seconds
Yeah id ask in a proper channel but im not seeing this "jitterish"
mipmap or antialiasing issues
oki dokey @naive pawn i got it installed now what
For flipping your sprite or scaling your graphics, you don’t need to overcomplicate it as a beginner..
Simply say:
- if input is right → face right
FlipToFaceRight(); - if input is left → face left
FlipToFaceLeft();
The issue with using a single Flip() method is that it usually tracks the last direction internally and only flips when the direction changes. that way if youre already facing the way youre moving it wont flip the wrong direction.. this will add extra steps and make the if condition more complex than they need to be (especially for beginners)..
and this is where you're issue is likely coming from... with that setup you need to Flip only when its a new direction which means you actually have (2) conditions for each state... (so if ur already facing left and go to move left.. it shouldn't Flip)
in your case you'd just need to iron out that logic or 👇
- A simpler approach is to use two separate methods:
FlipToFaceRight()andFlipToFaceLeft(). This keeps the logic straightforward and easier to understand as a beginner..
when ur input is left <- you FlipToFaceLeft(); this would work regardless if you are already facing left or if you are facing right
example code to match video clip 👇 https://paste.myst.rs/2gktd930
Hello! I'm unsure if my question falls into code or perhaps render? So redirect me if needed I'm understanding.
I'm attempting to make a cute little 2D game just something I can play idly on my desktop the issue I am having is I'm trying to follow code monkeys tutorial for a transparent background, however, for some reason despite doing the script and changing the camera alpha to black - 0 and some other player related settings. It still appears black and in full screen mode (I've changed the settings to fullscreen windowed and nothing came of that either so unsure.)
without seeing the setup or anything, not much can be done from this end
- As a note, I've never touched anything like this before so I'm a total beginner with zero clue what half of this stuff means. But I love bitting off more then I can chew so I'll suffer. x'D
What info do you think you might need to help with the process? I can provide links to the tutorial I am attempting to follow and the game I am using as reference. And any screenshots to settings and such.
restart vscode
oki dokey
how you wrote it in your setup, the settings you used, which pipeline you're using, OS etc.
now what
let it load for a sec, you should see stuff highlighted correctly now
I am just using the universalrenderpipelinglobalsettings.
I've attached the above script to an empty object
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
if u want to keep the way u have just make sure to log the values and stuff you are reading and using... and make sure the logic makes sense
if (moveInput > 0 && isFacingLeft) // our input says right, but we're facing left soo go ahead and flip
if(moveInput < 0 && isFacingRight) // our input says left, but we're facing right soo go ahead and flip
if(moveInput > 0 && isFacingRight) // our input says right, but we're already facing right soo don't flip anything
if(moveInput < 0 && isFacingLeft) // our input says left, but we're already facing left soo don't flip anything
ITS BIUTIFULLL
there we go
is that for the flip?
using his conditionals yea
there was a settings that needs to be changed in the Player Settings IIRC
did you change that part ? also you exported this for testing ?
u can make that shorter
i do it lika that
itsthe samne
altho i was suggesting just to have a function for each..
one for left.. and one for right..
that way he doesn't need to check which way he's already facing
if ur moving right and facing left -> flip right
if ur moving right and already facing right -> flip right for the hell of it
Yeppers, I went ahead and adjusted the player settings and switched or on any recommended via the tutorial. And did a run build but still shows as a black fullscreen background with img present
😭
man, try to pay some attention to the chat
spawn's been giving you a ton of advice on the flipping
i mean, you were told to configure your IDE, with pings, several times before you noticed 😂
^ its flipping b/c ur conditionals don't keep it from flipping when it doesnt need to be flipped
#💻┃code-beginner message
#💻┃code-beginner message
#💻┃code-beginner message
take a bit of time to read thru it.. check out teh video.. check out the script sample i gave.. and the comments
Knowing me, my adhd brain is just going brr and I'm missing something obvious lol
also Log the heck out of ur script..
when those conditions run.. log code u can read in the console to make sure its doing what u expect it to be doing
my guess is ur simply not updating the facingRight boolean once u do end up facing right..
should go like
{
Flip();
facingRight = true;
}```
and vice-versa
(i mean, it might be done inside Flip)
alright the DXGI flip seems unchecked which should be ok..
and where did you place the script, which gameobject
can't say without seeing the full code there
possibly.. was just a guess tho..
clearly the conditional is fighting itself tho
I just created an empty game object and assigned the script to it.
it gets way simpler if you just ditch flip and just always apply the correct scale when facing that way
instead of ending up in cases where you could flip at the wrong time
^ true story
okay and thats placed in the scene you are building ?
Nod its within the hiearchy
make sure to save
ahhhhhhhhhhh😩 ima just make the face not look lef tor right but to the player
it's not that complicated mate
if you're following a tutorial, just make sure to follow it accurately
hey do sombody know why my enemy dont move to the player? if (useMovement) { Vector2 newPos = rb.linearVelocity + DistanceToPlayer * MoveSpeed * Time.fixedDeltaTime; rb.MovePosition(newPos); }
could you try this
[DllImport("User32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr hwd, string lpText, string lpCaption, int uType);```
in start
```cs
int result = MessageBox(IntPtr.Zero, "Hello! World", "My Message ", 0);```
just incase here is the full script that works for me
<https://paste.mod.gg/rrbaovtlfdrc/0>
why are you using both velocity and MovePosition
choose one or the other, not both
{
Vector2 newPos = rb.position + DistanceToPlayer * MoveSpeed * Time.fixedDeltaTime;
rb.MovePosition(newPos);
}```u mean i should use this
DistanceToPlayer also doesn't make sense to be there
no, how did you get to that
nowhere in my message did i mention position
u mean the distance check?
you gotta stop extrapolating, man
extra what?
i didn't mention rb.position at all, yet somehow you assumed that i was telling you to use that
you should stop making those random assumptions
bro i just thought that this would bne the problem
the problem is most likely using velocity and MovePosition together
how are you mainly moving the enemy? with velocity or MovePosition?
with MovePositiom
alright then let's go with that
what is DistanceToPlayer supposed to be
that should not have a bearing on the movement - only the direction should be accounted for
its the distance between the player and enemy so i can stop him
the logic for the stop i need tu make in a if, but currently i only want to know why he is not moving
Vector2
it did pop up briefly
so it's a delta, not a distance
did it ? ok so interop seems to be working
if you did, it wouldn't be a Vector2
can you show your camera setting real quick. Also sent my script in its entirety you can also double check it and compare it to yours
also the variabel
ok, so it's a direction, not a distance nor a delta
it's the right value, just named incorrectly, then
doesn't make it correct
yeah
words mean things
they're moving too fast.. simply put..
but i do not know how to code movement and ive tryed to add movement for 3 day's now..
they ignored the Learn suggestions went straight to a tutorial I posted (trying to give them a basic one)
then very shortly after they had issues from that tutorial just b/c the syntax and stuff was poorly copied
this calculation should be correct then
they'll have to slow down, get serious to progress
ok, and what would you name a variable that actually holds a distance
you'll just be confusing yourself
DistanceTo..
see the issue?
you're naming 2 vastly different things, the same thing
hmmm u right
call it what it is, a direction
ahhhh directionTo..
have you tried debugging to see if the code is being reached
whould that make more sense?
yeah
okay, i understand what u mean
can you show your camera setting real
and the Enemy movement should now function, i will test it out
regarding the actual issue, see this ^
do u mean me?
if yes i did debuged the current speed of the enemy and isallowed to move. it works
here's a little snippet that may be useful to you
- Vector -> (points from a -b) (has magnitude and direction)
- Distance -> (taking the magnitude strips out the direction leaving only the distance)
- Direction -> (normalizing strips out the distance leaving only the direction)
void Start()
{
Vector2 a = new Vector2(0, 1);
Vector2 b = new Vector2(2, 3);
Vector2 vectorTo = b - a;
Debug.Log("VectorTo (direction + distance): " + vectorTo); // (2, 2)
float distanceTo = vectorTo.magnitude;
Debug.Log("DistanceTo (magnitude only): " + distanceTo); // ~2.828
Vector2 directionTo = vectorTo.normalized;
Debug.Log("DirectionTo (normalized direction): " + directionTo); // (0.707, 0.707)
}``` little cheat-sheet that helps spot the differences between them, i used something like this for a while before i started knowing it by heart
thanks g
yessir
does sombody knows why my [Header] somtimes dont work?
Because you're applying it to a field that's hidden
You've put the header on isGrounded and then told it not to draw isGrounded
attributes only apply to fields -- not on the whole script
You must place the header on a field that is drawn (serialized) in the inspector . . .
so, basically, when you do [Header(..)] public bool someField;, Unity will consider the header when it has to draw that field
so i need to change the "IsGrounded" with somthing thats actually using [SerializeField], and not a [HideInInspektor]
You need to put your header before a property that is actually drawn
drop it down to the first visible variable in the inspector 😉
ahhh chanks now i understand
che chada 👍
thanks
how many seconds for float maxvalue
The maximum value for a standard 32-bit single-precision float is approximately (3.4\times 10^{38}) seconds.
To put this number into perspective: This is far greater than the estimated age of the universe, which is roughly (4.3\times 10^{17}) seconds.
oh wow!
that has to be inaccurate, right?
math checks out 👍
so, assuming the universe is made with 32-bit architecture, we have quite long way to go
You can check this
the only inaccuracy is implying a float can accurately count through each of those seconds. with it needing to represent all of the individual numbers with only 32 bits there will be inaccuracies. but otherwise yeah the math is correct there
theres some nifty info in the Answers on that page ^
Unity calculates time as double anyway ^^ we can get Time.timeAsDouble or something
that person likes to be exhaustive when it comes to extremes, huh? haha
a fun fact in a similar vein that I calculated a while back is that the it would take 2.7x10^21 years to loop each individual int in an Uint128 with the very generous assumption that a single iteration of the loop only takes a single CPU cycle at 4GHz
😄 its actually pretty interesting..
i never thought about needing to store that much information.. or that big of a duration..
im just reading it to be reading it.. (i'll never need to calculate to such extremes)
lmao yea that caught my attention too.. catastropic cancellation
well, technically, precision would likely start be getting within the ns range within the 9h
for ms range where it actually matters, we shouldn't have an issue until much later -- maybe months
neat 🙂 lol
@grand badger u just doing a thought experiment.. or you got some really crazy timers planned out?
my humor is exhausted since 2h ago which is the timepoint I typed something really really funny :p
I just didn't wanna run out of milisecond precision with a Time.time approach for an idle game -- it just needs to support multiple days of uptime
so was considering whether I should refactor that early instead of building more stuff on it.. but seems it's safe to keep ^^
Hm actually, screw that -- I'll just switch to double ^^
Hey, can sombody help me. Currently my Spider Spits at the Player but at the wrong time. he is only allowed to Spit if he is in idel or None (none is jus 1 frame or somthing long). but the DebugError is fired consitenty. Did i do somthing wrong with my if Check? => ``` private void Update()
{
DetectDistanceToPlayer();
if (distanceToPlayer <= SpiderCombatSystemRef.startBiteDistance) //Nah
{
SpiderCombatSystemRef.currentAttackMode = SpiderCombatSystem.AState.Bite;
return; //To make sure nothing other triggers
}
else if (distanceToPlayer >= SpiderCombatSystemRef.startSpitDistance && (spiderBrainScriptRef.currentState == SpiderBrain.BrainState.Idle || spiderBrainScriptRef.currentState == SpiderBrain.BrainState.None)) //Fern
{
Debug.LogError("Ich bin in Spit Mode!");
SpiderCombatSystemRef.currentAttackMode = SpiderCombatSystem.AState.Spit;
return; //To make sure nothing other triggers
}
}
if the AState is => Spit the Combat Script handles that. it also working perfectly finde, i build there a Switch case. But i dont know why the Method is firing Consitenty. i thought about also making a MAX Distancte.
in my MovementScript it also changes the States correctly bewteen, NONE => IDLE => WALK
If you're getting the log error then that means that the condition distanceToPlayer <= SpiderCombatSystemRef.startBiteDistance is false,
and that either distanceToPlayer >= SpiderCombatSystemRef.startSpitDistance && (spiderBrainScriptRef.currentState == SpiderBrain.BrainState.Idle is true, or spiderBrainScriptRef.currentState == SpiderBrain.BrainState.None is true.
if needed i can post the Spiders Movement Code!
i actually need to use a Translater
give me a sec
ahhh yes but why it is true?
even i maked sure that all Statesments are not true in the if check
i thought about a boolien flag just for this case but i really want to understant what i make false here
Which of the two conditions is true?
consider logging the current value of each condition you are checking to find out which is true
You should log the values of them to see which condition is true
i mean i do have a Inspekor field that tells me the current State
the second with the Debug.LogError
hmmm, i definetly do somthing wrong. i dont think unity can make "somthing wrong"
i wish i would know, but we all can say the problem need to be i "SpiderBrain"?
No, I mean in that if. Which of the two conditions is true that you aren't expecting it to be
what do u mean? boxfriend
did you read what those messages said?
where
i delete them, i only allow one Debug per time so its dont get messy
i debuged the current state
and if the enemy was near a boolien flag that says true
And what did it say
did you know that you can put more than a single piece of information into a log message?
its says im in walk, but the Enemy shoots
i also have a inspektor field that says the current State
no
didnt now that
what is the syntax
i wat to learn that
just a "+"?
public void LoadFromDisk()
{
if (File.Exists(savePath))
{
string json = File.ReadAllText(savePath);
saveData = JsonUtility.FromJson<SaveData>(json);
// → is it possible that the saveData could be null here?
// → or fail somehow? considering using a Try/Catch although I never have before
}
else
{
// stim: no save data || rflex: create immediately with Defaults
saveData = new SaveData();
SaveToDisk();
}
}```
❔ looking for some advice from those experienced with load/save systems
im not trying to make something revolutionary or anything but someone pointed out
"what if the JsonUtility fails at reading/assigning my `saveData` var".... 👀
i mean.. i didn't know thats a possibility.. but now im curious if i should have some type of failsafe or something
What exactly did you log and where
i logged whicht current state the enemy has and is the player near/far away
enaugh
and where did you log that
i loged the distacne check with a invoke method every 0.3f sec
and the currentstate every time if its changed
i printed the current state if it chenge it and is not what it was befor
log the useful information at the time you check it
How about you log the values inside the condition that you are checking
i did, currentState is one of them
i did, i first started with the currentStates, after that i used the distacne check
then do it now and show the information
i mean show the fucking logs
dayumn chill
Okay, so what, exactly, did you log, and where, precisely did you log them
just show the code for where you put the log and what it printed
like i said befor, i print one think, if i think that i "dont" need them anymore i delete them
i can write it again?
okay?
that is literally what we are telling you to do. please actually pay attention to what people are telling you if you want to get your issue resolved
what did i do wrong again, i listen to u
if you were actually listening, then show the logs
So, put it back
and show the code
and what it prints
okay i will code it again
i did the currentState public in the inspektor so u can also see it better what i mean because my englisch skills are hella chopped
here u can see the currentState
i also can make it for the Distance check if needed#
can you actually try logging useful information like we've been telling you this entire time
Okay, so which of those logs is the state the enemy is in
stop using the inspector to debug the info, log the info when you actually check it
in the inspektor
okay wait
i can debug them also no problem
one sec
The inspector is worthless
why?
that's why we've been saying log it
Because humans are not good at being able to see exactly the frame a line of code is run
okay, yeah u right
Log the value at the time you want to know it
i debug them wait
so you don't just guess
log the values when you are checking them for your if statement. these logs you are currently showing are entirely useless
I don't know what the time is for. Which of these logs is the one that's inside the if condition you're checking?
guys one quastion
whould that be fixable if i say in the method return if its the false state
if he is in Walk return
would fix that tbh
how about you actually do what we asked and log the relevant info instead of trying random shit
at this point, since you refuse to do anything we are trying to actually get you to do, i am just going to assume you are trolling.
If you're not going to actually do any of the things we ask what's the point in asking
bro i dont know the code of the debugs
this is the problem
i dont now the syntax of it
Just log the variables you're checking in the if statement
inside the if statement
then how have you logged litereally anything else ever?
wait a sec
there isn't some magical special syntax that only applies when we ask you to do something. it's still just logging information, you just need to log the relevant information in the correct place like we've asked you to half a dozen times now
Yes now what does that say
you need to actually save your code and re-enter play mode
So, it's never running at all
did bro
then congrats. your else-if statement is never true
i does this is why the debugs are runned, the first mean "im Shooting"
WTF it must bor why should that debug apear
If you don't see the logs you put in the last screenshot, that condition is never true
if those logs never run, then it isn't this code that is assigning that state
but bro why does that one Debug fired even i clearly said u only allowed to shoot if u Atack Mode is "Spit"
this is so confusying
presumably some other code is causing it
If it's logging that one, then it's calling PerformSpitAttack. The logs you put are somewhere else, and that code is never running
but this is the only line where the states chaged to Spit
anyways. i now what to do now, but this was actually very hard to understand for me
thanks u two
Apparently not. Also just keep the logs there until you're actually done solving the problem
I have a problem - the red dot is supposed to look where it's going but as seen on the video it is blocked by something
here's the code:
{
Vector3 rawDir = target - transform.position;
float sqrMag = rawDir.sqrMagnitude;
if (sqrMag < 0.0001f)
return;
Vector3 direction = rawDir.normalized;
float targetAngle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
float zAngle = targetAngle - 90f;
Quaternion toRotation = Quaternion.Euler(0f, 0f, zAngle);
transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotateSpeed * Time.deltaTime);
transform.position += direction * enemy.speed * Time.deltaTime;
}```
(the function is also in charge of moving the red dot)
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
It's not clear to me what the issue you're asking about is?
How is this behavior differing from your expectations?
Does this red dot object happen to have a Rigidbody2D on it or something?
yes
If so, you are doing this all wrong.
You should never directly modify the position or rotation of a Transform directly when you have a Rigidbody2D
You need to move and rotate via the Rigidbody
oh ok, i'll try that
The weirdness you're seeing is because the object is colliding with the wall which is imparting an angular velocity on the object. So you are fighting that natural rotation every frame
but it wasn't near the wall when that happend (the large hitbox is a trigger so it can't collide with the wall i think)
What's the correct way to work with directions in unity? I've been using Vector2.MoveTowards and similar, but now I want to move an object in the direction of another object and past it.
well if you have a normalised direction you can use that instead of MoveTowards()
Normalized direction was the concept I was looking for, thanks a lot
Oh i have a question about this, what if i had a rigidbody and used navmesh does unity dislike that, or will i be fine?
that's still fighting against the rigidbody unless you are just using the navmesh for the pathfinding and doing the actual movement with the rigidbody
or the rigidbody is kinematic per https://docs.unity3d.com/Packages/com.unity.ai.navigation@2.0/manual/MixingComponents.html
Didnt know you could do that, i was just doing the basic navmesh follow call (forget the actual name)
note that NavMeshAgent is a specific component and the NavMesh is the actual navigation mesh. you are referring to using a NavMeshAgent, which wouldn't be needed if you were just getting paths from the navmesh
Using the agent
Or well was but have switched to a completely different system and was curious about it
Hello, i have a rigidbody(player) that has movement and jumping fine with script ,now when i collide with another collider(house for example) if i force it too much it goes into the box collider where could be the problem?this happens when i jump hold w it goes slowly into the collider
u can fix it if u set at the rigidbody property at contenius
show relevant code
and ideally the rigidbody/collider(s) involved
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
MovePosition is gonna phase right through everything
Maybe changing the collision detection from discrete to continuous on the rigidbody would help, though its normally meant for fast moving objects like a bullet
Oh yeah nvm
thats not gonna help here at all on kinematic
if its not set to kinematic, then don't use .MovePosition
Also feel like theres the problem with using deltatime in the rigidbody no?
normally yes, on MovePosition is fine (assuming its kinematic)
we can tell that this rigidbody is not kinematic on account of it using forces for jumping
true true. then MovePosition is the wrong function completely
Moves the kinematic Rigidbody towards position.
https://docs.unity3d.com/ScriptReference/Rigidbody.MovePosition.html
That and their wish for it to recieve normal forces from other objects (collisions with the ground to not passthrough)
the non-kinematic is probably wats causing some collisions to work, but not completely because of MovePosition
@slender nymph https://paste.mod.gg/chvbyqdbmbfe/1 this is my code dynamic is continous in rigidbody
A tool for sharing your source code with the world!
Im using this for my player detection:
Vector3 rayDirection = player.position - transform.position;
rayDirection.Normalize();
bool playerSeen =
Physics.Raycast(transform.position, rayDirection, out RaycastHit hit, detectionRange) &&
hit.collider.CompareTag("Player") &&
Vector3.Dot(transform.forward, rayDirection) > Mathf.Cos(60f * Mathf.Deg2Rad);
It seems like it works, but I'd like to know if there's a better way to do this or if this is fine on its own.
if it works its fine
Every time i start a animation this model enter in the ground, how i make him to stay in the T-pose?
why don't I have "OnDrag" event ?
I thought it was OnMouseDrag?
Never used it tho, so take it with a grain of salt
both don't work lol
Whats the context?
apparently I have to activate something but idk what
I want to make a camera system
that we can move
2D
and I want to move our camera with the middle mouse
Oh, idk then. Maybe its either an interface or it has a parameter?
for now it's this but I can't use OnDrag
OnDrag is meant for eventSystem
oh
and it only works on UI items unless the Physics Raycaster is used on camera
you can't declare a non-abstract method without a body
your issue isn't that you don't "have" OnDrag, your issue is that you aren't declaring a body for the method
I just started 2 days ago idk wtf am I doing
you're copying this code from a tutorial, yes?
I'm trying to understand with it
but I'm blocked with the OnDrag system and the guy just doesn't explain how can I get it
pay better attention to the tutorial. you aren't being "blocked", you copied it wrong
I just checked the comments other guys are saying the same things
link the tutorial
someone said this
A simple way to drag your camera in Unity 2D using the New Input System.
In case you want to know more about how to set up the new Input System, I have a video here: https://youtu.be/WNV9l04s8t4
Let me know if you need help with anything!
The script: https://github.com/chonkgames/Drag-Move-a-Camera-in-Unity-2D/blob/main/CameraDrag.cs
► Sub...
that is unrelated to your current issue
There is any way to check via scripting if editor is playing by editor tag?
currently im using if(Application.isPlaying) to check if the editor is playing
and i know i can filter final build / editor build with #UNITY_EDITOR on the script...
but there is a #UNITY_ISPLAYING tag?
you need to copy it correctly. go back to 2:12 and copy the method correctly
oh thats not even the OnDrag from UI... thats a custom Action
those are preprocessor directives and happen at compile time, it is not possible to check runtime state at compile time
thanks I'll pay more attention next time
You need to actually put something in that function
you should also consider learning the basics of the language. there are beginner c# courses pinned in this channel, start with those so you understand how to actually write a method. that way, when someone immediately points out your issue, it doesn't take several more minutes of back and forth (and then pointing you back to the tutorial you are copying from) to actually fix it
I wouldnt recommend copying tutorials directly. Try and experiment yourself with IDEs
I'm gonna check that
IDEs ?
Vscode basically, but it shows you unity functions
oh ok
You still need a baseline understanding on what to do
what do you mean by "with IDEs"? are you referring to using the intellisense in a code editor? because that would not have really solved this issue on its own
fiddling in the IDE alone will do nothing
basic c# / unity courses will go a long way
I mean, soon as I got it working I started to experiment and now I have a build on itch so it kinda worked for me
Yeah
what is the point of pulling up all the APIs from the IDE without knowing how to put any of it together? dude doesn't even know how to structure a function, not sure how IDE would help. Sure its good to have a configured one, but doesn't help with the basics
this has already been answered, you should have actually read the responses to you
@rich adder using linearvelocity instead of position solved it thank you !
Hey guys, how do people who take C# and OpenGL courses learn the Unity API? I'm learning C# in a course.
!docs
& 👇
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
i am not using triggers. I am using ``OnCollisionEnter2D` to check for collisions. I have set the asteroids with tag named "Asteroids", but i have no clue as to why it sometimes bouncess off of these asteroids, whereas other times, it gets hit and destroyed.
Did you check if that specific asteroid is setup properly? Select it and show us the inspector panel . . .
oh wait, what you said is right
one of them apparently did not change
Yeah, if it bounced off then I'd think it wasn't set . . .
I have issue with the collision I used sofbody jelly already prepared in unity then it like that
And I using only poligone collider
it a prototype for all that object they have a Three script ONE for the merge one for the comportement and the last one is about the physics jelly
and plus the softbody
First of all this isnt a coding question so wrong channel, also wdym "then it like that"
. @rough granite first of all the channel is code-beginner Am a beginner so that why I ask here if the issue is my scripts secondary If you have some advice to give to fixe my issues write it please three am not familiare with a professionnal discord like that so need some time to know every thing and every channel in this server thank you
so I will wait someone how can give me a valuable advice
Right its a code channel you've provided no code you needed help with nor have you explained your problem
I write here because I know my probleme is note from physics but from one of the three scripts and the video is for to see the resultes of all that three script
and I can`t provide any code because no one answer or ask me for if someone ask it will be a pleasure
Either english isnt your first language or you are ragebaiting me. This isnt you stating your problem
yes am trying my best
hahahah
Sure you can one motto most skilled here go by is https://dontasktoask.com/ "dont ask to ask" if you have a question ask it not ask for someone that can answer it then ask
Just remember for code use a code site
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
no there is no issue with you
never mind next time I will write prompt to explain every Detaille's of the issues in my prototype and send it with code too
as you can see am new here so I said it before don`t take it bad if I ask stupide question
but thank you ,You already give me a advice
Running into an issue where my mouse is not accurate. Everything is perfect in editor but in game my mouse hovering is not accurate. Code below and an image.
// Handle clicks
if (Input.GetMouseButtonDown(0)) // Left click
{
ray = mainCamera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
Vector2Int gridPos = GridManager.Instance.WorldToGrid(hit.point);
// ONLY allow movement to valid tiles
Tile tile = GridManager.Instance.GetTileAt(gridPos);
if (tile != null)
{
player.MoveTo(gridPos.x, gridPos.y);
Debug.Log($"Moving to {gridPos}");
}
else
{
Debug.Log($"Invalid tile position: {gridPos}");
}
}
}
I move my mouse slightly left anddddd
Show the logs. Also log the mouse position.
If the mouse position and logs are correct then it's likely something to do with GridManager.Instance.GetTileAt
Should I have it debug show my mouse position like the raycast?
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
future reference:
From FloorToInt() to use RoundToInt()
is your grid very big? if not then just use raycast from main cam to get the grid tile on mouse click
Nah I'm going to keep it pretty small
using collider
It's working perfect after that swap
nice
im back🤣
LOL dead chat for 1hour+
lololol
heyy so i am having trouble with my jump system for my platformer (2D) so pls help
Please don't spam the channel. If you have an actual question ask properly so it can be answered.
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
Yes, this is how bot commands work. Was something unclear the first time it was used?
no i just used bot cmd's for the first time ever
so cool
heyy hows this
You need to actually read what the bot message says. You still explain nothing about the problem. And this is a code channel, if you have problem with the code, post it.
done 😄
Then post it in #1180170818983051344 , again, this is a code channel.
oki dokey
wrong channel as well
whats the best practice for accessing children of a prefab? surely its not .Find() with a magic string, but I can't seem to find a better alternative :p
Make a field and drag the child into it in the inspector
it wont let me for prefabs
serialized references whenever possible
it only lets me drag if I make an instance of the prefab in the hirearchy
that shouldn't be an issue, could you explain more on what you're doing/what the context is?
instantiating the prefab and accessing its children to populate fields and stuff
tmp, sprites
all that
open the prefab and assign the references in prefab mode
wait, are you trying to get the references in an object that isn't the prefab?
ye
Make fields on a script in the prefab and then access them through that script when you instantiate
and use the "main" script of the prefab as the type of the serialized field you use to instantiate, that way you don't have to do GetComponent later
(rather than GameObject)
im lowkey just about to learn C# how long does it usually take im also wondering where i start cause i have no idea im just going off of unity documentation i dont even know what to click or start on give some tips
Do u have any coding experience?
none at all this will be my first ever language and learning how to code i wanna lock in and i have so much time on my hands
i do know what publics and privates are
and a bit understanding of floats
well no
no floats
only public and private
i know that youtube tutorials are not the way at all
i never understand those either
https://www.w3schools.com/cs/index.php
Do all that before touching anything unity
i have unity experience