#💻┃code-beginner

1 messages · Page 669 of 1

celest canyon
#

Hello, anyone good with basic Bolt?

naive pawn
celest canyon
#

oh ok

naive pawn
celest canyon
#

I see, thank you

cosmic charm
#

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?

wintry quarry
#

You just mean a visual effect?

cosmic charm
#

yes

#

exactly

wintry quarry
#

Use a particle system or VFX graph

cosmic charm
#

I don't need the particle system, I need the red visual effect

#

is VFX really needed?

rocky canyon
#

either a particle system, or an animation w/ multiple sprites

stark cove
#

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?

wintry quarry
#

It's the same

stark cove
#

alr thanks

shut swallow
#

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

wintry quarry
#

The component is called VisualEffect

shut swallow
#

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?

wintry quarry
#

If you're doing a melee attack or something I highly recommend direct physics queries rather than enabling/disabling a collider

wintry quarry
#

Is it a child of the player?
Is the graph set up for World Space or Local Space ?

shut swallow
#

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

rocky canyon
shut swallow
#

and if that's the case, does using collision queries even work?

naive pawn
#

you could also use the Transform methods to let it do the math for you (TransformPoint, TransformDirection, etc)

shut swallow
naive pawn
#

what do you mean by "object cast" exactly?

shut swallow
#

I'm trying to make a hitbot for a melee attack

shut swallow
#

And I was a bit confused as to how to implement it

rocky canyon
#

im pretty sure theres methods to convert them as well
edit: nvm.. the conversion are for directions.. Not positions

naive pawn
shut swallow
#

ah

#

mb

naive pawn
#

there are a lot of casts that take different parameters

shut swallow
#

But can you pause the physics cast or should I just use a coroutine for it

rocky canyon
#

just however u logic is setup

naive pawn
#

you can't pause a cast, it happens instantly

shut swallow
naive pawn
#

...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

shut swallow
naive pawn
#

well if everything is using scaled time then you could just have it set timescale?

shut swallow
#

because timescale would prevent my player from moving

cosmic quail
naive pawn
naive pawn
shut swallow
naive pawn
#

for timing, you would just keep track of time yourself, and stop counting when time stops

shut swallow
#

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?

naive pawn
#

well, you aren't using timescale, no?

shut swallow
cosmic quail
shut swallow
naive pawn
shut swallow
#

I've read that rigidbodies cannot move in timeScale 0 due to being physics objects

naive pawn
#

yeah

#

ah.

#

i mean, they respect timeScale so that makes sense - does that still apply to a kinematic rb that you move yourself?

sour fulcrum
#

you could problem tick the physics ahead yourself right?

shut swallow
#

but that depends on update, and when timescale is 0 update is not called

shut swallow
#

right now I could test by changing all time references into unscaled time

naive pawn
#

that doesn't sound right

shut swallow
#

and then manually set timescale to 0

naive pawn
#

im not too familiar with kinematic rbs tbh, could you explain what you mean by "kinematic motors"

shut swallow
#

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

grand snow
#

Velocity shouldn't do anything if physics is not ticking

naive pawn
#

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

shut swallow
#

but unscaled should still tick because it does tick when even if the editor is paused

shut swallow
#

it's not working

naive pawn
#

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?

shut swallow
fresh rivet
#

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

wintry quarry
fresh rivet
#

wow

shut swallow
#

is that in C# or Lua

#

I've heard that balatro is in lua

wintry quarry
#

It's a shader so neither

shut swallow
#

ah

wintry quarry
#

HLSL or GLSL or something

fresh rivet
wintry quarry
#

Nobody wants to learn anything anymore 😦

fresh rivet
#

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)

shut swallow
#

I've been learning from scratch and this server helped me a lot aside from video tuts

wintry quarry
sour fulcrum
shut swallow
#

I'm pretty sure that unity ver on gpt is in 2023.2

#

not unity 6

fresh rivet
shut swallow
#

I know this because I did try using gpt like once

#

and I gave up because it was not good

naive pawn
shut swallow
#

mayeb there's some potential issues over there

naive pawn
#

shit i forgot to get back to you one sec

shut swallow
#

lmfao

