#π»βcode-beginner
1 messages Β· Page 427 of 1
oh my god , im dumb mb , now the error doesnt show up but the weapon gets destroyed
Well yeah. You call destroy on it immediately
Simply... don't
If you want to destroy the PREVIOUSLY held item, call destroy BEFORE instantiating and setting the new one
good lord , thank you man that worked perfectly
love you bro
can anyone help me via dm hjaving trouble w my project
now DoTween gives me warnings since im using it for my weapon rotation but it stops when i have a new weapon in hand but just in case how can i get rid of the warning
Most people won't commit to go into DMs and trying to answer a question they know nothing about, especially when they don't even know the scope or focus of the question. It's detrimental for all parties involved - the asker ends up with fewer eyeballs on the question and possibly with someone who can't solve their problem, or may lead them astray, and the answerer has no idea what they're getting into or what they're committing to. See also
you're destroying a transform while its still tweening it seems
what the gyatt
yep , tried checking if the gameobject exists and if the transform exists but it still appears
aint no way you used gyatt unironically
well because you're destroying it while the tweening is happening already
you would have to stop the tween itself first
lol
You probably don't want to be moderated at this stage of your learning, so I recommend taking a minute to go do something else and be careful when coming back
you'll quickly be banned or blocked by most people here if you just troll. If you cant read then start learning to
you can stop a tween? how??
https://stackoverflow.com/questions/37214649/how-to-kill-current-running-dotween-sequence-in-unity3d
Of course you can. A tween library would be useless without that ability.
"How" depends on the library of course
Nav linked the way for DOTween
okay my problem is my getkey command isnt working it does nothing
isn't working ? what does that mean?
well im following a tutorial to get fimilar with unity and c# and just followed what the guy did and im having issues i feel maybe because the vid was 7 years ago
what kind of issues? thats vague
No, there are no changes in the last 7 years that would cause any issues like that
what is supposed to happen vs what is happening instead
You should maybe... show the code...
& link tutorial too
you've added debug lines already right?
ah im trying to move my object to the right using getkey D but it isnt working is hard to explain am noob
idk im just following the guy idk why it shoould be any different
show tutorial. sounds like its a bad one lol
link to the tutorial
In this video we learn to control our player!
β Download scripts, assets and project files for this course: http://devassets.com/assets/how-to-make-a-video-game/
β Developer Forum: http://forum.brackeys.com/
Difficulty of lesson: Novice.
Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
This video is part ...
its a8 min video
Ah brackeys. Of course
https://gdl.space/wusawutigi.cs does someone know why my character isnt moving? is something wrong with the code? or is it external ?
what a surprise
oof - I didn't realize he was the source of some of that confusion π
womp womp rookie mistake?
oh mygod he doesnt even use KeyCode
lmao
was it not available back then ? or just typical bad brackys
i just need help figuring it out
dont follow this tutorial is bad
Time.deltaTime in Force while in fixedupdate is horrid
What's getting logged there?
if you want to learn unity properly start wiht !learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
vector zero
Verified that lowercase d SHOULD work. Add some debugs as suggested
oh and also when i put my foward force to 200 so my cube rolls foward it doesnt do anything unless i put it aobve 300
i have it registered, or atleast so it seems
hard to explain for me
Stop using YouTube (especially Brackeys or Code Monkey or Dave). Start a new project and follow !learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
thats because you should not have TIme.deltaTime on addforce
thats why the numbers are ridiculously high
but if the cube is flipping you probably forgot to lock the rotation
yeah but i dont get why it isnt working the same as his?
no i did
Even when you apply the appropriate input? It sounds like that input action might be misconfigured... Maybe share a screenshot of the inspector for this script, and one of the configuration for the action?
Because of some other issue. Start over with a proper tutorial
so how should i write it then
you just dont add them
maybe its just a rookie mistake, but i did a movement system like 3 hours ago and it worked
Without deltaTime, as you were told
But seriously, you keep ignoring this so I will keep saying it. Start over with a decent tutorial (like the one you were linked to)
Oh geez. No, without the * Time either
no i know i just removed it
i cant because im learning this for someone and they want me to follow this
Tell them that you don't want to learn from trash
And would rather learn properly
i mean i alridy put 5 hours into this id hate to js quit
Because doing it this way will take far longer
Sunk cost fallacy
tried everything there and still nth
You will not lose your knowledge. And 5 hours is a tiny tiny tiny fraction of the time it will take for anything worthwhile
some times is best to start over , you will go faster with something better
you could store the sequence then Kill it in OnDestoy method
Yeah that all seems fine to me, at a glance. Perhaps the Player action map is not enabled? I think there's a debugger for this π€
the unity tutorials on their page are actually goated
i mean ill wait since hes more fimilar then me with c# and unity and see what he says
If he recommended that tutorial, he is not very familiar with either πΈ
No offense
Or maybe he just didn't look at it before suggesting it. Might have been first google result
im following one on IA navigation and the girl that explains it start from things as basic as what a normalized vector is and how it is calculated
he didnt look at it he just told me to follow it
how could i enable it in that case?
lol
Ah makes sense. That is messed up of him
in my game, i have a powerup that the player can collide with in order to gain. how can i sense the collision with the player, without the player momentarily being slowed down/stopped while the two collide?
i dont know if you want this but making it a trigger?
again, im lacking context but pretty sure thats what you want
how do i implement that instead of oncollideenter?
thank you! :)
if they told you to jump off a cliff, would you do it?
Well the issue is not with the code shown, other than the deltaTime issue we mentioned. So you would need to provide more information. Share ALL the code (not with screenshots)
!code
Show the inspector of the object with that script attached
π Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
im not familiar with unity im learning myself so obvi what do ik
so put Sequence mySequence = DoTween.Sequence() at the top of the RotateWeapon() method then kill the sequence OnDestroy method?
You can check Window > Analysis > Input Debugger. If the input actions are active, they'll be listed under Actions there while in play mode
oops
Rotation is NOT frozen, but you said it was
somelike that or the tween its been a while since i used dotween
I also do not see the script
On the rigidbody
yes but now you're somewhere with more experienced devs suggesting you use the Unity learn site instead to learn π
constraints..
they dont
Really?
do i check all the boxes?
Except y
didjn tknow it meant that
didnt
lol
its literllymnot moving
We said "freeze rotation" and that is the only place those words are shown in that screenshot
UN TOLD ME TOOO
Okay cool. You could enable the specific action with
movementReference.action.Enable();
if necessary. Enabling the whole action map varies depending on how your Input System is configured, but if you're using the global workflow, it'd be like... uhh...
misclicke
okay i just had to put DOTween.Kill(transform) in OnDestroy() method and it fixed the problem lol
nicee
Show the code as I said
when i set my foward force to 200 it never moves
i did
10/10 profile description
also i wanna hear ur thoughts , what if chargeable bow that deals damage based on how long you held ur charge button or smth like that
You sent a screenshot of some of the code, which I EXPLICITLY said not to do
thanks bro
And it had a syntax error that you SAID you removed, but apparantly did not
yea what about it ?
on start void right?
i wanna hear ur thoughts tbh
Yeah that'd make sense
Yeah that sounds pretty cool, should be easy to amke
are you trolling ?
Do
Not
Send
Screenshots
i dont know why now i need to do it tho, literally have the last player controller that i had on my other screen and it didnt need to be activated
!screenshots
No
Be mindful, if someone requests your code as text, don't send a screenshot!
No, absolutely not
if you aren't willing to properly help yourself to get helped, you're just gonna get a mod on you
what you mean
I think enabling the whole action map with the global workflow would be like
InputSystem.actions.FindActionMap("Player").Enable();
... I think. I'm not great with the Input System. I'd refer you to #π±οΈβinput-system for better information π
this is a waste of everyones time. Put some effort
also since i alr have a WeaponShooting script that handles all the weapon shooting stuff , if i wanna make the chargeable bow , do i replace the WeaponShooting with the new BowShooting script and then reference the WeaponShooting in the BowShooting script?
no im confused idk what he means
π Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
ty!
Look at "large code blocks"
kk
And also ffs remove the syntax error you said you took out
On line 16
Also remove deltaTime from line 20
how does that work i copy n past my code into whjat u sent me
ok
copy. paste, save and send link.
its not complex
ok
anyone know abt this ?
Yeah, I thought all action maps were enabled by default - at least in the global workflow. I'd be curious to hear if you glean any insights into why yours isn't π
are you willing to waste my time on purpose?
copy the link and send it in here
cause ill jst get mod on you
oh okay
Do that BEFORE SENDING THE CODE of course
why are you sending code with synax errors

