#💻┃code-beginner

1 messages · Page 444 of 1

wintry quarry
#

Yeah but you would want to turn off gravity for this, no?

muted wadi
#

let me give that a try

wintry quarry
#

body.useGravity = false;

muted wadi
#

even turning off gravity doesn't seem to fix it

#

i can see the rigidbody's use gravity checkbox gets unticked while im wall running too

wintry quarry
muted wadi
#

is there anything in particular you want to see because the script is really long

#

dont think i can post it here

wintry quarry
#

!code

eternal falconBOT
muted wadi
wintry quarry
muted wadi
#

could it be because of my jump?

#

actually maybe not, its not being called every frame

muted wadi
wintry quarry
#

time to add more logs and/or attach the debugger

wintry quarry
#

since tempGrav will be practically 0 (unless your gravity is crazy high to start), you're Slerping towards essentially 0

muted wadi
#

yeah thats the weird part

#

i turned it way down just to test but the gravity stays the same

#

i seriously dont get it

#

wait hold on

#

you were right before

#

i changed the slerp to lerp and now the gravity is changing

#

how tf does that even work

#

thanks for the suggestion anyway

wintry quarry
#

Slerp is really for direction vectors

#

linear stuff should use Lerp typically

muted wadi
#

ah i see

karmic isle
#

itll probably just be easier to rewrite my code for rigidbodies wouldnt it?

#

ill do it tomorrow im irritated

rocky canyon
summer stump
buoyant knot
#

the main benefit of rigidbodies is that they already have implementation to interact with unity’s whole physics system. To connect with and interact with colliders of different shapes.

#

And to stage the movements so motion can respect collisions.

#

The downside is that rigidbodies have several aspects about their implementation that are hard to get around if you need to.

twin bolt
wintry quarry
#

you're treating it like it's a set of euler angles

#

you can't do that

#

because it's not

#

i.e. plugging transform.rotation.x into Quaternion.Euler(x, y, z) is not valid

#

you're putting a square peg into a round hole

#

garbage in, garbage out

twin bolt
#

so do EulerAngles instead?

wintry quarry
#

no

#

it's best to avoid reading euler angles back from a transform if at all possible

#

they're not reliable

#

what are you trying to accomplish

twin bolt
#

I'm just trying to rotate towards -40 of the current z value.

wintry quarry
#

I'm not sure what that means exactly. That's not very precise language

twin bolt
#

I'm trying to rotate towards a certain value. That value will be the current z value - 40.

wintry quarry
#

Perhaps something like:

Quaternion targetRotation = transform.rotation * Quaternion.Euler(0, 0, -40);```
Then later on:

```cs
Dial1.transform.rotation = Quaternion.RotateTowards(Dial1.transform.rotation, targetRotation, Time.deltaTime * speed);```
gusty scaffold
#

wow you're still helping out here

#

i have another question

#

can i remap materials on a per-instance basis?

muted wadi
#

@wintry quarry hey, you helped me with my script before, could you also help me figure out why when i stop the wall run coroutine, the player's speed is still super slow and seems like the coroutine is continuing even though it should be stopped? https://hastebin.com/share/sujinutufi.csharp

raw token
muted wadi
#

added a bool but that didn't seem to fix it

raw token
#

There might also be a problem when you stop the wall run before the coroutine runs to completion - body.useGravity may still be false

muted wadi
#

i tried setting use gravity to true separately but that didn't seem to fix it either. I mean its strange because if i stop the coroutine then it should just stop where it is and not even run the part after the while loop

raw token
#

One more thought: I'm not actually sure whether or not a stopped coroutine will pass an equality check for == null... On paper it would still be a non-null value, unless Unity overloads the equality operator like they do for destroyed game objects.

You might test that just to be sure 👀

wintry quarry
#

So these won't run

#

Which doesn't bode well for the rest of your script

muted wadi
rich adder
muted wadi
#

im at a loss here i have no idea what im doing wrong

#

the slide coroutine doesn't have this problem

#

if you start a slide you can end it whenever you want and you'll have your regular movement speed immediately

raw token
#

What's the current state of your code?

muted wadi
raw token
muted wadi
#

yeah that seems like it could be an issue

#

ok so i've added a little check in update
if (isWallRunning && wallContact == null) { StopCoroutine(wallRunRoutine); }
but the issue still persists

raw token
#

Where did that go? I would think to just chuck a Debug.Log() into WallRun() just to check if it's starting multiple times

muted wadi
#

alright lemme try that too

#

btw that check just went to the bottom of update

raw token
muted wadi
#

yeah wallcontact is a variable in another script that just checks whether or not the rigidbody is in contact with a wall. I can see it update through the editor and it doesn't react when touching the floor if you're wondering

#

also i checked the debug log and it seems like when im touching the wall in midair the wallrun coroutine is being called every frame

raw token
#

Excellent - we've located a relevant problem at least 😅

muted wadi
#

okay so, the sliding is only called once when the coroutine starts and loop runs any amount it needs to, but the wallrun routine is called every frame even when the debug isn't in the while loop

#

oh my god

#

thanks so much

#

the problem was that i forgot to assign a check to wall running like i did with sliding. Sliding has a check to make sure it doesn't get called if isSliding is already true. Wall running didn't have that.

raw token
#

I had just reached that conclusion myself 😁. Solid!

muted wadi
#

the only other problem i have now is that jumping off the wall doesn't seem to work the way i want it to

#

it kind of just boosts me forward instead of up

steep walrus
#

I have these targets in my game that I shoot down and I want to reset them automatically after 5 seconds. I have some of the code but I dont understand how I would go about "saving" the original position. I only have one variable for it but would I need 5 variables as I have 5 targets?

#

oh wait nvm I think i just figured it out

rich adder
#

I would make a custom class to keep it neat

steep walrus
#

would making an empty at the original position for each target and then using that as the transform be a valid solution?

rich adder
#

but ig how you have is good too store it directly on the object itself as V3

rich adder
#

why do you need the whole transform?

steep walrus
rich adder
#

yeah thought you only want old Position

steep walrus
#

i dont really know how to store stuff in a list or what even a dictionary is and i also dont know what a custom class is

#

i think i do want the correct rotation tho fs cause i dont want them keeping their rotation after falling

rich adder
steep walrus
#

scale obviously doesnt change tho

rich adder
#

then modify it with a method

raw token
# muted wadi it kind of just boosts me forward instead of up

That might be because after the apex of the wallrun the body may already have some downwards velocity, and since the jump velocity is additive some portion of it would be spent counteracting what's already there. This could have the net effect of slowing the descent or gliding...

But if that's the case, I would think it would behave more as you would like when jumping anywhere prior to the apex

rich adder
#

so yeah thats why I suggested a custom class to also keep rotation

steep walrus
#

i see

#

yeah thats a good solution

#

ill try that

rich adder
#

custom class is nothing to fret, its just defining how an object would be.
this case you could combine Vector3 and Quaterion

#

or 2 Vector3s and store as euler

muted wadi
steep walrus
#

okay well my solution almost worked but the only issue is that they kept their original rotationfor some reason

steep walrus
rich adder
steep walrus
#

i do not have that in my code no

raw token
rich adder
muted wadi
#

really appreciate it

rich adder
# steep walrus i do not have that in my code no

this is also valid

private Vector3 oldPosition;
private Quaternion oldRotation;
public void Awake()
{
    oldPosition = transform.position;
    oldRotation = transform.rotation ;
}
public void Restore()
{
    transform.position = oldPosition;
    transform.rotation = oldRotation;
}```
steep walrus
#

