#💻┃code-beginner
1 messages · Page 350 of 1
no, show the current code and the console
totally irrelevant, do what I asked
the current code is the same as the hastebin i posted above
then you did not add the debugs as asked did you
i really did
oh wait i just realized..
i put the debug in the if statement by accident lol
if you really did the code could not be the same as before could it
ok now it outputs enemy
i just fixed it
!vscode
wait i think i found the issue, its the transform.position in the raycast
which is meaningless information as you have not even said which object this script is attached to. Please try and think about your questions and supply ALL relevant information
its attached to the enemy gameobject obviously
i thoght that was self explanatory
not obviously, I dont know your setup
i sent a screenshot, i thought that cleared the context up
not in the slightest, it does not even show an inspector
@frank zodiac would wait till someone else comes on. I've only been on this chat for about 10 mins and get the impression some of the people on here have an ego problem .
okay then next time ill try to clear things up 👍
lol i dont mind i just need urgent help
ok i fixed it thanks for your help chat
Steve, can you help me now?
No, I dont do Unity Ad's
Oh.
Is there an open-source asset to manage color palettes?
If you mean in editor, you can save colour palettes already in Unity
You can use scriptable objects for that, if you need multiple and switch between them
Otherwise, SOs are the best way to go ^
Yes, I mean for managing colours for different elements.
Ok. I'll look into that. Basically the SO will have different public fields and I'll add a ColourMgmt component to associate an SO with a GUI element.
anyone know why my navmesh agents would be walking circles around their target rather than stopping there
#🤖┃ai-navigation will help better
[to now deleted question] Ask in #archived-shaders
ty
what is wrong with the code
my door is clunky and i can still close it when it is opening
when its opening and i press E on it, it plays a sound then waits a bit and starts closing
Start by verifying the length of your OpenDelay value
it is 1
actually 1.2
those are placeholder sounds
this is from a scriptable object
so what does 'E' do?
E is what i as the character press to interact with the door
I know that but show the code for it
Is Toggable being used elsewhere?
toggleable does not get used anywhere else
then the problem can only lie with your OpenDelay
yes, and? If the animation takes longer than 1.2 game seconds you have a problem
it takes less
it takes 1
then what you describe is, literally, impossible
If I were you I'd rely on the animation instead of magic numbers to know whether an action has been finished. Animation events can be a solution
maybe you should be using WaitForSecondsRealTime?
Then it's Debug.Log time because what you say cannot be true somewhere
i think its to do with the animator
There is certainly nothing wrong with the logic of your code
except the wait is dodgy as @short hazel said
yeah using the animator is probably the better way to go but its fixed now
thankyou for helping
Is there a method to simply open many inspectors in individual windows at the same time? I want to select 3 GOs, right click, and open them in separate windows (not tabs).
it was the animatorcontroller which i didnt know how to use
Right click the header of the Inspector tab and you should be able to pop it out in a new window and/or lock it (allows you to select other stuff without affecting the Inspector)
I know that. But I want to open 10 SOs and side them side by side. Instead of manually doing this ("right click" > "properties" > select next SO and repeat), I would do it once to open immediately 10 windows with the properties.
Why? Multi-edit is a thing, you can select multiple elements and edit properties on all of them at the same time
At least that works on GameObjects
You only see where properties are the same. I want to see them side-by-side to see the progression, e.g., as damage increases from one enemy to the next.
You can't do this automatically
https://gdl.space/inoyamunat.cs hi im trying to get the top parent but it seems to be the wrong object
top parent should be npc ss but it returns player
just use transform.root
sorry please ignore sorted it
quick question, so when I slide I want the camera fov to change. Not sure why my code isn't working if someone could take a look. I was able to save, but something is preventing the fov from changing
still use transform.root
will do thanks steve
You're only changing the FOV once in StartSlide
You're not changing it each frame during the slide
you saved me so much code thanks
is this what you mean, I moved it into the update
No because that's still only happening during a single frame in GetKeyDown
Trying to build a 2d sidescroller with procedural generation and subterrainian caves etc. not gonna lie it's been a bit hellish and I can barely get off the ground with this. Does anyone have any recommendation to some solid learning resources on doing this? I went through probably 10 full video tutorials on this and in the end I do get various versions of just terrain, sometimes cave generation, but then it gets infinitely more complicated when I'd want to add something they dont show like ores, items, etc randomly on the walls
thank you, I fixed it
in unity a singleton class gameobject can be in the hierarchy be children of another? or must be root in the scene?
The singleton pattern in a pure C# thing, so the placement in Unity does not matter. Unless you plan on persisting the object through scene changes, in this case it has to be a root object otherwise DontDestroyOnLoad() throws an exception.
is there anyway to disable navmesh control along the y axis?
like I want the y axis to be controlled by a different script
hey, im currently building a 2d platformer and got a "Bubblemeter" which is like a kind of mana that gets reduced when hitted by an enemy
https://gdl.space/dekojobini.cs
my problem is that when i collect a bubble it adds one bubble level and updates the ui element correctly now when i get damaged it reduces the bubble level correctly in other therm i have 0 bubble level then i got 1 and after being damaged i got 0 again
But if i collect another bubble wich calls the add function i somehow get 2 bubble level. i found out that the bubble level before adding is 1 but in the inspector it shows 0
thanks for helpers in advance :)
Is there any way to obtain some text from a Input TextMeshPro without the ASCII 8203 character that appears at the end? I obtain the text doing inputText.text where inputText is a TextMeshProUGUI . Even a Trim() over this doen't remove it. I can do a Replace() after the Trim but I want to know if there is a better way or I'm doing something wrong
Yes you take input from the TMP_InputField itself, not the underlying Text it uses for display
public TMP_InputField inputField; + inputField.text
Ok, thx. Changed and working
The code looks pretty robust, you'd need to add some debug logs to see how many times AddBubbleLevel() gets executed. It's not possible that it increments twice at the same time
1 time :(
Make sure you have "Collapse" disabled in the console
And that there is only one instance of this BubbleMeter script in the scene
oh yeah i see
ty man you know how to prevent that it gets executed twice?
https://gdl.space/vuyosaliha.cs
thats the bubble that calls the add function
Looks pretty packed with checks too. Do you have two of them on the same object by accident?
Although you do not call DeactivateObject() anywhere here, but it might be done from another script since it's public
mh il check that thanks for your time
is there a way to make a 3D character move in a 2D way?
yes, dont use the z property in position
use sprite renderer
Heyo quick question I had, what do you call that feature in 3D games that will make an object slightly transparent so you can see the player model?
I've been trying to find some info on creating that effect for my game but i'm having some trouble. thanks for your time. 
you should post an ingame example of what you mean
ooh good idea let me get some!
I mean like how objects fade away like this when closer to the camera so the player can still navigate the world better, i was just wondering if there was a name for this feature in general.
Vector3 newDirection = new Vector3(0, 90, 0);
float angle = Vector3.Angle(oldDirection, newDirection);```
'angle' is always 0. Why?
not in the y axis?
i hope someone is able to help
All in the Y axis
They both point up, one is just twice as long as the other
As such they have zero degrees of difference between them
the only way i can think of seems super unoptimal
shader code seems the obvious solution to this. Perhaps ask in #archived-shaders
ah thank you i'll try asking there then
What are you expecting is the angle between them? Try drawing both of them on a graph and see what the difference is
I was thinking of them like the Vector3 of the transform.rotation.eulerangles
where y is a rotation axis
No, they're directions
when i think of them as points on a graph its obvious why my code didnt work
Two direction vectors like (0, 1, 0) and (0.7, 0.7, 0) would be 45° apart
yeah I realize that Vector3.Angle() is not appropriate for what I was trying to do.
anyways I think I finally just decided after a year of thinking about it and failing at trying lol that I'm just gonna make the tilemap by hand instead of procedural generation. Kinda makes it a little more unique of an experience anyways. If I keep going this way I'm never gonna get anything done with this game so figured it's not the worst thing in the world to do
What is the best way to learn unity(C# i think)???
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I'm doing some coroutine stuff to add a death screen right now, and I can't figure out why it isn't working.
I have this coroutine that is being called when the player should die, looks like this right now.
public IEnumerator Die() {
Debug.Log("Starting coroutine, awaiting finish");
yield return StartCoroutine(GraphicUtils.FadeToAlpha(fade, 3, 0.9f));
Debug.Log("Coroutine complete, calling all other coroutines.");
}```
This should, in theory, fade in a simple black screen, then fade in like buttons and stuff.
I know for a fact GraphicUtils.FadeToAlpha() is completing because I have some debug lines for it:
```cs
public static IEnumerator FadeToAlpha(Graphic i, float t, float a) {
Debug.Log("FadeToAlpha called, t = " + t + " a = " + a);
...
Debug.Log("Completed!");
}```
But the console never logs "Coroutine completed". Am I doing something stupid?
2 obvious ones
- GameObject/Script is disabled/destroyed
- timeScale is being set to zero
My timescale is never changed, and I have confirmed the gameobject/script is still alive with a debug line in Update
Plus, stuff still continues moving in the background
I'm guessing no errors in console
No errors.
Everything should theoretically be working perfectly
Idk what i'm doing wrong
Does stuff break if the original caller of the coroutine is destroyed? Because that does actually happen
One moment please
yes it does, see point 1
I see
didn't realise that
If that's the case, why does the fade coroutine not break then?
because it is static
!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.
sorry to ping i was looking through chats but FOR REAL
what is it with the unity community that makes every comment either sarcastic snide or just rude 💀
you seem to have a function that adds score already, so all you need to do is call that function whenever u run your script that spawns or deletes obstacles
since you already have it set up as a singleton its quite easy
lets say for example you have a script that deletes the obstacle
public Class HandleObstacles : MonoBehaviour
{
public void Start()
{
// Code
{
public void Update()
{
// Code
{
public void DeleteObstacle()
{
Score.instance.AddScore(5);
Destroy(gameobject);
}
}
you would call upon the function through the singleton like shown above
hope this helps
if you are asking about how to destroy the obstacles I would need more context as to what you are trying to do
wtf is that link? Why change paste sites?
fixed
I see nowhere there where you even try to add a score
Suffix gave you the exact line of code you need to use
yes I already gave you the answer but I wont write the code for you !
did you follow the instructions it said
You need to enter the code and name it as what the code you want to assign is named
if you get what i mean
i think i explained myself wrong
show your console and the contents of the clickred script file
is it the name clickred
caps
clickred is not the same as ClickRed
although if you are using 2022.2+ that isn't actually the issue
When i used unity to make my first proyect i had this issue and it was so hard lol
Ill be honest I just dont understand some of these errors when I fix one another appears
lmao
ok no im still getting the error
show your console
very cool 👍
you fixed a problem that i had for 1 year and was the reason i left unity for 1 year in 10 minutes
Im sure something will come along and send me off for my 1 year training arc
Is there a way to get clockwise / anticlockwise information from Quaternion.Angle()?
Like I said man think it's like an ego thing haha
There was one guy I just ended up blocking because their attitude towards some of the beginners on here asking questions was getting old real quick haha
Think for the community aspect might be more helpful using like Brackeys server, Gamedev.tv or like one of the other large game dev discords
is there a way to add another string to the GetAxis? I wanna add "JoyX" as another option for controller
They're defined in the input manager:
https://docs.unity3d.com/Manual/class-InputManager.html
float mouseX = Input.GetAxis("Mouse X");
float joyX = Input.GetAxis("JoyX");
// Combine the inputs. You can adjust this combination
float combinedX = mouseX != 0 ? mouseX : joyX;
Quaternion offsetX = Quaternion.AngleAxis(combinedX * turnSpeed, Vector3.up) * offsetX;
Then define joyx in the input manager
Like literally if you dint saw like 50000 lines of the unity documentation they will not help you
Can you two bond over this hissyfit in DMs? If you're unhappy with how people volunteer their time here, then you're free to leave.
point proven 🙌
Yes yes, something about ego. Move on.
Maybe don't volunteer your time then if you're going to have a negative attitude to beginners asking questions is what I was pointing out...
You're free to volunteer your time and help how you like. 🙆
And I don't have a negative attitude towards beginners asking questions. But you having a little tantrum about it isn't productive in this channel. Unless you have a question or are actively helping people, please keep it to yourself.
im getting the print log fine, but the audio mixer isnt actually reflecting the changes. this error only happens on startup, when the volume changes from player input it works as normal.
private void ChangeVolume(float sliderValue)
{
print("Changed Volume to" + sliderValue);
float volumeValue = Mathf.Pow(sliderValue, exponent);
audioMixer.SetFloat(channelName, Mathf.Log10(volumeValue) * 20);
PlayerPrefs.SetFloat(channelName, sliderValue);
if (sliderValue == 0)
{
audioMixer.SetFloat(channelName, -80f);
}
}
hi, i would like to lerp between score values but when i collect two coins (call function again) before lerp is finished it doesnt work properly. i would like to make it lerp between current score and final score but final changes before it finishes lerp and current score ``` IEnumerator CoinIncrement()
{
targetScore = 10 + previousScore;
Debug.Log("target score " + targetScore);
while (timerCount <= 1)
{
timerCount += Time.deltaTime * 0.5f;
amountCoins = (int)Mathf.Lerp(previousScore, targetScore, timerCount);
yield return null;
}
previousScore = amountCoins;
timerCount = 0;
yield return new WaitForSeconds(0.2f);
}```
This could be due to the order of operations when your game initialises.
I would personally use MoveTowards instead of Lerp so that it's moving at a specific speed instead of within a specific time. Then you can just do the MoveTowards in Update instead of using a coroutine and just add to the targetScore. then it will just always be moving to the target score instead of needing to start a new coroutine for each time you increase the score
oh and that WaitForSeconds at the end of the coroutine is pointless
Can chat confirm this? I thought that's what coroutine is for. So, where would you use WaitForSeconds?
What's your start method like ?
i managed to fix it by running it in start instead of awake
idk why that fixes it?
im assuming order like you said
In your code, nowhere. You don't need to add a delay.
And yes, if you're going to be moving towards a dynamically changing value, you don't want to use a coroutine. Doing it in update will be a lot easier.
Thanks
Could be the object dependencies it has too. At least it's working in start method
Thanks
You would normally put it before something you want to happen after a delay. In the code shared, your code waits 0.2 seconds, then does nothing, then ends.
Doing nothing right now is pretty much the same as doing nothing in 0.2 seconds
btw, code:
```cs
public class CodeThing
{
public float test;
}
```
public class CodeThing
{
public float test;
}
Works like a charm, thank you
No worries 🤠
whats the difference between activeself and activeinhierarchy?
Active self checks if this object is disabled, regardless of whether any parent objects are enabled or not.
Active in hierarchy checks if this object is active along with all of its parents
Extract the angle and axis from the quaternion. Then determine the direction of the rotation based on the angle and axis. Use Quaternion.ToAngleAxis to help with it
I ended up using Mathf.DeltaAngle() with the transform.rotation.eulerAngles and building around the -179 to 180 it returns, because Quaternions are scary and confusing 🤣
Haha fair enough, if it works then don't change it
i did also think that ppl are too rude sometimes
quick question, i made a script that will pause/unpause the game with the esc key and i was wondering if i need to add it to an empty gameobject for it to actually work (like be active)
any script that is not on a gameobject will not function
so an empty is the best idea for a pause menu?
if you disable the gameobject it wont work either. youll need a empty one, or use the canvas object
i think for things like that, people will usually make an empty named gameManager to put those scripts in
ohh thats smart
you could also have a parent pause menu object with your pause settings and escape listener, under the parent is the actual panel
thanks guys
https://www.youtube.com/watch?v=_H4azo71wOU&list=PLy1Xj-4F5G_cytIH8by-bZ9TVj5qKMlZn&index=9
I've been following this tutorial series trying to learn Unity and I'm trying to build upon it by adding UI icons that appear depending on the NPC via serialize field, I've been trying for a while but nothing I did really seemed to work all that well. I'm new to all this and if anyone can help it'd be greatly appreciated
My computer fan was screaming in this recording :( Getting a new computer soon to record better quality audio and video!
Chapters:
00:00 - Continuing the implementation
11:25 - Testing
12:10 - Debugging
Links
Discord Community: https://discord.gg/cVPCpGUSYW
Character Sprite: https://github.com/kiyama14/tutorial-art
is there anyway to control the vertical position of a navemesh agent
nah since they get stuck to the ground right
you could maybe disable the navmesh right when you wanna do your thing
or like
well like i made a monster neck and I want it to follow the player , but using a nav mesh it just drags along the floor, and using a base offset it cant adjust its height at all
increase the height of the navmesh?
Any Method to let Linear X max value become 3. I tried edit the key's value to 3 (like left's picture)but not working
I want the navmesh to be able to go up and down
sounds like you should do that with animations
man
or
can I move the object
that is following the navmesh
without moving the navmesh?
Good morning/evening all! The versioning of Unity is a smidge confusing going into the Unity 6 release this year and the current LTS dropping out of support.
I am starting a new project and have heard that the LTS is the go, which makes sense. But given that the LTS is about to go out of support would it be better to use a more recent version like 2023.2.x? Or would it be better to hold on that, use the current LTS and wait for Unity 6 LTS to release?
LTS versions get support for 3 years
2022 LTS will be supported for at least 2 more years
Unless I missed some special announcement about it?
Nah I think you're right, going back and reading again:
"We’re committed to supporting 2022 LTS releases with biweekly updates until mid-2024, after which updates will be monthly until mid-2025 (two years after the initial release date). These updates will only cover fixes aimed at improving the stability of the product to enable users to ship their projects."
I guess my coffee deprived brain read "until mid 2024" then totally switched off.
thanks for confirming though
do you have a whole monster and then a navmesh agent on its neck
I have the whole monster, with the navemesh on its head
so if the head goes up, the rest of the monster will too
but I figure out how to make the head move vertically
when using a navmesh
howd u do that
wym
this i mean
mb my brain is not working
but I NEED to figure out how to make the head move vertically
originally I had a basic look towards and movetowards script
and i could make it work
but idk what to do using the navmesh, since I can't just do movetowards anymore
it like overrides it or something
i dont rlly understand it
Your setup sounds weird, can you show a screenshot of it? It doesnt sound proper that you have an agent on the head only
on some things, doing it in lateUpdate can ovveride
^^ there
think i remember makin a navmesh agent fly away by overriding it wit the animation in lateUpdate
i will look into it
So maybe movetowards works too
nvm
alr ill try
wait a minute
I have my navmesh code in a different file then the movetowards stuff will it still work?
How does the rest of the body follow along?
A lot of moveTowards calls and LookAt and distance checks
wait it was transform.lookat that i overrided it with lateupdate not an animation
still try it
transform.lookAt works without an override... Ive tried that
but it doesn't rlly help my issue
doesnt seem to work
If you want custom movement you can always assign to the base offset at runtime. You can always take the path from the agent and do your own custom movement too
I have tried using base.Offset... since it technically moves the head vertically
it seem to break the neck code though
and the head starts moving freely
^^is this what you mean?
If I use baseOffset I need to to be able to constantly change
I have tried this
the head actually falls through the floor with that codw
Well I'm not entirely sure what you're moving it towards, but ideally you would have it raycast and check where the ground is.
moving the y val torwards the player
I was just using that to test
to see if I could even control the height
I will try raycast next ig
honestly your easiest solution is just gonna be making an animation which moves the visuals up and down, the visuals being a child object of some navmesh agent.
I was hoping to make the neck be able to reach through like small holes and stuff to get to you, is there any other way to still achieve that goal?
thats why im wondering if there is anyway to control the navmesh height off the floor
yk and making the neck not drag across the floor
yes maybe through a nav mesh link or just making your own custom movement which may at times use the navmesh path when it wants. Though im not entirely sure what the end goal should look like. I wouldnt say this is the easiest thing to code and make right
you mean coding it without or with very little usage of navMesh?
either way, because theres a bit of extra logic that you want ontop of just a navmesh agent moving. I think for the small holes, a link should be fine but you may need custom movement so that the body doesnt look weird going through walls. If this is even visible during the game
any recommended tutorials for navMesh links, I started tinkering with navmesh... today....
so Im not very familiar with ANY of this
there are the docs, they are quite simple. it just connects 2 areas of the navmesh so an agent can go along the link.
also some tutorials you'll find online. ive never watched any on links so cant really suggest. Its just what i imagine will be the easiest solution for a small hole since setting up the navmesh surface to include the hole as a valid surface will be annoying.
ty
how can i shake the camera and then it make look like its shaking the ui? im using screen space camera
@polar acorn this could serve a purpose when chaining coroutines such as:
private IEnumerator Nothing() {
Debug.Log("Nothing");
yield return new WaitForSeconds(0.2f);
}
private IEnumerator Something() {
Debug.Log("Something");
yield return StartCoroutine(Nothing());
Debug.Log("After Nothing");
}
private void Start() {
StartCoroutine(Something());
}
Although it would probably be more clear to put the wait in the Something() method.
Can someone tell me why is the touch input working in unitys game/simulator but not on an actual android device?
board.cs
https://gdl.space/qiyigixemu.cs
I'm ngl I've never seen Touchscreen.current.position
Usually I use the Input.GetTouch(i)
Might check it out later
@sullen galleon
yeah its the new UnityEngine.Input thing

i like how people are still calling it the new input system depsite it being nearly 5 years old
i thought its like 2 lol
nope, released with 2019.1 in october 2019
And that's in stable too
If beta is counted it'll probably be earlier
The current interface is pretty confusing ngl
well im just gonna copy paste this in input system cause ive been trying to get touch controls done for over 2 days now i think
Ive been following a lot of tutorials but haven't been able to set up actions for touch screens with Input System
dreadful
Remember to have Input Manager enables too in that case
well its only just default in unity 6 so ig for some people it is new
Huhh
funnily enough it kinda worked when i put some type of mouse controls in a long time ago when i was starting
wait for them to release another, then we can have the newest input system
in unity 6 the "new" input system is the default input system
is it even installed by default? i thought it was still an optional install even in 6
its optional, but installed by default
Instead of enabling it, you have to disable it
to my knowledge
The days of Input.GetAxis("Horizontal") are over
i mean im using unity 6 as we speak and it was enabled by default
I'm sure we will eventuallly
are you sure that wasn't some package or asset you installed that did that? like the starter assets
I mean I created a new project and I already had an input asset so yea
i'm going to test this right now, because to my knowledge it is still an option package that is not installed by default, like cinemachine
also has a project-wide "default" input asset with some keybindings already set up
ok i definitely dont have that in 2022.3.16f
no it's new with unity 6 I believe
It looks like they're also finally starting to depreciate the Built-In Render Pipeline too
i doubt BiRP is ever going to be fully deprecated, but it isn't one of the default templates now, yeah
Why would it ever not be fully depreciated?
I use it because every time I try to set up my own post processing in urp I fail miserably
In birp I can just Camera SetShader
also @slender nymph just created a new project to double-check myself, yup it's default installed now. You can remove it, the package isn't locked.
What about the settings for which Input to use? Is it Input Manager, Input System or both?
just confirmed myself too, it is installed by default. and active input handling it defaulted to Both
yup
Even when you install it LTS now it gets set to both, you always had to explicitly deactivate the old one
also seems to be defaulting to dx12 for windows graphics now and .net standard for api compatibility
dx12 for HDRP it must be, I'm in URP and it's dx11
I did try HDRP and it was dx12 I remember.
ah yeah, i guess i selected the hdrp template by accident. meant to select urp but oh well lol
Time for me to ask an actual question. I think I'm going insane because somehow I'm getting numbers higher than I think they should be.
public class TerrainHeightPassPerlin : TerrainPass
{
public override float MaxHeightDifference => _heightMultiplier;
[Space, Header("Perlin Noise")]
[SerializeField] private float _perlinMultiplier = 0.2f;
[SerializeField] private float _heightMultiplier = 1f;
[SerializeField] private float _heightSnapping = 0.25f;
[SerializeField, Min(float.Epsilon)] private float _minStrength = 0.25;
private Vector2 _offset;
public override float Process(float n, Vector2 pos)
{
Debug.Log($"Recieved: {n}, {pos}");
float r = Mathf.Max(n * Mathf.PerlinNoise((_offset.x + pos.x) * _perlinMultiplier, (_offset.y + pos.y) * _perlinMultiplier), _minStrength);
Debug.Log($"r: {r}");
return Snapping.Snap(r * _heightMultiplier, _heightSnapping);
}
public override void Reseed()
{
Unity.Mathematics.Random r = new((uint)UnityEngine.Random.Range(1, int.MaxValue));
_offset = r.NextFloat2(new float2(-2000, -2000), new float2(2000, 2000));
}
}
when n is 1, pos is some vector where both x and y is in the range [0, 40), Process() can return numbers like 3.2. I'm pretty sure PerlinNoise returns 0-1 (or numbers slightly out of that range), so it can't be that. Could the snapping function really be snapping a number really high like to 3.2?
oh I forgot to change the numbers to their proper values one second fixed
I can see here that it appears to be snapping 0.6308... to 3.2?
that is 15 seconds later and in some completely different code. are you sure your console is not set to collapse and you aren't doing anything to the values being used in those 15 seconds?
this is the loop that highlighted debug.log is called in:
pos.y = 1;
for (int k = 0; k < terrainPasses.Length; k++)
{
pos.y *= terrainPasses[k].Process(pos.y, new Vector2(pos.x, pos.z));
Debug.Log($"k: {k}, pos.y: {pos.y}");
}
When k is 0, pos.y is 1.
shoot hold on
I mean I can visually see that the numbers are going out of the range I think they should be in, but let me check
it was set to collapse, I usually have that off, my bad. It seems to snap 0.8186... to 1.8 however, even when the height multiplier is set to 1.
show the log before that too
ok im having a skill issue reading logs, sorry boxfriend.
you've got three logs that are important here. two are in Process and the third is in that loop. show all three of those
have you confirmed that _heightMultiplier is the value you expect it to be?
yea it's on a scriptable object, TerrainPass is just this:
using UnityEngine;
public abstract class TerrainPass : ScriptableObject
{
public abstract float MaxHeightDifference { get; }
public abstract float Process(float n, Vector2 pos);
public abstract void Reseed();
}
change that second debug in the Process method to this: Debug.Log($"r: {r}, heightMultiplier: {_heightMultiplier}, snapped value: {Snapping.Snap(r * _heightMultiplier, _heightSnapping)}");
time to use the debugger then and set some conditional breakpoints that will break when a value is outside of the expected range
ooh yes i forgor about conditional breakpoints
But I'm not even sure if snapping is the issue. Perhaps I was just being stupid. This is the visual problem I have, the scale is somehow 16 even though the height should at most be 1 * 5 (since I have two of these scriptable objects) I thought
it's not going to be the snapping that is the issue. it is going to be the input values and the math you do. so you'll need to figure out where the values are that you do not expect
but also with your previous log where r was 0.667 and the pos.y ended up being 3.4, if you are multiplying r by 5 it will by 3.33 snapped to the nearest 0.2 is 3.4 so the math and snapping was all correct with that set which indicates the issue is something on this line: Mathf.Max(n * Mathf.PerlinNoise((_offset.x + pos.x) * _perlinMultiplier, (_offset.y + pos.y) * _perlinMultiplier), _minStrength);
hmm skill issue with logs on my part. I still am not understanding how I'm getting 16 as a final value though, I've been going through it for a while.
Actually, I can't find a 12.4 here (final should 12.4 + 1), even with some new debug logs:
var c = _instantiatedWorld[i, j];
Vector3 pos = new Vector3(c.position.x, 1, c.position.z);
for (int k = 0; k < terrainPasses.Length; k++)
{
pos.y *= terrainPasses[k].Process(pos.y, new Vector2(pos.x, pos.z));
Debug.Log($"k: {k}, pos.y: {pos.y}");
}
Debug.Log($"pos.y before snap: {pos.y}");
pos.y = Snapping.Snap(pos.y, _globalPostProcessingSnapInterval);
Debug.Log($"pos.y after snap: {pos.y}");
c.transform.localScale = new Vector3(1, pos.y + 1, 1);
c.GetComponent<Renderer>().material.SetColor("_BaseColor", new Color(pos.y / _maxHeightMultiplier, pos.y / _maxHeightMultiplier, pos.y / _maxHeightMultiplier));
```They *are* set to a parent, but it's scale is 1, 1, 1.
you're searching for 13.4 but you never log that value, you log it before adding 1
yea the screenshot is of me searching for 13.4 but I quickly realized my mistake and searched for 12.4, I forgot to take another screenshot
hrmm.. how could it even be reaching such high numbers?
just use the debugger
yea
Maybe I am absolutely dumb for asking this but If the blue position is the object position + vector3.forward * distance; how could I calculate the green positions?
It just seems like there is probably already a method for that
you would rotate the direction by x degrees . . .
How do I rotate the direction from vector3.forward? Sry, I am just like abolutely dense rn
I am pretty sure I did something similar before but I just can't recall for some reason
thanks so much 😄
{
if (TownController.Instance.LoadingItem)
{
Debug.Log("Waiting for item to load.");
return;
}
TownController.Instance.LoadingItem = true;```
Any idea why this isn't preventing me from spam clicking?
does anything else modify the value of that variable?
nah, I have an async function in there that's causing it 😦
added an await, now it's working 🙂 weird
I Hate il2cpp.. it randomly gives me null obj reference when i start up game (Android)
in build ofc
there is no errors while building
you'll need to debug your build then. for android you'll probably want something like logcat to read the logs and see where the NRE is actually happening then you can investigate why
Is this a coding question?
True, my bad
Im having this issue with baking navmesh, which I believe it led the NPC clip through wall when playing
So when I try to bake my ground with no object involve, it baked fine, but when It have object, it can't be baked, I tried lower the ground without baking again and when NPC using navmesh, it chose the path with wall and somehow clip through it too.
In the video I try showing all the object is static, the NPC have rigid body too, so don't know why which happen, thanks for all the help
https://streamable.com/wngd82
You need to add a NavMeshObstacle to your walls and mark it as carve
you may need to reduce the Agent radius as well
thanks for the help
Helo I want to make a slot machine but im not sure how to go about it, do I have to animate every possible outcome
and then randomize which animation plays
easy option.
Make an array of all your sprites
Randomize those into separate arrays (one for each reel)
Step through those arrays and display the sprites one at a time
understood thank you
acually you can just make a prefab for a reel and then duplicate that for the number of reels you want
im assuming that means I make one of the spinny things and then duplicate it
yes a 'spinny thing' is a reel
bless
Hey, does anyone know how to tint/darken a ui gameobject and it's children? (I have a button with image and text, when clicked, I want all of them to darken)
By changing the alpha of the Graphic's Color, which uses rgba
Note that
each color component is a floating point value with a range from 0 to 1
Hi, thanks for the reply, I need to change the color rather than the alpha. However, if I change the parent ui gameobject color, it only changes for parent ui.
I see. Alpha adjusts the color's transparency. If you want to make the color lighter or darker, you'll have to increase or decrease each of the RGB values by a specific percent respectively
RGB represents Red, Green and Blue, and is respesentet in a range of 0 - 255.
So (255, 255, 255) is the most white, and (0, 0, 0) is the most black color.
If you have a color (200, 100, 50) and want to make it 2 times darker, you decrease its every value by 50%, which gives you
(200, 100, 50) * .5 = (100, 50, 25)
The Unity's Color has the values with a range from 0 to 1, so this will give you the color
(200, 100, 50) =~ (.78, .39, .2) * .5 =~ (.39, .2, .1)
And changing the color of the parent doesn't usually change the color of its children
I wonder whether there is a built-in Component for this. Anyway, you can make it yourself, which shouldn't be too complicated
hey i fixed the script now it works propertly but the text delete's it supposted to look like this but it shows only numbers
public void AddScore(int points)
{
score += points; // Add points to the score
scoreText.text = score.ToString();
highScoreText.text = highScore.ToString();
}
Why would you expect it not to?
You only set the text to your scores, so it will, obviously, just show them
dam
You have to adjust the strings you set you show the desired result, which, in your case, includes "Score: "
thanks
Is it 2D or 3D?
For 2D, you can look for rotation matrix.
Vector2 Rotate(this Vector2 vec, float radians)
{
float sin = Mathf.Sin(radians);
float cos = Mathf.Cos(radians);
return new(vec.x * cos - vec.y * sin, x * sin + y * cos);
}
For 3D, you'll have to use Quaternions.
Quaternion.LookRotation(your_vec, Vector3.Up /*This is fine.*/) * Quaternion.Euler(..., ..., ...) * Vector3.forward * your_vec.magnitude;
Below is my on collision code, the Gameobject this is attached to is a compound collider, does anyone know why this isn't working? (Let me know any details I can provide that could help)
private void OnCollisionStay2D(Collision2D collision)
{
controller.isInOcean = collision.Equals(playerCollider);
Debug.Log("Happens");
}
what do you expect this to do?
collision.Equals(playerCollider);
collision and collider are 2 different types so can never be equal
So, that doesn't mean the collision of the colliders?
no, of course not
Okay, thank you. I do have to ask, my goal is for a compound collider to act as a trigger. Once it is triggered by my character, it changes the function of the character through a boolean (isInOcean). How do you suggest I do this?
maybe, if youi looked at the documentation, you would see that Collision2D has a collider property
So if I do collision.collider.Equals(playerCollider), it would grab the collider of the other gameObject?
indeed
Unfortunately, it doesn't seem to function correctly. I made that change and once the player enters the compound collider trigger, it does not set isInOcean to true. Do u have any other idea on what could be the issue?
then you obviously need to Debug.Log the 2 objects so you know what you have hit
why are you checking if the colliding object is the player using Equals? compare the tag or check for a specific component type. your ocean thing shouldn't need a reference to the player nor the other way around
I mean, does it matter that much?
I have a question regarding box colliders. I want to attach this box collider trigger to the actual model but im not sure how to do so, any tips? I wanna have it attached to the player's arm
Its good practice, and once project becomes large enough it becomes spaghetti of references if you keep doing it like this
that depends, is your implementation currently working? if no, then what i suggested will work. if yes, then what i suggested will be better 🤷♂️
Lol ok
I think you add collider in armature no?
Yeah, it didn't actually fix the problem, but I get your point
maybe parent it to the bone?
how do i fix the options button in the home screen staying yellow?
yep just figured it out haha thanks!
https://hatebin.com/msewwjskqb how can i implement a dashing ability here? line 85 gives me an error and i dont know how to get around it
you can't assign a single float to a Vector2
i know that but whats a workaround to it
why not look at all of the other lines you assign the velocity and take a guess from that context?
oh wait i just realized how dumb i sound rn
put a log outside of the if statement to make sure that OnTriggerEnter is actually being called
i just need to make a new vector2
of if you are on 2023+ there's also the option of assigning just the X axis velocity
i should upgrade to 2023 tbh idk why im using 2022
but thanks
yooo a fellow ghazi lol
I've been trying to fix this all day and I just don't know how. I am making an FPS game and as you can see in the video when the player is moving the camera also moves along with the animations. I don't want it to move when the player is moving.I want the camera to be still for an example modern ware 3 when moving the camera doesn't move. If nobody helps me istg I'm gonna go crazy thanks.
never thought id see the day
This file looks corrupted. It did not embed, and does not play when I download a copy locally
I upload it to YouTube so it's more simple https://youtu.be/XTwMaP49Lvw?si=KqQq8twRIQvjefE9
I've been trying to fix this all day and I just don't know how. I am making an FPS game and as you can see in the video when the player is moving the camera also moves along with the animations. I don't want it to move when the player is moving.I want the camera to be still for an example modern ware 3 when moving the camera doesn't move. If nob...
How do I make it so that the variable becomes false?
on Play, the variable "touchingSomething" is false because it's not touching anything, but once the circle falls and bounces it is always True, when it goes up in the air, it's still true. If I grab my circle in the Scene view and just hold it in the air so it's not touching anything, the variable "touchingSomething" is always true and never becomes false.
The camera seems to be the child of something that's part of the animated model. It will move along as the animation plays. If you don't need that, parent it to something that is not animated.
Usually, the animated model is a child of an empty GameObject that's the "player root"
I don't think the camera is a child of something but I'll double check and let you know
If you're not touching anything, this foreach loop does not run, leaving the boolean unchanged
Well you'd have to write code that sets it to false. It's unclear what the context of this snippet you shared is but it seems to rely on a Collision2D existing.
Presumably there's no collision when you're not touching anything
are void OnEnable() and OnDisable() even necessary
oh, so since it's not touching anything it stays true because that was the last setting for it
and I should set my variable to false, outside of the foreach loop
Only if you want to handle the cases where the script/object gets enabled/disabled. You're free to not implement these if you don't need to
ok I will move some code around ty
ic ic
okay then
Before the loop, you can check whether .contactCount is 0, and if it is, set the bool to false.
There's also a flaw in this code which is in the case there are 2+ contact points and the last one doesn't have a normal Y greater than 0.95, it will set the bool to false, even if there were contacts that satisfied the condition earlier in the loop.
You should break; out of the foreach loop as soon as you find a "valid" contact
yes, if you use events and delegates you need those methods to subscribe and unsubscribe
Perfect, all cases are covered here
for some reason my variable is always true, it's only false at the start of play, then as soon it touches one thing, it becomes true always, even when it's free falling to oblivion
Well OnCollisionStay won't get executed if you don't touch anything
OnCollisionExit, set to false
honestly that method should return a bool instead so it could look more like this:
public bool TouchingSomething(Collision2D collision2D)
{
foreach(var contact in collision2D.contacts)
if(contact.normal.y > 0.95f)
return true;
return false;
}
whats the difference between the tap and press?
what do the docs say?
idk why i forgot about that
youre right let me read them rq
i cant find anything in the docs
worked right away lol, ty SPR2, I appreciate it
make sure you actually check the #🖱️┃input-system docs https://docs.unity3d.com/Packages/com.unity.inputsystem@1.8/manual/index.html
i did
let me check the other version
thank you! i missed that
hi! im new in the progamation and i need a script to generate a objet in a random position five times. Can somebody help me? Thank you for the atention, greetings from Argentina
Hello, this isn't a place to request and receive custom ordered scripts.
This is a place where you could ask a specific question about a script you are trying to write if you're experiencing an issue you don't know how to solve
thakyou very much!!
np
Sorry for the inconvenience, but the script does not work correctly, I need them to appear at the beginning and not when I press space, how do I do it?
You should learn the basics of coding I'm Unity
Otherwise you'll be here asking for every little change
You're right, I don't bother them anymore.
@queen adder And this is why we do not spoon feed
I understand your eagerness, but learning the basics is something everyone has to do for themselves.
To answer your question, you have to put the code into private void Start( ) instead of Update ( ), and remove the " if ( Input........ ) " line.
Good luck on your journey to learning Coding Manuka.
thank you very much!!
With the amount of help I receive, I wanted to also give some support back.
np
but I see your point, I'm learning 😅
I understand but not like that. This is probably for a school assignment and you have completely subverted the learning process which is the whole point of them
damn I didn't even think about that
I'll be more mindful
It is 3D, but is basically a 2D plane, I am only using the X, Z plane for most of the stuff, you can ignore the Y entirely, since you barely ever move or rotate on that direction. So basically on 3D I would have to use Quaternion.LookRotation and then multiply that for the angle and magnitude I want manually?
use Quaternion.AngleAxis
it can produce a rotation given an angle and an axis to spin around
e.g. Quaternion.AngleAxis(45, Vector3.forward) is a 45 degree rotation around the forward vector
and in a 2D game, the forward vector usually points into the screne
do not ask me if it's clockwise or counter-clockwise! i forget!

If you're working with 2D plane, then just go with the first method.
I even wrote a simple function that returns a rotated vector. 
lol, positive forward is counter clockwise
I suppose it's just like a rotation on the unit circle
what shoul i set?
in the artist chanel no one respont
idk xddd
then the question has no answer
thx bro
not really surprising. If you just post a screenshot and ask 'do you know how to fix that' How can you expect an answer?
Also, you do not go to the Bakers to buy Shoes just because the Shoe Shop is closed
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
I think every part is animated cause when I put it in different body parts the problem is still there
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Look at which object has the Animator, once you got it, all its children might be animated so you need to put the camera elsewhere.
Have you tried disabling the Animator to see if that's really the source of unwanted camera movement?
when I disabled the animator the unwanted camera movement is not there anymore
I'd use a setup like the following:
PlayerRoot (scripts: PlayerController)
> Camera (PlayerLook)
> Rig (Animator)
> ...
So the camera is separate from the rig, but still attached to the same object as the rig
https://hatebin.com/ikardedcqq any idea why the dash mechanic wont work? i have the mandatory components and parameters all assigned
Because you're doing this in FixedUpdate:
rigidbody.velocity = new Vector2(horizontalInput * walkingSpeed, rigidbody.velocity.y);```
well whats the issue
don't you see this will overwrite the velocity to walking speed?
not sure what you mean by that
i mean add the velocity for the dash to the velocity for the movement
how?
I mean what code would you write
Seems like you want the dash speed to replace the walking speed during the dash, not anything additive
should I make an empty object called player root? im abit confused on how to do this
okay i just fixed it my bad
i was running the same line twice
lol 😭
Yes, and move whatever you have to move the player there (rigidbody, scripts, etc.)
how about the player body?
The animated model?
the model
Right under it. I labeled it as "Rig" in my example
the player look is inside the player movement script tho?
Modify the script so it affects the child object where the camera is
could I just separate the camera look script?
If done correctly that should be just swapping everywhere you set the current transform.rotation to another object's transform.rotation
@short hazel
It's your project you do what you think is best
inputActions.Player.Dash.triggered; what does this return
it returns whether that action is triggered this frame
so a boolean?
idk how to check that.. im using vs 2022
If you just put your mouse over triggered it tells you
Just hover your mouse over it
docs are a hassle, discord is much faster
alright
I literally just looked at the docs my dude https://docs.unity3d.com/Packages/com.unity.inputsystem@1.7/api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_triggered
oh it works thank you
👍 😭
Server rules ask you to research before asking here, that includes looking up the documentation
my bad then
thanks for the heads up
@short hazel where should I put the camera root?
is this correct?
Partially - the Rigidbody should be on the root object
the rigidbody in the player should be in the player root?
It will construct a composite collider from all the colliders in the children, so there won't be any difference
That is exactly what I said yes
I just tested it out and I cant move nor can i look
in the camera what should I put in the player transform?
Proceed with basic debugging steps. Are there any errors? Are the scripts being executed? Is input being received? etc.
You do not need to ping me with each reply btw, we are the only active conversation right now and I'm frequently switching tabs to see if there are new messages
ok sorry but should I put anything in the player transform in the camera?
Nothing else, it looks correct right now
is there a function where i can move an object back and forth in a swift motion; like a spear weapon for example?
lerp i guess, or an animation
would mathf.pingpong work
I'd use an animation curve
idk maybe, you can try it and see if it works
do you have a short yt tutorial for that? i havent touched animations in a while so my knowledge is a little foggy
not an animation
just an animation curve
im not familiar with that
its just a value basically
The first 1,000 people to use this link will get a 1 month free trial of Skillshare: https://skl.sh/gamedevguide10211 - Animation Curves are more useful than you think! Let's take a look at some non-traditional ways we can take advantage of evaluating values in Animation Curves.
Making Progress Bars: https://www.youtube.com/watch?v=J1ng1zA3-Pk
...
thank you
yes
@short hazel I am using this code https://paste.ofcode.org/39TxA9jzPavnUPyX3ZmL5Fr for debugging and these errors keep popping up
its simple, just read it
Yep the error message is pretty clear on that one
if I change it will it break the project?
dont change the input system, just learn to use it through code
instead of the old one
Aren't you using the New Input System already?
what shall I change it to?
Yes you are, in the first screenshot here, there's the Player Input component with an Action Map linked
dont
So why are you trying to use the legacy Input class again?
what legacy input ?
If you separated the movement and camera look into two different scripts, it's as easy as adding another "Player Input" component aside the camera look script, and moving the relevant code that was in the player movement into the camera look script
what does this mean
It means you're trying to use = with a function/method which is not right
The Input class. Like you're using in your code example you linked. Input.GetAxis()
you call methods with ()
oh i see it now, thank you lol
sneaky typo
what shall I do man I did what you said and the script and inputs are working so why can't I move?
Post a screenshot of the Inspector with the root object selected, and another with the camera selected
public void OnAttack(InputAction.CallbackContext context)
{
Debug.Log("attack");
weapon.transform.Translate(new Vector2(Mathf.PingPong(Time.time, 0.75f), transform.position.x));
}
so basically when im running my game and i press the left click (attack) it just gives me these errors when the object is clearly assigned to the component
the weapon object is a child of the player object
You might have another instance of this script attached to another object by accident, and it's the one throwing. Serach in the Hierarchy's search bar for t: Player and go through all results
okay
nope, its just the one object
Might be there twice on that object
is there anything wrong I did? @short hazel
Please, be patient
no it isnt
Disable the script by unticking its check box (aside its name) in the Inspector and see if you still get the error
ok
i still get it
If its the only one in the scene at edit time and its a prefab, are you instantiating it? I noticed the weapon reference is a scene object which wont save in the prefab.
Yeah might be normal if the events are still subscribed. Can you locate the line of code throwing the error, using the stack trace in the error message?
okay
We're going to add a special Debug.Log() that will highlight the object in the Hierarchy when you select it in the console
wait wtf it randomly started to work again..
but now it runs 3 times instead of once
lol i just had to apply the changes to the player prefab
that was the reason for the error
How did you apply the changes to the prefab
overrides
The reference shows a scene object
if you had to apply the changes it makes me think you’re instantiating it
no its blue so its a prefab
In this image weapon is not blue
the weapon is a child of the player object
i applied the changes to the player
As I said, there should be a "Player Input" component on the camera object as well, so the CameraController script can receive the events raised when input is received
Unless they are routed from the PlayerController on the root object
Ah, so originally it was a scene object and now that you applied it its part of the prefab
yes 👍
also for some reason when i click left mouse button it runs 3 times
i only want it to run once
Did you subscribe three times to the input event?
I noticed the new input system runs 3 times on mouse clicks, are you using that?
it didn't do anything
Hiii guys,
I recently made a game in Scratch and I want to turn it into a Unity game. I'm not very good at Unity coding, so I could really use some help with the transition. Any help would be awesome!
You are using it, i just saw. Just check if the inout is starting. It should be something like context.started. If not don’t run the code.
Well that's normal, you need to add an input actions asset into it, and then look at what it tells you:
Will SendMessage() to GameObject: ...
Check that your input methods are listed there, and implement them in your camera controller script
Where I first learnt C#.
I know the basics of Unity and coding, but I'm having trouble figuring out where to start 
I already have input action assets tho
I’d say do that lesson to make sure you know your basics. Then you start by making the basic systems of your scratch game in unity.
When you don’t know how to do something search Unity’s Manual or API docs, google it, watch tutorials, or ask here
Oki, will do
Great. Now make sure you implemented at least the OnLook() method in your Camera Controller to be able to receive input
what do you mean inout?
youtube tutorials are pretty nice but theyre not 100% reliable
its a typo, i meant input
Fine for beginners. Beginners need to just do not really worry about whats right or wrong yet.
the onlook method in my script?
Yes... that's how it works
The PlayerInput component sends messages (events) to other scripts when input is received
im not sure what you mean by that message, my problem is that its running 3 times
Read
oh sorry i didnt see this
and yeah i am
So do this in your method
ic ic okay then
is this correct? https://paste.ofcode.org/UKyMSzX4yw4PxUyXuHUBDv
public Vector3 FinalVector()
{
return finalVector;
}``` can this be reduced to this..
```cs
public Vector3 FinalVector() => finalVector;
``` i've used `=>` before with one liners.. but never used the `return` keyword..
my IDE removes it.. just checking
thanks
just using a => means it returns the right side if there’s a return type that isnt void
i should probably be using a getter setter
it didnt work
in this case.. but i havent used those very often either
What’d you write? Could be barking up the wrong tree but just want to double check
i used context.started
Partly - the code in void Start() should not be there. Remove it
Same deal for in OnDestroy()
ya ive done things like
public void TurnLightsOff() => foreach(light in Lights){light.enabled = false};``` but never a return
ok it worked
Personally would only use => if it were a one-liner
By the way you can just make this a property
ya, thats what i mentioned earlier..
but it was a script that was already written.. and all the variables are private
@grave frost it works now but i have another issue.. https://hatebin.com/gsdsqcygpg
soo i just figured id make duplicates for the other scripts to use
You can “redirect” the property by just removing the ()s. Is finalVector serialized?
Or a switch expression, I mean look at this beauty:
string Sample(int x) => x switch
{
1 => "a",
2 => "b",
_ => string.Empty
};
ya they all are
they get initialized via scriptable object in awake
I still would prefer a return switch statement inside of a regularly typed function since its multiple lines
oohh thats a new one
And its a private field I’m assuming?
yea, they were public earlier.. but once i got it working i made them serialized private variables
I like to use these!
they're still in the inspector tho
any time the function boils down to a single expression
i'll probably lose the serializedfields once its finished
Here’s a neat trick. You can apply attributes to the underlying field of auto-implemented properties:
[field: SerializeField]
public Vector3 FinalVector { get; private set; }
that would apply all attributes in the same []s to the underlying field
alternatively, just leave the currently serialized fields and throw in some get only properties for public access. public Vector3 FinalVector => finalVector;
you won't need to fix serialization (since the backing field would have a different name you'd need the FormerlySerializedAs attribute or reassign in the inspector) with this since you're keeping the exact same serialized data and nothing inside the class needs to change with regards to assigning the field. the only thing that changes is now outside objects can read that data
Today I learned! 🙂
thanks guys! useful info, for sure
just trying to make this class not huge
any help please
its the biggest class i have.. (originally it was 800 lines long)
but that was like 8 months ago or so.. i've learned so much since then..
no more nested if chains, and abunch of other nasty stuff i was doing
whats going on? whats the white rectangle?
its my weapon, im trying to get it to ping pong to act like a spear but its not working
it looks like its its position is constantly getting added to
then.. how do i fix it
let me look at ur script..
alright
the attackVelocity is a float set to 5
TIL about that attribute. But we’re just discussing ways to do things since they want to learn syntax sugar, not saying they should do it that way per say :)
you need to reset the position after each attack cycle
i see, but that still doesnt help with why its moving randomly and diagonally
private void Start()
{
// Store the initial local position of the weapon
initialPosition = weapon.localPosition;
}```
```cs
weapon.localPosition = initialPosition;``` before you do ur Pingpong
I have a script thats 950 lines even WITH a lot of this syntax sugar stuff to reduce lines and more readability. It was data baking for pathfinding I made since for this particular project navmesh didn’t suit us.
weapon.localPosition
u should also use localPositions
esp if the thing is a child object of anything
thanks!
i went a bit crazy at first.. going from 800 lines to 200 lines was a stretch.. and then some of it was basically unreadable.. sooo i had to do a 2nd refactor.. to make sure it was clean BUT readible
balancing act for sure
Hugeness is fine as long as it's easy to read and find information
i had some messy scripts where I kept forgetting where, exactly, different things were happening
it was very tiring to work on them
Do you know about regions?
and XML comments?
https://www.spawncampgames.com/paste/?serve=code_616 <-- Player Input
https://www.spawncampgames.com/paste/?serve=code_901 <-- Modifying Speed before Move() function
theres functions that are still a bit ugly imo..
but not sure how to make them better.. might just leave them alone
well first off it looks like there’s several states that seem to be mutually exclusive based on how they set the variable that don’t use if/else ifs, nor return in the if
like dis?
yes
not sure what XML comments are.. but im pretty sure that 2nd one is what u mean
Summary is the only one i know about
also learned about snippets a while ago. and was going crazy with those 😄
XML comments have a lot more cool thongs you can do when you do things like <code></code> and <see/> (the see tag needs more i forgot exact syntax VS always helps me auto complete it)
it is
i just recently started using VSCode.. soo not sure how to do it with it just yet but i know its possible.. b/c i installed a Unity Snippets plugin
wrong video
no if ur goal is a boomerang thats not it
the pingpong should do what u need it to..
type three forward slashes and it'll expand into an XML comment
IEnumerator Rebound()
{
standby = true;
float elapsedTime = 0;
Vector3 startingPos = transform.localPosition;
while(elapsedTime < upDuration)
{
transform.localPosition = Vector3.Lerp(startingPos,targetUpPosition,(elapsedTime / upDuration));
elapsedTime += Time.deltaTime;
yield return null;
}
transform.localPosition = targetUpPosition;
elapsedTime = 0;
startingPos = transform.localPosition;
while(elapsedTime < downDuration)
{
transform.localPosition = Vector3.Lerp(startingPos,targetDownPosition,(elapsedTime / downDuration));
elapsedTime += Time.deltaTime;
yield return null;
}
transform.localPosition = targetDownPosition;
standby = false;
}
``` i use this for my headbob when the player lands.. it acts like a pingpong..
Ah I dont use VS Code, I like VS better (some people might think thats based).
When you hover over the method or class or whatever it should show the XML comment
ok this is the right video
i couldnt get pingpong to work correctly for it for some reason
e.g.
is this correct? should i js increase the velocity?
thanks
cref ahh. I was like ik its not href (although I think websites work too so you can use href with a link to unity docs for example)
i'm just doing whatever VSCode suggested :p
Why do so many people use VS Code? Never understood the draw.
ya, it also works in VSCode..
i made sure after i swapped IDE's
Sorry to ask whats gonna sound dumb, but, if I create a Unity project and then want to put it into a git repo with a gitignore on the first upload so I dont put in extra junk (gonna also use git lfs), how would I do this?
im just familiarizing myself.. i make youtube tutorials.. and I always use Studio.. and thers times when people ask about VSCode..
so i figured i'd learn it as well
Github desktop will give you a girignore that you put in the project folder. Also:
https://github.com/github/gitignore/blob/main/Unity.gitignore
create your project, throw the gitignore in there, then commit only the gitignore and other relevant git files. then you can start committing your other stuff
with enough extensions.. its pretty similar to Studio
{ if (context.started)
{
weapon.localPosition = weaponStartingPosition;
weapon.Translate(new Vector2(Mathf.PingPong(Time.time, 0.75f), transform.position.y) * attackVelocity * Time.deltaTime);
}
}
is there something wrong with this? its not working like its supposed to
You can stage the gitignore and it would start working when you stage the rest of the files the ones ignored will disappear from changes
.gitignore always should come first
@short hazel thank you for the assistance but I have a small problem. I still can't move but I can look around to the point where I can see my own body how can i fix this. sorry that I keep bothering you XD
you need to clamp ur rotation
before passing it into ur function
ok
I'll give that a go and parse out anything extra I'll need for the gitignore. Thank both! I think I may have a chicken and egg question coming up on if the repo is made empty then I move the entire project into it or what soon
yeah, but it's just easier to tell newbies to commit it first. plus each commit should contain only files changes relevant to that commit. so the gitignore plus gitattribute and other git related files first. then stuff like project files
You can put the rig root and its children on a specific layer that you'll exclude from rendering in your camera settings
Clamp Camera
something similar to this:
If you ever start making tutorials about advanced stuff lmk 🫡 i feel like there aren’t many good tutorial channels that cover advanced content (or even intermediate content)
😅 roger that! im working my way up to that.. gotta learn myself first.. https://github.com/SpawnCampGames theres a roadmap on my github page.. of whats next..
all pretty basic stuff for now.. but if u have an idea's let me know.. feel free to DM me if u wanna send me some suggestions
ur right... for a beginner git is more intimidating than it should be
best to test the waters first
Does anyone know how to create an animation where a card starts off transparent and lowered, but when you hover over it, it moves up and becomes fully visible?
Just one more thing on git repo stuff. So I created a new git repository locally and gave it a name. So now would I move my entire Unity project folder into that folder OR would I move all items within the unity project into that folder? Just trying not to break references and such
So I'd either have
A: My-Project\My Project{everything}
B: My-Project\{everything}
since this is a code channel, i'll suggest a code solution: implement the IPointerEnterHandler interface on a component. when the pointer enters the object tween it's position and the alpha channel of its color to the values you'd like
You should have created the git repo in the project folder in the first place
My suggestion is to drill into people's heads
Vector3.Lerp(transform.position, target, Time.deltaTime);
``` is __***NOT***__ correct
and instead use SmoothDamp
e.g. you go into My-Project (the folder that has the Assets folder) and run git init there @cunning narwhal
or just copy the .git folder and other git related files right into the project folder
then it's just a matter of opening the repo with your preferred GUI
you can use a parent as a collider
and use the card as a child object..
just animate the child object.. one at the position off screen it needs to be and the alpha set to 0
the 2nd one with the card at full alpha and positioned correctly..
then use a simple transition and a switch or boolean to flip when u click the parent.. (collider)
You could try #🏃┃animation, this could either be an animation or a timeline or code. I would prefer the code way of doing it though for something this simple.
https://gamedevbeginner.com/the-right-way-to-lerp-in-unity-with-examples/
i keep this on speedial 🙂
been meaning to make a readme for it.. and i'll def bring it up in some of my next tutorials..
i try to use MoveTowards.. to avoid the confusion.. so i dont get called Brackeys
Okay! I'll just use @slender nymph's method
Well I think SmoothDamp is better if you want smoothing, but MoveTowards works too.
yea #🏃┃animation would be ur best bet
orr.. use DoTween like a sane person 😄
I actually meant @grave frost since he mentioned that for something this simple, I could just use code 
ohh okay
ya, well if u wanna go that route.. go ahead and install and learn DoTween
my suggestion was also an all-code solution
its a tweening library.. for all sorts of stuff
I believe they're talking about your solution since I pretty much said to use code without giving any solutions
should be a bot command.. Use Code.
eh I dont need it. I write them myself and I'm building my own library of stuff.
ohh okay 👍 just a suggestion.. but if ur working on ur own library do it to it
why can't I move?
DoTween or PrimeTween are some good tweening libraries and work very similarly. DoTween probably has plenty more tutorials available, although you could just do it yourself with a Lerp or MoveTowards, what you are attempting is incredibly simple to set up and doesn't necessarily require learning how to use a tweening library, but that knowledge would be handy down the line when you want to start doing more complex stuff or chaining different actions
my library is bussin
Good question!
y u exclude LeanTween 😈
because i, much like many others, forgot that it exists
ahh okay.. probably my least favorite.. b/c DoTween has always been solid for me
just curious if u had a disliking for it
i didn't before, but now that i've looked at its documentation website i immediately dislike it. good lord that's some poorly formatted documentation
anyone know what this assembly is for?
Assembly-CSharp is the default assembly name that includes your scripts that aren't in a different assembly
well im aware of that one
I was planning for the future, once more money is acquired, a different card will come, and the left one will be pushed a little to the left. Should I still do it all in code, or would animation be smarter?
but one of my projects keep recreating it and i wasnt sure what the -firstpass is
but ill research it 👍 thanks!
I'm dumb @rocky canyon. Personally I think that's a horrible name for an assembly.
i wanted to make sure it was unity's and not some third party asset creating it
i honestly don't know how difficult that would end up being with regular animations. doing it in code is still pretty trivial though. you really just need to determine how far along the Y axis the card would need to move for the hover effect, then no matter where it is in your "hand", even after being pushed to the side, the effect will still work exactly the same
if you have a Plugins folder its from that since that gets compiled before other stuff
They are free btw. Atleast DoTween does provide free version that I know of.
the assembly is a predefined one according to the link boxfriend sent
okay.. yea im seeing it now..
my emptier project only uses 1 (the C-Sharp) one
but my fuller project keeps recreating the first-pass one..
just wanted to make sure it belonged 😄
what I would like to know is why I get bloom by setting a color's value past (1, 1, 1) even with my global volume turned off lol... I don't remember that happening in the past.
Did it this way and it works out :) For some reason when I di it through the gitdesktop application it likes to put the repo as a subfolder like "My Project\My-Project" instead of the intended "My Project" as-is with the .git folder within that.
I did come across an interesting thing on Git LFS and the "community recommended" gitattributes file from https://gist.github.com/nemotoo/b8a1c3a0f1225bb9231979f389fd4f3f in the comments where a user pointed out issues with line endings and binary files. Then someone wrote something up on that subject and posted it yesterday of all days which is nice https://www.chunfuchao.com/posts/unity-git-en/#gitattributes
welp, i know what im doing this morning..
Fork is a great Desktop client.. https://git-fork.com/ if ur looking to try different ones
been using it for 2 years now.. never looked back to github desktop
Oh nice, thanks yeah I'm always open to trying out something different
this looks like a fork of source tree or something lmao. How's it compare?
it'll detect changes u made automatically.. and then its just as easy as selecting the files it has detected.. staging them -> committing -> pushing
i had a friend show me how to use it the first time.. sooo i'll show u as well 🙂
the tree is epic..
thats probably my favorite part about it
yea that's pretty much why I use SourceTree. That and multiple stashes.
oooh
good stuff
can't do that on source tree
i try not to mess with it too often.. as im still very beginner to git..
when stuff breaks i go insane
One time at work my local branch was behind my local branch and it wanted me to pull the changes to my local branch in order to push my local, unpublished branch :D
good stuff
heres my most complex tree
this is where i like to stay
didnt even use git until i started making tutorials.. and then i needed to work ahead of my last version
Solo project sure. The screenshot I sent was of a team of 10 people. It was extra chaotic because some people would just keep reusing their old branch instead of creating new ones.
I've pretty much always used it. It's good to be able to revert un-undoable changes.
took all of 12 hrs for the github to be broken to hell
we started passing around unitypackages
haven't worked in a team since 😅
Well I have a suspicion that someone edited the gitignore or they placed a package in a place not covered by the gitignore
got 500th place out of 3.2k tho
That's what's happening in my current project my team don't understand how to work with GitHub
Oh in my latest semester of college the opposing team told me "We kept getting conflicts with meta files so we added them to the gitignore"
Me: "THATS HORRIBLE-"
Them: "Yes, we quickly found that out"
Recently someone had to pull 220 commits 😴
that happened to us once.. someone replaced it and tried to push the full library folder
From a big branch merge, right?
i have a 17 terabyte extenral harddrive i saved all my stuff to..
but eventually you need to go back a few steps..
and that i couldnt do.. so in comes github 🙂
Yea we merged everything into main, solved any potential conflicts and merged back into everyones branches
that sounds lovely
sounds awful
I already told them they should be making new branches but they didn't listen
isn't there a way to have to approve pushes?
Our project is cooked and final presentation is this week
They re-publish their local branch, bringing it all the way up the history from like 3 weeks ago. Like Creat. New. Branches. people
Pull request
so u can check for conflicts before it gets broken?
ya thast it..
hosting with github you have to pay. I ended up having to pay for LFS anyway
Tldr you disable pushing to main, ask your team to submit pull request, you approve pull request and it pulls
good luck, I just had mine this last wednesday 🫡
🫡
Yay, the animation works
And it also tells you any merge conflicts
Very helpful
1 GB storage, 1 GB bandwith. We used 0.98 GB at first, and then 10 people downloaded it...
rekt
Hi everyone! I'm working on a dialogue system for my Unity game and could use some advice. I need to manage dialogues with different triggers and conditions.
Also to enforce checks, you need to pay for github premium or whatever they call it
How may we advise you?
u can use a thirdparty asset to help u out
what hosting did you use? Unless you hosted yourself D:
any tips?
I don;t know how to manage the "triggers" part, and appearently you can do that with the unity even system which i hate using, but i also don't wanna do a personalized script for everything "dialogueable" with a bunch of ifs (it sounds raw and newbie(?))
something something.. Fungus
I have an overall Quest system, and nested in the Quest system are Quests which communicate with Dialogue system
scriptable object to manage dialogue lines
ok one sec
GitHub 😄