naive pawn
#

that feeling of "hmm i forgot something.. oh well"

naive pawn
#

!code

eternal falconBOT
shut swallow
#

gimme a sec

#

wait

naive pawn
#

oh wait i just got into how locomotion works with the kcc

#

you set a velocity, yeah?

shut swallow
#

yea

naive pawn
#

so deltaTime is handled internally then, probably...

shut swallow
#

you move based on changes to velocity on currentVelocity

shut swallow
#

maybe

naive pawn
#

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

shut swallow
#

not currently

naive pawn
#

what about extending the KCC, if some stuff isn't private/internal?

shut swallow
#

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)

shut swallow
#

it's like 3am here so i gotta dip
I'm probably gonna ask agin tomorrow or somethingh

naive pawn
#

@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);
        }
    }
}
shut swallow
#

interp is gonna be a dumpster fire

naive pawn
#

it's just calling those methods

shut swallow
#

but I could change deltaTime into Time.unscaledDeltaTime no?

naive pawn
#

yeah

shut swallow
#

or would that break it

naive pawn
#

that's pretty much all you'd change

shut swallow
#

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

naive pawn
#

easy litmus test - if there's an unscaled version, then then version without unscaled is scaled

shut swallow
#

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

acoustic belfry
#

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?

naive pawn
#

math, generally

#

there are tons of approaches to do it

#

tweening libraries, MoveTowards/SmoothDamp, setting velocities, adding forces, etc...

acoustic belfry
#

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?

shut swallow
acoustic belfry
#

yep

#

like this fella

acoustic belfry
#

i mean, the actor has a rb

shut swallow
#

Kinematic bodies needs math to be controlled

#

Otherwise, well, it just won't move

naive pawn
#

i mean, they never said it was a kinematic rb

acoustic belfry
#

i think it is

shut swallow
#

Oh mb

acoustic belfry
#

i mean, what kind of rigidbody has gravity and stuff?

shut swallow
#

I read rigidbody as kinematics

naive pawn
#

but even with that you could still get away with not much math

shut swallow
#

Damn I need sleep

naive pawn
shut swallow
#

It's 4am 🫠

acoustic belfry
#

ah yes, dynamic, now i remember

naive pawn
#

you can check the "Is Kinematic" checkbox - if it's false, it's dynamic

acoustic belfry
#

i mean, i want my enemy/boss to do cool stuff like the Mantis Lords from Hollow Knight, or Gabriel from UltraKill

shut swallow
#

That's more enemy AI

#

Finite state machines and the such

#

I'm rather unfamiliar with those bc I'm also learning

acoustic belfry
#

It is really bad if my enemy AI doesnt have states machines?.....

royal mist
#

hey can i get some help? im trying to make an asset bundle

shut swallow
#

Good practices ig

royal mist
#

can any of you help me?

shut swallow
#

Not too familiar with asset bundles but I recommend reading up the API (but you've probably done that already)

eternal falconBOT
odd remnant
#

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?

rocky canyon
#

what if i designed the ai's robot poorly on purpose?

#

wins every game ezpz

wintry quarry
# odd remnant So, quick pivot - I'm making a FAR easier game to start off in Unity. I jumped i...

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.

rocky canyon
#

bots getting old 😉 his reaction time isn't wat it used to be lol

odd remnant
rugged beacon
#

is it possible to curve a raycast? is it wrong to even do it

rocky canyon
#

lol.. u could raycast from segment to segment (creating a curve-ish..)

odd remnant
#

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?

rocky canyon
rugged beacon
#

no actualy curve like between 2 point

rocky canyon
#

raycasts def dont curve tho

rocky canyon
#

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_

wintry quarry
rugged beacon
#

idk this feel cheesy
probly will have to apply some math stuff

rocky canyon
#

ya, a "curved raycast" begins feeling cheesy

wintry quarry
#

what's the actual end goal here? This is an X/Y problem

rocky canyon
#

gotta go with the flow tho lol

rugged beacon
#

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

wintry quarry
#

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 😛

rugged beacon
#

if using math curve formula, then without cast how to get the hit

wintry quarry
#

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

rugged beacon
#

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

wintry quarry
#

start and target is not enough information to describe a curve

#

nor does it describe the things that could be blocking it

rugged beacon
#

like to draw a curve the 2 position are require, i understand some other factor can modify the curve shape

wintry quarry
rugged beacon
#

what to use to stimulate the cast here to get the hit on the path

tight sonnet
#

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?

wintry quarry
rugged beacon
tight sonnet
wintry quarry
#

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

shut swallow
#

If I use unsealed time on my character controller, how do I suspend input from character when I need to pause the game?

teal viper
polar acorn
#

I mean, if you're using unscaled time presumably it's because you do want it to work when timescale is 0

teal viper
#

Implement a custom time scale management system.

polar acorn
#

Probably best to not deal with timescale at all then and do some sort of isPaused flag and manually check it on everything

teal viper
#

Or just check if the menu is open before updating the character.

shut swallow
#

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)