that is what i wrote and when they respawn in the original spot they keep their rotation from when they fell on the ground so 90 off. they also glitch out randomly for a few seconds and then do nothing. when i try and shoot them again they have absolutely no physics

rich adder
steep walrus
#

okay ill make sure to store that and apply that

#

also is that maybe why they were glitching out. like does unity not like their physics colliders not connected?

rich adder
#

no you have to actually reset the velocity

#

when you teleport you still mainan the old velocity

#

im guessing this is whats happening , not sure

steep walrus
#

i think they were fully still but how would i set velocity to 0

rich adder
#

rb.velocity = Vector3.zero // linear vel
rb.angularVelocity = Vector3.zero // rotation vel

steep walrus
#

i put those two lines of code in the IEnumerator and im getting errors

#

should i put them somewhere else?

polar acorn
steep walrus
#

"the name rb does not exist in the current context" does it think its supposed to be a variable?

#

im assuming i did something wrong and was supposed to define it somewhere

polar acorn
steep walrus
#

no

polar acorn
#

So that would be the problem

steep walrus
#

oh so do I need to name a transform to some unity function

wintry quarry
#

You can only use variables that have been previously declared

polar acorn
#

What are you trying to change velocity or angularVelocity on?

timid pike
#

anyone got an idea what this means in simpleton words?

steep walrus
#

thats what i mean do i have to declare like "public (some unity function i dont know) rb"

steep walrus
#

which are targets that are just stretched out cubes

wintry quarry
polar acorn
wintry quarry
#

variables have types

steep walrus
#

variable types yeah sorry

wintry quarry
steep walrus
wintry quarry
#

ok so you need a reference to the Rigidbody of course

steep walrus
wintry quarry
#

make a variable

#

drag and drop it in the inspector

steep walrus
#

what kind of variable

polar acorn
wintry quarry
polar acorn
#

So, you probably want to make a variable that holds one

wintry quarry
steep walrus
#

gameobject

wintry quarry
#

no

#

Not a GameObject

polar acorn
steep walrus
#

then rigidbody?

wintry quarry
#

yes

steep walrus
#

is that a variable type?

wintry quarry
#

of course

rich adder
#

how were you using rigidbody this whole time?

wintry quarry
#

All components are

steep walrus
rich adder
# steep walrus wdym?

you said they were rigidbodies.. i guess they just fall ? you never applied any force to them?

steep walrus
#

okay so now I would assign the specific target rigid body to that? and that would allow me to set the rigid body velocity to 0 as well as the position to my original position??

timid pike
steep walrus
rich adder
# steep walrus

i see. so you shoot them and you want them to reset how they were?

steep walrus
#

i can shoot them and they fall down correctly and after the 5 seconds its told to wait in the code they respawn like this

rich adder
#

so you throw a projectile at it not a raycast, thats why they fall down. Gotcha

steep walrus
#

yes projectile

#

sorry if i wasnt clear i dont have the knowledge of what is and isnt important and relevant to my code

rich adder
#

ok so then just reference the rigidbody thats on the target

steep walrus
rich adder
steep walrus
#

oldPosition = rb.position;

#

like that

rich adder
#

ofcourse you need the component rigidbody referenced

#

correct

steep walrus
rich adder
#

this script i s on the target?

steep walrus
#

yes

rich adder
#

just call it rb

#

target doesnt make sense to me

steep walrus
#

okay ill add the other stuff now

#

and i js changed it ot rb

#

quick question is this part of the code setting those variables to the position and rotation to whatever they are at the very beginning of the game starting?

rich adder
steep walrus
#

and oldRotation is a Transform correct?

rich adder
#

no its a quaternion as I wrote it

#

unity stores rotations in quaternions

#

they prevent gimbal lock issues

steep walrus
#

oh im understanding some of the stuff you were saying earlier better now this is making a little more sense

rich adder
#

haha yeah it creeps up on ya

raw token
steep walrus
# rich adder haha yeah it creeps up on ya

The code I wrote earlier when I had originalPos as a transform variable is now giving me an error saying that vector3 doesnt have a .position
how would I go about changing the vector3 as a position

#

that was my attempt

rich adder
#

Vector3 position is a struct inside Transform

eternal needle
#

Vector3 is the type, a position is a Vector3

rich adder
#

Transform holds all 3
Vector3 Position
Quaternion Rotation
Vector3 Scale

steep walrus
#

oh i see

#

is that it?

wintry quarry
#

you can omit the this.gameObject part

rich adder
#

this is still wrong for two things

wintry quarry
#

just transform.position =

#

but also this is not anything to do with the Rigidbody

rich adder
#

you want to move the rigidbody position , and assign the variable you had stored

#

right now you're setting it to world 0 , 0 , 0

steep walrus
#

yeah i was just doing that as a placeholder

#

im not understanding these errors but is that how I would want to format tha

burnt vapor
#

The errors are very clear

rich adder
#

i literally wrote it for you

steep walrus
rich adder
#

i just said replace all the ones I wrote with transform with rb. You did something completly different

steep walrus
#

no errors this should work>?

burnt vapor
rich adder
#

why is transform.position still there

burnt vapor
#

Seriously, just test your code instead of asking

rich adder
#

you dont want to modify the tranform directly with rigidbody
delete the 2 lines transform

steep walrus
steep walrus
rich adder
steep walrus
rich adder
#

share the code with the proper formatting instead of screnshot I can show you since this might go on another half hour

steep walrus
steep walrus
#
 private IEnumerator ResetPos(Vector3 originalPos)
    {
        yield return new WaitForSeconds(5);
        rb.position = originalPos;
        rb.rotation = originalRot;
        rb.velocity=Vector3.zero;
        rb.angularVelocity = Vector3.zero;
    }
}
#

thats what im about to test

#

that almost worked. like visually the targets are in the right spot but the bullets just go right through

#

oh actually it looks like the bullets get affected but the physics are basically gone with the targets like they arent moving at all

rich adder
#

how many times is this function called

#

its in update which looks like once you hit iit, it keeps calling it

#

you need a better way to start this coroutine

#

use a Public method which the projectile will call OnCollisionEnter

#

get rid of that Update

steep walrus
rich adder
#

i know what it does, regardless its flawed logic

steep walrus
#
 public void OnCollisionEnter()
    {
        if(currentPos != originalPos)
        {
            StartCoroutine(ResetPos(originalPos));
        }
    }
#

thats what i have now and i got rid of the void update

rich adder
#

noo

steep walrus
#

do i need to get rid of the if statement

rich adder
#

this will call it when the item hits other stuff

#

OnCollisionEnter goes on the PROJECTILE script

steep walrus
#

ohhhhh okay

rich adder
#

the Target item only has a Public method that Starts the coroutine

steep walrus
#
public void OnCollisionEnter()
    {
      
    }
#

i added that in the "bullet" script i already ahve which is applied to my bullet prefab

