#💻┃code-beginner
1 messages · Page 716 of 1
Ill give it a try, thanks!
i want to know something, if ther ewould be something like a lot of bools, how would i go on to globably make them public/private when in need for example?
i understand changing each one, but is there some c# thing i dont know?
Not reproducible with: 2022.3.61f1
but.. that's the one i'm on.. what...?
well they said they couldn't reproduce on mac silicon either.. and it is pretty transient, so... 
not reproducable with?
it means they didn't find the issue on that version (meaning it was introduced in a later version)
sorry Im really tired rn and I may not get a few things ahah--
Just try to use them and if it says that it's inaccessible let the IDE auto complete change it
ohh
but i mean.. this issue is transient so maybe it just didn't happen....
peak cope rn lmao
huh???
no im saying like
it would be funny if that was true though. like, an "FU in particular" moment since Im a single patch beyond that
you would generally use properties for exposing those
being able to make the private/public
yeah it was found in .62
is there any docs for that
look up "c# properties" and find the result from microsoft
also, if you want to change multiple lines, most ides support multicursor
try looking that up for your specific ide
You already have them private. If you end up trying to use them elsewhere, your IDE can make them public for you
nono thats not what i mean, i mean something like going into a "debug" mode, and when u do that then all of these fields are shown
(shown in editor via serialize field ig)
[SerializeField]
oh
why unity...
you can just use debug mode in the inspector for that
so you don't have to actually serialize them
why must you do this to me... uhh idk 2023 time probably
2023 is alpha/beta only, the public release of 2023 is 6
I have an object that has a script on it that references several objects in my scene. Whenever that object is added to my scene, I have to manually drag and down the references via the inspector. This is a problem as I want to instantiate the object. Is there a way for me to have it so that I don't have to manually add the references each time?
if it's the same objects that only exist in that one place, you could use singletons
or you could receive the Reset message to initially set the reference with like, Find or something
Yes, but some of them are also references to other scripts on other gameobjects
probably not Find
not sure why that prevents them from being singletons
I want the player to be able to change weapons but instantiated different weapon prefabs. Would Singletons work for something like that?
Like, the player finds the gun on the floor, picks it up and equips it
could probably use SOs for that
What are SOs?
Okay, interesting idea. I've never used Scriptable objects before. Trying to learning how they work
So, say I had a weapon slot on my player, I could use a Scriptable Object to define what weapon it is, and it's features when it's picked up
Theyre basically inspector viewable/editable objects whose life isn’t tied to the execution instance. Like a prefab without a gameobject. So they kind of just store data for you and can be viewed / edited in the inspector.
How could I use them to help me achieve what I want?
Have a class of weapontype that inherits from scriptableobject
Then you can make a bunch of those, give them names and data and whatever
And they define your weapon types
A variable name, straight from hell:
TextComponent_FromInputField[Parameter_AreYouSureDelete_WarningPanelSCRIPT.SHAREVAR_WelcherDeleteButtonVonDennGanzenSaveslotsWurdeBetaetigt].text = ""; //UI
its long and the only part that is colored are these "" symbols.
Shortest German Word Award:
Do you understand it?
No I just know that German has very long words
I don't even actually know if that's German
but it kinda looks like it. I suppose it could be Dutch?
It actually is.
My "special" and weird methode to name variables in Germlish.
Is it possible to define where an object is located in space using scriptable objects?
I have muzzle flash that I want to always be on the tips of my guns but the guns are different sizes
SOs don't have positions. Ideally, your muzzle flash would be at the position of a specific child object that is part of each gun prefab
The SOs probably wouldn't have anything to do with it
Can I load in a prefab using SOs?
Yeah, your SO could reference the prefabs just fine and your object could get the reference from there
So if I understood correctly, I'm making an SO which I can then use to define each weapon, then they can be called from a script?
digiholic i tried to understand what to do with the information i got earlier regarding the prefab existing before the manager object
i couldnt
so i took a break
may someone help me pls?
i got this issue in my console after a long time scripting my npc dialogue system, but the thing is, before i start making this the whole player movement script was working perfectly and the body type is Dynamic so there is no reason to that happen
i cant establish a connection between the prefab and the manager SO in start() {
What is Player.cs line 61?
void OnMove()
{
rig.MovePosition(rig.position + direction * speed * Time.fixedDeltaTime);
}
Add this line right above the MovePosition:
if (rig.bodyType == RigidbodyType2D.Static) Debug.Log($"GameObject {rig.gameObject.name} has a Static Rigidbody!");
Then run it again and look at the log right above that warning
So, at the time this runs, Props has a Static Rigidbody
How can I apply a Scriptable Object to a gameobject?
So the player picks up a weapoon, how can I change the values in my Player_weapon script to make the game behave differently?
You'd create a variable of that SO's type and drag in the asset file you've created
And then you can access that SO's data from that reference
Do you mean make a variable of the SO script or .asset file?
Make a variable of the SO's type
and then drag in the .asset file into it
props is a game obj with a tile palette to place some structure on the map, so isnt it supposed to be static?
If it's supposed to be static, you probably shouldn't be calling MovePosition on it
the player mov script was not even supposed to do something with them
I'm not sure what you mean by SO's type
its not
public class __________ : ScriptableObject
It is though
that's what the log was for
You put it right before you called MovePosition on rig, and logged the name of rig.
That turned out to be Props
So, you're calling MovePosition on Props
Can I rename my .asset file or will that create issues?
You can call it whatever you want
Since I'll have a different .asset file for each weapon, I'd like to name them after each weapon
It's still the same type
When trying to assign a MeshFilter to my SO asset file, it says "Type Mismatch"
Didn’t some guy make all his variables out of scriptable objects so they could be assigned in the inspector? I think there’s a talk about that.
Assets cannot reference objects in the scene
that's terrifying
No that shows up when the old value is incompatible with the current field type
e.g. Changing GameObject to Texture2D
i just checked and i had the player script in the props gameobj
tysm
that also shows up with a scene object in a prefab
It also shows up if you try to drag a scene reference into an asset
huh well thats not a good description is it
It's somewhat recent that it does that I believe. It used to just silently fail
Doesnt it usually just do nothing or change to None?
It used to do nothing
Im stuck on 2022 so perhaps i've never seen the new way 😆
But now it shows "Type Mismatch"
Is it possible to load a prefab from an SO?
Sure, Assets can reference other Assets just fine
It was an interesting idea…. Instead of doing some coding shenanigans to hook up variables to ui, you could just drag and drop the SO into a UI element
Just not scene objects
How can I reference a prefab in script?
It’s a gameobject
It was a GDC thing, they used SOs to store "global" data for a game session. It's a pretty old one though
And you need to make it public or serialized it. And then drop it in in the inspector
Make a variable of the type you want from the prefab and drag it in
Any component on the root object of the prefab is fair game
it'll still spawn the whole prefab
Today in my ted talk i'm going to show how I horribly over complicated my game for no reasonable benefit
By "pretty old" I mean, like, predating UGUI old
So you didn't have access to things like UnityEvents and other things that could actually do this reasonably
you can easily make do without unity events with alternate design
but i get those without experience may not be able to implement such things
This was a time when UI needed to be done with 100% code
There were third party solutions back then, I started using unity pre ugui
Being able to assign anything in the inspector for the UI required such roundabout solutions
hm well i make do without using unity event subs in the inspector for my UI
Was it really that old of a talk I don’t even remember…
Okay so let's say my player picks up a weapon, how do I change the values on the script on my player to those that are defined in my scriptable object?
I think you need a basic unity lesson
you generally would not, you'd just use the values the SO provides
I know I can reference the scriptable object in my player script (I think), but what about when I pick up a different weapon?
you would reassign the SO reference
But how do I input those values into the script?
you don't
Like just asking a bunch of questions here is gonna be less efficient than trying to build something that forces you to learn the basic knowledge
I'm trying to build 😭
You'd have whatever object represents that pickup reference an SO asset that holds the data about what weapon that is
I kind of feel like SOs are intermediate knowledge that at least require the basics to be understood first
why's the button not working only on this scene? I copied the prefab on all the other scenes and they all work normally
https://streamable.com/29zvei
the difficult part is not setting up SO , is to have a container object , a structure that can utilize SO
Could you share the !code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ChangeScene : MonoBehaviour
{
public void MoveToScene(int sceneID)
{
SceneManager.LoadScene(sceneID);
}
}
Is the button not reacting at all to your mouse? Like no color transition etc?
Can you show the inspector for the event system in the not working scene?
This isn't that hard? Or at least wasn't for me when switching from public instance classes to SO's
the whole workflow is easy to intermediate i believe
Also sorry not to judge but you're swapping scenes for settings?
One of the following most likely:
- Blocked by something invisible
- No Graphics Raycaster on the canvas
- No raycast target graphic on the button
Yeah i think i would agree someone that's got no clue how OOP works would struggle.
no reacting at all & inspector of the event system
i'm swapping scenes to show that the same prefab is working on other scenes
What's this base input script
before i learnt SO , i tend to make monster objects one prefab by one prefab , setting up all stats , meshes , materials one by one
but after i learnt SO , i will make only one prefab as container , and a lot of SO to carry each monsters data
idk it's there when i click create scene, it's there for all other scenes
See what shows up in that window at the bottom under "Selected" when you hover over the button
Can you check if the input module in the other scenes on the event system is the same?
and then on init() , i will extract the data and apply to the object
thanks guys, turns out it's just the text box covering it
(idk why it works on other scene normally but it is what it is i guess)
hi
Here you can see a list of every method and property available on the GameObject type.
https://docs.unity3d.com/ScriptReference/GameObject.html
As you can see, there's nothing named text on it
alr thanks dude
yo guys i am new here on this discord and i dont find and Helping channel so i have an question
!ask 👇
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
Okay thank you
Pardon me, I have a question
I have a player controlled by a character controller; I want to implement inertia into their movement (so that, when the player changes movement direction, they keep going in the same direction they were going, decelerate while their direction changes, then accelerate normally)
I have already implemented acceleration/deceleration with C#; how can I implement movement changing inertia of the type I described? (Preferably without using a Rigidbody component, as I hear that using one of those with a character controller causes them to conflict with each other or something)
You're right that they conflict, but since it seems like you want some physics-based movement you should probably use a Rigidbody instead of a CharacterController
Perhaps you're right
Before I switch, though, do Rigidbodies support features like stepping up onto short surfaces and not rolling down slopes below a certain angle?
No, so I guess you'll need to decide if you'd rather deal with manually handling stairs or manually computing intertia
Since you can't really get anything that does both
u just keep up with ur momentum.. when u release the input it takes the last velocity and lerps it to 0
my CC has momentum + sliding i can show u some code if ur interested in how i did it
Yes, that would be helpful
k gimme 1 sec
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
alrighty.. so im sure ur aware ur only supposed to use the Move() function of the CC once per frame...
soo what ends up happening is you construct a finalVelocity and put that into the move function..
meanwhile ur modifying that finalVelocity all the time..
if ur putting inputs into it.. it calculates that.. adds it to it it..
if ur not using the inputs it takes the last velocity it has and lerps it down to 0 by a smoothing or dampening value
for mine is basically 3 vectors (a grounded vector, a airbourne vector and the jump)
the reason theres 3 is because i have different dampening values for each.. (say ur grounded ur momentum stops pretty quickly.. but if ur in the air.. its alot slower) this allows me to kinda change directions in the air.. or slow down my forward velocity if i overjump or something
basically i have Lerps (which are wrong to be honest) i should probably end up using MoveTowards() -> 0 instead
but when im not giving it input its constantly taking the Vector i last had and slowly moving it towards 0
same for being in the air..
those two vectors are just added together and given to the Move() function of the CC
soo i can control them individually..
you can watch the vectors in the inspector.. and see how its working.. (while im giving it input its basically my movement speed..) but as soon as i release the keys.. it goes from where it was when i released -> to 0
I think I get what you're saying, but if I do, then I noticed a problem
If your code "constantly tak[es] the vector [you] last had and slowly mov[es] it towards 0" when "[you're] not giving it input", then it wouldn't help with my problem - I want to make it so that, when I change direction immediately after going in another direction, the momentum carries the player in the old direction before slowly changing to the new one, making the movement less "snappy" and more realistic; if your code only lerps the velocity towards zero when not inputting direction, then it's functionally identical to the working deceleration code I already made
i get what ur saying.. but that can be changed to work out...
right now my airbourne vectors and stuff does that
if im running forward and i jump.. and i instantly press backwards.. my input first has to cancel out all that forward momentum.. b4 beginning to move in teh backwards direction
airVector = Vector3.Lerp(
airVector, // ← your *existing* momentum
airVector + airControlVector, // ← new input stacked on top
characterSettings.airControlStrength * Time.deltaTime
);```
airVector That’s your previous frame’s momentum.
Every update, you don’t throw it away — you start from it.
By "momentum" here, we mean velocity?
yes velocity..
see when im dampening it ^ im actually creating a new vector for the new input.. and adding that onto the old vector
and then when i become grounded i zero it back out to zero to start over again
like here
this allows me to have a jump that i can control but not entirely.. i dont want it to instantly snap the other direction.. u must overcome the old vector first...
that said... my code isnt perfect.. i just figured it'd give u some hints or tips on how to do urs...
Thank you
Let me try implementing that
good luck friend 🍀
im actually gonna try to clean up my code a bit as well.. now that i have it open and ready
but its basically all about caching vectors. inputs.. keeping what u need discarding what u dont.. and combining pieces to get ur Final end vector
Hello everyone, I am trying to create a spell that spawns a boulder that rolls and does damage in the battle scene. When I just put the prefab in the overworld it rolls just fine, althought when I try to use it as an ability its not rolling and giving me an error
*** BOULDER START: Initialize() never called, using defaults. ***
UnityEngine.Debug:LogWarning (object)
BoulderProjectile/<WaitForInitialization>d__43:MoveNext () (at Assets/BoulderProjectile.cs:219)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)
is this something that someone may be able to help me with in here?
This appears to be a custom message you've written into your script. Look at where you're printing it, and check what the conditions are that caused it to print
probably copied without knowing what its doing
I am using claude to write the script am I cooked?
lol.. well-done
its worked fine for everything else actually, just not able to fix this issue 🙁
damn clanker
Yes
You should actually know what the code you're putting in your project actually does
when the skynet transition happens it'll be getting guys to code in trojans and viruses into their own codebase
Haha I hear you, this is a side project ive been working on. I have tried to learn coding and still not at that level yet.
i got an idea.. ask Claude wtf it did..
give it the code.. the error.. and tell it what we just told u
see how it responds 😄
just takes time.. and trial and error
small steps, build the knowledge up. All it takes it time and commitment
I have 30 times literally for 5 hours, asked chat gpt, asked grok
the lesson here is you wasted 5 hours eating slop
then yea ur probably cooked... u might can pretend u didnt use AI and have someone help u debug it properly..
that 5 hours could have been spent actually learning
but AI has a way of completely fubar'in itself 😅
Hey at least I was being honest lol
Didn't realize it was frowned upon
true..
its not really frowned upon as a tool.
but once u start using it as a tutor.. and not knowing how to troubleshoot what it tells u
ur indeed cookin urself
its absolutely frowned upon as a tool
I have fixed alot of issues myself, just this one I haven't figured out yet
how do i access this? in code
meh.. i disagree but each their own
it's literally banned as a way of giving people help here in this server
myButton.OnClick.AddListener
you press the + (chose the script/gamebobject) and use Public Functions
helping for ai created script is banned?
or add listeners ye
thanks!!!!
helping via providing ai generated solutions
but asking for help with ai generated code often is met with tumblweeds as people are pretty uninterested in helping fix code you dont understand
no its not.. if ur willy nilly copying and pasting yes... but again as a TOOL.. if u validate and confirm its results
this is not true
its a waste of everyones time to debug AI generated code if you don't even know the basics though
every solution/explanation would be lost in translation
theres nothing wrong with using it.. ive seen vertex say the same.. (if u post w/o knowing its true.. or confirming it actually works.. yea thats bad)
people constantly use ai without confirming how it works
that is how people use it
are you passively or actively ignorant of that fact
I apologize, did not mean to open a can of worms, just needed some assistance
im just pointing out a blanket ban saying yea AI is completely banned.. is passively or actively being ignorant as well
the solution is you really just need to learn tbh
no shade
no shade indeed.. i dont disagree with that
ai usage like that will just rot your educational growth
lol.. ur good 👍
who knows where it even copied that LogWarning and why it never told you it might fail and how
apparently it expected an Initialized() method to run but never did , whatever that means
can u show the code? im kinda curious on what it actually wrote
Just curious, is my whole game just going to be shit because I use claude? or is there any hope whatsoever?
start trying to understand what it is ur writing now
there hope if you slowly ditch the ai slop
Writing code is easy.
Reading code to figure out how to fix a bug you didn't write is significantly harder.
its a steeper curve in the beginning but after a while you're literally writing mostly the same code, just used differently
By AI Generating code you've essentially ensured you'll spend 10x as long trying to fix it than it would have taken to just write it correct in the first place
I have been using AI to explain it if that helps
It doesn’t tbh
If it was capable of explaining it it wouldn't have made the problems in the first place
it will be like using a calculator to always do 5 x 5 but eventually you forget how to even do such a simple thing in your head
Next time ask it how may b's are in "blueberry"
Not "ensured," but yeah, the odds are quite high.
lmao.. is that still a thing?
It is now even more confident there are 3.
epic 🔥
The good news is if you genuinely did spend 5 hours trying to bruteforce ai generation that's probably a good sign that you can shift that effort into real troubleshooting and programming
Yes I am on version 33 of the script
I wake up at 5:30 to work on project before work
lol.. someone manually had to go in there and change it 💯
I have faith you can skill up friend 🙏
thats what i try to do..
hit up c# courses like the gym. at least an hour a day you'll be making good progress
after work im just burnt out
some of those phone apps are pretty cool at teaching the basics
I have 4 kids we just had our 4th just no time after work have a small break right now
u can learn about strings while taking a big sh*t
lol.. lord help you 🙂
im an uncle.. thats good enuff for me
Entirely possible. This went viral about 2 weeks ago so they had time to probably hard-code in a fix for this specific question.
https://bsky.app/profile/kjhealy.co/post/3lvtxbtexg226
beginners trying to understand why passing a string isn't based on reference but also they can be null
I have designed every aspect of the game, just trying to code the structure now
similiar to pokemon in a sense
some people have the exact opposite problem
they can code really well.. but structuring a good game-flow is harder
Not to throw out any doubt at all but just worth noting a lot of design tends to drastically change once you can actually play it
It's why a lot of prototypes tend to not have everything designed from the start
I understand, the core battle system is fun for me at least, different than pokemon
ya, i come up with game ideas all the time... but even when i try to keep them super simple (down to 1 or 2 pieces, only a couple of mechanics) once u start fleshing out the entirety of the game.. u get into balancing.. and thats where i fall off the deep end
better with unity editor now at least
Playtesting will confirm or deny that 😄
I don't disagree at least i am trying
Absolutely
the fact that ur here.. and listening to real people is a step forward 😉
yes, agree!
and always try to keep things in bite-sizes
even if u know how the full mechanic/system is gonna work
its best to do a little and test Thouroughly
and then do a little more.. and build up pieces u know work
you mean byte sized?
ok..ill see myself out now
much easier to debug an issue that happens that way
badum tissssssssss
Thats exactly what I am doing, the other abilities work great I have made so far, just this one having a little issue
thats actually good to hear
atleast ur not like "i built this big ass system that consists of 12 classes and now the entire game doenst work"
I test everything when I implement it and also test to ensure everything else is working
happens more often than i care to see
btw can you show the code , just curious what exactly it was even trying to do anyway
true.. use a paste bin and share what u have
no ones gonna wanna sort thru a bunch of AI garbage.. but if it isnt too bad.. or something simple someone can help point u in the right direction
mr president another ai generated invoke has hit the channel
we can tell you how to write things better, please don't ask us to teach you how to slop better 😛
I can take it I am thick skinned so will continue trying until it works
explain everything to me along the way tends to help weed out really dumb things.. but yea
Also like unironically once you get comfortable programming it's just gonna be faster than constantly rerolling ai shit
Probably lol, I will work on some courses as well
Will i move slower when my cameraObjects forward is to the ground? since there are ground colliders, my character cant go in y while grounded but if i look downwards, my total magnitude of moving vector wont change but since i cant move in y axis, that means i will only move on z axis and it will be lesser than if i were to look in z axis ( might be hard to understand since i couldn't word it properly sorry)
movementDirection = (cameraObject.forward * inputManager.verticalInput) + (cameraObject.right * inputManager.horizontalInput);
movementDirection.Normalize();
movementDirection = movementDirection * moveSpeed;
hello community
from what little i see i would say
why not create a Prefab of a rigidbody that u could use (with the values set up already)
and instantiate the rigidbody gameobject instead of Adding a Rigidbody.. and trying to configure it all in script
so u could have a different prefab set up for each kind of rb ur going for
That is exactly what I thought was happening lol
im working on this beginner course and for some reason the ai nav mesh agent just stops following the player after it reaches a certain distance in the players range
I have the boulder prefab made with the projectible component and rigid body set up on it
im just speculating.. but it seems like the Awake setup all that jazz seems too much
Thank you! I will go back to work on that
u could just have prefabs set up for different Variants of the boulder instead
do you think it would be something in the code or through unity?
cause it was working perfectly and then after i added this new part of code it just started acting different
I will show you a little preview of one of the monsters
also dont be scared to use Debug.Logs() in ur code..
after u write them urself..
ai slop all around
how should we know . we're not mind readers, without showing anything related to setup what context can we go on ..
// do something in code
Debug.Log("I did something in code");
// else do something else in code
Debug.Log("I did something else in code");
float myFloat;
Debug.Log($"My float should be: {myFLoat}");```
Appreciate it
^ if u work like that as a beginner it really helps
esp when something breaks or acts like it shouldnt
idk just based on context mb let me go into further detail
u can kinda catch it along the way while watching the console window
ok so this is both for the code and on unity
ive tried asking chatgpt but its telling me run this debug script and when i paste it comes out with 7 errors
maybe should i try debugging?
u should 100 percent try debugging like "All" of the time
that should always be the first step..
i dont even know how to debug in this scenario
regardless if its working as u suspect or not lol
what did you add that broke it
bro i started like 3 days ago chillax
this piece hold on
seemed pretty chill statement to me
If you are making a spawn boulder and roll x amount ability projectile, how many lines of code should that take?
how do i do this
nothing here should be affecting the navmesh agent, it probably stops entire playmode if you have an error
what do you recommend i should do?
did you check the console window when it stops ?
not sure exactly what u mean.. but u can spawn things using their script as a reference...
public BoulderScript boulderPrefab1;
public BoulderScript boulderPrefab2;
public RollXScript rollXPrefab;
void Start()
{
BoulderScript myInstantiatedBoulder = Instantiate(boulderPrefab1, transform.position, transform.rotation);
myInstantatedBoulder.certainValue = 10;
RollXScript myInstantiatedRollX = Instantiate(rollXPrefab, transform.position, transform.rotation);
myInstantiatedRollX.certainValue = 10;```
sorry i dont know what that means could you explain?
so i could instantiate boulderPrefab and immediately afterwards i could access it to change any values from it i needed to
which part ? Do you know what the Console Window is ?
Got it!
no not really
how ever long it needs
ok 1 second
ok i have it opened its saying this but i feel like its irrelevant from my issue no?
instantiation in Unity is one line, and setting values after spawn is another 1–3 lines.. it all depends on what all u need to set up determined by whats dynamic on the prefab.. and whether the default values need changed at all
thats y i was saying.. if ur code only spawning a few different types it'd be easier and more scaleable to just have a handful of different prefabs already set up the way they should be..
then they'd be little need to change things around after the Instantiation.. but guy was right. its just however long it needs to be
Makes sense thank you
errors are always relevant
that'll do it
if im driving down the highway and a car crash is infront of my lane the car crash is absolutely relevant to me
💔
how do you know they are irrelevant and whats wat, you only seen 4 out of 999+
theyre all the same message
select it and check the stack trace
-
ur script probably should check if things are null before u try to use them...
-
don't try to change values or call methods on things that have already been destroyed (therefor becoming a null reference)
no 2 is not always correct blah blah fake null
Hello, sorry to disturb but I have been having an issue in a 2d platformer game that I am working on where every time the player interacts with a collision, their position will be slightly different. I already vaguely know what could be causing this but I do not know how to stop it. The x axis glitch happens because I used Input.getAxis instead of Input.getAxisRaw making it so that the player moves and stops at varying speeds and possibly providing slight lag??? And the y axis glitch comes from my velocity calculations which probably is because of time.deltatime making it stop at a different location every time I think?? May I please request some help with fixing this behavior so that it always stops moving at the exact same location?
I would not be using Translate for any of this..
rb.AddForce(new Vector3(0, FlightThrust, 0), ForceMode.Impulse);
Should something like this be situated in FixedUpdate or Update????
Update if its impulse is fine
i remember something that already was multiplied by delta time but cant remember
I should probably add this, I do not want to use rigidbodies for this script
what wouldnt be fine? velocity change?
anything that moves over a series of frames
Oh, I forgot to add it as well, this is all in fixed update
actually reminds me of one edge-case i cant really recall. but im sure it had something to do with lists, for loops (collections) of some sort.. and if u destroy during a forloop you should instead liek collect all the things that need destroyed and destroy them all at the end of the loop.. but im having trouble remember the specificities of htat
googled it a bit and i think something along the lines of "Deferred Destruction"
unsafe to modify a collection as its iterating... instead of
Destroy(enemy); //or
enemies.Remove(enemy)```
```cs
foreach (GameObject enemy in enemies)
{
if (enemy.GetComponent<Health>().IsDead)
{
toRemove.Add(enemy);
}
}
foreach (GameObject dead in toRemove)
{
enemies.Remove(dead);
Destroy(dead);
}```
wait im gonna search the docs and come back if i dont understand, one sec
defacto is always in FixedUpdate. If its a 1 time frame thing like impulse (think like a jump) then yea Update is fine since it only happens once
honeslty no idea what the difference is
no its not its a jetpack
thanks for the help but as I mentioned previously, I don't believe I will be applying any of this to my project unless there is absolutely no other way of stopping this. It's a personal thing where I just don't want to rely on rigidbodies for my movement systems, I rather just make one from scratch instead since I feel like I would learn more transferable skills by doing so.
love that bg music 😄 so calming
one simple way i think ive seen is to use raycasts or something to cast to where you'll be the next frame and if its within a wall or a collision u do something else..
a friend got me to play that with them while coding...
Any chance your getting confused between rigidbodies and character controllers? Unless your studying some fairly heavy programming/non game dev programming/math stuff i don't see a reason why you'd wanna avoid rigidbodies
can i move here -> yes -> keep going
-> no -> do something else
"ill implement my own physics simulation!"
💯 hell ya..
im working on translation / collisions atm myself
i saw this really cool video about how some games just project velocity along walls and stuff and take the total length of the vctor and just redirect you until its used up
How to make actually decent collision for your custom character controller. Hopefully you find this helpful and people will finally stop saying "jUsT uSe DyNaMiC rIgIdBoDy!!!1!!11!!"
Chapters:
00:00 - Intro
01:09 - Algorithm
05:11 - Implementation
Improved Collision detection and Response (Fauerby Paper):
https://www.peroxide.dk/papers/collisi...
this is it.. collide and slide
yeah!
I saw that a bit earlier and I should definitely implement that but I wasn't sure if that would completely fix the issue
Not sure why that comment got deleted
wrong reply
Just a word of advice you can take or leave it
I would strongly suggest getting this prototype working with rigidbodies in a "complete" state then swapping to your own implementation after the fact.
actually right reply and I panicked
alright
I'll try that in that case
It's probably gonna make life a lot easier for you since you will have the majority of the game functional and can slowly swap out chunks from that point
maybe I could just use rigidibodies for moving the player but the gravity system can stay
always ask yourself , do you want to make a game / some functional to get going or spent months rewriting whats basically done for you just to "learn" it and possibly come up with something worse
procrastination at its finest
lol... they should make medicine for that
oblong wheels
lmao yes! forgot about this
perfect analogy when i go to build character controllers
still gotta work in the bouncy, spring raycast CC soon
aw fry go poof
just wondering, when would you use transform.translate in code?
very simple movements that don't need to be physically accurate
alright
Can you please help me understand why we use local for the second one and also why not use local for the first one
rotation = Vector3.zero;
rotation.y = lookAngle; // rotation around y axis
targetRotation = Quaternion.Euler(rotation); // Quaternion.Euler(0,lookAngle,0)
transform.rotation = targetRotation; // transform.rotation = Quaternion.Euler(0,lookAngle,0)
rotation = Vector3.zero;
rotation.x = pivotAngle;
targetRotation = Quaternion.Euler(rotation); // Quaternion.Euler(pivotAngle, 0, 0)
cameraPivot.localRotation = targetRotation
like animations, tweening is okay usually
i use it for environmental stuff... gears rotating, hydraulics flexing and retracting, tumbleweeds rolling away
but yea things that dont need physics
understood
like the train in GTA5
is there any benefit for using the character controller instead of rigidbodies?
its gonna train itself across the map no matter what gets in the way 🤣
u have total control..
yes you get a kinematic controller out the box with collider detection out the box, easier to work with
stairs
it comes with stairs built in
Rigidbody are usually dynamic, hard to work with / control.
Kinematic is good to start a controller with but you need to make your own collider detections with something like rb.SweepTest
i use it to learn from
I think I will depart now with this wealth of knowledge
🍀
oh my gosh, it's almost 1am
day is young lol
suppose so
I think the guy that made this turned it free because they got hired from unity now they make charactter controller for ECS
wouldnt doubt it.. super solid implementation
albeit a bit complex
but i cant make a simple kinematic cc so more power to em
I'm sure it took years of revisions haha if they got hired to make something as complex for ECS
I modified this package for a 3d platformer prototype where you could pass in functions that return velocity in order for the abilities to have a cool easy way to influence movement
was really fun to play with
its very well documented too
this is a close second... (i had it when it was paid asset)
ya, any CC that allows me to create simple Knockback and influencing forces is a win in my book
pretty straightforward to make basic movements any way u go..
but external forces acting upon them is a total different scenario imo
One thing I could never get right on CC was Elevators Up / Down
platform moves and creates weird studder
ya, i tend to make it a cutscene type situation
make an orbital cam attached to the elevator for the duration of the ride
i dont know if not implementing the mechanic counts as a solution 😛
I seen some games they seem to switch controller to a non-jumping thing, probably one thats "glued" to surface of elevator
ya, that'd work too gravity/jump be the big issue
its also much easier to code a CC to go down an elevator than up an elevator
I tried using a kinematic platform and even with syncTransforms the CC just couldnt catch up properly
make a trigger flip the world and have the elevator go down to get up
lol
i've only ever used Kinematics for elevators.. gotta pay for that feature pretty much 🤣
i wasn't a big fan of how this one does it tbh, it is flexible in implementation but it kinda didn't feel that way
ive gotten my CC to work on a swaying pirate ship pretty convincingly but it was a slow sway
I think ideally I like the idea of just directly using transform parenting in some way or form
if it were too much it'd still jitter. just found a sweet spot where it didnt.. but yea thast just avoiding the problem still lol
even if i maybe use a dummy object and a parent constraint or smth
i agree.. the manual is a godsend.. just apply forces to the Motor
thats pretty much how I do it, CC enters platform with trigger then it parents CC to platform
when player leaves trigger it unparents from elevator platform
but i had 1on1 help via his discord.. so wasn't too hard to figure it out
thats how the Pirate ship functioned too
this can be abit more of a pain in networked environments
there was a bit of a transition problem when u jumped out of the collider as the ship was swaying
a harsh snap but its a good thing i abandoned that project..
all is well lmao
DialogueText is null or DialogueText does not have a textmeshpro component
A reference object is null on line 59 . . .
Or that array is null
yeah true parenting was not fun to figur out on netcode
Check each reference on that line and you'll find the culprit . . .
Thats why I think ParentConstraints might be a handy middleman
i know that it's not the array, it has a textmeshpro, I'll check if it's null
Are you sure it is what you think it is
and is that the component throwing an error?
We don't have the code, so we can't tell what is on that line . . . 🤷♀️
it's a reference to the gameobject, i need the textmeshpro component
no?
why not use a public refernce to the TMPro instead?
oh! did a few tests, the gameobject isn't null, the component is
aye!
If you're dragging the GameObject then use the component instead . . .
i dont know why...it's here
No need to go from the GameObject to the Component . . .
i need the gameobject itslef for other bits of the code
public TMP_Text ActorText
if u have the TMP u can just go ActorText.gameObject <-- then u have a direct reference to the text.. and u can still access the gameobject from it
Ideally you might want a new component on that then
A Component always has access to its GameObject; there's no reason for a GameObject field . . .
this is a dumb way to do that
okiedokie.. its still a way tho.. im just talkin in examples
What do you mean? This is the better way to do it (if you need access to the GameObject) . . .
he just tell me that sht all the time.. lol
theres a reason i have to unfold his comments
I guess it depends on what they exactly mean by other reasons but if that object has more jobs to do than just the text imo it should be it's own component that manges those jobs
😆
anywho.. if it is stupid.. and u want to use GetComponent..
atleast use the GetComponent off the gameobject and cache it in Start or Awake or something
did that, it worked!
so u can have the reference to the TMP later on in the code w/o having to call GetComponent everytime u wanna change the text
also, been working on a dialogue scripting lang for my game, thoughts? is this the right channel for this
[ACTOR]"This is test text for UDM v.0.1!"
{1}"Option 1"
>[ACTOR]"You picked option 1!"
###
{2}"Option 2"
>[ACTOR]"You picked option 1!"
###
{3}"Option 3"
>[ACTOR]"You picked option 1!"
###
{4}"Option 4"
>[ACTOR]"You picked option 1!"
###
{5}"Jump to start!"
^TITLE```
i have all the processing done (the image :))
probablyyy more suited to unity-talk or maybe even a thread in code-gen just based on vibes
Curious on how this works though, i haven't done dialog stuff before, feels a little boilerplately off the bat but might be my ignorance
Seeing an array store dialogues reminds me of this video https://youtu.be/jDB49s7Naww?t=757 goes over how to store dialogue
uhhhh a thread might be better but also might be buried
https://discord.com/channels/489222168727519232/1407885336171905104 i can answer questions abt it on there
I was unable to find a way to implement your solution (regarding character controller movement inertia/momentum)
Could we talk about this over DMs or something? I get the feeling this is going to be a long and difficult process and I don't want to monopolize this thread
you could always make your own thread here
DMs are not a very good way of getting help, community servers exist for a reason
☝️ and ya, it was trial and error for me when i was doing it.. its was basically me breaking up the vectors so i could watch the inspector and debug and see what was going on..
i would suggest googling it.. i remember looking around quite a while to figure out exactly what it was i was going to need to do.. and how it applied to the basic movement i already had.. (this was before AI) but the ai overview basically explains it pretty well.. and theres tutorials, unity threads, and whatnot further on down the page
i started with just 1 axis at a time.. (forward and backwards) once i had that figured out i applied it to the other axis..
then it was about whether i was grounded or i wasnt grounded.. then i applied it to that.. (but not all at once)
I get the feeling this is going to be a long and difficult process
it definitely was not a fast or simple addition so yea might be worthy of a thread and to post up some basics of ur codebase ur starting with
Character Controller - How to keep momentum of previous movement when changing direction?
i dont see edit details am i just blind or does it not exist
This appears to be a guide for using the Terrain Tools package. Do you have that package installed?
https://docs.unity3d.com/Packages/com.unity.terrain-tools@4.0/manual/index.html
I'm not sure where the best place to post this but I'm trying to find a solution. I've recently downloaded Game creator 2 and Have installed on both in progress projects and new and I can never get the program to run correctly. most of the time I get an error: error CS0006: Metadata file 'Library/PackageCache/com.unity.collab-proxy@2.9.1/Lib/Editor/PlasticSCM/log4netPlastic.dll' could not be found
error CS0006: Metadata file 'Library/PackageCache/com.unity.collab-proxy@2.9.1/Lib/Editor/PlasticSCM/Unity.Plastic.Antlr3.Runtime.dll' could not be found
error CS0006: Metadata file 'Library/PackageCache/com.unity.collab-proxy@2.9.1/Lib/Editor/PlasticSCM/Unity.Plastic.Newtonsoft.Json.dll' could not be found
error CS0006: Metadata file 'Library/PackageCache/com.unity.ext.nunit@2.0.3/net35/unity-custom/nunit.framework.dll' could not be found
i do
oh sorry i couldn't see that channel
question: i have 1 map let's say the player can explore the map all they want but when they interact with some npc it will trigger an event like a mission or spawn horde of zombie, should i reuse the scene and depend on the save file to keep track to what player already done or make a separate scene with the same map just to make the player do the mission, or is there a better aproach?
@gaunt raptor : General advice is to try to reduce/reuse code as much as possible. I would assume reusing a scene would be the best approach but its impossible to know without more info.
I have a silly compile error I can't figure out. This code
if (controller.stage == 1)
{
float[] floatArray = { .8f, .6f, .5f, .4f, .8f, .4f, .2f, .1f, 0f, .1f, .2f, .4f, .8f, .6f, .4f, .4f, .6f, .8f, .6f, .4f, .7f, .8f, .9f, .8f, .6f, .4f, .3f, .2f, .25f, .2f, .25f, .2f, .15f, .1f, 1.5f, 2f, 2.5f, 4f, 5f, 6f };
}
else
{
float[] floatArray = { .8f, .6f, .5f, .4f, .8f, .4f, .2f, .1f, 0f, .1f, .2f, .4f, .8f, .6f, .4f, .4f, .6f, .8f, .6f, .4f, .7f, .8f, .9f, .8f, .6f, .4f, .3f, .2f, .25f, .2f, .25f, .2f, .15f, .1f, 1.5f, 2f, 2.5f, 4f, 5f, 6f };
}
if (startTime >= 0f)
{
int floatIndex = (int)Math.Floor((value * 40));
float currentValue = floatArray[floatIndex];
Produces the error : The name 'floatArray' does not exist in the current context. I don't understand why
becasue of the {}\
the scope of a variable is defined by the brackets]
you defined it in one scope and you're trying to use it in another
declare the variable outside of those scopes then you can use it.
the data seems to be the same in both anyways 😄
and if you have a data array like that you might want to ask yourself if you cant use a mathematical function to calculate the values instead 😄
Haha..it is, I haven't built the second stage yet. Are you guys referring to the {} when declaring the array? Sorry I don't get it.
(or use an AnimationCurve)
No math...its just random data
you can automate the randomness 😄
i assume its animation easing data?
No, its a value assigned to UI Slider
To trigger an glitch effect
So...I don't understand the {}...
oh yeah, then you might want to randomly generate some numbers 😄
I need it to be in the same place every time
if () {
INSIDE SCOPE
}
OUTSIDE SCOPE
anything you declare in the inside scope is only available between the {}
you can access stuff from outside in the inside scope, not the other way around
Oh...those brackets...so how do I do if statements in this case then?
ah ok
you did:
if (true) {
int x = 5;
} else {
int x = 4;
}
Debug.Log(x);```
You need to do:
```cs
int x;
if (true) {
x = 5;
} else {
x = 4;
}
Debug.Log(x);```
bool success;
if(thing)
{
success = true;
}
Debug.Log($"{success}");
or you can do var floatArray = controller.stage == 1 ? data1 : data2;
but given the length of your data i wont advise that 😄
perhaps too complex for someone who doesnt get scope
agreed
Thanks for explaining. Makes a lot of sense. I understand scope...I just didn't realize it was limited by if statements. Definitely beginner mistake of course
it's the {} not the if
i mean you can even create a scope without if
{ } defines the scope
you can just randomly do { in code and open an inner scope 😄
Are there better alternatives for remote version control for unity than github?
"better" is subjective
github isn't really remote version control - do you mean hosting?
there are indeed alternatives
gitlab, bitbucket
you can just search up "github alternatives" to get a list
Maybe start with explaining what issues you have with GitHub?
I have a few questions.
So, for items, I'm having items in my game generate a unique int ID, instead of using class comparisons to check if an item is a clone or not.
What are some good things I should know, going forwards? I know Int Comparisons are faster than String Comparisons, which is why I went with just generating a really big random number, but stuff like how big that number should be, post-processing to ensure I don't generate IDs that alredy exist, ect ect, I'm having more trouble finding info on.
I also saw some people using Unity's GUIDs, but for things that inherited from Object, which my items do not.
You can make your own GUIDs
There are two main approaches:
- Have some central coordinator that uses a monotonically increasing ID number to ensure no duplicates
- Use GUIDs
Sup i'm a newcomer tryna get into C# but i need some help with the script building itself
Look at the update part (it's an example of the problem i'm running into)
i don't understand what's happening
because this private is INVALID inside there
you cannot write private inside a method/function
should it be public?
ok - there is no reason you need to write private or public inside a method to write any code whatsoever
that is never valid C#
yea i see it now, thanks a bunch man!
private/ public (others you'll learn about later) are called 'access modifiers' - they can't go inside a method
One thing worth mentioning about guids is you still need to ensure copy pasting/duplicating assets using a generated guid refresh their value
If you instantiate an object from JSON that has a GUID, will new GUIDs created afterwards respect the existence of the "created" one, or does the system governing GUIDs only generate unique IDs from ones that were created using the method?
In the context of using a save/load system, specifically
Afaik new guids don’t respect anything they are just statistically reliably unlikely to collide naturally
But if your explicitly copying data you gotta watch out 😅
Yeah, I've got that part handled, My inventory system has a thing where it checks against existing entries and can force duplicates to regenerate their ID
I did this for the first time like a week ago lol
Do someone know that why camera moves when I drag joystick to near bottom left corner?:
https://streamable.com/o827rv
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
A tool for sharing your source code with the world!
I assume the camera is meant to move when you drag on the screen yeah, if so this should be self explanatory.
it looks like it's jumping to an odd position when the joystick is in a certain place
No, I don't want my codes to move camera by dragging joystick
How can I make the turning to another direction faster?
insta change the velocity
- Set velocity instead of adding force, or,
- Add more force
I want my codes to let players rotate camera in horizonal directions by dragging in empty space on screen but somehow my codes are also moving camera by dragging joystick but this is only happening for some area of joystick draggable range. This is happening in Joystick range's bottom left corner area
I was asking if dragging anywhere on the screen made it move
yes, camera can be rotated horizontally by dragging on screen's empty space
But it should not rotate by dragging joystick in bottom left corner
are you checking for the touch to be on the joystick? And if so, do not move camera
I'm getting this error on all my projects now even when I start a fresh one. error CS0006: Metadata file 'Library/PackageCache/com.unity.collab-proxy@2.9.1/Lib/Editor/PlasticSCM/log4netPlastic.dll' could not be found
error CS0006: Metadata file 'Library/PackageCache/com.unity.collab-proxy@2.9.1/Lib/Editor/PlasticSCM/Unity.Plastic.Antlr3.Runtime.dll' could not be found
error CS0006: Metadata file 'Library/PackageCache/com.unity.collab-proxy@2.9.1/Lib/Editor/PlasticSCM/Unity.Plastic.Newtonsoft.Json.dll' could not be found
anyone know a solution, I've deleted the PackageCache several times but doesn't seem to work.
im trying to set up sprinting for my character, but im getting these 3 errors, and im having trouble understanding the issue. I initially followed a tutorial that taught me to set up movement, so i tried to use the same logic to add sprinting but its giving me issues
Either you have two Updates in this class, or two classes called Player
the other errors are just basic typos
Yes, you can only have one Update method per class. You can add as much code as you want there
YES it worked tysm
now i just need to find out how to make sprint not cancellable midair
I did get the boulder sdript working, i simplified it a ton and just used the components on the prefab instead of trying to reset them
Guys unity cloud service got any API to get ip address upon authentication? 🤔
Hey can anyone help me understand why is my code not showing results? (sum advice could help me out as well)
my character keep stucking here what should i do ?
What do you mean by "showing results"? What kind of results are you expecting to see?
Also !code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
I will say your line 11 is wrong. You're probably getting NullReferenceException in the console right?
Line 11 needs to be controller = GetComponent<CharacterController>(); right now you're not assigning the variable.
From what i understood by watching a video bout the move function i tried to use it to create a simple character movement system
you shouldn't ignore errors in the console. Make sure your console window is always visible
So i should've referenced the controller
I'm explaining what you need to do, yes. Your code currently on line 11 does nothing.
yea i'm still tryna get used to unity's interface
refer back to other code examples to see how to use GetComponent properly.
Show inspector too maybe 🤔
nothing in the inspector here will matter
the error is clear from the code alone
Well I guess you're right we'll see if the components are on the same object
I think he trying to access the object but he didn't use the correct sytax to get the controller
yes I already explained that above
Yeah 🫶
Also try to post code directly in discord, so it can be copied and modified easily
Im sorry because this is probably a really basic question. Basically in my game you can create towers and then when you click on the towers it opens an upgrade menu but I cant figure out how to pass information from the specific turret that was clicked on to the menu.
Have the code that opens the menu do it
ok but how
How should we know without knowing your project? Presumably your Tower class
or whatever you use to represent a tower in game
Built in button script will have option to trigger a specific code
ok
Go to the bottom of the button inspector
There is onclick tab
Attach ur script there
And on right side drop down
U'll see which module to trigger on click
This is best if u r doing it from ui n buttons
But if u r doing on 3d space
Then i think best is ray cast
🤔
I'm assuming they already figured that part out
Hey guys coming back to disturb y'all cuz idk how but i managed to get rid of the scene "shortcut" i could say
does someone know how to make it re-appear?
Wdym by scene shortcut
In the top middle of the screen just sided with "game"
Right click the game tab and go to Add tab -> Scene
Or go into Window -> General -> Scene
oh damn, it was THAT simple, thx once again
If you are trying to share code use one of these.
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
ty couldnt remember which website to use 
I'm getting an unreachable code detected error code on every "break;" line in the switch case :/
https://hastebin.com/share/secakaloci.csharp
That's cause you have a return right before each one
oh should it just be after the entire switch case
or do you not even need breaks if you return out of the method?
Im not sure I've hardly used switch cases, you can try though
alright ty
Though does this need to even be a return type? Arent you setting the pageSprite in the functon?
technically not, but in this case a different script makes use of it returning something
also yes, you can just return out of a switch case instead of doing "break;"
compiler is at least not giving me any errors lol
you don't need Break if you're returning , hence the error
yeah figured
btw you can also do a switch expression
public TMPro.TMP_SpriteAsset LoadPageSprite()
{
return element switch
{
"fire" => fireSprite,
"water" => waterSprite,
"earth" => earthSprite,
"wind" => windSprite,
"lightning" => lightningSprite,
"dark" => darkSprite,
"light" => lightSprite,
_ => null
};
}```
how can i get rid of this line ???
use pixel perfect.
also not a code question #💻┃unity-talk | #🖼️┃2d-tools
mb
but what is pixel perfect ?
its a component, look it up
alright ty
oh wait that's so much cleaner
yea imo its cleaner if all you need to do is return based on value
this doesn't do the setting that the other did does it?
not sure what you mean with "the setting"
you mean the =
assigning value is redundant if you're returning a value
the pageSprite = fireSprite; part
ya thats redundant
if they need to they can just do
pageSprite = LoadPageSprite()
doing pageSprite = in each case unnecessary repetition
Some peole here should get paid
hi can someone help me? i'm making a moving platform and my goal is to let the player move with the platform, basically the player should move with the platform without clicking anything. a lot of tutorial basically puts the player as a child of the platform, buy when i do that the player makes "jerky" movement, i think he becomes a child but it's position doesnt change thew way it should. what could be the problem? the movement of the player is in another script and it is done with a rigid body
post code using links
a powerful website for storing and sharing text and code snippets. completely free and open source.
yes
are you using rigidbody to move player?
yes
you should probably look up the method for that, parenting afaik Only works with CC.
I gotta rememeber how I did it but basically you need to add the platform velocity to the player velocity
also you should be using a Kinematic on the platform itself too and move it via MovePosition instead of transform, that should also help sync the two
yeah i don't have he rigidbody on the platform only the colliders
can ı share my code im beginner i have a problem with state machine thing
dont ask to ask
just noted that i had on collision exit in the script but it doenst matter
a powerful website for storing and sharing text and code snippets. completely free and open source.
what do you mean by that? i saw a comment on a blog that said
"I’m assuming that your player script is overriding the player’s position, which will cancel out any movement coming from the platform. You will need to adjust your player script to take into account if you are currently on a platform."
it is something like that?
didnt write in english fully
the fact is that i think the position is changing by parenting but in a very small way
but the problem is after the attack ı cant get the idle parameter ıts just goes walking animation with idle timers
dynamic rigidbodies arent meant to move via parenting
https://paste.myst.rs/x3d5ym8k this is my controller if it can help
a powerful website for storing and sharing text and code snippets. completely free and open source.
mh
nav can you help me too after luketto's finish?
and what should i do?
help how ? you have to show the code + describe whats happening vs what you expect to happen
try the suggestions I sent
a powerful website for storing and sharing text and code snippets. completely free and open source.
the problem is after the attack
ı cant go the idle animation
it just goes walking with idle timers
why are we spamming the link?
its works fine until go back to state normal
so should i add a rigidbody on the platform too?
thats another step yes, but the main thing here you need to get the velocity of the platform and add it to the player
okok
i tried something like that but it didnt work
i had on my controller something like
Vector3 targetVelocity = moveDirection * moveSpeed * speedMultiplier;
targetVelocity += new Vector3(externalVelocity.x, 0, externalVelocity.z);
targetVelocity.y = rb.velocity.y;
rb.velocity = targetVelocity;
where external velocity was the platform velocity
nah you need the difference in motion
actually on my old project I did
moveInput.x * movingStats.MoveSpeed + movingTile.MoveVelocity.x
so it should work
but if you use kinematic on the moving platform which is what is usually done you need previousPos - currentPos and use that
ok i did something like that
on the platform's script i added velocity
currentVelocity = (transform.position - lastPosition) / Time.deltaTime;
lastPosition = transform.position;
and i added an externalVelocity on the controller script
Vector3 targetVelocity = moveDirection * moveSpeed * speedMultiplier;
targetVelocity += new Vector3(externalVelocity.x, 0, externalVelocity.z);
targetVelocity.y = rb.velocity.y;
rb.velocity = targetVelocity;
and simply OnTriggerCollider in the platform script i get the controller component and put externalVelocity as the platformVelocity
private void OnTriggerEnter(Collider other)
{
if (other.gameObject == Player)
{
PlayerController playerController = Player.GetComponent<PlayerController>();
playerController.externalVelocity = currentVelocity;
}
}
private void OnTriggerExit(Collision other)
{
if (other.gameObject == Player)
{
PlayerController playerController = Player.GetComponent<PlayerController>();
playerController.externalVelocity = Vector3.zero;
}
}
should it be ok?
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
did you try it ? does it work?
Kinematic will probably give you less (if any) jitters
wdym "ı cant get the idle parameter ıts just goes walking animation with idle timers"
maybe show a video as well? that can help
a powerful website for storing and sharing text and code snippets. completely free and open source.
in this code
in case great
i cant work with if part
its just go else and ı dont want it
no 😢
idk bc i put a print in OnTriggerEnter and it enter in the function so it should modify the externalVelocity
but idk
same with normal too
so whats happening instead?
after the attack ı cant reset the "bekle2" bool ı think
nav do you have an idea?
cant ı just pick a state while in a coroutine?
can you make a video show whats happening
ok
nothing the player stays on the platform but he doenst move
also the externalVelocity is modified so idk because he remains stopped on the platform
ı dont know if its the correct place to share a video but
everything is bugged lol
emirrk i feel you .....
So is whatever this state is the one that it's supposed to be in at that point?
walking
it should go walking and idle but
it just go walking
and wait in idle times
So, what is the condition from this state to idle?
walking false
idle true
the problem is ı cant see the idle
it waits with just walking parameter bcs
the if statement in great and normal case
doesnt work
This section, right?
if(anlık == durum.normal)
{
Debug.Log("durum normal2");
animator.SetBool("yürü", false);
animator.SetBool("idle", true);
}
Then bekle2 is false
but ıt should be true as ı see
yes ıt goes false but
oh
can coroutines interrupted by update method?
this place is sus
Coroutines are intentionally designed to be "interrupted" by the update method
That's what makes them "co"
makes sense
so bekle2 goes false here and gets interrupted by update and gets false maybe
They run until they hit a yield, then wait for their turn, and everything else continues to run in the meantime
but without this
"bekle" coroutine will work multiple times
are you sure there is only a maximum of 1 instances of the coroutine running at a given time?
All of your coroutines can work at the same time as each other. This code is a mess to make sense of since I don't understand any of the language, but it seems like your problem stems from your coroutines all happening simultaneously and fighting over the animator parameters
It seems to me like you should be handling the timing of animations in the animations, using Exit Time instead of parameters and possibly using Animation Events
the problem is a parameter (which is control) goes false bcs its get cuts by update and when the coroutine cant finish it cant be go true again
im currently making a movement script but whenever the player goes left it speed only goes to in between 0 and -0.99 it the speed cant go under -1 so i cant move left can someone please help?
!code please
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
i sent it is it not showing up?
you sent a .txt file not one of the links
oh alr hold on
is there a way to see how many coroutines work in the same time
All
There's nothing preventing any number of coroutines running simultaneously
assume there is an infinite amount unless you only call a specific amount
If you run the line StartCoroutine it will start a coroutine
alr
i cant get pastebin to work u know any other websites like that?
the other 3
The link you were sent has like 4
pick one of those
oh
a powerful website for storing and sharing text and code snippets. completely free and open source.
hi im new here which channel to get help
depends on what for
but #🌱┃start-here
And what was the problem again?
im currently making a movement script but whenever the player goes left it speed only goes to in between 0 and -0.99 it the speed cant go under -1 so i cant move left can someone please help?
if (mathf.Abs(NegativeValue) == 1)
passes it would make NegativeValue positive after right?
It would return the absolute value of the number you pass it
so for example
int horizontal = -1;
if (Mathf.Abs(horizontal) > 0.01f)
{
Console.Write(horizontal);
}
would horizontal log +1 or -1
ok wasn't certain since i have seen it change data a few times with other stuff in if statements and thought that was where their problem was
Mathf.Abs operates exclusively on value types. It can't change the variables you pass it because those variables aren't references
you call horizontal = Input.GetAxisRaw("Horizontal"); twice in Update();
ohh thank you
sorry that wasn't it i just noticed that
Extraneous, but it won't affect anything
what can ı do with animation events?
Still, worth getting rid of
no i just meant seen it happen with other calls that happened in if statements
Call a function at a specific point in an animation clip
oh yea ur right it dident fix it but still a good catch
Yes, the code in the if statement does actually run, so if the thing in there changes data, then it would change that data
why are we using this? Mathf.MoveTowards(rb.velocity.x, targetX, accelRate * Time.fixedDeltaTime); when it's going in rb.Velocity right after
To move the X Velocity closer to targetX with a per-iteration limit
also can ı see the circle in the overlapcircle?
fair though why does a player controller have a target :?
it was 12:30 when i was making it ok
oh nvm just never seen someone handle movement like this
Not by default, but you can grab packages that let you:
https://github.com/vertxxyz/Vertx.Debugging
is this made by the Mod Vertx?
tysm
i dont know its diffrent form all the other ones ive made but it was pretty fun so i decedied not to mess with it
Why not? It seems like a way to handle acceleration/deceleration in a more granular, if less physically accurate, way
yes
do you know what might be causeing the problem?
I don't fully know what the problem is, actually.
fair i miss understood what it meant by target when you mentioned it and thought it was going after an object :/
any advice to what to do about this? its annoying when it plays falling animation on such places
Like, what is the actual problem that's occurring in terms of what is happening in the game?
Like, it can't move left?
ill send you a video hold on
That would be great actually
add to the player the velocity on sloped
How are you currently playing the fall animation? What's doing the actual ground checking?
its character controller so i dont check it
it does it for me
when you go fast on CC and its sloped, it "skips" and ungrounds itself
there is a fix for that
So you'll probably need to either write your own raycast to detect when you're grounded, or do a ProjectOnPlane for your movement so you move down the slope instead of just forward + gravity
Encode the video as .mp4 and it will embed
going slow actually works, i tested it now
but how would i say make speed something else when on a slope, how do i detect im on a slope
here i just made an unlisted yt vid https://youtu.be/uekstg0ukoI
raycast down and check the angle / normal
going slow just skips the problem overall but its bandaid
so ill do playerPosition.y = hitpoint.y ? if not grounded
im not really good with raycast but i hope i can manage
Try logging some values, right after your MoveTowards, add this:
Debug.Log($"{gameObject.name} X Velocity {rb.velocity.x} -> {newX}, Target Velocity {targetX}, Accel Rate {accelRate}");
Add some debugs, is horizontal the value you expect? What about targetX etc.
See what happens when you try to move left
the horizontal value when i hold a or left key is -1 like its supposed to be
and the rest of the debug logs?
gimme a min
could the player also be moving down while left? feels like it's having friction with the ground.
maybe it's just really windy
that will feel terrible
what about not instantly but in 0. something seconds
I would say instead of just passing your vector directly to Move, if you're grounded, use ProjectOnPlane.
https://docs.unity3d.com/ScriptReference/Vector3.ProjectOnPlane.html
So, raycast down, get the normal of the RaycastHit
https://docs.unity3d.com/ScriptReference/RaycastHit-normal.html
And pass that to ProjectOnPlane, then pass the result of that to .Move
this is what i get when i move left Player X Velocity -0.3272377 -> -0.7972376, Target Velocity -16.6, Accel Rate 23.5
UnityEngine.Debug:Log (object)
and if you moved right?
Okay, and does it trend closer to -16.6 as you go?
no but i think i got it
check this
https://youtu.be/PEHtceu7FBw
but yeah project also work, its similiar
In this Unity game development tutorial we're going to look at how we can prevent a character from bouncing, when moving down a slope.
We'll start off by explaining why the character bounces when moving down a slope, and then explain how we're going to solve the problem.
We'll create a method that will detect whether the character is on a slop...
so mt gravity scale is 3 but i set it to one and now you can move left but your still moving noticibly slower then the right movement
then you didn't get it :/
it will be great if i can understand this slope problem, my number 1 problem right now 😄 thanks im watching now
also im sure you could change this if (Mathf.Abs(horizontal) > 0.01f) to if (horizontal != 0)
hey nav sorry do you have the project with player on the moving platform?