untold elk
#

!code

eternal falconBOT
untold elk
#
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
slender nymph
#

any errors in the console? have you ensured that component is actually attached to something in the scene?

untold elk
#

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

violet pebble
#

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. !

slender nymph
#

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

violet pebble
#

wasnt expecting was just asking

#

I dont know how to write it out and it would be easier

slender nymph
#

if you cannot formulate your issue into words, then how do you expect anyone to help you even via voice?

violet pebble
#

by showing

slender nymph
#

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

violet pebble
#

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...

slender nymph
#

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.

slender nymph
#

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.

violet pebble
#

"mods mods help me I'm being harrased by someone who wanted help"

frosty hound
#

@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

violet pebble
#

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

north kiln
#

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.

hallow sun
#
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?
slender nymph
#

what error(s)

sour fulcrum
#

that code does not care if that object is set active false

ivory bobcat
#

Executing code from non active objects is fine. The callback, if on the inactive object, should not though.

broken fox
#

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

eager stratus
#

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

keen dew
#

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

eager stratus
north kiln
#

Hard to say without knowing what you're doing

#

it's unusual to have 21 classes inside of another

#

if you mean class declarations

eager stratus
north kiln
#

but it might make sense depending on your architecture

eager stratus
keen dew
#

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

eager stratus
#

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?

north kiln
#

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

eager stratus
north kiln
#

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

eager stratus
quiet epoch
#

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.

burnt vapor
quiet epoch
#

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.

shut swallow
#

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

keen dew
#

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

shut swallow
#

it'll call the action, randomize within these two values and slightly change the angle

keen dew
#

That's too vague but probably just Random.Range(-75f, -105f)

shut swallow
#

ah ok

burnt vapor
quiet epoch
scenic vale
#

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.

median hatch
#

and click a random object and press F

scenic vale
#

still the same :<<

shut swallow
#

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

median hatch
novel ruin
#

hi had a doubt

wintry quarry
#

But not the graph- the VisualEffect component

shut swallow
#

do I need to set up an external script

#

Is it not like [SerializeField] private VisualEffectAsset swordSlashEffect;

#

and passing the asset into it?

wintry quarry
#

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

shut swallow
#

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

wintry quarry
#

Just do a boxcast. You don't need a collider except the one on the enemy

shut swallow
#

or is it better to leave the collision to all objects and handle the taking damage event on the enemy?

wintry quarry
#

I don't understand that second question

shut swallow
#

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

wintry quarry
#

The RaycastHit it gives you back contains all the information

#

Including which object you hit

shut swallow
#

how to get the infomation when it only returns a bool?

wintry quarry
#

Check the documentation for examples

#

It has an out parameter

#

RaycastHit

shut swallow
#

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

shut swallow
#

if I want to play the VFX with its center at a specific location, how do it set it?

verbal dome
#

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)

shut swallow
#

I'll try my luck over there

umbral tide
#

hi

half cliff
#

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?

teal viper
# half cliff Can someon explain to me why would you use different ways of communication betwe...

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.

half cliff
#

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.

charred spoke
#

You use reference when the objects have a direct logical connection with one and other. For everything else you use events

rocky canyon
#

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

high summit
#

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?

rocky canyon
#

thats 1 option... but then you'll never be able to have (2) doors in different states

high summit
#