rich adder
# steep walrus ```cs public void OnCollisionEnter() { } ```

    //projectile script
    private void OnCollisionEnter(Collision collision)
    {
        if(collision.collider.TryGetComponent(out ResetTargets target))
        {
            target.Hit();
        }
    }
    //ResetTargets script
    public void Hit()
    {
        if (restoring) return;
        StartCoroutine(ResetPos());
    }```
#
//ResetTargets script
bool restoring;
 private IEnumerator ResetPos()
{
  restoring = true;
  yield return new WaitForSeconds(5);
  rb.position = originalPos;
  rb.rotation = originalRot;
  rb.velocity=Vector3.zero;
  rb.angularVelocity = Vector3.zero;
  restoring = false;
}```
#

hope it makes sense where you're not blindly copying it..

steep walrus
#

i wasnt blindly copying it earlier i swear 🙏 i just dont have a good base knowledge of unity in general

#

thats why i was having a hard time i think cause i was comparing what you were saying without fully looking at the code

rich adder
steep walrus
rich adder
#

read the comment above

#

actually you can even get rid of the Parameter for IEnum thats useless if its a field already. Edited

timid pike
#

can someone tell me what this means? i dont have a single variable called "onclick" in all my scripts

wintry quarry
#

look at the full error

tired junco
#

Hey, im currently attempting to create a third person character controller but im facing weird camera/world/player glitch effects (see video) this effect appears either on the player or on the world when im switching the camera (cinemachine free look camera) mode from lateupdate to fixedupdate and vice versa here's the code https://pastebin.com/wizzRc2Z

rich adder
timid pike
#

whoopsies

rich adder
#

you're supposed to yes

timid pike
#

oh ok

rich adder
#

making sure index.html is at the root

steep walrus
# rich adder read the comment above
 if(collision.collider.TryGetComponent(out ResetTargets target))
        {
            target.Hit();
        }

i only have an error on "Hit" and its telling me its "inaccessable due to its protection level" and im not sure what that means

rich adder
timid pike
wintry quarry
timid pike
#

true

rocky canyon
#

i would concur

steep walrus
timid pike
#

it doesnt affect the game at all it just does an annoying popup when you start it and i wanna get rid of it, probably gonna have to go to newgrounds forums since this seems like a problem with the website

rich adder
#

I don't mean the final zip files.

#

inside the WebGL settings in unity, compression method. Try without compression

#

I know github throws a fit when I upload webgl compressed

muted wadi
#

so I know that it's possible to get the normal of an object using contact points, but how would i get this vector and what is it called? The idea is that when the player collides with an object, the camera forward will determine what direction that line will move in along the object.

eternal needle
wintry quarry
#

and yes - vector projection will get it

#

project the camera forward vector on the normal

muted wadi
wintry quarry
#

e.g.
Vector3 tangent = Vector3.ProjectOnPlane(cameraForward, surfaceNormal).normalized;

muted wadi
#

could you dumb it down for me 🙏

mint remnant
#

n is just the cross product of 2 vectors that lir on the plane, if it's in the downward direction swap the order of the cross product vectors

wintry quarry
#

camera vector is the dark blue
projected vector is the light blue

#

the surface normal is not pictured, but it would be sticking straight up out of the yellow plane

#

imagine shining a light straight down on the surface

#

and your vector casts a shadow

#

that's what vector projection is

muted wadi
#

oh ok

#

so when the camera vector comes in contact with the object, the projected vector only takes into account the direction along the object's surface?

wintry quarry
#

well the vector doesn't "come in contact with" anything

#

projected vector only takes into account the direction along the object's surface
Yes

muted wadi
#

ok im starting to understand

#

if it doesn't come into contact with the object then how does it know a vector is being projected onto it?

timid pike
wintry quarry
#

we just did some math with the vectors

#

we know because we chose to do the math

#

none of these things are "aware" of anything, they are mathematical abstractions

rich adder
#

if it still gives error then its probably 100% on their end

#

unless you test it on itch i suppose

muted wadi
#

@wintry quarry thanks so much for that explanation, it works perfectly

#

i just suddenly found out there's a lot to like about vectors

mint remnant
raw token
#

I never appreciated vectors in my physics coursework. I wish I had

#

They were neat, but not compelling, at the time

rare socket
#

Is it fine to have a coroutine running throughout my games entire duration?

raw token
#

Sure

rich adder
#

profile it if you have issues

rare socket
#

Will do :D

muted wadi
rich adder
#

in the context of school is boring, learning this in the context of a game stimulates the brain more for me

rocky canyon
muted wadi
#

oh definitely, i want to learn way more when its something i care about

rich adder
#

they dont really teach WHY exactly its important

#

not in my school at least

rocky canyon
#

not in america

ancient rampart
#

how would you guys recommend I setup a scrollspeed for my timeline, since it'll be based on bpm, I need that time to scroll consistently based on seconds so that my beats line up, it seemed to work fine up until I tried to introduce deltatime

rich adder
#

my cousin was raised in decent suburbs they had interesting classes like robotics n shit.
in mine had at most sports..lol

rocky canyon
muted wadi
#

is there a function in unity like ProjectOnPlane but for finding the edge of an object?

rocky canyon
rich adder
#

sports suck when you're a hermit lol

rich adder
rocky canyon
muted wadi
rocky canyon
#

u can just raycast forward. and increment the raycast upwards until it misses lol

muted wadi
#

wdym increment the raycast?

rocky canyon
#

raycast from center.. -> u hit.. okay
raycast from center + 1 upwards -> u hit.. okay
raycast from center + 2 upwards -> u missed..

#

meaning.. the ledge is between 1 and 2

muted wadi
#

oh, this just sounds like edge detection in shader programming lmao

rocky canyon
#

yea, but there'd be more too it..

raw token
rocky canyon
#

u'd have to check if its the same object ur hitting..
u'd have to check if ur within range..
u'd have to check when u miss it is indeed a miss.. and u just didnt shoot thru a gap or something.. etc

muted wadi
#

interesting

ancient rampart
#

hmm how how would that work? just check to see when the beat object passes over a certain part of the screen?

#

and then do a bunch of timer stuff to get the intervals logged?

rocky canyon
#

now that i know what ur talkin about.. theres tons of examples/ tutorials/ code

rocky canyon
ancient rampart
#

that sounds super inaccurate for this

rocky canyon
#

ofc, u'd have to watch it for a while b/c just a tiny tiny offset would add up big

#

lmao

rocky canyon
muted wadi
# rocky canyon just search for "ledge detection, unity"

alright, i'll have a look, its usually just tough to find a tutorial that has elements which work with my current setup. I kinda dont have time to rewrite my entire movement script around one mechanic so I'm trying to work with what I can.

rocky canyon
#

but im not that math savy, perhaps someone else

rocky canyon
#

u get better at adapting the code..

#

taking fundamentals u learn.. adapting them to ur own use-case

muted wadi
#

yeah, i think i'll find something though

rocky canyon
#

thats where alot of ppl go wrong..

#

they just copy tutorial from cover to cover.. and never really learn anything they're watching

#

😢 makes me sad

muted wadi
#

i try not to make that mistake since im aware that just copying does no good

rocky canyon
#

.. it does until u want to change it

rocky canyon
muted wadi
timid pike
timid pike
# rich adder awesome! good to know

its funny because i made the game like january - march of last year but never bothered to fix the issues until now because im trying to get back into the groove of game development so i might as well patch it

#

it was a fun first project

rich adder
timid pike
#

yeah

rocky canyon
#

(╯°□°)╯︵ ┻━┻

#

can u use breakpoints and the debugger to follow the flow of a script?

rich adder
rocky canyon
rocky canyon
rich adder
#

