#Feedback
1 messages Ā· Page 1 of 1 (latest)
Your variable names are very inconsistent and there's a lot of unnecessary whitespace making the script bigger than it needs to be
Yes ik i am not home rn but its not fully ninished its just in a working state
I stil have a lot of fine tuning to do
I'm going to fork it and make some stylistic changes so you can see maybe how you could format it better
That great thanx
I haven't seen anything bad/logically incorrect yet though so thats good
Yay
Actually what is fork it?
Found it
Didn't know that was a thing
I think thats the default naming convention made by microsoft
I don't know of any naming convention that asks you to start identifier names of _
According to them, private fields should start with underscore. Unity devs tend to just skip that
Ik and thats why we donāt use that š
Actually a friend helped me make some parts and he renamed it with _ bc they where all public before i made them private bc i like that more
well then that makes even less sense
Well ill change it when i get home hehe
[SerializeField] private bool isGrounded = false;
// private statements
there's also like a 6 line gap between the last field and the comment
there shouldn't ever be a more than one line gap
Oh not all the _ where made by him its bc he did it i thought it was necessary to do or something
no, the names of your variables dont ever affect what they do
unless they use reserved keywords
I need 2 line gap so it is organized i have a reading disability
Its just easier to read code if everyone uses same type of naming convention
There's also just a bunch of comments and things with inconsistent capitalization which just looks kinda bad
but ig it doesn't really go against a standard
however the variable names with inconsistent capitalization is bad
Well it isnt finished it are just notes for myself
what about the tooltips though
Headers*
What about it?
they have inconsistent capitalization, just a nitpick though
I thought they looked ok in the unity
Where is inconsistent capitalisation
[Header("ground c...
vs
[Header("Fall speed...
Unity automatically does a capital at the start in the editor thingy
well ig it just looks bad in the code then lol
And i like that the first letter in not capital if i have to write it a bunsh of times
the double newline thing ig is fine if you keep it consistent (which you dont)
Well i made the code in a way so you never have to look in the cofr
Ik ik
Hey just to be fair i only learned cs 4 days ago ok so i think i did pritty well
Buttttttt ill ajust the problems jou just said so it looks better and all
if (_movementDirection > 0 && !_isFacingRight)
{
FlipPlayer();
}
else if (_movementDirection < 0 && _isFacingRight)
{
FlipPlayer();
}
this is redundant
you only need one if statement for this
And what is the # reagon debug bc idk what it means tbh
if ((_movementDirection > 0 && !isFacingRight) || (movementDirection < 0 && isFacingRight))
{
FlipPlayer();
}
Yes while that looks better now i do not understand that piece of code
its literally the same thing but with an OR gate
I dont know how to ise ||
|| means "or"
Oh ok
so if the movement direction is more than 0 and not facing right OR movement direction is less than 0 and is facing right
I don't think the code I'll push will be useable out of the gate so you'll probably have to manually make changes
There's no point to initializing fields with their default values
bool foo = false is unnecessary
since booleans are false by default
Vector3 velocity does not need to be initalized as Vector3.Zero
if (isGrounded)
{
hasDoubleJump = true;
}
``` is redundant
hasDoubleJump = isGrounded makes more sense
ok yeah
isJumping = Input.GetButtonDown("Jump") && isGrounded;
@fervent igloo only logic issue I found by fast glance was this: currently youāre checking for all colliders inside the box area and only checking whether atleast one of those is not the player itself. If WhatIsGround layermask is set up correctly, you should never get the player itself as result. Checking the ground using single OverlapBox (you can check whether the result is null or not) should be enough. OverlapBoxAll just makes useless memory allocation every time you call it and iterating through the list of colliders adds some small overhead too. Same applies for the OverlapCircleAll.
oh yes thats gonna be slow
just got to that part
for loops on update are not good
especially when you're creating arrays
Well I canāt say for loops are automatically bad but ofc every pointless calculations should be avoided
if (groundCheckObject != null && boxCheck == true)
{
Gizmos.color = Color.red;
Gizmos.DrawWireCube(groundCheckObject.position, new Vector3(boxWidth, boxHeight, 0f));
}
if (groundCheckObject != null && cirleCheck == true)
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(groundCheckObject.position, circleSize);
}
this could be a style problem but comparing with == true is redundant
setting the gizmoz.color to red inside of the if statements twice is also redundant
gizmos*
#region is used for organization
its so you can collapse and navigate through code quickly
I canāt just imagine how many for loops unity is using per every single frame intenrally⦠even OverlapBox is most certainly using for loop to iterate through list of bounds and colliders to get the result. Some of the unitys internal for loops may happen on c++ side so it may be bit faster but my point is that you donāt need to be afraid of using for loops on update. You can use them always you have to but massive loops (which this obviously isnāt, the memory allocation is probsbly the biggest issue here) are obviously not good for performance
I dont understand lol ill look in to it
So not boxall but just box?
Cool
yes. that gives you whether the box hits any object on WhatIsGround (which would be better named as groundLayerMask or something like that) layermask and if it does, it gives the first object it hits as a result. if *OverlapBox gives you null, it didn't hit any object on those layers
Ah i like the way it is ill optimize a couple things but some words like groubdLayerMask doesn't make sense in my head so i avoid those words
I have some trouble reading this could you rephrase it please? My language is not english
mine is neither which may make my messages nothing but clear
Ohhhk?
well, let's start by this: what is the point of this checking? (the gameObject itself should never be on that collider array because I assume WhatIsGround layermask doesn't include the players layer) ```cs
if (colliders[i].gameObject != gameObject)
{
_isGrounded = true;
}
My friend made the ground check
Ill ask him
How do you make it in one of those boxes the code i mean
In discord
you just use 3 backticks on both sides of the code + cs to indicate that you want c# syntax highligting
this is called code block
backticks?
`
'''
if (colliders[i].gameObject != gameObject)
{
_isGrounded = true;
}
'''
` not '
if i remove All it gives me an error
you can't just remove it
So this ā¬ļø check is pointless because colliders[i].gameObject will never be same as gameObject due to the fact your OverlapBoxAll uses layermask (WhatIsGround) which doesn't include the player itself.
if (colliders[i].gameObject != gameObject)
{
_isGrounded = true;
}
Because colliders[i].gameObject != gameObject is always true, the whole if check is worth nothing and therefore the code is same as this:
for (int i = 0; i < colliders.Length; i++)
{
_isGrounded = true;
}
That means _isGrounded is true always except when colliders.Length is 0 and therefore the for loop doesn't run once. That means your code is exactly same as this ā¬ļø
Collider2D[] colliders = Physics2D.OverlapBoxAll(GroundCheckObject.position, new Vector2(boxWidth, boxHeight), 0f, WhatIsGround);
if (colliders.Length != 0)
{
_isGrounded = true;
}
So basically what your code is doing, is to check whether OverlapBoxAll hits any colliders at all. You don't need OverlapBoxAll to check that because OverlapBox exists. OverlapBoxAll returns list (it's technically an array) of all colliders the given box hits. OverlapBox on the other hand returns only the first collider it hits and null (basically in c# null means same as "nothing") in case it doesn't hit anything. Sooo finally you could just simplify your code to this:
Collider2D collider = Physics2D.OverlapBox(GroundCheckObject.position, new Vector2(boxWidth, boxHeight), 0f, WhatIsGround);
//checks whether OverlapBox hit something on WhatIsGround layer. if so, grounded can be set true
if (collider != null)
{
_isGrounded = true;
}