#💻┃code-beginner
1 messages · Page 766 of 1
the new input system pretty much handles all of that for you without the need for a giant switch statement mess
my main worry is edgecases where I'd want it hardcoded
well I gues not main worry
you'd probably never want to hardcode your input
you can do that with the new input system, and its more broader as you setup abstract inputs, where any key can be used for it
New input system can do basically everthing you are doing and do it easier AND it will actually be supported
damn 😭 what little unity knowledge I had from like 2 years ago out the window
trust me learning the new input system is worth it
where could I find a good tutorial explaining the new input system
Don't worry, you clearly still know how to use the editor and to write scripts
most tutorials i've seen massively overcomplicate it, i recommend you just read the docs
Docs is probably easier and more useful than any tutorial
guess I'll read tmr then lol
most easiest basic way to use it. is using the playerinput and sendmessage
I do robotics it's more of just C# with Unity's specificity as opposed to Java
eh, i like just referencing the actions directly, makes more sense to me
basically you would need to created a method for each of the inputACtions
oh most definitely, but if you don't want to deal directly with the events, its a quick and dirty way of using it
guys what is this error?
read it
depending on my use case i either use the PlayerInput for quick access of the InputActions, mostly for local co-op
seems you are trying to use the old input stuff while you have it set to only use the new input system
can i use the old stuff in the new unity version?
you technically can, but really shouldn't
Read what the error says and it'll tell you how to resolve your issue.
isn't it mostly there for backwards compatibility and transferring to the new
i read it but i dont know wher the setting is to let me use the old system
its in the other or extra section in the player settings
The new input system makes compatibility with input devices more flexible and provide a lot of extra functionality.
and if you want to do easy couch co-op, the playerInput allows that to happen and it will require the new input system
okay I will use the old system for now then try the new one
thanks for putting up with my questions guys
if you are in a time crunch, use what you are comfortable with unless you want to learn via trial by fire.
prototypes are also meant for testing a game concept, not necessarily optimal
PlayerInput allows quick set up, but it feels less flexible when it comes to event handling
definitely not.
@ashen trail i didn't see anyone answer you properly fully, so may as well -
with a PlayerInput, you can use methods in your class like you have, but you will have to configure it properly
for a method receiving CallbackContext, you'd set it to unityevents and assign the method.
for send messages, the method would need to receive an InputValue.
Thanks for taking the time to help me, I figured out the movement(probably not how i should do it but it works)
if it's wrong, it could lead to hard-to-trace bugs in the future. you have an opportunity to check now, why not do so lol
well I put some other stuff but this is basically it
i used the old unity movement system because I'm more familiar with it and dont understand the new one
there is definitely a learning curve, but if you take the time to understand it it'll be worth it - it's much more flexible and imo easier to use once you do get the hang of it
your previous method was set up fine, it just wasn't hooked up to events properly - i explained how you can do that here
any of you know how to check if your moving or not use InputActions? Mine works like this but I kinda need to check if im moving for the next part and idk how to do it with what I have
(to answer your question - that is correct for input handling, as it's being done in Update. you could also set the input in Update as well, just that it wouldn't apply until the next FixedUpdate)
Check if you're moving as in player has velocity? Or input is being pressed
input
those is trues are not doing anything btw, and you'd probably want ReadValueAsButton rather than the float check
well, doesnt matter
thanks, I'm having a lot of fun with unity
Great community
oh well you'd be wrong then, because it does work
the ones closed work
i didn't say they don't work. im saying they are semantically wrong
it works so its fine
is true literally doesn't do anything lmao. you can use booleans directly
that's the point of a boolean
and ReadValueAsButton exists to respect pressPoint, rather than checking if it's fully depressed (which it may not reach if it's an analog input)
alright
If you literally just delete the is true and leave the rest of the code directly as is it will work exactly the same but be correct
maybe don't dismiss things you don't understand lmao
Nah, I knew about it, I just forgot about it
that sounds dumb
anyways, you can check if you're receiving move input by just checking if input is Vector2.zero
Anyway if you want to check for input, just use the input variable you already have
alright
also, is is a specific thing, for most comparison you'll probably want == instead (though you don't need it in this case, since booleans)
(usually comparing floats with equality is bad, but InputSystem has deadZones to handle this)
yeah, I don't "is" for anything is
if(bool) is functionally the same as if(bool == true)
And if(!bool) means if(bool == false) or if(bool != true)
I know dw
Ok good
I just forget that you could do that
it sounds like you didn't know then...
Cause, I stopped focusing on unity for like
this isn't a unity thing
it's fine to not know things
maybe don't dismiss stuff if you've forgotten too then lol
We're getting away from the topic
getting defensive will just make us waste more time telling you things
Im not going to bother arguing about this in a help channel, but I didnt understand wth you meant
stop getting defensive and accept the advice, that's what im trying to say
thanks to both and im out
you mightve known it before, but you clearly aren't applying it, so why get defensive/dismissive that our advice is wrong lmao
I did apply it
You're also being a bit agressive about this advice, it may well be true but you might want to be more careful how you go about it in future
you weren't in the code that you sent
you're still doing is 1f there
yeah not that part
i am also referring to that part
that doesn't respect presspoints and does not account for analog inputs
im referring to the boolean part
cool, but there's also another part that ive given advice that you've also dismissed
ik
i'm going to be blunt if being gentle doesn't get the point across 🤷
ok, so maybe fix the code
That's not a great strategy for helping others
so you'd rather the point just get lost to the ether if the receiver doesn't get the point?
The way you've been phrasing it feels demeaning
No
ReadValueAsButton doesn't exist for me
ah whoops, that's for CallbackContext
I'd rather you rephrase until it's clear to the reciever while not being insulting
there is ReadValueAsObject
it's IsPressed for InputActions
yes, that's the point of being blunt
Yes but saying things like this doesn't feel like being blunt, it feels like being insulting, even if that wasn't your intention
yeah, that's somewhat of a necessary tradeoff
I disagree
you're free to
It's counterproductive to the goal of helping someone to make them feel bad about making mistakes
none of my messages were about making mistakes being bad, it's about not fixing them (when given easy instructions on how to) that's bad
the dismissal/defensive attitude is definitely bad, it hinders a lot of receiving more info or better advice
Yes but people become less likely to change their attitude when insulted
If you want to help someone overcome that insulting is the exact opposite of what you should be doing
no one was insulted
i don't see how my messages were insulting, tbh. i'm specifically pointing out the behavior
something being percieved as aggressive and/or degrading is one thing but thats not an insult, those are two different things
I think things like this easily read as insulting, again even if it wasn't your intention, with the passive agressive tone of "maybe don't" and "lmao"
and don't get me wrong, it's a very understandable response - but it's gotta be shed for efficient communication
ah, efficient is not the right word.. whatever the adjective form for "efficacy" is
stupid question but is it possible in python to have code print an input question and then print a new line under it before the input question is answered?
guys I'm not gonna lie
I may possibly, probably, just maybe, followed a youtube tutorial blindly and now I have no idea why my game object wont follow my players rotation
we wouldnt know, this is a unity server
...this is a unity server
but you can just print stuff before the input call
no
no
oh
When you're writing messages, especially online where tone can be easily misinterpreted, it's more imporrant how the other person percieves your tone than what you actually wanted it to be, and clearly it was percieved by multiple people as rude
!code 👇, and have you tried debugging the values you're using
📃 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.
dont know what debuggin is
ima try to figure that out
nope
(personally Ette also came off as fairly rude and i don't think Chris's messages we're that far off the pre-existing energy)
just Debug.Log the values, see if they're the expected values
see if mousePos seems right, see if rotz seems right, etc
I agree both seemed rude, but when you're in the position of helping someone the onus is on you to not become rude in response
agree to disagree there
also check if you're getting any errors. you should have a console window open, i'm noticing you don't have that in your layout
stuff pops up at the bottom when i have error but i will check
you should have a console open regardless, that's were debug values will be shown
Why? How is it possible to defuse a situation by countering rude behavior with equally rude behavior? That almost always leads to a spiral of anger
okay
personally i think its the internet and if the person asking for help doesn't want rude responses they shouldn't be rude to the person helping them. i don't think the responsibility is really on either party but one side is the one asking for something so
everytime I move my mouse the digits in the debug menu move
so ig thats working right?
stupid question incoming here
could it be because im using a vector 3 in a 2d environment or it supposed to be like that
@ashen trail wait, was the issue in the rotation or in the shooting or the graphics of the player or what exactly?
im noticing that the gameobject you're rotating is not the root of the player
no, that's fine. 2d is just basically ignoring the z component (or not having it)
ok
also im noticing that the black gameobject is rotating just not moving around the player
rotation around the player
Ok, let me rephrase, I don't think it's that the person asking for help should have the onus on them, but I do think that neither group should respond to rudeness with rudeness. I think it's perfectly reasonable to calmly point out that a certain behavior or message was rude, and attempt to defuse the situation. But responding with more rudeness cannot help in any way. The best case situation is that the response is ignored, and the worst case is a spiral of more and more rude replies.
I think when in a position of trying to help someone especially, knowing that people often might be frustrated with the issue they are trying to solve already, the attitude of "one side is asking for something" isn't productive. It's much better to take the approach of "never attribute to malice what can be attributed to unintentionality" and attempt to help rather than provoke.
I agree with this sounding rude, but I also just generally thought you meant that "is true" wouldn't work general overall if you understand? Thats is.
that doesn't answer my question. the rotation of what, exactly?
so I put an empty game object around the player(the black thing u see)
and i want it to follow the mouse position around the player so then i can later program shooting in that direction
idk if that answers ur question
if it were empty it wouldn't be black
do you mean the "create empty" menu item? that just creates a gameobject without anything inside, once you add components it's no longer empty lol
To be fair, (as I assume you now understand) the is keyword working was a lucky side effect, seeing that is does something completely different to ==, so it was a good idea to fix it, though I think it turned into more than it should have
create empty
so that black dot is the rotatepoint?
it's not a lucky side effect, it's just.. how comparison works
but is is pattern matching, which includes comparison as part of it
its what should follow the mouse around the player
sorry im new to all this programing terminology
the extra pattern matching would be the undesired bit
@ashen trail is this correct
I meant it's a seperate thing that also happens to work in the situation, but would open up to unintentional side effects (Which I think is what you were saying)
Yeah, but when I said "I forgot about that" I should've specified wth I remembered lmao. Otherwise the end part wouldn't have happend. I also didn't do the isPressed thing because I'm lazy
yes.. i think
no, what i was saying was that x is true is the same as just x
the is true is unnecessary and not doing anything
because I'm lazy
it's shorter though
Im just lazy
i have no idea what you're trying to say now
just forgetting stuff isn't a crime, you don't have to find justification for it
Do you mean that as in, like you were looking for the first thing that came to mind instead of the easier thing that would have required a few more seconds of thought
something like that
so what you have is a black dot that's offset from the player and rotating on its own, rather than orbiting the player
you'd have to either change the offset (position), or have an intermediate gameobject in the player that rotates instead
I also just havent learned input actions fully yet so I didnt know IsPressed existed
do you want the black dot to rotate and point in the direction as well?
yes
which was before... My brains gone off track
so it's not laziness, you just didn't know a thing
that's fine
and to confirm, you don't want the player to rotate, right?
yes
Before I asked, I didnt know at all about that, after I asked I just didn't feel like it. But it does make it easier for the future the .IsPressed
so you'd need a hierarchy like this, basically:
A
|- B
|- C
```where A is the player, C is the black dot
rotation is around the pivot point, which B serves as - B isn't offset from the player, but C is offset from B
then you would rotate B, which would make C basically orbit A/B
Also, just a note that without any tweaks for C's rotation, when you move your mouse to the opposite side of the player the rotating object will be upside down, which is totally fine if you want it to be like that but if not you'll need to tweak C a bit
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
okay thanks
Thank you
if you don't want the blackdot to rotate at all you could just modify the localposition instead of rotation
I remember when I first did this setup I rotated the rotating object by the opposite of the rotating point's rotation (so B at 35 degrees would have C at -35 degrees) which worked well enough for me at the time
yeah that's also viable, but if you just want to move it around a circle you don't need an intermediate pivot
i mean i guess you could do rotation + offset to not need a pivot even if you want the orbiting thing to rotate
a lot of ways to achieve it
a lot of ways to do the rotation math too
But you do have to use x = sin and y = cos for a circle and my 3am brain had forgotten what those words meant lol
you would need the opposite, but yeah
God damn it
actually, you wouldn't need trig, you can use the direction vectors
ima be honest i think im in over my head
Where are you up to?
yah that
transform.localPosition = (mousePos - playerPos).normalized * distance
but like make c offset from b
you would just use the same code you had before, but applied to B instead of C
what you had previously was basically A -> C
you would add an intermediate B and move the rotating script to B instead of C
you can use the same method to offset as before, just have C be 2 units away from B or whatever - it's the localposition, it'll be rotated along with B
I can draw up a shitty ms paint diagram if this explanation isn't good enough, but this is how rotation of parented objects works:
If you make B the parent of C, and move C somewhere away from B:
C will store its position relative to B
So imagine C thinking "I'm 2m to the right of B"
If B rotates, the direction of B's right changes to match the new rotation
But C still knows it's 2m to B's right
So C will automatically stay 2m to whatever B's current right direction is, the whole time during the rotation
This is a perfect demonstration @ashen trail
just rotating a parent on its Y w/ the child object offset on the Z
You're all good, rotations can be hard to get your head around
Hi, anyone knows why I'm getting this error when trying to add this script to an object in the world ? There aren't any compile issues I don't understand
📃 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.
@fluid ether ^
check your console for compiler errors, and make sure you've refreshed if you have auto refresh disabled
yup, it's the one i show at the beginning of the video it's extremely simple but I wanted to test it
here :
using UnityEngine;
[RequireComponent(typeof(HealthSystem))]
[RequireComponent(typeof(IDamageable))]
public class Destructible : MonoBehaviour
{
[Header("Destruction VFX")]
[SerializeField] Animation Anim_DefaultDestruction;
[Header("Destruction SFX")]
[SerializeField] AudioClip ADefaultDestruction;
public void DestroyObject()
{
}
}
there are no compile errors, I'll check auto refresh
also your file is called destructible instead of Destructible
iirc the file name matching requirement was removed in 6.0, but you could try changing the name to be sure
I don't exactly know how [RequireComponent] works, but there are no components with those names on the object you're attaching to. Could that cause that error?
no
the IDamageable might be a cause, rather than RequireComponent though
So, when i tried changing its name from Visual Studio, I got this erorr and noticed that in Unity the script is name d"Destructible" but in Visual Studio it's named "destructible"
huh, never seen something like that
RequireComponent force adds the required components, since Destructible depends on healthsystem and Damageable interaface, i put them as required components, so if I add Destructible to an object, those required components will be automatically added at runtime
you can't add an interface though
Have you been able to add the script to any objects? If not, since it seems like some kind of metadata clash, it might be best to copy the script into a new file and see if that works
that might be why
there is this thread https://www.reddit.com/r/Unity3D/comments/59na4t/psa_you_can_use/
oh i can't ?
which, if true, that's... horrifying
interfaces can't be instantiated
you would need a component that implements the interface
perhaps try adding an IDamageable-inheriting component first, then the Destructible component?
if that works, it's probably this
well healthsystem does so i guess it's fine, since destructible depends on it i can have it (healthsystem) as a requirement, which gets added, and since that implements the interface then it's fine
oh, then yeah then requiring an IDamageable doesn't make sense if you already require a specific impl
haven't tested, no
i'll remove that requirement and restart unity and VS, some weird metadata issue might be going on since they're showing different file names
i don't think it's a metadata issue, it might be a caching issue
yes caching, im not too versed in that type of stuff i thought it was metadata but yeah i was thinking kind of in the same ballpark 😆
does anyone know why my bullets arnt firing?
they just kinda apear on where C(the direction they need to go) is and disapear
@naive pawn @placid jewel it's working now, thank you both 😄
Congratulations! What did you do to fix it?
Are you giving them any velocity?
removed the [RequireComponent(typeof(Interface))] and restarted both the editor and the IDE
But i think the source of the issue was actually some weird caching issue, not necessarily the interface being there, althought that would probably cause another issue in itself
Just so you know, Instantiate creates a gameobject, but the method itself also returns the created object. So if you do something like
GameObject bullet = Instantiate(...) //asuming the instantiated thing is a GameObject
```, you can directly refer to the created object
If you mean in the Instantiate(), the position there only controls its position at the moment of spawning. Anything else you have to do yourself.
I can't tell exactly right now what the issue is, but the OnCollisionEnter2D will trigger when the bullet (which I assume has a trigger collider2d) overlaps ANY collider. So if the bullet just flashes into existance then is destroyed, try temporarily removing the OnCollisionEnter to check if that's the problem, and if it is, add a further check for specific colliders instead of just any collider.
if youw ant proper collision detection you will have to use physics for your bulelts not transform position
i added a + before the = in the position and now it shoots right when i click but i want it to shoot in the direction of my cthing
and in your OnCollisionEnter method you will have to check for a specific tag
Oh I missed that
collision isnt a problem for me rn
Give it a rotation when it spawns that's the same as object B's rotation
(or just based on layer collisions)
ima try to figure all that out after this stuff
if you bullet comes in contact with any collider it will immediately be destroyed, including the spawn position(gun or player)
so i got it working but it works more like a onetime homing missile lol
is there a way to override a prefab in which a gameobject has been called?
What do you mean? Both in terms of what it's doing and what you want, I don't understand
so the black dot is the direction where i want my bullet(the triangle) to go, right now it is doing that but only for the first bullet(its a prefab)
i think thats because in some of the prefabs code i refer to another object
so it doesnt let me override all the prefabs if that makes sense
does unity not have a redo buttom cntrl shift z isnt working
public List<Upgrades> productionUpgrades;
public List<Upgrades> substanceProduced;
public Upgrades productionUpgradePrefab;
public Transform productionUpgradesPanel;
[SerializeField]
public BigDouble[] productionUpgradeBaseCost;
public BigDouble[] productionUpgradeCostMult;
public BigDouble[] productionUpgradeBasePower;
public string[] productionUpgradeNames;
public string[] substanceProducedNames;
public void StartUpgradeManager()
{
productionUpgradeNames = new[] {"Ghost", "Spider", "Skeleton"};
substanceProducedNames = new[] { "Ectoplasm", "Silk", "Misunderstandings" };
productionUpgradeBaseCost = new BigDouble[] { 25, 100, 1000 } ;
productionUpgradeCostMult = new BigDouble[] { 1.5, 1.75, 2, 3 };
productionUpgradeBasePower = new BigDouble[] { 1, 1, 1 };```
I fell asleep before I got to send anything more, whoops.
what is not working , could you share the code where you instantiate the bullets and the other script for moving the bullet
I'm unsure where to start with this.
Like a few bullets will fire normal then it will freeze and no more will fire until i click the exit program button and restart it @frail hawk
!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.
Uh is unity free enough for making and publishing a small indie game?
yes
when i try to fire it pauses my game
are there errors
Hello , i'm currently making a project with some classmates and we want to do a simple unity game for a arg but they want in sais game to be able to have a text files pop up in the games files after a input but i find it difficult to find any help on how to do it on the internet.
Could someone tell me if such thing are possible on unity and if so could help me?
hello guys i'd like to understand why this little script spawn a hundred , thousand copies even when there is a for loop ?
its not
which can mean a couple things
one guess would be, does that purplecube perfab have that script on it?
maybe unity didnt load but it would be weird ?
post code not image
one sec
closing and opening the project is an easy step to confirm
i found the problem though
it pauses my game when i shoot
ok
yeah its crashing my unity anyways 😅
#💻┃code-beginner message
i think as Batby said:
first step is by posting code
how do i post it as code
!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.
no this is still spawning a thousand cube
did you check this
i dont think i know what a prefab is 😅
is it spawning it self?
wait i check
that code that spawns cubes, is it on the cube that is being spawned?
ooohh
on your prefab there seems to be the same script , so every prefab on start uses the same loop
yess this it think so
ty
A tool for sharing your source code with the world!
i didnt think of that
a quite recurisive problem
show the inspector for your projectilebehaviour prefab
that makes sense now
i cant see the projectilebehaviour component in that photo
are you dynamically referencing orbitC
but your bullet prefab can only reference things in the context of that prefab
or you manually referenced it?
its manually as shown in the stuff theyve posted
oh yea the game isn't running
dont know the difference sorry
this my code though
you can't drag and drop orbitC into the prefab if orbitC is not a part of the prefab
oh
it's like selling a microwave that comes with the wall outlet it's built to plug into
it doesnt make sense
so the logic that is spawning in the prefab should set the orbit point as well
or you can use a find object by name, but that isn't the best practice.
its quite bad
the orbitC is just connected to something else inside of the player that gives it its position and stuff
sorry but im new idk how to do this
In the code that instantiates the bullet, you need to also set the orbit point
Might help to remember this
Since you're instantiating by reference to the bullet's script, you could do
so the code that is spawning the projectile can have a reference to the orbitc. so when you instantiate the bullet, you should also access the bullet component with .GetComponent<>(); and use a function to set the orbit
okay I'm going to try to do that
You could do something like```cs
ScriptName bullet = Instantiate(...) //replace ScriptName with the actual name
And then modify the value
that is if has the reference to the prefab as the desired class
I don't think getcomponent is needed here because it instantiates via an instance of the script
It's in the other script that was sent earlier
playerMovement bullet = Instantiate(ProjectilePrefab, transform.position, transform.rotation);
like this?
yup
Are you trying to get the bullet's Player Movement script?
yes but your field type for projectileprefab will have to change from GameObject to projectileBehaviour
and you might need to drag the prefab back into it in inspector
it already is I'm fairly sure
Unless it was changed
its gameobject here
Ah
yea i missread, it is supposed to be the class of the prefab you are spawning
Change it back to projectileBehaviour in both the declaration of ProjectilePrefab and this line here
so if it is being instantiated as a gameobject you would need to use the getcomponent<>()
or that ^
https://paste.mod.gg/ is the code looking right?
A tool for sharing your source code with the world!
i put a get component thing in there
public projectileBehaviour ProjectilePrefab;
``````cs
if (Input.GetButtonDown("Fire1"))
{
var bullet = Instantiate(ProjectilePrefab, transform.position, transform.rotation);
bullet.OrbitC = OrbitC;
}```
pretty much that
or projectileBehaviour bullet = Instantiate(ProjectilePrefab, transform.position, transform.rotation); if you don't like using var
im getting an error still, I apprieciate ur guys help and support, however its 4am rn and im really sleepy so I think i have to go
sleep and look at your code with fresh eyes
goodnight guys thanks for the help
anyone know if there is something synonymous to like UnityEngine.Component[] comps = gameObject.GetComponents<Type1, Type2, Type3>();
I cannot simply get all components and check vs an array or similar of the components I want since I cannot use nullable types in a NativeArray
you can't specify multiple types with GetComponent calls
what exactly are you trying to do?
I am trying to add select component objects that I need to use in ecs systems to entities
I cannot use nullable types
i mean, any class is nullable
perhaps ask #1062393052863414313
isn't ecs part of dots? im not super familiar
my problem is not with the dots part
dont worry about the context it doesn't really matter it's a basic thing
but I just would like some way to get an array or list of components of specific types
without like if comp == typeof(comp1) || comp == typeof(comp2) ... comp == typeof(comp17)
that's easy, but that doesn't sound like what you're doing?
sorry
you want multiple speciifc types, right?
specific types plural
it kinda sounds like an https://xyproblem.info to me, but i don't really have the background knowledge of ecs to really tell (that's why i redirected)
what's wrong with just doing multiple GetComponents for each type you want?
just feels like a bit bloaty
you could also GetComponents<Component> or similar to get all components, i believe
you need to specify 20 types anyways
feels a lot less neat
(ecs is apart of dots afaik)
because I don't see why it something like GetComponents<//multiple types here> doesn't exist tbh
wanted to ask in case there was something similar and I simply wasn't aware of it's existence
could make a utility method to take a params Type[] and return a Component[] if you're going to put them all into a shared array
its not xy problem though
generics can't be variadic
Not really something that comes up in c# and usually is a sign of something being done weird (usually)
it'd have to be 1 overload for 1 type, another for 2 types, another for 3 types, etc, to some arbitrary limit
(that's what Action or Func do)
yeah I suppose
if this is a common operation in ecs, then there's probably a better solution in ecs
the core issue is just Component is nullable so cant use it in unmanaged lists
so the core issue is in dots?
multiple things here are pointing to this being an xyproblem, tbh
if it is a common operation, or even a common operation in your project specifically, there could be better solutions in ecs, but you'd have to ask the folks in #1062393052863414313 to find out
I know its a very 'source: me' moment but you'd understand if you knew what I was trying to do
thanks regardless
will have to settle for just a bunch of ifs or getcomps
anyone know what the hell i did wrong here?
I have an animation in unity with a spinning wheel. It's just two keyframes, a start with rotation 0, and end with 360.
I intend to loop this animation to get a spinning wheel, but it "eases out" at the end of the animation and slows down into 360. How can I make it keep a steady pace?
any of your functions in the stacktrace?
you can view the dopesheet in the animation window and remove the smoothing
i believe you can rightclick to use presets as well, to get a nice linear rotation
how do i check that?
click the error log, see if there's a stacktrace
nevermind it magically fixed itself thanks for the help tho
ah, transient errors...
it's probably not your fault then, just something went wrong internally in the editor
You're the man
also, not a coding question, use #🏃┃animation for questions like this in the future please
Gotcha, thanks again, looks super good now
yo anyone's using Cursor as ide? Im new to unity and tried to integrate but intelisense isnt working. Ive installed the sdk
only thing I havent made was installing the unity and c# extensions cuz vs studio blocked microsoft extensions for cursor
the unity and c# extensions
well, that would be how you get intellisense
Cursor is VSCode so you've got to follow the VSCode instructions
And yeah if you haven't done part of it that would be why
hi, do you guys know what's wrong in this line: Door[] doors = FindObjectsByType<Door>(); ?
ye ty
I'm lazy to read a documentation on this , but I just need to put in a SortMode right?
SortMode.None, works? is it like finding the first one in the hierarchy?
No sorting is a lot faster if you don’t need to care
Your doing findobjects
Sortmode none returns them all in whatever order ended up fastest to return
ohh okay yea its great, that's what u said when u told me no sorting?
or is that like another function u'd advise me
K ty so much
public class LevelupButton : MonoBehaviour
{
private GameObject _levelupScreen;
public void OnEnable()
{
_levelupScreen = GameObject.Find("Levelup Screen");
}
public void OnClick()
{
Debug.Log("levelup selected");
GameStats.isgamepaused = false;
Time.timeScale = 1f;
_levelupScreen.SetActive(false);
}
}
the button isnt pressing for some reason
event system in scene?
yup
do you have cursor locked / hidden ?
unless you've changed the buttons to not have any highlighting when hovering too then it isn't responding to any input. which could mean one of a few things, missing event system, something blocking it, cursor is actually locked to the middle of the screen
it probably is something blocking it but isnt the ui supposed to be on top of everything?
other ui objects could be blocking it
imagine if that Rect Transform of that 100 text is like HUGE and covering the buttons
for example, if someone had a UI object that looked like some girl holding a spoon and that was a raycast target and between the cursor and the button
i only have these ui objects and the hptext is not blocking anything
do buttons not work when Time.TimeScale is set to 0?
they do
ok show the HP Text then in scene view selected
or move it all the way at the top..
Bottom = Ontop of everything (for UI)
Your ui isn't getting highlighted when hovered over which is quite strange. This usually implies that the raytrace is either blocked or isn't happening.
make sure you anchor properly and the rect transforms are proportioned cause Free Aspect can throw you off (canvas mode is important )
box collider is irrelevant unless you had Physics Raycaster on the Camera
Yea you don't want or need to use physics colliders on ugui elements...
did i break my event system somehow?
if only unity didn't butch the new event system that shows nothing useful for hover
i tried disabling everything and adding a fresh button but that still didnt work
Is the cursor an in scene object?
nope
Maybe try making a new scene with the bare minimum and see if the buttons works.
So ideally: the camera system, buttons (enabled along with the canvas etc) and event system.
hi , is it possible to add a text files in the games files after a input is pressed?
yes
huh. that doesnt work for some reason but i did get these cool errors
tkx , i've been searching for hours how to do so but knowing it is possible already helps
what does "add text files" mean?
what text files, thats pretty broad.
File.WriteAllText for example is the simplest way to create a text file
They probably mean something else 😆
virusmaker3000
why do so ppl use if statements without curly brackets?
Second error says your camera object is missing a component. You might want to use a similar setup compared to your other scene.
look for stuff related to System.IO or JSON a file type commonly used cause it's human readability and it can store game variables and read them
basically for a arg project i need to make a little game which when a certain event happens add txt file in the game files
tkx , will do
Its just cinemachine
are you wanting to read data off these text files later or just for them to exist?
Cinemachine still uses Cinemachine brain on the Camera component though
unless you didn't add that..
the brain is meant to be on the camera?
whoops
i just need them to exist for the player to go in the files and read it
im pretty sure it adds automatically (just checked)
Preferences. Other than that, it can only be used when you're wanting the body of the if statement to be a single statement.
if you add a virtual camera sure it usually does
the brain is what controls which VM camera shows. The cameras themselves are "virtual" hence not real camera components
i've always put the brain in it's own object and the cinemachine camera on the camera :/ (though i also only ever work with one camera)
thats why adding like 20 VM does no impact on the game than adding 20 Camera components lol
idk about that, I suppose as long as it finds 1 unity Camera component, should be fine. I never do it that way though.. too confusing
can you have multiple brains?
maybe.. I dunno
..Probably
full video of my attempt
either way it should not affect UI afaik
try without a custom cursor
maybe the hitzone is off or something
still not working
oh that cursor is Your OS not unity ?
yup
maybe try a brand new project with same unity version and test , try to narrow down if its a project issue or editor issue
idk if something obvious is missing
Delete and re make the event system? Check if it has any warnings on the components too.
this is a fresh scene
Can you show the inspector for the camera object and scene view?
i've finally sorted out my enemy navigation issue and now i want to move on to implementing items
does anyone have any good guides on how item systems in roguelikes are programmed?
i've tried asking in the ror2 modding server but i haven't had a response yet
i'm very new to this so i'm not entirely sure how i would do it
there is no straight answer or specific guide on this, every system is tailored for specific needs of the project
ah
you would be essentially cloning/following someone made up system , it may be optimal or complete shit. its a gamble
Plan out your requirements , start small, build up the system.
and if i can't get this right then i probably won't be able to move forward
every complex system is just a bunch of smaller systems working together
i don't even know how i'm going to manage the inventory
that initself is a problem, if you don't know your goal how can you achieve it
research a bunch of different systems, find out about them and get a rough idea on how you could approach it
since all the items are either going to be utility, health/regen, damage or the like
i'll just give something a try for now
eg . would it behave like Risk of Rain? or maybe Hades? etc.
risk of rain is my main idea of what to do
the overworld items are just sprites with different ids dictating what they look like and what they give the player
implement a stat system first if you haven't then find ways to affect them
i've kind of done that
if you mean visually thats the last step (sprites and all that)
i made sure to keep that in mind when i was making my player's abilities
does that game even have an inventory? i though it was just a dictionary with the item (a class) and the count
its the default camera you get when you add one
you can even use a list of Scriptable Objects to serve as plain stats to add
like the more SO of Health you collect, the more health you have etc
or POCOs, or both
oooooh oki, I tried to add more lines under this if statement tyle and it gave me error, now I get it kek
thanks
If the scriptable object is just a source of read only data that's a good idea
But may not be preferable to just use many references to one for a complex stat/effect system once applied to some entity
alright i reinstalled the project, wish me luck.... and its still broken
why my gameobject sprite renderer is blocked? Ive just created it in an another gameObject parent
I mean i cannot drag and drop a sprite on there
and I cannot edit anything inside the Sprite Renderer
you have it collapsed
press the little arrow here
on the left
god damn, sorry guys, first 30m on unity lol
This is not a code question btw
in the future this goes in #💻┃unity-talk
sure! thanks
guys how do I make my bullet fire in my game?
i want it to fire in the direction of the black square
!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.
you can calculate the direction from point A to point B as (B - A).normalized
this is my code
A tool for sharing your source code with the world!
what does this code have to do with your question?
To clarify, the B and A in (B-A).normalized are Vector3s, of Transform.Position of object B and A
you did not share your code
look at the player movement cus use the prefab there
i dont know ifim doing it right
you haven't saved
yes
this code is something called "Trap"?
Yeah that was to @ashen trail not my own question
oh whoops, mb
that may be the paste you had open last.
do u guys see the code now?
Yeah that was just a link to pastebin.mod.gg, it opened code for a mesh-based script I had been helping with before and I was extremely confused lol
when i click my bullets only can fire for a little bit of time like 2 secs, then when i click anothor bullet doesnt fire
bullets only work at the beginning of my game
player.transform.forward = target.trasform.position - player.transform.position
Fire()
Can you send the script that creates the bullets also?
it's in the player movement thing for some reason
like wher they are Instantiated?
yes
there in the player movement script
this is not correct for a 2d game
also their projectiles don't care about player forward
Oh I'm unfamiliar with pastebin I hadn't realised I could see both scripts
Its just an example
have you tried adding debug logs to see what happens? whether they're instantiated, maybe if they're immediately destroyed, etc
this person has no idea what they're doing - they aren't going to be able to adapt it.
when i click this is what happens
i get that error
How is your bullet stored? Is it with a prefab?
i think it is a prefab
It is
did you take that screenshot at runtime?
no
should i get one like that too?
no reason really
yes
you did, and then you assigned the OrbitC from within the scene, didn't you
yah
that's probably part of the cause
so first off, remove that Bullet object in your scene
First thing is you need to assign the ProjectilePrefab as the one from your Scripts folder (But maybe take it out of scripts as well)
instead of GameObject, type the prefab field as the component that you actually care about, projectileBehaviour
is the problem that they arn't both prefabs? the bullet and orbitc
then you can assign OrbitC when you instantiate
(also bring up previous help you’ve already received so it doesn’t restart the troubleshooting process)
hi
when i created a new project, it came with a input action by default (universal 2d) , was i not supposed to remove that?
i've a bird in scene but it isn't showing up anymore
i tried disabling everything i can
i appreciate any help on this
you were probably not supposed to remove that
oh
It's z value is at 8
that's its scale, unrelated.
and if it was the position, it'd be fine
So it is
this is also the code channel and that's not a code issue, actually
Can you send a screenshot of the camera the way you did of the bird in the inspector?
True
@severe dagger continue in #💻┃unity-talk, and show your camera's inspector there
Send this along with what you've previously said in #💻┃unity-talk
if the camera is at Z:8 then the bird is behind it on account of it being at Z:0
aight . sorry for bringing it in wrong channel
@severe dagger
they didn't show the camera though
i was just going off the words they said. pointed out their issue in the other channel
that was another person that read the inspector wrong
ah my bad
Anyone know of some good game ideas to make as a begginer? I have like 2 months expierence probs by now but not sure what to make.
HOLY sh*t, i got it working, couldn't really tell u how but for now it works
snake, flappy bird, minesweeper, pong
done flappy bird and pong, I only really do 3d in the engine as find it more fun
then make 3d flappy bird, pong, minesweeper, or snake
tbf i havent made a 3d flappy bird only 2d
hello im not really sure why this started happening lately but for some reason, i keep getting this message seemingly randomly and it infinitely loops which messes up my animations i worked on, whether i saved or not
does anyone know why this happens?
try close unity, deleting library folder, open project, let it rebuild..then open scene again
using System.Runtime.CompilerServices;
using Unity.VisualScripting.InputSystem;
using UnityEngine;
using UnityEngine.ProBuilder.MeshOperations;
public class Player : MonoBehaviour
{
[SerializeField] float moveSpeed = 7f;
[SerializeField] float rotateSpeed = 10f;
[SerializeField] private GameInput gameInput;
private bool isWalking;
private void Update()
{
float playerRadius = .7f;
float playerHeight = 2f;
float moveDistance = moveSpeed * Time.deltaTime;
Vector2 inputVector = gameInput.GetMovementVectorNormalised();
Vector3 moveDir = new Vector3(inputVector.x, 0, inputVector.y);
bool canMove = !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDir, moveDistance);
if (!canMove)
{
//Cannot move towards moveDir;
Vector3 moveDirX = new Vector3 (moveDir.x, 0, 0);
canMove = !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirX, moveDistance);
if (canMove)
{
moveDir = moveDirX;
}
}
else
{
Vector3 moveDirY = new Vector3(moveDir.y, 0, 0);
canMove = !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirY, moveDistance);
if (canMove)
{
moveDir = moveDirY;
} else
{
//cannot move
}
}
if (canMove)
{
transform.position += moveDir * moveDistance;
}
isWalking = moveDir != Vector3.zero;
transform.forward = Vector3.Slerp(transform.forward, moveDir, Time.deltaTime * rotateSpeed);
}
public bool ISWalking() {
return isWalking; }
}
guyss help i can't move
is there anything wrong with script
best way to test your script and get information whats wrong etc is chatgpt or grok i think its the fastest way to analyse it
this is uity error
i did
it didnt help
instead it was showing more errors
Are you using Adaptive Performance?
Then the message doesn't mean anything
i fixed it
oh
It says that Adaptive Performance isn't going to be doing anything until you finish configuring it, but if you don't intend to use it anyway it doesn't matter
i get it
it had nothing to do with
it was misplacement of else statement i had to place in under if statement
I'm making a custom level for a game I like which will require some custom code and I see that the scripts the developers made have these nice UIs that let you easily set numbers and add objects and such. How can I add these to my scripts?
those are just serialized variables. either public or marked with the SerializeField attribute
Have you gone through the basic Unity tutorials?
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
This stuff is covered pretty early on
I haven't done them, no
yeah you're toouching on a pretty basic functionality of scripts in Unity here.
Can I have some help with a health bar?
!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
pay particular attention to the last couple points
int randomIndex = Random.Range(0, _nestSpawnPoint.Length);
Vector3 pos = _nestSpawnPoint[randomIndex].transform.position;
Quaternion rot = _nestSpawnPoint[randomIndex].transform.rotation;
_antNest = Instantiate(_antNestPrefab, pos, rot);
im trying to instantiate something from a prefab and keep the instance,. But for some reason when i do this in the awake function, it breaks out of it on the last line here and no instance is created. Does anyone know why?
it breaks out of it on the last line here
what do you mean by this
Yes, please explain what you mean by, "breaks out of it," and this is how to post your !code . . .
gotta have commands at the beginning of messages with the new bot
What, for real?
📃 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.
That's madness . . .
I cant see my ui text in my game
any reason?
- not a code issue
- it's not actually within the bounds of your canvas
It's outside your canvas, which is the box in the top right here
oh okay
thanks guys
its not letting me move the canvas for some reason
like i want it over my camera
you can't move the canvas
that's not how it works
so i have to move my project insde the canvas?
no
you have to move your UI inside the canvas
the canvas will be overlaid on the screen
Double click the canvas in the hierarchy
so you can see the full thing. Then you can lay out your UI inside it
ignore the game world objects when working on the UI
And again this is not a code discussion
ohh
okay i did it thanks for the help
i wanna use a use a Spline data type and name it ObjectSpline, but i don't get how it's not working. I thought i would just smack the Spline highlighted in blue inside the hierarchy into ObjectSpline slot that was supposed to appear, but it somehow did not. i am kinda confused
it's a probably SplineContainer not a Spline
oh ya... it does have the spline instantiate component in it which has a spline container which points to it. how would i go about creating a Spline object then?
what are you actually trying to accomplish here? because from what it sounds like, you want a reference to the existing object in your scene. which contains a SplineContainer component
i wanna access the ElpasedTime and Duration properties of the spline to make the t ratio
neither of those are properties on a Spline
those sound like things that are likely related to your SplineAnimate component though
oh ya, it is. i think i can access it then pretty easily...
considering you already have a reference to the SplineAnimate component, yeah. but also what specifically are you doing with those properties? 🤔
i have two animations for the duck, one for when it goes towards the right, and the other which is basically the same animation but flipped. i wanna know which direction the tangent of the knot the duck is currently at , points to, to trigger a specific animation
to do that, i need to use the evaluatetangent method, which requires an arg called ratio t, which i can get by doing ElpasedTime/Duration
then you do still need a reference to the SplineContainer
oh, the method's a member of this type?
so, my code was working perfectly before, then i tried changing the diff objects to [serialisedfield] which i think kinda broke the code?
show what the code currently looks like
so what exactly is "broken"?
the ducks ain't spawning anymore...also, it shows that destroy is being called even after a duck is destroyed? it spawns just one duck and then stops working
when i press space, the ducks should spawn...
wot
you enabled the one you were cloning which means it is also moving so it gets destroyed
also why do you have a separate "Duck Script" with the component that is only supposed to be on the ducks on it?
can anyone teach me the basics of scripting, or any tuto
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
ah i see
there are also beginner c# courses pinned in this channel
tysm
oh...that's why people disable it...aight
preferably you'd be using a prefab rather than a scene object so you can't run into this issue
lemme try something out, it might work...
alright...so it didn't rly work. i noticed something else which is pretty unusual
i pressed space, the duck got cloned. it didn't start moving until i checked it out O_O
i still think you should consider using a prefab instead of cloning a disabled object
but what you need to do to fix what you've shown should be fairly obvious
i think i do understand it, lemme explain then, and you tell me whether it's right or wrong
so before i even start playing, i have a object Duck, and when i reference this object inside the DamnDeseDucks script by dragging it onto the variable listed in there, this Duck gets referenced by adress. so when i do press space, and then it destroys itself, it returns a null reference anytime i start pressing space after it because thie Duck object gets destroyed. this doesn't rly explain to me why enabling the cloned ducks makes them work though...
it's not "DamnDeseDucks" that is breaking here, it's your poorly named ISpawnable which is breaking when the object is destroyed because it's trying to reference that destroyed object. Although presumably your extra DamnDeseDucks component that isn't even on a duck for some reason probably references that duck that was getting destroyed. So what you need to do is remove that object entirely because it is pointless. Then also fix your spawning logic so that the instantiated objects are enabled after being instantiated or you need to make that initial Duck into a prefab so that you can clone the prefab and they will be instantiated enabled
using UnityEditor.ShaderGraph.Internal;
using UnityEditorInternal.VersionControl;
using UnityEngine;
using UnityEngine.Splines;
using System.Collections;
using System.Collections.Generic;
public class DamnDeseDucks : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
[SerializeField] private GameObject Duck;
[SerializeField] private SplineAnimate aniSpline;
Queue<GameObject> cloned_ducks = new Queue<GameObject> { };
void Start()
{
aniSpline.Completed += onComplete;
Duck.SetActive(false);
}
// Update is called once per frame
void Update()
{
Debug.Log($"Ratio t is: {aniSpline.ElapsedTime / aniSpline.Duration}");
if (Input.GetButtonDown("Jump"))
{
Debug.Log("Space is pressed.");
GameObject temp_duck = Instantiate(Duck, Duck.transform.position, Duck.transform.rotation);
temp_duck.SetActive(true);
cloned_ducks.Enqueue(temp_duck);
}
}
void onComplete()
{
GameObject ducktodestroy = cloned_ducks.Dequeue();
Destroy(ducktodestroy);
}
void spawn()
{
}
}
i tried out something like this, but i still don't understand, how the hell was the code working previously with 2 different classes then??
how
why did you combine the two components? they should be separate
spawning should not be handled by the thing that is getting spawned
i think i misunderstood you then
" So what you need to do is remove that object entirely because it is pointless." oh...not remove the class
mb
yes, remove the random "Duck Script" gameobject that served no purpose except to cause issues
ehm..i undid the whole change, and...its showing the same error.
which error is it showing now
clones get made unchecked.
should i send a list of imgs and show what is being referenced where along with the code again?
that's not an error. and you just need to enable them immediately after instantiation like i suggested.
or use my other suggestion and use a prefab instead of a disabled scene object as the cloned object
they don't get destroyed in that case though...if i manually check them during runtime, after they complete moving along the path...they just, stay there. they don't get destroyed
show the code on the "DamnDeseDucks" class
using UnityEditorInternal.VersionControl;
using UnityEngine;
using UnityEngine.Splines;
public class DamnDeseDucks : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
[SerializeField] private GameObject Duck;
[SerializeField] private SplineAnimate aniSpline;
void Start()
{
aniSpline.Completed += onComplete;
}
// Update is called once per frame
void Update()
{
Debug.Log($"Ratio t is: {aniSpline.ElapsedTime / aniSpline.Duration}");
}
void onComplete()
{
Debug.Log("Duck will be destroyed.");
Destroy(Duck);
Debug.Log("Duck was destroyed.");
}
}

i don't think i am....
what do i even put inside the Duck variable...i am assuming it's supposed to be the cloned duck
why do you still have that
you said remove this thing
maybe i misunderstood

yes, the DamnDeseDucks component belongs only on the ducks
and i really wish you used sensible names for things
this component is what effectively manages each individual duck
it's on the duck
and notice how nothing is assigned to the Duck variable. not that the variable is even needed considering every component already has a reference to its own GameObject using the gameObject property
i will read up on it
yes
there are naming conventions and they help to keep things organised, especilly when getting help from other people
theres some youtube videos that could show you
i know interface use Isomethingable but i don't know the others
read up on what? naming? your names are just bad in general because they imply they are used for different things which is probably leading to a lot of this confusion.
"DamnDeseDucks" despite implying it manages more than one duck is only controlling one duck at a time, it's basically a DuckController. Your "ISpawnable" component implies it is something that can be spawned and that it is an interface. It should have a name more like "Spawner" or "DuckSpawner"
the issue isn't about conventions, it's just about you using confusing names that imply something different than what they are
ah ok
continue this though
wdym? that's a complete statement
"and notice how nothing is assigned to the Duck variable"....i thought....it required a continuation
oh wait
it worked
i was telling you to notice in your own screenshot that literally nothing is assigned to that variable. then i went on to tell you what you should be using instead
i don't know how but it worked
i just assigned the duck to it and it started working
right, but again that variable is absolutely pointless. you already have a reference to the gameObject via the appropriately named property called gameObject
wait then if i were to remove it, it would still work?
provided you actually pass the gameObject property to Destroy, yes
so just so that i don't misunderstand, what you are saying is that there is a way to make a script reference a gameobject which it's attached to without manually doing it in the inspector...ryt?
O_O gameObject is the GameObject the script is attached to
yeah theres a few ways
you can ask it to search for other objects by names or tags, or you can search for the gameobject component in parents and children
thx
oh yeah, you dont have to reference the game object that the script is attached to, but if you want to remind yourself in the code you can type "this." before your code eg. position = this.transform.position

good luck youve got this
now that you've got that sorted out, consider looking into how you can use prefabs instead of relying on cloning disabled scene objects
hey boxfriend, any chance you could help with an issue im having? you seem knowledgeable
!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
guy's goated for sure
No you ask the question directly so anyone can help you
okay thanks
could there be a particular reason that when i use getaxisraw ("Horizontal") it'll only one of the two keys?
i press the other key attached and it does nothing
it moves in the right direction with W and D, but otherwise I can't use S and A
📃 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.
https://paste.mod.gg/pxvgdyjjnqst/0
the script is for a prefab and OrbitC is an object in the inspector
i get this error when i try to shoot, any idea why
A tool for sharing your source code with the world!
Horizontal is only (A/D)
W or S got nothing to do with it
well yeah, i know
i'm asking why neither Vertical nor Horizontal aren't accounting for their negatives
show the inspector that is assigned.
check the InputManager
already checked
someone has answered this twice
can confirm that the negatives are still the opposites
probably but i still dont get it
it's available to read again if neccasary
show the relevant code
ima scroll up till i find it ig
if (Input.GetAxisRaw("Vertical") == 0)
{
rigidBody.AddForce(transform.TransformDirection(0, 0, force * Time.deltaTime * tSpeed));
}
else
{
rigidBody.linearVelocity = Vector3.zero;
}
if (Input.GetAxisRaw("Horizontal") == 0)
{
rigidBody.AddForce(transform.TransformDirection(force * Time.deltaTime * tSpeed, 0, 0));
}
else
{
rigidBody.linearVelocity = Vector3.zero;
}
it looks wonky but it's because i'm trying somin
I had written this before and encountered the same issue, so i changed it out for keys instead, and then someone sent me their code for movement, which worked on their end, but DID NOT work on my end
try
var horiz = Input.GetAxisRaw("Horizontal");
Debug.Log($"horiz {horiz}");```
press both A/D and see if you get the correct vals first
*assuming it should appear in console or something?
yea you put it in update ?
hmm, nothing is showing up in the console.
are logs enabled?
i assume you mean player logging?
yeahj
is it on an active gameobject , and is enabled
forget that
and it responds to the force
nothing is being printed in the logs when I do anything
but is it printing "horiz 0" at least or not printing at all
nothing at ALL
send the code in its entirety through site
(Did you save the script)
(yes lol)
!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.
Your saying lol but something you’ve said isn’t true so
{
public int force = 10;
[Range (0f, 100f)]
public float tSpeed;
Rigidbody rigidBody;
float horizontal = 0f;
float vertical = 0f;
void Start()
{
rigidBody = GetComponent<Rigidbody>();
}
// Update is called once per frame
private void Update()
{
Mathf.Clamp01(force);
var horiz = Input.GetAxisRaw("Horizontal");
var vert = Input.GetAxisRaw("Vertical");
}
private void FixedUpdate()
{
Vector3 moveDir = new Vector3(horizontal, 0, vertical);
if (Input.GetAxisRaw("Vertical") == 1)
{
rigidBody.AddForce(transform.TransformDirection(0, 0, force * Time.deltaTime * tSpeed));
}
else
{
rigidBody.linearVelocity = Vector3.zero;
}
if (Input.GetAxisRaw("Horizontal") == 1)
{
rigidBody.AddForce(transform.TransformDirection(force * Time.deltaTime * tSpeed, 0, 0));
}
else
{
rigidBody.linearVelocity = Vector3.zero;
}
}
no i'm saying lol because that's the first thing i checked
theres some other nonsense in here
bro didnt even put Debug.Log
also every time you don't press a Horizontal or Vertical so when you press one you immediately override it with 0
so you're not gonna believe this, it still doesn't work
what doesn't work
computer is never wrong so you probably did it wrong
you'd think
either again you didn't put the line or didnt save
(We know)
it should print at least 0 even if somehow the Horizontal/Vertical was busted
ok well show something
show something?
yeah like idk show the game running or something with the console window ?
or that you put the line in and saved
I can't see your computer what can I do with little info you give
the logs are literally disabled
I even said make sure they're not
can't trust anyone on the internet lol
man
ok so now what does it print when you press A or D. do you get 1 and -1
so A/D does work for horizontal
then something is wrong with how you apply that
tSpeed is also 0 I dont even know how you claimed this moved at all
i guess but you still aren't applying it with the horiz or vert
it'll be really funny if it is tSpeed
you made different variables and are applying none
rigidBody.AddForce(transform.TransformDirection(moveDir) * etc
horizontal = Input.GetAxisRaw("Horizontal");
vertical = Input.GetAxisRaw("Vertical");
that should probably work, or maybe InverseTransformDirection(moveDir)?..forgot which..
that clamp01 is also doing nothing by itself btw
guhh.. i think i need to take a break and come back to this later
the previous code I had worked by seperating each direction into if inputkeys, and just adding -force to the if that belong to A and S
Hiya friends
family and hopefully human beings
What are some functions to use for camera bobbing?
sin/cos
that depends on speed? But for now, just for sprinting and walking?
or like use the built in noise from cinemachine
noise?
I see
most games don't bob the camera itself though, usually its done on the meshes / whatever you're holding