basically once you hit breakpoint you can step through

safe radish
# rocky canyon i need to learn to do that real quick

There is nothing exciting about debugging, but it's such a vital tool for any developer. Train your debugging skills now and you'll save an unfathomable amount of hours searching through your code trying to find bugs.

❤️ Become a Tarobro on Patreon: https://www.patreon.com/tarodev

=========

🔔 SUBSCRIBE: https://bit.ly/3eqG1Z6
🗨️ DISCORD: htt...

▶ Play video
rocky canyon
#

thankyou, edit: im about to get fool-proof 😅

ivory breach
#

I want to implement an ammunition system for my special weapon where the game would check from left to right if any of the meters are full, and empty the first full meter the game finds, and fire a rocket. Can anyone help me how I can do that?

rocky canyon
ivory breach
#

The picture is just a mockup btw

deft grail
rocky canyon
ivory breach
deft grail
#

i imagine you would be using them from right to left instead

rich adder
ivory breach
#

Soemtimes the other meters might be full instead of first one, in which case the game would empty one of the other full meters instead

rocky canyon
deft grail
ivory breach
rich adder
#

ideally this would be an array yea

#

dont focus on "the bars"

#

this should all be data in code

rocky canyon
#

values* rather

#

if value = maxvalue (delete dat bich)

#

else skip to the next one

rich adder
#

do you have some type of AmmoBars[] ammoBars

ivory breach
rocky canyon
#

0 being the left or right.. -> and just assign them in order

ivory breach
rocky canyon
#

yess

rich adder
#

or int, depending what kinda weapon you do ig

rocky canyon
#

yup yup ^

#

AmmoManager.cs for ie.

ivory breach
deft grail
rocky canyon
#

no.. u could keep up with all ur weapons in 1 class if u chose

rich adder
#

yea this is getting a bit abstract of a question

rocky canyon
#

lol

rich adder
#

how you define it is up to you

#

could be even an enum

rocky canyon
#

scriptable objx

ivory breach
#

I'll start working on the rockets' ammo system now following your advice

rocky canyon
#

yea, if u never done it b4 just focus on 1 ammo type.. (just a value really)

#

and do the logic/ math and conditionals

#

then come back

rich adder
#

for sure start with the basic one

sleek marten
#

I have multiple scripts on my player but I only need one active at a time. I need those scripts to be active in a specific order. Only one script in that order should be active at a time. what is the best way to manage that?

sleek marten
deft grail
sleek marten
#

surely there's a more efficient way to doing this than having a million "disable everything but this" functions

rocky canyon
#

could call an event

deft grail
rocky canyon
#

thats what i always do.. forloop (disable all) -> enable the one i need

#

every time

#

could even have it a method..

#

DisableAll()

sleek marten
#

@rocky canyon could you elaborate on how that process works? I'm trying to imagine it in my situation

