#💻┃code-beginner
1 messages · Page 232 of 1
But you don't actually know what piece is so log the values of it
Stop assuming
check
i know vim is good and all but i REAAALLY need that code parsing to tell me what errors i have
hence why i stopped using code
It has that. But I was joking.
Well, VS Code has that too haha
Kk, im away from pc now, ill check in the morning, thx
vim does????????????
oh wow pretty based text editor tbh
see though vs code's syntax error parsing is broken when you connect it to unity
some people here actually told me i had to make the switch or else they would deny me help
since they didnt want to help me every 3 seconds about something i couldve easily fixed with the error parsing fixed
Make sure this has been followed 🤷♂️
yes, you are required to have a configured IDE in order to receive help here
👆 and that goes for rider, VS, and VSCode.
Any of them can be unconfigured
But tbh, vscode usually breaks the most.
yeah i was advised to not use vscode because it has broken configuration
Welp, you were given the options.
VS, VSCode, and Rider are the main choices. Check out which work for you.
Good luck!
i guess i'll see if rider works
I'm having an issue with some variables and the way that theyre showing up. I'm making a game where a ball (tag: CashTrigger) bounces off a platform (also tag: CashTrigger) to give you cash to buy upgrades. I have setup the debug log for detecting collisions and it sais they work just fine. here is the code: https://hastebin.com/share/idutegeboc.csharp I hope someone can help me out
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
What are you expecting to happen that isn't happening
so in the debug log it sais that the CashAmount isn't updating. I think thats cousing some of my other issues so I want to get that fixed first
If you're getting the "Collision Detected!" log, and CashAmount isn't changing, then it'd be reasonable to assume that CashPerBounce is zero. Try logging the values of CashAmount and CashPerBounce instead of just words
but I have ''CashPerBounce'' set to 10 '' public int CashPerBounce = 10;''
Are you sure
Log it
yea it shows in the log as well
What did you log, and what does the log say?
The code and the result
this is the code:
private void OnCollisionEnter2D(Collision2D collision)
{
// Check if both colliding objects have the tag "CashTrigger"
if (gameObject.CompareTag("CashTrigger") && collision.gameObject.CompareTag("CashTrigger"))
{
Debug.Log("CashPerBounce = " + CashPerBounce);
// Increase CashAmount by CashPerBounce whenever a collision occurs
CashAmount += CashPerBounce;
Debug.Log("Collision detected!");
// Update the text component with the new CashAmount
UpdateText();
// Convert CashAmount to a string and update the text component
text.text = CashAmount.ToString();
}
}
CashPerBounce = 10
thats the result
Change the collision detected log to this:
Debug.Log($"Collision between {gameObject.name} and {collision.gameObject.name}, CashAmount is {CashAmount}, per bounce is {CashPerBounce}");
That'll give you a lot more information
ill test it
Im looking for a good free C# course, does anyone have any suggestions ?
yea so now im getting this: Collision between Platform and Circle(Clone), CashAmount is 20, per bounce is 10
And if you bounce on that same object again, does CashAmount go up
yes CashAmount goes up
So it's working
yea just this code isnt: Debug.Log("Total Cash Amount: " + CashAmount);
that just stays on 0
but thats fine i guess
Are you sure that you're looking at the same Cash_Managers in both cases
and that you're not setting it to 0 somewhere else
you mean the same script?
Yes, each instance of Cash_Manager has their own CashAmount
ah yes i fixed it now I had an object in my hierarchy that had the script on it
thank u very much
Hi I'm using face.material.SetTextureOffset
This works great for an instance, but how would I get the second material of the face instead of the first one? The face is a renderer object
https://docs.unity3d.com/ScriptReference/Renderer.html
check the docs to see if there are any methods or properties that could give you the materials
So, about that second bit, what do you mean a physically compatible way?
Nvm sorry i figgured it out
making text printing script was following along with a tut cause im good at coding ui yet.
the last half of the code was cut off and im pretty much trying to fill in the blanks
start by configuring your !IDE 👇
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
Do you have to set up and configure Unity and Vsc everytime ? Because I did configure it but it gets undone again everytime somehow
Only once per project at most
But VS Code has issues sometimes
what gets "undone"?
I'm using face.material.SetTextureOffset
This works great for an instance, how would I make the face."material" part a reference to something like public Material myMaterial ?
what is face?
Face is a renderer object
Forgot to mention that
The material property of a Renderer creates an instance of the material that's unique to the renderer
sharedMaterial doesn't do this
Note that, if the material is an asset, you'll be modifying the asset
which creates annoying version control churn and means you're messing with project files every time you run the game
What you can do is assign myMaterial to all of the renderers that you want that material to be used by
So how would I target which material to make an instance of?
here's how I'd do it:
[SerializeField] List<Renderer> renderers;
[SerializeField] Material templateMaterial;
[SerializeField] Material instanceMaterial;
void Awake() {
instanceMaterial = Instantiate(templateMaterial);
foreach (var renderer in renderers)
renderer.material = instanceMaterial;
}
void OnDestroy() {
Destroy(instanceMaterial);
}
then mess with instanceMaterial
One thing I'm now less sure about is whether assigning to material will wind up creating new instances of the material
If changing instanceMaterial doesn't do anything to the renderers, then you probably just need to assign to sharedMaterial instead of material
This function automatically instantiates the materials and makes them unique to this renderer. It is your responsibility to destroy the materials when the game object is being destroyed.
oops
i've been very bad about that
i think just setting the material is fine. That happens entirely in native code
https://github.com/Unity-Technologies/UnityCsReference/blob/2a49d60b87de8036523dcedcbae97398f64f5fb8/Runtime/Export/Graphics/GraphicsRenderers.bindings.cs#L171
https://github.com/Unity-Technologies/UnityCsReference/blob/2a49d60b87de8036523dcedcbae97398f64f5fb8/Runtime/Export/Graphics/GraphicsRenderers.bindings.cs#L52
hello my noble tutors
huh
if i wanted to paste multiple scripts on one link is there a better way than copy pasting every script?
i finished my heirarchical movement state machine and wanted some feedback on if it could be optimized any better
I think it was a mistake with the materials
I think it was a mistake with the materials
how would you share multiple scripts without copy/pasting each of them? 🤔
Before that, did you confirm that there is a need for optimization?
like under eachother, instead of like tabs
you can use multiple links or a site that allows multiple tabs
i can confirm that there is absolutely no need for optimization XD
I literally just have movement set up and a full blown state machine error free haha
You can share multiple classes in the same link.
ill try, its allot tho
all as one single paste document though is usually a bad idea because it makes it an absolute pain to read
there are plenty of sites that allow you to paste multiple documents in the same link though, i personally use paste.mod.gg
ooo i like this one
A tool for sharing your source code with the world!
A tool for sharing your source code with the world!
thats a nice site, ill use that now, i like the tab feature
Somehow it fails to work properly on mobile
@vale karma You just want optimization tips?
To be fair, that state machine kinda violates the state machine pattern.
// Player Movement Script
private ReadInput input;
private CameraPOV playerCamera;
public CapsuleCollider capsule;
public LayerMask groundedLayers;
public Collider[] groundedResults = new Collider[10];
public Rigidbody rb;
[SerializeField] Transform orientation;
public Transform groundCheckSphere;
protected Vector3 direction;
protected Quaternion playerRotation;
// Input System Script
public Vector2 MoveAction { get; private set; }
public bool IsMovePressed { get; private set; }
public bool JumpAction { get; private set; }
public bool CrouchAction { get; private set; }
public bool SprintAction { get; private set; }
public bool EnableAction { get; private set; }
All of this stuff, the state machine itself shouldn't be dealing with or have access to
Im not sure, i followed iheartgamedev and his stuff, i didnt like how he put all if it in a statemachine script too
I had it factored into their own scripts, but to make it more simple to follow i put it all in one
Bad tutorial 🤷♂️
i agree, but its the only "well made" tutorial about it
he has 4 tutorials each going over his bandaids in the last one
I mean, if it works for you and you don't want to rewrite it, what's the point of asking for feedback?
Because looking at it now, it's gonna be a lot of refactoring if you want to make it right.
does the addressable got abandoned?
trying to chat there but there seems to be no reply
i still have the original scripts in tact. I will look into refactoring it back to what it was. and no this was helpful. I was seeing it so much i didnt notice the elephant there anymore
I don't think so..? Chat where did you try chatting?
the addressables channel of course
Ah, well, how is it related to "being abandoned"?
It just means that not many people sit in that channel. Anything else is a guess and speculation.
im trying out photon based on a tutorial and when i connect and load into a room that puts me onto a scene, all my shadows are super dark, is there a reason for this?
Probably don't have lighting settings generated for the scene. Also not a coding question.
i was suspecting it to be related to a load command
Then share the code
i thought since this is the official unity server they will at least take a look at their channels or something
if you take a look at the channel there is only people asking questions but without getting much of a reply about how to fix their problem
maybe i asked in the wrong place?
This is the official community server. Unity staff responds very rarely and they don't have an obligation to do so. If you want a response from unity staff, you might have better chances on the forums.
i did just run into an issue trying to make the player collider hieght get divided by 2 when he crouches, I got it working but if you jump and crouch it now moves the collider down permanently
I guess there's just not many people using the addressables actively and being active on the discord. I for one have barely used them.
hmm okay
thanks anyway
The last few questions in the addressables channel are very specific and unless someone was dealing with a similar issue recently, they probably wouldn't get a reply. Your best bet is to google and research the topic yourself.
Probably didn't reset the height properly or in correct place, send code block where you set height of your collider?
well i tried addressable and just want to know a simple thing on how to load from remote path (cloud server) but there seems to be no clear guide on how to do it
the documentation also very vague and searching on google bring about the same result
Guys, how do I always stop using the ammo and not the clip when the player tries to reload? The ammunition is only spent reloading the clip and the clip is only spent shooting, here is an example of the error``` private void Update()
{
if (gameObject)
{
if (currentAmmo > 0 && currentClipAmmo <= 0)
{
StartCoroutine(Reload());
}
if (currentAmmo > 0 && gunAnimator.GetBool("OutOfAmmo"))
{
StartCoroutine(UnFreezeAnim());
}
if (currentClipAmmo > 0 && gunAnimator.GetBool("OutOfAmmo"))
{
gunAnimator.SetBool("OutOfAmmo", false);
}
if (Input.GetMouseButtonDown(0) && currentClipAmmo > 0 && !isCooldown && !gunAnimator.GetBool("OutOfAmmo"))
{
StartCoroutine(Shoot());
StartCoroutine(BulletCartridgeEffect());
}
if (currentClipAmmo <= 0 && !gunAnimator.GetBool("OutOfAmmo"))
{
// gunAnimator.SetBool("IsReloading", true);
gunAnimator.SetBool("OutOfAmmo", true);
}
if (Input.GetKeyDown(KeyCode.R))
{
StartCoroutine(Reload());
}
}
}
public IEnumerator Reload()
{
//gunAnimator.SetTrigger("Reloading");
//isCooldown = true;
yield return new WaitForSeconds(0.8f);
int reloadAmount = maxClipAmmo - currentClipAmmo;
reloadAmount = (currentAmmo - reloadAmount) >= 0 ? reloadAmount : currentAmmo;
currentClipAmmo += reloadAmount;
currentAmmo -= reloadAmount;
ammoText.text = currentAmmo.ToString();
ammoClipText.text = currentClipAmmo.ToString();
/*isCooldown = true;
if (currentClipAmmo == maxClipAmmo)
{
isCooldown = false;
}*/
//isCooldown = false;
}```
the ammo is the small number and the big one the clip
I see there's a page called "Change resource urls" in the docs, which seems to be related to your question.
yes that one is what i called a vague explanation
im having trouble getting the player to not be able to jump until you let go of the jump key and press it again. atm its just jumping continuously once it is grounded. I tried using WasPressedThisFrame but it shows red underline under it
JumpAction is currently read as a button
Please share code @vale karma
i keep deleting it 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.
JumpAction.WasPressedThisFrame doesnt work basically. Atm i have public void OnJump(InputAction.CallbackContext context) { JumpAction = context.ReadValueAsButton();
any way that i try to add waspressedthisframe gives me an error. I forgot how ive called it before... idk what im doing wrong here
'type' does not contain a definition for 'name' and no accessible extension method 'name' accepting a first argument of type 'type' could be found (are you missing a using directive or an assembly reference?).
What is Ctx?
You don't have a parameter variable named that in the method signature . . .
long story short its apart of the tutorial to refer to the other scripts ig
That's doesn't make sense . . .
i half heartedly know what this stuff does haha, i know how to use it but not exactly what each part does
The code links don't work for me . . .
We kinda need to see the variable declaration to understand what type Ctx is . . .
We need the Basestate and the substate (jump) classss
Can I... just not use Lists in a Editor tool?
You can. Make sure you have the correct usings.
Care to share the error? That might help . . .
What does the error say? It should explain the problem . . .
It is in spanish... so if anyone is wondering is something like "non-generic List type cannot be used with arguments of type "
Share your usings
As dlich stated, it looks like you are missing a using statement . . .
You're missing the generic using . . .
Is that all?
Yep, I am missing one?
Though, where does the List come from then?
I thought they had the visual scripting namespace, since they had List too
You should be able to click the light bulb on that line for quick fixes . . .
I though List where just from System.Collections
Not the generic version . . .
Ok, it was just missing this for some reason...
I know, that's what I said. The generic using statement . . .
I really don't undertand this stuff, doesn't System.Collections already include System.Collection.Generic?
ok i did
No, that's why they are two separate. If that were the case, you wouldn't have the error . . .
If you put a file named List in a System/Collections/Generic path, would you be able to find it in System/Collections folder?
Why would you create a different folder for that though?
They contain different stuff
You wouldn't. Whoever designed dotnet did. As for the reasons, it's because List is a generic collection. There are non generic collections in the Collections namespace.
To put it simple: to keep things ordered and organized.
Well okay, thxs
and this is what happends with not working one
here i put the codes
without debug.log
{
TakePiece(piece);
Queen.SetActive(true);
Bishop.SetActive(true);
Knight.SetActive(true);
Rook.SetActive(true);
Debug.Log(piece.occupiedSquare);
Debug.Log(piece.team);
if (QueenPromote)
{
chessController.CreatePieceAndInitialize(piece.occupiedSquare, piece.team, typeof(Queen));
QueenPromote = false;
Bishop.SetActive(false);
Queen.SetActive(false);
Rook.SetActive(false);
Knight.SetActive(false);
}
else if (RookPromote)
{
chessController.CreatePieceAndInitialize(piece.occupiedSquare, piece.team, typeof(Rook));
RookPromote = false;
Bishop.SetActive(false);
Queen.SetActive(false);
Rook.SetActive(false);
Knight.SetActive(false);
}
else if (BishopPromote)
{
chessController.CreatePieceAndInitialize(piece.occupiedSquare, piece.team, typeof(Bishop));
BishopPromote = false;
Bishop.SetActive(false);
Queen.SetActive(false);
Rook.SetActive(false);
Knight.SetActive(false);
}
else if (KnightPromote)
{
chessController.CreatePieceAndInitialize(piece.occupiedSquare, piece.team, typeof(Knight));
KnightPromote = false;
Bishop.SetActive(false);
Queen.SetActive(false);
Rook.SetActive(false);
Knight.SetActive(false);
}
Debug.Log(piece.occupiedSquare);
Debug.Log(piece.team);
}``` i have this function currently
Queen, bishop, knight and rook at start are buttons
this code doesnt work, it doesnt read the position
yet this one works public void PromotePiece(Piece piece) { TakePiece(piece); chessController.CreatePieceAndInitialize(piece.occupiedSquare, piece.team, typeof(Queen)); }
Well shit, why is the List not appearing in the inspector now? xd
this one only works for queen, any idea why?
okay i got to where i can use WasPressedThisFrame, but i think im wrong about what its used for. It makes my character jump indefinitely after pressing it once, not just when i press the key down
Hard to tell without seeing it in more depth, maybe just make the pawn have a gameObject of every piece type as a dissabled children and just enable the selected one?
i did the checking one more time
I don't think you can assign default values to Editor class like that.
it seems it loses the values in the middle of the code
I did assign the Particle though, I need to assign a few prefabs for the things I want to do
Also if I add just a material component it does let me assign it
I guess that doesn't work for lists.🤷♂️
Does it work with an array?
The thing I do need specifically a List for what I am trying to do, the stuff needs to be in order
It doesn't seem to work with arrays anyways though
Array is ordered though...
I see. Well, default values are pretty limited, so I guess it makes sense.
I guess I will have to create several mat parameters and pass make them into a List later
Which, is kinda weird but ok
You could get them from a scriptable object or something.
Or load with resources or asset database.
I think I could. But all this is meant to do is to let me push a button to call all this and setup all the components of the objects automatically to save them as a prefab without the need of having to it manually for each manually and not having to assing it on start. For all I know scripteable objetcs are more meant to be for runtime stuff?
Read about them, but never used one yet
Share code please
Well, what prevents you from doing it with my suggestions?
SOs are totally not just for runtime. A lot of unity engine uses SOs for editor config and stuff. Like the render pipelines.
They're just a way to have an instance of an object as an asset.
So I just... make a SO to store a reference to a List of mats and pass that to the editor tool?
ummmm can someone explain to me why its not printing in order...
it justs goes out of order starting index 2...
and fixes itself after index 5
Yes.
You can define all the references needed in that SO. Not just the list.
I already did this crime against all the programmer community though xd
Where are these pieces of code in relation to each other?
I will use a SO properly, if I ever have to revisit the editor tool script for this project, which I probably will. For now I am gonna stick to this patch thx
It's mainly a crime against yourself. The community doesn't care about your project
the list is just at the top
the print code is just at start
and the 3rd picture is the console
but for some reason, its not printing in order
Oh, that's kinda mean and true at equal parts
Can you share the whole script properly? !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.
wait nvm, it just randomly fixed itself? I just kept pressing play
quick question, is there a way to disable/enable the sprite renderer of an objects child without directly referenceing the child object? (Just straight up disabling the whole gameobject is also fine, because it only has a spriterenderer component)
in code? or in the editor
code
do you already have a reference to it?
SetaActive of course.
I have a reference to the parent
If i set active for the parent with the child also be affected?
you'll have to iterate the children, find the sprite renderer, then setActive(false) it
Iterate?
yes, if you set the parent inactive, all of its children are inactive
Oh okay, thanks
iterate = "loop over"
Yes, GameObject's active state affects all it's children.
foreach (Person p in discord.AllPeople) p.Ping(); // this is what @channel would do
that's called iterating
What does it do?
oh wait nevermind I think I get it
It's basically saying "for everything in this set, do this once" right?
I am trying unity 3d for the first time
but dont know how to put a character (moving camera for now) and platform
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I am noticing that even though when using the editor tool to assign the components they do assign correctly, once I enter play mode they lose the reference for some reason, even though I am pretty sure nothing is messing with those parameters at all. It does work eventually, but most of the time is just doesn't
Any idea why this could be?
have you written a custom editor
If so, see Persisting Changes pinned to #↕️┃editor-extensions
So... it is not meant to work unless I specifically tell it too?
Cause it has indeed persisted like 1/10 times for some reason
Without me specifying anything
Well, that was VERY usefull, thxs
Right when you enter your loop, try to print out moves[i].base.name to the terminal.
it's just a texture
https://assetstore.unity.com/packages/2d/textures-materials/gridbox-prototype-materials-129127
Grab these
some of the unity templates come with some gridbox textures too
woo 
thank you mao
how do I tile/repeat the image, the options doesnt have the tile, I am confused
Is it a different unity version?
its in the material
this is the material
u have debug mode turned on
turn that off
or wait.. why is ur so different?
create a new material and use the textures from the pack
im so confused 
can u try creating a new material yourself..
okok, I will try
right click the project window, create new material
ah wait, it is in debug mode 
and then you can click next to Base.. and that will let u pick one of those grids from that pack as the texture
i knew it!
lol
I was so confused xD
me too b/c when u click the three dots on the material inspector u cant turn off debug from there
u have to do it on some other component first
😅
thank you spawn 
I was checking gravity
ohh cool cool 👍 carry on
but yea, debug mode exposes alot of new info.. but it also hides abunch of stuff
why does my screen get seams/ screen tearing when looking at tiles? (might not be just tiles)
can it be fixed?
adjust your near clipping on the scene camera
what is the comfortable clipping distance?

it is 0.3 atm
I tried 1, I think it looks better
I still see some tears, but is it only inside the editor?
Take a screenshot
sooo I'm a beginner 
screenshot cant get the seams
your game is good bro gj
but it looks like this from what I see (edited in paint)
Does that happen with a static image too(when the camera is not moving)?
I will try, but I only notice the seaming when moving
This will happen when you don't have vsync enabled. Or if the right framerate isn't achieved while you have a monitor capable of FreeSync or Gsync and an appropriate GPU for either technology.
ah, where can I find vsync?
I would have to google the documentation for you
and I think you can do that yourself
If it's in the scene view, then the scene view camera settings.
Go over the unity ui in the manual
ah I found it 
thank you vert, dlich
sorry for all the questions, I dont know most of the terms in unity, I hope it isnt too much trouble
Make sure to go through the !manual and unity !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
just consider this scope, without other scripts, will both behaves the same?
public int m_columnNum { get; private set; }
private void Awake()
{
m_columnNum = 8;
}```
```cs
public int m_columnNum
{
get { return 8; }
private set { m_columnNum = value; }
}
i simply dont want to make another awake functions
The bottom one contains an infinite loop
and also makes no sense
you can do public int ColumnNum { get; private set; } = 8; 🤔
why have a set at all when you always return 8
i just wanna have the property do the first one without opening an awake function
it seems that the
public int ColumnNum { get; private set; } = 8;``` its a good way to go👍
private Texture2D Render3DObjectToTexture(GameObject objPrefab)
{
RenderTexture renderTexture = new(256, 256, 24);
int LayerIndex = LayerMask.NameToLayer("UiItems");
GameObject cameraObject = new("RenderCamera");
Camera renderCamera = cameraObject.AddComponent<Camera>();
renderCamera.targetTexture = renderTexture;
renderCamera.enabled = false;
renderCamera.clearFlags = CameraClearFlags.SolidColor;
renderCamera.backgroundColor = new Color(0, 0, 0, 0);
renderCamera.cullingMask = 1 << LayerIndex;
GameObject obj = Instantiate(objPrefab);
obj.transform.position = renderCamera.transform.position + renderCamera.transform.forward * 4f;
obj.transform.LookAt(renderCamera.transform);
obj.layer = LayerIndex;
renderCamera.Render();
Texture2D texture = new(renderTexture.width, renderTexture.height, TextureFormat.RGB24, false);
RenderTexture.active = renderTexture;
texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
texture.Apply();
RenderTexture.active = null;
Destroy(cameraObject);
Destroy(obj);
return texture;
}
why is the background of the texture black even though i set the camera's clearflag to solid color?
did u chose black as the solid color its using?
dosnt it not change anything tho anyway? isnt it used as the color of the fringes where aliasing happens
renderCamera.backgroundColor = new Color(0, 0, 0, 0);
Why are you expecting anything but black?
i thought renderCamera.backgroundColor does that
But what color would the actual background be
ye i though it would only change the color of the fringes to black, not the whole background
But what do you think the background color would be? What sets the background if not that?
donsnt SolidColor clear the bg tho?
It clears it with the background color, as it says
ok, so how do i fix it bc if i remove the bgColor line, it changes the bg to blue
What do you want the background color to be
clear
why not make it alpha and clip it
There is no such thing as "Clear"
You cannot make transparency so your game is see-through
(Without hooking into complex OS-specific functionality)
say i want the ui behind the rawimage to be rendered instead of the solidColor
cant you render the texture, make black as alpha, then render it onto a quad with a transparent shader
or alpha clip the black
Ah, I see what you mean.
TextureFormat.RGB24 has no alpha channel
oh ye, i set it to RGBA32 and it works now
So I'm attempting to save an objects data set to json, But for some reason I can't get all the game objects with the tags added to the array?
Each call to FindGameObjectsWith tags is being reassigned to Frwogs, overriding the array with a new reference
also .ConvertTo<String>(); should just be .ToString()
Thats what I assumed, how would I go around this?
whoops my bad
How do I add them to the array rather than overwriting?
Add them to a list, and use that in your loop; or make a method that you call multiple times with each array, making sure to correctly increase the identifier between each one
Or, I wonder why you're using tags at all and not just getting all the FwogControllers?
so I create a loop that adds them seperately to the array?
I tried to do that, but I couldn't work it out
var controllers = FindObjectsOfType<FwogController>();
Says I can't convert it to game object
It's not a GameObject, it's an array of FwogController
ohhhh Im being silly ofc
I'd still need to create a loop to add them to the array though?
No
Awesome
You seem to be using 2023, which has FindObjectsByType instead.
Also Am I doing the saving of each Frwog's data wrong. Currently Im creating a new json file for each one
as surely if I tried to do it to the same file, it would overwrite each other?
Then im loading them like:
Not if you serialized an array or list of the data (which JsonUtility would need inside another object because it's ick)
What do you mean?
Heres the data... Do I want to reference this GameData from the FrwogController's and store their data here instead?
I mean you need to serialize a wrapper containing a list of your data if you want to save it all in one file using JsonUtility
[Serializable]
public class GameDataGroup
{
public List<GameData> Data = new();
}
oo
So How do I use this? Do I create a new script which just collects all the gamedata into a list?
then I can then save that using the json Utility
Like do I add a loop which adds them to the list?
You just create a new one of those, Add each of your things to the list, and then serialize that object
but how do I add the data to the list sorry?
!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.
You can easily google how to add to a list. If you don't understand something more specific about it then feel free to clarify'
Alrighty, Thanks for the help, I'll go search it up :D
I tried making character movement in 3d, but I do not like transform as movement because there is no momentum, how do I make one with momentum? 
I don't see where you use it, you declare a new one in UpdateMovement
Use physics (rigidbody)
I will try 
my jump doesnt work too
is there something wrong with the script
ifs
Hello there, is there any way to automatically assign via scripts an scriptableobject event to the GameObject with that script?
Todays video is all about making a fun to use and highly tweakable 3D movement system in unity.
First Person Movement Unity 2022
Code:
Remember to subscribe and hit that bell to always stay notified.
Go check out my other videos:
no lying I copy pasted from this guys tutorial
everythings the same yet my jump doesnt work
and layers are set correct
If you're following a tutorial, and it works in theirs but not yours.. you did something wrong or missed something
Did you forget to set something in the player inspector?
everythings the same
@polar acorn get in here
no
Ground is set its layer is set
groundcheck set
let me clarify that
it works
except for jumping
Would this be a good way of doing so?
Then I can then save the Data list to json
No update no mono
But how would I then loop through this data retreiving each data from the list? Would that be going through the index of the list?
So If I can't update, How do I run this?
No, you shouldn't be collecting these things in Update, you shouldn't be serializing a MonoBehaviour, and nor should the list of data be in the same object as the component array or serialization logic
Right, so I would add them in the save script
Where you had it before was totally fine, you just needed to do what I said, create a new group object—without changing what I wrote to something else, add to its list, and serialize that object
Then reference the gamedatagroup for when im saving it
maybe you need grounded
Like so?
I can't see what datalist is, and also note that you really don't need to declare these variables outside of the function if you're not using them elsewhere
i dont know whats causing this issue
i think i messed up a file or class name somewhere
Show the class you're trying to reference
It would be best if you linked to both sets of !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.
When looping to retreive the data, how would I do that? Would I just go through the index of the list?
here we are
second script starts from line 791
im currently using astar pathfinding project
Are you seeing this issue in the Unity console?
Yes, just a loop. You need to deserialize the same type you're serializing though, which is now GameDataGroup not GameData
yep
had to lanch my project in safe mode bc of it
Yep Just realised that... How would I go abouts doing this?
Would I need to loop through it?
and do the index?
its in the Pathfinding namespace
You still have Gamedata written there
Like so?
They're both in the code posted, both in the same namespace
Or am I being silly
You need to deserialize the same type you're serializing though, which is now GameDataGroup not GameData
If both of these scripts are within the Astar project and unmodified by you then it seems like something else has gone awry
i copied one of these scripts directly yesterday
What do you mean?
i deleted it after it caused significant issues, but
broke this getcomponent function
like i copied the aidestinationsetter script
What, and moved it somewhere else?
is this a clue?
i think so, batman
renamed it, renamed the class that sorta thing for the copied version
The script was originally in a location under an assembly definition, if you moved it out from that assembly then the other scripts won't be referencing it
wouldn't the namespace Pathfinding line be enough? im asking for myself.. not sure..
i thought no matter where the file was located if u specifically wrapped the class in the namespace everything would still be okay
No
only if it had references to the dll where the code was moved through
Thanks for all the help @north kiln. I understand how to use Json Utility much better!
ohh interesting.. okay. TIL
christ, looks like im gonna have to remake my enemy prefab
oof
its fine since i made a base before applying a* pathing to it
but thats gonna be annoying
Would anyone be able to help me with my c# script. Its a script that is supposed to rotate a gameobject to face another gameobject. Here is my function at the moment (Sorry if its a bit messy im very new to game dev)
The current error seems to be that it doesnt properly calculate the foodangle, it staying set and then the ant is rotated at the angle of -food angle. Iv tried a couple different ways of doing this and none seem to be working.
private void MoveTowardsFood()
{
if (currentFood != null)
{
float step = antTurnSpeed * Time.deltaTime * 10;
float foodAngle = Vector2.Angle(this.transform.position, currentFood.transform.position);
Debug.Log("Food angle = " + foodAngle);
float comparedAngle = this.transform.rotation.z - foodAngle;
if (comparedAngle> 10f)
{
float targetAngle = Mathf.LerpAngle(this.transform.rotation.z, foodAngle, step);
Debug.Log("Target angle = " + (targetAngle - this.transform.rotation.z));
this.transform.rotation = Quaternion.Euler(0, 0, (this.transform.rotation.z - targetAngle));
}
else if (comparedAngle < 10f)
{
Debug.Log("Snapping on");
this.transform.rotation = Quaternion.Euler(0, 0, (this.transform.rotation.z - foodAngle*2));
}
//This is just a function that moves it in the direction its facing.
Move();
}
}
ok i really need to start backing things up
this a* algorithm is messing up my entire project
im gonna push this onto git
just causing a lot of bugs
https://docs.unity3d.com/ScriptReference/Quaternion.RotateTowards.html
Can try using one of these
Ah, you need to use LookRotation in conjuction
Alright, ill try use LookAt and RotateTowards to see if it fixes it
Sorry I mean this https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html instead of LookAt
float degreesPerSec = 10; //some value
float step = degreesPerSec * Time.deltaTime;
Vector3 direction = target.position - transform.position;
Quaternion targetRotation = Quaternion.LookRotation(direction, Vector3.up);
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, step);```
alright let me try this
Alright, it now rotates towards the food but then continues to keep rotating past the item and then starts bugging when it begins to bug when the food leaves the collider snaping in then rotating back out and repeats
I did have to change it to only rotate on the Z axis since its a 2d game but i think i did that fine
Here is the code:
private void MoveTowardsFood()
{
if (currentFood != null)
{
float step = antTurnSpeed * Time.deltaTime;
Vector3 direction = currentFood.transform.position - transform.position;
Quaternion targetRotation = Quaternion.LookRotation(direction);
transform.rotation = Quaternion.Euler(0, 0, Quaternion.RotateTowards(transform.rotation, targetRotation, step).eulerAngles.z);
Move();
}
}
the rotation shouldn't overshoot, but if you don't need to rotate once looking at the target then flag it to stop calling your method
how would i check that? Just do another angle check and if its 0 not call the method?
yeah you could just compare angles
probably worth it to figure out why it's overshooting though for when you continuously want to look at something
it seems to be going to an angle which isnt where the food is which i dont really understand why. I'v attached a picture where it kinda just stays on that degrees while its supposed to be tracking the red dot? (made it so instead of getting caught on the collision boundary it would go past it so i could check where it was trying to rotate too or if it was spinning or what)
Do you have any ideas?
Ah, you're using 2D so your up axis would be z+
What do i change to fix this? Just change LookRotation to include an up?
vector3.Up is +y
Yeah, i would use vector3.Forward?
not sure if there's a 2D method for this, but try using Vector3(0, 0, 1)
cause forward is z+ and backwards z- right
Yeah, or vector3.forward
alright
i fixed it tysm!!
i used vector3.backwards
and it worked
idk why its backwards instead of forwards
Some day ago, i saw in one of Unity's documentation that they were using Time.deltaTime in FixedUpdate. We know using Time.fixedDeltaTime is giving almost exactly same value as Fixed TimeStep unless there is a heavy calculation. So my question is, which **deltaTime **to use in FixedUpdate?
It gives exactly the same value in fixed update.
they're basically equal
I was told it will use the time method relative to what loop it's in
Which is an abomination
No, it makes total sense
:d that was what i was doing until i saw that in documentation
if u like the way forwards looks u can always use -transform.forward 😉 aka backwards
Did i understood correct? You mean the Time.deltaTime equals Time.fixedDeltaTime in the FixedUpdate?
yup
Ah
Yeah, they are the same when queried in FixedUpdate
I think there's a misunderstanding @teal viper
You were talking about the fixedDeltaTime being the same value as* the fixed timestep?
Yep.
since fixed timestep is fixed, it'll always be the same.. (its the time that has transpired since the last fixed update)
The abomination I'm talking about is Time.deltaTime returning different values depending on whether it's called during the update or the physics step
Yeah
Why is this an abomination? It's how it works?
How is it an abomination?
Donno. It makes sense to me.
how is it an abomination?
Its not like it detects where its being called and returns a different value, its just a side effect of the physics simulation being called at a constant interval
^ basically just technicallities
Okay, fair.
Because the logic is not visible, and because there is an explicit Time.fixedDeltaTime property, it is prone to misleading the users
There is no use in having the Time.deltaTime property handle that logic because Time.fixedDeltaTime exists. My understanding is that they've added this internal handling to simplify the engine for beginners
That’s true lol
probably the calculation of dt is current time of this call- that of previous call so it returns fixeddt when you call it in fixed update
The interval in seconds from the last frame to the current one
I'm feeling a bit lazy so I want to know an easier way to write this expression
if (int a == int b || int a == int c)
looking for something easy like
if (int a == int b : int c : int d)
how i can download my game from cloud?
no, if you dont rewrite the compiler
you could use correct c# syntax, that would simplify it
Not a code question, and through Unity Hub.
btw if you need to check it against lots of int, use hashset
What's a hashset
Meaning?
Meaning wtf is if (int a == int b : int c : int d)
that isnt going to compile
neither would his previous line and that is what I meant
he's asking if theres something similar where he doesnt have to do each comparison individually
if (a is 5 or 3 or 1)
{
}```
It works like this but i dont think you should use it like that 😄
but nah.. not that i know of.. maybe could write ur own method to do something as such
Do you have a link or can you say what i must do now?
This, but I don't think this type of pattern matching is supported by unity
that compiles? huh, impressed
Still not a code question, and look it up yourself.
just tried it in unity, atleast in-editor it works
Nice, atleast this is supported lol
oh, first time to know that
hey! currently im working on a game where the player should overcame various obstacles one of them should be a canon that knows the target position and the distance between the canon and the target with these parameters the canon should align itself so that the projectile hits the player no matter what distance (image) how would you implement that or do you have any ressources you would recommend?
You can also do this
if (new int[] { b, c }.Contains(a))
Note this does equality by reference when you compare reference types so it might fail on objects.
(im not saying fuck off i dont want to talk to you, im saying this is not the right channel and you arent going to get effective help nor do people want to help people about this here)
Go to #💻┃unity-talk and ask there
My first line IS proper code.
must be some new c# syntax sugar
cap
Why is my data list count outputting double than there is in the list?
really?
if (int a == int b || int a == int c)
if (0=0 || 0=0)
cap
Look up the proper calculation for an object trajectory, there is a function where you can plug in a distance and it outputs you the angle you need to fire the canon at
Replace int letter with a number
They mean you made a mistake and accidentally put int in the statement twice multiple times. Remove those and it would work correctly.
For some reason, even though I only save 2 data sets to my list, It says there is 4 in there....
can you show the contents of the json file?
How do I find that?
Does this deserialize into a 2d array by any chance? Count will count all dimensions, which will be double (most likely). There is a GetLength method you should use instead.
i made a system like this last year.. it was trial and error. I would have the cannon angled up by soo many degree's and add a force... (i would adjust it so it would hit at a certain distance) like zeroing in a scope... once it was hitting i moved the cannon back and just adjusted the angle.. (keeping the force the same) and i did that until it hit.. and then i used those two distances and lerped the angle w/ those.. soo like 10 ft there would be a 15degree angle.. and then at 30 feet they'd be a 45 degree angle.. and then any distance between those.. would just find the middleground..
Go to C:\Users\username\AppData\LocalLow\gamecompanyname/FrwogData.json
oh might be, I'm not sure
it worked out prettty good after i did all the zeroing stuff.. (OR u can go math heavy and just use a formula for a parabola and do it)
Let me rewrite it so it's easier to understand.
if(numberA == numberB || numberA == numberC){ Debug.Log("it works.");
Well, what does GameDataGroup have?
how can you not know where you save data to?
dude you already got your answer
thanks
Ik I just don't like being misunderstood.
that is not saving data
It makes me look dumb.
JSONUtility can deserialize into a List? And here I thought it was too basic for that.
Well, doesn't look like a 2d array so nevermind.
okay can we have a look at your json file
go to Go to C:\Users\username\AppData\LocalLow\gamecompanyname/FrwogData.json
and paste the contents somewhere.
It can mostly serialize anything the inspector can.
he's deserializing multiple times and not clearing the List first
On college pc currently... Trying to access it
Thnx. Time to stress test it.
That works? The list gets assigned to when it gets deserialized, not added
Not seemed to generate a app data on my college account
appdata is a hidden folder
For some reason file exporer on the pc won't open 😂
check hidden items
This is great
wow..
thats kinda important
ur lookin at it
U can't json parse a vector 3.
Thats odd, its definetly saving information
No, but you could know if you see where persistentDataPath points to using Debug.Log
alright
Perhaps it's not this folder at all
Put in into a list<int>{int, int,int}
thats a possibility
You can in fact parse it, it becomes an object with a x, y and z value.
thats not the chief issue yet
we cant even find the save file its deserializing from
Pointing to the folder 🤷♂️
So has the code to save a json file invoked in the first place? Does this also point to this folder?
Did he add anything before the fwog folder cuz that data path looking a bit too short.
is that an issue?
That's a transform, not a vector3
a transform stores size and rotation too
which are both vector3s.
which are both serialized here.
ergo, you can serialize a vector3
facts
Last I checked a Vector3 does not keep track of a rotation
well the first one is a vector3
You will run into bugs because unity doesnt deserialize it well.
the rotation is a quaternion
but pos and scale are both vector3s
Right, I was just pointing out the object as a whole was not a Vector3...
i have quite literally never seen an issue with unity deserializing vectors
did the guy we were meant to be helping dip
why are we yapping about this
wheres the code that saves the file?
Thanks, this is much more clear now
lol
debug ur persistentDataPath and see if it is indeed that folder ur lookin at
Is this method part of a MonoBehaviour class?
I've done that, and it is..
wait
uhh yeah
yes it does
why is it faded?
its just visual studio being ass
ohhh ok
🤔
Okay, and are you aware this method only exists for the editor and not actually if you were to play a build?
oh really?
Can we stop spamming this chat? Send a single message and stop writing a few words
Yes. if you want to store data on quit you need to do something else
it would be ..localLow/DefaultCompany/ProjectName/FrwogData/FrwogData.json
... or is it? I might actually be wrong now that I think of it. Sorry
The documentation is unclear: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnApplicationQuit.html
whoops
Actually, the method is probably called regardless. Please place a Debug.Log in the code and see if the message is logged on quit
But the path here is right?
I'll keep that in mind.
if thats ur persistent path. ya theres where it'll be
Regardless the method should not indicate it's unused. Unity methods are hardcoded to not do that
You're just debugging the path variable, yes?
How does Path.Combine just yeet the extension
as far as teh ide knows it is unused since its called via reflection
Yes but stuff like Awake and Start are as well and those do show up correctly right?
In other editors, maybe? My Visual Studio and VSCode have faded methods, and they both have full intellisense.
I'll have a look
it is showing up correctly, it knows its a UnityMessage its just saying nothing calls it
differences could be the ide used
interesting..
All are faded in all my scripts so I think its my end
dafu
what IDE are u using? im curious
Could you at least log the method to see if it's called in the first place?
lose the /
Alr
Oh yeah lose the / before you try mine.
ohh yea you dont need the / if ur using Combine
🍿 im here for this..
whoop whoop 🎉
I wonder whether it was my college pc file stuff causing the issues?
This session has just been comedy
try saving it, post the json thing
whole point of Combine is it does the slashes for you, with the correct ones for said platform
probably not given it wrote a folder
anyways lets try fix my original bug
so it was probably trying to save it to ProjectName//Frwog...
and wigged out the system
It seems to be doubling the count of how much I am saving
yeah that wouldnt change
but can you post your json file
where do u call the method that saves it? debug it and see how many show up
So it saves the correct amount, but loads double
where do u call the method that loads it? debug it and see how many show up
datalist exists outside of that method
Am I using the correct term to see how many data sets is in the json file?
which should now show up in the expected folder
might want to clear it first
I've done that too, double
Yeah have been or im getting hundreds very quickly lol
yeah run dataList.Clear(); at the top of your function
ah that works well
thanks
didn't realise that I had to clear it before writing in it
I thought it just overwrite it
i did too..
hmmm, #💻┃code-beginner message
Ah missed that, sorry mate
Thanks for the help guys!
So you know how in the unity event system, you can select a geme object, then choose a function from one of the components on that game object? How do i get something like that on my own scripts? is there a class for it or smth? Im trying to make my own thing that is like the unity even system but also takes in a delay.
You are looking for the UnityEvent class?
It's under UnityEngine.Events
I just want the dropdown field in the inspector that has all the accessible methods on a gameobject
Yeah, that's the UnityEvent class
does anyone know any discord server for robotics
how is this in anyway related to unity code, but the shreibotics server is good
hello, i've recently built my app's apk but the camera is very far away from the content... i don't know how to do it, i don't understand how the main camera is working in the editor, it ain't displaying anything
this is what it looks like
i mean you can physically move the camera into place and size it, or if its ui you should be able to lock it onto the camera with this;
I am a tiny bit confused.
I have this collision detector:
private void OnCollisionEnter(Collision collision)
{
GameObject enemyObject = collision.gameObject;
// UnitCombat unitStats = enemyObject.GetComponent<UnitCombat>();
bool disableDamage = false;
print(gameObject);
}
Why does print(gameObject) return the name of the OTHER object that this is colliding with, as opposed to returning the parent?
When I do print(collision.gameObject) it returns the object that is running this line of code. I'm trying to work out if this is a bug so really I'm just looking for people to validate this as intended functionality.
It confuses me because if I do print(gameObject) outside of OnCollisionEnter it'll print the object that is running the code, whereas if I do it in a OnCollisionEnter it'll print the object that it's colliding with, not the object running the code. It completely inverses it...
but whereever i place the camera its always displays nothing
like that
and btw i can't find this ^^
this is not, infact, the intended functionality
thats actually kinda fucky what
Thought this might be the case, lost a good half an hour to trying to work out why the script wasn't working as intended. Guess I'll have to post this one as a bug then. Thank you for helping me validate it!
i don't understand
What type of item is it?
there are images, buttons, text
So what this does is when it collides with something, it returns information on what it collided with, which is nammed collision so collision.gameobject is the gameobject info of the thing that collided. When you just print gameobject is prints the gameobject the script is on
In the inspector on the top left do you see this?
Yeah, you lock the items to the camera
but how do i do ? ^^
Uh you might need someone else to help you with the specifics, or there is probably a video online on it
wait, is your camera a child of your canvas?
It's not printing the gameObject the script is on, when I print gameObject it's printing the object it collides with instead of the object the script is on.
Let's say we have an object called "MainObj" and MainOBJ has the script with print (gameObject) in it in the scope of OnCollisionEnter, and it's colliding with a gameObject called "Wall" which has no scripts at all and is completely devoid of anything apart from the components necessary to make it render, and a BoxCollider
Now, when MainObj hits "Wall" you would think MainObj would print its own name, but instead it prints the name of the wall.
The code inside of MainObj?
private void OnCollisionEnter(Collision collision)
{
print(gameObject.name)
}```
See how there isn't any code for print(collision.gameObject.name) but it's printing out the name of the object it collided with instead of its own?
camera should not be in screen space, so it should not have a recttransform
camera should be in world space
this makes no sense. your UI should be on a canvas
UI elements are supposed to be in canvas-space (screen space). Right now, you have it in world space
which is very very wrong
Yeah, if you would want to print the gameobject its on then print this.gameobject
so your UI elements all have recttransform, and are all children of an object with a canvas component?
it is rendering correctly in the game windown
because that is what should happen
they all are children of objects that are canvas children
canvas children? is there not one gameobject in the root that has a canvas?
one main canvas for everything
That doesn't work. (this.gameObject) still prints the other object, not the object that the script is a component of
then it looks like your camera or your canvas settings are wrong
check canvas settings

idk how this works exactly in 3D, since I only do this in 2D
but the canvas should display normally regardless of wtf is going on with the camera
it is a canvas. it exists in screen space, not in world space.
it effectively plasters the canvas onto your screen with the camera view behind it
yes i can move the camera in the scene and the game window still displays it perfectly
This is a reason the rules say to not crosspost. You have two conversations going on at once
sorry i tought this was the wrong channel at first
so the menu isn’t a problem right now, just the camera positioning?
and someone responded before i deleted it ^^'
which means the solution is to move the camera or change the camera settings
That's fair. No worries
In the future, #💻┃unity-talk is the right channel for this
i think but i'm not sure ^^
👍
even when i move the camera it does not shows anything
is there anything in the scene to look at? because it looks like no
Hey ! I'm trying to make my code cleaner by making some headers, but for some reason, the one you can see on the screenshot is not showing in the inspector, any ideas ?
your controller isn’t serialized
there is my UI
Header is an attribute that targets the next thing
which does not exist in world space
so camera is useless right ?
camera lives in world space, and sees things in world space
if there is nothing in worldspace to see, it will not show anything
so why when i launch the game on my phone i see the UI but very very small ?
Header is an attribute for character controller. Character controller is not serialized, so it is never drawn, so unity never asks if it has a header
it should be completely on my screen
the UI should be Overlayed..
maybe ur resolution/dimensions aren't correct on the canvas
canvas should autoscale to your screen resolution
this is not a default setting for some terrible reason
i can't even edit them
Is their any github project out their with basic Android platformer controls
because those values are driven by canvas
Because the Canvas component controls the size, not the transform
its controlled here in teh canvas scaler component
Oh thank you ! I didn't know it targets the next line, thanks a lot
btw since you are asking to make code cleaner, you should use private access modifiers, and autoproperties
the canvas component above.. is it set to screen space / overlay/
it is
seems fine
public float walkSpeed;
should be
[field: SerializeField] public float walkSpeed {get; private set; }
so you can’t randomly edit it from other classes.
thats ur screen size
i do warn since you are now serializing a different variable, you need to use [FormerlySerializedAs…] to keep the old variables
so is it good now ? or do i have to resize every componen
u can resize the scroll object to Stretch
all the objects that are children should fit
if you just copy paste this, the old value of walk speed will be reset/deleted, as walkspeed is now an autoproperty that targets k__walkingSpeed or somethjng
hello
it don't work ^^
Oh I see, a part of my code was like this at first because I followed a tutorial but I got a bit lost because I didn't understand how it works so I get back to what I know with this. I think I understand what you mean, I will try my best to go that way thanks !
did u hold shift when u clicked it?
is rigid body better than character controller? 
neither works
🤔 not sure then.. #📲┃ui-ux would be the place to figure this out tho.. as its not really code related
neither is better than the other
both have different uses
hmm, it is difficult, they both have nice features
as a beginner i would suggest CC
Same, rigidbody can become a mess at first
CC comes with ground checks, can walk up stairs, and can work with Trigger Colliders
Rigidbody comes with gravity, but thats it
ur coding the rest urself
public => anything can read or write. We really do not want just anything to write because that introduces a lot of problems.
public int x {get; private set; }
this defines an autoproperty for x that allows anything to read x, but only the inspector or class that owns it can write to x.
That works, but is not serialized.
[field:SerializedField] public int x {get; private set; }
x is a property with an automatically defined backing field, and we want to serialize the backing field. So we can’t just use [SerializeField]. We need to use [field:SerializeField] for that attribute to specifically target the backing field, which we can serialize.
make sense?
thanks for your help, i'll try later
in general, public fields are like public toilets. Everything is fine until someone shits in it.
I do feel like CC lacks a lot of things compared to rigid, would like to try rigid body as well 
Thanks a lot for this explanation. I did not encounter that many problems with public for now because I don't do a lot of advanced projects. I understand, it's a bit heavy at first but it will definitely be useful
dynamic rigidbody does a lot of things automatically that are annoying af.
kinematic rb struggles to handle collisions unless you have a custom kinematic solver.
yeah. trust me: as your project becomes bigger, and you have multiple classes trying to change variables, and then you can’t find out when a variable changed or who changed it… it becomes a massive problem
is combined? 
KCC is basically a custom physics engine for 3D
ya, this controller is a Kinematic controller..
one which is not shit for moving a player
its the best of the rigidbody world
my custom physics engine is inspired by KCC
can I use KCC, if ok
yeah, it’s free
I see, I need to practice a lot
one last random thing that might help you:
in visual studio, press ///, and it will autocomplete ///<summary> </summary>
write a comment between the two summary blocks. it is now a comment tied to the tooltip of the next class/struct/field/property/method
so if you mouseover the variable/method/class…, the tooltip will display that information
i love summaries
use em all the time now.. so i get less confused when typin my functions
Oh nice to know! thanks
Example:
///<summary>This is the height of a jump. </summary>
[field:SerializeField] public float jumpHeight {get; private set;}
the first one has a 20 in the z and it works because it sets the camera holder rotation to 20 on the z axis
cameraHolder.transform.localRotation = Quaternion.Euler(xRotation, yRotation, 20);
but here i use cameraPosition.localRotation.z and it barely sets the rotation
cameraHolder.transform.localRotation = Quaternion.Euler(xRotation, yRotation, cameraPosition.localRotation.z);
lets say i rotate the cameraPosition like 20 it only rotates the cameraHolder 0.1
localRotation is a Quaternion. The Z value of it has nothing to do with the Z coordinate in 3D space
cameraPosition.localRotation.z never do this
how would i do it?
It's a normalized four-dimensional vector
Basically never deal with individual components of Quaternions unless you're a savant at complex number theory
What are you trying to do? generally try to avoid euler angles. You can't generally isolate a single euler angle, they come as a set of three and are not independent of each other.
yeah that works
bettter but also likely to be problematic
localRotation.z is like looking at one of the parts of a complex number, which is not the Z angle you want
changing between euler angle and quaternions is not a one-to-one transformation
Im very confused about this function. How do i access the particlesystem that has collided? Or is there another collision function i should be using.
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleCollision.html
the best way to handle quaternions is to never ever touch/read/write the internal values of a quaternion
You don't "access" a specific particle. If you could do that, it wouldn't be a particle it'd be a full object
I mean particle system then, but i wanna be able to get its duration
you want to almost exclusively create new quaternions via the various quaternion methods, and multiply quaternions together (which is like applying a rotation to a rotation)
The object with the ParticleSystem is what you get passed as a parameter
particles are really bad at getting turned off individually by code
Assuming your script is on the thing getting hit by a particle, and not on the particle system itself looking for collisions with other objects
The object passed is a gameobject, should i do getcomponent for particle system and use that?
Yes
yeah thing getting hit
Not trying to turn them off i want my character to follow a line of particles going towards the oldest ones
As the documentation says, it's of type GameObject because it behaves differently depending on whether this is on the particle system or the thing getting hit by the particles
oh i see
particles are really bad at being modified or read by the rest of your game
Yeah they're not really meant to ever be taken individually
also, game behaviour should not be affected by graphics, ever
game logic changes world state, and you then render a graphical representation
i was working with a guy who made all the game logic for his game depend on animations. When the animation hit a certain thing, new things would happen etc… Very buggy
thats a bit better tho.. atleast animation events are a thing.. not sure theres a particle event 🙂
possibly in VFX graph
i could see that..
imagine if you skip to the next turn, and different gamelogic happens because the animations aren’t done
why is this happening when i lean right if(Input.GetKey(KeyCode.E)) ```cs
float angle = isCrouching ? crouchLeanAngle : isCrawling ? crawlLeanAngle : walkLeanAngle;
float distance = isCrouching ? crouchLeanDistance : isCrawling ? crawlLeanDistance : walkLeanDistance;
if(canLean)
{
if(Input.GetKey(KeyCode.E))
{
if(!Input.GetKey(KeyCode.Q))
{
targetLeanAngle = -angle;
targetLeanDistance = distance;
}
}
else if(Input.GetKey(KeyCode.Q))
{
if(!Input.GetKey(KeyCode.E))
{
targetLeanAngle = angle;
targetLeanDistance = -distance;
}
}
else
{
targetLeanAngle = 0;
targetLeanDistance = 0;
}
}
else
{
targetLeanAngle = 0;
targetLeanDistance = 0;
}
float smoothAngle = Mathf.Lerp(cameraPosition.eulerAngles.z, targetLeanAngle, leanDuration * Time.deltaTime);
float smoothDistance = Mathf.Lerp(cameraPosition.localPosition.x, targetLeanDistance, leanDuration * Time.deltaTime);
cameraPosition.eulerAngles = new Vector3(cameraPosition.eulerAngles.x, cameraPosition.eulerAngles.y, smoothAngle);
cameraPosition.localPosition = new Vector3(smoothDistance, cameraPosition.localPosition.y, cameraPosition.localPosition.z);```
it only works when i lean left
Because you're messing with euler angles
rule #1 of euler angles is friends don't let friends use euler angles
use quaternions and you won't have this issue
xyz quaternion rotation
Something like Mathf.Lerp with euler angles will lerp from -10 to 370 degrees by doing a full circle because it doesn't realize angles are cyclical and -10 and 370 are only 20 degrees apart
Use quaternions
i am having some issues with getting a unit to walk, been trying to figure it out and watched videos nothing is helping. not quite sure what to do, my next thought was scrap and start over again. but i wanted some input first i created terrain and a unit as a capsul i also created a new layer called ground and i baked a navmesh surface into the terrain so that the unit can walk from my knowledge the code is correct i have double checked it and even re wrote it and that is doing nothing
technically with quaternions your goal is to rotate in a orderly way forever, so ideally in a fps you stick to x -> y -> z rotations
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class UnitMovment : MonoBehaviour
{
Camera camera;
NavMeshAgent agent;
public LayerMask ground;
// Start is called before the first frame update
void Start()
{
camera = Camera.main;
agent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(1))
{
RaycastHit hit;
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit, Mathf.Infinity, ground))
{
agent.SetDestination(hit.point);
}
}
}
}
that is the code
!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.
euler angles are of limitted use unless you are in 2D
eulers is fine for single dimensional rotations
/// using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class UnitMovment : MonoBehaviour
{
Camera camera;
NavMeshAgent agent;
public LayerMask ground;
// Start is called before the first frame update
void Start()
{
camera = Camera.main;
agent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(1))
{
RaycastHit hit;
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit, Mathf.Infinity, ground))
{
agent.SetDestination(hit.point);
}
}
}
}
but once you add that second rotation axis does eulers create gimbal
the issues with angles is that they don’t commute
i've got this but it doesnt work```cs
float smoothAngle = Mathf.Lerp(cameraPosition.localRotation.z, targetLeanAngle, leanDuration * Time.deltaTime);
float smoothDistance = Mathf.Lerp(cameraPosition.localPosition.x, targetLeanDistance, leanDuration * Time.deltaTime);
cameraPosition.localRotation = Quaternion.Euler(cameraPosition.localRotation.x, cameraPosition.localRotation.y, smoothAngle);
cameraPosition.localPosition = new Vector3(smoothDistance, cameraPosition.localPosition.y, cameraPosition.localPosition.z);```
""" cs using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class UnitMovment : MonoBehaviour
{
Camera camera;
NavMeshAgent agent;
public LayerMask ground;
// Start is called before the first frame update
void Start()
{
camera = Camera.main;
agent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(1))
{
RaycastHit hit;
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit, Mathf.Infinity, ground))
{
agent.SetDestination(hit.point);
}
}
}
}
its supposed to rotate 20 degrees
those instructions are terrible
and it only rotates like 0.1
!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.
this will never work
No, it's your reading comprehension
you are fucking with the contents of a quaternion
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class UnitMovment : MonoBehaviour
{
Camera camera;
NavMeshAgent agent;
public LayerMask ground;
// Start is called before the first frame update
void Start()
{
camera = Camera.main;
agent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(1))
{
RaycastHit hit;
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit, Mathf.Infinity, ground))
{
agent.SetDestination(hit.point);
}
}
}
}
!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.
if you fuck with a quaternion’s guts, the quaternion fucks with you
what is a back quote
yo can I stop scrolling down every two seconds
guys, stop with the giant code blocks