Oh opening one of them unlocks both

#

It's one of these

naive pawn
frosty hound
#

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.

naive pawn
rocky canyon
#

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)

high summit
#

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

rocky canyon
#

hmm.. today i learned theres a lowercase quaternion

slender nymph
#

that's the one from the Mathematics package

rocky canyon
#

yup, there any difference really?

naive pawn
#

completely separate system

#

separate vectors and everything

high summit
#

Sorry lol, It's embarrasing posting my stuff like that but I mean, We all gotta learn right

rocky canyon
#

yessir! dont be afraid to post ur code..

high summit
#

I was always told make stuff work then figure out how to make it better atwhatcost

rocky canyon
#

else you wont learn bout things you think u may know.. (etc)

slender nymph
# rocky canyon yup, there any difference really?

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

rocky canyon
#

ahh gotcha! 👍

cosmic quail
rocky canyon
#

i thought they didn't have a configured IDE

#

so i had to check for myself..

high summit
#

I'm also SO glad c# doesn't care about indents because that was my downfall in other langs lol

naive pawn
#

i mean, not many languages do

rocky canyon
#

im sooo glad that my IDE self-formats

#

🤣 else id be in trouble

high summit
#

Python was rough

naive pawn
#

wait i can't actually think of any other than python

#

there's definitely more though

rocky canyon
#

javascript, and c++

high summit
#

Yeah js

#

Isn't c++ what UE uses?

rocky canyon
#

lol.. if u don't count blueprints

naive pawn
high summit
#

I haven't touched UE.. My friend always sends me pictures of his 'code' and it's just a bunch of worms connected together

rocky canyon
naive pawn
#

they're c-family languages, they don't care about indents

rocky canyon
#

oh, CodeGuppy lied to me

naive pawn
#

that's such a dumb statement lmao

#

indentation for formatting is important in every language

rocky canyon
#

thats y i always post what i find here! 🙂

#

easiest way to find out if ur wrong is to state something as the truth

naive pawn
#

ah, yaml uses indentation! but it's not a programming language lmao

rocky canyon
#

rofl

polar acorn
rocky canyon
#

true

slender nymph
eternal needle
naive pawn
#

depends on the definition of "required", huh?

high summit
#

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.

rocky canyon
#

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

naive pawn
#

coffeescript too

slender nymph
naive pawn
#

not.. unknown, at least

rocky canyon
naive pawn
#

gdscript needing indentation makes sense since it's based on python

eternal needle
high summit
#

Oh you can!

naive pawn
#

you can, maybe you're thinking of rigidbodies?

rocky canyon
#

absolutely u can.. and u can use children to seperate them if u want

eternal needle
#

i dont think you want both on one object anyways. how will you differentiate between the 2 when interacting with the drawer itself?

high summit
#

Wait thats a good point bawsi

rocky canyon
#

u could do a conditional and check which child object the collider belongs to. couldnt ya?

#
  • Door
    • DrawerCol
    • HandleCol
#

extra tho.. i gues

high summit
#

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'

#

Here is the interactor code

rocky canyon
#

just remember you can only use a single tag per gameobject.. as long as thats not a deal-breaker.. i guess that could work

high summit
#

Oh wait, Yeah I cant put a tag on a box collider inside of a gameobject can i

rocky canyon
#

u could tag it if it were on a child go

high summit
#

Oh I see what you're saying

rocky canyon
#

this is how i usually set up interactions

high summit
#

Now i can give that a tag

rocky canyon
#

yup..

high summit
#

Also, I must have made a tag and forgot to apply it 200 times in the past month

rocky canyon
#

yup, thats pretty standard 😄

#

or creating a variable and then forgetting to assign it

high summit
#

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

rocky canyon
slender nymph
#

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

rocky canyon
#

i was gonna say u could probably go up the object to the parent lookin for em but boxfriends idea is better

high summit
#

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

solemn bobcat
#

Any ideas why one project has different External Tools settings? It's the same Unity version.

naive pawn
#

do you have the visual studio package in both projects to the same version?

solemn bobcat
rocky canyon
#

corruption of some sort?

grand snow
#

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)

solemn bobcat
rocky canyon
#