deft grail
rocky canyon
#
    public void EnableGameObject(int index)
    {
        // Disable all GameObjects
        foreach (GameObject go in gameObjects)
        {
            go.SetActive(false);
        }

        // Enable the specified GameObject
        gameObjects[index].SetActive(true);
    }```
#

but in ur case, u could use w/e component u wanted

#

.enabled = true / false

ivory bobcat
ivory bobcat
vital storm
#

I'm trying to make an entity that spawns in every minute or so and hunts down the player. When that entity touches the player, it would flash an image onto screen and play a sound. Could someone help me with that? I'm pretty new to Unity so I don't really know much.

deft grail
ivory bobcat
deft grail
#

how do you spawn an enemy 1st

vital storm
vital storm
deft grail
vital storm
#

ok leme see

#

!docs

eternal falconBOT
vital storm
#

wait actually no

#

i worded that wrong

ivory bobcat
sleek marten
rocky canyon
#

correct

deft grail
rocky canyon
#

u'd not want multiple 'enable components' u'd just need a script to know about all of em and just enable 1 (disable the rest)

ivory bobcat
vital storm
polar acorn
rocky canyon
#

enabling a gameobject

vital storm
#

yeah enabling a game object

polar acorn
#

There are many checkboxes in Unity

#

Without context, this could be any checkbox

vital storm
#

this one

#

in the inspector

polar acorn
#

Yes, that is activating or deactivating a gameobject

deft grail
vital storm
#

how can i make it so after 1 minute an entity activates until it touches the player

sleek marten
#

well if I've got an array, and each thing is indexed from 0-5 then I'd want to do something like...?
each time the counter reaches 5; enable the next object in the array. Disable all others

ivory bobcat
deft grail
raw token
# ancient rampart hmm how how would that work? just check to see when the beat object passes over ...

I need to think on this more, but my brain is now spaghetti... This is either a vaguely clever start, or it's very very stupid. I was thinking of something along the lines of this psuedo-code.

Based on beats per second, it keeps track of how long ago the last beat should have occurred - a "beat delta time" - and a method that gets called as close to the previous beat as possible. The bps value could be multiplied to increase the number of beats per... tempo beat, I guess?

My hope is that a frequently resetting timer would be less affected by floating point inaccuracies... Though maybe there's a place in there somewhere to squeeze a little more accuracy out of doubles, if it proves necessary.

It may also benefit from actually checking how far along the audio playback is, if the tracks are not so long as to add more inaccuracies...'

deft grail
rocky canyon
#

that code would run a coroutine like digi mentioned

sleek marten
#

I'm just trying to validate the logic

vital storm
#

so basically the entity starts deactivated, after a certain amount of time it actives itself. When it touches the player it would go back to being deactivated and return to its original position. It sounds very simple on paper but I am a noob at C# so I don't really have a grasp on how to code all of that.

late burrow
#

for how long private variable will keep its value in editor

polar acorn
rocky canyon
polar acorn
late burrow
#

so until i close unity

ivory bobcat
rocky canyon
#

nah just during the game

late burrow
#

editor script

rocky canyon
#

once u restart the game.. or stop it.. it goes back

sleek marten
rocky canyon
#

why not debug it

ivory bobcat
#

If you've got some strange bug occurring, you ought to just explain what's happening.

polar acorn
# late burrow editor script

If you've used an editor script to expose a variable in the inspector, then it will be essentially identical to a normal public or serialized variable

vital storm
rocky canyon
#

search it up.. you've been told the sequence of events

deft grail
rocky canyon
#

"how to enable disable gameobject in unity"

#

"how to use a for loop in unity" etc

#

once u get stuck on something then return with specifics

late burrow
#

tutorials should start with foreach for is super unintuitive

rocky canyon
#

nah, pretty common in most languages.. well a forloop anyways

#

foreach may be special.. idk

ivory bobcat
crisp token
#

im making a non monobehavior class but id like to use Vector3, should I just make my own struct or is there a way I can import it

rocky canyon
#
  • for Loop: Use when you need to know the index or when you need to iterate a specific number of times.
  • foreach Loop: Use when you only need to access each element in a collection without modifying the collection's structure.
eternal needle
crisp token
#

ty

eternal needle
#

As long as you have using UnityEngine; itll be usable

rare socket
#

How do I solve these errors?

polar acorn
rare socket
#

Okay, will look into it :D

crisp token
#

is there a way to make getters and setters for these without writing out entire methods?

ashen scaffold
#

!code

eternal falconBOT
eternal needle
polar acorn
rare socket
# eternal needle Could also just be a unity error, is there a stacktrace

Yeah, but its quite the mumbo jumbo:

ArgumentNullException: Value cannot be null.
Parameter name: _unity_self
UnityEditor.SerializedObject.FindProperty (System.String propertyPath) (at <35c0e5f206594d2fa707969117964d70>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindPropertyRelative (UnityEngine.UIElements.IBindable field, UnityEditor.SerializedProperty parentProperty) (at <a26505b064194c429b83f4a02cfddb4d>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <a26505b064194c429b83f4a02cfddb4d>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.ContinueBinding (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <a26505b064194c429b83f4a02cfddb4d>:0)
UnityEditor.UIElements.Bindings.DefaultSerializedObjectBindingImplementation+BindingRequest.Bind (UnityEngine.UIElements.VisualElement element) (at <a26505b064194c429b83f4a02cfddb4d>:0)
UnityEngine.UIElements.VisualTreeBindingsUpdater.Update () (at <b8c852c145a8456ba2512bf23f96ab0b>:0)
UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <b8c852c145a8456ba2512bf23f96ab0b>:0)
UnityEngine.UIElements.Panel.UpdateBindings () (at <b8c852c145a8456ba2512bf23f96ab0b>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <b8c852c145a8456ba2512bf23f96ab0b>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <b8c852c145a8456ba2512bf23f96ab0b>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <a26505b064194c429b83f4a02cfddb4d>:0)

crisp token
rare socket
eternal needle
rare socket
eternal needle
#

Not really much to look into tbh, you just simply clear the errors and move on. I vaguely recalling having those errors on some scriptable objects but never remembered why

#

If it's not going away, then could always try resetting layouts/restarting unity (but that couldve been for another error)

polar acorn
#

Could also be passing a null to some static function like PlayClipAtPoint

rare socket
crisp token
#

will including the "set" accessory with a class like Vector3 only allow me to completely change the object and not modify its components individually?

#

!ide

eternal falconBOT
polar acorn
#

The only way to change it is to set it

crisp token
#

or is vector3 a struct

polar acorn
#

But you can make a struct

spiral glen
#

how do I change this via script?

spiral glen
#

thanks

eternal needle
spiral glen
#

That'd make sense, I'll make sure to check that before asking here from now on

#

Thanks ❤️

honest trench
#

So im tryna make it so theres a raycast sent out to the middle of the screen, and thats where the player should be aiming, the problem is that when the raycast from the center of the screen hits a object behind the player, the player looks towards it, subsuquentally breaking their back 💀 so whats a good way to solve this?```Vector2 screenCenter = new Vector2(Screen.width / 2, Screen.height / 2);
Ray ray = Camera.main.ScreenPointToRay(screenCenter);

    if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, aimMask))
    {
        aimPos.position = Vector3.Lerp(aimPos.position, hit.point, aimSmoothSpeed * Time.deltaTime);
    }```
mint remnant
#

before performing aimPos change, check if hit.point is behind the player

honest trench
#

alright let me try that

raw token
#

😮 Whacky - it's never crossed my mind to look into that. I just sort of assumed that that was a detail left up to implementations, for some reason

devout flower
#

i'm trying to make a force stronger the larger the distance, but when the distance is less than 1, the force is too small

#

does someone have an idea of what function/formula to use?

summer stump
devout flower
#

i never thought of that 🤔 thanks! i'll try that now

devout flower
raw token
#

Fair enough on all counts!

Maybe having grown up as a dev eating web techs I have just been conditioned to expect less of specs 👀

ripe shard
raw token
# ripe shard this is also just how the language presents itself to the user, it doesn't mean ...

Ah certainly, that is a reasonable assertion... That was part of my surprise though, that they would bother to supposedly back a struct with an inheritance chain at all, whether functionally or just conceptually.

I reckon it does make a lot more sense in the context of "OOP all the way down." It may have been more of a shock for C being the only other language I've worked in which makes prolific use of a struct keyword; at least to the best of my knowledge. The knee-jerk of what I'm used to thinking of as a central and simple core data type being described with inheritance :)

ripe shard
#

probably one of the reasons why some people prefer the more technical languages that force you to do everything yourself.

raw token
# ripe shard it would be nice if the type system was cleaner and more "predictable" in that r...

For whatever reason, JavaScript became one of my favorite languages over the years, all it's warts and weirdness included. It is maybe similar in that capacity - delving beneath the surface can be maddening. I've usually found it best not to look 😅

I do very much enjoy being able to more or less comprehend what my C code is doing along every step of the way without wondering about what's happening to my code within the black box, but I can't say I hold any love for actually working with the language

ripe shard
queen adder
#

How would I reference another script without using anything from the inspector

queen adder
#

thanks

queen adder
#

How do i get references from other scripts with my prefabs

summer stump
slender nymph
queen adder
#

Ill look into it

pliant valley
#

Because I can't use GameObject.Find() on inactive GameObjects, I created a static class that stores all UI elements that will at some point need to be referenced.

#

The UI has some tabs, though currently only the info tab has code set up for switching active UI elements when it's clicked

#

When the code first runs, it fills a list object that keeps track of all currently active UI elements

#

The first element is filled out correctly, but the second element isn't and references a null object.

eternal needle
#

also your !ide doesnt look configured

eternal falconBOT
pliant valley
#

That's what UI Record is. It's a class that contains a dictionary called "UIElements" that keeps a record of all UI elements that can be addressed by any other script

#

Why do you think it's not configured

eternal needle
#

a static dictionary populated using GameObject.Find is not the same as a singleton thats populated from inspector

#

also you have no coloring on stuff like Monobehaviour which is one giveaway

pliant valley
eternal needle
#

you just drag in the values from inspector, nothing about it is automatic. similar to how nothing here is automatic either since its relying on hardcoded strings

#

in relation to the error, a null reference error is always the same. something is null and you're trying to use it

pliant valley
#

Alright, so how do I do that with a Dictionary. It's only letting me me assign GameObjects to Lists through the Inspector

#

Or should I just create a List and then transfer it over to a dictionary in the Start function

#

Seems inefficient

rare socket
#

Hey all. I'm currently attempting to create a script that enables batteries to spawn in drawers. This script handles the instantiation of both drawers and batteries. The script should only spawn batteries when a drawer has also spawned. However, batteries are spawning when a drawer has not! Could someone help identify what I've done wrong?

The drawer/battery handler script:
https://gdl.space/ohecekubak.cpp
(The drawer spawning system is as follows: Drawer is instantiated alongside its parent prefab, if r = 2, drawer is destroyed)

The battery script:
https://gdl.space/vaqezivubi.cs
(This is here if needed)

I've added an extra collision check to both the drawer and battery, but it still isn't enough!! Help would be awesome! :D

eternal needle
rare socket
#

What was the issue with the input manager?

pliant valley
eternal needle
rare socket
#

The input manager is not bad in anyway, its just simplistic. The input system is highly event oriented and requires far more set-up and configeration. However, its more flexible and versitile, allowing for complex movements. What I'm trying to say is, unless you are planning on complicated and intricate movement/user interactions, then the input manager is completely fine.

pliant valley
#

Alrighty, I'll do that then

eternal needle
rare socket
#

Could you use a site to post your movement script so I could see a possible way to make your movement smoother?

pliant valley
eternal falconBOT
pliant valley
#

Seems to work

rich adder
#

!ide @pliant valley

eternal falconBOT
eternal needle
pliant valley
#

My IDE is configured

rich adder
#

if it says Misc instead of Csharp -Assembly , its not

#

close VS, click Regen project files and open script from unity once more

pliant valley
#

Did that but it still says misc files

rare socket
#

I'm going to be completely honest, I myself am stumped. However, I recommend incorperating Mathf.Lerp or Mathf.SmoothDamp. Both of these can be utilized to add a smooth increase in velocity. You know your script best, so incorperate these where velocity or movement is being added. (I am not qualified for this 🤣 )

Here is what I mean:
https://gdl.space/befugehedu.cs

summer stump
pliant valley
#

I did. It didn't change anything.

rich adder
pliant valley
#

Alright it's fixed

rich adder
#

sweet

drowsy oriole
#

Ok a gtag fan game (A popular vr game with hands as movement) Ok, I want to add ropes when you grab them, they move forcefully in the way you push then in, and your hand sticks to the ropes and thier movement, I want this feature to be activated by the grip button

topaz mortar
#
{
    Vector2 startPosition = transform.position;
    Vector2 direction = (targetPosition - startPosition).normalized;

    RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, 15, layerMask);
    Debug.DrawRay(startPosition, direction * 15, Color.red);

    if (hit.collider != null)
    {
        float distance = Mathf.Abs(hit.point.x - transform.position.x);
        Debug.Log(distance);
        if (distance <= 2f)
        {
            return;
        }
    }```
