#💻┃code-beginner
1 messages · Page 669 of 1
#763499475641172029 should be able to help you
oh ok
I see, thank you
Can someone help with implementing this? i'm trying to work on a platform that looks like a cloud where the character can go through and the platform will apply a sine wave from where the character went through, how can I do that?
What do you mean by "apply a sine wave"?
You just mean a visual effect?
Use a particle system or VFX graph
I don't need the particle system, I need the red visual effect
is VFX really needed?
either a particle system, or an animation w/ multiple sprites
heyo
just getting started with unity installed vs 2022 with it but for me whenever i try to create a c# script it only shows monobehaviour script as an option
is it the same thing or is something wrong?
They just renamed the menu option
It's the same
alr thanks
a question on vfx graphs: how to call the graph in the scene? I'm have a config like the photo attached and looking to both activate the hitbox and the vfx when the input is given
Like pretty much any other component, get a reference to it then you can call functions on it
The component is called VisualEffect
and the hitbox is swinghitbox sth like that
my question is if I spawn the Visual effect is it gonna stay in place or follow the player?
If you're doing a melee attack or something I highly recommend direct physics queries rather than enabling/disabling a collider
That depends on how you set things up
Is it a child of the player?
Is the graph set up for World Space or Local Space ?
I have a timestop mechanic which pauses all vfx and hitboxes from colliding during that period of time
so it should be global position once it spawns in i reckon
it's going to spawn relative to the direction of vision as a global object
if it needs to follow or track the player or something
as praet said it depends on the set up.. (it'll need to be attached to the player as a child object to follow along with it or have a script track the transform and position it) and the World Space/Local Space settings in the component itself will matter
how do you turn local into global? I'm thinking of getting the local camera forward vector and use it as the basis
and if that's the case, does using collision queries even work?
via transform.forward - something that's at Vector3.forward in local space is at transform.position + transform.forward * transform.lossyScale in global space
you could also use the Transform methods to let it do the math for you (TransformPoint, TransformDirection, etc)
so when I do an object cast, I pass the camera transform into it, correct?
what do you mean by "object cast" exactly?
I'm trying to make a hitbot for a melee attack
so someone from a few messages ago mention using a object cast
And I was a bit confused as to how to implement it
transform.position is world vector..
transform.localPosition is the local vector
im pretty sure theres methods to convert them as well
edit: nvm.. the conversion are for directions.. Not positions
well... physics casts? not object casts
there are a lot of casts that take different parameters
But can you pause the physics cast or should I just use a coroutine for it
just however u logic is setup
you can't pause a cast, it happens instantly
So I only call the cast whenever some condition is fulfilled, got it
...when you attack
you'd just do it whenever you want to register the hit
could have an animation event, or some coroutine delay, etc
or could happen immediately if you want to do that
yea because I need to pause the hit/delay the hit from registering whenever I decide to press hit within timestop, so I was thinking about this
well if everything is using scaled time then you could just have it set timescale?
I'm not using timescale but rather an external variable that dictates whether I'm in timestop or not
because timescale would prevent my player from moving
make it so if time is stopped then you cant attack
(i mean you could use unscaled time for that but i digress)
so you could just disable animations etc when time stops, no?
but that's a bit lame, I'm thinking more of registering the input happening and spawning in the hitbox but pause the hit registration until after the time have been resumed
for timing, you would just keep track of time yourself, and stop counting when time stops
so that would be unscaled time for the player and scaled time for everything else
which would also fix the issue of the hitbox thing since it spawns into timescale 0 and only continues its behavior after when time is not timescale 0, correct?
well, you aren't using timescale, no?
not currently but I mean I could pivot right now
could that be done if he's using a rigidbody to move though?
I'm using a kinematic motor so that's fine
they do respect timeScale iirc
I've read that rigidbodies cannot move in timeScale 0 due to being physics objects
yeah
ah.
i mean, they respect timeScale so that makes sense - does that still apply to a kinematic rb that you move yourself?
I'm not sure, from what I've tested, it stops kinematic motors too
but that depends on update, and when timescale is 0 update is not called
(im not sure if this statement is true or not)
right now I could test by changing all time references into unscaled time
that doesn't sound right
and then manually set timescale to 0
im not too familiar with kinematic rbs tbh, could you explain what you mean by "kinematic motors"
just player motor (movement behaviors) dictated by maths rather than physics simulation
for example, I need to manually make gravity happen by applying gravity*time.deltatime on the current velocity
Velocity shouldn't do anything if physics is not ticking
yeah deltaTime is unscaledDeltaTime * timeScale
unscaledDeltaTime is the true time between frames regardless of timeScale
setting timeScale to 0 means deltaTime is 0 - giving the effect of time not passing
so if you want your player to move normally regardless of timeScale, you would use unscaledDeltaTime
but unscaled should still tick because it does tick when even if the editor is paused
alright, lemme try it out
it's not working
i mean.. if you want help with that you're gonna have to provide some more info
what did you do, and how isn't it working?
swapped all instances of time.deltaTime into its unscaled varient
probably due to the interface I'm using (https://assetstore.unity.com/packages/tools/physics/kinematic-character-controller-99131) it broke
Hey I'm trying to make an balatro style background or something like that does one have a good tut I could follow. Just good background overall are appreciated in a balatro style game
You mean the swirly color stuff? Most likely it's a shader
Here someone did a shadertoy:
wow
It's a shader so neither
ah
HLSL or GLSL or something
Hope chatgpt tells me how to implement is thank you I will probably be back with more questions or it works!
Nobody wants to learn anything anymore 😦
I'm learing trough chat gpt it is my buddy. Tbh learned alot trough it. (Could have probably learned more if I figured everything out myself)
This server has been my buddy man
I've been learning from scratch and this server helped me a lot aside from video tuts
it's not bad at explaining stuff, yeah, but it's a little dangerous because you never know if it's making things up or not.
But I guess you could say that about people too
word
the ai has more of a reason to lie
Maybe I will try to ask for more help maybe it is going to make me a better programmer
I know this because I did try using gpt like once
and I gave up because it was not good
it gets less likely (to get a final incorrect answer) as there are more people to check/verify though
also a key thing to note about this, I think when I passed unscaled time, update velocity could not reference the interface
mayeb there's some potential issues over there
shit i forgot to get back to you one sec
lmfao
that feeling of "hmm i forgot something.. oh well"
can you show the relevant code, and explain how exactly it "broke"
!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.
yea
so deltaTime is handled internally then, probably...
you move based on changes to velocity on currentVelocity
A tool for sharing your source code with the world!
if I could go into their interface and change it
maybe
well, not the interface, the motor class
i mean, given that it's an asset rather than a package, you definitely could do that
not sure i'd recommend it, for the purposes of having the same behavior as, for example - other people, fresh installs of the same asset, etc
also you'd have to be smart about modifying it
does nothing else have a KCC? modifying that motor class would make that change apply to every KCC
not currently
what about extending the KCC, if some stuff isn't private/internal?
my idea of a equivalence of the same function is to store velocity and stop all movement
so then whether its a rb or kinematic it'll still be fine in timescale 1
(for rb I just change it into a kinematic object temporarily)
could be doable, but I'm a bit too new for it
it's like 3am here so i gotta dip
I'm probably gonna ask agin tomorrow or somethingh
@shut swallow so KinematicCharacterSystem.Simulate takes a deltaTime
if Settings.AutoSimulation is set, then the method is called on FixedUpdate and uses deltaTime, which is scaled
you could set AutoSimulation to false, then call that method yourself using unscaledDeltaTime/unscaledFixedDeltaTime
you'll also have to handle interpolation yourself
here's how KinematicCharacterSystem does the FixedUpdate
private void FixedUpdate()
{
if (Settings.AutoSimulation)
{
float deltaTime = Time.deltaTime;
if (Settings.Interpolate)
{
PreSimulationInterpolationUpdate(deltaTime);
}
Simulate(deltaTime, CharacterMotors, PhysicsMovers);
if (Settings.Interpolate)
{
PostSimulationInterpolationUpdate(deltaTime);
}
}
}
interp is gonna be a dumpster fire
it's just calling those methods
but I could change deltaTime into Time.unscaledDeltaTime no?
yeah
or would that break it
that's pretty much all you'd change
fair enough
I did read the config once, not sure if that's the only thing to change
but good to know, thanks a lot
is Time.time scaled?
seems like interp also needs some changes
yes
easy litmus test - if there's an unscaled version, then then version without unscaled is scaled
ight
The good thing is I looked through the kcm I don't have to edit anything there
but the kcs I need to change
Hey, how i can make an object/actor (wich has a rigidbody2D) move to an specific patron? Like, i want it to move its path into a triangle, how?
math, generally
there are tons of approaches to do it
tweening libraries, MoveTowards/SmoothDamp, setting velocities, adding forces, etc...
oh, so the addforce thing, nice
or, maybe i can add different points inside the game object, to wich it will be coded to try to substract the position distance until it reaches and then do it again with the other points... or this is a bad idea?
Isn't addforce for rb?
well, it's not inherently bad
i mean, the actor has a rb
i mean, they never said it was a kinematic rb
i think it is
Oh mb
i mean, what kind of rigidbody has gravity and stuff?
I read rigidbody as kinematics
but even with that you could still get away with not much math
Damn I need sleep
built-in? that's a dynamic rb
It's 4am 🫠
ah yes, dynamic, now i remember
you can check the "Is Kinematic" checkbox - if it's false, it's dynamic
i mean, i want my enemy/boss to do cool stuff like the Mantis Lords from Hollow Knight, or Gabriel from UltraKill
That's more enemy AI
Finite state machines and the such
I'm rather unfamiliar with those bc I'm also learning
It is really bad if my enemy AI doesnt have states machines?.....
hey can i get some help? im trying to make an asset bundle
Not bad, but it's important to have one if you are trying to make something complex like Gabriel
Good practices ig
can any of you help me?
Not too familiar with asset bundles but I recommend reading up the API (but you've probably done that already)
: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 #854851968446365696
So, quick pivot - I'm making a FAR easier game to start off in Unity. I jumped into the deep end a little too soon. It's a robot battling game, with Local/Networked multiplayer in mind for the future.
But for now I'm setting up player control and basic interactions. Players control a single robot they've designed, and fight in an arena against other robots. Before a match, players design their robot and they can design the AI's robot or leave it to chance.
Can someone help me think through the logical level of scripts for this? Originally I had all of the robot's stats as fields of the player, but actually I want them as fields of the robot itself - that way I can spawn a new robot for the player when one dies. So how then do I separate the PlayerController script from the Robot script? What should each be responsible for?
I think ideally the player robot and the enemy robots (assuming they're functionallity identical other than being player controlled or not) should be largely identical except for the addition of a PlayerControl script on the one that the player controls and an AI control script on the one the AI controls.
This of course requires the main robot script or the robot movement script or whatever to have an appropriate interface that both of those disparate control scripts can interact with.
bots getting old 😉 his reaction time isn't wat it used to be lol
Ok that's neat. I was wondering how to differentiate the control between the two, and that answers it.
is it possible to curve a raycast? is it wrong to even do it
lol.. u could raycast from segment to segment (creating a curve-ish..)
So when you say "requires an interface" I understand generally what this means, but not how to implement it in practice. Effectively the Robot script needs a generic "plug" for which the player or AI to send commands.
How is that typically done?
no actualy curve like between 2 point
raycasts def dont curve tho
yea no..
u'd have to segment it urself to simulate a curve
possibly u could do something with splines? n get a decent result.. (no clue the end-game tho_
no, raycasts are by definition straight
idk this feel cheesy
probly will have to apply some math stuff
ya, a "curved raycast" begins feeling cheesy
what's the actual end goal here? This is an X/Y problem
gotta go with the flow tho lol
i just have a random thought of a curve bullet path or smt similiar
not a path but like usually cast a ray to the target
If you are working within Unity's physics system, you would do a bunch of smaller raycasts like Spawn illustrated above.
If you were building your own physics system you could do it with math (if you could describe the curve mathematically, e.g. as a parabola, a bezier curve, or a circular arc segment or something)
you almost certainly don't want to build your own physics engine 😛
if using math curve formula, then without cast how to get the hit
it depends on what two things you're intersecting
a triangle and a bezier curve?
A circular arc segment and a triangle?
A box and a parabola?
These would all be different math
there are many ways to mathematically describe various curves, and many different shapes the curve could be intersecting with
i think to use the formula would need the position of the start and the target, but like check if the path is blocked or not
start and target is not enough information to describe a curve
nor does it describe the things that could be blocking it
like to draw a curve the 2 position are require, i understand some other factor can modify the curve shape
You sound like you're describing some specific kind of curve, perhaps a bezier curve. I'll refer you back to here #💻┃code-beginner message
what to use to stimulate the cast here to get the hit on the path
Hello everyone,
What would be the best way(s) to store information releated the monos? For example, I have a Player, a Car, and a Quest mono, the player leaves the scene (enters an other one) where the car is located so now the Car gameobject is destroyed, thus, the Quest script can no longer just simply have a reference to the Car as there is no object behind it anymore. Though, when the players opens the quest menu, the Quest should still be able to show data about the Car.
How would you deal with this?
You need to build a data model of the state of your game that can exist completely outside the concept of GameObjects and MonoBehaviours.
For objects in the game world that are specifically meaningful to the data model, you may consider giving them a unique ID, such as a GUID, and storing that in your external data model of the game state.
i think best to just drop the cast thing and just curve the bullet with collider in it
Does this mean that I just simply keep a reference to these data objects in a mono that lives in the DontDestroyOnLoad?
A singleton "Game State Manager" is a good idea, yes.
The game state data would basically just be one object
public class GameState {
// all the data describing your game state here
}```
it can get a bit complex when you're talking about loading/unloading scenes and having objects in the game world that correspond to objects in the game state. You'll need to have MonoBehaviours on such obejcts that contain a reference somehow to the objects in the game state that they correspond to.
This is step one of creating a saved-game system as well
If I use unsealed time on my character controller, how do I suspend input from character when I need to pause the game?
Assuming you mean "unscaled" time, you don't.
I mean, if you're using unscaled time presumably it's because you do want it to work when timescale is 0
Implement a custom time scale management system.
Probably best to not deal with timescale at all then and do some sort of isPaused flag and manually check it on everything
Or just check if the menu is open before updating the character.
Sorry it’s a typo, yes it’s unscaled time
My system of timestop currently uses a flag stored inside of a singleton to dictate if time has been stopped
Well, it’s different from outright pausing the game
But I’m thinking of using timescale to achieve the same effect
Because that will save a lot of time
(Since I don’t need to change rbs to kinematic objects and then store their velocity)
!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;
public class Player : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
private void Update()
{
if (Input.GetKey(KeyCode.W))
Debug.Log("Key W down");
else
{
Debug.Log("No input");
}
}
}
``` Hi currently using the input manager (old) as my tutorial by code monkey (from 2023) says to set it as such but my code is not working? matches the script im not sure as to why though and if anyone knows let me know thank you
any errors in the console? have you ensured that component is actually attached to something in the scene?
no errors forgot that to add the script to a script folder doesnt hold weight in the same breath like adding to a player object lmao tysm
Can anyone help me set up a start screen i got my image and followed tutorials bit nothings working and im really confused if someone could hop in vc for 5< mins would appreciate it a ton thanks let me know in dms or mention me here. !
if you need help with something then formulate a question and ask here. don't expect anyone to want to privately help you in voice chat
wasnt expecting was just asking
I dont know how to write it out and it would be easier
if you cannot formulate your issue into words, then how do you expect anyone to help you even via voice?
by showing
you can record a video. but if you cannot formulate your issue into words it's unlikely you'll get any help. why would anyone want to put in the effort of not only helping you, but also attempting to figure out what you are even trying to show
cos some people are nice and its 5 minutes of their day to help someone get into unity idk why everyone in this discord is so depressed yo was just asking something...
you're just wasting people's time. see #854851968446365696 for how to ask a question and consider also reading #📖┃code-of-conduct
definitely give #📖┃code-of-conduct a read instead of immediately going on the attack because someone isn't bending to your will and offering free private tutoring.
never said free either
since you're doing nothing but attempting to insult me instead of familiarizing yourself with the community's rules, perhaps a <@&502884371011731486> would be interested in stepping in.
"mods mods help me I'm being harrased by someone who wanted help"
@violet pebble If you have a question, ask it. Everyone here has no problem doing so, nor has there ever been a question that was impossible not to formulate. If you're going to attack people because you struggle with emotions, then just don't post. Thanks
dont struggle with emotions was asking a question and someone white knighted thought they were saving the day because they got offended that i would ask that someone who has 5 mins of free time could help someone out. Never told never harrased and didnt instigate this. they coudlve just been chill all i want is for my highlighting on my meshboxes to work. For my cursor to show up when i press play so i can click the play button and to get help making my play button work so that it loads my other scene correctly
We can all do without the sexist BS that was deleted, the comparison to moderators, the no friends statement. If you want to act like that again you'll be removed from this discord.
Just post a video of your problem and move on.
void OnTriggerExit2D(Collider2D other) {
if (other.gameObject == target.gameObject) //rest of code
}```
this is giving me errors when the exit is because the **other** object has been SetActive(false). [its a consumable being eaten by the holder of the script above]. The code works fine regardless but id still like to avoid these errors, any ideas?
what error(s)
that code does not care if that object is set active false
Executing code from non active objects is fine. The callback, if on the inactive object, should not though.
im having trouble building the game cause it says an editor is assessing smth or compiling smth idk
im new to this so idrk whats happening
This is a stupid question I should know the answer to, but what's the main reason we keep variables as local as possible again? It occurred to me that it's just something I was taught and never really questioned. I remember being told something about it preventing memory leaks or something, but nothing beyond what that really means. I guess what I'm asking is if keeping everything as local as possible is worth it even when it starts making the code more difficult to read because I have like 21 classes inside another class because I only intend for that one class to ever use them
Readability mainly (why mix variables that really need to be shared with variables that are used in only one method?), memory management (why keep a value permanently in memory when it's only used in one method?) and making it easier for the compiler to make optimizations
So when a hyper fixation on localization actually starts making the code harder to read I should ease up a little?
Hard to say without knowing what you're doing
it's unusual to have 21 classes inside of another
if you mean class declarations
Which is why I'm asking because I want to make sure it's really worth it
but it might make sense depending on your architecture
Oh no. I mean 20 classes. And the abstract they all derive from
It would be easier to give advice to a specific scenario. These things really depend on use case
Sounds like variable scope might not be the main issue here
I have a game data structure (the thing that's supposed to be serialized in and out of the game) and in it I put a class for character data, map data, and communal party data. But in the character data I want it to store class data (as in DND class not OOP class) and I want like 20 different ones (along with the abstract they're all derived from)
At that point it's worth just making a new script and putting all of those in that instead of localized to the game data structure right? Even though I only ever intend for the game data structure to actually care about any of this?
Sadly it's still hard to say, it all sounds a bit monolithic, which is hard to give advice on without understanding the whole thing
break out partial classes, make a new class, or make them all public, it's just an organisational thing
the only reason to encapsulate it is to not pollute the public namespace
So it doesn't really do anything different other than organization then?
but it's your own game, so it doesn't matter that much
it matters if you're building an API for someone else to consume
but you're not, so do what works for you
I never knew what a partial class was, but the more I'm looking into it, it seems this is the best of both worlds
Hello everyone, I have a problem that no one has been able to solve so far. I'm sharing my code below this message. In my Unity game (C#), when the enemy dashes at me and I attack at the same time — whether I hit the enemy or not — I get knocked back, even though I shouldn't.
A tool for sharing your source code with the world!
Please explain the flow of the code and where to look specifically, including what doesn't work here
I think the problem comes from the charging enemy's code during the charge. Maybe when the player gets hit, the force is still applied to the player on the enemy's next attack. But i'm not sure.
on randomness, is there any difference using cellular noise vs perlin noise or value noise?
if I want some random value in between two close values (-75, -105) does any one of these matter or is there one better than the other
Those are pattern noises. It depends on what kind of pattern you want and what you use it for
If you just want one value then none of those
I just want some randomness to change the VFX slightly in script
it'll call the action, randomize within these two values and slightly change the angle
That's too vague but probably just Random.Range(-75f, -105f)
ah ok
I need to know what methods, and what the flow is. I can't spend half an hour reading your code when you can just tell me
here is the explanation
i switched to unity 6 and then my URP project with no fog, post processing, or any fancy shaders suddenly had an issue. the editor viewport has this orange tint that i can't seem to get rid of but the colors of objects return to normal when i zoom up close.
check your camera clipping plane
and click a random object and press F
still the same :<<
how do you reference and use the VFX graph in script? I read the API and am still confused - I had the object reference set up already
try creating a new scene and see if its still there
hi had a doubt
You reference it and call Play()
But not the graph- the VisualEffect component
I'm a bit confused
do I need to set up an external script
Is it not like [SerializeField] private VisualEffectAsset swordSlashEffect;
and passing the asset into it?
VisualEffect
Not VisualEffectAsset
You need to put a VisualEffect component on a GameObject
It's like AudioSource vs AudioClip
You assign the graph in the inspector on the VisualEffect component
ah ok I get it now
also another question
if I want my hitbox to only register a hit when it collides with enemies in boxcast
how
Just do a boxcast. You don't need a collider except the one on the enemy
or is it better to leave the collision to all objects and handle the taking damage event on the enemy?
I don't understand that second question
as in if I boxcast and collide a wall it will still be a hit, but how does it know if I hit an enemy or a wall
The RaycastHit it gives you back contains all the information
Including which object you hit
how to get the infomation when it only returns a bool?
ah
I'm reading the api rn
so even if I boxcast I still need a RaycastHit object to store the information when object was hit
if I want to play the VFX with its center at a specific location, how do it set it?
Probably depends on the VFX graph. If it spawns particles using its local coordinates, just move the VFX object to the position you want. If it uses world coordinates, you need to pass in a vector3 that is used for the position (with SetVector3)
I'm no expert though, you can also ask #✨┃vfx-and-particles
ah ok, I have the world coords, but not sure how to implement it
I'll try my luck over there
hi
Can someon explain to me why would you use different ways of communication between game objects and when? I saw tutorials where they used things like finding the gameObject via a tag, using events? (I'm not really sure how they work honestly), some said something about "Delegates" (I also have little understanding of what those are) and I see just direct assignment too, when do you use which?
You're mixing up several concepts: ways to access/reference objects and different interaction types between them.
For referencing, if possible use serialized fields to reference things. If you can't, then you might need to use one of the find methods or singletons.
Delegates, events methods, public fields and properties are ways to interact with other objects and it's gonna be too much to explain here. I suggest you go read a bit of C# manual and come back if you still have questions after that.
Huh?
I was asking which way of communication I should be using between game objects in what scenario. I wasn't asking about what are references, just because I mentioned that its one way to do the communication that I know of.
I just listed out the way I've seen people do it, or talk about it and these are the ones that I know of.
You use reference when the objects have a direct logical connection with one and other. For everything else you use events
worked out something like i was mentioning (having scripting to segment ur "ray" that way u can curve it.. (bunch of str8 raycasts if first returns false it draws the next and so on and so on.. using a "hint" gameobject to curve it.. (got it working w/o having a target/end point) which makes sense for a raycast (casting into the unkown) but i cant really think of a way to do it without an extra transform tho.. 🤔 it was pretty hard to make it work without having an end point.. (for me atleast).. i looked into basic bezier curves, and quadratic bezier curves
could probably adapt any bezier asset to do something similar.. u only need the equation
referencing: #💻┃code-beginner message
@rugged beacon ☝️
sorry i had to jump off yesterday, never got to see the outcome of ur question
Howdy! I have a 'double door' and both of these 'doors' use this same script, When you try the door for the first time, It fires off a 'seems locked' voice line, Which only happens once, however, the other script has the same bool/script but it won't be true on the other script so it also fires off the audio queue when you click the other door. Any idea how to combat this?
It's a public bool
Do I just need static?
thats 1 option... but then you'll never be able to have (2) doors in different states
if you want the doors to work together then they probably shouldn't have completely separated scripts - they should probably be able to inform each other
No, make a DoubleDoorController component that sits on the root of the two doors. Have the doors notify this parent controller they've been interacted with.
no, like, you won't be able to make other double doors with the same behavior
best to just have a doubledoor controller.. (knowing bout both doors) like osteel mentioned
then u can have a singledoor controller.. (then they can all have their own states and conditions)
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
This is the.. Messy script I have been using/working with
I mean it works fine for my setup
But I see what you guys are saying, I have another set of double doors and It needed a unique script lol
hmm.. today i learned theres a lowercase quaternion
that's the one from the Mathematics package
yup, there any difference really?
Sorry lol, It's embarrasing posting my stuff like that but I mean, We all gotta learn right
yessir! dont be afraid to post ur code..
I was always told make stuff work then figure out how to make it better 
else you wont learn bout things you think u may know.. (etc)
thats a good practice
one of the main differences is that the Euler methods use radians rather than degrees. and annoyingly there's implicit casts to and from UnityEngine.Quaternion instead of requiring an explicit cast so that beginners can realize they are using the wrong object
ahh gotcha! 👍
its slightly better for performance not to have empty update methods btw
That's good to know! Thanks
I'm also SO glad c# doesn't care about indents because that was my downfall in other langs lol
i mean, not many languages do
Python was rough
javascript, and c++
lol.. if u don't count blueprints
no?
I haven't touched UE.. My friend always sends me pictures of his 'code' and it's just a bunch of worms connected together
what u mean no? is that not right?
they're c-family languages, they don't care about indents
oh, CodeGuppy lied to me
that's such a dumb statement lmao
indentation for formatting is important in every language
thats y i always post what i find here! 🙂
easiest way to find out if ur wrong is to state something as the truth
ah, yaml uses indentation! but it's not a programming language lmao
rofl
important != required
true
F# does too, but i think you can turn that off
https://en.wikipedia.org/wiki/Off-side_rule this is a list for them. It really is just python and then languages you probably wouldnt have heard of or wouldnt really use
is identation "required" in yaml, given that it's a superset of json 
depends on the definition of "required", huh?
Heres one for you guys, (Potentially wrong channel) Also ignore the audiosources I'm fixing that lol.
So the draw's box collider is on the handle. as thats how it's 'interacted' with to open.
However, When the draw is closed, If you stand back a little, and click to the side of the handle, you can actually collect the key inside with the draw closed.
But if I expand the draws box collider to cover the whole front panel, (This fixes it) but it also means you can click anything, not just the handle to open the draw, which I dont really want.
yup, yall are right.. when i change my query to "required" i only get python, haskell, and f#
need to step up my google game
coffeescript too
huh g-code uses indentation, though i can honestly say i've never seen a single line of indented code in any g code file i've looked at
not.. unknown, at least
why not disable the key unless it opens?
gdscript needing indentation makes sense since it's based on python
the most reliable solution here is just not making it possible to collect the key while its in this closed state. otherwise just make a separate collider so it isnt the same collider for the front panel and whole drawer
I thought about this but you can't have 2 colliders on one object right?
Oh you can!
you can, maybe you're thinking of rigidbodies?
absolutely u can.. and u can use children to seperate them if u want
i dont think you want both on one object anyways. how will you differentiate between the 2 when interacting with the drawer itself?
u could do a conditional and check which child object the collider belongs to. couldnt ya?
- Door
- DrawerCol
- HandleCol
extra tho.. i gues
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
This is how I'm opening the draw/closing
The interact system basically just means if an object is 'interactable' it's box collider is what you click
What I think i'll do is go into my interactor code and make it look for box colliders with a specific 'tag'
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Here is the interactor code
just remember you can only use a single tag per gameobject.. as long as thats not a deal-breaker.. i guess that could work
Oh wait, Yeah I cant put a tag on a box collider inside of a gameobject can i
u could tag it if it were on a child go
Oh I see what you're saying
yup..
yup, thats pretty standard 😄
or creating a variable and then forgetting to assign it
For some reason it won't detect my child box collider as interactable now
The draw controller script is on the parent
I guess I could move it onto the collider? object
Yeah that seems to have got it
yup, b/c ur code (i only glanced) uses an IInteractable interface.. (im assuming thats how u tell ur script whats interactable and not)..
if the component with that interface is on the parent rigidbody object then you can instead use hitInfo.transform or hitInfo.rigidoby since both of those will point to that object instead of the collider object
i was gonna say u could probably go up the object to the parent lookin for em but boxfriends idea is better
Might be a little weird but I got it like this...
The interact script is on the box collider object for the handle which pokes out a little past the box collider of the draw (which stops you going through the front of the draw to grab the key)
And the box collider of the main draw 'box' itself stops you grabbing it through the top etc
Any ideas why one project has different External Tools settings? It's the same Unity version.
do you have the visual studio package in both projects to the same version?
Somehow one project doesn't have packages at all. What the hell. 🤔
corruption of some sort?
Im confused why this is an issue to begin with, if the draw had normal collision blocking raycasts it wouldnt be possible to "hit" it when the draw is closed...
otherwise the easy solution is to somehow stop collection when the draw is closed (either some property on the object or by changing its enable state)
Copied the manifest file from another project. It's working normally again. But still, it was a weird scenario. 🤔
yup, i delete my library folder.. and then re-open unity.. once it rebuilds it it'll usually work pretty normally
but copying the manifest was a solid idea too
Deleting Library was the first thing I tried. 😄 I also deleted .sln file and checked if Visual Studio is selected in External Settings. I think I'm working with Unity for ~10 years, but I still get surprised by it. 😐
ahhh sooo true man
im having a wtf moment myself
editor inconsistencies.. between one project and another. (same version -> different results)
just another day in the life of a game-dev ¯_(ツ)_/¯
lol
Are you importing assets or compiling scripts?
idk what it means
I am guessing your code has errors and can't compile.
i have finished the game idk what i have to check if it is
mmm, i checked the code and it doesnt show any errors, just some deprecated methods and i have fixed
All I can see is a big warning and your Unity session trying to recompile. Maybe show the actual errors you are getting in the console? We can just see a little piece of one of them.
did you check the console to see what the actual error that caused the build to fail was?
sometimes you gotta clean libraries you're not using
debug the error, when you cant make a build unity creates logs for you
ok i will try everything u said boys, thanks ❤️
IT WAS 2 libraries i donw use
omg
thanksss
Hello all, just asking if anyone can give a hand with me:
I'm making components that use events, subscribe to events, Like a health component that sends out an event when its been hit, or health is 0.
Now i was struggling in trying to find a way to return values without coupling each and every component together, IE DMG can be resisted by armour, consumables etc - so they should somehow tell the Health Comp the resistance value.
So, i found out about Func<t> and im just wondering if thats the only way to do this kind of stuff, or is there a more optimised way of it?
I did a super quick test, and so far it seemed to work, best the Health component doesn't know of anyone's existence but its own. Yet still being new to it all i just wanna cover all my corners.
At the end of the day i just want to have a component that can scream out "give me a bunch of values" get said values and use the total for stuff, like Total Dmg Resistance or whatever - and not need to know anyone's existence - and not be a crippling aspect later on a project's life time.
You could use an event bus with mutable events
Indeed you could use delegates for this. e.g. make a delegate type:
public delegate int DamageModifier(int originalValue);```
Then you could have a `List<DamageModifier> modifiers;` on your component. Other thigns can add themselves through a public function like:
```cs
public void AddDamageModifier(DamageModifier modifier) {
modifiers.Add(modifier);
}```
Then when you want to calculate the damage you just go through all the modifiers:
```cs
int CalculateFinalDamage(int originalAmount) {
int damage = originalAmount;
foreach (var modifier in modifiers) {
damage = modifer(damage);
}
return damage;
}```
Alright, i'll have to look more into it, from what im thinking yeah seems like it could be easier to manage.
Thank you and to @tribal edge .
ayo!! i accidently replicated the MsPaint's curve tool.. (now if i add a 2nd hint) that'd be exactly it 🤯
One second, I also had a question but I can't figure out how to word it... (i'll edit this msg)
is it not just a quadratic bezier?
lol.. thats Exactly! what it is..
less special after i figured out the name of it.. but while building it i felt magical
and now it unlocked an idea.. but i dont really understand how the maths gonna work with it.. hold on.. lol
chat, so i want to do a double digit variable, as in horizontal and vertical, should i do matrixes or normal double ints would do
perhaps freya holmer's video on splines would be of interest to you (it's an hour long tho)
ya, now would be a good time to watch that.. (i usually use spline libraries or assets) so its all magic under the hood for me
up until now
what do you mean by "normal double ints"?
also what do you mean by "double digit variable"
i just assign 2 different ints
as in two variables that are stuck together, as in 2 in 1
so you would not use matrices for this
maybe an array, though not a particularly good idea
the good options are either a tuple or a struct - and unity already has a struct for this, Vector2Int
vector2int is 2 integars that are connected to each other right
no its a struct of 2 ints, nothing connected directly
you can create your own the same way, it doesn't "connect" them they are just part of the same object
same thingcs public struct XY { public int X; public int Y; }
oh, i just want them to be forced to be with each other
you cant have one if the other isnt
what do you mean "you cant have one if the other isn't "
so, lets say its a mapping 2 ints
what are you trying to do again ?
maybe you can do also a 2D array ?
int[,] xy
xy[3,20]
etc
u could use ints and just do a bit of remappin
if u only need to know about raw inputs.. on/off
since u can't put a negative in the ones place..you could remap it like
-1 = 0, 0 = 1 and 1 = 2 and then u just slap em side by side....
it wont be negative at all
ah, okay.. i gotta finish reading up above too ^ i got distracted lol
ya, struct makes sense to me. if thats all u need them (stuck together)
Coordinate.x, Coordinate.y
i feel like you have a base misunderstanding of how stuff is structured
to be clear, that's not bad, we all start somewhere
ig 2D array would probably be a better way to "force" you to use 2 values..
stuff isn't really "forced with each other"
stuff holds other stuff. an array can hold multiple values, those separate values aren't really "with" each other, they're just within the array
a Vector3 holds 3 floats, those floats are within the Vector3, they don't have any relation with each other
so what you need, if im understanding correctly, is just some way to store 2 ints, yeah?
whats the purpose of this data type
that would be either a Vector2Int (from unity) or (int, int) (from c#) or your own custom struct
i think that would shed lots more light || custom structs ftw ||
{
movement = value.Get<Vector2>();
}
void FixedUpdate()
{
if (!canMove) return;
accelTimer = movement == Vector2.zero ? 0f : Mathf.Min(accelTimer + Time.fixedDeltaTime, accelerationTime);
float speedMult = Mathf.Lerp(1f, 1.3f, accelTimer / accelerationTime);
rb.MovePosition(rb.position + moveSpeed * speedMult * Time.fixedDeltaTime * movement);
}``` Hello guys im having a problem that when my player moves diagonally and collides with the wall it slows him down, in my input system i use normalized vector so the speed is consistent in each direction, does anyone knows how to fix that? i already added no firection physics material for my player's box collider and i dont think its the code problem appreacite your help
to be clear, are you asking about why this happens or how to fix it?
friction material does nothing to affect MovePosition since its meant for kinematic movement
So what do you think the cause this problem?
the normalized vector
you need to manually create the wall sliding logic
Yes its beacues i noramlized my vector but then if i dont the player will move faster diagonally
when you move diagonally, it reduces the magnitude of each axis to keep the overall magnitude consistent
but when you hit a wall, one of those axes has no effect, leaving the other axis that had its magnitude reduced
yes, is there a way to stop that when colliding?
Hm guys so how can i fix this issue?
see nav's message
How can i create the wall sliding logic?
oh sorry i forgot to say my project is a topdown 2d game so wdym sliding
Guide on many of the first steps building up a top down 2d pixel art RPG from scratch in Unity 2022 version. The goal of this crash course is to cover as many relevant beginners topics as we can but linked together in actually building out some prototype mechanics for a potential game.
For the video, I'm using this mystic woods pack for this tu...
ty
this does xy iirc, prob need angled too you might need to modify it a bit but the idea is there and also uses kinematic movement which is important part
I was wondering if I could get help with an error when trying to reference another script. The other Scripts name is called RandomScript
using UnityEditor.Build.Content;
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;
public class RandomTarget : MonoBehaviour
{
private int score;
private RandomScript randomScript;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
randomScript = GameObject.Find("RandomScript");
}
// Update is called once per frame
void Update()
{
}```
What's the error? It's not finding it?
what error
CS0029 can not implicity convert type 'UnityEngine.GameObject' to 'RandomScript'
GameObject.Find gets a GameObject
Your variable is of type RandomScript
These are not the same type
yo guys im new to unity ig and i want to make my charracter aim and shoot but i find the code hard and non working
so in order to reference the script I have to point it to the parent GameObject?
Is there a reason you are not just making your variable public and dragging in the object
I've never been taught that I could even do that after completing the unity tutorials
Pretty sure the most basic tutorials will cover that well before they go into any sort of Find
IM NEW TO THIS SERVER IS THERE ANY PLACE WHERE I CAN GET SOME HELP
Here, if you ask a proper question
If you have a question you should actually ask one
"Code is hard" is not a question
I'll do some googling, thank you for the pointer :)
OKAY LET ME JUST RECORD MYU GAMEPLAY QUICK
: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 #854851968446365696
also can we not with the Caps lock?
Caps Lock is a key over below your tab key you might have hit it by mistake
ye im to lazy löl
then you picked the wrong hobby
Not a good trait to have if you intend to make games
i want my charracter to hold a gun or have a system like that. so he can aim and shoot but i find the tutorials confusing and fasdt . ps im noob
here
how to get rid of lazyness
lol
This is a code channel. If you have problem with code, post code here.
If you need help understanding a tutorial you need to post a detailed question in #💻┃unity-talk , see how to ask questions #💻┃code-beginner message
also you need to look up unity Animation Riggin IK or something
@rich addertold me too ask her
how did you get that from this..
Done some googling, found out how to do it. Now having the issue of type mismatch??
show code you wrote and details on message you are getting
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;
public class RandomTarget : MonoBehaviour
{
public int score;
public RandomScript randomScript;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnMouseDown()
{
randomScript.score += 1;
Destroy(gameObject);
}
}```
in the inspector?
Is one of the objects a prefab? Prefabs cannot reference scene objects
Yes it is
backticks, not quotes
they're usually on the key above tab/to the left of 1/below esc
You cant add scene components to a prefab 🦥
I'm guessing I'll have to go at this another way then, thank you :)
Fixed, thank you!
Assets can't directly refer to Objects in Scenes, but their instances can be configured with those references.
So you'll need to set it in code after the object is created. So there was a reason you weren't setting it in the inspector.
You could use a find in start but you want to find that specific type, not a game object by name.
https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Object.FindFirstObjectByType.html
Or you could have whatever object spawns in this object set the variable as nav's link suggests, which would be the preferred way
Tad confused but have tried my best, something like this I assume?
using UnityEditor.Build.Content;
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;
public class RandomTarget : MonoBehaviour
{
public int score;
public RandomScript randomScript;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
randomScript = Object.FindFirstObjectByType<Answer>(ScriptableObject);
}
// Update is called once per frame
void Update()
{
}
private void OnMouseDown()
{
randomScript.score += 1;
Destroy(gameObject);
}
}```
how can i prevent players from sliding? im using kinematic rb and using rb.movepos and when a player collides with another the one who got hit slides forever
if this isnt underlining red make sure to configure ur IDE
Oh it is... it's not happy but it was the best try I've had
if you want RandomScript then put RandomScript in the type..
randomScript = FindFirstObjectByType<RandomScript>();
look at the docs
Will do! Thank you
Where did Answer and ScriptableObject come from
[SerializeField] float collisionOffset = 0.05f;
[SerializeField] ContactFilter2D movementFilter;
Collider2D movementCollider;
[HideInInspector] public bool canMove = true;
bool isMoving;
Rigidbody2D rb;
RaycastHit2D[] castCollisions = new RaycastHit2D[10];
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
movementCollider = GetComponent<Collider2D>();
}
public void OnMove(InputValue value)
{
movement = value.Get<Vector2>();
}
void FixedUpdate()
{
if (!canMove) return;
if (movement == Vector2.zero)
{
accelTimer = 0f;
return;
}
Vector2 moveStep = movement * moveSpeed * Time.fixedDeltaTime;
bool moved = TryMove(moveStep);
if (!moved)
{
Vector2 horizontalMove = new Vector2(movement.x, 0);
if (horizontalMove.sqrMagnitude > 0.0001f) horizontalMove = horizontalMove.normalized;
moved = TryMove(horizontalMove * moveSpeed * Time.fixedDeltaTime);
}
if (!moved)
{
Vector2 verticalMove = new Vector2(0, movement.y);
if (verticalMove.sqrMagnitude > 0.0001f) verticalMove = verticalMove.normalized;
TryMove(verticalMove * moveSpeed * Time.fixedDeltaTime);
}
}
private bool TryMove(Vector2 moveAmount)
{
if (moveAmount == Vector2.zero) return false;
int count = movementCollider.Cast(moveAmount.normalized, movementFilter, castCollisions, moveAmount.magnitude + collisionOffset);
if (count == 0)
{
rb.MovePosition(rb.position + moveAmount);
return true;
}
return false;
}
}``` Hello guys do you see anything that can cause collision to pool player into the collider sometimes? or prevent him from moving when changing direction?
Answer was the name of the GameObject it's attached to ScriptableObject came from me trying browsing the manual of unity for what to put in :D
I've got it working now though, thank you for the time you've spent teaching and helping me both of you
im having trouble building my game cause it says an editor is assessing smth or compiling smth idk
im new to this so idrk whats happening
can someone help me?
what wrong with my code?
first of all !ide 👇
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
how can i run code everyframe in the editor mode similar to how I can in game mode within update()? I saw somewhere that [executealways] runs update even in editor mode but i dont know the caveats of using this instead of emulating a consistent tick function
you could subscribe to the Editor update loop for example
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/EditorApplication-update.html this is also an option but its not exactly every frame iirc
what are you trying to do exactly? whats the usecase
It doesnt matter much the timings of it, i js need something to run constantly in order to update the calulated position of a point in realtime. i have seen subscribing to the editor update loop as an option but it seems a lot more complicated?
i am calculating the position of point2 to be collinear with point1 and an anchor point
i would like it to move point2 on screen as i drag point1 using unity's handles
if its for like editor gizmos you could probably even use something like OnDrawGizmos that runs in editor as well
anyone know where do i see package name: com."company"."mygamename"??
i didnt think of that, ig the benefit of this method is that the updates are all synced
are you talking about mobile game like android ?
ProjectSettings
the issue is that my ondrawgizmo is within the class i use to calculate the logic and store the lists of points, is this a problem?
yess, do u know if it is on Player Settings?
@rich adder now my ide is correct?
The errors are being properly underlined in red now
Yep. Now your errors are underlined. I'd recommend just deleting all of this and starting over but now you have auto-complete
next step: learn the c# basics
this isnt the basics at all
eg you dont ever declare the access-modifier for a variable or method inside a method etc
~~yeah i just said that lol. ~~ oh left out the Player part mb but yes
it should be under the android section of Player
should i study all c# tutorials?
yes
those are especially important topics for basics
!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 miss the 📃 Large Code Blocks part
📃 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.
are you referring to inside his video as all i missed was the animation section and did not look over that aside from seeing him animating?
he was referring to the code being large enough to need posted to an external paste-bin site.. (like the bot embed says at teh top)
keeps the discord tidy. and helps keep the code consolidated and in 1 place thats easy to open
hey, i was reading that.. 😛
oh well heres the paste https://paste.mod.gg/chhvfbnubopj/0
A tool for sharing your source code with the world!
k.. so u said the raycast isnt following the player?
yeah it isnt allowing him to detect that theres a block infront he should not pass thru
well ur casting it above him arent u?
wait... actually i dont know what point1 and point2 are in the overload
ya, wait thats right.. so u have
from the tutorial i followed he declared that it was a top of and bottom of the capsule so when i raycast it casts the height of the capsule and its respective shape
ye should i change it avoiding height in the code as it makes the unit raycast to the sky?
should i use the x direction vector3.x and some form of radius or circle calculation with that so it detects from all angles of the character or should i do vector3.right / left etc
is it a 2d game?
and does ur character move left and right?
if so.. u could probably do transform.right * some offset to get a position in front.. of ur player
and transform.up would be above ur player. (these are the local directions that would be consistent with ur player). Vector3.right and Vector3.up are the world directions.. and will be the same no matter how ur players oriented..
ok im in a 3d realm so im assuming id do vector3.right and left
i have a simple issue that i cant seem to figure out, i want to have the text have a "+" in front of the quantity in the same string but i don't know how to combine them. Tried googling and it didnt really help me.
public TextMeshProUGUI text;
public void setNumber()
{
text.text = "";
}```
jus a u question but i get a warning that scenes can only have 1 event per scene would this be why my backbutton code could not be working?
Does anyone know why this happens?
it shows up in my console after I debug once or twice
I checked with chatgpt and I am not using any of the things he told me I am using
It's a simple project, with gameobjects and netcode for gameobjects for a coop game
Error:
TLS Allocator ALLOC_TEMP_TLS, underlying allocator ALLOC_TEMP_MAIN has unfreed allocations, size 17173
If you have multiple event systems that would probably interfere with any sort of UI button
ok ty
how do i make it so the ui has its own function and i can add it to the script the scene has so it all is in one event system
Just don't have two event systems in the scene.
restart unity? or delete library folder and rebuild 🤷♂️
but it happens each time i debug
it's not an option for me to do so each time it shows up
so try refreshing the library folder as suggested, if it doesnt fix it try brand new project and if does it report as bug.
do i need the same event script between two scenes so i can make a back button work as well or is it fine as long as its just one event on a scene
nvm i dont think thats at fault
ok here is my question how come my one public class works inside this event script but not the second which is the name of the button it is supposed to work with, https://paste.mod.gg/uymzdvfnmyfw/1
A tool for sharing your source code with the world!
You'll need to explain what you mean by "doesn't work". Is there an error? Is it not working as expected? How do you expect it to work and how does it work now?
And also what you mean by "Event script"
no errors the button does not respond to when i click it and i want it to respond by sending me to scene Gameplay / scene 1
and by event i mean a script where a certain code from a function goes off based off what function i want to work and that it only works if it is in the correct class
Is it a UI button
yes
Does the button respond to the mouse at all, like when you hover over it?
no it does not
Do you have an Event System in the scene
yeah entitled main menu
That's an odd name for an Event System
normally it's just called Event System
Can you show a screenshot of the inspector of it?
I needed a screenshot of the EventSystem
...I still need a screenshot of the EventSystem
this
I don't know why you've sent code?

that gets generated when you make a UI element
and is required for UI to function
which is why it is generated when you make a UI element
omg wait my brain
i found it oop
but it only exists inside my mainmenu not the scene this code is in
ok i also put in inputhandler and now it hovers but my function didnt pop up under the function tab for the button in on click
Did you drag in an object with that script on it
wdym specifically as it is inside an object with the script in it and also has the script inside itself too
If you want to call a function on a component by a UI button, you want to drag in an object with that component on it
ok tho my code with what spawn said to look for works using mainmenu playgame code but what i dont understand is why my class inside the code
public class FDRslide : MonoBehaviour
{
public void BackWard()
{
SceneManager.LoadScene("Gameplay");
Debug.Log("Loads correctly");
}
}
``` is not being noticed except the backward part becomes the script thingy in the place where i dragged the object into itself
it only does that once i choose playgame it works tho but im still weirded out is it because of the new class kind of funneling thru the previous code in some hierarchy ?
exist place where i can ask a for help learning c#?
I don't follow what you're saying. You're trying to have a button call this function BackWard, right?
What options are you seeing in the inspector when you drag in this object
yeah but the class FDRslide never pops up so i only see the MainMenu class which lists these functions
Does the object you've dragged in have an FDRslide component on it
i need try understand every line?
Ideally, yes.
If it's unity related, here is fine. Otherwise the C# community
Keep in mind this is pure C#, this won't do anything in Unity
where c# community
oh thank
wait so to clarify i can have a fdrslide script in the object even though the fdrslide has a menu script?
csharp 👇
Join the C# Discord server, a programming server aimed at coders discussing everything related to C# (CSharp) and .NET. https://discord.com/invite/csharp
...what?
Component as in component
ok then no
One of the things you've added to an object
Does the object have an FDRslide component on it
no if u mean this as component
also where do i get the lingo for unity so i better communicate cus it seems like something essential
this is the MainMenu component
You're trying to call a function on your FDRslide script
Does this object have an FDRslide component
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
oh dayum and ty and no it does not so i can fix it now 🙂
yay it work tysm my brain has derot
awww, i made a little clip , meh here it is anyway lol
-# Adding Script to UI Button to call Logic
spawn u literally took so much effort out of ur way to help visually i will be employing this for future learners as well lmao once im more aware of how to code
was just in case.. but with digiholic on the scene i knew i'd probably not get it done fast enough 😅
im coming back to this original question in regards to ray casting as i edited the code to use
Vector2 inputVector = gameInput.GetMovementVectorNormalized();
Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
float moveDistance = moveSpeed * Time.deltaTime;
float playerRadius = 1f;
float playerHeight = 2f;
bool canMove = !Physics.CapsuleCast(transform.position, transform.position + Vector3.right + Vector3.left * playerHeight, playerRadius, moveDir, moveDistance);
if (canMove) {
transform.position += moveDir * Time.deltaTime;
}
``` im trying this out but my buddy i play as still walks thru the blocks
Why are you casting to the right and to the left of the player's position in a single check? Multiplied by the height of all things?
Seems to me you want to cast in the moveDir from the player's position, if you want to see if you're going to bump into something?
Also is there a reason you're not using the built in CC for this?
i tried originally vector3.up * the height as the tutorial code monkey provided used that but when asking for help someone told me to try using the right and left though i dont think this was what he meant then
i believe that was me.. and i was under the impression u were doing 2D like a sidescrolling platformer
ohh ok i saw that and thought u seperated it to a 2d idea and 3d idea for the code
so i took the code farthest from ur question on it being in a scrolling platformer
Seems to me you want to cast in the moveDir from the player's position, if you want to see if you're going to bump into something?
Also is there a reason you're not using the built in CC for this
i agree with both these statements
i did want to go for the moveDir but im following his tutorial throughout so i didnt bother changing his code
a CC comes w/ a collider and a Move() function that wont let u Phase thru objects
since it worked for him
if thats the issue ur currently having
can u show a screenshot of ur player? and the environment?
ye
so we know what kind of shapes, and the direction of movement and whatnot
yeah im going to currently revert to the tut code (mind u i never heard of cc before this moment)
and have u considered using the CharacterController? it has lots of quality of life things that u dont have to do soo much
i think i will now i just need to find a unity doc or tutorial on what it is first
all directions but i didnt send it all cus too much photo data big one is just evidence of outside object
oh yea, that shape would work with a character controller simply
Vector2 inputVector = gameInput.GetMovementVectorNormalized();
Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);```
and since u already have ur input and made a vector out of it u'd just need to pass that into the Move() function
it'd be simple as that to get ur basic movement working..
In this video I demonstrate how to create a top-down character controller movement script in Unity which take into account the rotation offset of the main camera. This video also demonstrates how to make a game object rotate towards the mouse cursor on the screen, as is commonly seen in top down shooters. Learn some basic vector and rotation o...
dozens of tutorials for CC's out there. heres one i found w/ the top-down perspective like u have
ohh ty i was gonna use a basic tutorial in generalizations and usage in most cases
np, ya if ur doing top-down type movement probably better to follow a tutorial geared towards that..
it'll help keep things simple so u can understand better.. and then u can go out and adapt and modify
ah ty and then i would in the future make manual code outside of the cc script or inside the cc script?
Unity also has a good Character controller asset
both first person and third person.. but i hear some ppl say its a bit convoluted for beginners.. idk tho
a CC is just a component..
u write the script to manipulate that component..
and can be anywhere technically.. as long as u have a reference to it
1 thing ill mention.. is the CC works the best when you use the Move() function just once.. (per frame)
soo if u end up doing dashing, jumping and all that stuff.. instead of calling the Move() function for each part of that..
you basically just combine all the vectors before-hand.. and then at the end of the frame/Update() u pass it into the Move() function..
for example.. i use finalVector before i call the Move() function tho i combine everything, like my Vertical vector (for jumping and stuff).. and then anything else
https://docs.unity3d.com/6000.1/Documentation/ScriptReference/CharacterController.html the docs are super good for the CC as well..
alr tysm definently going to go into extensive research with the options for more specific character controlling scripts when it comes time especially once i need to implement the dashing for the game ty!!
This is kinda sully, but when you guys do timers like, "timeSinceLastMove" to check to trigger something if it's greater than X, do you cap it? Like do you set it to the max you are looking for or just let it running?
Cause I assume that would, after a veeery long time would just overflow the value
look up the max value of a float, then compare that to how many seconds are in a year
Still feels like maybe not optimal to store a high value you are really not gonna use, even if the difference is minimal
i suspect you didnt look up either of what i said. look up how many seconds in a day if you want a realistic value. Most people will not leave games running for more than days at a time. their computer would likely face other issues in the meanwhile
in terms of making a function that shows a ui toggle after 4 scenes are opened and exited
one at a time like you open a scene and when u close it it is completely closed , then it goes back to my main scene and u do this four times for example, and it then sets off an if statement that is true for all four having been opened in the game play so it can open the if statement?
just DontDestroyOnLoad then use OnSceneLoaded and check scene name and increase counter , then do logic based on that
hey, why my Gizmo doesnt shows?
void verificarYBrincar()
{
Vector2 rayOrigin = transform.position;
Vector2 rayDirection = transform.right * transform.localScale.x;
RaycastHit2D hit = Physics2D.Raycast(rayOrigin, rayDirection, groundRayDistance, groundLayer);
if (hit.collider != null)
{
float verticalDifference = valeriaPana.position.y - transform.position.y;
if (verticalDifference > 1f)
{
float force = jumpForce + (verticalDifference * jumpHeightMultiplier);
Cassielrb.AddForce(Vector2.up * force, ForceMode2D.Impulse);
}
}
}
private void OnDrawGizmos()
{
Gizmos.color = Color.green;
Vector2 rayOrigin = transform.position;
Vector2 rayDirection = transform.right * transform.localScale.x;
Gizmos.DrawLine(transform.position, transform.position + transform.right * transform.localScale.x * groundRayDistance);
}
}```
Presumably you don't have gizmos enabled in that view
Or your distance/scale is 0/close to
Also, you could simplify that to DrawRay and not do the addition of transform.position
oh, makes sense
well thanks
Making a music game any ideas on what to do with input key down functions
Or is that more advanced coding ?
Transform currentEdgeCheck = moveDirection == -1 ? edgeCheckLeft : edgeCheckRight;
bool isGroundAhead = Physics2D.OverlapBox(currentEdgeCheck.position, edgeCheckSize, 0f, groundLayer);
how come im getting isGroundAhead always false here? the yellow squares are the edgeChecks, the layers are set correctly. if i make the edgeCheckSize taller it returns true but thats not really the behavior im looking for
you set groundLayer correct?
yeah, cause if i make the edgeCheckSize taller it works, i dont really understand why, is there an issue with overlap if its too small and totally inside the collider?
Physics2D.OverlapBox returns Collider2D use that
i think also you can do !=
all i did was make edgeCheckSize have a larger y and here it's returning true and moving. but i dont want it this tall cause im just trying to check if theres ground beneath the character, to prevent him from walking off edges
I feel like you should never call a layer mask a "layer", because it can hold more than one. It makes it unclear what's going on
i switched to using raycasting and that seems to be working fine, just a weird issue with overlapbox 🤷
uhhhhh anyone know a fix?
you can't use UnityEditor classes in a build
wdym
when you build everything in the UnityEditor assembly gets removed
ohh
im sorry im new
but uh
where do I fix this at
read the top error carefully , usually thats the first error to fix
what are you using it for
either put it in an editor only class or wrap it in compilation statements
I dont remember adding it there
so I have no clue
IDE auto-insert prob
maybe
I do have an extension on
VS
where it likes to give me suggestions
and it bugs me and sometime I might
actually click the tab button
which the button that adds the suggested code in there
intellicode or intellisense depending on the context
tab?
if by "the code" you mean the one thats grayed out then you press tab it adds it thats intellicode, if you mean the box that shows classes/methods and common used thats intellisene
can you mess with cinemachine statedriven camera instructions using a script at runtime?
Why is my tilemap stuck vertical?
wdym "stuck" its default to 2D view axis which is cell swizzle xyz iirc
also not a code question
ur scene view if you press 2D button its properly oriented
hey, i was seeking two different ways to make the player's assistant jump, but im not sure wich method is better/more cleaned
Cassielrb.linearVelocity = new Vector2(Cassielrb.linearVelocity.x, cassielJump);```or
``` Cassielrb.AddForce(Vector2.up * cassielJump, ForceMode2D.Impulse);
oops wait
Hello! My collision detection isn't working, can you guys please help.
Here is a screenshot of the issue and then code beside it.
!code
also show the relevant collider(s)
📃 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;
public class Player : MonoBehaviour
{
[SerializeField] private float moveSpeed = 7f;
[SerializeField] private GameInput gameInput;
private bool isWalking;
private void Update()
{
Vector2 inputVector = gameInput.GetMovementVectorNormalized();
Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
inputVector = inputVector.normalized;
float playerSize = .7f;
bool canMove = !Physics.Raycast(transform.position, moveDir, playerSize);
if (canMove)
{
transform.position += moveDir * moveSpeed * Time.deltaTime;
}
isWalking = moveDir != Vector3.zero;
float rotateSpeed = 10f;
transform.forward = Vector3.Slerp(transform.forward,moveDir, Time.deltaTime * rotateSpeed);
Debug.Log(inputVector);
}
public bool IsWalking() {
return isWalking;
}
}
The player has the detection, and the cube is just there as a reference example.
okay and what collider(s) are you expecting to hit with the raycast? also is there a reason you are using raycasts for manual collision detection instead of using a CharacterController or Rigidbody based movement?
The cube or any object.
so show the collider
I'm a beginner, I don't know what you mean.
do you know what a collider is?
Yes, I do, I just don't know what mean by show the collider.
i mean show it. instead of screenshotting the hierarchy and game view that does not show any useful information, i am asking you to show the information regarding the collider. surely you've seen the collider component, yes? that is the collider.
is that the collider you are expecting to hit with your raycast?
It's a collider detection, so it can't go into object, so sure.
that collider is irrelevant to your hit detection. you are using a raycast, not that collider
i feel like you are just not understanding what i'm asking here. or anything about what i've said so far.
I would like to understand how to fix the collider detection, that's the question.
If I'm a beginner, then I'm not going to understand everything you tell me.
alright, i'm out. if you won't even engage with what i'm trying to tell you then it's pointless to continue this.
if you are not sure what you are doing then consider starting by learning the basics. do the pathways on the unity !learn site to actually learn how to use the engine.
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
If I'm using the wrong practices that's on me, but I'm doing it manually to learn.
Unable to parse Build/WebGL.framework.js.gz! This can happen if build compression was enabled but web server hosting the content was misconfigured to not serve the file with HTTP Response Header "Content-Encoding: gzip" present. Check browser Console and Devtools Network tab to debug.
😭
but also read the error, you may need to disable or change the compression used
I tried to look
but I cant find it
ill try again rq
I need help for something maybe dumb. I have an ennemy and i want it to attack my player but. I don't know if it's my code or my animator but my enemy attack only in one direction...
for some reason my character gets stuck sometime between tiles, I actiavted used by composite but still not working correctly
!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.
can you show the inspector of your tilemap?
I made the grid size 0.99 instad of 1 and it worked, I don't know if it's a bad solution or not
doesn't sound like that'd reliably solve it
A tool for sharing your source code with the world!
does it not attack at all? or just doesnt' show the animation?
try adding some logs where it's supposed to attack
no it attack but it only attack in one direction not always the direction of the player. It's the animation who doesn't follow the direction of th player.
sounds like an issue with your animator rather than here
check the transition parameters, do they look right
my transition work like that
and what's the right side
and have you done the debugs i told you to do? or just checked to confirm that AttackDirection is what it should be
I have a dodge roll animation setup for my player that uses root motion.
I have a few issues
- The roll animation does not seem to finish fully when pressing the roll key
- my camera does not seem to follow the player when dodge rolling ( can show relevent scripts for that)
- the player returns to the starting roll position when the dodge roll ends
!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.
sounds like you should set exit time on the roll animation though, for the first and possibly third issue
I should set the exit time?
from the transion of the dodge roll, or out of the dodge roll
out of the dodge roll
yes ive done that
and transition time is set to 0?
or since you're working with rigs, uh, exit time set a little less than 1 and transition time set to more than 0, maybe
idk - you'll have to ask #🏃┃animation about that
Okay
And about the camera not following the player during the dodge roll only, ill show you my code one second
The dodge roll is specifically happening in the dodge roll and on animator move function at the bottom btw
where are you doing the camera following?
Camera script, can show you that, one second
how can i change a UI image's source image with a script?
_image.sprite = ...
what if the image object is a child of the object where the script is attached?
doesn't change, you need a reference to the image component anyways
what changes is possibly how you get that reference
im really trying to learn unity but i dont how to solve this
Go to project settings
Player
Search for "active input handling"
And change it to "Both"
Why does my animation not show properly in the preview? The same occurs in game too, the animation simply does not play even though I'm pressing the corresponding button.
Do you get the log
yes
Try keeping this animator window open while the game is running with the object selected. You should see what state the object is in at all times
I'm assuming empty state is correct?
You can dock that in a separate part of the screen so you can look at it while controlling the game. See what happens when you press the button
Do you see the trigger getting set? Does it spend any time in the animation state?
Yeah the condition is being set and the trigger goes off, no animation though 😭
Okay, so it's in that animation state. Looks like the code is all working, maybe there's something with the animation itself? If you just change the entry animation to that clip is that animation playing?
It still doesn't play when I set it to the layer default state. The animation plays in the preview when I look in the projects section yet whenever I try to put it into the Animator Controller even the preview just shows my character standing still.
Seems like it's an issue with the animation itself then, the code and the Animator setup all seem correct. I don't really know a lot about how to fix those I just use them. Maybe #🏃┃animation would know more?
Currently I have these parameters that I want to pass to spawn in a VFX object, how can I do it? (with same direaction and center)
I'm not sure how spawn in the object alongside my box cast
Assuming it's a GameObject, you can just set its transform.position and transform.rotation (or, more likely, transform.forward since you have a direction vector, not a Quaternion)
Do I just
GameObject slashVFX = new Gameobject("vfxgraph_slash", typeof(VisualEffect))
use a prefab ideally
You would probably want to instantiate a prefab
digiholic's advice also assumes that your VFX graph works in local space, not world space
relative to the player?
I want it to work both cases
both locally as a child of the player and world space
If the graph is set to use local space then the effects will spawn relative to the transform of the object that has the Visual Effect
So in local space (0, 0, 0) would be at the object's origin. If it was in world space, (0, 0, 0) would spawn at world origin
This sounds confusing to me
as in, I want to be able to spawm both relative to the player and independent from the player
Alright, then you probably want to have the VFX use world space and pass in the position and rotation manually
Instantiate a prefab with the given position and rotation
https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Object.Instantiate.html
Nvm this, you can also just use local space and let it use the transform's position and rotation @shut swallow
does the particle move when spawned relative to its parent?
Child objects move with their parent object to maintain the same relative position to it
alright I got something like this:
{
_attackReady = false;
var slashDirection = castCenter - cameraTarget.position;
var slashDirectionQuaternion = Quaternion.Euler(slashDirection);
if (!GameManager.Instance.timestopTriggered)
{
var hit = Physics.BoxCast(
center: castCenter,
halfExtents: vector3HalfExtents,
direction: slashDirection
);
Instantiate
(
vfx_slash,
position: castCenter,
rotation: slashDirectionQuaternion
);
}
else
{
Instantiate
(
vfx_slash,
position: castCenter,
rotation: slashDirectionQuaternion
);
SuspendSlashes();
}
}
else
{
_attackReady = false;
}
IEnumerator SuspendSlashes()
{
swordSlashEffect.playRate = 0.05f;
yield return new WaitUntil(() => !GameManager.Instance.timestopTriggered);
swordSlashEffect.playRate = 1f;
}```
does this work?
I mean, the only way to tell is it test it out, no?
one more question, how to cull the prefab after spawning it?
Cull it from what? 🤨