but copying the manifest was a solid idea too

solemn bobcat
rocky canyon
#

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

rapid laurel
#

Anyone could help here?

#

can't build my game 😒

whole osprey
rapid laurel
#

idk what it means

whole osprey
#

I am guessing your code has errors and can't compile.

rapid laurel
#

i have finished the game idk what i have to check if it is

rapid laurel
whole osprey
#

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.

slender nymph
rocky canyon
#

looks like this asset is missin

median hatch
#

debug the error, when you cant make a build unity creates logs for you

rapid laurel
#

ok i will try everything u said boys, thanks ❤️

rapid laurel
#

omg

#

thanksss

shadow briar
#

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.

tribal edge
#

You could use an event bus with mutable events

wintry quarry
# shadow briar Hello all, just asking if anyone can give a hand with me: I'm making components ...

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;
}```
shadow briar
rocky canyon
#

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)

naive pawn
rocky canyon
#

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

supple flume
#

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

naive pawn
rocky canyon
#

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

naive pawn
#

also what do you mean by "double digit variable"

supple flume
supple flume
naive pawn
#

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

supple flume
#

vector2int is 2 integars that are connected to each other right

rich adder
#

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; }

supple flume
#

you cant have one if the other isnt

rich adder
supple flume
#

so, lets say its a mapping 2 ints

rich adder
#

what are you trying to do again ?

supple flume
#

their location horizontally, and vertically

#

as in 1,1

#

1,2

#

3,10

rocky canyon
rich adder
rocky canyon
#

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....

supple flume
#

it wont be negative at all

rocky canyon
#

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

naive pawn
rich adder
#

ig 2D array would probably be a better way to "force" you to use 2 values..

naive pawn
#

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?

rocky canyon
#

whats the purpose of this data type

naive pawn
#

that would be either a Vector2Int (from unity) or (int, int) (from c#) or your own custom struct

rocky canyon
#

i think that would shed lots more light || custom structs ftw ||

long matrix
#
    {
        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
naive pawn
#

to be clear, are you asking about why this happens or how to fix it?

rich adder
long matrix
#

So what do you think the cause this problem?

naive pawn
#

the normalized vector

rich adder
#

you need to manually create the wall sliding logic

long matrix
#

Yes its beacues i noramlized my vector but then if i dont the player will move faster diagonally

naive pawn
# naive pawn the normalized vector

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

long matrix
#

yes, is there a way to stop that when colliding?

#

Hm guys so how can i fix this issue?

naive pawn
#

see nav's message

long matrix
#

How can i create the wall sliding logic?

#

oh sorry i forgot to say my project is a topdown 2d game so wdym sliding

rich adder
# long matrix 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...

▶ Play video
long matrix
#

ty

rich adder
#

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

jolly stag
#

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()
    {
        
    }```
tribal edge
#

What's the error? It's not finding it?

jolly stag
#

CS0029 can not implicity convert type 'UnityEngine.GameObject' to 'RandomScript'

polar acorn
#

Your variable is of type RandomScript

#

These are not the same type

full cobalt
#

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

jolly stag
polar acorn
jolly stag
polar acorn
full cobalt
#

IM NEW TO THIS SERVER IS THERE ANY PLACE WHERE I CAN GET SOME HELP

tribal edge
#

Here, if you ask a proper question

polar acorn
tribal edge
#

"Code is hard" is not a question

jolly stag
full cobalt
#

OKAY LET ME JUST RECORD MYU GAMEPLAY QUICK

eternal falconBOT
rich adder
#

also can we not with the Caps lock?

polar acorn
rich adder
#

then you picked the wrong hobby

polar acorn
full cobalt
#

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

supple flume
full cobalt
fickle plume
rich adder
#

also you need to look up unity Animation Riggin IK or something

full cobalt
#

@rich addertold me too ask her

rich adder
#

how did you get that from this..

jolly stag
rich adder
jolly stag
#
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);
    }
}```
polar acorn
naive pawn
rich adder
jolly stag
rich adder
polar acorn
jolly stag
# polar acorn So you'll need to set it in code after the object is created. So there _was_ a r...

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);
    }
}```
abstract copper
#

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

