#💻┃code-beginner
1 messages · Page 519 of 1
on my computer, Alt + 225 is ß
check the number again
mine either i still cant find this widget
yes just the player locally flip outward
mines different
We would need to see some code that rotates the orange ball on the Z axis, also it looks like you are flipping the orange ball
not your parent of the orange ball
not quite sure why you would expect to see a difference, flipping a circle about it's pivot point will just give you the same circle in the same position
yes that is what I was saying, I do now see my flaw in my other sentence though
i just need to rotate it outwards
I was not aimimg my remark at you rather at OP
oh my bad
from where? rotating on the pivot point will not move it
i showed the image already
you have not showed what you want the final position to be
you would rotate the parent preferably on the Y axis I do believe it was
you seem to be scaling it
rotating or flipping the orange circle will NOT move it visually
parent object h es to rotate
it rotates to the left or right
when player collides it needs to flip so y-as points outwards again
you are rotating the parent object? the code you provided shows you scaling the transform
scaling is a way to flip btw
@gray coral why not show us a before and after image of what you want to achieve so we can stop all this guess work
btw to flip it you can literally just do
transform.up *= -1
on the parent mind you
from the image he provided it look like he is rotating the orange ball
Which one is a better practice, having a collection of bool in a dictionary, or just a bunch of public bools? The context is that the bools will be set and read often from different scripts
the orange ball is the parent, im an idiot
no the orange ball is the player
yes
There will be 5-8 different bools
correct, but you do not want it to move the the opposing side of the magenta ball
also you would always rather just do a HashSet instead of a Dictionary.
I should have said the Player not parent
e.g. HashSet<string> is better than Dictionary<string, bool>
is this not what you wanted?
no
Thankyou!
yes but i adjusted myself
to show what i want
not a rotation a flip, a rotation would also move the red arrow
are you scaling the player OBJ and not the actual player parent?
i think this is the best option
(that just rotates it, by the way)
your X will still be flipped too
So what i’m getting is that hashset is like a list but it’s more efficient if we use it on normal variable but not class?
aslong y faces outwards is good
i dk how to record with unity otherwise i showed you what iam building
more efficient if we use it on normal variable but not class
I have no idea what that means
no
a HashSet is a set
not a list
you would use any other recording software
lists allows dupes for example, hashset does not
they are extremely efficient
HashSet doesn't allow duplicates and doesn't have a concept of an "order" or indexes for its contents. HashSet is faster than list for Contains and Remove.
and lists are nothing more than arrays on steroids lol jk
they are arrays that resize
i was basing it from https://stackoverflow.com/questions/4558754/define-what-is-a-hashset
yea i'm familiar with array and list
but this is the first time i encountered this one lol
its just a buzzword for me
wait till you learn about Queue and other collections lol
i see it all the time. but no where near ready to use em

