#💻┃code-beginner
1 messages · Page 430 of 1
i am
How is it?
really good for 2D, but i dont really understand the 3d
I am still using 2022.3.11f1
Unity 6 should only be used by those who really, really know Unity
Isee, its just beta right now?
i think preview
I see
Ooh i fixed my problem
but now it moves so slow that it just falls
thanks for the help guys
oh gosh i made a worm
ur good
🤣
haha
look ima send u a video
Alr
you probably want to freeze the x and z rotation on your rigidbody
oo yeah that makes sense
thanks
also do freeze position on Z if you don't wanna make it go in unwanted axis
if its just x movement
nicee it works now
nope, im just trying to apply what i learned in 2d to 3d
with the z axis
What game are you making
I see
i dont really know, in 2d i bought a course for unity 6 (platformer) and i was curious about 3d
so maybe a 3d platformer
Thats nice
Just clear the fundamentals of local space and world space
if your using rigidbodies, thats gonna be really helpful
How can i make the player no longer move if i stop pressing the key?
Just add a condition
If (input > 0.1f)
{then move}
else dont
And You have to verify if thats just the input movement or the Physics affecting your object
set velocity to zero on GetKeyUp
oh and every project now seems to come with one of those new input systems
by default
Damn thats great
i think ill learn that one since its more default now
oh and also
you now have to manually install the Built in render pipeline templates
now the standard is those universal 2d and 3d ones
urp as well?
same
does it happen to you that you understand the whole input system concept, or the movement logic. But when u type the code you just forget that what was it
is looking at learning plugin dev got some ideas is it c plus plus and .net
i forget what it is before i even start typing
before opening unity
It's called being human :P
plugin dev for unity can be done with C# and .Net. generally C++ does not use .Net
so .net is a good option
for Unity dev? Of course
you mean the IDE?
yeah as a newb
yes, but when you develop plugins you do so external to Unity
ok
I used
rb.MoveRotation(Quaternion.Euler(25,12,135) in FixedUpdate()
Surprisingly it makes the object fly away. This only happened when I kept the 'Z' Axis value little high. Otherwise this didn't happen in smaller values.
Can anyone explain what's happening??
Why would it fly away, there is no movement in that code only rotation
How can I do that a button could only be clicked once?
I have a button that decrease lives and after one click it changes, but if you click two times fast it just decrease 2 lives instead of 1, this is the click listener of the button:
optionButtons[index].onClick.AddListener(() =>
{
optionButtons[index].interactable = false;
OnOptionSelected(isCorrect);
optionButtons[index].interactable = true;
});
Exactly my question. When I put small values it didnt fly
I suspect you are looking at the wrong thing, this code alone will never cause 'flying away'
So what would?
anything which affects velocity
can you share the complete method !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.
RigidBody rb;
Void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
rb.MoveRotation(Quaternion.Euler(25,12,145));
}
}
your changing of interactable there is complete useless
It's a long class so I will only be sharing the related methods, is fine?
https://hatebin.com/hbnnwgtqrz
It's for a level that it's like a trivia, so when a option is selected the content of the buttons with the answers and the question changed
line 14 was what I was looking for, so thars's fine. the usage of interactable still makes no sense
Yoo @slate haven
This is the whole code I used
Yes?
I implemented the new input system into the movement, now it works great
Yeah, this was just a way of trying to stop this, just testing. I aslo try with a corroutine to wait
yes, setting interactable to false and then a cooldown to set it back to true in a coroutine should do the trick
Thats good bro
Once u get a hang of it, its better than the legacy
yeah, but i still have some problems with gravity doe
Maybe u know how to fix it?
its at the end
I tried this way, but still not working, idk what could be wrong or either how to debug this. Maybe because I reference the button using button[index] when maybe index is a different value? I don't know if unity set the listener when is declared or when is executed
https://hatebin.com/wyuwlckeyd
Did u tick the gravity checkbox in the inspector?
you gotta check if the player is onGround , if he is then enable gravity , if he aint then disable gravity
or i think its reverse
yup
alright thanks
that is not how you Start a Coroutine
I see your player is getting affected by gravity, but its way too slow
My bad, I'm stupid, long time without using Unity
ill try what hellio said
cant remember on how i did it but i remember something with checking if ur onground
Is working, thank you so much for your patience
hm alr
np. you were damn close, I just gave you a nudge
Check if any objects in the hierarchy has conflicting rigid bodies with player
on the child objects of player dont put any rigidbody
always put Rigidbody on parent
maybe try this
im just gonna continue on my 2d game
or create a new game Object
done that already
nope
i think its cuz of this in the movement
and Rigidbody to it
Yeah try that in a new game Object
cuz the y is always changing to 0f
and see if its the same
ima continue on my 2d game
ohhhhh
wanna see some of it?
sure
perhaps make a thread if you want to just talk about your game without help
or DM eachother
How could I upload stuff to the asset store?
become an asset store publisher
This is a code channel, ask code related questions. To find out how to become an asset store publisher, I'd suggest googling and read the info Unity provide

