#💻┃code-beginner
1 messages · Page 720 of 1
why? it only needs to hold a boolean.
those are 2 separate functionalities
"detect button press" vs "detect button press, keep track of held progress, check if it's full"
the actual interacting doesn't happen in the interface.
...ok?
Why does your interactable interface even care how the input happens? That sounds like something that should be on your behavior. The interface just needs to have an end point, the thing that you call when an interact happens
IInteract, IHoldInteract
how hard is that?
Or, make your interface have two methods: OnInteractStart and OnInteractEnd.
Then, you call both on every interactable. Ones that are press just look for start and have an empty end method
so i have to do another getcomponent check which one is not null then run an interact that is the same?
Ones that work on hold actually do both
if trygetcomponent interact {
interact
} elseif trygetcomponent holdinteract {
holdinteract
}
i agree i don't need seperate interfaces it'll just confuse things.
if (interactable is IInteract)
//reg interact
else if (interactable is IHeldInteract)
//held interact
but this is going way off topic i just wanted to know how to have an overridable / un-required boolean in my interface.
..you're going against the whole design of an interfaces
class Handgun : IInteractable
{
void OnStartInteract(){
DoShoot();
}
void OnEndInteract() {}
}
class Flamethrower : IInteractable
{
void OnStartInteract(){
StartFire();
}
void OnEndInteract(){
StopFire();
}
}
Boom. One interface
two interaction styles
This can not be done
Stop wanting that
Interfaces, by design, do not have optional methods. The thing you're doing is making one with a default implementation. Everything that implements that interface still has that function
"its a contract / an obligation" for those classes to implement those..
it guarantees those methods exists.
oh ok. but i don't want an onpress and on release. i want them to just have the player hold the button then it'll fire the method. which rn is handled by my interactor script that checks whether the object i'm interacting with has the boolean TakesTime set to true.
i'm fine if i can't.
starting to feel this is overcomplicated ngl
why couldn't you just have an interactable component instead of an interface
(potentially separate interactable and holdinteractable too)
then use a unityevent or something to link that to the actual behaviour
if there is already and interactor with bool doing what you want, whats this conversion about interfaces again ?
yeah in hindsight i think you're right.
i just wanted scripts that don't take time not to require public bool TakesTime { get; set; }
you're skirting around the question, why not just keep it an interactor component , why convert it to an interface?
let's say i have a base abstract class, gun, and a class which inherits from that, shotgun. if i later on want like, a double barrel shotgun, it'd be dumb to make a whole nother inherited class, no? is there a better way?
personally I think you should checkout SO (scriptable objects) and rethink how you handle weapon data
Then you wouldn't put that on an interface
Interfaces are the solution to the problem of "I don't know what class this is, I don't know what this class does, but I can guarantee, enforced by the compiler, that it has functions with these names and method signatures"
Optional things do not exist in interfaces
It cannot be done
ok.
i thought about it but abs classes allow me to use anny shooting logic
So would ScriptableObjects
They can have functions too. They just shouldn't store state (due to inconsistencies with how they save things in the editor vs gameplay)
it will be so much easier you can create almost unlimited weapon types just by changing a few common stats and creating a new SOs.
if some weapons shoot but "feel different" it just changing the stats..instead of having a clutter of classes
and you can still have some inheritance where needed
wdym by states, like enums...?
Hey guys how do I make the line from the linerenderer component follow its gameObject parent?
I'm drawing it using this
if (Input.GetMouseButton(0))
{
points.Add(new Point(virtualKeyPosition.x, -virtualKeyPosition.y, strokeId));
currentGestureLineRenderer.positionCount = ++vertexCount;
currentGestureLineRenderer.useWorldSpace = true;
currentGestureLineRenderer.SetPosition(vertexCount - 1, Camera.main.ScreenToWorldPoint(new Vector3(virtualKeyPosition.x, virtualKeyPosition.y, 10)));
}```
which draws fine and correctly on screen but the drawing fails to follow its parent.
like if your weapon has modifiable runtime stats that change, you wouldn't change it on the SO itself
Basically, unless you know what you're doing, you wouldn't change variables on ScriptableObjects to avoid confusing yourself. But they can still have functions that do things
alr
time to restart the weapon system TwT
its good to just lay out all the options before delving deep. Weapons system can range from simple to very complex
good idea to take your time seeing what you got to work with
Interfaces, Abstracts and SO can all work together, or separate to create good weapon system
hi guys just as a reminder how do you paste code on the server?
!code 👇
hmm dyno asleep?
📃 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.
📃 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.
holy laggin hell
anyway in case that dont work its also in #🌱┃start-here
setting useWorldSpace to false makes it follow the parent, but draws in the wrong place (probably because it translates the virtualKeyPosition relative to the parent's position)
Hmm maybe I should subtract the parent's world position from the virtualKeyPosition
that didnt do it boo womp
hi why does my vs code wont show intellisense tooltip even after downloading unity extension on vs code and modifying my packet manager as well as external tools in unity?
!vscode
follow the above guide
If your IDE isn't providing autocomplete suggestions or underlining errors in red, then it needs to be configured.
ive done all of that before, i forgot to mention im on macOS
Make sure your unity preferences has Vs code set as the external editor too
i have all of that done already. When I type "Debug." or "transform." it doesnt recognizes it and intellisense doesnt show up either.
also you have an Error (red box) if you Press should bring you to the Issue in output window. Most likely SDK missing
have you installed the dotnet sdk and then restarted the ide
and you dont need to check all this off, they just create clutter.. you only usually need the first top 2
yes
confirm that run dotnet --list-sdks in terminal
i restarted my system it works now
Could someone tell me why I cant access it? I have it already installed from registry
thats no longer the namespace in 3.0
iirc its Unity.CIinemachine
ty vm
@rich adder do you have an actual good beginner guide on unity game dev recommendation?
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
hey i'm can't figure out how to check where the player is looking a A, B, C i am currently using a very hacky method but even that doesn't work.
float Pos1 = (1Pos.position - PlayerPos).normalized.y;
float Pos2 = (2Pos.position - PlayerPos).normalized.y;
float Pos3 = (3Pos.position - PlayerPos).normalized.y;
float dir = transform.rotation.eulerAngles.normalized.y;
int val = 0;
if (Pos2 - dir < Pos1 - dir)
{
val = 1;
}
else if (Pos3 - dir < Pos2 - dir)
{
val = 2;
}
``` i really want a better method but i just can't think of it (also does anyone know how to shift lines to the left i know in vscode its Ctrl+{ )
also does anyone know how to shift lines to the left
in discord?
yes. or can you not?
Delete the tabs
Juste delete the blank space at the front of the line..
ok. i just thought there might be a better method
there is not - it's not a fully fledged text editor, indentation isn't something you'd expect
https://docs.unity3d.com/ScriptReference/Vector3.Dot.html
The Dot Product of two direction vectors is their "sameness". It's 1 when they point the same way, 0 when they're perpendicular, -1 when they're opposite.
So, get the directyion the player is looking in, and the directions you want to compare it to, and see which one has the highests dot product
(or the one above some threshold like 0.9 or something)
disclaimer: 1/-1 will represent parallelism/antiparallelism only if the inputs are normalized
Right, the key word being two direction vectors, meaning a normalized direction vector, not euler angles or anything with a magnitude
so...
Vector3 Pos1 = (1Pos.position - PlayerPos).normalized;
Vector3 Pos2 = (2Pos.position - PlayerPos).normalized;
Vector3 Pos3 = (3Pos.position - PlayerPos).normalized;
Vector3 dir = Player.transform.rotation.eulerAngles.normalized;
int val = 0;
if (Vector3.Dot(dir, Pos2) > Vector3.Dot(dir, Pos1))
{
val = 1;
}
else if (Vector3.Dot(dir, Pos3) > Vector3.Dot(dir, Pos2))
{
val = 2;
}
``` (btw there is a better method by selecting everything and shift+tab)
(whoops mb, didn't see that word)
middleclick drag to select a region
eulerAngles are not a direction vector
Still important to point out the intention behind the words "direction vector"
you'd want Player.transform.forward
should forward be normalized?
It is normalized
no.
why do you think it isn't normalized
It is
Transform.forward
Returns a normalized vector representing the blue axis of the transform in world space.
oh. cool.
what did you mean by this lmao
bump
i meant that i didn't put .normalized in front.
oh, i just re-read it i thought he said is it normalized.
int val = 0;
if (Vector3.Dot(dir, Pos2) > Vector3.Dot(dir, Pos1))
{
val = 1;
}
if (Vector3.Dot(dir, Pos3) > Vector3.Dot(dir, Pos2))
{
val = 2;
}
``` its never 2?
Try logging those values and see if the dot towards Pos3 is ever greater than the one for Pos2
sorry i meant it's never 1 sry. i will log the dots.
well seemingly the one at the bottom will always override the last one?
Well, yeah. If you change a variable to something then change it to something else, that's the new value of the variable
yeah i know that but i mean the bottom one will always be true for some reason besides when its closer to pos1 rather then pos2?
Well, the bottom one checks if Pos3 is closer than Pos2
If that condition is true, it sets val to 2
yes, but pos2 should be closer in my scenario but it isn't.
What do the logs say are the values of Pos3 and Pos2?
dot1: 1.003048dot2: 1.081255, i think there's some things that need normalizing...
Yeah dots shouldn't be over 1 if both inputs are normalized
But also this is dot1 and dot2
I asked for dot2 and dot3 since those are the conditions of your if statement
sorry this Is dot2 and dot3. inconveniently dot1 and dot2 sorry.
How about for clarity:
float dot1 = Vector3.Dot(dir, Pos1);
float dot2 = Vector3.Dot(dir, Pos2);
float dot3 = Vector3.Dot(dir, Pos3);
Debug.Log($"Dot1: {dot1}, Dot2: {dot2}, Dot3: {dot3}");
And then you can use the dotX variables in your if statements as well
it works! just needed to normalize the Pos1,Pos2,Pos3 stuff.
Where's the best place to learn C#?
Just check the pinned messages and start from their. No one source will have everything (except the C# documentation) . . .
how to see int[,] in the inspector?
on the job
Unity cannot directly serialize multidimensional arrays or jagged arrays
what you can do is something like this:
[Serializable]
public class MyIntCollection {
public int[] data;
}
public MyIntCollection[] allData;
I have this issue where when I switch issue before the player changes it stops the movement which I don't want how can I fix this? https://paste.ofcode.org/CKBqU4kk2RD92kHGcnbhNC
store the Rigidbody's velocity in a variable and then apply it to the newly created object
The code will be simpler and easier to understand if you:
- Use Rigidbody for the variable types instead of GameObject
- Give the variables better names like "mainPrefab" instead of "mainPlayer"
On the job doesn't help when you are the one training yourself lol.
sure but it's definitely the best place to learn 😛
Microsoft Learn site, Coursera , codecamp, w3Schools etc.
If I remove the gameobject and replace them with rigidbodies and if I try to destroy them won't it ony destroy the rigidbody?
Change the code to access the gameObject so it's destroyed and not just the Rigidbody component . . .
congratulations
why is SpawnEnemy() being run constantly?
@tiny crag you have to somehow not make it run constantly
why not just use Time.time
https://docs.unity3d.com/ScriptReference/Time-time.html
also don't post code with screenshots
Thanks! that was way simpler that I thought. https://paste.ofcode.org/34UfHjCtNXLKW4RBEbKTw8X
its still running constantly
what do you want it to do then ?
yes the idea is that the timer is supposed to reset when spawnenemy() has been run
to be triggered every 2 seconds
but also for the trigger to happen 0.05 faster every time its triggered
Then reset the timer inside the method. This ensures it's always reset when it's called . . .
the method is being run inside all the clones that are currently active in the scene
!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.
A tool for sharing your source code with the world!
This is not right
why did you change it back, if its supposed to keep speeding up just keep it how it was with
Timer += Time.deltaTime;
ok
Interval = 2f / gameSpeed;
Timer += Time.deltaTime;
if (Timer >= Interval){
SpawnEnemy();
enemyScript.movement();
Timer = 0f;
gameSpeed += 0.05f;
foreach (EnemyScript.fullPosition enemyposition in enemyPositions){
Debug.Log(enemyposition.x);
Debug.Log(enemyposition.y); }
}```
ima try it
still running SpawnEnemy constantly :(
Your doing something wrong then
yes and im trying to figure out what exactly
add this Interval = 2f / gameSpeed; in if statement *
its there in the code
Huh, that's confusing because you call it inside of Update and Timer is a class member. Why would it be on a different script?
I meant move it inside if statement
Timer = 0f;
gameSpeed += 0.05f;
Interval = 2f / gameSpeed;```
Nah man your doing SOMETHING WRONG THOUGH
Debug the values and see whats going on. chances are might be something else
because i want the movement and spawning to be synced in the game, i need a game manager to run the script for spawning and movement
no wait hol up a sec
@cosmic dagger @rich adder omg all i needed to do was as randomunityinvader said and just reset the timer inside the method
idk why it doesnt work in the update method but it is what it is
Finally he did it
@cosmic dagger sorry i got the movement method inside the prefabs mixed up with the SpawnEnemy method im tired :)
hey man thanks for telling me i did something wrong it really helped!!! 🤗
timer stays > interval on the next frame
ill make sure to ping you whenever i run into an issue
i dont understand are you saying that its better to reset the timer in the action that is being taken by whatever is triggered when the timer reaches the interval?
seems like it runs a couple frames more before resetting
order of event issue I think, I believe if you did
SpawnEnemy();
enemyScript.movement();
Timer -= Interval;
gameSpeed += 0.05f;
Interval = 2f / gameSpeed;```
it should work fine
either way as long as its solved lol
Just letting you know that the next non-useful thing you post here will be your ban, seeing as you just came off a 12 week mute for spamming.
hello, trying unity for the first time, following a quite old but good tutorial for player movement, heres my code:
https://pastes.io/unity-player-movement
but even though the movement works great, i cant jump 🤔
yee haha
put Log inside ```cs
if (Input.GetKey(jumpKey) && canJump && grounded)
if its not called, then one of those conditions isn't true
it is indeed not called 🤔
I was wondering why this whole exchange seemed familiar
after removing && canJump, it now works, but its very akward
lemme record a clip
How do I say a useful thing
anyone?
so then make sure canJump is true
i can just remove that, idrk what it does, but jumping is incredibly wierd
I dont see anywhere where canJump starts true..
removing it is not the solution..
i go up and basically glide in the air for some seconds
do i just change the air multiplier?
what?
but it works :O
oh
it "works" as in breaks somethinig else
all you need to do is make sure canJump starts true
ill do that when the jump becomes a jump and not a glider
alright your project, do what you want lol
i offered you the solution but you seem fixed on removing something that was put in place for a reason
what does canJump do here when grounded is put
i added it back and set it to true in the beginning
I guess multiJump
ask the tutorial dud
the whole point of it is for a "cooldown" so you dont jump right after jumping
Oh yeah that works too
You can tweak the gravity on your object
if you use a Char Controller change your motion equation if you're using a rigid body increase downward velocity (or force depending on what you're using)
mass does not change how fast it will fall
calling AddForce in multiple places is probably causing the issue in air
if you want something to fall faster you multiply the gravity by multiplier
rb.AddForce(Physics.gravity * forceFalling
wdym?
im having yet another issue, i want the object running the code to keep the current value of spawnSide for the duration of its existence, which is why i try defining it in Start(). But that value isnt saved for the method called movement(). Why is that?
A tool for sharing your source code with the world!
what are you confused on?
"you multiply the gravity by multiplier", like i apply extra gravity after the rb already has?
first what are you trying to do exactly. Can you show the issue?
vc? so i can screenshare
make a video and post it, there is no VC channel here
dm vc?
too much of a commitment , I don't do private srry
nw, ill just make a video
how did you make sure Start is running before movement()
here, i fall too slowly and in my opinion to linearly
they are being run simultaneously, maybe thats the issue. Should i define it in awake()?
sure you can try that first
@rich adder
what about when not pressing movement keys
wdym?
like when i dont press WASD?
This looks like something is setting your Y velocity to 0 every frame
also that linearDamping is pretty high
if its not that high i go zoom at like 50m/s
nothing is settings the velocity, only applying forces tho
Show !code
well technically JUMP is
📃 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.
horrid site but here they posted it
https://pastes.io/unity-player-movement
lemme paste the updated code
unless somehow Jump keeps running, its probably the damping imo
Put a log in Jump()
yeah... it logs when i jump, as expected?
Okay, and it's not spamming when you're floating down to the ground?
Then it's the damping
but when i lower the damping it only changes x and z damping, not y
disable the script , keep the same damping. if it falls the same its the damping
pretty sure ..damping doesnt just pick XZ on its own..
its apparantly the damping, but when setting the damping to 0 it still falls really slowly, and when reenabling the script, when moving in the air my speed spikes up to over 100
wdym..if you put it to 0 and still fell slowly , what makes you say it is indeed the damping?
nvm it just felt real slow when compared to how fast you move, just lowering the movement speed fixed it
thanks for the help guys
ill be back later
because now ill try to implement sliding
https://hastebin.skyra.pw/fezuqesopu.pgsql bro im gonna start tweaking im working on this for hours but i cant figure out what causes the problem. i have this character that should choose a random point to move to, but if its hungry (searchFood = true) it should first check if theres food near it, if yes it should move there, if not, it should search a random point again and move there instead. at first when it was hungry, it wouldnt move at all. ive got it to work a little bit, but as soon as a berry is in its range its getting mentally unstable or sh as it moves in a zigzag randomly. but if theres no berry in sight it just works. im getting more and more mentally unstable the more i try to fix this, so im pretty sure i wont find the issue myself, thank you in advance
debugging is how we solve issues
this is code is all over the place, many moving parts. Debug each one to see where it goes wrong
also seems way to overcomplicated for what you seem to want to do
how would you do it?
for starters probably trim down some of the repitions in code
are there some specific examples where?
I wouldn't worry about that now.. First find the root cause of the issue, place logs and figure out what the code is actually doing and is everything what you expect
okay i try
ok i logged basicly every line of code and it seems like the code checking if the target is reached never gets called so the velocity is never set to zero. meaning the direction changes and i think thats causing the zigzag. i really dont know why the target is never reached though. cant be because of a collider as the berry´s collider is set to trigger
are you talking about the part of Vector2.Distance ?
yes exactly
if (Vector2.Distance(target, currentPosition) <= 0.2f)
{
rb.linearVelocity = Vector2.zero;
timeBetweenMoving -= Time.deltaTime;
if (timeBetweenMoving <= 0)
{
targetX = Random.Range(transform.position.x - sightRadius, transform.position.x + sightRadius);
targetY = Random.Range(transform.position.y - sightRadius, transform.position.y + sightRadius);
timeBetweenMoving = Random.Range(-defaultTimeBetweenMoving / 3, defaultTimeBetweenMoving / 3) + defaultTimeBetweenMoving;
}
}```
make the distance a variable and debug it, see what values are doing
also isn't zig zagging meaning changing the target pos constantly, I dont think I see anywhere where you only search target if one was not set?
Hello, Is anyone familiar with Photon sdk's and how they work??
probably people on the photon server
should be pinned in #archived-networking
what do you mean?
which part
"also isn't zig zagging meaning changing the target pos constantly, I dont think I see anywhere where you only search target if one was not set? "
do you have multiple berries? is it finding one , then finds another , then another ?
oh yeah that might be really possible
should i disable every berry except one for testing?
try that first sure
Ty
man testing something random is really difficult if theres only 1 wanted outcame wait
wdym "only 1 wanted outcame wait "
the only outcome that delivers info is one where the berry is in its range. but baiting it to the berry is not easy
huh
thats weird
how does it normally move to berry
it should move randomly until it has a berry in a certain radius. its really primitive i know
oh okay. I just didn't know that was your mechanic
and no zig zag ?
its only as smart as what you code it to be.. most likely something wrong in the code
I would use a switch statement here for a very basic state management, so you can see what happening with their " current thinking" too
bro that theres something wrong in the code is the only thing i know rn 😭
yeah thats actually a good idea
i think im just gonna scrap the whole project i dont want to see this little guy anymore
Idle, Wandering, SeekingFood
etc.
you dont have to scrap the entire project, but perhaps make a simpler part / project where you only test the wander system / food seek
imposter syndrome kicking in right now🙏
thats what I usually do when Im stuck
make a separate project for the mechanic you are struggling with this simplifies just concentrating on that 1 part, no assets , nothin
funny thing i have 2 classes in this project, one that doesnt work as we know by now and one thats basicly almost empty
this project is basicly empty
thats a good thing. Means you know the limits
better than having the Dunning-Kruger Effect
then perhaps you overcomplicated the code too soon.
got humbled by my own projects a lot haha
this is 2D project right ?
just curious, so you're not using pathfinding right ? just randomly moving top down or something in random dir ?
yes. wanted to do pathfinding but got humbled very fast by a mystical algorithm called A*. scraped it and went for a (how i thought) a simpler solution
man was i wrong
Ah, the "Speedrunning why everyone just uses the algorithm" solution
you can still achieve the random pathing, just use A* project to simplify it or use the custom Navmesh by h8man
I think it's a CGP Grey quote that "Any solution that 'seems reasonable' and 'is easy to implement' is universally a colossal failure, the albatross of which will shackle all future developments in the field for decades"
now thats a quote
ik i will probably do something with that in the future when i have time to look into it a bit more as i want to understand how it works a bit
fr
hmmm..lemme see If I can cook a quick example
isnt that the hexagons are the bestagons guy?
yes
It was about airplane boarding systems
ohh i saw that vid
couldnt remember that quote tho
i havent been on unity for a while so does anyone know what this is
what is "this"
a defaut c# class?
void start and void update dont work
no i tried to add them bc they werent there
whats that
thanks
when making a new script make sure you make it a MonoBehaviour script
(if you want to use those method / put script on gameobject)
do i just replace void start with monobehaviour.start
if not what do i do
oh nevermind
nah. start over and make new MB script like I said
try it
yes
is subtracting 1/50 from a value in FixedUpdate the same as subtracting Time.deltaTime in Update?
assuming you haven't changed the rate that fixed update is called it theoretically is. but also, why not just subtract Time.deltaTime?
for example if i need a timer in a method that should be called in fixedUpdate or are there better solutions?
the better solution would be to use Time.deltaTime
didnt evenn know you can change the rate
in fixedUpdate?
yes. did you know that there is documentation for things like Time.deltaTime that tell you how they behave?
ok sory ill use documentation next time
thats crazy work for half an hour if you ask me thats pretty cool
especially considering i took 3 hours to make something twice as complicated work half as good
not even, i just booted it up. took a few mins
thats crazy
in due time you will probably do the same. Just takes time
https://paste.mod.gg/mmohwphdbiey/0
probably mistakes somewhere but for a 2 min script should get the point across
A tool for sharing your source code with the world!
if (foodTarget == null) is this so it doest change the target as lon as it exists so it doesnt zigzag with multiple possible targets?
yes that is so it doesnt keep running Overlap when it has a target to go to
when you reach the destination with V2.Distance you can eat the food and set it to Null
perhaps this simplified version can steer you in the right direction
ofc it would be also better to make a simple state machine with enum like mentioned earlier
its all relative, I get imposter syndrome every day lol
only time i dont get it is in school because even tho you might not believe it in programming class i get asked for help more often then the teacher
I don't doubt it.. everyone has different knowledge / skills, so just knowing more in certain aspects just means you have experienced it more
yea
ask me anything procedural and I go into fetus position and rotate in circles on the floor
ngl thats so relatable tho
how do i get alpha with .dds files? it shows transparency in my file browser but it's gone when in unity and there's no alpah options in the import bit
Didn't even know it had any support for em
are you working with a mod ? whats the benefit to dds format
no but im planning to make modibility easy, and also dds is directly with the gpu which makes it much much faster and it has built-in mipmap generation
ohh I see..thought things like DXT compression took care some of that, but Ig idk enough about it so i'll take your word 
im not an expert i just know a few things TwT i did fallout 4 modding awhile back
was about to say i only knew about dds cause of fallout :p
basically gpu compatible bytes vs metadata contained or something..
Unity already does this stuff for you that's the point of an engine.
You provide a normal image and it handles the format and mip gen based on settings you configure
was about to say saw option to generate mip in import texture
Pretty sure even source engine had mip gen it's nothing new
whatever is there a way to use alpha with .dds?
Check the docs for what textures unity supports. I'm going to presume no
DDS isn't even listed so I doubt it will work
https://docs.unity3d.com/6000.3/Documentation/Manual/ImportingTextures.html
uh i shut down unity shut down my pc. and now none of my game audio works. Any suggestions?
there is sound int he editor I can manually play the script from the assets folder in the editor but its like none of my audio is actually playing now and I cannot figure out why
audiosource.Play is being called if i disable the audiosource it will throw warnings in the console
Check your game view isn't on mute, there's a button at the top.
Nevermind, don't crosspost please.
Hey, I'm trying to learn how to make Inverse Kinematics. I'm trying to make logic that moves the head point to where the player clicks, and its flying away so fast it breaks int limit. This is my code: https://hastebin.com/share/onifetozip.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Is boocean a real thing or am I just making up nonsense
Nonsense
did you add logs to see why this may be happening? also consider just looking into unitys premade IK and animation rigging
Premade IK hasent been updated since 2022 and I have a specific use for it
well then still add logs or use the debugger and see exactly what these values are, you'll very quickly see why your object is flying away fast. unless you plan to move via physics, you dont need fixed update there. you'd also want to multiply by Time.deltaTime when adding to the position there
when I lerp a rotation how can I keep it from going all the way around?
I'd like the right to be the same as the left and not have that little flick (or left same as right, both are pretty good as long as it is consistent)
I honestly don't see anything in this video that is clearly a rotation
the trail obscures it a bit, let me make it more clear hold on
you can see the sword flicking a full 360 on the right but not the left
This was already answered last time you were here
you'd have to show the code
but it sounds like maybe you're lerping euler angles instead of using the appropriate function for rotation interpolation which is slerp
Trident.transform.eulerAngles = Vector3.Lerp(Trident.transform.eulerAngles, new Vector3(0, 0, 0), 0.3f);
yup that's it
so do I slerp rotation instead of lerping eulerangles?
Yeah lerping eulerangles is a recipe for this kind of thing.
You can use Quaternion.Slerp instead
Trident.transform.rotation = Quaternion.Slerp(Trident.transform.rotation, Quaternion.identity, 0.3f);
although this is also framerate dependent but that's a whole separate issue.
yup, works now
No one answered it yet ⬆️
you should not be rotating a Rigidbody via the Transform
most likely the body is just settling back to the stable orientation as you try to rotate it
it's also not clear exactly where this function is running
hello beautiful people i need help making this door and door window open in sync. its from the abandoned asylum free pack on the unity store if that makes any difference
guys i have a problem
the character controller tutorial i was following
doesnt implement sliding
only crouching
Parent the window to the door
i actually just did that im completely new to this this is all my first day in unity
its somewhat similar to ue5 which is what im use to but i heard the pathing and ai stuff is way better here so here i am
I'd recommend going over the learning paths on Unity !learn then. Before diving into actual real projects.
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Or read through the manual.
i will absolutely do this once i figure out how to get the textures on some pinkage i got going on.
hi
i need help with terrain generation so i am trying to build a map that generate infinitely and has trees and every thing with a road on which we can drive i tried the unity documentation but under terrain section there wasn't any thing about that can some one help
@high mauve Don't cross-post. If you have a code question then post the code you have problem with.
i dint have a code , and what is this about cross-post isnt this a beginner chat?
Choose a one relevant channel to !ask a full question.
: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
ok thankyou
when trying to reference my inputs with
[SerializeField] private InputActions _inputActions;
nothing pops up, and I have to reference individual refs such as
[SerializeField] private InputActionReference _zoomInput;
is this intended?
What is InputActions?
Make sure you have !IDE properly configured.
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
It's just my custom inputs with the input event system, my IDE is working fine and intellisense/debugging all works perfectly fine
Make sure your custom class is [System.Serializable]
Still can't get it to show up in the interface for some reason after doing that, InputActions is just from the unity generated class
turns out setting the default value to something non null seemed to serialize it 
Might not have been saved previously. Project needs to recompile for serialization to update. Saving triggers it unless overridden.
appreciate the help
im new to unity, just bought a template for an incremental game im trying to create i imported it into my project but idk how to set it up/ make it run liek its advertise like despite me adding it idk where to put it for the thing to run
like i have it here
but i dont know how to actually put it to display so then i can mess around with the settings
Does anyone have a resource on how achievements (10 kills in smoke etc) are done in a clean, modular way? It's something that's been picking at my brain lately and I can't picture how it might be done
Not necessarily a C# resource just in general, or a source-code example from industry maybe?
Assets come with documentation and example scenes
What’s a scenes canvas
How can I access it
This is a channel for code questions.
This server is not for help with bought assets.
Read the docs that came with the asset.
Contact the publisher of the asset for help.
Do tutorials on !learn 👇 so you know what you're doing
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I try dragging it in the scene but it doesn’t work
check the read me .txt might show you the steps
it says this
but i try draging the button on the scene
and nothing happens
i try dragging it here
do i need like a specific scenes for these to run
There isn't anything to "run". They are UI elements. You'll have to first learn how to do UI in Unity before using this asset
🥳
does anyone know how to read and work with values from light probes?
Similar how Steam does it.
Have a 'Stat' class that tracks the kills.
An 'StatAchievement' class that checks a specific Stat
Your Units should have events for dying, killing, etc. that the Stat (or another intermediary) class can listen to.
Then a AchievementDisplay class that displays any earned achievements (if Steam is not running)
The issue is if you have a bunch of obscure achievements (kill 10 enemies underwater, drive a car 10km, click on the logo 100 times etc), you end up hard-coding everything into that Stat class. For just kills it's pretty simple, but I probably shouldn't write a separate system for each achievement type right? Unless I misunderstand
This might actually be the best/only approach, but you never know
why do you want to sample light probe data?
There does seem to be some data we can access but I think its only for loaded scenes
https://docs.unity3d.com/ScriptReference/LightProbes.html
@grand snowim trying to make a stealth system where the players lighting is compared to the lighting of the wall behind the player (from the enemies perspective), and i read somewhere that light probes could be used for that kind of stuff but I'm open for better alternatives if there are any
was testing out this model and noticed that a bit of his hair comes out when jumping. Would there be any quick way of editing the model in unity or will it be a go back to blender and rerig the model type of thing?
Edit: never mind, just fixed it
you probably want your own storage of this data so it can be accessed easier. You can read the lighting data assets in editor to build this data ahead of time (e.g. bake light then update your lighting data)
https://docs.unity3d.com/ScriptReference/LightingDataAsset.html
https://docs.unity3d.com/ScriptReference/Lightmapping.html
This would be editor only automation to prepare the data
@grand snow I'm sorry, I'm very, very new to all of that. Could you explain that to me like I'm an idiot?
Make new component that stores a grid of light data. You can read the lightmap data, parse it and write the new light data to your component in editor.
We can modify assets, prefabs and scenes outside of play mode with code which lets us do cool stuff and automations like this.
You can get the probes for a scene with https://docs.unity3d.com/ScriptReference/LightProbes.GetSharedLightProbesForScene.html
You then need to get the baked probes, sample the lighting and based on that figure out brightness for that position.
It may be a bit advanced but is most likely the way this would need to be done. Access the light probes and sampling colour would be required either way.
for some reason game build size keeps being more than 100 mbs, theres any reason on this?
all the assets that i inserted to the game is mirror
also it has a few amount of assets like textures and meshes
overall it shouldnt be more than 100 mbs
how do i make it so if the player presses like, A and S at the same time it chooses one of the two instead of just stopping the player's movememt
liike, if you press two opposite values, a and d, or w and s, (was a typo) it canceles
but i want it to choose w or s if both are pressed
yeah that's usually the intended behavior, and how you change it depends on how you're processing input
Check the build log for a list of included assets and their size
and figure out from there whats taking up lots of space!
I'm using an input map, a player input component, and a script which the component invokes callbackcontext onyo
I'm trying to compare these strings (Line 168), but the code never enters inside the "If"
As example, I'm trying to compare "romantic" with "romantic"
But I don't know where I mistake :/
That's my Debug.Log
set "which side wins" in the composite binding
try logging their lengths, perhaps there's an invisible character you don't know about
Ahhh
How can I adjust it?
When I set to write in the debug log, show the exactly string
well romantic should be 8 so seems like the first one has extra chars
where's that string from, and perhaps try logging out each char to see what said invisible chars are
i forget how you'd do the latter
This whole string comparison game is lipstick on a pig.
Stop using strings for this in the first place, unless you can guarantee you're sourcing them from a one single place. Use an enum instead.
I'm not sure if I understood :/
Do not use strings to compare
Use and compare enums
Im trying to make the rigidbodies stay on a plataform
Doesnt work they just keep falling
public class movablePlataformBase : MonoBehaviour
{
public Rigidbody2D rb; // Platform's Rigidbody2D
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
void OnCollisionStay2D(Collision2D collision)
{
Rigidbody2D otherRb = collision.rigidbody;
if (otherRb != null && otherRb.bodyType == RigidbodyType2D.Dynamic)
{
// Apply platform velocity to the object
otherRb.linearVelocity += rb.linearVelocity;
}
}
}```
I mean
The plataform moves without them
I think without them touching and there being high friction they often wont
Huh?
adding velocity like you are wont really help because you keep adding the platforms velocity which will keep building up
why share it then 😐
Cuz is the only code i had in hand
You can try translating the other rb by how much the platform moved or ensuring the velocity of the other rb does not drop below the platforms velocity
the latter wouldn't allow you to go backwards relative to the platform
where?
hmm thats true. maybe physics materials is the easy way then
O h
my other idea is adding force needed to move the other rb along with the platform
Physics materiales?
yea try one with high friction on the platform
in the inputactionsasset
isn't parenting the usual recommendation? does that not work for rigidbodies?
static can be set differently
you could set a different combine type to force it for this interaction, but then that'd also introduce side friction
Huh?
What do you mean?
check the doc page, there is dynamic and static friction as well as the combine mode
perhaps high static friction + max friction combine mode on the platform will do it
actually put both high 😆
i feel like if you set only static high it could make walking forwards go backwards lol
these are options on a physics material asset
Separately the frictions
can't find it
Doesnt appear
I already made a material (thats why the player has zero friction)
Theres only..friction
And bounciness
And the combines
fuck is this 2d?
dang yea i forgot that has less options avaliable. try it anyway
Sorry i put the 3D one in hiatus cuz i discovered i would struggle with level design
But try what exactly. I cant modify dynamic and static separately
doesnt exist for 2d physics 🙁
they are seperate physics libs so we dont get the same stuff
This was already mentioned yesterday. Take the velocity of the platform and append it to the velocity you're planning on moving the character, this frame.
What you're doing now is having the platform control the velocity of the player, which is backwards.
I try it
Oooh
I mean
Im doing it that way cuz it must also checks enemies
Maybe objects
So it would look odd if some objects worked and others fell
And those objects should have controllers which handle this, not the other way around. Platforms are dumb objects, they should not have authority over anything other than their own movements.
Makes sense
i cant find any setting related to which side wins
platform be like: "imma platform doing my thing.. up n down, whatnot"
thing thats controlling the player movement: "ohh, hey platform, now i know ur a platform gimme ur up n down whatnot and ill go ahead and (add)apply that to the movemnt code we already got going on"
So in theory
When calculates if is standing on top of something or not, should check if has component movableBoi, if it is, should plus it velocity with thr plataform's velocity, right?
Yes, which is what was said yesterday
like u on an airplane... if u walkin down the aisle.. ur moving a certain velocity.. and the planes moving a certain velocity... and from a bystander ur actually moving with both added
I did it. Didnt worked
What i did wrong?
same concept can be applied to all kinds of movement, momentum stuffs especially
knockback, so on and so on
how do i exit out of an if statement and go to the bottom else?
Holup
redesign the code 😄
#💻┃unity-talk message i also mentioned it.. velocity of platform + velocity of player
you dont
either if or else gets executed. If you want both you need a second if
make a function that does the else stuff and call it at the end of the if
and also in the else at that point
eh you can probably have a bool to control this logic being executed
Like this?
{
RaycastHit2D hit = Physics2D.CircleCast(transform.position, groundcolliderradius, Vector2.down, groundcolliderdistance, groundlayer);
// Check if the hit object has the movablePlataformBase component
movablePlataformBase platform = hit.collider.GetComponent<movablePlataformBase>();
if (platform != null)
{
// Add the platform's linear velocity to your own rigidbody
if (rb2D != null) // Make sure you have a reference to your rigidbody
{
rb2D.linearVelocity += platform.rb.linearVelocity;
}
}
}```
really not the same thing tho yea
I dont know what went wrong
I mean
The player doesnt stay with this neither
is the code running? have u debugged and made sure u getting values?
-
Are you even getting to this code? You haven't debugged that.
-
Are your platforms actually using physics based movement?
These are basic things you should know to do by now. At some point, this handholding needs to be upgraded into critical thinking.
on the composite, not its parts
the one that says 2D Vector
I mean, it would be weird if didnt ran
debugging especially.. it should immediately be the first and always go to.. come with the facts! 📖 👨⚖️ lol
Alright, good luck then.
yeah, seems it's only avaible for axis1d, split movement into movex and movey
All debugs work
ah right, yeah that makes sense.
so the linearVelocity of ur player rigidbody has the extra platform velocity? do the numbers add up?
if soo it is working.
@primal trench why exactly do you want that behavior though? like i mentioned, it's usually the normal behavior that pressing both sides yields no movement
if not.. what else would it be maybe try a multiplier to multiply the force of the platform and see if it just takes more effort to move ur rigidbody around
Mmm, idk
Only the debugs are triggered
feels better gameplay-wise
......
It coould be part of the issue, if the plataforms arent moving actually?
A huge empty gameobject moves
It has plataforms inside
....yeah
a "platform" should be the actual rigidbody object w/ a collider
or a collider within it children
It has a rigidbody
b/c the raycast detects the collider
the rigidbody gives u the velocity
Just ...that doesnt move
you have to move it by physics
well if nothing is moving then ur player isnt gonna be moving
The parent moves with physics
🤔
The childrens are it "decorations"
The thing is this
Big empty game object, has a rigidbody and a boxcolliser on the bottom for move, inside of it, are kinematic boxes
Its like a walking mountain
This sounds like you're confused, the visual doesn't matter.
the "platform" is all the components made up to make it.
The plataform is a children
The plataform doesnt even moce
The parent moves
And by so, the plataforms follows it
Do that affects smt?
the collider gets detected by the raycast
its hunting for movablePlataformBase
and im assuming it has a rigidbody
that means in theory all of these pieces need to be on the same gameobject for your script/setup to work from what it looks like (bare minimum the collider and the plateformbase script)
and just for a pro-tip u should be probably workin on this in isolation since ur having trouble with it..
forget the elaborate parent/many platform deals u got going on. and make a super simple platform..
test ur code with that.. if u can see and know how it works before hand it makes troubleshooting more complex situations make sense as u know what ur looking for.. and what the conditions made it
The parent is still part of the platform.
{
Vector3 Speed = new Vector3(MoveInput.x * CurrentSpeed, 0f, MoveInput.y * CurrentSpeed);
Speed = transform.rotation * Speed;
CharController.SimpleMove(Speed);
}```
why can't the player move in the air
it is relatively simple.. like i said start simple and then graduate to more complex..
also (in my honest opinion) it helps do things like expose the rigidbody in the inspector like i did here.. so that i 💯 know
when its getting velocity from the rigidbody.. (inside hte platform code its just using simple Lerping and the rb.MovePosition())
and as u can see after getting it working thats just step one.. as theres already 1 bug i found in my own implementation where when the platform moves downwards it loses contact with the rigidbody.. probably some drag/dampening things i would need to consider to continue
void HandleMovement()
{
Vector3 Speed = new Vector3(MoveInput.x * CurrentSpeed, MoveInput.y * CurrentSpeed, 0f);
Speed = transform.rotation * Speed;
CharController.Move(Speed);
}
this is a simple fix, flying a character takes much more than that @primal trench
adjust what?
There is nothing in your code that suggests you cannot.
meaning you can move slightly while in the air on the x and z axis?
The only assumption here is that your HandleMovement isn't being called while in the air, for whatever reason. Maybe you're only calling it when you've detected the player is on the ground.
where i can check the log?
its in the build?
When do you call HandleMovement
update
!logs
Unconditionally?
yes
is the HandleMovement() inside of any if statement?
Then you can move in the air.
If it's called in Update uncondtionally, and nothing else is moving the character, this will work in the air
Maybe you should share !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.
ok thanks
[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour
{
[Header("Movement Speeds")]
[ReadOnlyInspect] public float CurrentSpeed;
[SerializeField] public float WalkSpeed = 3.0f;
[SerializeField] public float SprintSpeed = 6.0f;
public enum MovementState
{
Walking,
Sprinting
}
[ReadOnlyInspect] public MovementState State;
[Header("Look")]
[SerializeField] float MouseSensitivity;
[SerializeField] float VerticalClamp = 80.0f;
[Header("Input")]
[ReadOnlyInspect] public Vector2 MoveInput;
[ReadOnlyInspect] public Vector2 LookInput;
private float VerticalRotation;
private CharacterController CharController;
[Header("References")]
public Transform CameraRoot;
private void Start()
{
CharController = GetComponent<CharacterController>();
}
private void Update()
{
StateMachine();
HandleMovement();
HandleLook();
}
void StateMachine()
{
switch (State)
{
case MovementState.Walking:
CurrentSpeed = Mathf.Lerp(CurrentSpeed, WalkSpeed, Time.deltaTime * 5); break;
case MovementState.Sprinting:
CurrentSpeed = Mathf.Lerp(CurrentSpeed, SprintSpeed, Time.deltaTime * 5); break;
}
}
void HandleMovement()
{
Vector3 Speed = new Vector3(MoveInput.x * CurrentSpeed, 0f, MoveInput.y * CurrentSpeed);
Speed = transform.rotation * Speed;
CharController.SimpleMove(Speed);
}
void HandleLook()
{
float MouseXRotation = LookInput.x * MouseSensitivity;
transform.Rotate(0, MouseXRotation, 0);
VerticalRotation -= LookInput.y * MouseSensitivity;
VerticalRotation = Mathf.Clamp(VerticalRotation, -VerticalClamp, VerticalClamp);
CameraRoot.transform.localRotation = Quaternion.Euler(VerticalRotation, 0, 0);
}
}
Log your CurrentSpeed in your HandleMovement function and see what it is when you're in the air.
it's 3
But also why are you multiplying your calculated speed with the rotation of the object? What's the purpose of that?
Also nothing here seems to be changing MoveInput so where are you reading input?
seperate input script so it's not connected to this specific movement stuff
move in the direction the player is facing
Try logging it. Log Speed before you call move
And also the actual MoveInput to see if it's actually a value. We don't know how that is being passed in, or when, or what other potential ways you might be modifying it before it's sent.
it's exactly what i'd expect
Okay but what actually is it when you're in the air
depends on what buttons you press speed is a vector 3
So give some examples. The point was to see the vectors, not the magnitude
Hold forward and show what it prints then
here are a few
while in the air?
maybe something outside of this script is preventing from moving the player
is the character (in the air) moving slowly or not at all
I'm pretty sure SimpleMove works fine in the air, it just replaces the y value with gravity. Just as a sanity check, replace it with .Move. You will no longer fall but you can at least try to see if you can move while ungrounded
correct
Correct as in it works now? Or correct as in it didn't change anything?
no like, if i do move it does remove gravty but you can move when ungrounded
not at alll
nopethere's no ifs
I can't get unity ThirdPersonFollow component on cinemachine to work straight over the shoulder.
Okay, so you can move mid-air with normal .Move, but not .SimpleMove?
yes
Then I guess you'll need to handle gravity manually and use .Move
how would I do that?
Keep track of your vertical speed separately, use that for the y value of your movement vector you pass to .Move. Subtract some gravity value from it every frame, and when you're grounded reset it to some small downward force like -0.1 so you can remain in contact with the ground
// Vertical movement (Y)
float vertical = currentVelocity.y;
if (controller.isGrounded && vertical < 0f)
vertical = groundedGravity; // Stick to ground
else
vertical += gravity * Time.deltaTime; // Apply gravity
// Combine horizontal + vertical and move
currentVelocity = new Vector3(horizontal.x, vertical, horizontal.z);
controller.Move(currentVelocity * Time.deltaTime);```
yup, you just take the movement u already have and tack on a gravity value before sending it to `Move`
something like this works to keep u pretty grounded
isn't there built-in gravity?
If I define a vertex shader that defines some input parameters that a mesh doesn't provide (like taking TEXCOORD1 but the mesh only having 1 uv channel), what happens if I use that shader to render the mesh?
what a sigma
It'll be treated as either all 0s or all 1s. I don't remember which, but you can usually check it by just having that value map onto a color or something
how do i solve this
whats there to solve. What am I looking at after being blinded
use words
so after building the project, suddenly its size got more than 100 mbs, ive looked to build logs and saw this
it just added 100 mbs from no where
i dont remember the engine itself weight like that
is it depending on build profiles?
Should I use visual scripting or learn c#
learn c#
I have experiences in visual but it's easier than unity but harder than scratch
tutorials or docs?
both
both
theres tons of ways to learn
And I don't want to use godot because I hate the node system
100mb is tiny for a unity game
the what
it takes time. these are your best bet for C# first
Microsoft Learn site, Coursera , codecamp, w3Schools
the first build had 40 mbs weight
Where exactly can I find one that actually teaches me something, not just type and here is your script
Can someone remind me what the order of awake, initialize, and start is? And isn't there a 4th thing?
Okay
but it got more than 100 mbs later
Thanks
take it slowly , most of the concepts are the same no matter what you do VS or C#.
variables, methods etc.
I know basics like variabled
when you get more comfortable then you look into more specific unity API functions and concepts
good so that can only benefit you further knowing these
With visual scripting
If terrorist touches you-> -1 from "health" variable
so theres no way to lighten the build?
its the same things, except you're writing it
which causes less mess tbh
if you want to learn the components unity has you can play with their VS as well , while you learn the c# too.
Thank you 🖤 🖤 🖤 
what initialize thing are you talking about
RandomUnityInvader answer it all good
Learning both?
just needed to find something post init
Is that a feature?
https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/manual/build-view-reference.html you can use this to get a better idea of your project size (puts the size on each asset in the build tab) @trim quarry
its a feature if you make it such lol
yeah but init isn't a thing built-in in unity so not sure where you're getting that from
ok ill see thanks
It sounds like maybe you should familiarize with general programming without Unity first?
You can consider "Awake" their initializer for MB but otherwise you have none @neon forum
How can i
The programming level I am currently at is print hello world
(they did include awake already so 🤷)
Which is python
@inland flame perhaps give this a read
(in general) there's 3 major parts to programming:
- Language - The syntax, structure, and paradigm of each language
- Library - The interfaces and utilities that each environment or toolset provides
- Logic - The algorithms to do work at runtime
Logic is almost completely transferrable between each language and environment, you just have to learn the specific Language and Library that you're using
Language is also shared quite a bit between languagesof course, learning 1 part at a time is easier than learning everything at once, which is why tools like scratch or code.org are popular as coding courses for beginners, especially kids, because it only focuses on the Logic aspect
Then you really should learn C# first. Don't worry about anything Unity-specific. You feel that way because Unity tutorials probably assume that you already know how to program
The weird thing is, I used to program on game engines nobody even knew
So there was a scene system, scenes were parts of game (like menu, shop menu, game itself , death menu etc) now I take a look at unity godot etc they use scenes for objects too
I don't exactly get that, everything is different
which is hard for me
Did you use visual scripting then?
Yes
everything is pretty much a container..
Scenes are containers for gameobjects
gameobjects are containers for components.
etc.
Like when adding a game object, they make a scene for that first
Then you are basically trying to learn unity and C# at the same time which can be overwhelming
if you are actually planning to stay and keep learning unity game developement, you need to learn c#, it will take time, but if you just want to make something quick use visual scripting
I actually did learn godot and unity, I can understand them better now but coding is still hard
SceneManagement and the BuildIndex (where u add all ur scenes for ur game to build) would be the "Scene System"
The whole point is me to learn c# and make games
If I use visual scripting
It will be boring after some time and I will regret because I don't learn c#
visual scripting is usually good for small scale projects
VS will be a complete mess and harder to understand than code after a while
it just gets real messy once you start doing anything complicated that usually only takes 50ish lines
I start off small like that terrorist game, then add featured until it becomes 50 megabytes 
anything bigger and more complex, you will start seeing weaknesses, and the nodes will get a lot more complex very quickly
this is not the case with programming
Unity was easier than godot for me
So, I dunno if my idea is correct. I wanna have so if my player collides with the weak spot, it destroys the enemy. I'm just kinda piercing together other bits of code that are similar though, so I dunno exactly how to accomplish it.
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Weak Point"))
{
Destroy(Enemy.gameObject);
}
}```
have you tried it ? seems fine
You are comparing a tag to a name
also yeah actually Tag != Gameobject names
So should I use unity or not
actually why do you have a reference to a specific Enemy Object ?
you should be using other.gameObject for the one you hit
every game engine has weaknesse and strengths
but unity is good too
Yeah
Godot was bad for me because of node system
I want to add a city map, the nodes make it impossible for me to edit normally
Too complicated
Don't go with unreal engine as a beginner by the way, unity would be good
yeah one thing I disliked about godot was the nodes
very confusing imo
tried it too
Godot is also a good choice but again, every game engine has strengths and weaknesses
does this mean I can't make GTA 7sadblob
Also my laptop has i3
I'm scared that after some time it will start to lag and crash
so you can't even run GTA V 😅
not even 4
wait
Yeah
I finished 4 in i3 it was fine but not 5 ;P
It was 10 fps
how in the world did you complete GTA IV with just 10 fps
oh ok
The best game I could do was a dark themed game where you had to pick up crystals, I couldn't code picking up system and I stole the movement system
But you had a flashlight
Which was a child of player
big achievement
Oh Im very aware that what I'm doing is wrong, I just don't know what to do that's right. The tutorials I've had until now are along these lines, but they directly delete the thing they collide with. I'm not sure how to destroy something else.
what do you want to destroy instead ?
guys so i bught something like a template game, that the guy is able to run in like web version and he sent me a folder with scripts. how can i put these in a new empty project and make it run
did you read the file that is named READ ME
The enemy that the weak point is a child of
you mean from WeakPoint to Enemy ? just do
other.transform.parent.gameObject
Its a bit weak but should work here
in an ideal situation you could make the reference to enemy directly on a component placed on weakpoint trigger
its nothing there
just some bs
i assume he only sent me the code
and not
the sprites right
like not the full game just the coding behind
How would we know, you're the one with the files. If there are only scripts in that folder labelled Scripts, then you would probably be assuming correctly.
Yep, that worked. Are oyu able to explain why it uses transform to reference that?
parent is a property found in transform property
b/c other is a collider.. collider doesn't have a .parent variable..
it's Transform does however
i'd say open a google doc and take notes on stuff you learn. it helped for me
the point that u assumed its gona be hard to remember is a better reason to jot it down
yes taking notes is also good.. also you need to use it often to remembe rit
Repetition is the mother of learning
ur just grabbing the main Transform of the gameobject in order to access parent, child, etc, everything #💻┃code-beginner message thats on the doc page
So what was the thing nav said about in an ideal situation you could make the reference to enemy directly on a component placed on weakpoint trigger ?
So basically you would put a component that has a reference to the Enemy
then you can access it as a field / property
in case your trigger is buried down the heirarchy and doing transform.parent might not always yield the wanted transform
so it would look like if(other.TryGetComponent(out EnemyHurtTrigger trigger)){ Destroy(trigger.Enemy.gameObject)
EnemyHurtTrigger would just have
public Enemy Enemy // assigned in inspector
^ yea.. the component u end up grabbin from the trigger/collision
would also have a reference to it's specific Enemy
Put a script on the object that you collide with, then that script knows what object it's supposed to destroy
Hmm, I understand bits and pieces of what's being said
thats a step lol.
which part you're mainly confused on?
So, make a script, put it on WeakPoint
Write something like public GameObject enemyPrefab; at the start of the script
Drag the enemy prefab into it in the inspector
Is that right so far?
not the prefab, no
you want to know about the specific enemy, not the prefab it's from
What do I drag into the inspector then?
the parent you want to destroy
Well my enemies are prefabs though?
yes so you would make this in the prefab so it works for all enemies spawned from it
Ah, I think I understand
its just a quicker/safer way to reach the parent, or any objects you want
traversing through transform can be "weak" if the hierarchy changes you're shit outta luck.
Do they actually exist in the game when it is running?
Double click the prefab to bring it up in the "blueprint looking room" and then drag the enemy parent from that heirarchy into the inspector
they are not, they are prefab instances
the prefab is basically a blueprint for the enemy
you can't use it directly
you Instantiate it to create an actual enemy from the blueprint, called an instance (hence the function name)
Yes, that
Hi, I'm trying to program a basic movement system into my game using the new input system, but I'm currently stuck with trying to figure out the code for sprinting and crouching. I plan to do a class callback in the Update function, but I have yet to figure out the actual code to put in the if function. Does anyone have any suggestions?
move expects a v3
which direction you want it to go?
oh, I want the sprint to just go forward
so you could use transform.forward for example
but if you want a sprint like thing, I would maybe use a Coroutine and call it while thats goin on
So what's this bit about?
if(other.TryGetComponent(out EnemyHurtTrigger trigger)){Destroy(trigger.Enemy.gameObject)
I assume that's going in the script attatched to the weak point. Is that gonna be using an ontriggerenter?
oh yea that's true
I have to brush up on coroutines though, its been a hot minute since I've touched that
this would be on the player (though tbh it feels like it would be easier to do on the weakpoint)
it checks if the other object has an EnemyHurtTrigger, and if it does, to get its .Enemy.gameObject and destroy it
oh wait misread that
it's your code lmao
check the docs, its pretty easy way to get some timed events.. You can ofc also use plain old timers in Update
thought I read EnemyHurtTrigger should go on Player . My brain is fried today mb lol
If you put it on player, what would be the point of putting a script on weakpoint just to reference it's parent (enemy)?
the player just looks for the EnemyHurtTrigger (component on child / trigger)
from there up to you if you destroy it from player like you have it now, or create a function that does it directly on trigger script
Hmm, back to being confused
which part ?
now it's not the "parent"
like, that's not how it's defined
how would i push a character controlleer to the ground?
You put a script on the object that you interact with in OnTriggerEnter. Then that script can do whatever the hell it wants with that information
So, you've now made a more robust system that can work for more than just "Destroy this object's parent"
now it's just, the enemy that the weakpoint belongs to
could be the direct parent, could be something else
point is, it's managed by a serialized reference now, so it's more flexible
the player doesn't have to assume that it'll be the direct parent
@thorn kiln
A few.
I'm confused about what code to put in what script and how to reference things in each
two scripts.
One on the player for detecting OnTriggerEnter
and another on the WeakPoint Trigger
If you have a script on WeakPoint you don't need to do .CompareTag anymore. The component already tells you what it is, and you can use that to do something with
I was about to say "So I'm not putting any actual code in the EnemyHurt script that's attatched to WeakPoint at all?", but then Chris said the code would be easier to do on WeakPoint?
I also could use a little help in this thread here:
https://discord.com/channels/489222168727519232/1407920726580793385
Okay, this is the end result of juryrigging everything people here said to me, and it works, though I can't say I fully understand it.
private void OnTriggerEnter(Collider other)
{
if (other.TryGetComponent(out EnemyHurt trigger))
{
Debug.Log("Collided with weak point");
Destroy(trigger.enemyPrefab.gameObject);
}
}```
enemyPrefab as a name is misleading
prefabs dont exist at runtime, they become regular gameobjects
Just what the tutorials always ask me to write
prefab in the name implies something you will spawn as a copy
its already an instance, just call it enemy or whatever
Well, reguardless, I'm trying to understand the if statement
checks if other has a Component EnemyHurt plain and simple
if it does, stores the result as trigger
So "other" I assume just means any other object besides the one the script is on
TryGetComponent is telling it to look for a component of the object it collided with?
It's looking for the script "EnemyHurt"?
I don't know what out is or what trigger means in this context
no other is the Collider that OnTriggerEnter returns
See how you have Collider other in the parameter list? That is defining a variable called other. other is just the name of that variable.
Okay, I kinda get that then. In the JS course I did the tutorials would always have you give stuff a filler parameter too, like "x"
Just that it's a thing that needs a parameter so any name is fine
you have declare types in a statically typed language
[Type] [name]
Well typically you want to give your parameter a descriptive and meaningful name, but yes according to the compiler the name can be anything
the name can be anything ya
just a name. You can literally call it asjhdjaskh and it will still work..
just who would remember that lol. you wanna be descriptive
Well it's more an observation that it doesn't even make you type it, it just auto-completes to other
thats the way unity setup the Code Snippets
using the sprint toggle i made causes my player to teleport, rather than increasing his movement speed
i set it to
{
playerMoveSpd = playerRunSpd;
}
else
{
playerMoveSpd = playerWalkSpd;
}
Anyway, why is it out EnemyHurt trigger instead of something like how GetComponent works just typing "EnemyHurt"? What does out and trigger do here?
it worked when i did my 3d project but not when applied here
the same concepts here, except the result is coming from out because the function TryGetComponent already returns a value bool so you can't have 2 return values
trigger is just a name of the EnemyHurt found, stored in that name / variable (same thing, name can be anything here)
the bool is because TryGet returns true if it found the component you want, otherwise it just skips the if block
show how you're moving the player
wdym, im using a + d if you mean keybinds, but i didnt specifically set them up
the code
if(TryGetComponent(out MyComponent myComponent)) myComponent.DoStuff
//is same
MyComponent myComponent = GetComponent<MyComponent>();
if(myComponent != null) myComponent.DoStuff ```
you should at some point learn about `out` its very powerful keyword / tool
i put the code in the video but alright
using UnityEngine;
public class PlayerWalk : MonoBehaviour
{
private Rigidbody2D rb;
public float playerMoveSpd;
public float playerWalkSpd = 2;
public float playerRunSpd = 4;
private float moveHorizontal;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
moveHorizontal = Input.GetAxisRaw("Horizontal");
if (Input.GetKeyDown(KeyCode.LeftShift))
{
playerMoveSpd = playerRunSpd;
}
else
{
playerMoveSpd = playerWalkSpd;
}
}
void FixedUpdate()
{
MovePlayer();
}
void MovePlayer()
{
Vector2 movement = (transform.right * moveHorizontal).normalized;
Vector2 targetVelocity = movement * playerMoveSpd;
Vector2 velocity = rb.linearVelocity;
velocity.x = targetVelocity.x;
rb.linearVelocity = velocity;
}
}
i put the code in the video but alright
yeah that's not an adequate way to share code
idk what jetbrains is, i closed the project, and when i reopened it was there, im lowkey confused
it's the company that makes a lot of ides like rider, intellij, webstorm, clion
not sure why it's there tho
¯_(ツ)_/¯
ide (Code Editor) probably thought you were trying to use a class from it
it does that sometimes
silly VS, whimsy little guy
perhaps try setting interpolation
i know what an ide is 😭
just being explicit, some dont 😛 it is code beginner after all
You might want to give this some easing / interpolation if you want a smooth sprint
true lmao, im learning c# from the microsoft thingy, but also trying to apply stuff i learn along the way
ill try it out and report back 
after like an hour of figuring it out
also does turning Interpolation on rigidbody itself help a little ?
still teleportin </3
something like Mathf.MoveTowards can possibly help smoothing those values
i really dont know if i efficiently set up the movement, as im basing this off of a piece of code for 3d movement i studied
looks okay to me..btw you can also do
rb.linearVelocityX = for 2d rigidbodies https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Rigidbody2D-linearVelocityX.html

Okay, trigger is just a random name then, got it. I still don't get out though? Not something I've come across until now
dang 🦥
I find documentation so hard to read
probably should make an effort to get used to it considering reading docs is like 90% of programming
It becomes kind of an endless dive because every page uses other words that I also don't know
the microsoft one is surprisingly good
Or just lays it all out in a very technical way so it read like jargon
TLDR Simplified af
Functions return a value. They cannot return 2
you can use out as a way to get extra return values from the function
sounds ok