rich adder
jolly stag
rich adder
#

randomScript = FindFirstObjectByType<RandomScript>();

#

look at the docs

jolly stag
#

Will do! Thank you

polar acorn
long matrix
#
    [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?
jolly stag
broken fox
#

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?

shy forge
#

what wrong with my code?

rich adder
eternal falconBOT
iron pendant
#

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

rich adder
#

what are you trying to do exactly? whats the usecase

iron pendant
#

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?

iron pendant
#

i would like it to move point2 on screen as i drag point1 using unity's handles

rich adder
#

if its for like editor gizmos you could probably even use something like OnDrawGizmos that runs in editor as well

rapid laurel
#

anyone know where do i see package name: com."company"."mygamename"??

iron pendant
#

i didnt think of that, ig the benefit of this method is that the updates are all synced

rich adder
iron pendant
#

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?

rapid laurel
shy forge
#

@rich adder now my ide is correct?

brave robin
polar acorn
rich adder
#

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

rich adder
shy forge
rich adder
#

those are especially important topics for basics

untold elk
#

!code

eternal falconBOT
rich adder
#

did you miss the 📃 Large Code Blocks part

eternal falconBOT
untold elk
rocky canyon
#

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

untold elk
#

ah

#

oh my brain didnt load there tysm lol

rocky canyon
#

hey, i was reading that.. 😛

untold elk
rocky canyon
#

k.. so u said the raycast isnt following the player?

untold elk
#

yeah it isnt allowing him to detect that theres a block infront he should not pass thru

rocky canyon
#

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

untold elk
#

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?

rocky canyon
#

this is what id think it do

#

ud want instead to have it point out in front

untold elk
#

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

rocky canyon
#

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..

untold elk
#

ok im in a 3d realm so im assuming id do vector3.right and left

edgy tartan
#

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 = "";
   }```
polar acorn
edgy tartan
#

ah ok ty

#

i know i had done it before i forgot about doing that

untold elk
#

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?

tiny bloom
#

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

polar acorn
untold elk
#

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

polar acorn
#

Just don't have two event systems in the scene.

rich adder
tiny bloom
rich adder
untold elk
#

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

untold elk
teal viper
polar acorn
#

And also what you mean by "Event script"

untold elk
#

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

untold elk
#

yes

polar acorn
#

Does the button respond to the mouse at all, like when you hover over it?

untold elk
#

no it does not

polar acorn
#

Do you have an Event System in the scene

untold elk
#

yeah entitled main menu

polar acorn
#

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?

untold elk
#

sure

#

i did the whole photo of the window incase u needed to see the hierarchy etc

polar acorn
#

I needed a screenshot of the EventSystem

untold elk
#

ah ok

#

using stuff cut off

polar acorn
#

...I still need a screenshot of the EventSystem

untold elk
polar acorn
#

I don't know why you've sent code?

polar acorn
#

the component

#

called event system

polar dust
polar acorn
#

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

untold elk
#

omg wait my brain

#

i found it oop

#

but it only exists inside my mainmenu not the scene this code is in

polar acorn
#

then this scene will not function

#

An Event System is required for UI to work

untold elk
#

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

polar acorn
#

Did you drag in an object with that script on it

untold elk
#

wdym specifically as it is inside an object with the script in it and also has the script inside itself too

rocky canyon
#

then ud drag itself into it

#

isnt this what ur hunting for

polar acorn
untold elk
#

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 ?

shy forge
#

exist place where i can ask a for help learning c#?

polar acorn
#

What options are you seeing in the inspector when you drag in this object

untold elk
#

yeah but the class FDRslide never pops up so i only see the MainMenu class which lists these functions

polar acorn
shy forge
#

i need try understand every line?

teal viper
teal viper
polar acorn
#

Keep in mind this is pure C#, this won't do anything in Unity

shy forge
teal viper
shy forge
#

oh thank

untold elk
#

wait so to clarify i can have a fdrslide script in the object even though the fdrslide has a menu script?

rich adder
eternal falconBOT
untold elk
#

component as in script?

#

as to what u asked i had in the object

polar acorn
#

Component as in component

untold elk
#

ok then no

polar acorn
#

One of the things you've added to an object

#

Does the object have an FDRslide component on it

untold elk
#

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

polar acorn
#

You're trying to call a function on your FDRslide script

#

Does this object have an FDRslide component

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

untold elk
#

oh dayum and ty and no it does not so i can fix it now 🙂

#

yay it work tysm my brain has derot

rocky canyon
untold elk
rocky canyon
#

was just in case.. but with digiholic on the scene i knew i'd probably not get it done fast enough 😅

untold elk
# untold elk ok im in a 3d realm so im assuming id do vector3.right and left

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
frosty hound
#

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?

untold elk
#

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

rocky canyon
#

i believe that was me.. and i was under the impression u were doing 2D like a sidescrolling platformer

untold elk
#

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

rocky canyon
#

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

untold elk
#

i did want to go for the moveDir but im following his tutorial throughout so i didnt bother changing his code

rocky canyon
#

a CC comes w/ a collider and a Move() function that wont let u Phase thru objects

untold elk
#

since it worked for him

rocky canyon
#

if thats the issue ur currently having

#

can u show a screenshot of ur player? and the environment?

untold elk
#

ye

rocky canyon
#

so we know what kind of shapes, and the direction of movement and whatnot

untold elk
#

yeah im going to currently revert to the tut code (mind u i never heard of cc before this moment)

rocky canyon
#

and have u considered using the CharacterController? it has lots of quality of life things that u dont have to do soo much

untold elk
#

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

rocky canyon
#
        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...

▶ Play video
#

dozens of tutorials for CC's out there. heres one i found w/ the top-down perspective like u have

untold elk
#

ohh ty i was gonna use a basic tutorial in generalizations and usage in most cases

rocky canyon
#

it'll help keep things simple so u can understand better.. and then u can go out and adapt and modify

untold elk
#

ah ty and then i would in the future make manual code outside of the cc script or inside the cc script?

rocky canyon
#

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

rocky canyon
#

u write the script to manipulate that component..

#

and can be anywhere technically.. as long as u have a reference to it

untold elk
#

oop i meant the scripts u add for the cc lol

#

and ok ty

rocky canyon
#

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

untold elk
frigid sequoia
#

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

eternal needle
frigid sequoia
#

Still feels like maybe not optimal to store a high value you are really not gonna use, even if the difference is minimal

eternal needle
untold elk
#

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?

rich adder
acoustic belfry
#

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);
    }
}```
north kiln
#

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

