#๐ปโcode-beginner
1 messages ยท Page 765 of 1
Deprecated ? Intellisense can't find anything about LightUnitUtils
I'm genuinely lost on this man
Ahh, okay, well at least thats some information you can work with.
Regardless, that's really not helpful for me anyway, my issue isn't unit conversion ๐
I was just wondering, if your light somehow is in a different mode than your RP or something and therefore converts the lumen values weirdly
But wait, it just says, SetIntensity is outdated. not setting intensity on the HDAddlight... directly
hdLightData.intensity is deprecated too, it says to "Use Light.intensity instead" which, afaik i think resolves to what I was doing with flashlight.intensity since flashlight really is just a Light
I think the whole HDAdditionalLightData thing has been deprecated maybe was used during the whole HDRP merge thing or idk
@fluid ether This page for HDRP: https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@17.4/manual/creating-and-editing-lights-at-runtime.html Seems to imply that you can set the intensity using light.intensity to any number, not just between 1-8 (look at the examples)
Does that break in some way when you try?
yeh, its all deprecated, my bad. I just read about the clamp happening due to exposure or other values in the RP settings
Indeed, all deprecated :/
Documentation for HDAdditionalLightData:
But HDRP says
Someone forgot to update the docs
Yeah that just resolves back to Light.intensity, which is what flashlight.intensity is doing in my code.
Does seem like it
Is there an issue with just using that then?
So this seem to work on my side. on HDRP. It has to be something on your settings
Yes it just won't set the intensity, it defaults to 600 no matter what I set it to
You spawned the Light and its parent GameObject at runtime in code ?
Nope, just set it in hierarchy. but let me copy your code actually into my project and see what I get
can you paste it quickly somewhere or tag it?
That works for me too, it's just the runtime spawn that won't set the intensity for some reason
Now I am hooked and want to test it ๐
sure, here
{
flashlightObj = new GameObject("Flashlight");
// Fallback to attaching the flashlight GameObject to the parent if playerCamera can't be obtained.
if (playerCamera == null)
{
flashlightObj.transform.parent = transform;
Debug.LogWarning($"{this.name} tried to attach {flashlightObj.name} to the playerCamera but it was null." +
$"Used fallback attachment to parent transform." +
$"This will likely cause unintended behaviors and should be fixed.");
}
else
{
flashlightObj.transform.parent = playerCamera.transform;
Debug.Log($"{this.name} attached {flashlightObj.name} to {playerCamera.name}");
}
flashlightObj.transform.localPosition = Vector3.zero;
flashlightObj.transform.localRotation = Quaternion.identity;
// Set up flashlight component.
flashlight = flashlightObj.AddComponent<Light>();
flashlight.enabled = true;
flashlight.type = LightType.Spot;
flashlight.lightUnit = UnityEngine.Rendering.LightUnit.Lumen;
flashlight.intensity = 5000f;
flashlight.spotAngle = 80f;
flashlight.colorTemperature = 4000f;
}```
!code
๐ Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Haha, nvm, copilot ai just created it for me 
oh my bad
the issue is, that you can not set the intensity directly after setting the lightunit
I guess, because HDRP is recalculating all lights all the time. And therefore trying to ease out all lighting to fit PBR realistic lighting
if you just set it in update for example, it will eventually reach the lumen
i set it on the ToggleFlashlight call and it does work but this isn't something i'd expect
would the StopCoroutine on line 28 stop the coroutine started in line 20?
A tool for sharing your source code with the world!
I would store the coroutine in a property to be sure, you are starting and stopping the correct one
thank you for your help, much appreciated!
how would I go about doing that?
thank you as well!
I just tried async delay the setting lumen mode and wait for a 1sec and then set intensity to 10000f and it results in something around 21k. So thats where my assumption comes from about it recalculating over time
makes sense
You are very welcome. Great learning for myself in the future ๐
store the coordinates in a variable?
you want to stop exactly the coroutine you were starting. so you assign the method StartCoroutine(YourMethod()) to a new property and stop that property later
google and the docs are first result: https://docs.unity3d.com/6000.2/Documentation/ScriptReference/MonoBehaviour.StopCoroutine.html
i already read the documentation, it just tells me to use the same parameter type but im not too sure on what it means by that
the example code does exactly what I suggested. assign to the field coroutine and later StopCoroutine(coroutine);
this way you guarantee to stop the one you started
oh i see thank you for your help
no, you're creating a new coroutine to stop.
already fixed but thanks for your help
didn't see anyone actually directly answer the question, so i answered it
Why when i click to any points, i got something like this in console:
Point 1 UV=(0.21, 0.54), click UV=(0.79, 0.46), distance=0,5789823
Activation Radius = 0.006, mesh sizes 0.1(X,Y,Z)
Points activating when i click to opposite side of plane.
Plane lies in XZ
!code
๐ Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
what are you expecting to get exactly? what's the issue?
I want create script, that should create polygons by points on mesh UV and translate it to RenderTexture, that using for overlay texture 1 to texture 2 by lerp, like
LerpA - Texture1
LerpB - Texture2
LerpT - Render texture
And if 95% of all points is activated i send OnBlue bool to material for changing texture
ok, and what's the issue?
(also, share your code appropriately as described in the "large code blocks" section above please)
Point don't activate when pressed
are you getting any errors/warnings? have you debugged to see what point in execution is reached? etc
A tool for sharing your source code with the world!
When you said:
Points activating when i click to opposite side of plane.
If that's the issue, check that your mesh triangles are threaded the right way.
Yeah, Point 1 UV=(0.21, 0.54), click UV=(0.79, 0.46), distance=0,5789823
It's debug log
hm so basically opposite sides, i'm noticing they're like, 1-x of each other
sounds like something was set up inverted?
Points are pass through this code:
private Vector3 UVToWorld(Vector2 uv)
{
float x = (uv.x - 0.5f) * meshSize.x + meshCenter.x;
float z = (uv.y - 0.5f) * meshSize.z + meshCenter.z;
Vector3 localPos = new Vector3(x, 0f, z);
Vector3 worldPos = transform.TransformPoint(localPos);
return worldPos;
}
After, i get coordinates of click point and compare with each point
like distance between them <= activationRadius
btw, gizmos are editor only
Wdym?
once you build the game/project, gizmos won't show up. they're for debugging in the editor
I know
Just double checking again, are you sure the triangles are wound the correct way? Winding is explained here if you aren't sure https://docs.unity3d.com/6000.2/Documentation/Manual/mesh-index-data.html
I've already created games, but not so hard
I had a similar issue where a mesh I was making via script was inverted due to the winding order of triangles
It is a mesh right?
are the gizmos in the expected place?
Yeah
I think, i should do this for now
I mean points issue
And then polygon
Yeah that's what I'm trying to help with
You say the points work if you click on the opposite side of the plane?
Yeah, like if i change activationRadius for 1, when i click it's all get activation true
If the triangles are wound the wrong way (*or some other mesh issue) the mesh will be upside down, which could explain why the mesh is working from the wrong way
How have you set up the mesh? Via code or via mesh object?
Just mesh object with collider
Idk what do u mean, can u explain some better your answer?
Looking at that it does seem like the mesh is the right way round so that won't be the issue
In your code, can you explain why on line 208:
private Vector3 UVToWorld(Vector2 uv)
{
float x = (uv.x - 0.5f) * meshSize.x + meshCenter.x;
float z = (uv.y - 0.5f) * meshSize.z + meshCenter.z;
Vector3 localPos = new Vector3(x, 0f, z);
Vector3 worldPos = transform.TransformPoint(localPos);
return worldPos;
}```
Oops
The line in question is float z = (uv.y - 0.5f) * meshSize.z + meshCenter.z;
Why do you take uv.y into world space z coordinate exactly? I'm having trouble understanding the code itself
What if i delete this method and work only with Vector2 points and get mouse click in UV?
Are you not already getting mouse click in UV? With
private bool GetMouseUV(out Vector2 uv)
{
uv = Vector2.zero;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit))
{
Debug.Log($"Raycast hit: {hit.collider.name}");
if (hit.collider.gameObject != gameObject)
{
Debug.Log("Hit object is not this plane");
return false;
}
hitPoint = hit.point;
uv = hit.textureCoord;
uv.y = 1f - uv.y;
return true;
}
Debug.Log("Raycast did not hit anything");
return false;
}
I mean do not use this part and work with point.uv in struct
public class ContourPoint
{
public Vector2 uv;
public bool activated;
}
Hold on
Wait never mind I thought I had spotted something but I misread it
So when you click it calculates the distance between the texture coordinate of the click position and the ContourPoints.UV value which is a Vector2
Yeah
The ContourPoints.UV value is also a texture coordinate right?
Not a world position?
I'm assuming you've manually defined each of the contourPoints[] values in the editor, with one for each point
private Vector3 UVToWorld(Vector2 uv)
{
float x = (uv.x - 0.5f) * meshSize.x + meshCenter.x;
float z = (uv.y - 0.5f) * meshSize.z + meshCenter.z;
Vector3 localPos = new Vector3(x, 0f, z);
Vector3 worldPos = transform.TransformPoint(localPos);
return worldPos;
}
I think it's world position
Yeah
If uv is a world position and clickUV is a texture coordinate (i.e. vector2 with values from 0 to 1 representing the position on a texture associated with that point) then that might be an issue?
yo i just started whit unity only thing i know is control.Writiline("hi"); does anione have any tips?
It is i think
!learn
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
aight thanks bro
Am I daft?
Type '='
think it is an issue or think it is a different value? i've lost your meaning
I think it's an issue
uhh can anyone help me w this one thing
so when a player walks into a portal and presses a button, the player turns 90 degrees towards the wall and all the gravity thing is shifted accordingly so that the player can walk on the wall as if its ground, whats the simplest way to do this?
I literally struggled long enough that I felt the need to ask a question here instead of normally figuring it out myself, oh no.
'Couze i thought it should be in one type of coords
!learn
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
it will be somwhere
or google it up im new so idk yet
of note, it will probably be much easier to convert from the world coordinate of ContourPoints.UV to a textureCoord than the other way around
U're trying to push an array to number 
can i not have a straightforward answer? ๐ญ
no๐ญ
No, that command is for formless questions like "How do I learn?" Any specific questions like how do I approach this we can try to help people with. If you don't know how to answer don't answer.
i actually joined the server for this one thing so i need some help ๐ญ
I've done a similar thing in 2d before, but it should be doable in 2d similarly (I'm assuming you are using 2d)
Waht
yessir 2d
U mean transform point UV coord to texture coords too?
daum
I meant to write 3d not 2d but if you're using 2d even easier
ohlmaoo
What stage are you at so far? Do you have a character controller?
The "simplest" (it's not simple) is to have custom gravity that you apply to your CC. Moving through a portal simply updates the direction that gravity points.
Yeah this is where I was going to go
yo @placid jewel what version of unity shoud i download?
Your CC will rotate so its feet is always pointed in the direction of the gravity vector.
But the bad news about that is that you have to make a custom character controller in order to do custom gravity usually
Wait I'm not sure if I even understand, is it sleep deprivation or do I actually just not understand arrays properly.
What am I supposed to do exactly?
and can i do it multiple times? like if i enter another while walking on the wall, can i walk upside down? cause like 90 + 90 = 180
Why not?
ahh okay thankss
Whichever version you want, you can research that yourself although usually the most recent LTS version. Also this is a code channel, go to #๐ปโunity-talk for general questions/
Imagine you're trying to fit a fleet into a ship
It's custom gravity, you can update it whenever and however you want.
thanks bro
I see.
You can even make your character walk around a sphere at that point, updating the gravity to always point towards the center of it.
any version that has the latest security patch
If u want arrays, just type [] when initialize variable
like bajaBlast[] = { 10, 20, 100};
So long as you're familiar with how velocity and acceleration work even in a vague conceptual state, then you can mess around with applying gravity in whatever direction you want
I JUST REALIZED.
I literally have done that for one of the variables I have.

it goes next to the type not the variable name.
Thanks.
Yeah?
you put it next to the variable name
Oh
(fun fact, languages cannot agree on this ๐)
yea lol
It's sooo different
So did they here though? So what's the issue?
ive done too much cpp recently, ive started writing them in the wrong place lmao
damn, array syntax as a whole too.
yea cpp is weird like that
It's also so strange when learning so many cpp sublanguages
meanwhile java accepting both...
I didn't add [] when I declared the variables, but I did for one of them, though.
Yeah, galaxy brain, I know.
Ahhhhh
Only one of them deserved to be arrays.
I see now
also this is for declaring, not initialization
yeah like is it type[] var var []type var[] type []type var or type []var
i had to learn 3 out of 5 of these in languages and it does get annoying...
yayyy okayyy, most stuff in the game is done and i was planning to add this thing for a gimmick for a single level and i had no idea how to implement so came here
var []type
who tf does this
Oops.
It's ok
go
try swift it gets even weirder
I tried dart
that looks so jarring...
It's looks like py + cpp
Based whitespace ignoring programmers
oh no wait
XD
was it go
that's not what it is
it is, yeah
dang im even messing them up now
var <name> <type>, so var a [2]string
ah yeah
Guys, who to do it?
primes := [6]int{2, 3, 5, 7, 11, 13}
what is thattttt
It could be in DreamBerd (though I doubt that language would stoop so low as to have arrays)
I mean this vertical line
Wait no they do
and the type of type is said like "this variable is variable as structure of type" or atleast thats how they explained it
> text here
you can right click > copy text to find out
Wait till you see DreamBerd arrays
const var
๐
yeah thats go
classic
Oh, i got it, thx
const const const, fixed value for all users, forever
yeah i found it from the arrays example
horrifying...
that looks like javascript
In dart u have
final, const, late, late final for example
no no no, constant for all users as in anyone who ever uses the language in any unrelated script around the world
its less confusing if you just keep this explanation in mind: #๐ปโcode-beginner message
damn this got off track real quick, whoops
Real
(that wouldn't make it on topic)
So, @placid jewel
I should change this
private Vector3 UVToWorld(Vector2 uv)
{
float x = (uv.x - 0.5f) * meshSize.x + meshCenter.x;
float z = (uv.y - 0.5f) * meshSize.z + meshCenter.z;
Vector3 localPos = new Vector3(x, 0f, z);
Vector3 worldPos = transform.TransformPoint(localPos);
return worldPos;
}
to this for example?
private Vector2 WorldToUV(Vector3 worldPos)
{
Vector3 localPos = transform.InverseTransformPoint(worldPos);
float u = (localPos.x - (meshCenter.x - meshSize.x * 0.5f)) / meshSize.x;
float v = (localPos.z - (meshCenter.z - meshSize.z * 0.5f)) / meshSize.z;
return new Vector2(u, v);
}
Oh no
To this...?
private Vector2 ToUV(Vector2 localPoint)
{
float u = (localPoint.x - (meshCenter.x - meshSize.x * 0.5f)) / meshSize.x;
float v = (localPoint.y - (meshCenter.z - meshSize.z * 0.5f)) / meshSize.z;
return new Vector2(u, v);
}
Just for points and mouse click earlier
You only use it in OnDrawGizmos I think?
For now
If i got u, i should change UVToWorld to Vector2 in texture coords
?. doesn't work reliably on components btw
(unityengine.Object to be exact) @boreal violet
unity overrides the == operator
Yeah so since you're using it somewhere it might be best to make a new function for WorldToUv and use that in Start to convert your List<ContourPoint> contourPoints into a List of texture coordinates that you use in update instead of the original list
That's what I'd do
I see no reason to change UVToWorld at all since I don't think it's related
I tried, after this my points just go to other place
What do you mean?
Like they was at letter 'e', after Start method they go to a corner for example
Wait what have you done
Nothing for now
Did you modify WorldToUV?
No
Or UVToWorld I meant but I think you assumed that
So wait
How does UVToWorld even work
https://paste.mod.gg/xxxzqqszkerz/0
I have this code now
A tool for sharing your source code with the world!
No changes
I think what i should do now
It takes the values from contourPoints.UV and multiplies them out by the mesh size, which would imply that contourPoints.UV were already texture coordinates
Wait tell me
How big is your mesh
.1 on each XYZ
.1? Hmm
.006 on activation Radius
I feel like the issue is from using a mixture of texture coordinates and world coordinates, and since all the world coordinates are possible texture coordinates (i.e. between 0 and 1) there are no errors thrown
But I don't know for sure
contourPoint.uv is the world coordinate of that point
If you convert it to the texture coordinate of that point and then check the distance of it from mouse click texture coord that should work no?
No?
What do you mean
What I want to know is what values are put in contourPoints.uv
And can you send a screenshot that shows the points on the mesh? (like your initial one)
Ok
Those look like texture coords to me
Since they're larger than the actual mesh size
In that case
Could the issue not be that the mosue has to click extremely close to the point in order to actually hit it?
I think no, when u change parrent size to .1 .1 .1 for example, and create child with 1 1 1, it's equal size
Wait what do you mean
Oh
I think that still works for texture coords since the mesh is square
You are doing that right?
Wait
I do think tht if the activation radius is 0.006f it's hard to get that precision
This is how close the detection range is
(The purple circle around the green dot)
You mentioned before something about if you increased the activation range to 1 it worked
What happens if you say increase it to 0.02?
In debug, it's actual size of activationRadius
Is it possible to click from the right side then?
(These are questions I ought to have really asked earlier lol)
If i change to .02:
If you click them, do they activate at that radius?
No ๐
But they do at radius 1
It's if i change to radius 1
Can you send a screenshot of the outputs of this line (with normal radius or not, it shouldnt affect)
You gave some example values before but I'd like to see at least a few of the full values
If you know where point 1 is, can you try to click next to that one specifically and show the output for that one?
Or any index point
Point 1 being the one labelled Index 1
It looks like the mouse pos is 1 - the uv coord yeah
Also, could you create a small gameobject at position (0.02, 0.054) and show me where that is?
Not parented to the mesh
Odd request but it's to check that the uv values actually line up with world values
Wait what position is your mesh actually at
-3 by z

if i change to 0 0 0
What?
Vector2 clickUV = new Vector2(1 - hit.textureCoord.x, 1 - hit.textureCoord.y);
I added this
Points get activating when i click on them
There's a possibility it's the uv coordinates that should be 1-x and not the mouse pos (though that is mostly irrelevant and just a code cleanliness issue)
What are they?
I clicked at point with black lineup, but activated with blue too
That seems like it would be an issue with the detection radius
Also here is no polygon that should lerp two textures...
Could you move the Debug.Log($"Point {i} UV={pt.uv}, click UV={clickUV}, distance={dist}"); to inside the if (!pt.activated && dist <= activationRadius) and show me which ones activate when you click the same object?
Like this
Yeah?
The logic is that I kind of flash it and when I make a large polygon, the points that are inside the polygon are activated, forming it fully, but for some reason it doesnโt take into account neigbourhoodRadius
Ideally you use your IDE correctly and do "find all references" for the symbol
Oh...
a simple text find is not reliable
it looks like your vs code isnt setup correctly anyway
!ide
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
โข
Visual Studio (Installed via Unity Hub)
โข
Visual Studio (Installed manually)
โข
VS Code
โข
JetBrains Rider
โข :question: Other/None
For what is it?
I can tell by the lack of syntax highlighting your vs code is not fully configured for use with unity projects
That's not VSCode
ah my bad, still same issue
It's this
XD
It's not my code I'm just searching through what was shared with me

why cant i export it to VRM? exporting it to VSF works, but when i load the VSF file into VSeeFace its not working. I have been doing this for like 5hrs ๐ ๐.. I have the (.glb) 3D slime object, i just wanted to use it as an avatar where it floats.
Well.. I think i should add method for get nearest activated point for my click?
!vrchat
Join the growing VRChat community as you explore, play, and create the future of social VR! https://discord.com/invite/vrchat
I suppose so
I'm not exactly sure how the polygon part works but you definitely aren't using the neighbor radius value in it
Whats the issue? I cant locate the original message
Finding the closest vertex to some position?
XD
No
Points didn't activate when i click on it
How do you detect which one is clicked and how is the state reflected in the gizmos?
private void OnDrawGizmos()
{
if (contourPoints == null || contourPoints.Count == 0) return;
planeMesh = GetComponent<MeshFilter>()?.sharedMesh;
if (planeMesh != null)
{
meshCenter = planeMesh.bounds.center;
meshSize = planeMesh.bounds.size;
}
foreach (var pt in contourPoints)
{
Vector3 pos = UVToWorld(pt.uv);
Gizmos.color = pt.activated ? Color.green : Color.red;
Gizmos.DrawSphere(pos, activationRadius);
}
foreach(var pt in contourPoints)
{
Vector3 pos = UVToWorld(pt.uv);
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(pos, neighborRadius);
}
}
uv to world wut?
Idk what is 'Wut'... :p
uv doesnt naturally translate to a vertex
I would expect a world to local position conversion for the input position, then you use local positions only (local to the mesh/Transform)
This case uses a mesh that's just a flat square with a certain size, so UVToWorld just converts the point local to that plane to a point local to the world I think
But I do agree it's better to work all in local positions
It's plane mesh
Yeah I don't know why I forgot the word for "plane" and went to "flat square" lol
I suppose it's technically accurate
Not 1st language too? XD
you just assume then that a uv pos and vertex pos are the same but that is just an assumption
At any point, I'm not sure I can be of any more help and I've got to go to bed so I'll leave you in what seem to be much more capable hands for now lol, good luck with the rest ๐
anyway wheres the other code that changes activated
No it is which is the worst part, I'm just very tired
https://paste.mod.gg/xxxzqqszkerz/0 It should all be in here @grand snow
A tool for sharing your source code with the world!
A tool for sharing your source code with the world!
Or that one
It's old vers
Go sleep hero
Thank you ๐ฉ And best of luck

This is a bad idea Vector2 clickUV = hit.textureCoord;
You should just convert the hit position to local for the object and then find the closest.
Then you can just use the methods on Transform to convert
It just started work 
I did it, so what do u offer?
What I already said but you don't seem to care
A UV position can't be translated back to a local object position reliably
A mesh may happen to have vertex positions match up with uvs and that's just luck or a presumption
So, this is why my code doesn't generate polygon for RT?
Don't know but using uvs is flawed
my charecter is phasing through edges when moving and using a jump pad im using a tilemap with comopsite collider 2d
my charecter has a sqare collider 2d
It's in the link
havent used unity in like 2 years did they change scripting fully?
Apparently cant even use do manual character movement script
gotta use a feature or something
presumably you are doing something wrong then
no you have to open this to use it
otherwise it doesnt let you use it
that's not a change in scripting, nor is it an issue with "manual character movement"
this is just you not reading your errors
nothing about scripting was changed in that regard. the new input system is just the default input handler now as of 6.1
And for velocity apparently i have to use linearVelocity or something
changes every single time i type it
yes because the name of that property has changed
there may be other small changes that your IDE will tell you about if you try to use something that has been deprecated. so just trust your tools
and for future reference, instead of asking a vague question like "has scripting changed" you should ask about your actual issue
i am not saying you cannot ask questions. i am just saying your initial question's actual premise wasn't even what you were asking about
it was more like a discuss other than a issue
aight
i got you
is there a way to chage between 3 sprite
im tryna make a mute unmute button
rn its
unmuted + click = muted can convert it back to unmuted icon
its a toggle btw
an if statement and assigning to the .sprite property
this is a code channel mate
fair enough
give #๐โfind-a-channel a read if you want to find a channel that isn't focused on code for your questions that aren't code related
okay
my chrecter is behaving as if its collideing with something even though theres nothin there
you're gonna need to provide more info, like relevant code and info about the scene setup
1min
https://paste.mod.gg/gybktjrvkcqy/0
https://medal.tv/games/screen-capture/clips/lsEpG8RNmruQk24R2?invite=cr-MSxvaXMsMjczNjI5NzM5
A tool for sharing your source code with the world!
Watch Screen Recording Trimmed Clip 1 by iron_booii and millions of other Screen Recording videos on Medal. Tags: #screenrecording
not related to the actual issue, but is this not your code, or is there some specific reason you have this part in it?
#if UNITY_2023_1_OR_NEWER
uiManager = FindFirstObjectByType<UiManager>();
#else
uiManager = FindObjectOfType<UiManager>();
#endif
same i have no clue why its there i havent added it i figured unity auto added it so i didnt remove it
unity would not have automatically added preprocessor directives
i do use ai occasionllay that my be the source aswell
This statement works only for assets
ah, yeah AI generated code makes sense. for future reference, you are required to disclose that in this server #๐โcode-of-conduct
and i don't help with AI code so someone else will have to help you
I mean assets from asset store
oh ๐ also its added by unity version controll
version control does not modify your code in any way
that was likely something added by the AI you use
okay if you say so
make sure theres no colliders in the way if you believe its hitting something..
run ur gamewindow next to your scene view window.. and click around (or select everything w/ gizmos enabled to see if theres a collider or something) also make sure your colliders are expanded.. so they'll show in the sceneview..
also make sure your colliders are expanded.. so they'll show in the sceneview..
if its only happening in that one vertical shaft area.. perhaps test out in the open.. to confirm
if the same code works fine in one area but doesn't in a specific area... then odds are its something in that specific area.. and not in the code
it also happes on top
check those areas.. โ๏ธ make sure theres nothing in the way..
- one thing we see is people will destroy or disable a gameobject (a coin pickup, or maybe a door) and they'll somehow forget to remove the collider that represents that object..
- (removing the graphics but leaving the collider)...
** this could be the cause or something
also when i stick to the right wall in the shaft area it lets me go up
what do expanded colliders mean
if i go to the render button and make it wireframe it shows all colliders ?
gotta confirm is nothing actually in the scene (thats blocking) and then you can move to the next likely thing.. (which i have no idea what may be..) might be ur jump logic.. /something in ur movement.. idk.. but the first guess is just something is in the way..
// on the the rigidbody gameobject
void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log(collision.gameObject.name);
}
if you use the https://docs.unity3d.com/6000.2/Documentation/ScriptReference/MonoBehaviour.OnCollisionEnter2D.html method you can Log everything it touches in the console...
just peep ๐ the console when that happens.. and make sure its not colliding with anything...
Negative.. Wireframe shows Meshs... but if its just a collider... it wont
thanks alot ๐ญ
this is a previous vesion i had wich i hadnt made the level sprite and collider properly so i had redone it both the current and the collion on top are fixed thanks again
i want to put my collider mode on continous but when i do that, my onCollisionEnter2D stops working
i noticed continous completely prevents tile clipping from happening which would be really nice.
private void OnCollisionEnter2D(Collision2D collision)
{
Vector2 contactPos = collision.GetContact(0).normal;
//If velocityY is relatively high
if (recordedMagnitude >= dangerMagnitude || recordedMagnitude <= -dangerMagnitude)
{
//Only hurt if hit from above or below
if (contactPos == Vector2.down || contactPos == Vector2.up)
{
int damageAmount = Mathf.RoundToInt(recordedMagnitude) / 2;
print(damageAmount);
TakeDamage(damageAmount);
}
}
}
Does anyone know why continuous just stops it from functioning?
Continuous Collision Detection wouldn't stop OnCollisionEnter2D from working, in fact that mode makes the rigidbody do more/complex checks to ensure collisions happen more reliably. If OnCollisionEnter2D is not working at all then something else is likely wrong
For example, continuous collision detection could potentially be causing you to collide with a different object than you were expecting to
should absolutely add some logs outside of those if statements to figure out what is actually happening
I added a simple print at the top. which never printed out
it should've especially if something else collided.
show both colliders involved in the collision
or rather just go through this: https://unity.huh.how/physics-messages/2d-physics-messages
Oh right that's relevant. tilemap collider can always be abit indifferent.
This is my tilemap collider.
when im i stay close to the edge of water and underwater i can see under water... any ideas how to solve it? i already set clippin planes to 0.01 and it still does that
Godsend.
that solved it
which part was it
like the last place to ask about that problem and probably one of the hardest to solve
Hey, got a question about Animation Trigger in code
why does this trigger not reset by itself when the condition gets set to false?
I go from jump to fall but isJumping still is active in animator.
A trigger will un-set itself once it's used for a transition.
it goes from Jump to fall, i can see falling animation running
it has that bar below it in animator
What is the transition condition from jump to fall
presumably you are setting the trigger multiple times, including after it was used for the transition and automatically reset
isFalling true
ah okay, i will check this thanks
you want to only set the trigger one time to enter the Jump animation then not again until you want to enter the animation again
ah i see,
btw any tutorials/assignments on net i can do to improve my animator logic?
I get stuck in it alot
Yeah, so, looks like it's set, which causes the animator to enter Jump, then there is at least one frame where the velocity is still above 0.1f, which sets it again.
Then, once the velocity becomes negative, it goes into Falling
yes, looks like its triggering multiple times
yes, every frame for pretty much the entire duration of your Jump animation
man this animator is confusing.
gets messed up so fast
made one earlier and it has like 8-9 parameters
rather than checking every frame if the velocity is above a specific threshold, why not trigger the animation when you actually add force/change velocity to perform the jump
that way you aren't setting the trigger every frame
is it good practice to set animation direction in jump function?
when i press jump
cuz arnt we suppose to keep stuff seperate?
I currently have a UpdateAnimation funciton running in Update
there are plenty of ways you can handle this. but it all stems from that initial jump input detection which is what you want this trigger to respond to
can you please suggest me a way to do it as a beginner theres so many ways it gets super confusing
i just did
Hello i am new to C# and im here to learn more to flex to teacher and get 10 int technology class hehe
yo im looking for somone to make a game whit me for now i wanan just to make a map but the idea is cool its a vr game (like gorilla tag) so if u wnat dm me
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
โข
Visual Studio (Installed via Unity Hub)
โข
Visual Studio (Installed manually)
โข
VS Code
โข
JetBrains Rider
โข :question: Other/None
you are breaking 3 rules at once ๐ญ no collab posts, crossposting the same thing in multiple channels, and posting in a code channel
No way bruh
daum๐ซก
Hello. I have a problem using TMP and some fonts with layout groups.
I'm using two objects, parent have vertical layout + content size fitter with preferred horizontal fit, child is just a centred text. When text have some symbol combinations it breaks in to two lines.
Okay, I think I can fix that by settings text to "No wrap" mode, but I'm still curious why is this happening
yea that wat i was going to mention.. it appears to be the default wrapping..
the symbol part is a bit confusing tho
Use a non-breaking hyphen which is Unicode \u2011.
The normal hyphen is defined as a line breaking characters whereas the non-breaking hyphen is not.
- Stephan_B (Unity Staff)
-# ๐ Line Breaking Characters
Hello. I tried making something on my own until realizing I am woefully underprepared.
I am trying to make an idle game where the production upgrades create an item, and that item is the thing that generates the main currency.
Kind of like > Arbitrary Building creates an Arbitrary Item and that Arbitrary item makes Arbitrary points.
I could do it one by one, which I would have probably succeeded in already, but I tried doing using lists and arrays and... Yeah, I'm lost. I'm not sure what to do.
I'm trying to screenshot this code but I don't even know what to show. Hm.
You can paste your code using the ``
Start by telling us what the main issue is (that is not working correctly) and post the code relevant to it . . .
Do you think this is a reasonable layout for a tower in a tower defence game?
Since status effects could be a big thing, I'm thinking of putting a separate script just for status effects
Blue means functions
how can i make it so particles are affected by lighting
Give them a lit material
private void OnValidate()
{
ValidateAtrributes();
}
public bool ValidateAtrributes()
{
if (DoesRequiredAttributes)
{
foreach (var attr in itemAttributes)
{
if (attr.Attribute != ItemAttribute.None || attr.BaseAttributeValue! > 0)
{
return true;
}
}
Debug.LogError("All attributes set to none Or Value is set to zero, atleast one attribute must be set to Str,Dex,Int");
return false;
}
return true;
}
I am trying to throw error if my item require attributes but the attributes in the array are not set properly , then I will get an error do I can fix it ,but currently despite some scriptable objects having the requirement for me to get an error, i dont get an error
Try logging something in the true cases. Log the attribute before the first one, and log that the object doesn't require one in the second. See which true its hitting when you don't expect it to be
Probably include the name as well
the issue was i forgot to set DoesRequiredAttributes true for the objects
the only thing id reconsider here is how you handle the costs, using an array or list rather than "u2 cost" "u3 cost" etc.
otherwise, most of these are just words on a canvas implying features you want to add. Theres nothing particularly coding related about this
I see
I'm trying to think of a way to make smooth movement and overall I am lost and Don't want to spend my entire day trying to code this :p
smooth movement like one that feels good to play?
yeah
well there isn't really one way to do that
but there are a bunch of techniques you can search for
yeah ik
I just
wanna try and figure this out myself ngl
I just want some help :p
I'm getting somewhere, but I, well. yk?
you can check out some videos from gmtk like theo ne about celeste, which covers what you can actually implement to make it feel better (but not actual code itself)
๐ด Get bonus content by supporting Game Makerโs Toolkit - https://gamemakerstoolkit.com/support/ ๐ด
Celeste is one of the most satisfying platformers released in recent memory. And a big part of that is due to the tight and responsive controls of the gameโs main character: Madeline. In this video, letโs look at how designers Maddy Tho...
the techniques still apply to 3d, it's just an extra dimension
yeah
(also, just changing the position directly like this will make it phase through walls)
ah, so move the rigidbody tjem?
whilst actually using the rigidbody
use the rigidbody's linearVelocity
lmao idk
right you can use
xyz with rb
whoops
wdym? a vector?
you just set it
(also, you probably wanna be doing this in fixed update to make physics more consistent)
facking
alright
wait im so screwed lmao
do I have to use *=
or just *
*=
idk why I didnt test it before asking
just =
oh
it's just a property
should my input vector be vector3?
I think so for the z direction right?
input = move.action.ReadValue<Vector2>();
i mean you don't wanna move vertically with wasd do you
you just wanna move on x and z
well your input is a vector2
rb.linearVelocity = input.z * forwardDirection * speed * Time.fixedDeltaTime;
I changed it to vector 3
you want its x component (a and d) to move you on the x axis and its y component (w and s) to move you on the z axis
look at your mouse on your desk when you move it around
well, no, your input is still a vector2
whaaaa
you only have 2 dimensions you can move in
w & s and a & d
w & s is the y component and a & d is the x component
alright
it works
wth is wrong with unitys moderation
i cant even say some words
anyways, its rotating not actually moving
you should read the message from the mod bot next time ๐
i couldnt say "but"
or ":p"
and again, read the bot message next time
IM SORRRYRYY
my fault
this is what I currently have, its just rotating rn
I have now paused all constraints
so thats that
but now it just doesnt move :p
it probably does move, just very little
linear velocity shouldn't be multiplied by delta time, the engine does that automatically
oh
yoo it works
the x is the same thing correct?
but then I've just gotta make it all even
well you'd multiply it by the right direction
yeah
ideally you wouldn't do multiple multiplications and would instead create a vector3 from your input and transform the direction of that
also just fyi, but transform.TransformDirection(Vector3.forward) is equivalent to transform.forward
if you want to create fake velocity, you can modify position by increasing it by a certain amount * time.delta time
But if you just set velocity to a vector, it would move by that vector per second by default, unrelated to the framerate (so no delta time needed)
heres this btw, I dont move forward. But I guess its overriding it correct?
and yes, don't multiply your velocity by deltaTime. just use an appropriate speed value as velocity is already expressed in units per second
you'd need to add them together, right now you're just overriding whatever you did for the forward direction with the rightward direction
yeah you are saying "Velocity is a certain vector in the forward direction" then immediately saying "forget that, velocity is a certain vector in the right direction"
What do you mean by that
same line
straight up just add them together
potentially
but not necessarily
Just add them together in as many lines as you want
(input.y * forwardDirection + input.x * rightDirection) * speed
I'll make it cookies
since that seems better tbh
but it works
now time for camera
im guessing camera is weird
do i use the quaternion.lookTorward or whatever its called
i usually just do it with euler angles directly
or
Vector3 playerVelocity = (input.y * forwardDirection + input.x * rightDirection) * speed
rb.linearVelocity = playerVelocity
But this is not really necessary
a bit unnecessary
looks fancier and you can mention it easier later ig
WAIT
no
nvm
you can just put the variable in there, myfault
Hi all. This is probably a stupid question, but what should I do if my tileset is too complicated for a Rule Tile? For example, I have some tiles that can have tiles in 8 directions, but in some directions, it has to be a specific subset of tiles
Can't you mention it later by just getting rb.linearVelocity anyway?
yeah
if you want it to be more readable, i'd do
Vector3 forwardInput = input.y * forwardDirection;
Vector3 rightInput = input.x * rightDirection;
Vector3 input = forwardInput + rightInput;
rb.linearVelocity = input * speed;
you can
Also theoretically if you ever wanted to, say, add a slow factor, but keep track of how you would have moved unslowed (just for example) you would want to use this setup
whos needs readable anyways. But how do i start out a camera in code. like camera movement
well you wanna rotate the camera based on the mouse movement
https://docs.unity3d.com/ScriptReference/Camera.html
And your preexisting knowledge of gameObject Transforms
If it's 3d and you want mouse input, https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Pointers.html might be helpful (This is the input system mouse input docs)
I have this but yk. Im a slow dumbass ngl
well i'd personally handle rotating the camera in its own script
but if you don't want to you don't have to
I'll listen to you
I mean like
you have the best profile in this server hands down
and your really helpful
thanks haha
Seconded, mainly because dealing with rotations are annoying enough anyway to not want to have to sort through multiple unrelated sections
how would you use the eulerangles
Ive never used them before
well euler angles is the intuitive way of representing 3d rotation, where each x y and z angle rotates about the x y and z axes respectively
yeah
so like
how do I use it yk?
im thinking that
I get Vector 2 of look InputAction
well you want your camera to rotate around the x axis (which would be up and down) whenever you move your mouse vertically
then assign it through there whilst using angles
and around the y axis when you move it horizontally
Also, do you want your mouse/crosshair to stay in the center of your screen? (Like in most 3d games)
dw I already know how to do this
this is the one thing I remember how to do
๐ญ
You might want to consider using the .delta property as your source for the angle (if you haven't already)
so like wdym
should I grab the Quaternion of the cameraholder?
I think so
or do I use transform.rotation or smth
no, we're gonna be using euler angles
aaaaaah
(transform.rotation is the quaternion)
transform.eulerangles right?
well, because converting quaternions to euler angles can be a little inconsistent, you'd wanna make your own variable for the angle
Also make sure you know whether to use eulerAngles or localEulerAngles based on how the objects are set up
so variable = transform.eulerangles? smth like that
you'd wanna keep track of them yourself
and you initialize it to transform.eulerAngles only at the start
i hate rotations
everybody does but it's just something you have to put up with
just make a vector3 variable
by which you mean like,
at the start you initialize it to eulerangles
then each update, you update the variable as desired
then update the rotation of the object to match the variable
I make a vector3 variable to grab eulerangles correct?
yeah
yes, in outer scope
can this leave me alone
no because unity is stubborn and wants their own vectors
aaah
you want UnityEngine.Vector3 not System.Numerics.Vector3
yeah dw I know
do I add the Vector3 variable to the transform.eulerangles?
then the input and what not or smth
or is it more complicated
add the variable to the rotation?
Don't think so
you just set transform.eulerAngles to that variable
now, you'd wanna add your vertical mouse movement to its x component and your horizontal mouse movement to its y component
i know it's a bit confusing, but it's because x rotation is rotating around the x axis
here it's just rotations that are confusing haha
how?
did I do something wrong
i said, you want to add your mouse's horizontal movement (the x component) to your rotation around the y axis, and your horizontal to your rotation around the x axis
oh
also, you shouldn't be adding your angle to eulerAngles - you should just set it directly
since transform.eulerAngles converts from and to quaternions when accessed and set, it can be inconsistent and confusing to work with directly
you want to essentially:
-read the euler angles to a variable at the start
-update your variable with whatever logic/math you need to get the right rotation
-then set euler angles to the variable
yeah
It's like taking a copy to work on, since you don't want to mess up the original
well no, it's like working on your own copy and then occasionally updating the target
hey
git
if I look up, I kinda fly
yeah, because you need to set your input's y component to 0
its kinda funny tbh
right
yeah
like here
Vector3 forwardInput = input.y * forwardDirection;
Vector3 rightInput = input.x * rightDirection;
Vector3 input = forwardInput + rightInput;
// set it to 0 because you can look up
input.y = 0;
rb.linearVelocity = input.normalized * speed; // needs to be normalized, because you don't want to move slower when looking up
it might be better to base it on the player object's transform.forward direction and then rotate the player according to the mouse movement
oh
I was thinking that
eh, not necessary
but like
and might be more confusing
so like
instead of this
just set (forwardDirection.y = 0)
And then normalize forwardDirection (I assume)
not justforwardDirection
here
doesn't right direction not have a upwards component though?
since it's perpendicular to the forward direction
it should be only along x and z no?
well no?
or i might be getting confused myself
but i'd just set the sum's y to 0
and then normalize it
well you're clamping your movement, not the final angle
well, you clamp the x angle, not the y input
doesnt matter im a dumbass
double checking the angle.x is the y axis? because i am so confused with which is what now
no, you're clamping the input.y
Mathf.Clamp() returns the value you passed in, but it can't go below the min or above the max
you're passing in the input.y, which is what you're clamping
buyt you don't wanna limit the rotation speed, rather the target rotation
okay, do you know what returning a value from a function is?
I think
let's say i want you to write a function that takes a number, multiplies it by 2 and then returns it
is the 'return' thing or something else
how would you do that?
public int Double(int value) {
// what do you put here?
}
It's not really important but I want to make sure I'm not going crazy myself lol
These are the two angles of rotation of the camera (the black arrows) and the corresponding rotation (blue arrows) of the right vector (green), I don't see how it's possible to rotate the camera in a way that the right vector doesn't stay horizontal
because i'm trying to teach you, not give you the solution straight up
I dont entirely understand how to use functions
thats mainly what I would rather lol
I know the basis
oh yeah, but it still makes more sense conceptually to normalize the sum
knowing how to use functions is a major part of the basics
that's a linear algebra term
yk?
well a function is just a piece of code you can reuse
they can take arguments and return values
I know you use return to return values from memory
yeah
or you can use just return; to exit a function that doesn't return any value early
buuut,
the "int" and "value" in the thing you sent I dunno if you meant multiplay the value
I just remembered what the int part is lmao
the int is the return type and the value is one of the parameters
yeah
public int /* <- return type */ Double(int value /* <- parameter */) {
}
public int Double(int value) {
value *= 2;
return value;
}
Forgot if it was *= or just *
*=
or *
wait
* just gives you the value multiplied by 2, but you aren't doing anything with it
while *= sets it to that
doing value *= 2 is the same as doing value = value * 2
it's just a shorthand
I forgot if you do return and then value
alright
you did it in python
this
that I mean
return (in a function whose return type isn't void) returns the value after it
so return "Hello world"; makes the function output "Hello world"
Working on movement for my game and really want this to feel polished, the character does not move well, at all, I want the model to move with the camera smoothly, I am using a premade movement pack from the unity asset store, trying to get a VR feel from a pc game
okay, now how do you use a value that some function returns?
reference it from the function?
outside of the function
how do you use a function that returns something
I forgot to add that
int myInt = 4;
int doubledInt = // how do you use the Double() function we wrote earlier here?
well the first thing would probably be adding an animation
almost
you don't have a value declared anywhere, that value we had in the function was simply the name of the parameter
which is what you use in the actual function
but you need to double myInt
oh
ohhh
lmao
hold on
I forgot how to be smart lmao
int myInt = 4;
int doubledInt = Double(value = myInt);
something like that
well, it'd be value: myInt
but you can just do Double(myInt) - you don't need to explicitly name the arguments if you pass them in the same order
It has just an idle set right now
close enough lmao
alright
now, let's look at a more complex example - writing your own clamp function
public int Clamp(int value, int min, int max) {
// (...)
}
you should really make a thread if you plan to just tutor someone
lmao
What "doesnt feel polished" about it to you? What would "moving with the camera" look like to you? To me it seems that you model does move with your camera, as cookie pointed out it just doesnt play any animaitons that feel like the character is "moving" like arm swinging for example, head bobbing, etc (but thats less code related and more animation relation at that point)
I have a feeling its something involving minusing or adding
not necessarily, it's just branching
well, if your value is less than the min, you want it to return the min, and if it's greater than the max you want it to return the max
and otherwise the value itself
right
Okay I see what you mean, it looks like it rotates with wasd when I would pefer with it was facing where I was looking, is this annimation related?
I can use if statements
yeah
then just make it face where you're looking
shouldn't be that hard
Okay, that makes sense, when typing it sounds silly
Thanks
Everything in game dev sounds silly, but asking questions is how we learn
public int Clamp(int value, int min, int max) {
if (value > max)
{
value = max;
}
else if (value < min)
{
value = min;
}
return value;
}
Something like this
yeah (you got the greater than sign the wrong way round tho in the second statement)
but you still need to return the value
I was contemplating it ngl
I forgot about that
Forgetting one crucial part, how is the value coming back out
I forget things fast alright
Don't worry
okay, now how do you use our fancy not-exactly-new clamp function?
Probably should make a thread by the way, it feels like this discussion is going to go on for a while longer
yeah sure
why cant i move my character??
What is moveSpeed set to?
just do velocity
and make sure speed is set in the inspector
nevermind, but it is probably speed
Can you send a screenshot of your character object's inspector widow?
yeah
ohh
oh yea don't know how i didn't catch that lol
so i should just call it in fixedUpdate then?
Yeah
are you you using the playerInput?
But it might be a good idea to move line 17 (velocity update) into your movement function
and is it set to event, sendmessage or broadcastMessage
okay
I searched up the new unity movement input thing and just tried using that
not sure if that answered your question
usually i just go for the "C# events" for the new input system. and i just access the InputAction directly for movement input
if you are using the new input system either you have to use the PlayerInput or manually setup the C# events
(or reference the input action)
yup
but with playerInput you can reference a global and easy to edit InputMap/actionMap
you can just add the playerInput component to your object
i dont really know how input works or anything really
so i just went with this
ohh and then set playerinput to 1
and it should work
or am I tweaking?
playerinput is a component
no need to set playerInput to 1. its a component
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;
using Unity.VisualScripting;
using Unity.VisualScripting.Dependencies.NCalc;
using UnityEngine;
public class playerController : MonoBehaviour
{
public float playerSpeed = 5f;
public int playerJump = 10;
private Rigidbody2D rb;
private Vector2 moveVel;
private Transform grounded;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
grounded = GetComponentInChildren<Transform>();
}
// Update is called once per frame
void Update()
{
moveVel = Vector2.zero;
handleInput(KeyCode);
moveVel = moveVel.normalized * playerSpeed;
}
void FixedUpdate()
{
rb.MovePosition(rb.position + moveVel * Time.fixedDeltaTime);
}
void handleInput(KeyCode key)
{
switch (key)
{
case KeyCode.A:
moveVel = new Vector2(1 * playerSpeed, 0);
break;
case KeyCode.W:
moveVel = new Vector2(-1 * playerSpeed, 0);
break;
}
}
}
how do I feed my key inputs into this? I'm not even sure a switch case is necessary here either. (Also before anyone says to use getaxis I don't want to because I'd rather have more finite control over which keys are moves
okay thanks
Use Input.GetKeyDown
you should really be using the new input system
new input system is quite nice. has a learning curve but it has flexibility
what new input system?
btw is there an inputaction reference for sprinting or smth? or should I just use the Keycode
wdym?
can I assume this enables controller + keyboard support without manually writing out stuff for both?
you just make a sprinting action and reference that
oh
you'd need to set the bindings for controller
you can edit the default input actions
iirc in unity 6 and up it by default gives you a input action map
if I did want to do it this way though for the sake of learning and understanding how could I pass a value into the function(also ignore the keycodes I fixed them)?
you really shouldn't be learning an obsolete way of handling input
Especially if it's for the sake of learning, you should do your best to learn the new system, it's a bad idea to learn something that's actively being replaced
well my main thoughts were: the game is going to be a roguelike and I want to have other bindings for certain skills and this seemed like a straightforward approach