Why do I get 0 distance the first few frames? After the first few frames it correctly sets the distance
raw token
topaz mortar
#

that's what the layermask should prevent and then it wouldn't change the distance after a few frames?

raw token
#

ah fair point 🤔

slender nymph
#

print something more useful than just a single number. log what is hit, and where

topaz mortar
slender nymph
#

the "and where" part is also important. it seems like maybe these objects are very close to each other for the first few frames

#

Debug.Log($"{name} detected {hit.collider.name} at {hit.point} from {transform.position} at distance {distance}");

#

also fun fact, but you don't need to calculate the distance yourself. RaycastHit2D already has a distance property

topaz mortar
#

cool thx

slender nymph
#

there it is, it's hitting something else

topaz mortar
#

wasn't my mask supposed to prevent that?

slender nymph
#

have you looked at that object to see what layer it is on?

topaz mortar
half egret
#

Never thought I'd need something like this, but it seems insanely convenient. Cheers

echo hamlet
#

Rigidbody movement jittering?

#

I dont know whats wrong

#

ignore all the other objects in the hierarchy. They are there to test other things

rich adder
#

but its probably the camera?

echo hamlet
half egret
#

I often forget my pre-processor directives in the heat of battle, I appreciate the followup 🙂

buoyant tendon
raw token
buoyant tendon
#

I solved it thank you

static cedar
#

Harsh but yeah. UnityChanPanicWork
Also, i'm miffed to see get; set; with no access modifiers. Additionally, wrapping over collections is normal. If getting, and adding/setting is the only thing necessary, then that's all that needs to be exposed.

public RectTransform this[int i]
{
  get => UIElements[i];
  set
  {
    if (UIElements.ContainsKey(i)) UIElements[i] = value;
    else UIElements.Add(i, value);
  }
}
bronze token
#