acoustic belfry
#

oh, makes sense

well thanks

solemn crypt
#

Making a music game any ideas on what to do with input key down functions

#

Or is that more advanced coding ?

pseudo frigate
#
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

pseudo frigate
#

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?

rich adder
#

i think also you can do !=

pseudo frigate
#

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

north kiln
#

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

pseudo frigate
#

i switched to using raycasting and that seems to be working fine, just a weird issue with overlapbox 🤷

toxic cove
#

uhhhhh anyone know a fix?

rich adder
rich adder
toxic cove
#

im sorry im new

#

but uh

#

where do I fix this at

rich adder
toxic cove
#

ahhh

#

using UnityEditor.Callbacks;

#

should I just remove this

#

oh wait

#

its done

rich adder
#

what are you using it for

#

either put it in an editor only class or wrap it in compilation statements

toxic cove
#

so I have no clue

rich adder
#

IDE auto-insert prob

toxic cove
#

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

rich adder
#

intellicode or intellisense depending on the context

toxic cove
#

accepts the code

rich adder
# toxic cove accepts the code

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

willow iron
#

can you mess with cinemachine statedriven camera instructions using a script at runtime?

hollow niche
#

Why is my tilemap stuck vertical?

rich adder
#

also not a code question

#

ur scene view if you press 2D button its properly oriented

acoustic belfry
#

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);
neon glade
#

oops wait

alpine heron
#

Hello! My collision detection isn't working, can you guys please help.

#

Here is a screenshot of the issue and then code beside it.

slender nymph
#

!code
also show the relevant collider(s)

eternal falconBOT
alpine heron
#
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.

slender nymph
#

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?

alpine heron
#

The cube or any object.

