#💻┃code-beginner

1 messages · Page 288 of 1

tender stag
#

why is this modifying the z rotation?

willow scroll
deft current
#

omg you're a life saver that works, thansk so much 😭

swift crag
#

If you drag the script asset in, you'll only see "MonoScript" in the list of things you can call methods on

#

(and that doesn't even exist in the built game)

tender stag
#

it was because i was using slerp

vast vessel
#

what was that method that returned 0 if a vector3 was right in front of a direction, and 1 if the vector3 was behind the object?

swift crag
#

Dot tells you how well two vectors align

south sky
#

Hey guys I wanna add a way to attack in my game. I dont have any sprites for attack so i wanted to make like a sword go around in a circle like terraria. Anyone know how to achieve this. Dont worry about hitboxes or collision detection just wanna know if anyone can do the spinny thing with a sword

swift crag
#

Two unit vectors produce 1 if they align, 0 if they're perpendicular, and -1 if they point in opposite directions

edgy prism
#

!IDE

eternal falconBOT
naive river
#

Ty for the help

vast vessel
solid bough
#

i have a prefab on my enemy; i also have an enemyspawner that instantiates more enemies over time, but as soon as I destroy the original enemy, they obviously cannot get the prefab anymore since he died
whats the easiest way to fix it?

swift crag
#

what gameplay are you creating?

vast vessel
#

im trying to use the data for my animation controller

#

i have three animations, one for front melle attack, one for left, and one for right

swift crag
#

I'd suggest using Vector3.SignedAngle followed by Mathf.InverseLerp and Mathf.Lerp

#

SignedAngle gives you the angle between two vectors.

#

InverseLerp turns a range of values into 0..1

#

and Lerp turns 0..1 into a range of values

#
float angle = Vector3.SignedAngle(transform.forward, targetDir, transform.up);
float t = Mathf.InverseLerp(-90, 90, angle);
float result = Mathf.Lerp(-1, 1, t);
vast vessel
#

here is a diagram of what i want

swift crag
#

That might be backwards. I always forget which way the angles go

#

(so you might need Mathf.InverseLerp(90, -90, angle))

#

If angle is 45, Mathf.InverseLerp(-90, 90, angle) would produce 0.75

#

Then Mathf.Lerp(-1, 1, 0.75) spits out 0.5

#

If you need to snap this to -1, 0, or 1, you can use Mathf.Round

swift crag
#

i dunno why Mathf doesn't have that baked-in

vast vessel
#

whats the difference between Vector3.Angle and Vector3.SignedAngle?

swift crag
#

Angle produces a value between 0 and 180

#

It can't distinguish between a left turn and a right turn

#

SignedAngle takes a third argument to figure out which way is left and which way is right.

vast vessel
#

so its the same but always positive?

swift crag
#

hence transform.up being included

swift crag
#

notably when the two vectors are not in the plane of the third vector

vast vessel
#

right

swift crag
#
Vector3.Angle(Vector3.forward, Vector3.right + Vector3.up);
Vector3.SignedAngle(Vector3.forward, Vector3.right + Vector3.up, Vector3.up);
#

I'm not sure how signed angle behaves there

#

I've always used it with vectors that I've already projected onto the Vector3.up plane

vast vessel
#

well, thanks, ill try it out and see if it works

lethal elbow
#

I'm currently working on a project involving scripts for a car, a spawn zone, and a GameManager in Unity. I've encountered an issue where I want the game to transition to a 'game over' scene when an object spawned by the spawn zone script touches my car. However, I'm having trouble implementing this functionality. Like I create a script for my object that get spawn but the code I use aint working. I would appreciate any help! pepelook

swift elbow
#

You should read the docs if you want more info on how these work

vast vessel
#

can anybody tell me why the projectiles appear on that wall on the top?
they are supposed to be created on the transforms with the yellow gizmos(assigned in the flechetteDirection Transform array)

https://hastebin.skyra.pw/falasavoxe.csharp <- Hunter_Flechette.cs script placed on the projectiles (position assigned on line 41)
https://hastebin.skyra.pw/xoturuyaya.csharp<- AI_Hunter.cs script creating the projectiles (Init() func of the Hunter_Flechette script called on line 94)

lethal elbow
#

the gm is for my GameManager script that has the Game Over scene

swift elbow
#

What is scenefin()?

lethal elbow
#

Is the Game Over scene (some of my code is in french oop)

swift elbow
#

Yeah but what is in there

#

Can you show that?

lethal elbow
#

It supposed to bring to bring u to another scene

swift elbow
#

I get that...

#

How are you doing that though

lethal elbow
#

Just for context that part is also for some portals I have that if u collect them all it will bring u to You Won and if u dont Game Over

#

idk if that is why it cause some trouble for my code to work

swift elbow
#

Add debug.log statements first and then keep troubleshooting

lethal elbow
#

Ayt!

lethal elbow
willow scroll
#

The those scenes included in build?

#

I'm talking about the scenes you're trying to load in the image above

lethal elbow
#

aah oop my bad

#

Yes they are in the build cuz they work with my portals when I collect them all and when I dont

willow scroll
#

And you say they're not loaded in the SceneFin method?

lethal elbow
#

I just cant make it work for my spawn object that when it come in contact with my car it doesnt bring me to the Game Over scene

swift elbow
willow scroll
#

Is the method even called?

#

Yeah, that's what you usually do before asking a question

#

You should figure out what part of the code isn't working

lethal elbow
summer stump
summer stump
willow scroll
lethal elbow
polar acorn
# lethal elbow I have this but doesnt work

The Three Commandments of OnTriggerEnter:

  1. Thou Shalt have a 3D Collider on each object
  2. Thou Shalt tick isTrigger on at least one of them
  3. Thou Shalt have a 3D Rigidbody on at least one of them
willow scroll
#

Is it a traditional English?

#

Also IsTriggerEnter is called when the object, containing the script, has isTrigger ticked

#

Otherwise OnCollisionEnter

edgy prism
#

Quick question is there ever a scenario where you configure your IDE correctly and it doesn’t work?

lethal elbow
edgy prism
willow scroll
swift elbow
#

"Correctly" implies that it will work, you have to be more specific

edgy prism
edgy prism
swift elbow
#

!ide

eternal falconBOT
swift elbow
#

You should forward this to them ^

edgy prism
summer stump
polar acorn
lethal elbow
polar acorn
summer stump
willow scroll
#

Are they too shy to ask themselves? You're both going to end up wasting more time on this

summer stump
lethal elbow
#

I was able to fix it!!

lethal elbow
summer stump
lethal elbow
#

I guess OnCollisionEnter would have solve it quicker hahaha I will keep it mind!
I appreaciate the help!

smoky mauve
#

is there any limit in string size in unity?

slender nymph
smoky mauve
#

im loading a 266 Kb csv into a string and its giving me trouble

smoky mauve
#

can i store it on a string list somehow?

vast vessel
#

does GetComponentsInChildren() also return a component in its array if its placed on the object calling this method?

polar acorn
rich adder
vast vessel
#

lets say the first line of a virtual method has return in it, and a method overriding it, has the base method, on its first line and some other operations next. will those operations also be aborted?

polar acorn
#

It behaves the same as if you did SomeOtherObject.TakeDamage() instead

#

it just specifically calls the version of the function from the parent class instead of this one

mighty falcon
#

what exactly is it asking me to do here

rich adder
#

since they live on the class itself

#

why is damage static in the first place

mighty falcon
#

good point

#

its not longer static

hidden sleet
#

with a raycast, is the layer you pass in one to ignore or one that it will only collide with?

hidden sleet
#

ah, how might I tell which way round I have it?

rich adder
#

if you add ~ you can Invert the mask (hit everything else but these)

hidden sleet
#

As i've got a layer for objects that can obstruct the view of something, and a player layer it needs to try and pickup on

#

given that, i think mine is just set to hit the layer I've given it

hidden sleet
#

just trying to troubleshoot why this isn't working as I'd like

Vector3 playerDirection = playerLocation.position - transform.position;
        Ray ray = new Ray(transform.position, playerDirection.normalized);

        if (Physics.Raycast(ray, out RaycastHit hit, playerDirection.magnitude, obstructionMask))
        {


            Debug.DrawLine(transform.position, hit.point);
            print("passed LOS");
            return true;


        }
        else
        {
            return false;
        }
``` I have it so when I enter this radius, it should perform a raycast to see if the source has LOS on the player, but it always returns false. Think I've missed something somewhere
rich adder
#

put it outside the if statement

prime cobalt
#

How could I find which enemy in a 3d space is closest to my crosshair in the center of the screen?

rich adder
prime cobalt
#

Thanks!

rich adder
# prime cobalt Thanks!

in 3d might be easier to use ScreenPointToRay or a plane, instead because of the prospective camera

prime cobalt
#

Wouldn't ray also count the distance from the camera backwards as well as sideways/upwards?

rich egret
#

How to make a character jump while animating?

rich adder
rich adder
hidden sleet
prime cobalt
#

I'll give rays a shot and if that fails I'll go with the screenpoint thing

hidden sleet
#

oh wait hol up

rich adder
rich egret
#

!code

eternal falconBOT
hidden sleet
#

yeah fixed that, the ray is correctly projecting towards the player, but even if there are no obstructions it never behaves like it should when it has LOS

rich egret
hidden sleet
#

So i can see the ray now, but the raycast always returns false

rich adder
hidden sleet
#

ray's supposed to come out from the sphere, be blocked by objects with the 'obstruction' layer, and if it hits the player without being blocked by said objects, does a thing

#

Unless I have things the wrong way round

rich adder
#

but it should hit obstructions, if you put them in the Layer on the gameobject itself ofc

hidden sleet
#

yeah that's what I've done, all I need is to return a boolean whether the player is obstructed or not

#

but at the moment it looks to always be saying it's obstructed, when it's not

vast vessel
#

can anyone tell me why i should not use null propagations on unity objects? i mean, they are way shorter then a if statement.

rich adder
astral basin
rich adder
hidden sleet
#

shouldn't be, the sphere only has the default layer, none of the player's layers have that layer on it either

rich adder
finite dew
proven inlet
#

Hi i need help bcs I lack for logic.
I want to make pattern for an enemy with pattern switching randomly( think of a bullet hell) but I dont have any idea how to do that

astral basin
astral basin
#

x = 1
i = 1 -> 4

rich adder
polar acorn
astral basin
polar acorn
proven inlet
rich adder
polar acorn
polar acorn
astral basin
#

beacuse i have 8

polar acorn
rich adder
#

not 8

astral basin
#

ik

#

but it startrs at 0

rich adder
#

exactly

astral basin
#

oh

#

lmao

polar acorn
#

So don't use magic numbers. If you want to use the count of a list, use list.Count

astral basin
#

OH NO

#

mb i have 9 audio sources

polar acorn
#

don't just do it by hand and type it in

rich adder
#

so .length

vast vessel
#

will this create one instance of a material, and then have all of my renderers use that same material instance like i want it to?

rich adder
#

the advice is still solide

polar acorn
astral basin
#

like this?

south sky
#

Yo guys, what does serialise field mean?

rich adder
#

first time im seeing these weird crops 👏

rich adder
#

serializing = storing/saving stuff in an organized way

south sky
rich adder
#

encapsulation basically

#

guarding against yourself or collaborators from changing it in the future

hidden sleet
south sky
polar acorn
# astral basin

Yes. Those are pretty bog standard loops now. You won't hit an out of bounds exception with i with these no matter what audiosource and music are. You might still get one on volSliders though, you could probably do with a check to see if x is greater than the length of that array too

rich adder
astral basin
#

x can be 0 and 1

#

the else statement is for the time its 1

#

it can only be 1

rich adder
polar acorn
# astral basin its not i checked

As long as you have it checked somewhere and are not just assuming it's correct, that's fine. It doesn't need to be in this method, it could be a check before calling this method

hidden sleet
rich adder
#

usually is

polar acorn
# south sky Whats the benfit of having it private over public

Organization. On a big project you're going to have an order of thousands of potential variables at your disposal at any given moment. If you make private the things that shouldn't ever be changed outside this class, you can add a field variable (to use between functions in this class for example) without increasing the overall complexity of the system

lunar fern
#

i posted this in the c# server and have still got no response so ill post it here:
so i have a glitch where the player starts "twitching" when you walk beside a block or just on a block thats not a plane. ive tried a bunch of things and now im getting brain bleed. i have no idea why this is happening (plus ive got a automatic parkour movement without implementing it!). ill leave the code and a vid of me showcasing it down below. thanks in advance

// public's
public float speed;
public float jumpForce;

// private's
private Rigidbody rb;
private bool isJumping = false;
private bool isGrounded = true;

void Start()
{
    transform.position = new Vector3(0,1,0);
    rb = GetComponent<Rigidbody>();
}


void Update()
{
    if (!isJumping && isGrounded)
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Jump();
        }
        else
        {
            Move();
        }
    }
}

private void Move()
{
    Vector3 direction = Vector3.zero;

    if (Input.GetKey(KeyCode.W))
    {
        direction += transform.forward;
    }

    if (Input.GetKey(KeyCode.S))
    {
        direction -= transform.forward;
    }

    if (Input.GetKey(KeyCode.D))
    {
        direction += transform.right;
    }

    if (Input.GetKey(KeyCode.A))
    {
        direction -= transform.right;
    }

    direction.Normalize();

    if (Input.GetKey(KeyCode.LeftShift))
    {
        rb.velocity = direction * (speed * 2);
    }
    else
    {
        rb.velocity = direction * speed;
    }
}

private void Jump()
{
    if (isJumping == false)
    {
        isJumping = true;
        rb.AddForce((Vector3.up+(rb.velocity/5)) * jumpForce, ForceMode.Impulse);
    }
    
}

private void OnCollisionEnter(Collision collision)
{
    if(isJumping == true)
    {
        isJumping= false;   
    }
}
private void OnCollisionExit(Collision collision)
{
    isGrounded= false;
}
private void OnCollisionStay(Collision collision)
{
    isGrounded= true;
}
astral basin
#

@polar acorn whenevr i use any of the sliders the error comes up yet the code works exactly as i intended

astral basin
polar acorn
astral basin
polar acorn
# astral basin

I would like to direct your attention to exactly the thing I said would happen

#

x is out of bounds of the array

#

So check

astral basin
#

i checked though, the script is attached only to those two sliders, in one, x=0, and the other x=1

polar acorn
#

because the second one is what I said to do

#

and I have a feeling you're using it for the first

rich adder
#

btw shouldn't it be < instead of <=

polar acorn
astral basin
#

what do you mean how can it be not 0 or 1 if i never defined it as something else

polar acorn
modest dust
#

i is out of bounds, it should be < instead of <=
x is probably alright (but I'd rather just make separate fields for these two sliders)

astral basin
#

i printed x infinitely and it said 0 or 1 aswell

polar acorn
# astral basin

Again, that's your fallible human brain, who knows if you've got a copy of this script with less vol sliders set?

polar acorn
polar acorn
# astral basin

How about, instead of going on a snipe hunt you just, you know, put in the if condition

polar acorn
#

Print the value of x and the length of the array

astral basin
#

both of the arrays?

#

since the error occurs on both lines

#

whenevr the loop is active

polar acorn
polar acorn
# astral basin both of the arrays?

Once you've fixed the condition like navarone and caesar pointed out, i cannot be out of the bounds of audiosource or music. x, however, can be outside of the bounds of volSliders

south sky
polar acorn
#

Because nothing in your code is preventing you from passing in 4 or -12 or 525600, and nothing in your code is checking if volSlider has anything in it at all

astral basin
#

what do u want me to do

polar acorn
#

And maybe an else statement with a log that prints x and the length of volSlider so you can see what those numbers are when it goes awry

astral basin
#

like so?

polar acorn
# astral basin like so?

Sure, but putting it around the function call is probably fine, that way you don't need to add it twice to have it around both conditions

modest dust
#

Around, or an early return

#

To avoid more nesting

astral basin
#

the else statement isnt printing anything

lunar fern
#

can someone help me because my player movement script somehow got Wal climbing without me even needing to code it? like i stick to walls and stuff

astral basin
#

and it lets the for loop run

summer stump
polar acorn
modest dust
#

< instead of <=

astral basin
#

ok let me do that

polar acorn
#

Multiple people, in fact

#

Length is fine, that's not the problem

lunar fern
#

please ive tried to fix it for a while now and its still not fixed

astral basin
lunar fern
#

anyone please

rich adder
rapid crescent
astral basin
#

wait wtf did i write

rich adder
#

also you have no provided code

polar acorn
# astral basin
  1. That only checks one condition
  2. your else has no braces so it will just always print volSliders.Length
#

Wrap the call to freqVolume in the condition

lunar fern
# rapid crescent send your code lets have a look

here it might be messy:

// public's
public float speed;
public float jumpForce;

// private's
private Rigidbody rb;
private bool isJumping = false;
private bool isGrounded = true;

void Start()
{
    transform.position = new Vector3(0,1,0);
    rb = GetComponent<Rigidbody>();
}


void Update()
{
    if (!isJumping && isGrounded)
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Jump();
        }
        else
        {
            Move();
        }
    }
}

private void Move()
{
    Vector3 direction = Vector3.zero;

    if (Input.GetKey(KeyCode.W))
    {
        direction += transform.forward;
    }

    if (Input.GetKey(KeyCode.S))
    {
        direction -= transform.forward;
    }

    if (Input.GetKey(KeyCode.D))
    {
        direction += transform.right;
    }

    if (Input.GetKey(KeyCode.A))
    {
        direction -= transform.right;
    }

    direction.Normalize();

    if (Input.GetKey(KeyCode.LeftShift))
    {
        rb.velocity = direction * (speed * 2);
    }
    else
    {
        rb.velocity = direction * speed;
    }
}

private void Jump()
{
    if (isJumping == false)
    {
        isJumping = true;
        rb.AddForce((Vector3.up+(rb.velocity/5)) * jumpForce, ForceMode.Impulse);
    }
    
}

private void OnCollisionEnter(Collision collision)
{
    if(isJumping == true)
    {
        isJumping= false;   
    }
}
private void OnCollisionExit(Collision collision)
{
    isGrounded= false;
}
private void OnCollisionStay(Collision collision)
{
    isGrounded= true;
}
astral basin
polar acorn
astral basin
#

no

polar acorn
astral basin
#

x is the int in freqvolume

lunar fern
astral basin
#

its either 1 or 0

lunar fern
#

ill send i vid

polar acorn
#

what calls this function

rapid crescent
astral basin
astral basin
lunar fern
polar acorn
#

Do you want to fix this one or do you want to do it correctly?

lunar fern
#

it took a while to upload but there

astral basin
polar acorn
# astral basin lets do it correctly

Make two functions. Both take a float parameter. One loops over audiosource and sets the volumes to that parameter. One loops over music and sets the volumes to that parameter. Call that function from the slider OnValueChanged. It will pass in the float from the slider and you no longer need to have an array of sliders

smoky mauve
#

    public List<Carrera> RandomRacesCreator()
    {
        print(dias.Count);
        List<Dia> RandomDays = dias;
        Shuffle(RandomDays);

        float reductionPercentage = UnityEngine.Random.Range(0.3f, 0.5f);

        // Calculate the number of elements to remove
        int elementsToRemove = Mathf.FloorToInt(RandomDays.Count * reductionPercentage);

        // Remove elements randomly
        for (int i = 0; i < elementsToRemove; i++)
        {
            int randomIndex = UnityEngine.Random.Range(0, RandomDays.Count);
            RandomDays.RemoveAt(randomIndex);
        }
        List<Carrera> carrerasa = new List<Carrera>();
        foreach (Dia dia in RandomDays)
        {
            foreach (Carrera c in dia.Carreras)
            {
                carrerasa.Add(c); 
            }
        }
        return carrerasa;
        
    }

Why is the script removing the variables form dias?

if i call this function various times it eliminates the Dia from dias and not form RandomDays

#

shuffle is a custom function that shuffles the list

polar acorn
#

If you want a copy of dias, do List<Dia> RandomDays = new List<Dia>(dias);

smoky mauve
#

oh

astral basin
#

but if i have 2 functions and 2 sliders i dont even need the float do i

polar acorn
#

The float parameter is the value of the slider

astral basin
#

i can just volume = slider.volume

polar acorn
#

Just use a parameter

astral basin
polar acorn
#

the slider passes its value to the function

astral basin
#

and then volume = x?

#

wait what

#

idk what im doing

rapid crescent
polar acorn
# astral basin

Yes. Although tbh you can probably just use a foreach instead of an indexed for loop

lunar fern
astral basin
polar acorn
eternal falconBOT
#

:teacher: Unity Learn ↗

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

astral basin
# astral basin

anyway what did i do wrong cuz what i wrote doesnt reference in any way the slider volume amount

polar acorn
astral basin
astral basin
polar acorn
astral basin
#

ohhh

polar acorn
#

As long as you actually picked the dynamic function

astral basin
polar acorn
#

and not entered a value in the box

astral basin
#

ok let me run it

polar acorn
#

is your slider set to ints?

astral basin
polar acorn
# astral basin

Use the dynamic function, not the one that has you enter in a value manually

astral basin
polar acorn
#

pick the one from the "dynamic" section

astral basin
#

ohh

polar acorn
#

Do that on both

astral basin
#

alr

#

YES

#

THANK YOU SO MUCH

polar acorn
#

Now consider doing !learn to catch up on the things you missed

eternal falconBOT
#

:teacher: Unity Learn ↗

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

astral basin
#

but ill definetly get into it soon

#

cuz i definetly need it

#

thanks

south sky
#

Guys from this code I only want the enemy to track the x position of the player, how would I do this?

rich adder
#

u wont be able to use it in MoveTowards

#

make a new v3

#
Vector3 targetPos = transform.position;
targetPos.x = player.transform.position.x```
south sky
#

Thanks navarone but this would make the enemy teleport to the players x position, how about just slowing moving there?

summer stump
#

Not a code question
And don't crosspost

rich adder
south sky
#

Mbmb

#

Yo @rich adder you gonna make more yt vids?

rich adder
south sky
#

Especially younger

#

Unless you dont care about them kids lol

rich adder
#

there are more youtubers with more oomf personality for videos haha

south sky
#

Loll i get ya

frosty river
#

Hey all I'm really stuck on this muzzle effect:
the cone of light only goes backward

swift elbow
#

Not much more I can discern off of such little info tho

frosty river
#

I'm u sing particle system for the muzzle flash effect

#

it's from a free asset pack

swift elbow
#

Show the outline of the cone

#

Like in your scene view

frosty river
#

how can I get it to show the outline of the cone?

swift elbow
#

By selecting your light gameObj

frosty river
#

I have the muzzle effect selected

swift elbow
#

You need to select the light, the muzzle is different

frosty river
#

how can I select the light?

#

i don't see it on the hierarchy

#

I just have MuzzleFlashEffect on the hierarchy

swift elbow
#

Select whichever gameObj is giving off the light and turn gizmos on...

frosty river
#

sorry not sure what you mean by turn gizmos on

#

there is a light module for the particle system component

swift elbow
#

Ok select it

#

Can you see a cone in your scene view?

#

One that reflects how the light is showing?

frosty river
#

expanding the Lights module does nothing

#

as far as scene view

hot palm
#

Can I draw a ray (debug), using a Ray as input?

swift elbow
#

Press on the gameObj in the light area

frosty river
#

"ParticlesLight"

swift elbow
#

"ParticlesLight (Light)"

frosty river
#

yea

#

I have it open in Project tab and inspector

#

(ParticlesLight)

hot palm
#

Ah this should work

swift elbow
frosty river
#

I don't know how to make it show in scene view

swift elbow
#

When you select it, it should be highlighted in your hierarchy

#

After selecting, press f to focus

frosty river
#

it's not in the hierarchy though

swift elbow
#

Use the search bar and search for lights

#

And find which one is the muzzle flash light

frosty river
#

nothing shows, the only light in my hierarchy is the directional light of the sun

#

but the ParticlesLight are definitely the cause of the backwards cone

rocky canyon
#

flip it

hot palm
frosty river
#

ok so rotate the ParticlesLight

swift elbow
#

Yes, then you will know if that is really what's giving off the light

swift elbow
#

No, rotate the particle effect

frosty river
#

Rotating the particle effect has no effect

rocky canyon
#

yea,, u need to sim it in local space no?

frosty river
#

i think its only effecting the orange square part here:

swift elbow
#

So there is a gameObj in your scene that has a light component

#

Find it

frosty river
#

that light in the back

#

on the player

#

is definitely ParticlesLight

#

because when I uncheck Lights on the effect it disappears

swift elbow
#

Show the inspector for it

frosty river
#

inspector for ParticlesLight?

swift elbow
#

Yes

rocky canyon
#

if ur rotating ur particle and nothing is noticeable.. it leads me to believe its simulating in world space

#

instead of local space

frosty river
#

ok, here it is. note that it's a prefab, not in hierarchy

swift elbow
#

Show the one in the hierarchy

frosty river
#

the Effect?

ruby python
#

Evenin' all. I've got myself a couple of issues I can't seem to figure out with my enemy spawner.

Video to demonstrate the current working for context.

https://streamable.com/ud8k8j

Wave Spawner code with a comment at the top explaining one issue.

https://pastebin.com/vaMvd2iz

Basically I have a wave spawner where I'm trying to keep track of the enemy count per 'wave' when the enemies 'hit' their position in the grid formation the count goes up by 1 (if they get destroyed, the count goes down) and at the end of the wave, if the enemy count is 0, then a power up will get dropped. Now the keeping track of how many enemies there are works fine.

https://pastebin.com/yYdFwh6j
This is how I'm keeping track of the enemy numbers.

The first issue is I can't figure out where to 'reset' the enemy count to 0 as the Waves 'overlap' each other in terms of spawn time, so if the next wave starts to spawn and the count gets reset to 0, if I shoot one of the previous waves enemies, the count goes into negative numbers.

The enemies are governed by a State Machine

Enemy Code.
https://pastebin.com/agAjHcn2

Apologies if that's a lot, but this is driving me up the wall.

And please excuse any random un-needed 'using's for some reason VS keeps randomly adding them.

So, basically, any ideas where I should put my reset to 0 line? 😕

Watch "2024-04-04 19-47-14" on Streamable.

▶ Play video
swift elbow
frosty river
#

it's not in hierarchy

#

as you can see only Directional Light (the sun) is there

swift elbow
#

Press the box next to the search bar and search by component

frosty river
#

the box to the right of the search bar?

swift elbow
#

Yes, that's what I just said

frosty river
sharp wyvern
swift elbow
#

For that gameObj

frosty river
swift elbow
#

You meant the prefab is what you have in your scene 🤦‍♂️

#

Unpack it and mess around with the values

#

Or don't un pack it

#

Up to you

tall delta
swift elbow
ruby python
frosty river
swift elbow
#

Yes, you don't have to ask for permission for everything

frosty river
#

rotating the prefab has no effect

swift elbow
#

Press f and focus it in your scene

#

Where is it?

frosty river
#

it's not in the scene

swift elbow
#

🤦‍♂️

swift elbow
frosty river
#

right

sharp wyvern
swift elbow
#

Rotate whatever obj is giving off the light

#

Idk how you don't know what it is

ruby python
#

Thank you 🙂

frosty river
hot palm
#

Best notification I got today AAAAAAA

willow scroll
#

Hello, does someone know why accessing Image.material doesn't create an instance of it?

renderQueue = image.material.renderQueue;
#

Accessing TMP_Text's fontMaterial does though

renderQueue = text.fontMaterial.renderQueue;
rocky canyon
hot palm
#

From one problem into the next one tho Sadge

rocky canyon
#

when u access the material ur accessing the property of the shared material, when u access the text ur accessing the material instance specicially for the text component.

#

u probably need to create a copy of the image material and queue that

tender stag
#

how can i check if an animator has a trigger?

willow scroll
tender stag
#

how can i check if an animator has a trigger?
like if(animator.TriggerExists("Shoot"))

rocky canyon
#

just an idea

willow scroll
rocky canyon
#

i know when i want to change the material of a renderer i have to do the same..
create a copy.. modify the copy.. assign it back to the renderer

rocky canyon
#
foreach (var param in params)
{
    if (param.type == AnimatorControllerParameterType.Trigger && param.name == triggerName)
    {
        return true;
    }
}```
hot palm
#

My ray is doing this, but still logs Hover regardless of where I am aiming, but only when I am clicking the mouse button?

#

(The Function Hover just Logs Hover!)

#

Anybody got an idea why?

tender stag
#

so this is fine?

rocky canyon
#

ive never used the exact syntax or hunted for triggers i didnt know where there

#

soo. you can test for me 😆

rocky canyon
hot palm
#

Yeah that's weird

rocky canyon
#

its in fixedupdate.. w/o being in any kind of input conditional

#

unless u have multiple scripts running.. and (1) is

hot palm
#

I have this, but I don't use mousePos anywhere

rocky canyon
#

then why u have this?

hot palm
#

Before I did the LookAt - POV, I did the MaincameraToScreenPoint. But that didn't work, so I tried it without using an input action (potentially wrong)

#

I am very confused bcs it doesn't seem logical for once

tender stag
#

seems to work

#

thanks

rocky canyon
#

👍 ur very welcome

#

may not be the most performant to search thru all the params of the animator tho

tender stag
#

i'll prob end up having a bool

rocky canyon
#

cool, just letting u know in case u get performance issues later down the road

#

you'll know what to look for

untold raptor
#

is there a decent way of rendering 3D models onto a canvas? or if not possible whats the next best workaround

rocky canyon
#

as long as it doesnt have 100s of params u should be fine

tender stag
#

i only have 3

rocky canyon
#

u could have the camera w/ the canvas render just the model

#

w/ the UI on top (or around it)

untold raptor
rocky canyon
#

if you wnat it to be part of the canvas like a 2D image.. you can use a 2nd Camera.. and a RenderTexture

#

ur Image component would hold the render texture.. and it would be rendering w/e the camera is showing..

#

ie: focused on ur 3d model

untold raptor
#

i see

rocky canyon
#

can you show it? !code

eternal falconBOT
leaden lotus
#

Good evening, im struggling with a code where my code works, half of the time. So basicly my code consists of:

public bool hit;
Vector2 movement = new Vector2(horizontal * moveSpeed, rb.velocity.y);

hit = Input.GetMouseButton(0);
if (hit);
{
terrainGenerator.RemoveTile(mousePos.x, mousePos.y);
}
anim.SetBool("hit", hit);

and it will not allow me to break all the blocks on the map. Blocks are being placed like:

public void PlaceTile(Sprite tileSprite, float x, float y, bool backgroundElement)
{
    GameObject newTile = new GameObject();

    newTile.transform.parent = this.transform;
    newTile.AddComponent<SpriteRenderer>();
    newTile.GetComponent<SpriteRenderer>().sprite = tileSprite;
    newTile.name = tileSprite.name;
    newTile.transform.position = new Vector2(x + 0.5f, y + 0.5f);

    worldTiles.Add(newTile.transform.position - (Vector3.one * 0.5f));
    worldTileObjects.Add(newTile);
   } 

and are abled to be deleted by:

public void RemoveTile(int x, int y)
{
    if (worldTiles.Contains(new Vector2Int(x, y)))
    { 
        Destroy(worldTileObjects[worldTiles.IndexOf(new Vector2(x, y))]);
    }
}

and for some reason i dont understand why it will allow me to break some of the blocks on the map, but it wont allow me to break all of them. This is totally random so idk whats going on. If anyone could help me?

hot palm
summer stump
rocky canyon
untold raptor
rocky canyon
# hot palm
public void Hover(Object whatCalledMe)
{
    Debug.LogWarning($"Hover! {whatCalledMe}");
}```
hot palm
#
private void FixedUpdate()
{
    Vector3 raycastDirection = (_LookAt.position - _POV.position).normalized;

    RaycastHit hit;

    Ray ray = new(_POV.position, raycastDirection * interactRange);

    if (Physics.Raycast(ray, out hit, interactRange, LayerMask.GetMask("Interactable")))
    {
        if (hit.collider != null)
        {
            if (hit.collider.gameObject.CompareTag("Interactable"))
            {
                hit.collider.gameObject.GetComponent<InteractableObject>().Hover();
            }
        }
    }

    Debug.DrawRay(_POV.position, raycastDirection * interactRange, Color.red, 1.0f / 60.0f);
}
#

I'll try that

rocky canyon
#

can u change ur debug to include this? then in ur Hover() method.. u can
hit.collider.gameObject.GetComponent<InteractableObject>().Hover(this);

#

u can see what script is calling it.. if it is indeed ur only script it would be obv but im not sure..

hot palm
#

Yes Ill try

rocky canyon
#

is there an interactable object blocking the raycast?

#

idk why it would be being called all the time

#

especially when ur pressing left click..

hot palm
#

No for testing I tagged evrything as untagged an only the object as interactable

verbal meteor
#

Hi, how can i save this in PlayerPrefs?

rocky canyon
#

ud just need to save the musicSource.mute bool

hot palm
rocky canyon
#

and when u read from it.. do the function

hot palm
#

ah I know whay

rocky canyon
hot palm
#

forgot to updte this

rocky canyon
#

ohhh u have events going too?

hot palm
#

One step closer

rocky canyon
#

well its not passing in any object

#

so its like running by it-self?

hot palm
rocky canyon
#

did u add this part?

#

yea.. weird

#

it should show u the script/object that ran that function

hot palm
#

I can assume my code is not working, but me left clicking starts this event somehow

rocky canyon
#

but its saying null

#

ahh yea.. the event part i wasnt even aware of

#

thats probably linked to ur mouse click

#

alright.. u can change it back how u had it.. that didn't reveal any use-ful information as i thought it would

hot palm
#

Well I now know that event stuff isnt really working perfectly

verbal meteor
rocky canyon
#

ya, silver lining i guess

rocky canyon
#

like when ur loading

#
-> set it[yourgameobjectsyouneedactive] active or inactive.. to match```
#

playerprefs should contain simple data..

#

1s and 0s

#

strings and such

#

all u need to know is if it is muted..

#

and then if it is.. ur loading logic would handle what changes in the game

hot palm
#
PlayerPrefs.SetInt("Music", 0);
bool music = PlayerPrefs.GetInt("Music") == 0 ? false : true;
#

Like this

untold raptor
hot palm
dusk musk
#

Hi folks! Can somebody advise me on how to fix my script for successfully printing my player name? My current script is:

    public static string playerNameInput;

    public void ReadPlayerName(string playerNameString)
    {
        playerNameInput = playerNameString;
        Debug.Log("Player name = " + playerNameString);
    }

I believe the issue comes from the section circled in red on my screenshot. There shouldn't be a field to type something, right?

Thank you!

hot palm
#

Turns out why it was loggin this, now I just need to find out how to get the raycast thin working

rocky canyon
hot palm
#

Maybe I am using a bad approach

#

No I understand it now it's fine

rocky canyon
#

ya, i would just retry

#

do it something simple..

#

i tend to isolate things until i get them working/fully understand them

hot palm
#

Yeah

rocky canyon
#

may help you too.. to maybe make a new scene w/ nothing in it..

#

and just work on that 1 script.. maybe a simple cube or 2

hot palm
#

Well I did just that

rocky canyon
#

ya, even simpler..

#

forget about the capsule/controller and everything else..

verbal meteor
hot palm
#

No you would safe it, whenever you change it

#

So OnMusic has the PlayerPrefs.SetInt("Music", 1); (1 is for true)

#

and OffMusic has PlayerPrefs.SetInt("Music", 0);

rocky canyon
#
// Read your data
bool isMuted = PlayerPrefs.GetInt(MuteKey, 0) == 1;

// Now apply your data to the game world
musicOn.SetActive(!isMuted);
musicOff.SetActive(isMuted);```
hot palm
#

Then this

bool musicOn;
private void OnEnable()
{
  bool musicOn = PlayerPrefs.GetInt("Music") == 0 ? false : true;
}
#

you wouldn't need musicOff, as musicOn being false means the music is off

rocky canyon
#

yup. just 1 bool..

#

isMusicOn and isMusicOff is the same property

#

altho i know why u have 2 gameobjects..

#

1 for like a Microphone.. and 1 for a Microphone with a slash thru it

#

but u dont need that extra stuff for the playerpref key

#

just do that in ur logic after u read the key

hot palm
rocky canyon
#

same for like levels.. if ur on level 2..u just read that 1 value.. and then ur gamemanager or w/e would set up everything else.. that level2 needs

rocky canyon
slender nymph
rocky canyon
hot palm
#

2 years into unity

verbal meteor
#

i dont know, I do not understand PlayerPrefs :/

hot palm
#

Know nothing of netcode but a bit about stuff going on.

rocky canyon
#

ahh okay.. about the same as me.. have you never worked with raycasts before?

hot palm
#

Not really that's the problem I am at right now

#

I have problems with detecting collision with raycasts

#

All the stuff I tried didnt work

rocky canyon
#

oh yea, me neither.. im 3 years into Unity.. i know my way around raycasts for sure.. but i havent touched netcode yet

hot palm
#

Can I call OnTriggerStay on the script doing a raycast and make the interactable a trigger?

#

Do I put OnTriggerStay on the intersecting object or the one with the trigger collider?

rich adder
#

why use triggers event if ur using raycasts

rocky canyon
#
// Check if the left mouse button is pressed
if (Input.GetMouseButtonDown(0))
{
    // Perform a raycast from the raycastStart position in the forward direction
    RaycastHit hit; // Store information about the object hit
    if (Physics.Raycast(raycastStart.position, raycastStart.forward, out hit, distance, shootableLayer))
    {
        // Log the name of the object hit
        Debug.Log("We hit: " + hit.transform.name);

        // we also have the *hit* variable we can check against for components / tags
    }
}```
#

heres my basic raycast script that i recycle..

#

pretty basic.. and has everything ud need as a beginner.. uses a layermask... and has an out variable

hot palm
#

Yeah but that doesn't work somehow

rocky canyon
hot palm
#

What I want to do is

#

Have the object know when I could interact with it and the object listens to my input and does the event when specified input is done.

rocky canyon
#

a string

#

the name of ur playerpref key

hot palm
#
string muteKey = "Music";

In this case

rocky canyon
#
private const string MuteKey = "IsMusicMuted";``` i actually used a cosntant in my example code
#

but same thing..

hot palm
hot palm
#
private void FixedUpdate()
{
    Vector3 raycastDirection = (_LookAt.position - _POV.position).normalized;

    RaycastHit hit;

    Ray ray = new(_POV.position, raycastDirection * interactRange);

    if (Physics.Raycast(ray, out hit, interactRange, LayerMask.GetMask("Interactable")))
    {
        if (hit.collider != null)
        {
            if (hit.collider.gameObject.CompareTag("Interactable"))
            {
                hit.collider.gameObject.GetComponent<InteractableObject>().Hover(this);
            }
        }
    }

    Debug.DrawRay(_POV.position, raycastDirection * interactRange, Color.red, 1.0f / 60.0f);
}

This should work, no?

rich adder
#

wrong

#

ray don't have a range

hot palm
#

Oh good to know

rich adder
#

they are infinite line from 1 point toward direction

verbal meteor
#

I know is bad but i don't know what do next or :///

hot palm
#

!code

eternal falconBOT
rich adder
swift crag
hot palm
#

Put the GetInt line in the enable function like this

private void OnEnable()
{
  bool musicOn = PlayerPrefs.GetInt(MuteKey) == 0 ? false : true;
}

Because it will ask for the value you want, when you start it

slender nymph
#

that's assigning to a local variable whose scope is entirely within that method

hot palm
#

Also you do this

private const string MuteKey = "IsMusicMuted";

Above outside the function

mild void
#

Hey Guys, Can anyone have help to why the transform position of 2 prefabs is the same, but their position in the scene is different? Thanks (:

slender nymph
verbal meteor
#

what I got lost notlikethis

hot palm
#

The transform origin of a child is its parent. So if you have a parent and a child, the child has to be 0, 0, 0 to be on the same position

mild void
hot palm
# verbal meteor what I got lost <:notlikethis:1068134558123442236>
private AudioSource musicSource;

private const string MuteKey = "MuteMusic";

private bool isMuted = false;

private void Start()
{
    isMuted = PlayerPrefs.GetInt(MuteKey) != 0;
    musicSource.mute = isMuted;
}

private void ToggleMusic(bool value)
{
    musicSource.mute = !value; // Calling this function with true will mute the music

    int num = value ? 0 : 1; // Int is 0 when not muted, 1 when muted
    PlayerPrefs.SetInt(MuteKey, num);
}
mild void
#

sorry i dont know the terminology quite yet, thanks for the help

hot palm
#

Is it (bool) ? when true : when false; or the other way around?

rocky canyon
#

condition ? true : false

hot palm
#

Okay

slender nymph
#

PlayerPrefs.GetInt(MuteKey) == 0 ? false : true;
can just be PlayerPrefs.GetInt(MuteKey) != 0;
also what's the point in storing that in a field if you are just not going to use that field ever

hot palm
#

I edited it now it makes sense

#

Also that's good to know

hot palm
polar acorn
#

that'll help you find it online

hot palm
#

ohh thx

hot palm
# rocky canyon ```cs // Check if the left mouse button is pressed if (Input.GetMouseButtonDown(...
private void FixedUpdate()
{
    Vector3 raycastDirection = (_LookAt.position - _POV.position).normalized;

    RaycastHit hit;

    if (Physics.Raycast(_POV.position, raycastDirection, out hit, interactRange, LayerMask.GetMask("Interactable"))
    {
        if (hit.collider != null)
        {
            if (hit.collider.gameObject.CompareTag("Interactable"))
            {
                hit.collider.gameObject.GetComponent<InteractableObject>().Hover(this);
            }
        }
    }

    Debug.DrawRay(_POV.position, raycastDirection * interactRange, Color.red, 1.0f / 60.0f);
}

Changed it a bit still doesn't work

#

Lemme trouble shoot

queen adder
#

can i get iframe to add my unity webgl game to my website

rich adder
queen adder
#

i dont think that will work

rich adder
#

ofc it works

slender nymph
#

have you tried it?

queen adder
rich adder
#

ok, i know what an iframe is

queen adder
#

told you

#

when I pressed yes it didnt work.
i am gonna scavenge the code for an i frame

slender nymph
#

you also don't need an iframe. you just need to embed the game onto the page literally the same way that the index.html file does for the built game

verbal meteor
# hot palm ```cs private AudioSource musicSource; private const string MuteKey = "MuteMusi...

    private bool isMuted = false;

    private void Start()
    {
        isMuted = PlayerPrefs.GetInt(MuteKey) != 0;
        musicSource.mute = isMuted;
    }

    private void ToggleMusic(bool value)
    {
        musicSource.mute = !value; // Calling this function with true will mute the music

        int num = value ? 0 : 1; // Int is 0 when not muted, 1 when muted
        PlayerPrefs.SetInt(MuteKey, num);
    }

    public void OnMusic()
    {
        musicSource.mute = false;

        PlayerPrefs.SetInt("MuteMusic", 0);
        bool music = PlayerPrefs.GetInt("MuteMusic") == 0 ? false : true;

        bool isMuted = PlayerPrefs.GetInt(MuteKey, 0) == 1;

        
        musicOff.SetActive(isMuted);

        //musicOn.SetActive(true);
        //musicOff.SetActive(false);
    }

    public void OffMusic()
    {
        musicSource.mute = true;

       
        musicOn.SetActive(!isMuted);

        //musicOn.SetActive(false);
        //musicOff.SetActive(true);
    }```
#

like this?

hot palm
#

You can delete Off and On music

#

I don't know what you want to achieve with

//musicOn.SetActive(true);
//musicOff.SetActive(false);

but you can add it if you need it

eternal needle
hot palm
#

Now just call ToggleMusic(false) somwhere to mute it

slender nymph
hot palm
#

We should probably check it, true.

if (PlayerPrefs.GetInt(MuteKey) != null)
{
  isMuted = PlayerPrefs.GetInt(MuteKey) != 0;
  musicSource.mute = isMuted;
}```
slender nymph
#

if (PlayerPrefs.GetInt(MuteKey) != null)
is not valid

#

an integer cannot be null

verbal meteor
hot palm
#

How di I check for it existing?

slender nymph
#

and that is also entirely unrelated to what bawsi was asking

hot palm
#

Thought he meant reading it instantly = in start

hot palm
rich adder
slender nymph
hot palm
#

Well OnMusic and OffMusic are italian food at this point (Spaghetti), so they can go

#

You should probably rename ToggleMusic to MuteMusic for better readability

#

(Mark it, press F2 and rename it there, press enter) That changes the name everywhere

#

Sorry for messing stuff up. I'm working on a game jam simultaneously and I really need to get stuff done haah

verbal meteor
hot palm
#

Last thing I realize it you should change it to

musicSource.Mute = value;

if you rename it to mute music, aswell as swap the line to

int num = value ? 1 : 0;
verbal meteor
#

can i tell you what i need to do?

hot palm
#

You can always ask. In the case I don't answer some one else will surely

verbal meteor
#

I need if it´s mute (this button)

#

like this

#

i change the scene and come back

hot palm
#

I see

#

Then add the code with the set active

verbal meteor
hot palm
hot palm
# verbal meteor to remain mute

It should, if it's not staying the same and you followed everything you will need someone who understands playerprefs. I don't like using them. I rather use actual data saving like json

verbal meteor
#

okay thank you

verbal meteor
hot palm
hot palm
#

Or how you named it

hot palm
# hot palm How tf does the object change transform
private void FixedUpdate()
{
    Vector3 raycastDirection = (_LookAt.position - _POV.position).normalized;

    RaycastHit hit;

    if (Physics.Raycast(_POV.position, raycastDirection, out hit, interactRange /*, LayerMask.GetMask("Interactable"*/))
    {
        if (hit.collider != null)
        {
            Debug.LogWarning("Intersecting Raycast object " +hit.collider.gameObject.name + " at " + hit.collider.gameObject.transform.position + "!");

            if (hit.collider.gameObject.CompareTag("Interactable"))
            {
                hit.collider.gameObject.GetComponent<InteractableObject>().Hover(this);
            }
        }
    }

    //Debug.DrawLine(_POV.position, _LookAt.position, Color.red, 1.0f / 60.0f);

    Debug.DrawRay(_POV.position, raycastDirection * interactRange);
}
slender nymph
#

it looks like your raycast is hitting the cube object on the player

hot palm
#

oh my

#

you are completely right

#

face palm moment

#

Sometimes we don't see the things directly in front of our eyes

#

I had removed the capsule collider but not the box

slender nymph
#

why did you remove any colliders? you should be using a layermask with your raycast to ensure it only detects colliders you want it to

hot palm
#

I usually have that, but as you see I commented it out for troubleshooting

#

Also I remove all colliders from my visual stuff, as I don't need them messing with the controller

#

Is there a simple way to debug something every second instead of every frame?

frosty hound
#

You'll have to make a timer

hot palm
#

I see

#

alternative would be an IEnumerator with wait for seconds and then calling stopcoroutine at some point, would that work?

frosty hound
#

Alternatively, you could use the Invoke call and set it to 1 second to call a debug function

hot palm
#

And if a condition is true recursively call it huh?

frosty hound
#

Yes that would work if there was a need to stop it

hot palm
eternal needle
#

Well you're just debugging, it doesnt matter if you use them

frosty hound
#

This is for debugging, so you can be as messy as you want.

hot palm
#

I see

#

So I am educated correctly, that invoking is a bad thing? xD

frosty hound
#

It's just unnecessary if you've organized your code correctly

hot palm
#

I guess coroutines do everything you would need so no need for invoking?

#

Btw I'm trimmed to used private functions and parameters as often as possible, why's that? Hacking/Cheating?

frosty hound
#

You can't prevent hacking or cheating by making things private

#

It's purely for code organization, and preventing accidental changes by the developers.

#

This really only matters when things get large or with multiple developers working together.

hot palm
#

I see, good to know. Thanks for the information

austere hedge
#

What is the syntax for the 'i' at the end of Coin? I have pickups that are called Coin1, Coin2, etc.

#

I vaguely remember it looking something like $"Coin"[i] as well but it's still not right.

hot palm
#
$"{Coin[i]}"
rich adder
hot palm
#

I think

rich adder
rich adder
hot palm
#

Oh mb didn't understand what was asked

#

I really should focus on one thing at a time

#

My compare tag seems broken

atomic yew
#

Hello everyone. In Unity, my particle effect covers my item as I want, but when running on Android, my particle effect does not cover my item. What could be the reason for this? Does anyone have information?

slender nymph
austere hedge
austere hedge
hot palm
#

It almost works. I get a reference to the Interactable GameObject. It just doesn't seem to accept the tag.

slender nymph
#

i just meant to not base your logic on the name of an object. like when you collide with an object or whatever don't check its name, check its tag or for a specific component

slender nymph
hot palm
#

Well I do that, but only once for every new object

#

I know I hit the cube

#

And the 1 runs

#

just the 2 not

#

meaning something is wrong with _Target.CompareTag

slender nymph
#

because you've hit something that you are not expecting to have hit

#

nothing is wrong with CompareTag

hot palm
#

Wait is it checking the parent tag? ughh

#

It is

slender nymph
#

because that was the object that was hit by the raycast

hot palm
#

It is checking cube tag, not the object the collider is on

#

The collider is on the Interactable object

slender nymph
#

Cube also has a collider

hot palm
#

👀

#

Makes ense why I get a nullpointer

#

Gosh I hate it

#

It's the simple small things

#

thx for enduring my stupidity @slender nymph 💌

carmine sierra
#

what is that function which can be used to detect collisions for non-trigger colliders

#

does it run as soon as the collider is touched

hot palm
#

OnCollisionEnter?

carmine sierra
#

yeah thanks

hot palm
carmine sierra
#

Any idea the best way to make a simple 2D destruction

#

in terms of visuals

#

of a rectangle

hot palm
#

particle system I guess

#

Dani said it's good

#

xD

#

Or shader stuff. I'm not into shaders tho

#

yet

carmine sierra
hot palm
#

What happens to Debug stuff when leaving it in a build?

ripe shard
south sky
#

Yo guys, the sprite of a character is moving in my game but I want the sprite of the character to flip when it moves in the other direction, how would I do this?

hot palm
#

Check it's velocity and flip the sprite renderer y

open vine
#

Is there an operator for if (x == a or b or c) then do this. Instead of having to write if (x == a || x == b || x == c)

ripe shard
south sky
hot palm
hot palm
#

You can check in which direction it walks by looking at the x velocity (when you have an rb2D) or just have 2 variables get the last and the current position and check which one is smaller

open vine
south sky
hot palm
ripe shard
open vine
#

LOL did not occur to me that "is" would be the actual one. Thanks!

ripe shard
south sky
#

Any work aroud?

hot palm
#

Oh, then you have to make one parent game object for both and either set x scale to -x scale or rotate around the y axis by 180

#

Idk if this is code-based, but everytime I move my cursor in the editor, I get nullreferenceexceptions. Also this text blends in and out of existence, whenever I hover Debug Inspector?

south sky
#

Damn and i though your the one who knew everything lol

hot palm
#

Haha no no. I just learned by doing for 2 years. More complicated stuff will often exist

teal viper
hot palm
#

What do you mean? This are the errors

teal viper
hot palm
teal viper
#

That's the callstack

hot palm
#

Okay

south sky
hot palm
#

Hover it

#

It should tell you

teal viper
# hot palm

Seems like a random unity ui bug related to the inspector. Does that happen if you disable debug inspector?

hot palm
summer stump
hot palm
#

But it's not workign as intended

teal viper
south sky
hot palm
#

Does a canvas block raycasts?

summer stump
teal viper
hot palm
#

It should display text now, which it doesn't (it sometimes does)

summer stump
#

Or multiply position by a vector with only x, times a float for the magnitude. Like Vector3.right

rich adder
#

there is Graphic raycaster which uses rect transforms or something

teal viper
south sky
hot palm
#

I dp use a Physics.Raycast

hot palm
teal viper
polar acorn
hot palm
#

But dont need help for the X problem rn

south sky
teal viper
rich adder
teal viper
rich adder
hot palm
#

Basically if UI in world space can interfere with collision and raycast

hot palm
#

bcs I expierenced some weird UI behaviour regarding raycast before

#

Not in 3d tho

#

I think it was something like text making a slider area bigger or smth

teal viper
#

You can debug it really easy. Just print what your raycast hits

#

If it does hit the UI somehow, you will see it.

hot palm
#

true

rich adder
#

are you trying to hit a WorldSpace UI with FPS controller?

hot palm
#

No I want to evade that

rich adder
#

oh ok

#

you should be fine then

hot palm
#

I want to display world space UI when looking at a collider up to a max distance, but it jitters kinda

#

let me ask you more after troubleshooting this

south sky
#

People need to know about the Awake() method more its so good

#

Better than Start() imo

hot palm
#

Well it's important for static instances and referencing them in the start method

rich adder
#

they're very different methods

summer stump
rich adder
#

so like initializations

#

Start is better for Using the values from references like you said

#

also Start can be disabled via script checkbox, Awake cannot etc.
(Awake always runs on disabled scripts not disabled objects though)

rich adder
#

nah unity runs awake when the instance is created

#

only game object starting disabled would prevent that

#

these methods * can be disabled from running ( i mean the checkmark in inspector myb)

teal viper
rich adder
#

of the GameObject active state, not script .enabled

#
 private void Awake()
    {
        Debug.Log("Awake Ran");
    }
    void Start()
    {
        Debug.Log("Start Ran");
    }```
teal viper
#

Oh, I see.
The first paragraph in the docs was a bit confusing as it mentioned "enabled" components.

#

I guess it was me who had false memories after all.😅

#
Unity calls Awake when an enabled script instance is being loaded.
rich adder
#

ah yeah tha is confusing, I always assumed that to be like a traditional constructor

toxic fossil
rich adder
#

when unity has a gameobject as active its running its own new()

#

which runs awake basically

teal viper
#

I see. That makes sense.

timber tide
#

and awake is basically useless for scriptable objects in the editor

#

q_q

timber tide
#

only called through a domain reload

rich adder
#

oh cause its like an Asset being created not a runtime thing

timber tide
#

yeah, it's silly

rich adder
#

I guess the whole AssetDatabase needs to update too

timber tide
#

So better off using OnValidate() or ISerialization interface, otherwise grab all scriptable objects and implement your own Awake

rich adder
#

no wondering i see OnValidate more often in SOs 😅

south sky
#

So uhhh any alternatives?

teal viper
teal viper
timber tide
#

right, usually the better idea. Also similar idea for plain c# objects

carmine sierra
#

quick question for documentation reasons, is there a point of oncollisionenter on a trigger collider

teal viper
south sky
teal viper
rich adder
south sky
rich adder
#

always check the docs/api when something doesn't quite line up

#

shouldn't your IDE have that in the suggestion box somewhere :p

south sky
south sky
#

Soz

south sky
#

I may have read wrong

summer stump
south sky
#

Ima try anyway

teal viper
rich adder
#

if the child has no parent, then local is just world

south sky
#

Im learning

#

Thank you thank you

heavy temple
#

!ide

eternal falconBOT
hushed hinge
#

I remember someone said with a video that I could also use a camera follow that doesn't just fully focused on the player like you can go to the egde a bit, but I don't remember where

hushed hinge
#

which one? there's many

rich adder
cosmic dagger
#

it's a package you import for the camera . . .

hushed hinge
rich adder
#

in Package Manager there is only 1 Cinemachine package

cosmic dagger
hushed hinge
cosmic dagger
#

@hushed hinge you can search or google where the package manager is or how to import cinemachine. i'd look for a tutorial . . .

rancid tinsel
#

what can I use instead of a while loop here?

cosmic dagger
hushed hinge
rancid tinsel
#

but i havent implemented a level ending yet so just until they run out of time for nnow

cosmic dagger
rancid tinsel
#

definitely nnot half a second

#

oh wait

#

i know what happened

#

its in update 😭

cosmic dagger