How can you say ik and still send it
are you 12 ? what is happening
whaty ou emkan by remove delta time though
Send the most current code including all changes you have been told to
idk what you mean*
Select the words and press backspace......
the * Time.
navarone could you perchance know smth abt this?
You really really need to go back to a basic c# course before even doing the unity course we sent
https://www.w3schools.com/cs/index.php
And then
https://learn.unity.com/pathways
alr im just followeing the tut
is this fine
ill send link
No of course that is not fine
Do you see the red underline?!
if the weapon functions differently just keep it simple and make your own script for it
error mb
I think I am going to have to block you and leave. I wish you the best lano
and just copy these in the BowShooting script since i need them
you're going to have to pay attention to what you do if you plan on doing any games
dont do something without knowing why you are doing it
i know
im just annoyed why it isnt working like the tut is telling me
well we told you its a bad tutorial
okay but how if it works fine for him?
again its wrong
prove to me that now it doesn't work with this new code
and lower the speed
wheres the error smh
what error ? there is no error anymore..
inb4 "what speed"?
How would i go about checking if a function has been just called for an if statement in another script
Nah actually, inb4 "it is so fast"
Because ignoring 90% of what we say seems the norm here
A bool or event either flipped or invoked in the called method (respectively)
i ran it and my foward force is crazy high even if its still at 200
idk what i did jow
now
where is the part where you shoot? thats mainly the only part that can change or just add that as an options for other weapons too, maybea bool
Called it
yes i told you its too high
what should i change it to then
what do you think..
its trial and error, not that difficult
okay
its this pretty much and in Update i just check if i press left mouse button then call Shoot
so just add an option for a chargable shot
its still crazy fast
like add a bool as an arg to the Shoot method?
200 was slow before because of Time.deltaTime
which was wrong
ohhhhhhhhhhhhhhhhhh
Physics objects already move on their fixed Update
this can work maybe
yeah..isChargeable or sum
you would have to design the whole shoot method again though
to compensate for "charge time" and whatnot (timer)
I restarted it because it arrived after 15 minutes, it gets stuck there, why doesn't it load?
dont change it in the code if its exposed in the inspector, the inspector takes precedence
thats why we have Serialized in the inspector so they can be adjusted, also while playing to figure out th eproper numbers
not really a code question at all
so leave it as 2000 how it sbeen forall this time or change
cant i just wrap the Shoot code into smth like this
private void Shoot(bool isChargeable)
{
if (!isChargeable)
{
normal shoot code
}
else
{
chargeable shoot code
}
}```
Like I just said.. if its exposed in the inspector what you change in code is irrelevant since it already serialized with whatever number
It has to be changed in the inspector in that case
something like that, the bool can also just be a field
yep but i think using it as an arg feels more clean for some reason
ig depends where you are storing that info
also i dont want the other guns to be able to charge so how can i check if its the bow ?
well you gotta store it somewhere lol
navarone my getkey command isnt working
my problem is i have a function that it is essentially i have the function im trying to check has a string name (example 1) and in the if statement im trying to actually check for a specific string name (Example 2)
public void Function(string name)
if (script.instance.Function("nameofthing"))
how would you go about it?
can u see if theres a problem
i forgot abt this heheheheheheheh
try if (Input.GetKey(KeyCode.D))
can just simply check WeaponSO.name == 'Bow'
I meant the bool
but yeah that works
yippie
I would set a variable and check that variable
Or actually return something function
except you use " not '
time to stay all night working on this
' is for chars
i used ' cuz i wrapped the message in "
iput deltatime because i wanteds the force value i put in to represent the force per second
this isn't javascript lol
AddForce already is
you dont even know what it does, what kinda logic is that..
also the getkode didnt work
no no i meant like it doesnt let me use "when "the message is already between brackets" so yeah"
its not moving at all
show the updated code
send it the proper way as shown to you earlier
ohh == "idk"
lol
wtf
how does it let you
so is it moving forward ?
oh wait "im stupid"
when i press d i want it to move right
thought `` was the same as "
and so forth yk what im trying to do
oh haha
I get it mate..
i know what ur trying to do
I asked you if its moving forward
ok can you show the inspector for the object
Does the x value in the transform component ever change?
Also, don't acquire input in the fixed update method
this might be part of it too ^
Acquire it in Update as some bool and use the bool in fixed update
though since its GetKey and not KeyDown it should work fine
since it doesn't apply the force till fixedupdate frame anyway
whats transform
Ideally, yes - relative to key held
So the object does move
Are you perhaps moving the floor as well?
nope
Forward in the standard position would be the z axis - I'm assuming your object's forward is in the standard position.
if it moved its working
You mean "not working"?
Put a log and see if it prints
yeha not lol
kk
can u type it
so i can copy n paste
or do it to my getkey statement
wdym put a log
Look at the message right before yours.....
i did
AND click the link?
ok i will do that
If you do that, you should absolutely know what a log is
Oh my god, you actually didn't? I was joking by suggesting you click it. I assumed you would have tried that already
Spoonfeeding, on sympathy for their early juncture in the learning experience.
It prints a message to the console. So if you put it in your if statement's body and it logs a message, you know that execution has reached the statement body, and thus that the condition was true:
if (Input.GetKey(KeyCode.D))
{
Debug.Log("D key was down during FixedUpdate");
rb.AddForce(500, 0, 0);
}
yeah ik that but i js didnt know where u guys weanted me to writ it lol
For perhaps the fifth time, you need to IMMEDIATELY stop what you are doing
You need to do some very very basic courses (preferably not on youtube). This is quite ridiculous
They showed you exactly what to write and where....
You could literally copy paste that. You need to put in at least 1% effort here
I just wanted to see if the code was executing.
i did
copy n paste
!screenshots
No
Be mindful, if someone requests your code as text, don't send a screenshot!
Check your console logs
How many times have you been told no screenshots
They asked you to show the console
I'm assuming you aren't aware of what the console window is
then why did you how this
becuase i ran it first
Show the whole thing, not cropped
you hit clear?
i belive he has
ohits collapsed ofc
ya
gg
Errors are hidden
lul
whatt
amazing , how did you manage to do that
Click the red icon
click the stop sign icon
yu've gotten ur errors disabled
I only want warnings no errors π
ima laugh if its still broken from * Time.
It's a miracle you guys are even helping still
Just for the sixth time, but in a different way. You would probably be FURTHER in your project if you had restarted and followed the guide I linked when I first sent it
i just peeked in
yeah my patience ran out lol off to cook some bok choy. goodluck guys
alright whatever ill just dropp unity isnt for me lol to confusing
I suspect you pasted what I wrote into the class body, instead of adding the Debug.Log to your existing if statement in the FixedUpdate() method.
But yeah, if you do want to pick up a higher quality tutorial, the Junior Programmer Pathway on Unity Learn is a good start
its confusing because you're jumping int he middle of the book instead of starting from the beginning..
how would you follow a movie from the middle of the story or beginning ?
You need to fix the errors
C# is new to me im only familiar with python π€£
I too would give up building a rocket ship if I never learned advanced physics.
You're ignoring all advice to go do the basics, of course you wont be able to make a game
start with the pathways and you will pick it up withina year
Even if you were familiar with python, some skills would translate. But you dont even seem to be aware what debugging is. Start from the absolute beginning
eh its a bit diff for me
little
just reminder. link again .https://learn.unity.com/pathways
I started with python and moved to c#
You know how I did that? It wasn't by jumping into an intermediate tutorial and demanding help on every sub-step and issue along the way.
I took basics courses.
Unity is one of the simpler game engines. If you are giving up on it as too confusing, don't think anything else is going to be LESS confusing.
You need to actually try. Trying means doing the basics, which Nav just linked (which is what, the eighth time it was linked?).
But if you wanna stick with python and use a slightly more confusing engine, check out pygame
yeah im only doing this because i was put on to learn wich i am going to be creating a demo for someone and obv im getting run trhough it all i needed to do was copy exactly what brackeys did but apperantly it doesnt even work
I did go through that tutorial (after you linked it) and it worked for me. You did something else wrong
But it is too hard to even find out what because it is like nails on a chalkboard trying to get any info from you
I did remove the deltaTime and fix the force, but it did work before that too
are yopu at getkey part ?
you at
I finished it
brackeys tutorials are shit but they do work for the purpose of the demonstrations. His video wouldnt be popular if they were filled with actual compile errors
I did the same tutorial years ago, you really just arent copying properly
I did remove the deltaTime and fix the force, but it did work before that too
I made that change at like three quarters of the way through because I just couldn't handle that haha
his tower defense tutorial I thought was pretty cool
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
π€·ββοΈ consider that you also refused to read the initial messages any of us sent (which is why i stepped away from helping). Its doubtful that you're even looking at the tutorial properly. its clear you're trying to copy as fast as you can, in which case youve taken a 1 hour process and turned it into a several hour struggle
Roadwarden hit me really hard. I had a minor bout of delirium when I learned it was built on pygame π
if you insist on youtube vids, go find Sebastion Lague's
Sebastian is a bit too advanced for them imo. ("A bit" being QUITE generous)
i did u guys werent be specific enough for me to understand lol
You are required to put effor in on your own (see #854851968446365696 )
fair enough, but he does good clean code
do you really expect me to believe this lol
We try not to spoonfeed
i only just pciked up c# since the morning
Clean code by itself is more advance then they are at this point haha.
I always say just write crap until you get why you shouldn't
debatable
Dabba table!
(β―Β°β‘Β°)β―οΈ΅ β»ββ»
debebtababble
debabby
can anyone tell me why this method isn't properly using float RaycastDistance or stopping when it should stop?
case KeyCode.W:
Vector2 RaycastDirection = transform.rotation * Vector2.up;
RaycastHit2D forward = Physics2D.Raycast(transform.position, RaycastDirection, RaycastDistance, BulletMask);
Debug.DrawRay(transform.position, RaycastDirection, Color.green, RaycastDistance);
MoveCheck(forward, PlayerRB, Speed, true);
break;
///
private void MoveCheck(RaycastHit2D hit, Rigidbody2D PlayerRB, int Speed, bool Forward)
{
if(Forward == true && (hit.collider == null))
{
PlayerRB.AddRelativeForce(Vector3.up * Speed);
}
if(Forward == false && (hit.collider == null))
{
PlayerRB.AddRelativeForce(Vector3.down * Speed);
}
}
I don't think your debug ray is correct. Check the de oca page
sorry?
That parameter is duration (in time), not distance
btw RaycastDirection * RaycastDistance for drawray
In drawray
Someone mentinoed that Debug.log had something to do with varargs, can someone explain what this means?
got it
I don't think Debug.Log uses variadic arguments?
I have no idea what they mean either
Debug.DrawRay(transform.position, RaycastDirection * RaycastDistance, Color.green, RaycastDistance); ?
last one is duration
What you call distance is still the time it lasts
https://docs.unity3d.com/ScriptReference/Debug.DrawRay.html
The original question was why debug.log has an overloaded parameter that allows you to pass in inf amount of parameters
which I have no clue of
This would work, but the last argument is not distance
do note Draw Ray will NOT stop at walls
then how do i set it's distance?
You already did with the multiplication
You already did here. Please read the docs.
Direction (a vector3) has a magnitude
Does it?
I'm pretty confident that that overload does not exist - at least in modern Unity. It's not in the docs or the intellisense hints π
I don't see one
I see one that takes a string, and one that takes a string and gameobject
https://docs.unity3d.com/ScriptReference/Debug.Log.html
yes
im very new to unity and i just followed a tutorial completely with the entire game working, but when i go to build the game and run it, it just loads an older version and doesnt work properly? does anyone know any common fixes? let me know if theres any extra info i can provide.
press save in your code editor
i saved the game before building and it didnt change
- Make sure the build doesn't fail. That there are no errors on the console after the build
make a clean build
welp, i understand the raycasts a bit better, but it's still moving when it shouldn't be.. hmm
3 seconds for a build sounds sus
its a very simple game
did you make sure you did a Clean Build?
whats that? like make a blank game and build it?
- Make sure that the scene that you work on is included and loaded first.
like in the top left here?
no idea why it won't stop moving. any ideas?
is that the correct scene you're working now ?
Can you share the code with a paste site? Pretty hard to read.
i only have one scene so yeah i think
curious but try a Clean Build from here
how do i exclude certain gameobjects to be found by findobjectsoftype. im searching for cameras but i want it to ignore itself
ok got it
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
reference the Camera component on the current gameobject and remove it from the array into a list
just an example, but there is probably a better way
[SerializeField] Camera currentCam;
var cameras = FindObjectsOfType<Camera>().ToList();
cameras.Remove(currentCam);```
same output but longer build time
what exactly is wrong on the build?
in comparison to editor
it wont detect any input, and i changed the background color to test if it is the same in both versions but it is still the old color
i have code that when i click or press space it should fly which works in the editor, like in flappy bird, but in the build it just doesn't move
So, what we said about DrawRay does NOT apply to Raycast. You have a duration in there, but raycast takes no duration
You need to change that back to how it was before
ah, on it
is there any way to screen record? would that help?
yes use OBS or ShareX or Windows + G
this still doesn't really fix my issue though? the drawrays aren't the problem here
The raycast might be though. And that was just something I saw, not a solution
ah, okay
What should it be hitting? And what layer is that thing on? Does the layermask INCLUDE that layer
Masks are for what it SHOULD hit
the mask is inverted, though
Ah, so anything that is NOT the player? But it is not registering any of that
it should just be colliding with walls, really. so obstacles. i could uninvert the mask and set it to obstacles
Just to be absolutely certain, what's your Physics2D.Raycast() call look like now?
I would first of all put in a debug.log including the name of what it should hit
RaycastHit2D forward = Physics2D.Raycast(transform.position, RaycastDirection, RaycastDistance, BulletMask);
Personally, I would just make a LayerMask variable and set the layers in the inspector by hand
yep, doing that now to see if it helps
oh it didnt capture the other part hold on one sec
yep, fixing the mask seems to have fixed it. thanks!
well I can already see whats wrong anyway
oh sweet
remember when we asked if you're exporting the correct scene?
yea
notice something?
oh is it because i changed the name?
did you duplicate it then rename it?
or save As
yes
i saved as im fairly sure
or you can drag n drop
when you do that(SaveAs) it created a new Scene asset
so you just never added it to the build but instead the old one is still there
i really appreciate it. ill try to keep this in mind next time lmao
fellas im trying to draw a boxcast for something and im a very beginner to boxcasts entirley, (2d game) and it would be nice to have some help of how to write them and especially how to know where they are/ if ive done it correctly... is there a way to see them ingame?
You can use gizmos to draw a cube or a wire cube at the hit point.
https://docs.unity3d.com/ScriptReference/Gizmos.DrawCube.html
is there like a public function i can copypaste for debugging purposes, i really dont want to have to learn how to draw things just to start on my goal lol
Might be if you Google or look on GitHub. This is not something complicated, so most people would write it themselves.
but im dumb π
That's just a lazy excuse. !learn properly and you'll figure it out.
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
If you stumble on an issue while learning feel free to ask the community. But don't ask people to provide you a complete and ready solution. Show some effort.
no i srsly do plan on learning stuff like this i just wanted to learn boxcasts today and this would make it wayyyy easier and i didnt wanna go on a detour ykyk
Well, then consider drawing gizmos as part of learning about box casts. Then it's fine, is it not?
It will look so if you miss some more basic understanding, that you'll need for the boxcast as well. So maybe step back and start with the basics first.
ive just avoided most things gui cuz it looks like a completley different language
probably not the best thing but i'd rather get the fundamentals of the rest done first
Don't know what you skipped, but you should probably not do that if you're following a structured course/pathway/tutorial.
no im mostly just making whatever i feel like and learning along the way
Probably not a great approach for you. If you do it like that, you should be ready to research new topics when they're thrown at you and not complain about it being too difficult or beg for a complete solution.
If you can't do that, better follow a structured learning course.
dude omg i know stop backseating my aproach lmao
i thought "ok i wanna learn how to detect when onground, so ill learn boxcasts" and i can bearly wrap my head around that i just didnt want to take a massive detour in the middle of it
Even simple things like ground detection can be pretty complex if you are missing some of prerequisite knowledge. There are many ways to detect ground and box casting is one of them.
If you really want to learn about casts then maybe start with a Raycast, as it's easier to visualize and understand in general. A box cast is just a more sophisticated raycast.
A raycastyou can visualize with Debug.DrawRay
i guess
Personally if I'm just looking for an easy check I'll just use a debug.log along with a message (you can even print out the item(s) you hit). Then if I'm not getting what I'm expecting back I'll dive deeper into drawing the gizmos. There is an add-on on the unity store which adds a few more easy to use debug.draw extensions, which you may find easier than gizmos (though gizmos are not hard at all, trust. Can be intimidating) https://assetstore.unity.com/packages/tools/debug-drawing-extension-11396#reviews
thanks :)
i knew i would be working with VERY small box casts so if there was a small mistake i made it'd be very hard to tell
which, by the way, how would i detect when the player is ON the ground, cuz say the box cast was on like a pixel down, you'd be able to jump higher if you jump exactly as you land right?
maybe i should just use a collision detector for ground detection and use my new found "knolege" of boxcasts for other stuff (i would assume it also transfers to raycasts atleast a bit)
That depends on the size of your boxcast, so not necessarily.
Yeah there's a few ways to do it. Could certainly use OnCollosionEnter, boxcast is probably the way I'd go but you could also have a child object with your box collider on it, position where you want, set it to trigger and create a new script that uses OnTriggerEnter to detect the ground. And in this case you'd be able to easily see the ground detect box in editor because it's just a box collider component. This video explains this (and boxcast) method better. Trigger method is at the end https://youtu.be/c3iEl5AwUF8?si=0tz5SPYcLn49Krms
β
Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=c3iEl5AwUF8
Let's look at 3 different methods for doing a Ground Check which is a necessity if you're making a Platformer.
If you have any questions post them in the comments and I'll do my best to answer them.
π Subscribe for more Unity Tutorials https://www.yout...
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
β’ Visual Studio (Installed via Unity Hub)
β’ Visual Studio (Installed manually)
β’ VS Code
β’ JetBrains Rider
β’ Other/None
Probably a very basic question, do static bools act like switches you can flip from other classes? I'm thinking about hugely simplifying 90% of my code using it
Static bools sounds like a terrible idea
Oh?
In general, if you you're thinking of static fields it's usually a bad idea.
There are some exceptions.
If you're a beginner thinking of static fields, 99% it's a bad idea. Especially if it's to "simplify code"
Simplifying the code that way is gonna make everything else subtly harder and harder over time until you gridlock. At least that was my experience when I had the same idea years ago haha
It would let me change this into this
And allow me to access functions that loop once per frame, which is far more useful than I imagined
Coroutines are fine and making an event for it is ok but having it in Update is so much nicer
It you really need to, you could use singletons, although it's not a great idea to use them lightly as well. Still better than a public static field.
Why exactly shouldn't I use them?
It's a bad habit. If you start using them as a beginner, you'll keep on using them in a more complex project which would bring a lot of issues. But you wouldn't know the proper way of doing it.
Imagine you have more than one character with skills in a game for example.
I got an error on my code while trying to do something, could someone help me figure out how to fix it
Mm good point, the game I'm writing code for currently has multiple creatures that can use a skill which is giving me enough problems anyway
Can't help without knowing the error or seeing the code of course
I have this error in my console
Ok, show that code
Someone did just fill me in on a little thing called creature.HasSkill(""); which will be far better anyway
TowersInGame containing null?
how is it containing null?
That does not show any value getting added
this is the only other place its referencesd
Yes, so GetComponent likely returned null
how do I prevent it from turning null?
Make sure it has the component you are querying
I think it does, how can I make sure
Logging, breakpoint, whatever way you can debug
I might have fixed this but I got another error
I think I just forgot to put the script on the prefab, only the tower originally
Did you try to check if it is null? (And accidentally write = instead of == ?)
And got that error?
i think it was trying to get me to fix this line because I removed it because for some reason it causes an error with enemy spawning
when I remove it enemies spawn but it returns the original error I had above
The line numbers are cropped out here
Oh, and the script is the wrong one. The error is line 24 of TowerTargeting
here is tower targeting line 24
what do you mean
Line 37 of GameLoopManager
whats wrong with it? I'm pretty new to unity api so I dont see the problems very easily
You are creating NodeDistances based on NodeDistances.Length ?
I'm just confused. You are making a new float array that is one shorter than the previous?
But also, it is likely emptied at that point? I would need to test. Not sure looks like that is the point
Ahhh, yes that does make more sense
so should I change it to NodePositions = new float[NodePositions.Length+1];
Why +1 now? And shouldn't it be NodeDistances = NodePositions (you changed both sides)
misclick sorry
Do you know how NativeArray works? Bit confusing that a beginner is using it
not really, I usually look at others peoples code until I understand the arguments and can write it myself, thats how I learned C# modding, but I havent used it much in unity context so its still confusing to me
They spawn now, but I get this error when I put down a tower
Are you using ECS or Jobs?
jobs
Probably shouldn't have a +1 OR -1 in that part we mentioned earlier
okay
Ok, that explains it then
why
Well nativeArrays only really make sense in the two contexts I mentioned (and other custom reasons, but not just general unity usage)
Unmanaged code vs managed code
when I removed the one I got
Your loop iterates until i == NodeDistances.Length - 1, but inside the loop you're accessing NodePositions[i + 1], which will be the element after the last element in the array on the final iteration
How can I fix that?
Presumably, stop your iteration at NodeDistances.Length - 2 - since you need two points to calculate a distance, you will have one less distance than you have points. But the solution may vary - I don't really follow what's going on in this code π
Like maybe you need an equal number of distances and the final one should instead be the distance between the first and last point
I changed it to 2 and got this
What's happening around that line?
which line
original - 1 is fine
You'd want distance between nodes then it is natural to have one less element
The line responsible for the error - TowerTargeting.cs:67
But apply the fix cathei mentions and see if the error persists, first. Add the - 1 back to the NodeDistances initializer
how could i make a variable that changes depending on what iteration i am inside a for loop, between certain numbers that i want, and how can i calculate how to rotate an object depending on what direction the objective if respecting the position? (further context in photos)
srry for the bad explanation but idk other way of telling what the problem is
i want to make a triple missile that goes towards the player, how do i get the degrees i need to set it for?
ive been thinking about switch case but i still dont know how to calculate the 3 directions i need
Apparently EnemiesToCalculate is an empty array and EnemyToIndex[0] is -1 π€·
is that bad
Hey, is there a shortcut for this:
DamageText.transform.position = new Vector3(DamageText.transform.position.x, DamageText.transform.position.y + speed*Time.deltaTime, DamageText.transform.position.z);
It's what the runtime is complaining about, so yes. Accessing any index of a 0-length array will throw an error, as will attempting to access the index -1 on any array
oh found this:
transform.position = transform.position + new Vector3(horizontalInput * movementSpeed * Time.deltaTime, verticalInput * movementSpeed * Time.deltaTime, 0);
To Answer my question:
DamageText.transform.position += new Vector3(0, 1, 0);
what should I do with it
DamageText.transform.position += Vector3.up * speed * Time.deltaTime;
That looks good, I will try that π
I assume Vector3.up is same as Vector3(0, 1, 0);
I guess you might return null early if EnemiesToCalculate is empty. That may or may not address the other issue with EnemiesToIndex[0] being -1 - I don't know how that's calculated
Anyone else having trouble getting into learn.microsoft.com ?
Seems fine from Colorado
Subtracting the launcher's position from the target's position will give you a vector which describes the distance and direction to the target. You can apply the rotation described with a quaternion to a vector by multiplying the quaternion with the vector - so if I did something like
Vector3 direction = Quaternion.Euler(0f, 30f, 0f) * directionToTarget;
now direction is 30 degrees offset from pointing at the target on the y axis.
You might store different rotations (maybe quaternions, maybe just floats for one axis) in a list or an array, and loop through it to produce directions for each projectile
!docs
hello all, can someone tell me how something like this is possible? i am stumped (sorry if this is a stupid question with a stupid answer it is midnight currently)
the string is not changed at all, the first screenshot is taken while the game is running
You might have multiple instances of this component within your scene, and one or more may be missing that value. You can search your hierarchy for t:MyComponent to find all game objects with the component to double check.
Or alternately, supply that Debug.Log() with gameObject as the second argument and the error will link to the GO responsible for the message
i did this to solve it:
https://gdl.space/jarazesupe.cs
but now the last one is the one that is exactly on the player and not the one in the middle
help request
I have searched long and far for a working method to do a very simple action.
I have a 3D project with a camera for a player. All I want to do is for it to rotate right when you press the right arrow, and vise versa for the left. I want to be able to control the speed of this, as well.
I do not want acceleration or deceleration, which all the examples i've seen do.
Something similar to DOOM (1993) camera movement
i think its because they are on radians which would make sense
do you want the player to rotate with it or?
Nice!
Yeah I'm trying to wrap my head around that - the angle's in radians but Quaternion.Euler() takes degrees
But what you might do is iterate from -1 to 1 instead of 0 to 2, and adjust the math accordingly. That way the middle missile will have an i of 0 that can be used to cancel out the adjustment
The camera is a part of the player object. the player is transparent, so I don't care if it visually rotates.
thats kind off what im trying, since im substracting 5 from the starting point 1 is equal to -1, 2 to 0 and 3 to +1
now im trying to change it to degrees instead of radians
btw love the pfp
Too be more clear: I want to be able to rotate this player/camera side to side a la DOOM (1993) with the arrow keys, without acceleration or de acceleration.
This is a code channel, we expect you to share the code you have. We do not do handouts
I have nothing that works remotely, so showing anything I think would be irrelevant. All I ask is what functions or strategies to get this working.
I'll work up something quick to have as reference.
Well firstly you need code to recognise the key down then you will need something like
https://docs.unity3d.com/ScriptReference/Transform.Rotate.html
This is effectively what I want to happen, but getting it to do so has proven difficult
look at the link i posted
Okay, this looks like it's working, but would it stay stable at different framerates? Not a huge problem, but it'd be nice to know
multiply your cameraspeed by deltatime
how can i calculate the rotation i need to give in the z axis to an object at the time of instantiating it, taking into acount that it should go to the direction of the "player" originating from the "enemy"(gameobject instantiating the "bullet")
ive tried a lot of weird math and i cant make it happen
2d
ah
!code
π Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
what i did was just
that is the code for rotating it
why not
wait
it is
its currently 09:45 am and i havent slept srry if i dont grab things in an instant
sleep depravation hitting me hard currently
then go to sleep
it is indeed being modified
i woke up at like 8pm
so ive only been awake for 14 hours
just that i get sleepy at this time of the day
lmao
i encourage you to take a nap
i aprecciate it but im to stubborn to leave it uncompleted
you wont leave it uncompleted
youll just complete it
later
in an hour
or smthin
i know what you mean
but i cant leave until i finish this
im to stubborn, ik i should take a rest because it will help me view it from other pov and think laterally but i have that negative trait
take some rest*
so work on the negative trait
i should
ik its worth it
your computer wont run away
lmao
take a nap and pick this up later
aha okay well
i was going to suggetst
transform.up = target.transform.position - transform.position
ohhhh
and make the target equal whatever you want to point at
in my code
target = gameobject.findwithtag("ship")
yeah but my problem is that i want additions,
i want there to be 2 more that are slightly offset
therefore i think i need degrees and/or radians
i dont know how to do this in code as i am very new myself
the way id do it is just make 3 different projectiles, make them all instantiate from one spot
and each one has the same code just offset by -30 or 30
exactly
thats the long way around but i believe theres a better way to do it
thats my thought proccess
so do taht
but i dont know how to write it in code neither
lmao
since it is also in a for loop
why a for loop
because i want to instantiate 3 bullets simultaniously
Get the vector from the enemy to the player
And look up rotating vectors online to get the other 2
so just make the projectile instantiate 3 gameobjects
thats quaternions right?
That's vector calculus
ill search myself no need
another time caesar coming in handy
i am ty
Yeah, that works
Unity directly has methods for rotating vectors, also Vector * Quaternion will rotate it.
You really dont need any trig
but the instantiate method asks for a quaternion
lmao
You can create quaternions from vectors, or you can also just rotate the rotation directly with Quaternion * Quaternion
isn't the multiplication the other way around? at least I thought so
im scared of quaternions
tried to understand them once
was not a pleasing experience
Could be, I always forget the order. Doesnt matter though because one way will have an error so just swap it if so
true
it wouldnt matter since its a multiplication right?
or am i delusional right now?
It's an overloaded operator - it's not actually multiplication. Just a fancy function call dressed up as if it were
for matrices and quaternions the order matters
Math doesnt always follow the rule that AxB = BxA
But this is different anyways that it's just used for rotating the vector
You mean trying to undertand what each of the x, y, z and w component means?
not only that but how it works
You kinda shouldn't, I know neither and I can use Quaternions to my advantage
understandable
For quaternions, you truly dont need to know much. Just know how to construct them from values u are familiar with, euler. Then rotating them with multiplication
so i can just quaternion.euler(x,y,z)?
knowing the multiplication operations and the utility methods provided by unity is all you need in 99.9% of the cases
You can also use Quaternion.FromToRotation, .AngleAxis and such but you basically never need to know what the 4 values individually are. You only need to know it's some 3D rotation that you can visualize in various ways
okay
srry for the ping
Hi !
I develop the system of NPC shop where the player can buy some weapons. Now, I have this UI but I want to highlight what weapon button is selected with changes his opacity compared to the others. The arrows can change what weapon is selected. Someone have some ideas ?
i dont know where i messed up but it doesnt work
The UI :
Quaternion.Euler gives you Quaternion, not Vector3
but the 3rd parameter in an instantiate needs to be a quaternion right?
oh wait my bad
let me see
So bulletDirection is now a direction vector, not rotation/euler angles of any sort. That's why the .z does not translate to any meaningful angle. Usually if you want to get rotation out of direction, you can use Quaternion.LookRotation(direction)
so instead of quaternion.euler i need quaternion.lookRotation(vector3)
btw how do you write in that space?
for example the .z
you put these ` around (you can edit your message to see)
yes, vector3 being the bullet direction
pretty sure it's Vector3's, you don't need to give 2, the other one is set to Vector3.up by default which often works fine
unless you are using the wrong math library or writing shaders
for what i know im not using a math library at all
if you hover over Quaternion you will see which one
unity.mathematics.quaternion
wrong math library
why are you using unity.mathematics at alll?
yeah, that's meant for the burst compiler/dots stuff afaik
i dont know if it has anything to do, but my objective is to make an enemy that shoots like this
one towards the player and 2 slightly offset
idk if that has anything to do with why im using maths
you need to pay more attention to what you are doing. you have obviously mistyped something somewhere and then blindly let the IDE correct it for you without reading what it was doing
your code editor
true
could i know where?
im really frustated right now since i dont understand on can come up with a solution to it
look for the using unity.mathamatics statement and remove it. the ide will then highlight the errors
ot does not highlight any error
then it was only in the one place you have already corrected
oh
you should ALWAYS look at your using statements to see if there are ones that should not be there
okay
i have a question if i may
why is it rotating the x? https://gdl.space/ifohedaquw.cs
you mean here ?
Vector3 bulletDirection = Quaternion.Euler(0f, 0, 30f * i) * direction;
yes
the joys of Quaternion math. Dont try to understand it just accept it works
srry i was doing a micro mental pause to see if i would detox
but it doesnt even work π
i want it to rotate the z axis
yes but quaternion rotations can be expressed in multiple euler rotations and that is what you are seeing
i did not understand the meaning of that
basically im having a skill issue since im not using the correct euler rotation?
basically, if you put Euler angles into a Quaternion and then get Euler angles out 99% of the time they will not be the same but they will represent the same rotation
I'm not sure why you are doing this
Vector3 bulletDirection = Quaternion.Euler(0f, 0, 30f * i) * direction;
as direction is also a Vector3. so calculate the direction first and then convert it to a Quaternion
but the direction should be a vector3 right?
or should it be a degree?
because ive tried that and it did not work
neither with radian
probably because i did it wrong tho
did you check if the direction itself is an issue? or does the projectile even rely on its starting rotation?
rely?
rely is a word
depend on with full trust or confidence.
you instantiate the fireball with a starting position and rotation, but does the fireball even use its rotation to move? Is there an actual issue with the direction of it moving?
because u shouldnt read the values from inspector to see its euler angles, due to what steve said
yes
it doesnt go on the direction
mainly because i havent made the movement yet
but if i move it across the new y axis
it doesnt match with the direction the player is at
i dont really know what you mean by most of that. I would just look at the forward direction of these fireballs and see if they're oriented how you want. If not, then try to describe your issue based on that
You realize you just asked if the forward is up
the forward is forward
i think it was
i might just be talking nonsense at this point
can I suggest you take some time with a pencil and paper and actually learn this stuff so you know not just think because otherwise you are in for a world of pain
you can ofcourse
but for what i recall learning the forward direction was along the z axis in 3d
it is and you can read them all here https://docs.unity3d.com/ScriptReference/Vector3.html listed under static properties
maybe in 2d it works in other way which would make sense and i should look into that 100%, but thats why it seemed odd to me and thought about it being the transform up
did you ever get an answer to this, i have the same issue currently
store the string value, and then pass it to the next scene
well yes but how do i do that, my script currently does not want to access other scenes things to be able to pass it
oh thats really helpful, thank you
first port of call is google
i mean i know its just a google search but i searched similar things and found not much useful other than a niche case scenario that didnt work for me
How do I get to Left, Top, Right and Bottom on a RectTransform component in code?
if the assets database doesnt work on builds then how do i assign a different audio clip to the audio source component
if you mean loading an unreferenced clip use Resources.Load
How do i lerp one value to another?
Thank you!
these things are in the pinned messages, always worth checking there first before asking
Ohh i see it now
I'm creating a procedural animation system and am trying to limit the rotation between segments to a rigidity variable, so if the segment after the one being checked creates too sharp of an angle its supposed to bring the position of the next segment back in line but it kinda just freaks out making me think there's either an issue with the math (probably the cross product being negative or positive) but I have no clue how to fix it.
this is my code:
Vector3 forwardVector = (segment.position - segment.parentReference.position).normalized;
Vector3 connectionVector = (segment.position - Segments[GetChildSegmentIndices(i)[0]].position).normalized;
float angle = Vector3.Angle(forwardVector, connectionVector);
Vector3 cross = Vector3.Cross(forwardVector, connectionVector);
if (angle < 180 - segment.rigidityAngle)
{
Debug.Log($"Segment {i} is too sharp!");
Quaternion myRotation = Quaternion.AngleAxis(180-segment.rigidityAngle-3, cross);
Vector3 result = myRotation * forwardVector;
Segments[GetChildSegmentIndices(i)[0]].position = segment.position + result;
}
Hello
To save data when we changed scene and save some data like the remaining life of the player or his inventory, is using playerprefs is correct or there is something more optimised to do this ?
ScriptableObjects, PlayerPrefs is not a good idea for this
What would you use ?
A ScriptableObject
Hello
Is there an easy way to make a sliding joint that slowly detaches from a rigid body using gravity?
Okay thanks π
heyoo, ive been doin unity for a lil while now but first time actually tryin to do scripting and such and im wonderering if someone has a script to be able to make a collision detect any mesh thats touching it
ive been able to make it so when two objects with certain tags touch they send a message in console but i want any mesh that touches it to affect it
What's a "sliding joint". Something is either attached or not attached. Some joints have settings that allow it to be further away, if that's what you want. Depends on 2d or 3d but the 3d configurable joint has a shitton of options
the problem is i dont have a resources folder, should i create it myself?
idk why, maybe its a unity version problem
of course, if you need one
I'm trying to use a Slider Join 2D but it doesn't come off after the rigid bodies stop touching each other
ight thanks, earlier it was created automatically
I would add a lot of debug drawrays here so you can visualize it. A lot of these variables arent really stuff we can see so it's hard to know what's correct just looking at this
no, Unity will never create a Resources folder in your project. That is up ,to you
specifically, i want it to work just like a nail hanging from something, once it's removed enough it should fall off
debug draw rays?