slender nymph
#

so show the collider

alpine heron
#

I'm a beginner, I don't know what you mean.

slender nymph
#

do you know what a collider is?

alpine heron
#

Yes, I do, I just don't know what mean by show the collider.

slender nymph
#

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.

alpine heron
#

Hopefully this suffices, here is the screenshot.

slender nymph
#

is that the collider you are expecting to hit with your raycast?

alpine heron
#

It's a collider detection, so it can't go into object, so sure.

slender nymph
#

that collider is irrelevant to your hit detection. you are using a raycast, not that collider

alpine heron
#

Yes, I know.

#

I'm learning, and I need the raycast, how do I get it functional.

slender nymph
#

i feel like you are just not understanding what i'm asking here. or anything about what i've said so far.

alpine heron
#

I would like to understand how to fix the collider detection, that's the question.

alpine heron
slender nymph
#

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.

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

alpine heron
#

If I'm using the wrong practices that's on me, but I'm doing it manually to learn.

toxic cove
#

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.

😭

slender nymph
#

but also read the error, you may need to disable or change the compression used

toxic cove
#

but I cant find it

#

ill try again rq

quiet epoch
#

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...

cosmic charm
#

for some reason my character gets stuck sometime between tiles, I actiavted used by composite but still not working correctly

naive pawn
eternal falconBOT
naive pawn
cosmic charm
naive pawn
#

doesn't sound like that'd reliably solve it

quiet epoch
naive pawn
quiet epoch
#

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.

naive pawn
#

sounds like an issue with your animator rather than here

quiet epoch
#

here is my animator

naive pawn
#

check the transition parameters, do they look right

quiet epoch
#

my transition work like that

naive pawn
#

and what's the right side

quiet epoch
naive pawn
#

and have you done the debugs i told you to do? or just checked to confirm that AttackDirection is what it should be

zealous garden
#

I have a dodge roll animation setup for my player that uses root motion.
I have a few issues

  1. The roll animation does not seem to finish fully when pressing the roll key
  2. my camera does not seem to follow the player when dodge rolling ( can show relevent scripts for that)
  3. the player returns to the starting roll position when the dodge roll ends
naive pawn
#

!code

eternal falconBOT
naive pawn
#

sounds like you should set exit time on the roll animation though, for the first and possibly third issue

zealous garden
#

I should set the exit time?

#

from the transion of the dodge roll, or out of the dodge roll

naive pawn
#

out of the dodge roll

zealous garden
#

yes ive done that

naive pawn
#

and transition time is set to 0?

zealous garden
naive pawn
#

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

zealous garden
#

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

naive pawn
#

where are you doing the camera following?

zealous garden
#

Camera script, can show you that, one second

undone depot
#

how can i change a UI image's source image with a script?

spiral narwhal
undone depot
naive pawn
#

what changes is possibly how you get that reference

wicked raptor
#

im really trying to learn unity but i dont how to solve this

wintry quarry
#

Player

#

Search for "active input handling"

#

And change it to "Both"

wicked raptor
#

i dont have active input handling

#

nvm

#

im stupid

#

thanks

viscid girder
#

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.

viscid girder
#

yes

polar acorn
#

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

polar acorn
#

Do you see the trigger getting set? Does it spend any time in the animation state?

viscid girder
polar acorn
viscid girder
polar acorn
#

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?

shut swallow
#

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

polar acorn
#

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)

shut swallow
polar acorn
verbal dome
#

digiholic's advice also assumes that your VFX graph works in local space, not world space

shut swallow
#

I want it to work both cases

#

both locally as a child of the player and world space

verbal dome
#

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

verbal dome
shut swallow
#

as in, I want to be able to spawm both relative to the player and independent from the player

verbal dome
#

Alright, then you probably want to have the VFX use world space and pass in the position and rotation manually

shut swallow
#

yep, and I have these values already

#

I just need to know how to pass it

polar acorn
verbal dome
shut swallow
polar acorn
shut swallow
#

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?

cosmic dagger
#

I mean, the only way to tell is it test it out, no?

shut swallow
#

one more question, how to cull the prefab after spawning it?

frosty hound
#

Cull it from what? 🤨