#💻┃code-beginner
1 messages · Page 562 of 1
Sounds like an animation problem not a movement code problem
yes the movement not a problem it jumps and moves right and left
so its not script problem?
#🏃┃animation for animation problems
oh thx
Well if the animation is controlled via script it can definitely be a problem with the script, but it's also likely to be a problem with the animator setup
ill check it out ty
hello
i would like a little help since ive bin stuck on my problem for 3 days and i dont find anything on google
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
so i want to import my character with clothes accessories and i dont know how i should set it all up, like how to export and import it right
here?
oh i was thinking infinite like a inifinte world, like super mario but you couldn't go backwards instead of like "open world" whereyou can revisit the older areas. I misunderstood the gametype though i think lol
Yes it's essentially an infinite map
Unity Arduino C# and Unamanged C++ structs
thats why I was wondering if you were able to revisit the old areas
You could go with only saving the changes that the user has made. So you first generate the chunk from the seed and then load and apply the changes to it
I heard about quadtrees. Is that useful here?
hello, how can i load a lightmap from a png file inside the unity editor and assign it to a scene?
can anyone help me make a interact script
whats wrong with the tutorials designed for this
I have looked at as many as i can and mine always never works even though i copy everything
never works, is less likely . Seems you haven't it done the same then
you'd have to show what you tried for far and what isn't working exactly.
the OntriggerEnter and Ontrigger exit for when i walk up to an object just doesn't work
if it doesnt work
A. you used the wrong methods for the physics type you're using
B. You're missing rigidbody somewhere etc.
also when i do type the same thing, the tutorials letters some up as different colors to mine, is that because i did something wrong?
most likely your IDE is not 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
okay ill try again, thanks!
sorry, do you recommend the visual studio via unity or manually installed and what version 2022 or 2019?
that depends on how you installed your IDE
whats IDE?
the thing you write code in
"integrated development environment"
Which one are you even trying to use?
Show us a screenshot of your code editor
okay
this?
is that vs 2019 or 2022
i think so, its just my file explorer one
that open automatically
You are still cropping out the title bar.
It's clearly Visual Studio, at least
(people very frequently mix up Visual Studio and Visual Studio Code, and I can't exactly blame them)
what should i use?
a better screnshoot
follow the VS steps in the bot message
use whatever is installed already
If you didn't manually download Visual Studio and run an installer, you want the "installed via unity hub" option
yea i never manually downloaded one, i jus had it.
then more than likely you already have the workload part if thats installed through hub, you just need to link it in the External Tools part and possibly click Regen Project Files in that same page
You should see it in the guide
will it like interfere with my scripts now if i download a new one?
not at all no
Unity doesn't care about your IDE at all -- it compiles the code on its own.
ohr okay, so do i get this?
you should already have that ideally(all new projects come with it) thats the least important step
linking it in External Tools is most important step
the package version there is more important for
VSC which your not using here, it expects at least 2.0.20
hello guys could i ask a question real quick ? im not sure im in the right place here but im having a problem with the universalpipelinerender ... with the built it you could use the transparency with the Axis but this universal one i cant find where i can change it .... could someone give me a hand with this pleasE? its a 2d sprite game so im following a tutorial but my rendered is different
probably more of a #archived-urp question
this is a coding channel
they were both locked, do i got to my external tools now?
External Tools is a page inside your Unity editor Preferences, nothing to do with package manager
ty maTE i didnt know there was a channel for that im new here sorry and thanks
okay, so that's definitely wrong
ya now do it according to the guide
which one do i change to?
you dont need all those checked, the first two are fine and default
only check off first top 2, then click Regen Project Files (make sure VS is closed first)
then open a script from unity
You will have tons of unnecessary csproj/sln files otherwise
now my VS dont even load
did you double click a script ?
ye
wait a moment until the bottom bar says Done
it says "Survival game" it clearly loaded something lol
in the bottom left it says ready
go to View and open Solution Explorer
You have no files open right now.
but shows nothing, that the thing
i know i'm doing something dumb, but i'm trying to fix this:
public string enabledIfTrue; bool SpecialCondition = DialogueLua.GetVariable("" + enabledIfTrue).asBool;
where i need to get the public string value of enabledIfTrue to appear in the GetVariable
try double clicking a script again, or open View -> Solution Explorer and click a file that way
ok right click it and do Reload with dependencies
right click and reload with dependencies
does something go wrong if you don't do this string concatenation?
what's a string concatentation sorry? you mean if i just put enabledIfTrue in by itself?
Yes
do i jus install this?
"Foo" + "Bar" concatenates two strings
yeah doesn't work either unfortunately
seems you dont have the Unity Workload for 2022 .
Go back to Visual Studio Installer, find 2022 hit Modify make sure the Unity Workload is checked off and installed
what does "doesn't work" mean?
compiler error?
runtime error? does nothing at all?
and is that second line of code from somewhere inside of a function?
or is it a field declaration just like the first line?
as in, it doesn't seem to "get" whatever i put into the enabledIfTrue's inspector field. If I manually put the string in the place of enabledIfTrue in the script it works, but i want it to get the value from the inspector
it's in Update i just put them together like this for display's sake
should i not download that VS that popped up?
Share the entire script. I need to see what else is going on in it.
!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.
thats not VS, that is unrelated workload , its incorrectly detecting it as it doesnt know unitys context
It's trying to install features that are used for an unrelated kind of work, yes.
@swift crag here's everything relevant, thanks for checking it out
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;
using UnityEngine.UI;
public class UniversalButtonDestroyer : MonoBehaviour
{
public bool oneTimeUse;
public string enabledIfTrue;
//public GameObject button;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
bool IsInConvo = DialogueLua.GetVariable("IsInConvo").asBool;
bool SpecialCondition = DialogueLua.GetVariable("" + enabledIfTrue).asBool;
Button button = GetComponent<Button>();
Image image = GetComponent<Image>();
if (SpecialCondition == false)
{
button.interactable = false;
image.enabled = false;
}
okay so i got back to my VS then what?
Perhaps you have more than one UniversalButtonDestroyer component in your scene.
hmmm i don't, but would that be a problem if i did?
You could check by searching the hierarchy for t:universalbuttondestroyer at runtime
you could be configuring the wrong instance
for example the "IsInConvo" works totally fine
Right, because every single instance will have the same string there
nvm i can't even load up my scripts cuz it said i need to install?
No not VS. I told you Visual Studio Installer, go to it, Find 2022. Hit MODIFY button then follow the steps https://learn.microsoft.com/en-us/visualstudio/gamedev/unity/get-started/getting-started-with-visual-studio-tools-for-unity?pivots=windows#install-visual-studio-and-unity
they said earlier that they did not manually install Visual Studio
would the installer still be available?
But if you have five instances of this component in your scene, each one can have its own string in the enabledIfTrue field
yeah it automatically installs it via that
VS doesn't install without the hub/installer as its how it updates too
Should I use MVC to separate UI from game logic? Is there a general way of separating them?
I swear the most common issue here is people not having their ide setup correctly (usually vs)
sure you can use MVC too if you want to
yeah its usually the most important step too
it would solve probably 70% of the questions / issues here
Quick Actions is godsent lol
what version is this?
i mean it a yt tut ss
hold up
looks like shitty brackys code lol
that time.deltaTime on the mouse inputs is dead give away or maybe someone copied that bad code
also the colors shown there are just a theme
those looks like VS2019 icons
It's absolutely incredible how much staying power that Brackey's bug has had on the Unity tutorial space.
That bug will never die
You can never be too safe.
(for those unaware: mouse input is not a velocity; it's an absolute amount of movement. multiplying by deltaTime makes no sense!)
this is my origonal problem, i jus dk this tut as i said ealier dont work for OntriggerEnter adn exiy
OnTrigger works fine if you have a rigidbody or CC
but you should really fix your IDE before anything..
ideally you wouldn't even be using trigger messages for interacting with objects so it seems like a poor tutorial anyway
true that, nothing a simple Raycast or other type of Physics query wouldn't solve neater
what rigid body cuz i just copied scripts from tut, how do i learn scripting?
use the pathways on !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
this way its more structured
You wont be copying your "dream game" right away, its more about learning all the building blocks at your disposal before you build your house
w quote
btw i've installed 2022 now so what do i do now, will it work?
You wont be making your first project the game you always wanted to make, its something you build up to
2022 was installed already 🤔
did you do the Workload part
i wonder how many people trigged endless loop of updating view/model 😆
that whole time it was installing
and yes i did the workload
it was like 1.8 gb
the Unity one yes ?
ye
you tried opening a script/set it in unity while it was installing 2022 🤔
don't do that lol
easy way to corrupt your install
no no no , i waited first
ok so you try reload the solution now
that right
whats the last step
probably learn the basics before you do such complex systems like interactions
eg what does it mean to Get a Component etc.
yes you're using correct thingslike Raycast but do you know why? or what it is?
I know but you're copying without understanding why you need that
copy and paste you wont learn anything
if you must copy and paste, learn why it is you need those
so learn
and what other outcome could possibly happen?
quit mashing random code together and use the resources you've been pointed to already: #💻┃code-beginner message
im tryna make a radius when my test appears and disappears
things like learn site, documentation and manual
trifecta of success
how do i give the distance
yes because even if you see the docs, would you even know how to read it? or use specific parameters without using a new signature?
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Physics.Raycast.html
also is this a good movement script?
okay last thing lol jus to make sure, i do go down teh junior programmer pathway, i dont wanna waste my time lol
if you're new to the engine entirely then start with the essentials
ik most stuff its mostly scripting
okay then don't start with the essentials?
Wow, I had no idea this was what I was doing. I thought I was on to smth the whole time . . . 😄
haha yeah I think I've used quite a few patterns that only after reading up on them I'm like wait a second...this seems familiar..
I think other .net frameworks are more strict with MVC and MVVM
It's like a copy, honestly, it's kinda creepy how close you csn get to smth else someone has done with no knowledge of it . . .
I only learned a few years ago that I was abusing events and the pattern was called "observer" lol
True, I've always done a custom (but close) replica of the observer pattern . . .
For MVC, I'm actually testing out using a C# class/struct instead of a MonoBehaviour, so it's pure data. Hopefully, it'll be better for null checks, and using the modern conditional operators. Plus, it's pure data, not tied to a separate MonoBehaviour. I'll see if it works out . . .
The tutorial has an error. It uses the null-conditional operator on a MonoBehaviour to check if health is null before calling Increment and Decrement, which is incorrect. That will not correctly check for Unity's null . . .
oh wow good catch lol
maybe it was meant regular class
nah wait that wouldn't make sense cause you couldn't put it on a object
well actually if you do Serializable it
and its a SerializeField, it should work as its own health
maybe they got lazy lol
nvm HealthPresenter having an instance of Health would probably be going against the whole mvc thing
Because you could turn the controller into a generic class with T being any stat, like Health, Stamina, Dexterity, and the different fields for those C# classes/structs would appear in the inspector for your controller . . .
yeah idk someone got lazy to write if (health != null) for the rest lol
also they use early return pattern in the same method and then go into a nest if statement :\
if (health == null)
return;
if (healthSlider !=null && health.MaxHealth != 0)```
when it could just be
if (health == null || healthSlider = null)
return;
weird inconsistencies lol
can make sense if there is more happening to health but not the slider, but could also cleaned up better for readability 😄
With Unity, HealthPresenter (the C/P) is the intermediary and observes the Health (Model) instead of the View, so it gets the data from Health by referencing it. Its fine since both MonoBehaviours are on the same object . . .
yeah that makes sense now lol
Using a C# class/struct would remove having a second MonoBehaviour, but you're right, it would tie the data (Model) with the controller (Presenter) since they wouldn't be separate classes (layers) you csn access individually . . .
!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.
Just imagine having two classes for a bunch of Controllers. That's a lot . . .
hey guys, anyone know how i get this pop up menu for auto correct for my IDE?
if it is configured that should appear automatically when typing
unless you've intentionally turned that off in the settings
do i need a plugin or something because i don't get that pop up
no, it's a built in feature
thats because you're trying to pass the type itself and not an instance of it
is that not the example image of what they want?
yeah which means it should be working just fine unless they've intentionally disabled intellisense
lets hope not lol
i didn't i installed it as you said
wat
wdym what did you touch since this
it was working fine
you must've done something
im doing the programmer tutorial that you showed me
since idrk how to script
I understand, but did you not open your script through unity?
i did im making a different script
for a different game
that hes teaching me to make
show your external tools page again in Unity and solution explorer in VS
if you did a new project maybe the Preferences didn't save..
ohr okay
Okay so back to doing what you did before, select it
and regen etc.
close unity a few times
so now if i just load it it will work?
Is this auto fill thing already built into Unity
they already have it configured to do so , it comes from VS working with the Unity Workload . Its a VS feature called Intellisense
I have to install it?
!ide 👇
Wait nvm
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
hello! i'm having issues with an animation transition
it's oddly delayed for some reason
has exit time is unchecked, transition duration and offset are at 0
no empty frames at the beginning of the animation
don't really know where to go from here
sounds more of a #🏃┃animation question no?
unless its code you want to share
it runs inside a coroutine if you think that could be relevant?
but other stuff also runs inside it and they work instantly so back at the beginning
take a look if you want let me know if there's any blaring mistakes
i'll try in the other channel
oh jeez.you should really cache that player also use variables instead of very precise magic numbers, it puts meaning behind them
Triggers are pretty wonky, if the transition is too long iirc they repeat
it's just a concept project. first time using unity so i'm learning functionalities
but yes i should absolutely find a better way to reference that player lol
if its runtime beside DI, you can just cache into a variable in Awake
what's DI, also will take that into account
don't really know the practical differences between Start and Awake either i just use whichever
is there a better way to handle null reference exceptions other than try and catch and if else
try/catch is the worst way
why
because it's extremely slow
and it hides actual programming errors that you need to fix
I guess is there any other way around if else statements
Generally a NullReferenceException is a great thing
it tells you that you failed to set up or configure something about your scene or your data model
the best way to fix it is to make the thing not null
by properly setting things up
In the rare case where it's acceptable for a variable to actually be null, you just need to check if it's null before you use it.
you mean not acceptable?
exceptions should be exceptional
no I mean acceptable
I mean - the program is in a good state even if that thing is null
I know that Python encourages you to just YOLO it
oh ok
I've been getting rid of more and more "maybe null" variables
and factoring those out into separate components
Dependency Injection. Like if you spawned this object from something in the scene that could have reference to player, you "pass it " to the new spawned object. That is passing your Dependency or "injecting it" the term is a bit loose In Unity though.
Also Awake is basically constructor for gameobject, it runs regardless of gameobject (unless the whole thing is disabled). Start has a checkmark, if its disabled then it doesnt run
in our java programming class our professor was telling us about how excepetions are the best way to handle errors or at least better than if else
- Is there an “and” thing. Like if Boolean true do this and this.
he was referring to errors -> exceptions in general
There's nobody who knows less about real life programming than college Java professors in my experience tbh 😆
he certainly didnt mean to use them for logic flow and fixing sloppy coding
you can put as many statements as you want within the block attached to your if statement. you're only restricted to one line if you don't attach a block scope to the if statement
Are they also making you Eclipse IDE?
So for example, given that all these variables are GameObjects, they should all go in Awake?
yeah actually she did mention one thing about zero division and how its dumb to use exceptions for it
no netbeans
even worse lol
bruh I hated that ide so much
awake is a good way to cache something yes
I just used intellijide
I need to find a way to get a shit ton of points or trace the cursers ray hits.
whats the usecase
I wanna make a baulders gate like movement system where you can drag a line from your player to make a path.
Specifically draw since actual placement during the movement is important
So you can make your char move In a straight efficient line or a long detour line
just record each point the mouse is touching each frame in a list
then have your character follow the list of points
You could do every .1 seconds or something instead for performance reasons
Okay that what I was kinda planning
But it’s the actual execution I need to figure out
Like what to type and stuff. So research time!
cant you use navmesh to get the path and then show the line accordingly?
They don't want the fastest path to a point
they want the character to follow the path the mouse traced out
ah okay, thought they gonna track just start (character) to end (mouse pos) and then let them walk there, my bad
you probably still want to have navmesh involved though - to handle pathfinding to the mouse points, because the mouse may trace out a path that goes through a wall for example
Just was thinking of the mentioned baldurs gate movement, where you just set the destination, not the path itself. But something to clarify by the questioning person
I was going to nav mesh to each point. The game is ran in “frames” (for lack of a better name). So you move 1M a frame. So I need to stop the nav mesh or freeze the player mid run
(Think yomi hustle X BG3)
Ah, so you need specific distance points your player can "use" to move?
Kinda. I’m having it so you draw the line and then as the frames advance you run it, unable to stop. Risk and reward type thing
Sure. This is going to be little more than just keeping a list of the points and a cursor into the current point you are navigating to. Once you reach one point you start navigating to the next one, etc.
I am sure, you can split up the found path into some "sub"paths and go from there. But as you said, that really sounds like a prototyping thing to test what works for you
My plan was to do the point thing ever second, then seperste it into segments that are each 1M total
Sigh I am realizing this project is a bit big scope for a first every game. But motivation is motivation
Think of systems, not the whole game and things get smaller.
one piece at a time
Hence why I’m starting on movement and not the combat or the environment shit
Or the… online comparability
I do plan on having about 300~ abilities in the game but again, that’s an issue for later
Just keep in mind, its your first game so even if you fail, you gain knowledge. And if you dont fail, congratz. Just look at it as research for your career path rather then trying to be the next AAA title. Be proud of smaller achievements like learning navmesh in this case and other things, that will come up while you realize, what you need for the systems you want to include.
Back in the days when I wasy ounger, AAA was good 😄
I hope it’s a functioning shit show
The days of 2010s
more like before 2000s childchood 😄
I think what I need to learn first is. Raycasting. Navmesh. And saving points
Oh the 1900s
Sounds like a plan 🙂
Quarter of a decade ago damn
So, time for me to get some sleep, getting late here 😄 Best of luck for you and have fun learning and researching! 🙂
Ive been having this error show up on my console since I started my project before I even started coding anything
Unity.PlasticSCM.Editor.ViewSwitcher.OnDisable () (at ./Library/PackageCache/com.unity.collab-proxy/Editor/ViewSwitcher.cs:205)
Unity.PlasticSCM.Editor.PlasticWindow.ClosePlastic (Unity.PlasticSCM.Editor.PlasticWindow window) (at ./Library/PackageCache/com.unity.collab-proxy/Editor/PlasticWindow.cs:1096)
Unity.PlasticSCM.Editor.PlasticWindow.OnDisable () (at ./Library/PackageCache/com.unity.collab-proxy/Editor/PlasticWindow.cs:283)```
this is a known bug. apparently not yet fixed
you can remove the VC package and restart unity
if you use unity VC idk then lol
Hey, im having an issue with this rotation handling im calling in fixed update which results in a jitter effect of the whole character
!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.
and share the full script as we're missing context here such as where is this running
ok well I would say a few possible issues here:
- Your use of
transform.eulerAngles.yin several places. Euler angles cannot be isolated individually from a Transform and expected to be relied upon for game logic - Potential lack of interpolation on the Rigidbody
is there a simple way to dynamically resize text to fit inside a gameobject? i'm trying to make a function that, given a gameobject (with a child tmp_text), maximises the size of the text whilst not letting it get bigger than the size of the object itself
TextMeshPro has an "auto size" feature
i have tried that
it doesnt seem to account for the length of the text string itself
or some other variable i'm probably missing
Any chance someone can help me with this script? As far as I know this is all right, but after the objects are assigned it doesn't seem like the script effects anything
gameobject that started this coroutine is either disabled, destroyed or you have timescale at 0
debug.log your EventStarter before Wait see if it even enters the Coroutine
So nothing activates/deactivates (turns off or on)?
Correct
put log on each step see where it fails
I'm new new chief, how do I do that?
Debug.Log("step 1");
etc.
above each Wait for seconds
I've never had to debug. Where, how, what? (I apologize)
they explained where. they said place this line of code (they provided the line of code in their message) above each wait for seconds . . .
AH
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Debug.Log.html
should probably be the first function you ever used in Unity
Forgive me, but I'm so lost, this right?
no why didnt you copy how I wrote it lol
It doesn't recognize it
wdym?
how does it not recognize it? does it tell you that? just wondering what you mean . . .
Debug.Log("step 1");
yield return new WaitForSeconds(2);
Debug.Log("step 2");
etc..```
Apparently it was being picky, its fine now
Uno momento
also, as they mentioned, place that line of code above each WaitForSeconds, not just the first one . . .
yeah looks fine. maybe you can even put a step 4 under the last WaitForSeconds
save it. then run the code again, check the console tab
ok so its working
it does work!
And that's what's confusing me
so are sure you referenced the correct objects you are lookking to disable / enable
so, the question is: what do you expect to happen that does not?
did you do something silly like drag prefabs into the slots in the inspector?
hehe yeah that would be bad
make sure you dragged the correct GameObjects in each slot. check if they are activated/deactivated during runtime . . .
this was my initial thought . . .
Huh?
what part of the question do you not understand?
also your screenshot shows you allegedly did not do that anyway so 🤷♂️
we can't see where these GameObjects are. they look like UI GameObjects; are they in the scene view or off-screen?
public static Collider GetCollisionOnUpdate(Rigidbody self, float maxDistance = Mathf.Infinity)
{
float distancePerFrame = self.linearVelocity.magnitude * Time.fixedDeltaTime;
Ray ray = new(self.position, self.transform.forward);
// Based on estimated position next physics update, check if there is a collider there
UnityEngine.Physics.Raycast(ray, out RaycastHit hit, Math.Min(distancePerFrame, maxDistance));
return hit.collider;
}```
Anyone know what im doing wrong here? I'm trying to predict whether a collision will occur or not in the next physics update, and will return the collider that it hits (which will end up being null if there is none), except it never seems to return the collider when i would expect it to
```cs
Debug.DrawRay(ray.origin, self.linearVelocity * distancePerFrame, Color.green, Time.fixedDeltaTime);
I've added this for debugging, and it looks as expected, so i have no clue what im doing wrong
you realizing that charSirDummy and charLadyDummy are already enabled, what sense would it be to set them as active again
Sorry, "prefabs" isn't something I'm yet familliar with
One on screen one off screen
then you should perhaps take a step back from what you are doing and go through the unity essentials pathway on the !learn site so you can learn how the editor works instead of just fumbling along blindly
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
they start Active, why are you setting Active = true in code ?
perhaps you wanted to HIDE them ?
or you're just misunderstanding what SetActive does
its not gonna magically make them appear if they're offscreen
I've been receiving assistance from various people who ahve said multiple conflicting things, I appreciate it
isn't your distance too short? you don't need to multiply by fixedDeltaTime . . .
you still haven't told us What you expected to happen from the script running
"but after the objects are assigned it doesn't seem like the script effects anything"
is unclear on the issue, since we proved the script is running correct
Apologies, let me explain
Surely i do though? If i want to work out where my object is going to be next frame, do i not need to work out its velocity; per second and then multiply that by the time between updates, which is by default 50hz. Linear velocity is just units per second isnt it? I'm guessing metres
I've set up an animation for the Lady off screen to come on screen, which works. As well as an animation for the Sir on screen to fade in, which works.
I'm merely trying to delay their activation so they don't all playout at once
And I've fixed it
so start with them DISABLED prior to running game
Yeah I pressed the wrong button
anyone?
Mayhaps I shoulda worked on this when I got a proper sleep
Thank you all very much for your assistance though
The debugging will definetly be helpful. I've been lucky up till now that I haven't needed it, but it'll be good to know👍🏾
yes debugging will be most of your time developing lol its a good way to confirm facts rather than assumptions
no. FixedUpdate runs at a fixed rate, not a variable rate like Update . . .
No i know that. But isn't it still correct for my code? I want to check that for the next time a physics update occurs, that i will collide, therefore im casting a ray in the direction of my velocity, with the length of how far it will get in that period, to check if it hits a collider
Sorry i realised i probably used the word frame when i shouldn't, i'm just talking about physics here, not rendering
I am having trouble understanding why scriptable objects are used the way they are.
I read the docs for them and noted in other tutorials it should be used as a data container, but the data shouldn't be changed.
Additionally, other uses for it have scriptable object is communicate through events?
If I wanted to use a scriptable object for a global variable to reference through events, should that variable never change?
Anyone have a video that explains them with an example that makes sense.
Scriptable objects let you define a cluster of variables and store them in a file you reference from multiple places
I cannot seem to find the code to align center the Button
if (GUILayout.Button("Select Output Folder", GUILayout.MaxWidth(250)))
{
baker.SelectOutputFolder();
}
So for clarity, should those stored file variables be adjusted during runtime or not?
no, you just need the distance value. it's frame-rate independent; that is why you don't need to multiply values by fixedDeltaTime . . .
You should avoid changing them. They behave differently in the editor as they do in a build if you change them at runtime
can't you change them, but have to write them out to a save file..
are you doing editor code? probably better off in #↕️┃editor-extensions
the problem is, you can mutate the values of an SO during runtime, but it must be an instance of the original SO. because of how SOs work (under the hood) they behave differently in the editor than during a build. this causes a LOT of confusion when first working with them . . .
That did indeed fix it thanks, I'm still not sure exactly why though. I was fairly confident i needed fixedDeltaTime. is linearVelocity not per second?
Think like, a TCG card. Every Grizzly Bears is a 1G 2/2 Creature with no abilities. This never changes. If you play a Grizzly Bears and then buff it with Giant Growth, it doesn't change the file that says "Grizzly Bears is a 1G 2/2 Creature with no abilities", you are just changing this Grizzly Bear
try cs GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Centered Button", GUILayout.Width(250), GUILayout.Height(50))) { Debug.Log("Button clicked!"); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal();
Wait no, it didn't fix it. It's triggering too early. We are definitely on the same page here right? I need to check per fixedUpdate, not per second, so im 99% sure i need fixedUpdate
Thank you 🙂 that is very helpful
did it work? been a while since i touched the old school GUI lol I'm tooling with UIToolkit now
check your length and your debug. it may be too long now since it was shortened by fixedDeltaTime . . .
It did! for the button you included. now i have to tinker a bit to include the other buttons, as they would all want to be on the same line if i put the
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
above all of them. It proves the concept though, and know i understand the Syntax a bit better
too long because it was shortened, Huh? That's fine, my ray debug looks exactly as i would expect, that's why i dont understand where the problem's coming from. I feel like you're not really reading what im asking
The Asset SO is a serialized ScriptableObject instance:
In Editor: Mutable and savable as a standalone file. Changes are serialized and saved via the AssetDatabase and Unity's serialization system.
In Build: Read-only. Runtime values can change but cannot be saved back, as it is part of the build.
On scene reload, the ScriptableObject resets to its original state.
To Save Runtime Changes: Use external files or systems that are not included in the build.
you pinged the wrong person . . .
its clarification, so its bound to your post for follow up
He said that it was short because of the * fixedDeltaTime(0.02 by default), you deleted it so now its too long and it triggers too fast
But the point is i want it to check for the position it is the next physics update, the behaviour i have right now for the debug line with the fixedDeltaTime in looks as i would expect, i dont want to check where it will be in a second
For more context the reason im doing this is because i want physics based rotation control in my game, but i dont want my character to spin out when hitting something, so i am constraining rotation when i suspect i will hit something
if (PhysicsUtils.WillCollideOnUpdate(rb, out _)) rb.constraints = RigidbodyConstraints.FreezeRotation;
else rb.constraints = RigidbodyConstraints.None;
I didn't say its wrong, i clarified you reading misunderstanding of someone else post. The formula is good it follows the physic one s = v * t. But you estimate the position just after 1 fixed frame, which is the equivalent of position after 0.02s (20ms) (human reaction time is 250ms for comparision).
just estimate the position after 50 frames
im not trying to get a human to be able to respond to it, im trying to prevent rotational forces being applied to the player when they collide with another object when that collision is inevitable, which will be if you have the velocity to collide with an object by the next physics update
how come? i dont want it to constrain rotation any longer than it has to
just increase the frame value, thats the solution, explaining it is effortless
But if im checking every single fixed update if it will collide next update, surely its going to check for a collision before it collides no matter what, and by checking the position next frame, every single frame, it's always checking at the latest possible time
do math with real numbers, and you will understand how the distance ray looks just for 1 frame, 1 frame is equivalent of 0.02, put the numbers, calculate
like this, not in code block to don't copy paste
what IDE are u using?
nvim
Maybe your confusion comes from seeing the distance as a measurement per frame or per second
First, when dealing with movement in FixedUpdate, since it's frame-rate independent, you don't multiply by deltaTime (we already know this)
Second, the distance is a measurement of space, not time; i.e., 1 is 1 unit, 10 is 10 units (a unit is one grid space in the scene). It's independent of time. Multiplying by fixedDeltaTime will only change the measurement of distance in space, not on a per frame or per second basis . . .
Late response sorry. I feel like we're going around in circles here. But that is what i want i get what you're trying to tell me but i don't see how that's helpful, as its limiting my rotation before i want it to
Input System Newbie:
I've been adapting the Smartfox Shooter demo which has walk, run, jump etc all set up.
It has the Input System - Custom Character Controller - Animator already in place.
I'm now trying to add dance animations for my not-shooter game.
I've gotten a key working to toggle dancing on and off but I think it's not switching the boolean Dance.
To keep the UI simple for now, I've made an Animator layer that (I think) can progress from one animation dance loop to the next to the next as long as Dance == true.
I think the boolean Dance isn't activating when my key press toggles it on, although I can see that it's activating the reset of the other booleans. Maybe it's getting switched of by the other functions which check the move/jump functions.
Also the two original layers have a blue line under them but my new third dance layer doesn't.
I'll experiment with adding my Dance == false rule to the other layer, but any advice would be welcome.
i'm unsure about your issue, i just wanted to point out a piece of your code: dance = dance ? false : true;
it seems you want to flip its value, if that is true, you can simplify it with dance = !dance;; it's more readable and shows your intent more clearly . . .
Thank you. I'm working on understanding this demo's controller logic, so I can add my own additional animations.
- Having dance anims on a separate Animator layer is preferable b/c their walk/run/jump graph is a web with every state connecting to every other state.
- The logic seems to be:
(for example) Tap shift to toggle run on - update RunForward bool on Animator to true - send animation change to SF2X multiplayer network - Animator changes state to RunForward b/c that bool is true.
I can see the bool changes for their walk/run/jump in Animator. Now I'm figuring out how to add my dance animations correctly.
Useful for me as a beginner programmer.
https://www.youtube.com/watch?v=BMrYv9nNQGI&list=PLNoRsahkiuzV_OgO9QmIuCy7nr__RGzBS
Intro to my new series on Editor Scripting!
This is intended to be a very basic introduction into Editor Scripting and customizing assets to be more clean and usable inside of the Unity Editor.
Keep in mind... the first few videos will be covering a few basics that aren't Editor Scripting proper, but are necessary to build off of as we move to ...
i put it here because it covers concepts that are used all the time. it is Not Editor Scripting specific.
Don’t think that’s a code question but you just layer another sprite
yeah but after i did that, it collided with another object
Oh I thought you were talking about the holes on top. You would probably use a tag based approach to have some colliders ignore other colliders maybe
not "unity collider", i'm talking about the holes in the board
You just said it collided with another object, did you mean overlap?
!collab
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• Collaboration & Jobs
hi, im new iin coding, what does this meaan?
show some of the code maybe
Hello Everyone, having trouble with the script below:
So I need to rotate Instantiated object by 90 degrees on X axis, but it says that it can't convert void to Unity.GameEngine.Quaternion
Tried using variable, didn't work
rotation probably instead Rotate
Yeah, that what I was here for the first time, but as I said, it spawns that object below 90 degrees on X axis
Rotate is a method, not a quaternion, which it expects
You are instantiating whatToSpawn (bad namings btw) and you set it to the position of the whatObject and then you Rotate the target object with nothing. Thats your code currently doing
It does not make sense at all, because your instance created is not parent of your whatObject, so you rotate it but nothing happens to your instance
How do I rotate with something?
do you wan to have the same rotation as an gameobject at that time

or will the rotation always be the same
orr do you want the initial rotation of the prefab
So it should take the position of main object, and then when it spawns, rotate it by 90 degrees on X
So it will look not straight, instead, it will look up
Because if I leave with rotation, it will look straight
Just need to rotate bit a bit
Quaternion.Euler(90, 0, 0); try this
Thats not taking into account the whatObject rotation tho
Ah my bad, it was just position, true
you are welcome
you could also just have the prefab rotate 90 degress on x before instantiating and then simply use Quaternion.identity
Oh, and @astral falcon, you said namings were bad, was it because it was hard to understand what they mean?
Renaming to:
confettiVfx
plrBody
Is more solid and understandable?
depends on what you gonna do with that method. But if its a specific object, "whatToSpawn" and "whatObject" does not explain anything about your setup. Just imagine explaining it to someone else. its like calling everything "this" and "that" 😉
That's something like, keeping the original rotation after copying?
yes
Oh I got it, thanks
my character wont move anymore after I put the animations, pls help
im just using the code from the tutorial im watching
post it as code , it is easier to inspect
also do you have any error messages in the console
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private float speed;
private Rigidbody2D body;
private Animator anim;
private bool grounded;
private void Awake()
{
//Grabs references for rigidbody and animator from game object.
body = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
private void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);
//Flip player when facing left-right.
if (horizontalInput > 0.01f)
transform.localScale = Vector3.one;
else if (horizontalInput < -0.01f)
transform.localScale = new Vector3(-2, 2, 2);
if (Input.GetKey(KeyCode.Space) && grounded)
Jump();
//sets animation parameters
anim.SetBool("RUN", horizontalInput != 0);
anim.SetBool("GROUNDED", grounded);
}
private void Jump()
{
body.velocity = new Vector2(body.velocity.x, speed);
anim.SetTrigger("jump");
grounded = false;
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Ground")
grounded = true;
}
}
i did, but it cleared out
line 32 looks weird to me
what tutorial is it that you are following
by wont move you mean the animation stops but the character itself still move on the plane? or animation and character doesnt move at all?
i assume it is this: #💻┃code-beginner message
that is why i asked which tutorial they are following, maybe just a simple typo
the animation is animating but the character isnt moving
In this video we're gonna focus on how to animate a 2D player in Unity. We're upgrade our graphics, create animations and make them work from our code.
● Unity Asset Store: https://assetstore.unity.com/
● Dragon Warrior Asset: https://assetstore.unity.com/packages/2d/characters/dragon-warrior-free-93896
● Pixel Adventure Asset: https://assetstor...
i have it in uppercase because the parameter's name on mine is RUN, same for GROUNDED
do you still have any errors
on the console, no
transform.localScale = new Vector3(-2, 2, 2); this doesn't look right
comment the if with that line out
and check if its working
wha is the value of speed in your inspector
10
fix line 26 to transform.localScale = new Vector3(-1, 1, 1);
dont see anything else wrong
nothing happened
also, i just noticed, it also isnt falling even with gravity
Scale has nothing to do with gravity anyway
Can you log body.velocity?
Loks, check what it is. I assume that it is constantly 0 or a weird value
and show inspector screnshoot of the character with uncolappsed rigidbody2d
Are there errors in the Unity console?
one just showed up
So this script is probably not even attached, or something else isn't
Click the message, it will point to the missing component
Assuming it's this script, add it
its not doing anything when i click it
It should point you to the missing referenced script in the inspector
Regardless, I can see the script is included here so that's probably not the issue anyway
the Component looks ok, thought you freeze one of axis by mistake but no. You can Debug.Log(horizontalInput) right after you assign value to it
Does the scene play with no errors?
no but something new happened
the running animation now plays when I press trhe arrow keys
but im still not moving or falling
and the character now flips depending on the direction (which was a problem i was trying to solve earlier but ig its fixed now)
yeah that the line you fixed
and its reacting to input so you doesnt need to debug the horizontal input anymore
Like I said, debug the velocity
i think its still may be line 26 fault, the flipping x axis may collide with physic system
unlikely
Apart from it still being as lot of guesswork due to lack of debugging results, this is very unlikely to be the issue
it alreeady affected animator and physics when it was scaled up, now its just flipped on x axis, thats from where that guess coming from
few debug.log would solve it easy
If it has anything to do with flipping then the unflipped variant would not have any issues
Again, bunch of guessing while there is no actual proof of anything so this is pointless
i guess he just pressing in one direction
You guess huh
The object that the code is linked to should become invisible when another object taken from the scene is visible.
Can you help me with writing this code? Because mine don't work out.
i got this on the triggerenter of my object to move the camera up but nothing happens: if (other.gameObject.tag == "trig")
{
Debug.Log("itsworking butnot");
camera1.transform.position += new Vector3(0, (float)cameramove, 0);
// Camcontroller.moveup = true;
}
i get the debug message
but the camera doesnt move
Then cameramove is likely 0f
I suggest you debug what it returns
do you really want += or does it have to be =
cause you are only doing this in one frame.
+= i want it to move up and not at a certain place
then you would have to do that in the update or maybe in a coroutine.
rn you are doing this in the OnTriggerEnter
its okay if it happens once i dont want it to keep happening
its not moving but its suppose to
What does cameramove return then?
it returns 1
not at all
f (other.gameObject.tag == "trig")
{
Debug.Log("itsworking butnot");
camera1.transform.position += new Vector3(0, (float)cameramove, 0);
Debug.Log(cameramove);
// Camcontroller.moveup = true;
}
What does it log when you do Debug.Log((float)cameramove);?
Alternatively log camera1.transform.position before you add cameramove
I don't see how this doesn't properly mutate the value
Something else could be modifying the camera pos
stil 1
Like cinemachine, a script, or even an animator
Yes, then it's probably being reset if you're certain it's being added
could be cinemachine but its a normal camera
You see cameramove is a valid value that would update the position, and the code looks correct.
What you can also do is log camera1.transform.position in an update function to see what it returns each frame
If correct it will show the new value, then go back to the previous value
alr ill see
i maybe know why
the object the script is on is a prefab
and i made the camera a prefab
and the position of the prefab changes instead of the camera in the sccene
bc in the debug its shows its moving up
could that be it?
I just got back, how exactly do I do this? i still dont get how to log
See the link I added with this message
If your camera variable is referencing a prefab then yes that's definitely it
how can i fix that bc i cant asign the in scene camera to camera1
I suppose you are Instantiate-ing the camera somewhere? That method returns the instantiated object. You can store that reference
rn i just have the camera in the scene from the start
but how can i store an instantiated object?
You need some way to get a reference to it
By assigning it to a variable with ... = Instantiate(...)
thank you
thanks for the help
i dont think im doiung this right because its saying all compiler errors must be fixed before entering playmode
screenshot your console
I think the first error is pretty obvious
this showed up after i tried to debug
Hi
ok so show me line 21 of the PlayerMovement script
still tryna figure out how to use debug.log
And what does the first error message say?
this has nothing to do with Debug.Log. It is absolutely basic C# syntax
Did you try? This should be fine
I don't see how the link is unclear, it explains it properly
And like Steve said, this is basic c#
Actually, take a step back because your editor is nog configured
So configure it first, and then continue with the issue
Because it's obvious the editor is not helping
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
i just started using unity 12 hours ago, theyre all pretty hard for me to understand rn lmao
you can read can you not?
Properly configure VSCode first. I suggest you switch to Visual Studio or Rider however
ight
Junior Programmer Pathway on the !learning site is a good start
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
It can't even detect a missing semicolon so if you have trouble writing code you should definitely get the extra help
end of line 21
if the error message is not understandable then learning C# basics is an absolute necessity
its working now, i missed a semicolon
yes, exactly what the error message told you
Please stop trying to fix issues and just configure your editor
I am very aware of the issues, that wasn't the point of configuring it. You are going to have a hard time yourself
they are going to laugh when they finally configure it, and watch it start auto-completing code for them
Hello!
So I've encountered a problem with music (SFX) not playing when player collects collectible object.
Script works fine, with VFX (explosion) being played, but for some reason music is not.
Any thoughts?
you play the audio and then immediately destroy the game object
So, it doesn't have time to fully play?
how can it? It no longer exists when you destroy it..
you should call destroy like this, Destroy(gameObject, Audio.clip.length);
That's a good way to delay the destroy, but not the only thing that will need doing for this. The visual will still be present until the clip finishes, and that needs to disappear straight away.
but if it is a particle effect, you would just call play once and not make it loop
or stop it once you know it should stop. e.g. delay
yes, so making it disappear straight away
Is there another script/option in unity than animator.Play("StateName");? like play.this.animation ? i have a lot of animation and i need just add for inspector my animation. I have to do it faster
every time type ur animation in script is boring : / i just need add for inspector my animation
just this
So. Another question.
How do I tell the script which one I want it to play?
Since you can't rename them, what's the option?
Why do you have 2?
Make serialized fields and drag them into different slots
ooo
- For Win SFX
- For Collecting SFX
Can't you just use 1 and use AudioSource.PlayOneShot?
That is assuming you have two separate audio sources because you want to avoid cancelling eachother. This would fix it.
Wait wait. I'm completely confused.
If there is a problem with using 2 same components in Unity, how do people manage to play multiple audio on a single GameObject?
There's not, I am just suggesting a simpler alternative if this is the reason yo have two audio sources
It is perfectly possible to have multiple channels. PlayOneShot has its own limitations
But if you want to simply be able to play sounds without them cancelling eachother out, you can have a single channel and use this method
But to answer your question, generally you'd make a sort of manager that maintains the audio sources and balances sounds between them. Specifically by using specific channel groups
Don't make a source for every single sound, make them for a category in that case
Is it beginner friendly?
I guess
Alternatively just use GetComponents in a script to get all audio sources and use one of the returned instances
So the idea is just to play a sound when player collects an object, but the thing is that player body is already using one of the AudioSources, so that's the problem
Yes so PlayOneShot would fix this
AudioSource.PlayOneShot does not cancel clips that are already being played by AudioSource.PlayOneShot and AudioSource.Play.
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/AudioSource.PlayOneShot.html
Also, what about Empty GameObject with Box Collider? Since empty GameObject is actually nothing and does not Collide, you can make lots of them and use like a hitboxes?
The problem with Destroy() as said
Even with PlayOneShot(), sound doesn't have enough time to play
so think about it logically..
You want to:
- hide visual
- play sound
- destroy after sound has finished
I didn't see the chat about destroying it
Yeah considering it's more or less a fire and forget thing, you can't check if it finished
I think I will just make it to send a signal to play that sound on the Player model
So it doesn't destroy with the sound
no, it shouldn't be on the player.. it has nothing to do with the player
I literally just said do not do that
Alright I won't
You could, but it just couples a sound on the player which has nothing to do with the actual player
So you really should not
Collectable parent should be an empty gameobject, with the components on it.. the visual should be a child of this.
collect -> disable visual + play sound -> destroy parent when sfx finished
Maybe I can try with Get components ()?
🤔
How do I check if SFX is finished?
you need a longer memory
Thanks for a tip
Uh, it does the thing but. Collectible is no longer destroy..
Nvm, I fixed it.
Thank you guys for your help! @hexed terrace @burnt vapor @cinder schooner

Thanks!
hello im doing a score UI where the player collects things and the score updates, the score is changing but its not displaying in the screen i need bit of help
How are you currently updating the UI?
If you want help then please share the relevant code and point out where the issue could be
📃 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.
using UnityEngine;
using TMPro;
public class ScoreManager : MonoBehaviour
{
public TextMeshProUGUI scoreText;
private int score = 0;
public void AddScore(int points)
{
score += points;
UpdateScoreText();
}
private void UpdateScoreText()
{
scoreText.text = "Score: " + score.ToString();
}
}
Huh. That looks right. Do you get any errors or anything in the console when you run it?
Though actually I'm not sure if you can access the text from TextMeshProUGUI itself. I tend to use TMP_Text anytime I want to edit the text. Don't quote me on that though (I don't think I've ever tried accessing it through the UGUI type) but could possibly be that
Please debug if UpdateScoreText is called at all. Breakpoints or logging will do
Also check for errors in the console, which could prevent compilation of newer code
guy i'm using this very simple player running code
{
playerSpeed *= 2f;
}
if (Input.GetKeyUp(KeyCode.LeftShift))
{
playerSpeed /= 2f;
}```
it kinda work when holding the key but i feel like this code gonna going to break any time soon. do you think this code is ok?
yep its being called and no errors in console
nope
im frying my brain
i tried everything
Huh. And the score Text variable is assigned to the correct one right? (I've had it before when I've spent ages tryna work out why my text isn't showing and it turns out I had the TMP_Text variable set to an invisible component 😭)
this my first game i have no clue what im doing icl
Now add Debug.Log("", scoreText) and click the console message that appears
Does it point to the correct component?
And also, is this the component actually written to the UI?
Looks good to me. A couple potential things though:
If there's ever a case where somehow it registers like the get key up twice but get key down only once or something (seems unlikely but it could potentially happen if Input is ever switched off for whatever reason), then it could end up with the walk and run speed both doubling or whatever. I would recommend setting it to specific values
I would also suggest using the new input system. Not necessary but it's definitely useful for adding and changing bindings if you ever wanna do that in the future (plus if you use PlayerInput components you can much more easily pause the game with anything not tied to deltaTime by switching them all off)
This works, assuming you don't change speed elsewhere. It breaks as soon as playerSpeed is mutated anywhere else
Ah lol very fair tbh. What does your score Text component look like? Is the colour set up right (eg the alpha not being 0) and does it display the text if you enter it manually?
Instead, set up a system of decimal speeds and get the average from them
So base speed 1, then sprint speed 2, final speed is 2
When anything mutates player speed, apply this list of modification, and use the final result as the speed
For example, slimy floor slows you down with 0.75
List is now base 1, add sprinting 2, remove slimy floor 0.75
Final speed is now 1.5
Also, what is its not displaying in the screen?
Is there no visual indication of text at all, or is there text but it doesn't update?
https://youtu.be/6Ai0xg6xTUk?si=tiFtvSInPkJHFYRX i follow this tut and my enemy is somehow at the speed of light
In this video, you will learn how to make an enemy object that will follow your player. The first thing you need to do is to make a cube that will resemble an enemy. I have set this cube to be red colored, just by making a material and choosing the base color to red. You can also download the script files.
DOWNLOAD THE SCRIPT: http://github.com/...
I even increase mass and decrease speed
please do not post photos, use screenshots
And your code? This is a !code channel after all
📃 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.
enemy follow script
read the bot message
firstly why are you using SetDestination EVERY frame?
whatthe tutorial said
how would i fix that?
think about it.
irl, if you have to go to several places at what point of your journey do you decide where to go?
start
exactly, not 200 times per second
I'd argue that it's not quite so simple in this case as the AI is moving to the player, which would theoretically be moving so you would have to call SetDestination at other points to move to where the player now is. But yeah ideally using something other than Update because that's probably not very preformant
hes still zoomiung off at the speed of light
also, if this code
transform.position = Vector3.MoveTowards(this.transform.position, targetObj.position, 10 * Time.deltaTime);
is from a tutorial, bin the tutorial because it is a waste of space and find another one
Also what object is your followscript on?
the enemy
@azure bridge?
I swear this whole day has been people asking something and then just disappearing without a solution
I think both scripts are attempting to do the same using different methods (one using the navMesh and one using transform) so then the movement from both kinda add onto each other if you're using both
very common in the yoof, attention spans of the proverbial knat
Judging from a quick glance at the tutorial anyways
the enemy follow script doesnt have aspects of moving the enemy only locating the player tho?
Which is a shame because today is one of the few days where I actually have extra patience for everything 
From what I can tell, the follow script is updating the enemies position every frame to move towards the player
Which is what the navAgent stuff is also doing
good plan, 3rd of Jan is a good day to do it, means I DON'T have to do it for the next 365
so what would i need to do to fix
Presumably remove the follow script and just keep the nav agent one on the enemy
you should first figure out what you're actually trying to do here
The enemy follow one
Does the enemy slide directly towards the player, or does the enemy use the navmesh to navigate towards the player?
You probably don't want to be doing both
guy what does this error mean?
NullReferenceException: Object reference not set to an instance of an object
Unity.PlasticSCM.Editor.ViewSwitcher.OnDisable () (at ./Library/PackageCache/com.unity.collab-proxy/Editor/ViewSwitcher.cs:205)
Unity.PlasticSCM.Editor.PlasticWindow.ClosePlastic (Unity.PlasticSCM.Editor.PlasticWindow window) (at ./Library/PackageCache/com.unity.collab-proxy/Editor/PlasticWindow.cs:1096)
Unity.PlasticSCM.Editor.PlasticWindow.OnDisable () (at ./Library/PackageCache/com.unity.collab-proxy/Editor/PlasticWindow.cs:283)
UnityEditor.GenericMenu:CatchMenu(Object, String[], Int32)
the Version Control package is throwing up again
It means there's a bug in the PLasticSCM / Version Control client package
how do i fix it?
You don't fix it. Unity needs to fix it
lets say i make multiple enemies, would i need to do anything or can i just duplicate this enemy?

good advice
but -- as a rule, if the enemies aren't fighting over a shared resource, duplicating them will work just fine
if in doubt actually read the error message, this 'Unity.PlasticSCM.Editor.' tells you where and what and that it is not under your control
So it would break if you did something ridiculous like this
the only thing i Rember before this error happen is i spam on the undo history tap
...actually, I'd have some trouble writing an example
maybe i'm clicking to much
you do realize you are making a game not playing one?
i know
but i'm trying to undeleted an object
so you do thing with consequence not just 'spam a function'
no, wrong, this is NOT a game
ok i reset the unity now everything fine
this is a pretty weird response
mashing undo should never cause the editor to malfunction. it should behave exactly correctly.
if you want to do game dev, or any kind of dev for that matter, you must realize that every single keypress you do matters and so you must know what it does BEFORE you do it
ok understand
if i use == operator on class with the overload for that operator, which overload is chosen, left hand side or right hand side?
rofl, only if undo has been implemented correctly which, in the case of Unity, it never is
What do you mean by that exactly? "left hand side or right hand side"?
no, 90% of Unity functions and Assets do not implement undo correctly
Foo x = new();
Bar y = new();
if (x == y) {
}
Who wins?
Yeah this, Foo and Bar both overload ==
well that depends
what do the overloads look like
which types do they take?
and what's the relationship between Foo and Bar? Is there a conversaion operator between them? Is one a derived class of the other?
Is there any documentation link to the exact rule for that?
I mean it will pick whichever one it can coerce the types into
I assume you didn't define it as:
public static bool operator== (Foo obj1, object obj2)```
presumably you did
public static bool operator== (Foo obj1, Foo obj2)```
maybe it is better for me to just look at the exact rule for it but i haven't found it on google
Basically the question doesn't have enough information
we need to see the type definitions in question
but it doens't work any differently than any other function in terms of overload resolution afaik
same as:
public void MyFunction(Foo f) {}
public void MyFunction(Bar b) {}```
suppose both of the overload have the same type, which one is selected
it will be a compile error
assuming the types are not related
if one type is a child of the other then the parent class one will be chosen
Hey there, i have a question.
I have a public float variable named motor_torgue with value of 20f. I would like to change this value in my game menu (on other scene) via input field method. How can i do that please?
because the parent cannot be coerced into the child automatically
Uhh nvm i only get more confused instead of getting the answer. I better off reading ecma c# specification
set up a listener for the input field that sets your variable
Okay, will try. thanks!
public void OnTorqueFieldChanged(string input) {
if (float.TryParse(input, out float parsed)) {
motor_torque = parsed;
}
}```
For example
so, first, at least one parameter of the operator method must be your type. You can't do this:
public class Foo
{
public static bool operator ==(object lhs, object rhs)
{
return true;
}
}
second, the order of the arguments matters. If you do this:
public class Bar
{
public static bool operator ==(Bar lhs, object rhs)
{
return false;
}
}
then the compiler will not find it if you do this:
if (foo == bar)
It only knows about an overload that takes a Bar on the left-hand side.
What Praetor said & I would recommend changing the input field settings. Can't remember exactly what it is but you can change what it accepts as input, and you should be able to confine it to only numbers iirc. Should prevent the player trying to input anything that wouldn't parse
third: the compiler will pick the most specific overload possible. If Bar derives from Foo and both Foo and Bar define an equality operator with themselves on the left side, then this will pick Bar's method:
if (bar == foo)
If there is no most specific method, you'll get a compile error
Thanks for the additional info. I am learning how to use input fileds right now at all and i will try your suggestion.
sorry was eatingim back
let m try
Good 😠
did you bring enough to share with the class
may i ask you a question?
You can ask the whole class the question 🫴 https://dontasktoask.com/
Assuming it's coding related, of course
ok, just a habit
Well, when my body have 0 degrees z rotation, i give him velocity 75, 0, 0. How to do, if your object have another z rotation (not a 0) it will be given another velocity. As an example: if my object has z rotation = 0, it will get velocity 75, 0, 0, but when it will have x rotation = 90, it will get velocity 0, 75, 0
rotate the velocity vector by the object's rotation
yeah, just multiply the rotation with the vector
Vector3 rotated = transform.rotation * original;
e.g.
Vector3 localVelocity = new(75, 0, 0);
Vector3 rotatedVelocity = theObject.transform.rotation * localVelocity;```
(beat me to it)
or the more "formal" way:
Vector3 localVelocity = new(75, 0, 0);
Vector3 rotatedVelocity = theObject.transform.TransformDirection(localVelocity);```
🙂
(The difference is TransformVector would modify the vector magnitude if the object is scaled)
ow, okay... im a rookie in unity, sry...
@burnt vapor i did the debug thing what am i supposed to check i dont understand
in the console it writes score: 1 when i get it
its invisible i cant see nothing of the text
This stuff isn't obvious at first glance :p
it does but only in the scene
My main concern was how you were asking about a really fussy detail (exact rotation angles) instead of thinking of the bigger picture (shooting a projectile in the direction you're facing)
i thought it will be work with sin and cos
You can do that too
But I do almost no triginometry in my code
You've got lots of methods in the Vector3 and Quaternion types
Check this out, for example...
Oh weird. So you can see it in scene View but not game view? What do your anchors look like on your object?
i tried cos and sin, but it gave me a lot of errors
this?
Vector3 flattened = Vector3.ProjectOnPlane(entity.transform.forward, Vector3.up);
yaw = Vector3.SignedAngle(Vector3.forward, flattened, Vector3.up);
Vector3 rotated = Quaternion.AngleAxis(-yaw, Vector3.up) * entity.transform.forward;
pitch = Vector3.SignedAngle(Vector3.forward, rotated, Vector3.right);
Given an entity's look direction, I can recover the pitch and yaw needed to get that exact direction.
I use this when the player takes control of an entity
No trig!
thanks, gonna learn it... it's really nice of you
Yeah. I'm not entirely sure but with a quick glance, it looks like your text element will be being positioned out of the screen with the current anchors. If you switch it to be the centre of the screen (click the anchor, then alt+shift click the centre one should automatically position it as well), does the updating score text show then?
it disappears now LOL
It may also end up positioned weirdly based on your canvas UI Scale Mode. I tend to set it to Scale with Screen Size, set the reference resolution to whatever my display resolution is, then get it to match height over width
Oh wait what. As in just the game view or scene view as well?
every
it doesnt disappear but like
it goes somewhere to ofar
i think
mny braincells are disappearing
Ohhh right hmm
u can see it in scene (i f i dont anchor it like that)
So it's anchored in the middle with a position of 0,0,0 right? What's your current game view display resolution at?
so close to fhqwhgads
Oh wait are you trying to get it to show screen space or world space?
Is this attached to a Canvas?
if so, is that Canvas in "Screen Space - Overlay" mode?
@leaden pasture i want it to be shown anchored at the camera like if the player moves the score doesnt
It might not even render at all then
yes it is
In that case, the apparent position in the scene does not matter