Thats good
so how do use the randomValue variable in update
why do you have randomVal and randomValue ?
sorry that was so dumb
thanks for helping
ObjectDisposedException: SerializedProperty questions.Array.data[4] has disappeared!
UnityEditor.SerializedProperty.get_propertyPath () (at <fe7039efe678478d9c83e73bc6a6566d>:0)
Does this mean that im trying to acces an object that was deleted?
have you written any editor code? because that error is related to editor code
Im at very begging, i dont even know what editor code is. You mean c# scripts?
then the answer is likely: "that is an editor error. clear the console and move on"
ok thanks, so nothing to worry about
the size of the values mean nothing here, this is just a rotation. The issue is likely in your setup, maybe you have other code affecting this or there are overlapping colliders
also please dont record with your phone, record on your computer. there are many apps to do this, OBS is free and pretty widely used
Nope, only 1 script, Collider is only on the Plane
Oh yes, I had 2 colliders on the player as well
I can see colliders on the object in the video. Try recreating this in a new scene, a basic cube and only attach this script.
Is it correct to say that the behavior of method hiding is that whe you cast the derived class into the base class, the original base class method is called instead of the "new" keyword defined method;
whereas method overriding will call the derived "override" keyword defined method regardless of what class it's being cast to
yes
Thank you
Quick demonstration of that behavior: https://dotnetfiddle.net/fX1Kjo
Very comprehensive and quick demo
Question: So I have this Recoil function, it get called once per click, no update
//Unrelated logic removed && names shortened
public void DoRecoil()
{
recoiledRot += new Vector3(x, randY, randZ);
transform.localRotation = Quaternion.Euler(transform.localRotation.eulerAngles + recoiledRot);
recoiledRot = Vector3.zero;
}
This script lerps all the stuff back to its original place
void Update()
{
lerpedRot = Vector3.Lerp(lerpedRot, desiredRot, rotLerpSpeed * Time.fixedDeltaTime);
transform.localRotation = Quaternion.Euler(lerpedRot);
}
but it is failing to do that with the rotation, probably because I dont know how to properly lerp rotation, any help?
Im trying out other stuff rn, its the issue with me lerping euler angles directly prob
the lerp you've shown appears to have nothing at all to do with the DoRecoil method you've shown as none of the values used in either method are used in the other. Not only that, but you are using fixedDeltaTime in Update for some reason, that is going to make it go faster on higher framerates because fixedDeltaTime does not change as the framerate changes like deltaTime does. also that's a "wrong lerp" and ideally when dealing with rotations you'd use Slerp not Lerp
this is a code channel. but if the tools aren't showing up there, then select the 3 dot button in the upper right of the scene view window to open them again
I'm sorry, I don't know the right channel
3 dots don't show any snapping options though
Yeah, well they are related indirectly, the second script is only supposed to lerp the gun back into its position, its easier because I can just add a recoil to the gun, and it will get moved back by the other script, I need it to be like that because of unrelated reasons
Im aware im doing wrong Lerp for now, might not even change it because I dont need it to be accurate
It works as I want it with positions, but I didnt show that in the samples I gave
Give me some time, I messed up big time on the lerp again
Hi,
For search a gameObject in a scene with 50 others gameobject in it, is it more optimised to use GameObject.Find() orGameObject.FindWithTag()
Well, searching with tags means only searching objects with tags vs every object by its name.
What exactly are you trying to do?
When I switch between my scenes, I want to take 2 gameobjets in the scene to take their transform position
Hmmm, maybe have a Singleton manager and have the new instances register themselves as references with the manager on Start or something. You would be able to access the two instances directly instead of having to search. For instance, player one and two would just tell the manager which objects in the scene they are and every other object within this scene thereon could access them directly using the manager.
Unity keeps an internal list of objects with any tag so FindWithTag would only have to search those
Okay I see. So in a script, I put the instance of the 2 gameobjects and take it in the other script by their instance ?
i think this is where to put this but I'm trying to push my unity project to github
I have git lfs installed and registered to recognize .dylib files
every time i try to push i get this error:
remote: error: See https://gh.io/lfs for more information.
remote: error: File Library/PackageCache/com.unity.burst@1.8.16/.Runtime/libburst-llvm-16.dylib is 124.60 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
To https://github.com/Myusername/myproject
! [remote rejected] master -> master (pre-receive hook declined)```
I've been hitting my head at this for an hour now and idk why it's not working
i also have the gitignore recommended for unity
private void Start()
{
PlayerManager.Instance.PlayerOne = this;//Set this object as player one with regards to the manager
}```
So don't need to attach a script to the gameobjects right ?
this exceeds GitHub's file size limit of 100.00 MB
Just do a SIngletonManager and take their instance
yeah
i have git lfs installed
and it has the file recognized
The script would be on the players in the new scene. They would tell the player manager (a Singleton object - ddol) who they are.
Oh okay I see
So I was wrong
And so, PlayerOne is a gameobject stock in the Playermanager script right ?
It would be an accessible member of an instance of the PlayerManager script - a field or anything (my naming convention implies it's a property).
You can lookup Singleton patterns with Unity on Google - pretty sure vertx has got a generic example somewhere as well. Assuming the Singleton registers itself as the unique instance in Awake and prohibits other managers from existing (as intended with the Singleton pattern), you'd just tell the manager who you are per scene in Start (assuming every scene would attempt to create a manager if one doesn't already exist).
This isn't really a code question. You shouldn't be pushing these folders. Use a gitignore template for Unity.
Could anyone please help with detecting collisions with touch screen actions? Ive been able to get tapping to work but I need to be able to swipe through the object as well. https://pastebin.com/Wj4skwPr
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
The Singleton pattern: https://unity.huh.how/references/singletons
oh alright. sorry. didn't know where to put it really
Follow what it says
First check your console window for any compile errors
It says "This is not allowed", they worked before
What? Wdym
Show your errors
And this is not a problem with one script, it is about all scripts
What is not allowed
Show your errors
Show the first error.
if literally any script has a compile error, then nothing can compile
Once you fix the compile errors it will work
It just says "This is not allowed" every time I try to open a script
Clear the console, show whatever is left, starting at the top
Clear the console and show the first error
That is your actual error
Just one problem with a script I'm programming now
You need to fix that before anything can compile
Yep, gotta fix this
so i put it at the dge of the map and i still cant put it over the map. I tried it over transform position and Layer Selection but it still doesnt work. the Problem is im working with a duo who designed the Tiles for the map so idk what he did
my player gets stuck on the edges sometimes
When using Physics.Raycast and you want the distance between the player and the object, what does the "out hit" do in that case ?
new to c# and unity.
Are strings compared by reference before being compared by value?
So comparing two strings is actually fast?
It's a RaycastHit struct which contains lots of information about the hit.
this
could you explain furthur?
First by reference:
https://github.com/microsoft/referencesource/blob/51cf7850defa8a17d815b4700b67116e3fa283c2/mscorlib/system/string.cs#L558
alright sweet, then they should work fine as dict keys
I mean that doesn't mean it's "fast"
there's no guarantee the two strings are the same instance
unless you're using a const field or something
in which case you might as well just use an enum
it's still likely fast enough, it depends on your use case
well I am just porting code now, ported my plugin from unreal to godot, now from godot to unity.
Unreal had FName which are basically hashed so comparing two of them is just comparing an integer.
Godot has StringName which as far as I understand are just immutable string, also compared by ref.
I couldn't find a unity equivalent to either, but I figured if the strings are compared by reference that is close-ish
problem with an enum is that I don't know all possible values at compile time, since users can add more
C# has enums
Yes..., I meant that the reason I am not using enums is that I don't know the values beforehand
Just FYI if you're hashing the string that a user inputs, you're still having to iterate over the whole string once to create the hash
I think you're probably prematurely optimizing worrying about this though
sure, but that is a one time thing
it's not a one time thing unless you explicitly are saving the hash int somewhere and using that as the dictionary key
Ehh, I am hitting a hashmap with hundreds of elements on update for hundreds of objects
have you profiled it
on the target hardware
not yet in unity. since I just started porting it
Do it the most straightforward way first, and profile it
if you have a performance issue, then worry about optimizing it
@steep rose for some reason im not allowed to send a pic or sum
maybe bad internet, idk
but I have three parameters, and 6 transitions, 2 between every animation
what do you mean by "it was not being animated at first (cuz its js some few blinks)"?
im triggering it when the MouseButtonDown, so idk if its related but its not long
making it with no exit time fixed it, but I mean it aint exiting
my code made it not work both ways lol
you mean the bool is not turning false and stopping the animation?
or the animation stops to quickly
at first or now?
at first it didnt even play I think
now what does it do
well, the animation just sometimes play
and sometimes not
and it never plays while idle
yeah im gonna need to see that animator, the code looks fine. its probably something with the animator
its giving me upload fail
oh nvm lemme use a vpn
ight should be sent now
still slow af
if my memory serves me correct I believe there is a duration float in the parameters on the animations
i would have to check for myself
on the animation or transition?
check on both
The Unity equivalent to FName is https://docs.unity3d.com/ScriptReference/PropertyName.html
But it's worth noting you can only turn it back into a string in the editor
thank you!
you may need someone else for this, I was familiar with the animator but i havent used it in a while. From what im seeing it might be something with exit time, im gonna have to reintroduce myself to this to be able to help fully.
I know there are people that can help that have way better knowledge than I do
Also worth noting that while FName is (iirc?) case-insensitive, PropertyName is case-sensitive
Im still gonna try to help but it might take me a minute
np ty
In my unity project I want my character to turn (rotate) and move towards the closest enemy when the attack button is pressed, but at the moment these movements happen instantly and I have no idea how I can lerp them.
I use the following code:
transform.LookAt(targetLocation);
characterController.Move(targetDirection * speed * Time.deltaTime);
Originally I thought multiplying with Time.deltaTime would do the trick, but it doesn't. Anyone know how to do it properly?
You would interpolate the direction vector/rotation you're looking at
something like:
Vector3 direction = targetLocation - transform.position;
Quaternion targetRotation = Quaternion.LookRotation(direction);
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);```
Is it better to write code with properties instead of fields? Read online that it was better practice because you get proper encapsulation, but I find the unnecessary get/set to be a bit frustrating
itch.io has a bunch of those free assets
this isn't really a code question. Also did you look it up.. they have so many guides on this
Best practices are to make all fields private and provide public accessors if and when needed.
aye aye, so basically to never use public?
In general, yes. It makes it really easy to add a listener pattern to send a message whenever the data changes, or to put debug breakpoints on getters/setters to know when something's being modified
never public fields. You can have public properties and methods
Also was wondering, what exactly is the difference between Delegates and Action? The way you set them up seem identical
Action is a del
Action is a delegate type
Delegates let you specify an entire function signature. Action (and other similar things like Func or Predicate) are specific signatures that you can use
Sort of like how an Apple is a fruit. So you kind of asked "What's the difference between Apples and Fruits?"
I see
And in this cse delegate is fruit and apple is the type
Ah I see, would it be right to say Actions are delegates with void return type
Alright, math time because I'm messing up worldspace conversion, and I'm not sure where I'm going wrong.
I need to do three things. Listed in order of least likely to have messed up to most.
1: get what the position and rotation of object A would B in A's localspace (which I need for later)
this is done via:
localPosOffset = referenceObject.transform.InverseTransformPoint(this.transform.position); //if we were a child of ReferenceObject, this is what our local position would be.
Vector3 tempRightForward = this.transform.InverseTransformDirection(referenceObject.transform.forward);
Vector3 tempRightUp = this.transform.InverseTransformDirection(referenceObject.transform.up);
localRotOffset= Quaternion.LookRotation(tempRightForward, tempRightUp); //if we were a child object of ReferenceObject, this is what our local rotation would be
From what I can tell, this works perfectly.
I apply it, which also works perfectly, by:
thing.localPosition = localPosOffset;
thing.localRotation = thingsparenttransform.localRotation * (localRotOffset);
Where I'm stuck is inverting this w/ the offset I have, so that instead of the values being used to create a child object under the parent, it makes an instance of the parent in the same relative rotation around it (without rotating the object itself), so i can configure it. Works one way atm, but not the other.
my current "stab" at it is dumb, and doesn't properly consider rotation or anything, so I'm kinda fishing here.:
wouldBeParentObject.transform.position = this.transform.TransformPoint(-localPosOffset); //also dumb.
wouldBeParentObject.transform.rotation = Quaternion.Inverse(localRotOffset); //dumb
basically I get the local offsets of B, which when applied to a child of A result in it being in the same spot as B.
With these same offsets, is it possible to get the inverse, so I can spawn an object & have it be where A would be, if B were the child of A (but it's not, it's just worldspace so I can config an object)
int randomSoundNum = Mathf.RoundToInt(Random.Range(1.0f, 2.0f));
if (randomSoundNum == 1)
{
bagietaDyingClip = Resources.Load<AudioClip>("AudioClips/Bagieta-dying.mp3");
}
else
{
bagietaDyingClip = Resources.Load<AudioClip>("AudioClips/Bagieta-dying-2.mp3");
}
playerAudioSource.clip = bagietaDyingClip;
playerAudioSource.Play();```
why is this not working
i have the bagietaDyingClip variable assigned earlier not in the function itself
what isn't working about it
its not playing, atleast i dont hear it
is the code running? When is it running?
could it be something in the unitys settings?
its running when the player dies in the gameover function
which runs when?
Also if the player is "dying" are you destroying it?
Is the object with the AudioSource on it getting destroyed or deactivated
In which case, are you destroying the audio source?
no
im not nothing is getting destroyed
it runs when a player collides with a wall or goes out of bounds
well again, you should start with checking if the code actually runs
so OnCollisionEnter or something?
{
endTime = Time.time;
gameManager.GameOver(startTime, endTime);
}```
and
private void OnCollisionEnter2D(Collision2D collision)
{
endTime = Time.time;
gameManager.GameOver(startTime, endTime);
}
that top one
is in Update?
yh
if so it's going to run every frame
and restart the sound every frame
but - again you need to check that your code is actually running
Okay, so, in this diagram, A is not a child object of B, but you want it to behave as if it were as B rotates?
it does cause the menu pops up etc.
ok but which one is running
really you should use Debug.Log to check this
I record the offsets of A to B, so that when applied to a child of A, they match B.
To configure this, I wanna spawn objects in worldspace that'd match up with where A is as B's parent, without moving B basically.
Okay, so you want a sort of snapshot of the local transform values of A as if it were a child of B, and then you want to apply those to a different object, after B has moved into a new position?
Yeah, basically. Let's use hands as an example because I'm gonna keep mixing up A/B
Ae, I record the local position of a ball where it'd be in a hand relative to the hand, so I can just move the ball (or Ig attachment point if we're doing hand stuff) to the offset (in local space) to have it match.
to configure the hands, I wanna spawn them in so the offset between them (ae, hand to object) is equal to what I have recorded, but without rotating the base object. So if the hand was configured to be on top of the ball, and I tipped it back 90 degrees or whatever, it'd be on top (but with the same end result if I recorded the offsets again)
@wintry quarry it was becase i added the format at the end .mp3 lol
Okay, so, if you had a ball in the palm of your hand while your hand is held straight out, you'd want to be able to spawn a ball in the palm of your hand while it's upright like a waiter holding a tray. The hand moves and rotates, and you need to keep the relative position.
Just want to make sure we've got the right idea of what the intention is so we don't get too into the weeds of trying to make a specific solution work, in case there's a different way to solve it that might be better
In this case the hand stuff is handled. I can apply the offset to the attachment point on the hand and it'll match up perfectly fine
I'm trying to do the inverse of it. everything would still be the same distance/orientation/etc, but with the ball as the parent instead of the hand. basically applying the offset I recorded (from hand to ideal ball position) backwards, to get where the hand would be if in worldspace the ball was both it's child & in the same position/rotation it currently is
Ah, okay, that is a much more complicated problem. What I was reading it as was something actually pretty easy to do with parent constraints but this is a bit more difficult. Gimme a second to think about it
Yeah, no problem. it stumped me too.
Idk if this diagram helps but here;
Okay, so, the local position and rotation are basically the difference between the parent and the child, right?
That would mean the hand's transform should be at the ball's world position minus the offset, and the rotation be the world rotation of the ball minus the offset rotation.
I have no idea how to do the quaternion math on that, but let's try it with the position first and see if this idea is sound at least?
wouldBeParentObject.transform.position = transform.position - localPosOffset;
If this puts it where we want the parent object to be, I can figure out the math
wouldn't work. first thing I tried unfortunately, it doesn't account for rotation (ae, if you have the hand pointing @ the bottom left corner of a box, and rotate it 90 degrees, it won't change spot)
...lemmie try etcetc position = this.transform.TransformPoint(-localPosOffset); though. if that works rotation's probably a similar deal
Ah, right. Dang
yeah, .TransformPoint also doesn't work, presumably because the offset only works in localposition if the rotation's right. hm
Unfortunately I can't just record the offset both ways, as it's open to direct user (or configurator ig) editing, I've gotta work backwards here.
this double sucks as the unity discussions pages keep giving me 403s (probably because the migration, which I'm sure will go well
)
Yeah, I'm trying to fiddle with it on my end and am also coming up with bupkis. I'm gonna have to ponder this for a while, this is actually starting to eat into my actual job time. If I come up with something and no one else has come up with anything I'll ping you
Gotcha. I'll ping you if I figure it out lol
is there a gizmos.drawcapsule?
appreciate you 😄
i have this really long annoying if statement for different types of collisions. I feel like its really inefficient and was wondering how i could make it better? I have 4 different shapes so i'd have to make 16 versions of this to keep this up 😭
re-use an enum and switch statement
yeah, i decided to give each class an enum instead of directly checking the class type itself
is there sideways movement on a rigidbody? im trying to my character left and right without looking in that direction but i only know Rigidbody.forward()
to move**
Well, there's no such thing as Rigidbody.forward()
So if you're looking for something like that for sideways, that also doesn't exist
i meant transform.forward
mb
There is transform.forward
And transform.right
Etc
You can easily look up the docs for the transform component and see it all. That should always be your first stop
so can i do transform.right * input.GetrawAxis(Horizontal) and itll work?
is directly checking class type expensive in the context of a physics simulation?
That is not how I would write it, but sure
https://paste.ofcode.org/yYiuUYTrhLKCYVz5gD3FDU i made this simple code that should made the enemy follow me when i am too close but it doesnt work and the enemy stands still even if i am too close
Can someone help me with this bug?
Try logging Vector3.Distance(transform.position, player.position) and see what the value is
lemme try
@polar acorn it gives me the same value when game starts even if i am too close
So, the value doesn't change?
my entry state dissapeard lol
And it's always that distance, even when moving the player around?
it also giving me errors with nothing relateed to my code
nvm reset and everythin worked (and gone as well)
float dist = Vector3.Distance(other.position, transform.position);
ive tried that same problem
Then the distance between this object and whatever object you've assigned to player is 12.48762
And that object is not the one that moves around
That shouldn't really make a difference. Since it is just a float telling the distance between two points. Not a vector or anything
yes

Try typing Player into the hierarchy search
does anyone know how to check if my character is grounded? is there a isgrounded function in rigidbody?
I am at work. But I guarantee you it will not change anything
Just think about it for a few seconds and you will see why
There is not.
Do a raycast (or other spatial query) down to test the ground

alr ty
it doesnt work
It's a displacement, there's no sign on it. It's the same either way
can someone help me fix something in my code
for some reason it's not affecting animtor's variable
it was working a bit ago but I had to reset my animator
I just posted what it said on the documentation
where?
not that
oh mb
Funny you write this but you clearly didnt try it
I dont have unity open
"How far is that rock from me" and "how far am I from that rock" would clearly have the same answer, right?
is it a navmesh problem? becouse not even chat gpt managed to fix me this bug
Gpt will likely just make things far worse
You say "not even" as if gpt was capable of fixing it
is the same as (a-b).magnitude
Magnitude is an unsigned value. The documentation says it's the same
That's irrelevant. I'm just pointing out you really shouldnt just be guessing at issues if you arent confident in what the problem is. Most of us stay out of problems we arent knowledgeable about
Rip for me
I've told you what the problem is. The object you're checking distance to isn't moving
Whatever object player is set to is not the one that's moving around
Try typing Player into the hierarchy search
Yeah but the player is moving shouldnt still tell me the distance?
Only if that object is the one you dragged in for the player variable
Yes it is
Prove it
Ok, and you did not drag in a prefab?
If it were, then the distance would be changing. Since the distance is not changing, the only conclusion is that the object your player variable holds is not moving.
Drag that in one more time. Just to be sure
If you're certain the assignment is correct, then Player does not move.
Ok
Check the inspector for Player as you move around. Does the position change?
No
Then your Player object is not moving
In ter es ting
What have you been moving then?
anyone have any unity functions that may help me create a draggable screen because I can't think of anywhere to start
I managed to fix it
i forgor that player was an empty object
so i put player body and it works
Wait. So you are moving the child and not the parent?
Generally you move the parent, and have the model and animations on the child
not exactly a direct coding question, this is more vscode related:
does anyone know what extension provides this "tab to complete" option?
Intellicode
thank you 🙏
also thats Visual Studio not vscode
oh, there's a difference???
yes very much lol
i've always called my visual studio vs
LMFAO
WHOOPS
i thought vs was short for visual studio
Visual Studio is a true IDE,
Visual Studio Code is a text editor that can become somewhat of IDE with extensions
ahhhhh
Hey guys
So I'm trying to create this obstacle (orange rect) that is activated by a Trigger
and moves ping pong between two points
but even though my code works in a similar object that isn't activated by a trigger
it refuses to work for this triggered obstacle
It moves to the first point and pauses
I tried diffferent approaches and it either jitters after reaching the first point or pauses
start by sharing 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.
it's big 😅
did you not read the part about Large Code
thats why the bot has a section marked large code blocks
No sorry
why ? thats more work. more friction..
What do you mean?
Can I send a txt file?
mate just send as links.
Ohhhh
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
putting Logs inside these functions to see what what the current values are vs what you expect, and if they print in the first place
(I mean https://gist.github.com/ for reference, not a repository)
They are printing correctly
and also alternating
how did you verify
private Vector2 GetCorrectNextPosition()
{
nextPointPos = points[pointIndex].transform.position;
print(nextPointPos);
print(string.Format("The point index is {0}", pointIndex));
return nextPointPos;
}```
Called on Update
The block reaches the first Point and then prints the position of the other point and the correct index
Then the position of the point the block is jittering at and its index
where is that here, i dont see it
Instead of moving, it keeps jittering
is the trigger a rigidbody?
i'll fix that, thanks
this is not working for me
works for me on both, which editor are you using?
Visual Studio Code
No BoxColl2D
do you have the Unity plugin and the c# Devkit ?
these are ALL of my extensions
alr maybe a quick vid of whats happening
anyone know how i can limit the range to 90, -90?
Okay
clamp
If you google "unity clamp" you will see many examples
are you moving the whole object with the points?
clamp the maximum distance with a max and min value
https://docs.unity3d.com/ScriptReference/Mathf.Clamp.html
Of course. There are docs on all of it
You have google at your fingertips right now to find it
No, the code gets the Child(0) which is the Rhino
but now that you say it, maybe it weirdly changes into the parent object when the Rhino reaches the first point??
I'll try using a SerializeField private var for the Rhino
where are the Rhino points at
the hirerchy would nt randomly switch
thats why i said put logs in the code and see if the function is still running
yes im aware
put Gizmos on them
public abstract class FixedCollider : MonoBehaviour
{
public Entity _entity;
public ColliderShape colliderShape;
public Fix64 radius;
public Fix64 height;
public fv2 center;
public fv2 size;
is there a way to hide some of these fields for sub classes that wont use them? like a box or polygon collider wont use radius
you dont need render order for that
click the Dropdown next to the name and assign an icon u can see in the scene
i usually pick the diamond one
You mean this right
It already has the orange one, I thought they don't show up in the Scene
that's why I'm adding sprite with high render order
they do if gizmos is on
its not working but its not showing any error
sprite renderer has no differences on gizmos, they are completely different
did you not read the docs?
Clamp is a function that returns a result..
there was no example of scenario
what
it just showed a block of code abt animation or smth
its called an example
it didnt match my situation
do you know how examples work?
you look at them to figure out how its being used..
this is basic c# reading documentation is essential..
eg what return type the function has etc..
I'm not lol Just saying look at the exmaple , you said it "doesnt fit your usecase "
Not reading Documentation is like trying to use a device without reading the instruction manual
hes not being harsh
could you show where both points are placed
one sec compiling
caught the bug red handed
Thanks for telling me to debug again, I still have to think about how to fix this though lol
So it's not actually changing the Point
could I see some code?
Yes one sec pls
presumably the index part
but yeah debugging is the best way to find these little things
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
The immortal print statement
how do i find my debug log, im logging information to it but it's nowhere to be found
In the console
Make sure the toggle is not deselected on the top right
And if it is not toggled off, and you do not see the log, then that code is not executing
and i find the console where?
it should be open at the bottom of your screen
Go into windows at the top, go into panels, and click console
you can add as many as you want too
right click the bar where it says Scene
you can probably do Via Add Tab
3 dots button
@summer pilot Or you can click the blank space at the very bottom (which may or may not have words)
Maybe it is under analysis? Can't remember where exactly in the windows menu. Just look around if you go that route
does nothing
sorry the 3 dots, on the rightside
IT'S WORKING
If you google "unity console" it will of course tell you exactly how to get there
Check the other foldouts. Pretty sure console is under "General"
But there's not many to look through
Thank you @rich adder
Stop sending pictures. Just look through all the windows menus
it was there, than k you
Or google it
UX failure
i was already in this chat where people were willing to help me, why are you being so adamant about being a dick to me
Wow, rude. I was not. I pointed you where to go. Please do not call people names
Sending all the pictures floods the chat and makes it hard for others to get help
See #854851968446365696 and #📖┃code-of-conduct
Especially the part about trying to find the info yourself before asking here. It is a quick google
when there are others who are walking me through where to look, i don't need you sitting there telling me to stop what im doing and making me feel like im doing something wrong. 2 people were telling me exactly where to look as I am still new to unity in general, let alone their super confusing window UI
woah now, lets cool it
i was also already in this chat asking this question when people were telling me to access the console
Sending pictures over and over IS doing something wrong.
And I told you exactly where to look
I was the one who told you it was in the console, and to look in the windows menus.
But whatever, if you wanna be rude, just gonna block you.
Best of luck with everything. Please be nicer to others and grow up in the future, because this is not it
You are welcome for being the first person to help you and tell you everything you need.
whatever man
now that is true
is anyone able to tell me if this is correct? no debug messages are being printed when the objects interact and i dont see any issues with tags or colliders.
Put a log outside the if and log the tag of other
See if that prints
The Three Commandments of OnTriggerEnter:
- Thou Shalt have a 3D Collider on each object
- Thou Shalt tick
isTriggeron at least one of them - Thou Shalt have a 3D Rigidbody on at least one of them
The 3rd commandment is one I always forget
Yes
Because this is the 3D OnTriggerEnter function
ahh
You should probably be using OnTriggerEnter2D
How did IntelliSense not correct you
Because OnTriggerEnter is a perfectly cromulent function
It just isn't called by a 2D Rigidbody
works fine now, stupid mistake, thanks
Okay, well not auto, I press down arrow when the suggestions pop up
Why doesn't my collision detection work?
The Three Commandments of OnTriggerEnter:
- Thou Shalt have a 3D Collider on each object
- Thou Shalt tick
isTriggeron at least one of them - Thou Shalt have a 3D Rigidbody on at least one of them
lol
Thou is right, I forgot to check isTrigger
Keep in mind, this has no validation and will destroy themselves when hitting ANYTHING.
Figure it's a test, but just worth mentioning
I have a question
shoot
I want to create an Obstacle that moves this way
Sine
Well, specifically, absolute value of sine
on Y axis I presume?
DOTWeen has the jump ease
no, X
If that's the axis you want it to move on
That sees this exactly
Thank you, I'll check out both ways
I took the coward's way out. a false victory. a weakling's approach
but it works lol, just juggled parents & used the offset the same way I normally do, then put the object as a parent of what used to be it's child & restore it's old worldposition
I was so deep in the weeds trying to figure out the math I legitimately did not consider that as an option
it's a shitty option but it's better than it not working. Ideally I'd understand the math but ig my brain isn't big enough for that yet
How can I make a bullet shoot from a players position but not destroy the player? Is the solution to spawn the bullet just a bit in front of the player or is there another way?
I just mentioned that above
#💻┃code-beginner message
Validate the collision
Instead of just destroying literally everything it touches, maybe check to see what object you hit first
if (thing I want to destroy)
Thank you I saw your comment earlier but I just wasn't sure how to validate the collision
I also really wouldnt have objects just destroying other objects like this
Do I hake different bullet prefabs for the enemy because if I tell the bullet to not destroy the player than the people firing at the player can't do anything.
This is the only way I know how to as of right now but I'm working on getting better with the code.
Call TryGetComponent in OnTriggerEnter on a damageable script and say bullet hit, pass it some value, and that script will decide whether or not to destroy itself
Or have a bool on your script that tells it whether it is the player or not.
If not, damage player
If it is, don't
There are many ways to do it
Okay, the bool makes sense to me, I will try coding that and see how it goes.
Depending on the use case you could keep it as is, but it's usually better if you call a function on the object the bullet is hitting. Then the object can destroy itself if it's dead and also choose to play animations/sounds before being destroyed
i have a capsule as my player and it keeps tipping over since i have a rigidbody, how do i freeze the y and z coordinates of the rotation and keep the x availible
there's constraints on the rigifbody for rotation and position you can toggle
make sure you are not in debug mode, ive made that mistake 1 to many times 😅
i already have those on and it still tips over
Show your constraints
You probably want to freeze x and z
I researched the issue and it said this could be code related? Not sure what it means by type mismatch.
what type does it want its just an object with a script
ohh yeah i confused x with y
tysm
What type is the Money Manager variable
im trying to reference another script named money manager
type mismatch.. for example.. you reference a Coin.cs but instead u try to drag in a SodaPop.cs
Okay, and what object did you try to drag in? Show the inspector of it
Okay, and are either of the objects involved in this prefabs?
Prefabs cannot reference objects in the scene
so, unless ur MoneyManager is inside that prefab u can't drag a reference in like that
you need to set the reference on the instance in the scene after creating it
you need to assign it during runtime via some assignment in Awake() or Start()
or some other type of interaction between the 2
Its hard to remember all of these seemingly small things
Is Task.Delay the only thing for tasks that doesn’t work in webGl
Am I calling for the player position wrong?
No, that is how you get the position of an object.
But you're assigning the position to a Transform type, they're not the same.
Hello everybody, i have one question: Why I can`t see objects that are floating in Play Mode? I have position.z -10 and order in layers 1.
https://github.com/SpawnCampGames/Resources/blob/main/101/WebGL.md just a list i was putting together of WebGL limitations and whatnot..
i dont build in webGL very often.. but its something i been meaning to educate myself about
How do I fix it?
@topaz niche Go into 3D mode, show where the objects are in relation to the camera frustum
Transform and transform are different things
why does rb2d.AddForce not work on android build? It works in the editor
make it Vector3 instead of Transform I suppose
Don't try to store a square peg in a round hole
Transform is the <Type>
transform is the specific Transform the script is attached to
your FirePoint variable is a Transform. Player.transform.position is a Vector3. These are different types
transform.position <-- "this transforms position"
i am trying to make a jetpack kind of thing, it tried it with transform.position += ( code )
What is .Transform?
Thank you very much)
help me with this please 🙏
Firepoint = Player.transform ❔ ❓
why does rb2d.AddForce not work on android build? It works in the editor
i am trying to make a jetpack kind of thing, it tried it with transform.position += ( code )
HELP PLEASE 🙏
dude
omg that worked, sorry I couldn't understand a lot of stuff you guys were saying I'm not too good at coding.
i was just getting to you, chill
Firepoint is a Transform...
Player.transform.position is a Vector3..
Player.transform is a Transform..
You're going to need to explain what "not work" means
it just doesnt jump or fly
And what you're actually doing with it
show us code
have you tried to debug your build using LogCat
it clicks the button but it just doesnt fly
https://gdl.space/xejevaheso.cpp main movement
https://gdl.space/osalohatin.cpp detect button
so you've debugged the method and confirmed that the code is indeed running
the code is correct
cuz i tried flying with a different method, it works
just the AddForce doesnt work
You shouldn't mix force-based and teleportation-based movement
They'll fight with each other. You should use entirely teleportation or entirely physics
using force based in left/right isnt what i want
but using teleportation based on jumping is fighting with the gravity
#🏃┃animation would be a good choice, not a code question
alright thanks
Hey, I'm making a rhythm 2d game and I want to add telegraphs to the attacks, but the issue I've ran into is that I need to spawn the attacks on beat, rather than the telegraphs. Does anybody know whether async is better than using coroutines?
I've done it so that the telegraph spawns exactly 1 beat before the following attack does, and it fades in and out before being destroyed. The attack should spawn right when the telegraph is completely visible, and the only way I could figure out was using async or coroutines, but I'm not sure if that's the best solution
Personally, I would implement a data structure that holds information about when the note plays in the song, and using multithreading.
oh well I'm using Unity Events with double floats (x & y) to call the needed spawning functions, and I call the events when the note I need hits
What's the issue?
I'm not sure if using async is optimized well enough, and I'm also getting a bunch of errors when I stop the game before an attack is spawned
the errors itself don't really do much as when they appear the game is already ended but they still are a sign that I might be doing something wrong
Your script should either check if it is null or you should not destroy the object.```
Why are you using an int for the timer?
because that's what the Task.Delay() function takes in
Oh. Lol
that's actually the reason why I started doubting using async, as the resulted time in milliseconds comes out to be not as precise
for example: with a bpm of 128 each beat takes 0,46875 seconds to play, but the same value in milliseconds can only be represented as 468/469.
Yeah. That doesn't sound very precise
I'm just curious whether using coroutines would be a better solution to this
or if there's any other viable solution
Coroutines you can at least use a float
true
but then I need to start the coroutine in a separated function
and use that one instead
so it is quite odd to use as well
there's actually a bunch more issues I've had with the way I implemented telegraphs, but it would be too complicated to put in a single message or a screenshot
so I'm just searching for solutions from the rock bottom lol
That's all you can do sometimes.
not really a coding concept but i just want to ask; what is multithreading and why do we use it
to run multiple threads /s
CPU cores can only do one thing at a time, ever. Your computer seems like it is doing a bunch at once but it's actually just changing between them very fast.
Modern CPUs actually have more than one core, so each core can do a different thing. Multithreading is writing code that can run on multiple cores at once, letting you actually do more than one thing at once. This is generally not actually used in Unity, because UnityEngine functions only work on the main thread.
how do i use this or enable this?
outside of unity
i mean anywhere whatever game engine
Depends on the language
what about c++
thanks
btw Unity works with c# not c++
im aware, i dont use unity that often and im transitioning to c++ for gamedev so thats why i was asking
about things other than unity
the only reason i asked in this server was because quite frankly all the other servers are dead
why do some of the scripts not have an option to be disabled?
If the script has nothing that would be affected by being disabled, it doesn't have a checkbox
no code is dependent on it
So, if there's no Start or Update or anything, it doesn't give you a checkmark
right
is it possible to fill an entire array (hypothetically of a size of 3 values) without doing:
array[0] = blah
array[1] = blah2
array[2] = blah3
use a loop
the values of blah are gonna be different, that'll only help with the placement part of it
what are you trying to do exactly
I have 3 arrays that'll be chosen if an int is equal to a certain value (e.g. 1, 2 or 3)
I don't know if I can instantiate an array with built in values
use collection initializer syntax
what is that?
google it
that might work
arrayPlacement(1,2,1,comboChoice[]);
if I make a function that requires the input of an array would I implement it like this?
(comboChoice[]) being the array
I have no idea what this is asking
Coroutine iteration will be the same as your framerate, so it may be better or worse than Task.Delay() depending on the platform and framerate...
But since you can't really change your visuals faster than the framerate anyway, I would think to decouple the telegraph and the attack, and spawn each as close to their respective beats as possible. If you modify them such that you can set their states to specific times, you could immediately update each right after they're spawned in order to compensate for the delay between the frame and the beat - this way the animations and such should still be dead-on with the beat, and in the very worst case the player will miss out on one frame's worth of animation/effects
What are 1, 2, 1 here?
ar[0] = a;
ar[1] = aa;
ar[2] = aaa;
}```
mb should of included this
I'm having an error when inserting the array into the function
where it says I need to add a ;
You dont add [] when calling the function
Okay, so pass it three ints and an array of int
Thankssss
I'll try that
hey fellas. i've recently added some code to my game that runs upon firing a bullet. it's meant to pull the correct variable from the bullet prefab, and then add that force as relative force on the player. everything is set correctly in the inspector, debugging shows me that it's pulling the correct variable from the bullet, the code is definitley running, and no matter what number i use, no force is being placed onto the player. any ideas?
if (hit.collider == null)
{
Vector3 spawnPosition = transform.position + transform.up * 0.5f;
GameObject bullet = Instantiate(CurrentBullet, spawnPosition, transform.rotation);
Vector3 knockbackDirection = -transform.forward;
PlayerRB.AddRelativeForce(knockbackDirection * CurrentBullet.GetComponent<Bullet>().BulletKnockback, ForceMode2D.Impulse);
} else {
deny.Play();
}
Are you overwriting the player rigidbody's velocity in a movement script or something like that?
nope, player movement works by adding relative force as well
that was my first thought lol
damn. got no idea!
What object is this script on, out of curiosity?
it's on the BulletSpawn object, a child of Player which acts as an invisible point to fire bullets from
everything works fine, and i can't see why the knockback portion isn't working. quite odd
anyone have an idea?
how can i make my own version of ontriggerenter and oncollisionenter that would work the same way? like i just put it on anything with my own custom collider and it will send the message accordingly?
public void FixedTriggerEnter(FixedCollider other)
{
}
public void FixedCollisionEnter(FixedCollider other)
{
}
When do you want it to be called?
It looks like you're working in 2D... is transform.forward the correct direction? Wouldn't that move them on the Z axis?
When a collision / trigger is detected in my custom simulation manager.
can i send out a message or something?
oh shit, maybe it should be transform.up. ill try that.
But it's fairly slow, since it attempts to call that function on every behaviour on the object
you're the best dude, that was it. i really had no clue, thanks a bunch
If you could do a TryGetComponent and call it directly it'd be better
will do this. thanks!
use an interface rather than a specific component and you'll be able to implement it on any component
what so like ICollisionReciever or something
yep
within my simulation manager?
not sure exactly how to do it w/ triggers i use a raycast but thats the TryGet w/ an interface
just note that unlike using SendMessage which attempts to call the method on every monobehaviour on the object, TryGetComponent will only get the first component with that interface that it finds
ah that could be a problem
cus some things would have multiple colliders
This might be the one use case where SendMessage is actually preferred over manually getting the component
probs
i'll do that then
how does it work for ontrigger again?
only one has to be a trigger for it to be a trigger collision
You'd just call SendMessage on an object and it'll call the function with that name on every behaviour on the object
i'm curious what the purpose of all of this is. if you're just replicating how unity's physics already works, why not just use that? 🤔
because i need to do it with a fixed point number system to ensure determinism for my game
my code for knockback should be applying force correctly. it's -transform.up, so it should be in the direction opposite to what the player is facing, instead, when the player is facing downwards, this pushes the player downwards as well. any ideas?
I was kind of wondering about applying a relative force relatively... but I didn't quite think through it all. You might try swapping to AddForce though
you've done it yet again, dapper racoon. you are truly a light in the deep darkness of C#
thanks a bunch 🙏
are there any negative consequence from making a vector 3 nullable? Vector3? foo
Other than all of the annoyances that come from dealing with nullable types in general, probably not
Try using a Vector3? somewhere expecting a Vector3 and let us know if that is a negative consequence
I cant use Vector3.zero and the easiest solution I can think of uses a null value
can you give some examples of why it would be annoying?
can you describe your actual usecase
if i make something readonly how am i ever meant to set the value?
In the ctor
you would create a parameterized constructor to assign the values
right, thanks
When passing it to a function that expects a Vector3
and you need to check and unpack the value
a Vector3? click is assigned hit.point from ray cast against a terrain so long as the player clicks within the 'map bounds.' If the player clicks the terrain outside of the map bounds, a null value is set and a null check stops the command from being issued. Its the only Vector3 that needs to be nullable.
also bawsi im sorry if i was being a dingus earlier
Raycast returns a bool if it hit or not. You dont need to null check something here. Nullable is totally something you can do, but im not a fan. It's something you need to design around using
Honestly I dont even remember what happened, if anything happened.
i don't understand the need for that to be nullable. if you're going to be checking whether the hit point is valid or not, just don't issue the command if it isn't a valid point? why do you need a nullable Vector3 to not issue the command?
i was being a dingus, 
yea nullable overkill here
I could see it being useful if you're making some public vector3 and someone else was using this code. But in my own code I've never felt like I needed or wanted nullable
the terrain is much larger than the 'play area.' I'm checking the hit.point with bounds.Contains(hit.point) You guys would just recommend using bool isValidClick or something?
{
click = hit.point;
Debug.Log($"click = {click}");
}
else
{
click = null;
Debug.Log($"click = {click}");
}```
you're not really providing enough information about why that bool or the nullable Vector3 are even necessary
why are you not just doing whatever checks and stuff you need inside the if statement here?
what is the point of assigning a variable and doing the checks elsewhere?
hmm... when you put it that way
remember the KISS principle. don't overcomplicate things
yeah lol why would I ever not just check BattleMapManager.Instance.battleBounds.GetComponent<BoxCollider>().bounds.Contains(hit.point) instead of changing all these classes to accomodate a nullable Vector3. Damn.
or if the point is for other objects to be notified when a valid click happens, just invoke an event in that if statement intead of polling the check variable
accommodate a nullable
That right there was my biggest annoyance when trying them. It is essentially a completely different type. You start down the road of changing all your internal api, then hit the unity api which you can't change and need to make workarounds or conversions and it is just... so much more work than most other methods
This kind of things you learn by going over C# basics.
int[] a;
ik i already know other programming languages and didn't realize it was different in c#
Well, that doesn't change the fact that you don't know C#. If you know other languages, learning C# basics would be a breeze. Do it now before it's too late.
ik i learned a lot of it just skipped over arrays because i assumed they where the same
also my problme is i have an array
Perk[] PerkArray = {};
but i cant refrence "PerkArray" later on in the script
Yeah ik i was dumb T-T
i was getting impatient and bored
This is also probably due to missing the C# basics
try a List instead, probably simpler to understand
You'll need to share more of the code
just looked at that, that's closer to what im looking for
but don't forego what dilch said, learn the basics primarily
My character controller is Jesus. It defies the laws of Move() and gravity despite being !isGrounded.
Annoying problems:
- The radius is set perfectly for my game world. Can not make smaller.
- I can not change the skin width otherwise the controller susceptible to friction slow falling when hugging a wall.
- I do not want the player to be able to traverse
> 60 deg angledslopes.
You'll need to share some code as well
i checked microsofts documentation and in theory i should be able to do
PerkArray.Add(Whatever);
but if i try and do that it shows Perk array being non-existent
this is within a public class serializable class, which is in a public static class
I can show full script if needed
i checked the docs and that should work
You can see in the camera mini-view the player is visually well overextended.
I believe the Capsule collider is getting stuck on the curved edge as seen in the wireframe view.
@teal viper What part?
An array doesn't have an Add method and can't be resized.
this is a list
not an array
woops
the first peice of code is
List<Perk> PerkList = new List<Perk>();
this is the same as shown on microsoft's docs except instead of string im using my class, Perk
Share the exact error and the whole !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
What block do you want to see? How I Move() my controller? When gravity is applied? How I handle landing?
ok
Whatever is responsible for movement. Ideally just share the whole script.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class Globals
{
public class Perk
{
string name;
}
[Serializable]
public class Perks
{
List<Perk> PerkList = new List<Perk>();
PerkList.Add(Perk);
}
}
there's also some other errors but they are related to perklist not existing
That's another part of missing the C# basics. You can't call methods in the global scope.
And you can't add types to a list
ohhhhh
Unless it's a list of types.
void Update() {
// Check if player is grounded
groundCollisions = Physics.OverlapSphere(groundCheck.position, .4f, groundMasks);
if (groundCollisions.Length > 0 && velocity.y < 0) velocity.y = -2;
// Movement controls
Vector2 movement = playerInput.Movement.Movement.ReadValue<Vector2>();
Vector3 move = transform.right * movement.x + transform.forward * movement.y;
controller.Move(move * movementSpeed * Time.deltaTime);
// Landing
if (!isGrounded && !isPlayingSFX && Physics.CheckSphere(groundCheck.position, .4f, groundMasks)) {
// Land shit
}
if (groundCollisions.Length > 0) {
isGrounded = true;
// Dynamic movement speed
movementSpeed = isCrouching ? 2.5f : isSphereGrounded ? 5 : 6;
// Jump
if (playerInput.Movement.Jump.IsPressed() && !isJumping) {
isJumping = true;
velocity.y = Mathf.Sqrt(jumpHeight * -2 * -19.62f);
}
}
// Apply gravity and move player with bridge
velocity.y += -19.62f * Time.deltaTime;
controller.Move((velocity + externalVelocity) * Time.deltaTime);
externalVelocity = Vector3.zero;
}
@teal viper Here's the abridged version
In C#? I don't think so.
nooo
godot uses gdscript
and in gdscript u can make a list equivelant
and im used to u being able to add methods (or functions) to them
Ok, well I said multiple times, but C# is a different language. Go learn the C# basics.
ok ill read through some of that
On the first glance there doesn't seem to be a problem, so you'd need to debug it. Place logs or use visual debugging to see where and how much movement is applied to the character and where it comes from.
I'm telling you it is the character controller capsule collider itself getting stuck on the ground whenever the collider begins to curve.
If I disable my PlayerControls class the fucking wise guy just hovers there
well yeah, the CharacterController does not have built in gravity
sup
@slender nymph Wait a second you're right
i usually am
You only get gravity with a CC by default if you use .SimpleMove(speed)
@primal trench also think about what you're attempting to do there, a container of Perks inside hte Perk class, you add a perk and it too has a container of PErks too now. Typically a container goes outside of the class that it wants to contain
`void Update()
{
touchin = Cd.touchin;
if (touchin == true)
{
questbeing.SetActive(false);
fatbeing.SetActive(true);
fatsurround.SetActive(true);
fattext.text = "isudfhisuf";
}
if (Input.GetKeyDown("q"))
{
Debug.Log("q was pressed");
}
}`
three back ticks, not just one
Regardless of your point @slender nymph The guy's still hovering.
The PlayerControls and gravity are enabled
Yet that small enough lip is enough to carry his entire weight
is there a way to reset gizmo settings?
i'm drawing a sphere but it's turning out as an oval
let me guess, it's hovering about the CC.skinWidth above the ground?
so basically my problem is when the first if statement is done even once, the second just doesnt work almost like its stuck in the first if statement, even if its condition isnt met anymore
He's not hovering "above" he's hovering over the edge. He should be falling.
Yet that tiny contact point on the edge of the capsule collider is enough to hold the entire player up
the CC's capsule collider has absolutely nothing at all to do with your ground check since you do that manually with the OverlapSphere
use the physics debugger to visualize your overlap sphere so you can see how large it actually is
The player is NOT grounded when this issue occurs
If I position the player any further over the edge the built up velocity from "free-falling" shoots me down
then your capsule is too wide or your ground check sphere is too small. they should have the same radius considering the CC's collider coming into contact with any object during its downward motion will stop that motion. just like any collider that is large enough (in any way) to be in front of it at all when you move forward would stop it
and of course you have to consider the skin width of the CC for collisions
I can not change the skin width or the player radius for the reasons outlined in this post.
the only reason you gave for the skin width was related to how you do your ground check and apply gravity
Changing the skin width does not effect the results of the issue. I have tested with above, below and equal to 10% of the radius.
okay well at this point i've explained why your issue happens. so you can either correct it or not 🤷♂️
My capsule and ground check radius are not incorrect. I have tested this.
And yes I consider skin width in the positioning of the ground check
well then i'm happy to hear you don't have an issue
ok after reading and watching some videos i think i understand better now
thx for the advice!
Maybe a bit too fast to get ahold of the basics, but glad you got it.
i already knew some of the basics, just never got to arrays because i got bored and overconfident
sorry for being stupid to u :p
sure, but again if there is any collider that the CC can collide with below the CC when it moves downward and its collider would collide with that (taking into account its skin width as well, meaning your CC is effectively 0.58 units wide, not 0.5) that will stop it from moving downward
i genuinely do not know how i can be more clear about that, colliders in its way stop the CC from moving because that is what the CC is meant for
having trouble dragging my text script into my score text so it would show me the position of my cube the further it goes but it wont let me drag it and put it in there
what type is the field. I cant see shit from these cropped photos..
if you are gonna crop at least make it make some sense.
If Action is the void return type of delegate, do event delegates exist since event actions exist?
it wont let me drag it into there
thats right, the types don't match
Do you see It says Text
yess
yours says TextMeshPro UI