hey guys, so me and my friend are making mario and the thing is we are working on two levels on our own laptops.
how do we combine these levels?
we've tried sharing folders (prefabs and scenes) but that didnt work :/
so yea how do we do it?
(we're both beginners 503error )

rich adder
#

lookup version control

static cedar
#

Wa.

bronze token
half egret
#

By default, one person can work on a scene at a time. They have to commit (save) their changes before the other person works on it, or the conflicts will be essentially unresolvable.

timber cargo
#
    {

        SceneManager.LoadScene("MainScene");
        InitializePlayer();      
        
        
    }

    public void InitializePlayer()
    {
        level = 1;
        experience = 0;
        maxHealth = 20;
        health = maxHealth;
        MinDc = 1; 
        MaxDc = 4; 
        transform.position = Vector3.zero;

        SetHealthUI();
        UpdateLevelUI();
    } ``` https://streamable.com/fae5pn  When i click my npc and travel to the "skeleton dungeon" and die. The scene comes back to the main scene but my Onclick events are gone and i cannot re-enter the dungeon. I've been trying for 2 days now but im at a wall. Video to show whats happening.

Watch "2024-07-31 08-52-23" on Streamable.

▶ Play video
static bay
timber cargo
static bay
# timber cargo ``` public static SceneManager instance; void Awake() { ...

Right. So what's happening is you load in, and the SceneManager sets itself in that instance variable. When you change scenes, the SceneManager still sticks around due to DontDestroyOnLoad. When you go back to the original scene, a new SceneManager is created but is instantly destroyed because the singleton is already set. Those buttons have a reference to the NEW SceneManager, which is getting instantly destroyed.

#

That's why they're displaying "missing".

timber cargo
#

wow, ive spend ages trying things and it was that simple, thank you ❤️

cedar bone
#

im sorry for posting here

#

but im kinda stumped

median halo
#

my unity project keeps deleting itself and i log on to just the main camera and nothing else. This has happened when i have been in safe mode for a couple days. Is that related?

timber cargo
#

so im guessing the same thing is happening with my playermovement, so ill look into that

static bay
timber cargo
#

hmm its getting playermovement from player gameobject, but i need that to be destroyed

#

or else im running about with a twin

static bay
timber cargo
#
    {
        if (gameObject.name == "Player")
        {
            if (playerInstance == null)
            {
                playerInstance = this;
                DontDestroyOnLoad(gameObject);
                Debug.Log("Object marked as DontDestroyOnLoad: " + gameObject.name);
            }
            else if (playerInstance != this)
            {
                Debug.Log("Duplicate object detected and destroyed: " + gameObject.name);
                Destroy(gameObject);
            }
        }
#

thats attached to my player gameobject

static bay
#

So like for your SceneManager.

public void ChangeSceneOnManager(string levelName)
{
    LevelManager.instance.ChangeScene(levelName);
}
#

put this method on some script

#

throw it onto the button

#

have the button call this method

#

@timber cargo

timber cargo
#

Getting lost 😛

static bay
timber cargo
#

The first button is fixed by removing the singleton from my change scene script. And the same thing is happening to my Player movement script, but it is inside the player gameObject. And since my PLayer game object has a script ^ above that is needed to destroy my player. THe buttons player movement is also destroyed.

#

Thats what im guessing is happening. And my playermovement script does not have a singleton because it is inside the player gameobject that has the "Dont/destroy" script

#

The playermovement is attached to the button because i wanted to stop allmovement when the npc was clicked then start moving again when moved to a new scene. It was the only way i could manage to do it

static bay
#

Makes sense?

#

Your goal now is to tell the buttons "Hey, don't call the methods on the Player/SceneManager that come with this scene. Call the methods on the Player/SceneManager that are currently stored in those singleton instance fields."

#

The SceneManager stored here

#

and the Player you set here

#

Does this make sense?

timber cargo
#

Trying to make sense of it but my brain has a monkey playing symbols atm >.<

static bay
#

Do you know what a Singleton is?

#

Like do you know what this really means?

#

and what you're doing with the whole null check and instance set thing?

#

Do you know what statics are?

timber cargo
#

It allows it to be accessed from other scripts

static bay
#

Color is not static.

#

You can spawn multiple apples, and set each to a different color.

#

In the below case, Color is static, meaning ALL apples you create will share that color.

public class Apple : MonoBehaviour
{
    public static Color color;
}
#

You access static members by writing the class name, and then member name. In the case below, you're setting the value of Apple's color to white. Remember this applies across all apples.

Apple.color = Color.white;
#

So in the case of your SceneManager singleton, you can write.

SceneManager.instance.ChangeScene(*the name of your scene*);
timber cargo
#

Thanks you for the help, ill just remove the player movement part until i understand unity and c# more. Getting to lost with this at the moment.

loud sage
#

I wanna add a bouncing sound effect to the ball I was working on the other day, whenever the ball touches anything
can I use the original sphere 3d collider as a trigger or is it better if I add a new one instead?

#

if I add another one I could make it slightly bigger for a more consistent detection idk

#

not sure if making the original collider a trigger messes with anything since the rigidbody for the physical interaction stuff is already there

#

how do y'all usually work this kinda situation?

languid spire
#

why a trigger? If you already have a physics collider on the ball just add code to it's OnCollisionEnter to play the sound

teal viper
loud sage
#

noted

languid spire
#

no, you do not

teal viper
loud sage
#

ohh alright I didn't factor in OnCollisionEnter; I thought you could only make scripts do stuff with specific triggers

#

mb

#

I'll try to script it with the OnCollisionEnter

languid spire
#

it's pretty simple, literally 4 lines of code

loud sage
#

I figure

sick storm
#

!code

eternal falconBOT
sick storm
#

hi im trying to make my character shoot projectiles but i cant get them to go left

#

the code is there

#

and i want to be able to shoot left without changing my players rotation

#

the bullet is spawned at a gameobject which is a child object of the player

sick storm
#

i mean left and right

#

as in if im facing left

#

i want to shoot left

#

and if im facing right i want to face right

#

shoot right

#

i am using a single game object for shooting left and right btw

ivory bobcat
#
if(left) 
    //go left
else
    //go right```
languid spire
#

so get your player to tell your bullet which way to shoot

sick storm
#

i have given it a flip function before

ivory bobcat
#

That would be the more appropriate solution, yes.

sick storm
#

but it would flip the bullet

#

and when i move it would flip the bullet in the direction i move in

#

while it is still out

ivory bobcat
#

Instead of setting the direction in Start, do it after instantiating the bullet.

sick storm
#

as in put it in update?

ivory bobcat
#

You'd put it where you'd instantiate the bullet

sick storm
#

i have that code on the player

#

and the code i pasted on the bullet

#

i tried to do a flip function but now when i shoot the bullet it only goes right and when i move left so does the bullet

languid spire
#
if (facingRight)
        {
            rb.velocity = transform.right * speed;
        }
        else
        {
            rb .velocity = -transform.right * speed;
        }

????????????

sick storm
#

what did i do

languid spire
#

you dont need to set the velocity EVERY frame

sick storm
#

so do i put it in fixed update

languid spire
#

you do it when the direction changes

sick storm
#

isn't that what that is doing

languid spire
#

no

sick storm
#

when i press a facing right is false

#

when i press d facing right is true

languid spire
#

and the next frame? and the frame after that?

sick storm
#

same thing

languid spire
#

so it sets velocity again and again

sick storm
#

yeah

#

how do i fix that

languid spire
sick storm
#

still don't get it

languid spire
#

do you not have 2 if statements which are true when you change direction?

sick storm
#

do you want me to put it where i put if input = a or d?

languid spire
#

yes, that is the logical place for it

sick storm
#

still does the same thhing

languid spire
sick storm
#

ik

vital gale
#

Hi, Is there a way to have only one instance of an object when I transfer back and forth between scenes? I added a DDOL on the object on Awake... but when I go back and forth, I have an issue of having multiple same objects

eager spindle
languid spire
topaz mortar
#

or destroy the object when you close the scene 😛

wide raven
#

Guys what can be the problem? I'm trying to resize the parallax background to fit to the screen whenever I resize so I can keep the look (This is a map maker for growtopia so I want the parallax to look like growtopia)

#

And I need to fix this happening when you move the camera upwards

teal viper
wide raven
teal viper
#

The kind of flickering that you have in the video would imply that the scale is jumping back and forth.

#

So start from debugging the scale. Then follow down the calculations path to see where it goes wrong.

wide raven
teal viper
#

Rising every time doesn't sound like jumping back and forth.

wide raven
teal viper
vital storm
#

How do I make a dropdown menu of everything in my Animator Controller? Here's an image for example

wide raven
teal viper
wide raven
sullen rock
#

is it possible to override native unity functions

#

like AudioSource.Play

cosmic dagger
willow scroll
willow scroll
sullen rock
# cosmic dagger what are you trying to do?

force an audiosource to wait until one clip has finished playing until it starts playing a new one, I know I can do it with an extension method, but I was hoping I could override the .Play itself

#

thanks!

cosmic quail
willow scroll
cosmic dagger
cosmic quail
cosmic dagger
willow scroll
cosmic dagger
cosmic quail
#

oh he already said he knows he can do it with an extension method, nevermind

willow scroll
#

They are the same as normal methods, but act as if they were implemented inside of the original class

cosmic dagger
willow scroll
cosmic dagger
#

they're great for extending functionality of a class . . .

willow scroll
#

That's why I do them for everything

cosmic dagger
#

i ended up creating a package because i started making a bunch of extension methods. some very specific to me, and others . . . probably not necessary, but for eas-of-use/funsies . . .

cosmic dagger
#

no, that's what i need in life . . .

#

packages that i can import into any package. a core package of common types i use in all projects and an extension package for the same reason . . .

tawny bone
#

hey all, so I was wondering is it possible to randomly spawn prefabbed tilemaps onto a map? Like a sort of "randomly generated" map? the idea is I want to make a bunch of prebuilt rooms that can possibly be pieced together to form somewhat unique levels

ripe hill
#

ive seen some one do it before but cant remember the way he did it

vital storm
#

yes

#

lol

tawny bone
#

alright I def could use some help, this is my second time creating a game in unity and i've been using a couple tutorials, but im realizing my code is all over the place and I'm trying to figure out how to fix it

#

this is my input manager, which does my player movement

#

currently im working on the attacking animations

#

and this is my player controller

topaz mortar
#

!ide

eternal falconBOT
tawny bone
#

my issue is that the input manager script is on a seperate object

topaz mortar
#

is your IDE set up? pretty sure it's not, but not familiar enough with VS Code to see

tawny bone
#

I'm not sure I think it is

#

but basically the input manager script is on a seperate object, so all I think I need to do is reference the animator attached to my player

#

but I'm not sure how

mossy pulsar
#

can anyone please tell me how to change a game object texture while moving left or right, and change it back to idle when not moving anything. its a 2d game btw

tawny bone
#

im wondering if I just moved the input manager onto my player object it would be a lot better

topaz mortar
mossy pulsar
#

i couldnt find one, do you mind telling me what to search

cosmic dagger
polar acorn
mossy pulsar
fickle stump
#

Heya! Doing an AR project right now and cam across an old problem i already had but I'm too dumb to figure out 😄 I currently have a setup with one parent, 3 child objects and each child has another child with more child objects (yes this sounds very weird haha). Question: I have a script on the child of the parent object. In that script i would like to load the child of the child and unload the other child object of the parent. Is there a way to unload other objects from the same parent? while loading child objects aswell... Not sure if you guys understand my question/setup

#

xD

#

(and i know there's an AR channel but this is more of a coding question than AR)

topaz mortar
fickle stump
#

So I'm gonna access the parent and disable the two other child objects?

topaz mortar
#

sure

fickle stump
#

and i can acecess the child of the child which i want to load by... doing what?

#

doing the same thing?

topaz mortar
#

yes? Transform.GetChild, Transform.parent

#

you also have GameObject.GetComponentInChildren

#

and Component.GetComponentInParent

fickle stump
#

I see...

#

can i actually share images here?

topaz mortar
#

sure

fickle stump
#

this is basically the setup I'm having rn.
So to load the content of the Phoenicians marker, I want to use the GameObject.GetComponentInChildren and activate the content and to unload the other markers i want to use Component.GetComponentInParen?

#

Ah no wait 🤔

topaz mortar
#

really depends how/what/why you're trying to do this
if you have the parent object, you can just find it's children and enable one then disable the others
if you have the child object, you can find the parent and then disable the other children

languid spire
fickle stump
#

Wait whats the difference between loading and activating?

languid spire
#

your gameobjects in your image are already loaded by the very fact that they are there

fickle stump
#

and yes this is german, no need to read it xD

fickle stump
#

thank you

topaz mortar
# fickle stump thank you

you could just have some sort of state manager that you call when you click one of these
put references to all 3 in the manager and then there's no need to search for parents and children

#

you just enable/disable the ones you want

fickle stump
#

This

#

kidna makes way more sense

#

LOL

topaz mortar
#

it's easier to help if we actually know what you're trying to do 😛

fickle stump
#

And trigger each object if the content is clicked

#

Lmao

#

Yeah yeah makes sense haha

#

I'm a bit afraid to show stuff that I'm doing cuz I really hate beeing jugded by people <-<

willow scroll
#

YourEvent disables the current button and enables the new one

ionic zephyr
#

Is it better to have the Interaction(for example talk, open an specific menu) component in the entity or in the player?

frosty hound
#

The settings, rules and overall definition of the interaction should be on the object. The actual interaction itself based off those rules, should be done on the player (in my opinion)

ionic zephyr
frosty hound
#

A button on the wall?

ionic zephyr
#

what should the logic in the player and in the button be?

polar acorn
frosty hound
#

Player is responsible for detecting interactions, and then doing whatever is necessary based on the interaction type (button), such as handling the animation of pressing it

The interaction component on the object can have function calls to sync up its own results locally

OnInteractionBegin
OnInteractionComplete
Etc.

#

Each interaction type/object will have its own controllers that do what it needs to do. Button opens door. NPC initiates dialogue. Chest drops loot.

ionic zephyr
frosty hound
#

If you want. Depends on how big of a sequence you want.

ionic zephyr
#

for example

#

should I have an interaction component for chests, npcs etc

#

but i dont want the chests to talk or the npcs to open a box

#

so it cant be the same component

frosty hound
#

Hence:

ionic zephyr
# frosty hound Hence:

yeah but when I write public void interact{ } how can I distinguish what I am pressing

#

and, if so, I dont want to make an if, if, if with the components

frosty hound
#

You can have a base Interaction class, and each controller type extends it

ChestController : Interaction
NPCController : Interaction

(or use interfaces)

ionic zephyr
#

I would like to have a common method with different reactions

ionic zephyr
raw token
#

You could also rig up a generic interaction target component. Have it invoke an event or UnityEvent or something when the interaction occurs

ionic zephyr
#

however, I don´t know what is the best way to do it honestly

#

all of the tutorials I´ve found show this working with events

slender nymph
raw token
#

I haven't implemented one in my current project, but I think I sort of lean that way as well. It could still be extended into another class if it requires some sort of more complex general behavior 🤔

frosty hound
#

I just checked an old prototype, and that's apparently what I did as well 😆

ionic zephyr
#

So events win the game right?

strong wren
#

Generic component that then fires events, yes

slender nymph
#

after implementing it and using it for a while i think i actually prefer this way over the interface/inheritance method because i can move the interaction to another object, like for doors. I can just reuse the exact same door component that opens/closes it even for doors that would be opened/closed from some button rather than directly from the door itself

frosty hound
#

I seem to have done both, just to force implementing the functions.

#

Well, time to put that project back to sleep.

raw token
#

Night night, project 👋

ionic zephyr
#

the check of interactable area should be in the player or in the object?

vital gale
#

Hi, how do I debug a built game? The issue is when I try to "Host Game" or "List Lobbies" that is read from Steam, the buttons don't work. However, when I try it in the editor, it works just fine.

slender nymph
#

i typically give my player object a component that raycasts to check for interactable objects

rain ginkgo
#

hello

#

from where i can learn c# for the unity game dev?

raw token
rocky canyon
rocky canyon
#

are we talkin about pros and cons?

rain ginkgo
vital gale
slender nymph
#

hint: read the page

tawdry ember
#

Does anyone know how to get rid of the refrence things that keep serperating my code?

slender nymph
#

that's called code lens. it's typically better to leave it on as it helps with debugging

rocky canyon
#

u can turn it off but i suggest u dont

tawdry ember
#

Why shouldnt I?

rocky canyon
#

b/c its more important than just the refernece thingy

tawdry ember
#

What exactly is it for?

slender nymph
#

it tells you where you are using the members of your objects. and as long as you've actually got your !IDE configured it is actually useful

eternal falconBOT
rocky canyon
tawdry ember
#

Ok, thank you

rocky canyon
#

in code u can turn off the reference part seperately while keepin CodeLens enabled

#

not sure about vstudio

tawdry ember
#

visual studio

rocky canyon
#

ahh, sorry

mint remnant
#

it can be turned off in studio as well, up under options

rocky canyon
#

Via VS Code settings: Go to File > Preferences > Settings and search for "csharp.referencesCodeLens.enabled" and make sure its unchecked. code allows u to disable just the references

twin bolt
#

Question, I'm trying to make a moving system like skyrim or portal, but instead of the object following the players mouse, it stays on the ground, and moves with a delay, basically like real life. How would i go by doing this?

twin bolt
rocky canyon
#

hmm.. let me think about that a min

#

i use spring code btw..

#

w/ strength, dampening, etc

twin bolt
#

ok

rocky canyon
# twin bolt ok

u can probably raycast towards the ground as u do it.. and when it gets too far away stop it from lifting anymore

rocky canyon
#

u could.. yes

twin bolt
#

ok

rocky canyon
#

depending on how it looks.. u probably need to try a few different methods

hazy fiber
#

how to check if the moving player has crossed a certain boundary?
(i need to write a code where the player can't pass a horizontal/vertical boundary)

#

i wanna limit the player's movement area to just the red lines and the vertical blue line in this image

hazy fiber
#

already have a circle collider for player1

wintry quarry
#

Yes now use more colliders to make the boundaries

hazy fiber
#

those colliders will be applied to a separate sprite ye?

wintry quarry
#

Sprites would not be involved

#

Just GameObjects with Colliders

hazy fiber
#

how to create a static collider to make boundaries then

#

oh ok

#

thanks

rocky canyon
#

may want to work w/ rotations as well

ionic zephyr
#

Should the interactable area be a child object or is it better to have it in the player gameobject

frosty hound
#

It should be on the interactable object

#

But it really depends on what kind of game you're making as well