Queues are cool
Anyway, thanks again
wait wat more could there possibly be?
we've already listed off
- arrays
- lists
- queues
- hashsets
Stack ?
omg. how did i forget that one
I’ve been meaning to learn about hastable
and then you have the Blocking Collections as well for multi threading
But I haven’t encountered a problem that needs me to use it yet
Dictionary is HashTable
HashTable is just the non-generic dictionary in C#
you just added more to my todo list for today 😭
dont want to use it for primitives or structs though because you'll get lots of boxing/unboxing
some of them had to learn the hardway lol
im not gonna need half of em but i'd still like to have some context so i'll read this later today thanks
yeah most of them are pretty niche, and if you're into microptimizing tbh
Most of my learning comes from asking people “how can i do this stuff better instead of going goblin mode on the coding” and people would tell me more efficient stuff that i never know even existed
I cannot read docs like those lol
I’m too zoomerbrained
you should have the mental capacity to read documentation
and, preferably, remeber it
it's a shame Unity package docs are so shit now
they should convert it like the NGO ones, is good because it goes through github so we can actually submit revisions or add more info with PR
this is what i make, at the second jump you see the ball doesnt really correctly moves up. some suggestions how to fix it?
hard to say without some code
type out a full question.. not bits and pieces
give us !code examples too
📃 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.
player code: https://hatebin.com/nygdqdlheu platform: https://hatebin.com/tasrkbecog
hatebin working today? niice
If persecution is true, so the corutine "Persecution" is active but if the false, the corutine "Persecution" is desactive and the corutine "Patrol" is active
after trying to implement the hashset, i got confused. what i'm trying to do is to make a state true or false. like if i were to use dictionary it would be {("clock", false), ("note", true)} how would i do this using hashset. more importantly, how to set the true or false of a hash set if it only contains value
so i assume ur using a while()
are you sure the parenting isn't the thing messing it up?
This does nothing
you are waiting a bunch and then doing nothing
these are poointless
!screenshots
No
Be mindful, if someone requests your code as text, don't send a screenshot!
you need to yield inside the loops, not after them
your whole coroutine, in fact, is pointless, since you just have a while loop that doesn't pause inside it
ya that while loop could be in update.. if theres no waiting needed
are you doing like an inventory ? just stick to a dictionary if its easier for you
or if statements even
It's true if the set contains the value. False if it doesn't
The problem with dictionary is you actually have three states:
- Not in the dictionary
- in the dictionary and false
- in the dictionary and true
for hashset there are two states:
- not in the set
- in the set
so the hashset is a better pure boolean solution
Well, my idea is wait, but how can desactive and corutine and active other
¿¿¿
bool note = mySet.Contains("note");``` @odd widget
for your example it would just be a set containing note
oh
and not containing clock
@rocky canyon
whats up (╯°□°)╯︵ ┻━┻
i really dont understand what ur going for.. can u tell us what ur wanting to accomplish?
besides "desactive and corutine and active other"
I want what stop a corutine with base a condition
I start a corutine with base a same condition
if it were me i'd put my logic in the update, cache the Coroutines and stop and start them that way
can also use a while loop with a specific bool you can set to false anytime
Basically you would either do something like this:
while (something) {
if (someCondition) // do something
yield return null; // wait one frame
}```
or you would start and stop the coroutine.
^ all good options
priorityqueue
stop, im overloaded already lol
I will try with all thores options, ok¿
ok ok.. i see the flex
SQL
😏
yea, i remember those dark days
tuples
tuples, when you're too lazy to make a struct
u should make a thread and list EVERY thing u can think of
i'll go back and look at it when im not as busy
maybe..
everything i can think of would be repetitive as hell because different languages call stuff differently lmao
oh yeah, heaps, trees, and graphs
we only concerned about c# around these parts
ive been using structs to grab all inputs
great way to go about it
I love dem structs. Pretty much most of stats and other playermove data is all structs
same.. almost all my data goes in a struct or an SO
right or wrong.. it feels right
i hate that unity doesn't support the latest c# we can't even field initilizers for struct so its annoying they all have to start at 0/default value
calm down now.. is 9 not good enuff?
never!
I mean most is syntax sugar but dammit..give me file-scoped namespaces dammit..
thats facts.. the way i see it i know enough now (without knowing close to everything) to do almost everything i need to do..
i hate the indentation when i'm using namespaces in unity
wym? just dont indent then?
!screenshots
No
Be mindful, if someone requests your code as text, don't send a screenshot!
why not?
it's code, we want to analyze it as code, with text search, copying stuff, etc, not as an image
Not working,
i thought you gonna get hacked
Wait and stop the corutine
recursion is not the tool for this, you should probably just use a loop instead
coroutines stop when they're done, StopCoroutine is for stopping a coroutine before it's done
you don't need an explicit StopCoroutine here
Well, i don't use Stop else a return null?
staring at screenshot of code is the most unintuitive way to help someone because you cant select anything easily, copy and paste.
its also annoying af on a phone screen to zoom in and stuff. Its okay for showing something visuals, code doesn't need to be
But, i want the wait 4 seconds
waiting for what?
you aren't doing anything after 4 seconds, so what's the point
if you want to check again, use a loop, which is the proper tool for that
could be but how i suppose to let my player rotate togheter to achieve this effect
maybe rotation constraint and or just manually match the rotation ? then disable before launch?
hard to tell from here for me tbh i need to see more of the setup
Calling Persecution() is done to create new Coroutines (or to be more accurate new IEnumerators). To stop a specific coroutine, you want to save a reference to it (to end it from outside the coroutine), or use yield break (to stop it inside the coroutine):
void StartCoroutine()
{
if (myCoroutine != null)
StopCoroutine(myCoroutine); // <- stop coroutine from outside
myCoroutine = StartCoroutine(MyCoroutine());
}
Coroutine myCoroutine = null;
IEnumerator MyCoroutine()
{
if (somethingIsTrue)
{
yield new WaitForSeconds(1.0);
yield break; // ,_ stop coroutine from inside
}
// other stuff
}
just like that guy said, in your case, manually stopping the coroutine isn't needed since it will automatically end when it reaches the end of the function.
I wrote that from muscle memory did I mess up my sytax or something?
missing a myCoroutine=null at the end of MyCoroutine so it does not stop a finished coroutine
was fine. I think that's why they redacted the message
yes, I thought that StartCoroutine() and StartCoroutine(MyCoroutine()) would conflict but of course it will use the override
my game uses a dialogue system that displays text on a screen with one character at a time using a coroutine. it gets this text from a dialogue object which has lines of text + other stuff. how would i improve this coroutine so that if the text inside the dialogue object was something like "<b> bold text </b>", it would display the text as bold?
probably not trivial since you are also splitting / breaking the RichText tags
<b> b </b>
<b> bo </b>
<b> bol </b>
etc
TMP has maxVisibleCharacters just for this
i'll check it out, thank you!
it's working :). but i was wondering if i could expand this with my own custom tags? like if it was "<w> wavy text </w>" the text would move along a sine wave or something. how would i let the typing coroutine know that whenever "<w>" and "</w>" in a line it should make the text wavey and not to type out the "w" and "/w"?
maybe with help of regex
probably least efficient way but you can store all the found words within as "wavy" words and then go from there
https://dotnetfiddle.net/1yJZO3 @sterile radish
can you return the items in a grid layout?
grid layout dont think it stores anything (it just works on cells/dimensions)
you would prob iterate the children n get specific item
thats annoying 😭 i'm trying to do like a grid select thing and i thought maybe i could iterate over the grid layout stuff
you can probably just link those together with the event system no ? or Navigation layout thing in UI .
yeah, but i want to use multiple cursors for local multiplayer, and the event system only accomodates one i think?
maybe you could just do your own grid in code like 2d array, to store the actual x/y grid
something like that yea, not on it yet but i'll have to do some research on it further. do you know what this selection system is called?
its just some type of grid navigation system, not sure if it has a name tbh
table navigation ? columns and rows navigation ? lol idk
hi, i kind of opted for a different approach where i use a tag detector for each character that is currently being written. i'm just having trouble on what i would do after i figure out "inTag" is true.
what is a "tag detector"? What's the goal here?
how is this better than the regex suggestion I sent lol
hi guys
Have you all encountered this situation before?
Using the same drawing code, encountering completely different color results on "OnGUI" and "OnRenderObject"
😭
basically im making a dialogue system that types out a sentence one character at a time. similar to how you can type "<b> </b>" to make a text bold, i wanted to implement my own version of that with "<w> </w>" to have wavy text. my question was just asking how i would apply the wave effect to the character once i know it's in a wavy tag.
i'm pretty sure regex would've been better but the syntax kind of scared me off to be honest
Suggestion:
- Use StringReader
- If you rely on containers, such as brackets, then I suggest you get the inner string instead of constantly checking if you are near the end
Probably a linear VS gamma issue, IMGUI being gamma corrected
So if you enter the tag, look for </w> or something and then just proceed with the code on the inner string
you just made an overconvolued way instead myguy, it was like 3 lines of code lol.
string input = "This is a <w>WavyScooter</w> inside a string with another <w>WavyWordd</w>.";
string wavePattern = @"<w>(.*?)</w>";
MatchCollection matches = Regex.Matches(input, wavePattern );
foreach (Match match in matches)
{
Debug.Log("Wavy Words: " + match.Groups[1].Value);
}```
You have the words, after that you can just iterate them for the effect you want
replace pattern with any tag you want instead of `<w>`
`match.Groups[1]` gives the word without the tags
`match.Groups[0]` gives the word with the tag too
Is there any way to make the content drawn by OnGUI consistent with OnRenderObejct
so in this case would the input just be the line of dialogue and in the foreach loop i would just do whatever i want to the text after i know it's a match?
yes thats why it was labled as "input" its the incoming dialogue text
This is OnGUI
okay, thank you for the help!
np.
also next time if you had any confusion or question you could've just asked lol would've gladly showed how to put it to use instead of ignoring it then doing it another way, i mean defeats the purpose of asking for help no?
Problem with Input System / Build
No idea. Not sure why you'd want to use OnGUI, and I'm not sure why you would use OnRenderObject either. It feels like there should be less legacy ways to do whatever it is you're doing.
why? is it better than planes or sprite renderers?
...why
Because the original project was based on SlimDX, this is a porting project
Might be worth taking the time to recrate the graphics as an image and using Sprite Renderers
😭
If the point is to port it to a modern engine, it's probably going to take some effort to modernize the asset pipeline
GUI.DrawTexture might use a gamma corrected material. No idea though
GUI.DrawTexture can indeed display correctly, but Material cannot be used. I will try some algorithms for color conversion
whats the difference between Pause() and Stop() for audio sources?
like why would you use one over the other
Do you know the difference in meaning between Pause and Stop?
You can't unpause an audio source that was stopped
i got that, the bit im confused about is then whats the point in using Stop instead of just resetting it and pausing
or is that basically what stop does?
hey guys! I have an issue with my code, its a really weird one and im not sure how to explain... anyone free to call and help? (im a beginner at this stuff TnT)
If you want to stop the sound, use Stop. If you want to pause it, Pause
that's really all there is to it
!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
It isn't working working for me...
what is not working
like using the API script refrencing stuff, the trouble shooting etc
the issue is regarding scene changing in Unity, but what I don't understand is that the same exact thing worked for the 2nd scene, but then when i try for the 3rd scene, it doesn't work
ya, sorry, i just didnt know how to explain it very well
Show !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
what did you do for scene 2 that did not work for scene 3
And explain in more detail what "doesn't work" means. What are you expecting to happen and what actually is
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneChanger : MonoBehaviour
{
public void LoadScene(string scenename)
{
Debug.Log("Loading scene: " + scenename);
SceneManager.LoadScene(scenename);
}
}
The code is generic and should work, the only thing i should have to change is scene name. This is attached to the canvas, and there is a button to be clicked in order for this to run.
what does "not work" mean
I am expecting a scene change, but nothing happens
nothing happens? Do you have your console window open?
Make sure there aren't errors
ya
and make sure the code is actually running
and what does it show
the console doesnt say any errors or anything actually
if it doesn't say anything then your code is not running at all
it should be printing at least the results of Debug.Log("Loading scene: " + scenename);
thats where im getting stuck.... Im not sure why it isnt doing that. It is working for another scene, where it says "Loading Scene H1"
Is the button reacting at all to your mouose?
If not, you probably forgot to include an Event System in that scene
the thing is, i didnt include it in the first either
you did
the scene that works with this code
just not on purpose
it gets included when you create a button
or any ui element
but if you just copied the button from another scene, it won't be there
and things won't work
so the thing is, you need to check if you have an Event System in the scene that isn't working
tutorials usually forget to tell you that you need an Event system for any UI to work correctly
oh ok i think I understand now, thank you so much for helping me guys!
I'm pretty sure that I did that actually! So that must be where the issue is.
how would i access the vertices of each of the characters in "wavyWords"?
https://hatebin.com/eiganwiwmd
i think you got that backwards, you'd need the text to be in the tmp before you can get the verticies
sorry i don't really understand what you mean, could you explain further?
well first answer me this, how do you expect to get vertices out of characters ?
if you think about it, doesn't make much sense
I'm guessing you would need to start here
https://docs.unity3d.com/Packages/com.unity.textmeshpro@1.2/api/TMPro.TMP_CharacterInfo.html
but don't ask me how
which you get array from this i think https://docs.unity3d.com/Packages/com.unity.textmeshpro@4.0/api/TMPro.TMP_TextInfo.html
but you would need to probably put each char inside and then animate
https://youtu.be/FXMqUdP3XcE i think this shows the process
im having and isue about my code, when i move the player, the rotation changes:
Vector3 newCamPos = new Vector3(hoverObject.transform.position.x + camDistanceXZ, hoverObject.transform.position.y + camDistanceY, hoverObject.transform.position.z + camDistanceXZ);
player.transform.position = newCamPos; // Quaternion.Euler(new Vector3(20, 225, 0))
it is random but close to the result
what is this code supposed to do
move the player
is the player object parented to something
it moves with the grey object
no
well the root i guess idk
its either parented or not, how you not know lol
no scene is not parent, its root
is that only piece of code on the player?
Hi, does anyone have some resources on mesh generation using a compute shader, I want to generate a mesh with a dynamic number of vertices (that isnt known at compile time) and i'm wondering how to do that, as all the tutorials i could find on it assume it operates on an existing mesh and deforms it, but doesn't generate new vertices.
hi, i've gotten the vertices of each of the characters in the text now using TMP_TextInfo but it doesn't work whenever im playtesting? the text just types out like usual with no addiitonal wavy effects
uh I want this ray to hit the ground but it seems like it isn't going anywhere and I don't really know why
Have you checked which object the ray is hitting (if any at all)?
Debug.Log($"The ray hit {hit.collider.name};");```
the hit distance is 0, so it's basically drawing nothing
oh it's hitting the camera area
or it's not hitting anything
yep - gotta use a layer mask
yes
hmm normally positioning an object shouldn't change rotation
nothing in this code will change rotation
maybe you have some other code forcing the camera to look at something
or cinemachine
and therefore by changing its position it must change its rotation to keep looking at that thing
nope
without seeing your project it's impossible to say then
presumably something else is doing it
changing position does not change rotation
the camera is used to fire a raycast, but im not changing the raycast (if that's possible) im only getting it
This is really vague. Fire a raycast to do what? Fire it where? For what purpose? With what code? What does that have to do with rotation?
Share your code.
I've created a scriptable tile object that im using as a tile in my tilemap and it has a function to change its own sprite. How can I actually call this function from a second script? I want the sprite for a tile to update whenever the mouse clicks on it.
In my second script Ive got the following code:
Vector3Int tilePos = fieldsTilemap.WorldToCell(Input.mousePosition);
TileBase tile = fieldsTilemap.GetTile(tilePos);```
but this doesnt get me the scriptable tile object I've created with the function I want to call. Will I need to make a function in the ``fieldsTilemap`` itself to do this?
if (tile is MyCustomTileClass myTile) {
myTile.MyFunction();
}```
how can i make my sure my z rotation is always aligned with y
doesn't MyCustomTileClass myTile refer to a specific tile? Wouldn't I want to just check the type by doing tile is MyCustomTile? But either way I can't call the function on that specific tile object. If im comparing to myTile it would always call the function on that specific tile but I want it to call the functionn on the specific tile that I click on
which y?
can i say something like this: transform.rotation.eulerAngles.z = transform.up *= -1;
if the method you want to call is on a type other than TileBase, you need to cast your tile to the 'proper' type to call it
of my player
the z rotation make my player move into different direction
doesn't MyCustomTileClass myTile refer to a specific tile?
Yes.
Wouldn't I want to just check the type by doing tile is MyCustomTile
That's what my code example does, yes.
I can't call the function on that specific tile object. If im comparing to myTile it would always call the function on that specific tile but I want it to call the functionn on the specific tile that I click on
I presumed from your descriptioni thattileis the specific tile you clicked on.
if i keep it on 0
I think maybe you're misunderstanding the code:
if (tile is MyCustomTileClass myTile) {``` This is a shorthand way of writing:
```cs
if (tile is MyCustomTileClass) {
MyCustomTileClass myTile = (MyCustomTileClass) tile;
it's just much simpler and less code
oh I see. yeah I was misunderstanding it. Thanks for explaining that, I've got it working now
thanks. i've got it working now
you mean transform.up ?
That doesn't make sense, transform.up is a vector, eulerAngles.z is a float
Also transform.up is based off of your current rotation
Hello, a question, if I have an error in my game that I am developing, which channel should I go to to see if someone can help me?
yes
when z rotation is frozen
even when iam faced towards a way with y, z rotation makes it move up
if ur error results from your code then right here. if it's something else then you should post it in the channel names that match the nature of ur problem :) (for example problem with ui? then #📲┃ui-ux )
How can I make it so each tile (im using my own custom tile class) in a tilemap is a separate instance? right now when I update a value for one of the tiles, it changes for the customTileClass itself and so it changes for every tile in my scene.
:(
Ok, my mistake is that I am doing the paralax effect in my game but the background looks strange when it moves and I don't know how to fix it, plus the background moves very fast
If you are using one SO per type and modifying it, it's going to be shared among anything referencing that type. It probably makes sense to use the SO as a template, but copy that data into an instance for each tile if they need individual data
sorry, i'm not skilled enough to help with coding problems ^ ^
np, ty
Currently on the built version of my game, I'm getting a "Crash!!!" error. It happens when closing a Menu in my game, which, is fine, helps me narrow it down a bit I Suppose.
My question however is, is there any way to narrow it down easier?
oh okay. Ill try that
check the !logs
(click the documentation link)
hi, i'm using regex to find out whenever the dialogue in my game has "<w> </w" tags to make the text wavey. this is my code so far, but it doesn't seem to be making the text wavy? the text is just there with no additional wavy effects
Logs weren't much useful when I was looking at them sadly.
I was able to track down the cause however.
you don't seem to be doing anything with the vertices array you are modifying
i am moving them based on a sine wave in the 32nd line no?
it doesn't matter what you're doing because you're not actually using that array
you're copying the vertices from the mesh, modifying your copy, and then letting it disappear in to the void
sorry, im a bit confused am i not using the vertices to update the geometry of the input text?
you're making a copy of the vertices
and modifying your copy
that's all
you're not modifying the original Text object at all as far as I can tell
Is there a way to do this right in the unity editor? Like without having to do CreateInstance? I tried messing around with it but couldnt figure out a way to do this
Could someone please explain to me how the onBecomeVisible function works and how to use it in a script?
do you know how i could fix that? when i used this chunk of code in an update loop on a seperate script for a separate piece of text the text was being wavy perfectly fine. could the problem be because of how it's structured in the CheckTag() function?
the method is called whenever the renderer becomes visible by any camera (including scene camera, annoyingly)
Something really weird here.
Sometimes my Visual Studio just stops showing errors and coloring words.
Reopening it fixes for a few minutes.
Is there anything I can do?
the alignment with the sphere is just not good which causes problems for the next jump.
any suggestions
the red arrow is how it should be
shoot a raycast down and use the normal of the surface as the jump direction, unless that does not work for 2D
Thank you
or, assuming the pivot point is in the center for both objects, the direction is just (smallCirclePosition - bigCirclePosition).normalized
that would work too
no, I'm not sure how it could. You can use CreateInstance for each tile to make a copy and use that, or you can have the 'instance' properites also on a monobehavior and copy them over to that, or you can do a combination where you have a list of 'modifiers' that's stored on the monobehavior which it runs the values from the SO through before returning them
i dont understand
you are calculating the direction between the 2 manually
well i've not seen your code so i can't be more specific than that. but that would give you the correct direction
he came in late, but these solutions provided should work
on collision iam flipping the player ``` private void OnCollisionEnter2D(Collision2D collision)
{
// Check if the player collided with a platform
if (collision.gameObject.CompareTag("Platform"))
{
// Make the player a child of the platform
transform.parent = collision.transform;
isMovingUp = false; // Stop upward movement upon collision
Debug.Log("Player has collided with a platform and is now attached.");
// Flip the player by rotating 180 degrees on the y-axis
transform.up *= -1;
}
}```
alright ill try that out and see if i can get something working, thanks
but now the other problem occures, it has contiously has a weird z rotation
not centered with platform
on the collision of an object you flip the character then use one of the solutions above to orientate it correctly
thats pretty much it
with my solution you wouldn't even need to rotate it. and since you make the small circle a child of the bigger circle you can just use its localPosition as the direction of the jump (just normalize it)
yup his solution seems like the better option
idk mate, its just not working. this is the final code ``` private void OnCollisionEnter2D(Collision2D collision)
{
// Check if the player collided with a platform
if (collision.gameObject.CompareTag("Platform"))
{
// Make the player a child of the platform
transform.parent = collision.transform;
isMovingUp = false; // Stop upward movement upon collision
Debug.Log("Player has collided with a platform and is now attached.");
// Calculate the direction from the platform's center to the player's position
Vector2 platformPosition = collision.transform.position;
Vector2 playerPosition = transform.position;
Vector2 direction = (playerPosition - platformPosition).normalized;
// Set the player's rotation to face outward based on the platform's position
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0, 0, angle);
transform.up *= -1;
}
}
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0, 0, angle);
transform.up *= -1;```
Both of these last two lines set the rotation
so that last flip is based on the direction after the rotation
its again face to the different angle
well two things, 1. if you want to rotate the object, then just assign its transform.up to the direction you've calculated
2. you don't need to rotate it at all, unless you have some other specific reason to. my solution was about applying the force or whatever for your jump that had been incorrect
but if you want to rotate it, then you will need to do so each frame
player flips that alright
just the z slightly rotations is the problem
i just dont know.
why is it a problem. why do you need to rotate it?
CreateInstance works perfectly! only thing is i have to create the tiles from a script on startup rather than being able to paint them into the scene, but not a big deal for what im doing
so you've ignored everything i've said up until now
because i told you how to solve that
i tried to implement but, the same problems occurs
prove it, show your jump or whatever it is to show you've implemented it
how can I reference the object that the script is attatched to?
I have a script attatched to a TileMap and currently I have a serialized field to reference the tilemap. I tried using gameObject but then I cant call .setTile() on it.
for example: ```private CameraController cameraController; // Reference to the CameraController script
void Start()
{
// Store the original parent of the player (usually the root of the scene)
originalParent = transform.parent;
// Find the main camera and get the CameraController component attached to it
Camera mainCamera = Camera.main;
if (mainCamera != null)
{
cameraController = mainCamera.GetComponent<CameraController>(); // Getting CameraController from the camera```
i was about to give up.
so originalParent is the object that this script is attatched to?
.gameObject is the GameObject you are attached to. But if you want to do SetTile that's part of the Tilemap component
so you'd need to get the Tilemap component if you want to do that
What's the best way of moving rigidbody objects manually?
AddForce seems to yeld some results but feels weird to implement, rb.MovePosition straight up moves through walls if i apply enough force
You're going to have to be way more specific about what you mean by moving manually
have you considered setting the body's velocity directly?
Sorry, i'm trying to achieve this but gave up on manually setting collisions and just switched to physics
Setting the body's velocity directly might be the way to go but i don't know how much of a problem slowing down would be, right now i'm just exploring options
i was using AddForce beforehand and that seemed to yield interesting results although i had to fidget with it to get the code to slown the cube down
not sure what you are trying to show in the video
you are making some motion that involves handles that's all I got
I don't understand what kind of collision behavior you are looking for
or how it should behave when the handles are pushed through obstacles
Right now i'm just trying to be able to drag a handle and it moves, i'm gonna deal with hidden handles as soon as i get to that bridge
looks like you already have that
so it's time to move to the next problem
I mean are you looking for physical interaction or something? If not this would be very easy to do just with physics queries
i.e. Physics.BoxCast
how to use regex get rid of the <w> at the start of my dialogue line? my regex currently is Regex.Replace(textToType, @"<\/?w>", "");
is it always there?
Why not just myText = myText.Substring("<w>".Length);
or myText = myText.TrimStart("<w>");
no it's only there at certain times when i want it to be. it basically just acts like a bold <b> </b> tag but with a different effect to the text
since it's an @ string you don't need the \ there
i mean you wouldn't need a \ regardless
though that shouldn't matter 
Seems to work fine 🤔
i don't know to be honest, i've removed the " \ " but the problem still remains
debug.logging it seems to output the correct text as well
so what's the problem, looks like it's working.
(my guess - you're probably ignoring the result of Regex.Replace)
the original text was "<w>Ayo...</w>" however when it comes to actually displaying it after the regex stuff, it just displays what is shown in the screenshot instead of "Ayo..."
but you haven't shown your code so we can't say for sure.
this is the chunk of code for the displaying text part of my script
StartCoroutine(KeepTextEffectsActive(textToType, textLabel));```
what's this do and why are you passing in the raw textToType instead of displayText?
that is there because without it the wavy effect stops whenever the line is finished. i pass in the raw "textToType" intead of "displayText" as display text has been cleansed of all tags
here is the full thing:
https://hatebin.com/rifkmswhwh
what does CheckTag do
CheckTag looks for any "<w> </w>" tags in the text using regex. if there are any matches, it applies a wavy effect to each letter of the matched text based on a sine wave
seems like the string originalText parameter is completely unused
oh yeah thank you, i'm pretty sure i had forgotten to delete that from before
anyway if the debug log prints it without the tag, then some other code must be addng the tag back
or this code is not running with the correct TMP_Text object or something along those line
probably the latter?
i can't think of anything in the code that could be adding the tags back
mb if i'm being stupid, i literally started scripting today, but i can't find how to check whether the player is touching the ground, i tried ray casting (which i looked up online) but it's only detecting that it's off the ground in a specific y coordinate above the ground and if the player goes above or below it, debug log still shown as grounded
this is in a 2d project btw
You'll need to show the code
hai im trying to use Unity's timeline to do a quick intro scene, first time using it. I have an animation clip added that moves a GO from one spot to another, and Im trying to implement a sound effect to follow but I can't hear anything. The .wav does play a sound tho. Also the game is in VR, not sure if that changes anything although even when the game isnt playing and im in the editor, the sound doesnt play. I tried attaching the audio to an empty GO and attaching it to the (NONE, audio source) track of the screenshot but that also didnt work. Any tips ?
Is instantiate an expensive function to call? I’d like to make an arena of small cubes and would like to know if it’s a good or bad idea to do it with a loop
Depends. Doing it 1k times at the start of the game is okey. Doing it 1k times per frame is not
i think the simplest way is to use oncollisionenter() : https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionEnter2D.html
//give all ur ground objects a tag
//in the oncollisionenter, check if the tag of the rigidbody's GO has that tag u specified
//if true, toggle a isGrounded bool
there's also an oncollisionexit that u could toggle that bool once they arent "grounded" anymore: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionExit.html
ahhh alr tyty
Yeah it’s at the start of the game to build the arena, thank you 
Title: Item Prefab becomes invisible after build to mobile,
hi everyone's i'm a beginner here's and currently are struggling with a bug, can you tell me how to resolve it?
full disclosure, i've juggle throuh some of the code and asset, also i'm using Unity 6, and the game can be found at play store and app store named, "Beat This Dummy 3D"
First Problem invisible item - When i use Unity everything's went smooth, cosmetics of mesh are being renderer perfectly, but when i tried it after downloading the game from app/play store the item simply become's invisible. any ideas what cause this?
The current approach i'm doing is, move the files to Assets/Resources, so at loading screen is taking place, all the files are being loaded at the start of the game, so player can avoid this bug, will it resolve this porblem? i'm still waiting for the review of app store this is killing me
please any input will be a big help for me as this bug been torturing my in this past week 💀
i've attach some screenshoot so you guys can emphasis more on the problem.
Does anyone know how to set this? When I right click the executable, it doesn't seem to show the right settings
Hey! I don't suppose anyone could give me some ideas on how to go about making this.
Billy!
Billy is a fun, physics-based robot that walks around using inverse kinematics for his legs. He can be thrown, knocked over, and generally messed around with [see the video below of Billy for an example].
Billy is from a game on Steam called Karlson, and for a while, I’ve really enjoyed re-watching this video of him. I like it so much that I’ve been trying to make my own version of Billy! The only issue is that physics are hard and so is inverse kinematics 😭.
I’ve been making a lot of progress, but when it comes to actually having Billy react to different situations and be pushed around like he is in Karlson, I’m getting nowhere.
[See the second video for my progress (it’s not that great yet)
for the inverse kinematics im using a mix of Animation rigging and a script called IKFootSolver mines a bit modified but is functionally the same but im 200% sure that is far from what billy uses i can tell this because well mines janky and billy isn't janky
now as for my question after all that yap
how exactly can i go about in both improving the kinematics and improving well billy so i can knock him over and have him actually react to it (by react i mean just let me call a void or something when he falls idk)
I would try to keep them in memory directly, why load through the resources folder? Better to avoid this folder unless needed. May be worth a test to create a scene, one object referencing the assets instead of a resources folder load. The images are also a bit hard to discern the problem out of.
Not really my specialty, but it looks great!
Hi, I can't find the option to create a new ScriptableObject!
Any help?
Create a c# script and make it derive from ScriptableObject
unless you're doing this with visual scripting?
I don't know why unity doesn't have a ScriptableObject template
because it takes 3 seconds to make it from the already existing option to make a new script
you'd have to show more of how you're actually moving the robot and the player. that first video looks like the robot is a rigidbody and whoever made that has their own rb controller script for it so it hovers. then on collision or whatever logic happens with the dragging, it loses control and can freefall. the main difference id say between the 2 videos is that yours doesnt have some timer for how long billy should be in a ragdoll state for.
also when asking questions, try not to include a lot of backstory/irrelevant details. its just easier to help when all the necessary details are clear
Billy appears to have both of his legs synchronised with a small offset, and looks to be pushing himself along via a gentle force
which allows for smooth movement
try to make a scriptable object script? first try to create the C# script then delete the monobehaviour instead use scriotable object?
using UnityEngine;
[CreateAssetMenu(fileName = "Data", menuName = "ScriptableObjects/SpawnManagerScriptableObject", order = 1)]
public class SpawnManagerScriptableObject : ScriptableObject
ref: https://docs.unity3d.com/Manual/class-ScriptableObject.html
try not to copy and paste the code from the unity docs
well im using a fixed update and some simple Vector3 position moveing code at the moment
float distanceToPlayer = Vector3.Distance(transform.position, player.position);
if (distanceToPlayer > stoppingDistance)
{
Vector3 direction = (player.position - transform.position).normalized;
transform.position += direction * moveSpeed * Time.deltaTime;
}
Vector3 targetDirection = (player.position - transform.position).normalized;
Quaternion lookRotation = Quaternion.LookRotation(targetDirection);
transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * 5f);
billy finds the straight path from Billys current position to the players position by subtracting one position from the other. The .normalized part makes sure that the direction is a unit vector (length of 1) so Billy just heads in the right direction without speeding up over distance.
the rotation bs is to rotate in the direction of the player
you should only use fixed update for physics
i know i just left it on a fixed update because its supposed to be physics based (its not right now 😭 )
i hate unity physics so much 😭 (its because i have a clear skill issue in this department)
I created a working procedurally animated 6 legged character yesterday, but it isn't physics based
😭
rip
if it was physics based that would be specifically epic for me to hear but otherwise it still sounds cool 🤣
welp billy is fine for now
just wish it was as good as dani's (the guy who made billy)
procedural animation takes time
well then you should really start working on converting this to RB stuff if you want unity physics. im not 100% sure that the 1st video you shown is a rigidbody (since this is literally not possible to know) but it sure looks like how one would move.
it looks like they have a moving/ragdoll mode, where they hover while moving. the arms most likely dont have colliders on them and are just visual to give the impression its moving, so its pretty unrelated to the main movement logic
i mean im not sure if its an impression then its really good because the arms seem to directly hold up the head in a very convincing way 😭
but ive also been told alot its just inverse kinematics witch would make sense because ive heard the maker say that before im sure
I dont get the difference between the observer pattern and command pattern.
Observer pattern: singleton (preferably) class that has a bunch of signals and other classes subscribe to those events, then the signal gets invoked whenever you want
Command pattern: singleton (preferably) class that has a bunch of commands and other classes make instances of those commands, then call the command's methods whenever you want
Could someone enlighten me please?
what do you mean? this isnt the real world, the arms arent holding it up and moving the body. the body moves, and the arms just use IK to look like a hand grabbing the ground with a bent elbow
you can even see the arms go through the ground at one point
no i mean it just appears that way by the bobbing
which is entirely the purpose of IK
for some parts of its movement anyway
🤣 yeah lol
sorry if im being rather stupid on the topic (ive been awake for more than 25 hours)

lol
just go to sleep. I'm no doctor... but that sounds bad
i would but uhm
its 10 am so now i gotta do the 24h challange to fix that sleep schedule
okay
i need a new keyboard i cant type on this one
(blaming my keyboard for a skill issue is a top 1 gamer move)
wsp i have problem with URP pipe
i have like file of that but i cant import it to graphics in project settings
If I wanted to have a constant line going from my GameObject to another GameObject, and it automatically moves itself when either GameObjects change positions, what would I use?
LineRenderer. you will have to update the positions when the game objects move
Alright, Mr. AI said the same thing.
this is a code channel, delete and ask about animations in the #🏃┃animation channel
If i have multiple OnEnable for my inputsystem how do I know which gets called first? I'm trying to set the inputsystem = new() in one script but then its trying to load an input before that which causes errors in another script
Hey mates, anybody experienced with unityTests?
I'm having an issue importing my scripts, I can't reference them in my tests, is there any issue with the proyect structure?
I can load my prefab but can't reference my script. Also, I tried disabling from the UI one of the scripts my prefab has but the test still executed it, any ideas about that?
It's random. You can use the script order execution innn... err project settings, but it's best to structure your code in such a way that you don't need to change that, it quickly becomes messy and a pain to maintain
I thought it was random, it was working one day but then stopped next Editor launch thanks
If it makes sense to do so, control the enabling of the objects so that they get enabled in the correct order
there is LateUpdate
It's fine I'll just move all my action calls to Start() and keep the creation of the input system in OnEnable() thanks for help
is the FloorManager assembly referenced by the test assembly?
Now, yes I managed to make it work, thanks but I was wondering.
I managed to run the playtests without creating an assembly specifically for these tests, did unity remove that button from the test runner tab? see https://docs.unity3d.com/Packages/com.unity.test-framework@1.1/manual/workflow-create-playmode-test.html
not entirely sure if they removed it, but you can always right click the project window, Create -> Testing -> Tests Assembly Folder
I think you used to be able to run tests that were in the Tests or Editor/Tests folder a while ago without asmdefs, but I'm not sure if that's still supported
Thanks 🙂
Couple of q more:
- It feels to me although I have disabled manually a script, that it still runs, I can programatically disable it on test, but it really feels akward that this happens.
- The test with this component actually fails by a log error message, why is this the case? Usually in other languages logs really don't matter to your tests, just exceptions.
the log error is unexpected indeed, you can disable this behavior for a test case with LogAssert.ignoreFailingMessages
not sure what do you mean with your first question though
Can you configure the log stuff globally?
So, I have a prefab with a bunch of scripts, see image. I have manually disabled the Spawn manager script (I unchecked the checkbox on the left of the name).
But my tests, do seem to execute it's code, at least the awake method, is this expected?
Because, as my code subscribes to an event:
private void Awake()
{
EventDispatcher.Subscribe(EventType.FloorReady, OnFloorReady);
_floorManager = gameObject.GetComponent<FloorManager>();
}
Chatgpt tells me that:
In Unity, the Awake method will still run when instantiating a prefab, even if the script component is initially disabled in the prefab. This can happen because Unity initializes the entire object hierarchy during instantiation, which includes calling Awake on all components regardless of their enabled state.
if this is the case, it feels like I'm doing something wrong tbh
I don't think you can do it globally, but you can have a method with the [SetUp] attribute and that will always be executed before the tests, then you can have a base class with that
the Awake method should only be called on enabled MonoBehaviours, there should be no differences between play mode or test mode in that regard
So would you say this assertion is true?
I thot that when you disabled something from the inspector, it would not run the awake method:
In Unity, the Awake method will still run when instantiating a prefab, even if the script component is initially disabled in the prefab. This can happen because Unity initializes the entire object hierarchy during instantiation, which includes calling Awake on all components regardless of their enabled state.
the docs say something similar indeed, but you can easily test this
the behavior should be the same in play mode or test mode though
change your Awake to OnEnable, debug the difference
boxBottom.GetComponentInParent<BoxController>().moveable = false;
Anybody see why this line of code wouldn't change the variable "moveable" to false in my Box Controller script?
Multiple BoxControllers in the tree?
no, not as far as I can tell
how do you know it doesn't?
BoxController controller = boxBottom.GetComponentInParent<BoxController>();
controller.moveable = false;
Debug.Log(controller.name + " moveable changed to " + controller.moveable);
start with this
I watch the check box
so, basically you don't know
If the line I showed set the variable to false, the checkbox would uncheck
yes but you are assuming 2 things
- the object boxBottom is the one you think it is
- The BoxController script found is the one you think it is.
you need to check that both of these assumptions are actually true
ok, so the code is accessing the method in the other script. I must just need to create a delay within that method
not what I am saying at all
Debug.Log the InstanceId's of both objects. Switch your Inspector to Debug mode and compare the InstanceId's. They must match
It's also possible that some other code then immediately changes the value back to true. You can't see it just by looking at the checkbox.
I put a debug.log in the method that the change gives me access to, which tells me the code I posted works.
That is in fact the problem. Thank youo
but it does not tell you EXACTLY which objects it is working on
If it accesses the method within the script I'm targeting, that's a pretty dead giveaway
no it's not
The script is doing what I wanted it to do now and my question was answered.
and you still have not learned to debug properly
Isn't the point of debugging to determine if your code is working the way you want it to?
yes, but also to determine if the objects it is working on are the objects you think they are.
A C# script can have many instances, each the same, if you do not KNOW which instance you are talking to then you will not get the outcome you expect
Maybe it's because I didn't post my entire code, but it seems unnecessary in this particular case. I can see where it might be useful in other circumstances, but I'm fairly certain I'm communicating with the right object and script due to debugging I did previously.
you do you but in my book 'fairly certain' is not certain enough
In different circumstances I might agree with you
"Fairly certain" is not enough in programming. If everything you were "fairly certain" about was true, the code would be working. So now your job is to find out what things you think are true that actually arent
If that line of code is running, it's setting that value on that specific object to false.
So, either that line isn't running, that object isn't the one you think it is, or something else is changing it back
Also, this channel has had a ton of people that assume everything around the problem works fine. It rarely is.
I got the code working in the beginning of that conversation and he was still insisting I did the debugging his way. I understand the need to be precise. Anyway, I had to scrap that whole code and rethink the problem anyway. What I was trying to do wouldn't work because of other factors.
I was also, just trying to give a general lesson on how to debug because, tbh, you didn't seem to have much of a clue
Hey all. In your games you're working on, do you reload scenes through scene manager? Or do you simply reset all the data to the beginning instead of reloading scene? Maybe like put a fake load screen so player does not see whats happening and thinks its reloading etc? I am currently having trouble reloading my scene.
hey guys, sorry for the silly question but I'm completely stuck on this. I'm trying to build a system for mesh culling, but I'm having an issue with arrays and lists while generating the "map" of what gets culled when.
https://hatebin.com/fcpjousaeg
the premise of the system is simple. I have 2 structs that come in to play during runtime, a simple "drawslot" struct, which is just a mesh, a material and an array of matrix4x4s that the system uses for GPU instancing, and another "drawSlotIndexMatrix" struct, which just contains 4 matrix4x4s (for each cardinal direction each mesh might need to be rotated in), and an array of integers, representing the indexs of the "drawslots" it will add these matrix4x4s to when the camera will be viewing the building from said direction.
the issues however, comes while building this "map" of matrices and drawSlots.
you have 4 wall prefabs, each represented by a struct called a "buildSlot". each "floorSlot" contains 4 of these, and the system simply loops over all the wall slots in each floor slot, building a "map" of matrix4x4s and integers to add to an array of matrix4x4s which can be drawn by the GPU as needed.
however, there is an issue. while looping over the 4 walls, the script for some reason beyond my comprehension, as it loops over the 4 walls, it adds the mesh indexs to ALL 4 DRAW INDEXS, and I have no idea why.
am I missing something? or is this just a quirk with arrays and lists I don't understand?
as can be seen in the first image provided, the system should be working (I'm currently only using a simple wall data, with 1 front and 1 back mesh), but in the second image one can see that the script is adding the int "startIndex" to ALL of the elements in the buildMatrices array, causing it to be added to the final "front draw indexs" element 4 times (one for each wall)
as can be seen in the video provided, the system is adding matrix4x4s to the drawslots correctly, its just adding all the draw indexs to the drawSlotIndexMatrices as I loop over them.
any help is greatly appreciated!
I'm a beginner, no doubt, and I appreciate the help. Sorry if I came off argumentative. Trauma response. Nothing personal.
SceneManager.LoadScene(newGameScene);
It gets rid of all the additively loaded scenes though.
Oh, that's beyond me. I've not done a whole lot with scenes yet besides title screens and such.
Yeah like im trying to keep my init scene while reloading the currently active scene additively.
I don't need to have "Is Trigger" checked to use OnCollisionEnter, do I?
In fact you can't check is trigger if you want to use OnCollisionEnter
OnCOllisionEnter only works with non-trigger colliders
Thats what I thought
Hey I need a little help, Im using the new coding software and ive followed the tutorial to install intellisense but it still seems to not be working
What new coding software?
Rider?
!vscode
I'd recommend Rider, it's much easier to set up and works better (and is also free)
Free under specific circumstances. Not for commercial use
This is a little embarrassing but I'm having issues with a simple collision. The script seems fine, is saved and assigned in inspector. Neither object has "Is Trigger" checked. The object tagged with "Bomb" has the rigidBody. But the objects are still passing through each other and the Debug.Log is not being triggered. Anybody have any ideas?
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Bomb"))
{
Debug.Log("Collision detected.");
}
}
if they are passing through each other there is no collision
if there is no collision, OnCollisionEnter won't run
show the inspectors for the two objects.
You want a screen cap?
yes
Your story is fairly difficult to follow so I don't know what the problem even is, but why don't you just attach your debugger and step through the code to see what's happening?
This is for the "Bomb"
This is one of the objects with the script. Each wall of that box you see has the script assigned to it
those walls are pretty thin. Is the bomb moving fast? Try setting collision deetection mode to Continuous on the bomb
The bombs just drop down but the player moves into them at a speed of 20
It's been a while - but the OnCollision events only get sent to the gameobjects with the RB on, don't they?
the box is the player?
If the box is MOVING it needs a Rigidbody
Looks like the OnCollision is on the wall, without an RB
yes
and yeah the script with OnCollisionEnter must go on the parent object with the Rigidbody
not the child with the collider
you should set the collision detection on both moving objects to continuous as well
ok
Sorry thanks for the help before but one more issue, Im trying to make it to where when my player jumps its set to "true" while they're still in the air; but once they land on the ground its set to "false". I already have my ground's tag as "ground" but it still wont set the "isjumping" to false. any help?
Also if the player doesn't have a rigidbody it suggests that it's not moving using physics
Use Debug.Log to verify that OnCollosionEnter2D is running
It doesn't, really. It just moves around trying to catch the balls
is the ground actually tagged as 'Ground' ?
moving obejcts with colliders must have Rigidbodies
or things get wonky
and you need to use physics to move for collisions to work properly
the "Bomb" uses an rb and I read that all you needed was one for collisions to work
it is not
yes
well that's a problem
did you put it outside the if statement?
if you did then you haven't satisfied the requirements for OCE2D to run
lol yeah it is, and yes I did
Cna you show the inspectors of the two objects that are colliding?
or meant to be colliding
All objects that move must have a rigidbody (and use forces/velocity to move)
will do, gimme a sec
The "Playercontroller" is the one thats jumping should be set to false once it touches the ground again, the ground is the stage
heres the play area if you need it, though before I hit play I have the box in the air so it can land on the ground, then I get to testing
the setup seems ok. Can you show the updated code with the log in it?
And can you show a screenshot of your console window too
public void Move(InputAction.CallbackContext context)
{
horizontalMovement = context.ReadValue<Vector2>().x;
}
Why is Vector 2 wrong in this case?
what makes you think it's wrong?
And what are you trying to accomplish?
the error in VS Code haha
What error
You know we can't see your VSCode right?
What does the error say
just share the error message
You should get used to actually reading error messages
You did using System.Numerics;
you need to delete that
which class should be responsible for updating text of UI of resources like Stone, gold, wood etc ?
I have a class called Resources, that tracks the amount of resources. should i update the UI from it?
use events
UI is best updated using the observer pattern
events?
basically a script on the UI that listens for events from the game's data model.
i see i see
okay Thank you, that work
do you have anything in another script overriding the isjumping boolean?
oh what the heck
hey yall .. i jus finished learning simple physics n player movemnts where or what should i start learning 2nd?
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I have like five different coding scripts all called the same thing
ty
im gonna delete all of them and just copypaste my script and get back to you
it should have given you an error if they are the same name and have the exact same variables
it didnt for some reason...
Hi, is it possible to keep updating the mouse position even if the window is not focused?
I couldn't find much on this because it's a really odd thing to do but I need it in order to avoid executing a shell script constantly which would be inefficient if I am not mistaken.
Hi, I've since found a quick fix for this error and I'm working on fixing other bugs with it now, but thanks for looking at my question anyway!
which window ?
the unity window
I am making a background music visualizer which means that the window is not focused and therefore, I am not getting mouse position updates
I think you can just use the Run in Background option in the Player settings
I already am, cursor is not updating the position
Are we talking about the Windows OS here?
fixed it, thank you both. It's that I had multiple scripts @wintry quarry
no, linux, arch, hyprland
then I suggest you go do some research, every OS GUI is different
I recently heard about "bootstrapping" in unity and I've been skimming around some youtube videos trying to find out how it works
what I'm not quite getting is who has the responsibility of actually getting data from the bootstrap scene into objects in the scene
this aint a beginner question
at the moment I have a small project with a single scene that has some singletons and I'd like to have a main menu scene where the player can input some numbers and those numbers are shot over to the actual game scene where it gets thrown into a singleton as some init values
and I'm curious what best practices are for this
actually I think I'm misunderstanding what a bootstrapper is supposed to do lol
!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.
Bootstrap scene with DDOL objects
https://hatebin.com/suhvbejocj
Could somebody look at this code? I keep getting: Object Reference not set to an instance of an object but I don't see why this wouldn't work.
on which line
32
at a guess i'd say one or both of your GameObject.Find calls is failing. but you've also failed to say where the error actually occurs
then sphere is null
Then either sphere or box is null. Use logs to find out which
if it was box it would fail on the line before
@past spindle See what I meant about learning how to debug? It took us literally 5 seconds to see the problem
This time we're on the same page.
Does anyone know how to add animation when key get press?
But I don't understand why it failed
because the Find did not work so returns null
you don't have an object in your scene named Sphere at the time this code runs
I'm adding my animation to any state but it seems not working
At that point, check the docs:
Hey guys I have this code snippet:
cam.transform.rotation = Quaternion.LookRotation(newCameraDirection, PlayerCam.transform.up);
This works well if the camera and player are facing the same direction, but when they are opposite directions from one another the transform should be mirrored on the other side of the Vector3.up so that they look synced (see the image attached).
Basically I need the mirrored PlayerCam.transform.up relative to vector 3.up
This diagram is kinda hard for me to think about... what is the layout of the scene exactly and what is the goal here exactly?
Basically my player does a 180* turn when I invert gravity so it faces upside down
I have portals like in portal 2
the illusion used to break b4 when turning 180* because I was using Vector3.up as the up direction for the Quaternion.LookRotation
I changed that to PlayerCam.transform.up
but that still breaks the illusion of portals that mirror one another (opposite directions) as it appears in the portal image that the portal flips opposite to the PlayerCam
So I need to mirror the PlayerCam.transform.up so that it's going the opposite way when portals are mirrored so the illusion doesn't break
I can deal with vectors but not quaternions or rotations, it's beyond me
The questions boils down to how do I reflect a vector3 across a normal/axis
Yeah the simple solution here is this:
Quaternion diff = exitPortal.rotation * Quaternion.Inverse(entryPortal.rotation);
Quaternion newCameraRotation = cam.transform.rotation * diff;```
it's highly possible I have the order of that diff calculation backwards
Anybody know nothing about RenderTexuture and Unity 6?
looks like the texuture didn't get updated unless I change any of the camera parameters like Clipping plane (far/near) ¯_(ツ)_/¯
Nevermind, was messing up the scene and 3 cameras were writing on the same texture 🫣😅
ended up giving up and converting to euler angles instead
cam.transform.rotation = Quaternion.LookRotation(newCameraDirection, PlayerCam.transform.up);
Vector3 currentEulerAngles = cam.transform.rotation.eulerAngles;
currentEulerAngles.z = 360f - currentEulerAngles.z;
cam.transform.rotation = Quaternion.Euler(currentEulerAngles);
now it works
the original text in my game was "<w>Ayo...</w>" . I made custom "<w> </w>" tags and used regex to detect when they popped up in my text. after my regex finds a match, i apply a wave effect to each character of the matched text. the end result of this is supposed to turn the original "<w>Ayo...</w> text into a wavy "Ayo..." text. however my screenshot shows what it displays in game. the wave effect works perfectly fine but the text is all skewed.
(after further debugging it seems like my code uses the displayText for actually displaying it correctly but another script perhaps interferes with it and makes it completely ignore my regex and adds back in the "<w>"
here is my typing script
https://hatebin.com/paqdnbyotw
Invalid regex, according to https://regex101.com/
Escaping the slash does what you expect it to.
C# string might need you to escape the escape character, so if it still doesn't work, try <\\/?w>
the same problem still persists. however when debug.logging it tho it says the correct text
If the log is correct, then that would mean the textbox is showing something that is not displayText
Is there a AI for Unity yet that automatically creates UI? Even basic? Based on some Model/ViewModel or whatever.
You set textLabel.text before the loop, but nothing in the loop is preventing something else from setting that. It'll just continue to loop over whatever text value that text element has, but you're using the length of the parsed text, which is why it's cutting off early
So, something outside of this loop is setting textLabel.text to the unparsed string, after this coroutine has started
right and i'm thinking this could be the script which displays the dialogue onto the ui which occurs after the typetext coroutine has begun. should i share that code?
I suppose
okay, thank you for taking your time out to help me. also note that the "typewriterEffect" script this is mentioning is the code you were just looking at
So, StepThroughDialogue is setting the text each frame that the coroutine is running. If both coroutines are running, this one would "win" since it sets the text most recently
right, and because this one is "winning", could it be line 9 that's messing up what text is being shown and what's not?
Since the typewriter effect just changes how many characters of the textLabel are visible, whatever the most recent change to textLabel is will be the value of that text box. You'll want to find anywhere that you change that value, and see which ones happen in between textLabel.text = displayText; and textLabel.maxVisibleCharacters = i + 1; in the typewriter coroutine
sorry i don't understand your second sentence, could you explain further?
Step 1: TypeText sets the value of textLabel.text to displayText. As your log shows, this is the correct string value.
Step 2: Then, something else changes the value of textLabel.text, somewhere.
Step 3: TypeText now reaches the part where it changes textLabel.maxVisibleCharacters, which updates the text in the UI element. This is changing the visible characters of the new value that was changed to in step 2.
So, look at anywhere you change that text, and find out what is setting it in between steps 1 and 3
i think i've found what is setting it in between steps and 3! after the runTypingEffect coroutine my code debugs the correct text which is, "Ayo..." however after setting textLabel.text = dialogue;, my code debugs "<w>Ayo...</w>" for some reason with the wavy tags??
You're setting it to dialogueObject.Dialogue[i]
Does dialogueObject.Dialogue[i] have the tags in it?
yes it does
So that would be why the text now has tags in it
because you're setting it to a string that has the tags in it

asking whether AI is available
Yes and I'm telling you how to do it yourself
ohhh okay, but then what else would i set it to? wouldn't my text need the tags?
how is that not totally irrelevant?
You would set the text to the value you want the text to be
making ui yourself is more fulfilling, it teaches you something new, and it most definetely will turn out better than ai :)
Because my suggestion will actually help you finish something
something other than my generative AI for Unity? 😆
anyway the reason I'm asking is because I hadn't had the chance to mess with Muse and other AI assets in Unity, so curious on what the SotA is atm
Sorry, you're right, let me link you something more your speed.
https://www.amazon.com/Crayola-Washable-FingerPaints-Stocking-Stuffers/dp/B00MC7WV6K
and that would be my text without the tags, so like this?
string displayText = Regex.Replace(dialogue, "<\\/?w>", ""); textLabel.text = displayText;
I'm tempted to ping the mods to give you a warning.. hope you're not being an arse to newcomers too
Well, what's the point in changing the textLabel contents outside of the RunTypingEffect coroutine?
You should probably have one singular place responsible for changing the text, then you can let other things read the value of the textLabel, and know that it only changes in the one place
A newcomer is at least doing the work
i don't know to be honest, i feel like this whole thing of hopping between scripts s very inefficient. i agree with your idea of having one singular place responsible for changing the text. how would you recommend i go on about doing that?
what's the actual issue? I would say more have standalone and reusable components than handle everything from a single place.
e.g.: You could make a TypeWriter script that only has this public method:
public void Write(string text, System.Action callback);
or even this if you're going for nesting coroutine behaviours:
public IEnumerator Write(string text);
Then you could await it with yield return StartCoroutine(typeWriter.Write(dialogueText));
Ther are a lot of ways to handle this and it mostly just comes down to planning out what you need to be done and ensuring that everything has one specific "job" to do. Figure out what is responsible for deciding which raw text to display, what is responsible for handling the tags and their effects, what is responsible for just putting text on a screen, etc.
I would not recommend using so many coroutines. Use components with Update functions instead.
Probably the only coroutine you'd need is the RunTypingEffect, and it should just handle slowly increasing the maxVisibleCharacters over time, and should be able to report when it's "done" for other scripts to deal with
the parsing and displaying can be done elsewhere
okay, i think for now with my coding ability as well, i'll just remove the text effects part of my dialogue system and let future me expand upon that using my future knowledge along with the points you've stated, thank you guys for the help!
np. It's not wrong to have everything on a same place if you think it's very specific or won't need to be reused, but it's very likely you'll want to reuse it eventually -- be it on the same project or in others.
how do i set a new parent to a game object
can someone check out why this scriptable object keep resetting every time unity reload? other scriptable object is fine but this one has a custom editor and it wont save
Edit: solved it
ok thanks
Hello! sorry im having a issue with the recent change to Unity 6 was using the version before and the controllers that im using for my 2.5D game no longer works do to a change in the rigidbody.velocity, it wants me to use linear velocity but it doesnt work, here its the code if anyone could help me
It was working in the version of unity (2022.3.22f1)
Change .velocity to .linearVelocity
when i set its parent it becomes scaled like it
how do i make its scale independant
By not making it a child object
but i want it to be welded to it
A child object's transform is based off of its parents.
You could use a Joint or a Position Constraint
im trying to do an item pickup with a tutorial
i meant without a tutorial
i feel like this is dumb
Thanks, sorry it was mb I had the rb in kinetic and it was messing it up
why dont you get ai to do the rest of the project as well
then you can sell it for a bazillion dollars
there are bunch of AI assets that write code and set up component behaviours. e.g.: https://assetstore.unity.com/packages/tools/generative-ai/ai-toolbox-with-chatgpt-dall-e-whisper-gemini-etc-250892
The asset store even has a separate section for generative AI assets: https://assetstore.unity.com/tools/generative-ai
why would you want AI to create UI for you?
well, for starters, it's my least favourite part in development
This is a coding channel
also, could iterate a lot and create bunch of layouts to choose from rather than working in figma or photoshop or something
no.
also this is a coding channel, lets talk in #📲┃ui-ux
<@&502884371011731486> I believe you know what to do
that was insanely quick, good job
Im using unity 6 behavior Graph, is it possible to release an event from C# side for the Wait For Message node to receive? if yes how could I do it?
Im trying to create a turn based rpg battle system like in Final Fantasy. I want it so that the damage that the player deals is shown above the targeted enemy. So if the player attacks with a damage of 10, it will create a text and that text will show the damage done. This is what I got so far.
{
player.StartAttackAnimation();
int damage = player.attackPower;
CreateDamageText(damage, enemy.transform.position); // Pass damage and the targeted enemy to createDamageText()
enemy.TakeDamage(damage);
EndTurnPlayer(player);
}
private void CreateDamageText(int damage, Vector3 enemyPosition)
{```
It creates the text field and everything is fine, but the text is not visable in the gameview. Its like in another position? Im new to Unity so I dont really understand whats happening. Was wondering if anyone could help me. Thanks!
{
// Instantiate the damage text prefab
GameObject damageTextObject = Instantiate(damageTextPrefab, canvas.transform);
TextMeshProUGUI damageText = damageTextObject.GetComponent<TextMeshProUGUI>();
damageText.text = damage.ToString();
damageText.fontSize = 0.5f;
Vector3 positionAboveEnemy = enemyPosition + new Vector3(0, 1, 0);
damageTextObject.transform.position = positionAboveEnemy;
StartCoroutine(DamageTextAnimation(damageTextObject));
}
// Coroutine to animate and destroy damage text
private IEnumerator DamageTextAnimation(GameObject damageTextObject)
{
float duration = 1f; // Duration of the animation
float elapsed = 0f;
Vector3 originalPosition = damageTextObject.transform.position;
while (elapsed < duration)
{
elapsed += Time.deltaTime;
damageTextObject.transform.position = originalPosition + new Vector3(0, elapsed * 2, 0);
Color color = damageTextObject.GetComponent<TextMeshProUGUI>().color;
color.a = Mathf.Lerp(1, 0, elapsed / duration); // Fade out
damageTextObject.GetComponent<TextMeshProUGUI>().color = color;
yield return null;
}
Destroy(damageTextObject);
}```
you're trying to spawn a ui element using world space coordinates
You're most likely using a screen space canvas
so that's a completely different coordinate system
using enemy.transform.position as the position is not going to work
yeah I am
One option is to use world space UI instead (canvas render mode - world space)
sure but like
you probably don't want ALL your UI to be world space
jsut the damage text or whatever
switching that is going to pretty much immediately break all the other UI in that canvas
Yeah it messes up all the panels and stuff
Is there a way to just make the damage text world space?
Would it require another canvas
yes you make another canvas just for that
How can I make it so that when the character jumps it jumps normally and not bounces? because, for example, if I press several times or hold down, it doesn't always jump the same height and it seems as if it were bouncing.
A normal, well executed jump mechanic doesn't exhibit those behaviors. You must have made some mistake in your code or your scene setup.
It's in 2D. I use this code:
if (Input.GetKey(KeyCode.UpArrow) && jump == false) {
rigid.AddForce(Vector2.up * strenght, ForceMode2D.Impulse);
}
- you're using GetKey which is true continuously as you hold it down. Most likely you want GetKeyDown
- You're probably running this in Update (physics always belongs in FixedUpdate)
- no indication here if and when jump gets set to true
!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.
For sharing code in the future, it's better to share the full script as such^
I created another canvas, and set the render mode to world view and the battle text is a child of that canvas when it gets created. But its creating it off screen? I coded it so it should create it above the enemy position that the player is attacking.
10 is the damage the player is doing
pay attention to the position and size of your canvas
and the position of your text object
I set the BattleTextCanvas to the size of the scene. So it covers the whole scene. Is that wrong?
I would most likely just make a small canvas containing only the text
and move the canvas around
Or just not use UI at all
just use TextMeshPro
as in - not the UI version
Which IDE is best to use? VS Code, VStudio, Rider
Hi, someone can explict why whathapened this?
personal preference really, I heard rider is great but I have no opinion since I do not use it
VSC is lightweight and does require extensions to be installed first before use with unity (basically a glorified text editor)
VS is great overall IDE but is not lightweight and comes with most bells and whistles that and ide provides
what are we suppose to be looking for, what do you expect to happen
presumably, your code?
Well, I loocker, and a entrance looker that able a player entry to loocker, but, a entrance looker have collider trigger for a message in screen, the problem is that camera view and entrance loocker crush and move to player, both colliders (Entrance and camera) have collider trigger
Isn't the trigger supposed to allow traversing objects?
okay so you have a collider stopping your character from moving when you look up im guessing
vut
lets take a look at that objects inspector
your code could also be the culprit as well
Yeah
ok
Loocker
Entrance_Loocker
we don't need to see the lockers inspector, just the "looker"s inspector
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Object_grab")
{
grab_message.SetActive(true);
player.GetComponent<player_controller>().can_grab = true;
}
if (other.gameObject.tag == "Entrance_loocker")
{
player.GetComponent<player_controller>().can_hide = true;
hide_message.SetActive(true);
}
}
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Entrance_loocker")
{
if (player.GetComponent<player_controller>().hide == true)
{
hide_message.SetActive(false);
exit_message.SetActive(true);
}
else
{
hide_message.SetActive(true);
exit_message.SetActive(false);
}
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Object_grab")
{
grab_message.SetActive(false);
player.GetComponent<player_controller>().can_grab = false;
}
if (other.gameObject.tag == "Entrance_loocker")
{
hide_message.SetActive(false);
exit_message.SetActive(false);
player.GetComponent<player_controller>().can_hide = false;
}
}
first off !code, second off place any code that does movement
📃 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.
That is an other script
void Update()
{
if (!hide)
{
moveInput = playerInput.actions["Move"].ReadValue<Vector2>();
if (playerInput.actions["Run"].IsPressed()) //!crounch
{
speedCurrent = speedRun;
}
else
{
speedCurrent = speedWalk;
}
movement.x = moveInput.x;
movement.z = moveInput.y;
movement = cameraTransform.forward * movement.z + cameraTransform.right * movement.x;
movement.Normalize();
// if (crounch)
// {
// transform.localScale = new Vector3(1, 0.6f, 1);
// }
// else
// {
// transform.localScale = new Vector3(1, 1, 1);
// }
}
}
okay so you are using the camera's direction, use the players transform instead
you can also add an orientation object under your players hierarchy as well and use that transform
How¿
add an empty object as a child facing in the forward direction of your player and reference it in your movement script then use its transform
is that the orientation object? that does not seem like it is
How do you set this 3D text so that its in front of everything else?
Right now, it goes behind everything
if its a mesh its probably the Z position
I am trying to have the player pick up boxes and there will be 10 of them. But I dont want them to be able to pick up more than 1 box at a time but I cant find anything on how to do this. This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoxPickup : MonoBehaviour
{
public GameObject PickupPrompt;
public GameObject BoxOnPlayer;
// Start is called before the first frame update
void Start()
{
BoxOnPlayer.SetActive(false);
PickupPrompt.SetActive(false);
}
private void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player")
{
PickupPrompt.SetActive(true);
if (Input.GetKey(KeyCode.E))
{
this.gameObject.SetActive(false);
BoxOnPlayer.SetActive(true);
PickupPrompt.SetActive(false);
}
}
}
private void OnTriggerExit(Collider other)
{
PickupPrompt.SetActive(false);
}
}
!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.
oops my bad
You shouldn't test for input in physics callbacks
Also you should use CompareTag, not equality to compare tags
To answer your question, just cache a reference to the box you're carrying and set the reference to null when you drop it
I am trying to have the player pick up boxes and there will be 10 of them. But I dont want them to be able to pick up more than 1 box at a time but I cant find anything on how to do this. https://hatebin.com/tjplqdrkbf
On pickup, check that the reference is null to confirm you're not carrying anything
and what is this?
Cinemachine the player camera view's
that is not what I said to do, you have to make a new empty and name it "orientation", then place this new object right where the center of your player is, then reference this object in your movement script and use its transform
Ok, i get it
I am trying to limit the player to only holding one object.
Yes, and what I described is one method of doing that
okay sorry i was confused
how can I see what index it attempted to call when this exceptionn was thrownn?
Use the debugger and have it break on exceptions
Im very confused. When "E" is pressed I need to check if the object is null but i dont know how to do that
Seeing the code would probably allow folks to guess, if you're looking for someone to make a guess.
For example, if the collection has a size of zero it's probably throwing on the first element..
You need to invert this logic and put it on the player, so the player holds the box and tracks that
I'm running into a problem when toying with camera controls.
I'm trying to make it so pressing Q and E makes it so the camera rotates about a point at set angles. A lot like what xcom did.
Issue is, in xcom, when a rotation occurs, it doesn't seem to change what is at the center of the screen (barring when the elevation of the camera is changed, which makes me curious).
In my current implementation, it unfortunately does change what is at the center of the screen. If anyone has any advice, let me know! If you want to look at the class involved, here it is: https://pastebin.com/Q5uSGmc1
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
private int[,] fieldsCoords = new int[1, 4] {
// format: {x1, x2, y1, y2} bottom left -> top right
{-20, -12, 4, 12},
//{10, 20, -30, -20},
};
void Start()
{
for(int i = 0; i < fieldsCoords.Length; i++) { // loop through each field
for(int j = fieldsCoords[i,0]; j < fieldsCoords[i,1]; j++) {
for(int k = fieldsCoords[i,2]; k < fieldsCoords[i,3]; k++) {
Debug.Log("(" + i + ", " + j + ", " + k + ")");
var tile = Instantiate(fieldTile);
fieldTilemap.SetTile(new Vector3Int(j, k, 0), tile);
}
}
}
}
the last debug.log before an exception is thrownn is (0, -13, 11) which refers to the (i, j, k) values
im trying to make it easier to generate the tiles by having a 2d array of them at the top instead of hard coding the numbers into Start()
fieldsCoords[i,1] returns an element (value) and not the length of the collection. Will this value be the size of the collection?
yeah thats what i intended it to do
Array Length is the number of elements in the entire array
oh
Not just the first row
how can i get the number of rows of the 2d array?
GetLength iirc
got it, thanks
Im having a problem im trying to make it when the Player or Enemy attacks and the Enemy or Player takes damage it flashes white for 0.2 it works when the Player takes damage but not the enemy in the Entity FX Scrpit you can see it switch Materials and switch back but it does not show on the enemy its self
I am trying to make the player only pick up one object at a time. Here is my code https://hatebin.com/ueejujnkqz
Is there a less instant version of RotateAround? It's a bit jarring for what I'm trying to achieve
https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html
it has a parameter for the angle to move by. if its instantly, thats because you set the angle too high then
Oh, I think I see what's going on. Yeah, I'm just calling it once and instantly setting the angle to what I want it to be, rather than using a smaller number until I reach the target
you still want to see the details - but make the texture whiter?
make a shader and multiply by HDR white (values above 1) to make the texture more white.
does anyone have any idea on how to implement crouching with a character controller?
Hey mates, has anybody managed to run unity tests from VS code?