#šŸ’»ā”ƒcode-beginner

1 messages Ā· Page 93 of 1

burnt vapor
#

This really isn't a question that fits in this server as it has nothing to do with Unity. I doubt anybody will know the answer.

#

You're better off asking the !cs server

eternal falconBOT
static cedar
#

You can still rename it to .cs and send it. :p

#

Most people on pc can view it.

#

But it can get so long as some point that discord will cut it off anyways.

kindred swallow
#

why i cant refrence it?

slender nymph
#

is the interface in a namespace you haven't added a using directive for?

slender sinew
#

it should tell you why it doesn't work if you hover over it

delicate portal
#

In unity's input manager package, it had a binding to mouse delta. It doesnt have it now. Why and how can I replace it?

rare basin
#

!code

eternal falconBOT
bitter oar
#

oh thanks didnt know

#

Hey, I need help. I've got a player that moves, and when i change the movement direction, he faces it straight away. what i want to do is like in mario games, that he starts slowly facing that direction and drifting towards it. (like leaning to it). i dont care about rotation right now just about movement.

my code is this:

private void HandleMovement()
    {
                moveDirection = new    Vector3(cameraObject.forward.x, 0f, cameraObject.forward.z) * inputManager.verticalInput; 
                moveDirection += cameraObject.right * inputManager.horizontalInput;
                moveDirection.Normalize();
                moveDirection.y = 0;

                if (inputManager.moveAmount > 0)
                {
                        if (isSprinting && inputManager.moveAmount > 0.5f)
                        {
                            moveSpeed = sprintingSpeed;
                        }
                        else
                        {
                            if (inputManager.moveAmount >= 0.5f)
                            {
                                if (!isSprinting && moveSpeed < maxSpeed)
                                {
                                    moveSpeed = maxSpeed;
                                }
                            }
                            else
                            {
                                if (moveSpeed > walkingSpeed)
                                {
                                    moveSpeed = walkingSpeed;
                                }
                            }
                        }
                        moveDirection *= moveSpeed;
                }
                else
                {
                    moveSpeed = 0;
                    moveIncreaseSpeed = 0;
                }
        if (isGrounded && !isJumping)
        {
            Vector3 movementVelocity = moveDirection;
            playerRigidbody.velocity = movementVelocity;
        }
    }
#

here

#

sorry

rotund condor
#

what exactly are you trying to achieve? is this a platformer?

bitter oar
#

third person platformer, yes

rotund condor
#

aha, and what exactly do you want the movement to do?

bitter oar
#

lets say im facing forward, and then i turn the joystick right-up. now, he just keeps moving in that direction. i want him to slowly face that direction so the turn will be more rounded (sorry if my explaining sucks, if you still dont understand ill try to explain better)

rotund condor
#

so you want your camera to align or better word recenter to the direction you move to correct?

bitter oar
#

no not the camera

#

can i send a screenshot?

#

or is it against rules?

rotund condor
#

I have no idea im new here

bitter oar
#

i see someone has sent here screenshots in the past so i will asume you can

hexed terrace
#

videos and screenshots of your issue are wanted

#

they're useful and help get the point across better than words

bitter oar
rotund condor
#

I see, how about for turning left and right you rotate

slender nymph
#

slerp your movement direction and rotation toward your input

rotund condor
#

or that

bitter oar
slender nymph
bitter oar
#

so would it be like this?

moveDirection = new Vector3(cameraObject.forward.x, 0f, cameraObject.forward.z) * inputManager.verticalInput; //front and back
                moveDirection += cameraObject.right * inputManager.horizontalInput;
                moveDirection.Normalize();
                moveDirection.y = 0;

                moveDirection = Vector3.Slerp(moveDirection, moveDirection + cameraObject.right * inputManager.horizontalInput, 2f);
#

i guess not because its not working... did i do it wrong?

slender nymph
#

first thing i notice is that your t parameter for the Slerp call is 100% incorrect

bitter oar
#

oh so i need to multiply it by Time.deltaTime?

slender nymph
#

well that depends on how you want to handle it. technically that is wrong, but may lead to results that are close enough to what you want

bitter oar
#

t is like how much time the lerp takes, right?

rare basin
slender nymph
rare basin
#

t is the interpolation point

#

basically timeElapsed/lerpDuration

bitter oar
steel smelt
#

can the assumption be made that awake has been called on every scene components at the time of unity's sceneloaded callback?

slender nymph
#

probably, i just tested it and Awake was called before the sceneLoaded event was invoked. but i honestly wouldn't count on that always being the case

bitter oar
#

is this better?

moveDirection = new Vector3(cameraObject.forward.x, 0f, cameraObject.forward.z) * inputManager.verticalInput; //front and back

                moveDirection.Normalize();
                moveDirection.y = 0;

                if (driftTimeElapsed < driftDuration)
                {
                    float t = driftTimeElapsed / driftDuration;
                    moveDirection = Vector3.Slerp(moveDirection, moveDirection + cameraObject.right * inputManager.horizontalInput, t);
                    driftTimeElapsed += Time.deltaTime;
                }
                else
                {
                    driftTimeElapsed = 0;
                    moveDirection += cameraObject.right * inputManager.horizontalInput;
                }
#

tried it

#

made a modification

#

ill edit the message

#

so it kinda works

#

its lerping correctly

#

but when its done, it resets and does it again

rich adder
#

where did you put this script?

#

it should prob be in a coroutine and ran once

bitter oar
#

good idea

#

im running it in fixedupdate

rich adder
bitter oar
#

because the player can always just change the input

rich adder
#

oh you have input in there..

bold nova
#

Im trying to instantiate a player and enemy prefabs at the start of the game session, somewhy there's an error stating that prefabs are inactive, even though as prefabs they are saved as active

#

Instantiate(playerController, playerController.transform.position,
playerController.transform.rotation);
Instantiate(enemyPrefab, enemyPrefab.transform.position,
enemyPrefab.transform.rotation);

bitter oar
rich adder
eternal falconBOT
bitter oar
#

thats the problem

rich adder
bitter oar
#

oh ok thx. anyone else?

tawny cave
#

I'd like to teleport my player upon death but I get syntax errors, I don't know how to fix them...

rich adder
#

how do we assign things in code ? šŸ™‚

bold nova
#

oh, backquotes..

tawny cave
rich adder
#

what is error is saying

#

what is target

#

postion is a vector3

polar acorn
bold nova
#
    public void StartSession()
    {
        loseMenu.SetActive(false);

        Instantiate(playerController, playerController.transform.position,
            playerController.transform.rotation); 
        Instantiate(enemyPrefab, enemyPrefab.transform.position,
            enemyPrefab.transform.rotation);

        playerController.GetComponent<PlayerController>().StartIntro();
        enemyPrefab.GetComponent<Enemy>().StartIntro();

        enemyPrefab.GetComponent<Enemy>().StartShooting();
        spikeSpawner.gameObject.SetActive(true);
        gameIsOn = true;
rich adder
#

and show the prefab of such object

polar acorn
bold nova
bold nova
polar acorn
#

What is the actual error you are getting

bold nova
#

Coroutine couldn't be started because the the game object 'Player' is inactive!

little meteor
bold nova
#

yeah, i've assigned prefabs, now everything seems to work now

polar acorn
normal arrow
#

Hi again !
i've found this command in the unity API ScreenCapture.CaptureScreenshot and from what i understood, this takes an entire screenshot, but from which camera ? is there a way to choose to camera that takes the screenshot ?

normal arrow
#

yeah that what i tought indeed

rich adder
normal arrow
#

yeah but it's a bit overkill for what i want

#

thanks !

little meteor
normal arrow
#

at runtime

tawny cave
#

So when trying to teleport my player upon death, it gets teleported for 1 frame to the right location then is right away back where it was. I am using characterController to move the player. Any fix ?

little meteor
tawny cave
#

I am thinking of moving it with a vector between spawn location and player location with characterController.move, but I'd like an easier way

polar acorn
bold nova
#

ok, i've figured it out. I wanted to locate those prefabs on the dafault point, when player clicks replay button. Now everything works, but is if someone knows better way, im opened to suggestions.

#
        Vector3 enemySpawnPosition = enemy.outPoint.position;
        Vector3 playerSpawnPoint = playerController.spawnPoint.position;

        playerController.gameObject.transform.position = playerSpawnPoint;
        enemy.gameObject.transform.position = enemySpawnPosition;

        playerController.StartIntro();
        enemy.StartIntro();

tawny cave
rich adder
#

if you move manually , the next frame will just return back

crisp tulip
#

like your brain

#

i know

#

just turn off the wifišŸ‘

frosty hound
#

There's no off topic here. Move on.

smoky niche
#

Hey there I have a question. I start a coroutine in another coroutine using yield return StartCoroutine(CoroutineTwo()); This should first finish that second coroutine before moving on with it's onw code if I remember correctly. The problem is that everything after the CoroutineTwo() doesn't get called anymore. Can anyone help me find the problem? Here is my code for the first Coroutine:

    {
        if(activePlayerPowerupState == newPowerupState) yield break;

        isPoweringUp = true;
        yield return StartCoroutine(animationController.PowerupAnimationCo(newPowerupState, activePlayerPowerupState));


        //THE CODE BELOW DOESNT GET CALLED


        if(activePlayerPowerupState.powerupSize != newPowerupState.powerupSize)
        {   
            if(player.IsDucking())
            {
                SetCrouchSize(newPowerupState);
            }
            else
            {
                SetBaseSize(newPowerupState);
            }

            controller.CalculateRaySpacing();
        }

        activePlayerPowerupState = newPowerupState;
        isPoweringUp = false;
    } ```
#

Here is my code for the second coroutine:

    {
        if(activePowerupState.powerupSize == PlayerPowerupState.PowerupSize.Small)
        {
            if(newPowerupState.powerupSize == PlayerPowerupState.PowerupSize.Large)
            {
                Vector3 startScale = transform.localScale;
                string animToPlay = CheckAnimationState();
                SetAnimator(newPowerupState);
                PlayAnimation(animToPlay);

                transform.localScale = new Vector3(startScale.x, startScale.y  / 1.2f, startScale.z);
                float newYScale = transform.localScale.y;
                
                SetSpriteOffset(newPowerupState);
                float yOffset = (startScale.y - newYScale);
                transform.localPosition -= new Vector3(0f, yOffset, 0f);

                yield return new WaitForSeconds(0.1f);
                transform.localScale = new Vector3(startScale.x, startScale.y / 1.3f, startScale.z);
                newYScale = transform.localScale.y;
                SetSpriteOffset(newPowerupState);
                yOffset = (startScale.y - newYScale);
                transform.localPosition -= new Vector3(0f, yOffset, 0f);

                yield return new WaitForSeconds(0.1f);
            }
        }
    } ```
buoyant knot
#

!code

#

ok fine. I summon thee. Come! !code

fossil drum
#

You can summon all you want, but the dyno shards are dead

rich adder
#

!help

buoyant knot
#

he needs a blood sacrifice, but I’m all tapped out

rich adder
#

one of us

smoky niche
#

Oh sorry do I put the code in there and post it here again?

buoyant knot
#

yeah. it’s tidier, and on mobile, your code looks like this

smoky niche
#

Ah I see, I'll do it rn. Thx for letting me know!

buoyant knot
#

i assume this is for the mario project, right?

#

it’s not relevant to the discussion. just asking

smoky niche
#

Yeah just a prototype thingy that gets stuck

#

Wait how do you know lol

buoyant knot
#

i saw the video, your code, and your name. put two and two together lol

smoky niche
#

Oh okay, well yeah I'm basically overhauling the thing ans starting over

#

Okay how do I send the filled in hatebin thing?

buoyant knot
#

link at the top

#

i wonder if the issue comes from the second coroutine coming from a different class.

smoky niche
#

Well I have done some testing with a coroutine in the same class and it does the same so I dont hink that's the issue

buoyant knot
#

you could try making the second coroutine’s IEnumerator private, and give a public method to start that coroutine. I assume the second Ienumerator comes from a class derived from monobehaviour?

smoky niche
#

Yeah it's a monobehaviour

buoyant knot
#

i’ve done it before too, but i don’t recall doing that within a Coroutine

quiet dune
#

Hi hi, i want an animal to eat another. My idea is to add a collider to the eaters head and "eat" anything, that collides. I already have a collider on the game object tho. Can implement collision or trigger methods for individual colliders or is this approach over the top?

buoyant knot
#

ok, try making a public method in the second class that starts the coroutine

#

btw, you probably want to save a private variable for the coroutine to make sure you don’t have two running at once.

smoky niche
#

Oh okay I'll try that

#

Thanks

#

But can I then still yield return it? As it's wrapped in a method

buoyant knot
#
public void TryStartPowerupAnim() {
if (poweringUpAnim == null)  poweringUpAnim = StartCoroutine(MyCoroutine());
}```
#

and MyCoroutine sets poweringUpAnim = null at the end

#

oooh, the formatting was so strange, I didn’t understand why it wasn’t working

#

i didn’t realize you were yield returning StartCoroutine

tawny cave
#

what is the method if I want to make my player object child of a platform so that it moves with it ?

smoky niche
#

Oh is that why it doesnt work?

buoyant knot
#

so, how is it supposed to work?
Coroutine 1 code block 1, Coroutine 2, then Coroutine 1 code block 2?

smoky niche
#

Yeah

buoyant knot
#

ooooh. Ok, so we don’t want to start coroutine

merry basin
#

fellas i need help my script does everything i want BUT it does not let me look up or down not sure what im doing wrong here

buoyant knot
#

or rather, we don’t want to start the second ienumerator as a separate coroutine

#

we want to manually enumerate through it.

little meteor
polar acorn
smoky niche
#

Oh okay okay

polar acorn
#

which makes it not doing everything you want

merry basin
buoyant knot
#

I forget the exact syntax, but in the first coroutine, you need something like;
IEnumerator powerupAnim = PowerupAnimationCo(…);
while (powerupAnim.MoveNext())
yield return powerupAnim.Current;

#

i need to check what the methods are called for IEnumerator, but you want the first IEnumerator to enumerate through the second one, partway thru

#

the system running the coroutines is probably extremely confused that you yield returned an object of type coroutine

smoky niche
#

Okay I see

#

Lol I remember doing smt similar in the past where it did work, but might be wrong

buoyant knot
#

ok i think the syntax I gave you is roughly right

merry basin
smoky niche
#

Nice I'll try it and do some more research, thanks for the help!

buoyant knot
#

good luck

smoky niche
#

Thx

summer stump
little meteor
wintry quarry
merry basin
tawny cave
#

is there a way to get the object name a character controller is standing on ? like characterController.isGrounded but for the name of the object

wintry quarry
#

Are there any errors in console?

slender path
#

Hey so I don't know if this is normal or not but my update function does not work

frosty hound
#

Obviously that is not normal

#

But you'll need to show code for anyone to see why

buoyant knot
#

define ā€œnot workā€

slender path
#

I might of fixed it

buoyant knot
#

another happy customer

slender path
#

nope it still does not work

slender path
buoyant knot
#

if the monobehaviour enabled, on an enabled gameobject, and timescale > 0?

slender path
#

It was the enabled thing

#

But i have another problem

#

I can't get a button to work

slender path
#

I am adding the listnener in the code above

buoyant knot
#

if you only say something doesn’t work, understand it is impossible to help fix

slender path
#

I try and have it log CLICK but it does nothing when I click it

buoyant knot
#

is giveitembutton null?

slender path
#

No I assigned it

buoyant knot
#

give the button many different colors for the different states

wintry quarry
buoyant knot
#

like for highlight, select, normal, etc

wintry quarry
#

Do you have an event system in the scene?

buoyant knot
#

give the button all different colors for selected, highlight, etc to see where the problem is

slender path
#

Thanks

topaz mortar
#

easy one šŸ™‚
var entry = character.FakeCharacter.SpriteCollection.MeleeWeapon1H.SingleOrDefault(i => i.Name == itemSO.SpriteName && i.Collection == itemSO.CollectionName);
How do I replace MeleeWeapon1H by my itemSO.CollectionName variable?

wintry quarry
#

SpriteCollection would need to have a Dictionary<string, whatever type MeleeWeapon1H is>

topaz mortar
#

heh? no I'm calling this line of code with multiple different itemSO.CollectionName's and I need the MeleeWeapon1H to change to the variable value

wintry quarry
#

And I'm telling you how to do that

#

C# is not Python or JavaScript

#

we cannot simply substitute strings for variable names willy nilly

topaz mortar
#

CollectionName is an Enum

wintry quarry
#

ok then

#

Dictionary<ThatEnumType, Whatever>

#

you will need a dictionary or a switch statement basically

topaz mortar
#

SpriteColection is "external" code - I can edit it, but would rather not
so I guess I just use a switch statement then?

wintry quarry
#

You can use a Dictionary or a switch

#

either way

#

you can build a function:

public Sprite GetSpriteForWeapon(WeaponType wt) {
  // return the corerct sprite for the weapon type
}```
#

you can implement this function with a Dictionary or a switch statement

#

I'm guessing at the types here

#

you'll have to fill in the correct parameter and return type

#

A better option than all of this might be just to have a direct reference to a ScriptableObject that has the sprite on it

#

There's too many unknowns in the example you provided to get very specific here though

topaz mortar
#

well basically I need to do this:

var entry = character.FakeCharacter.SpriteCollection.Helmet.SingleOrDefault(i => i.Name == itemSO.SpriteName && i.Collection == itemSO.CollectionName);```
But I don't know if it will be MeleeWeapon1H or Helmet up front and theres 15 other types
wintry quarry
#

You really should write shorter lines of code

#

this is all šŸ˜µā€šŸ’«

#

Anyway I explained what to do

#

You can tqake it or leave it

quiet dune
#

Can i have multiple colliders on a GameObject "A" and have only collisions to a specific collider of "A" execute a methode?

wintry quarry
#

Whatever SpriteCollection is needs to have a function on it to get a sprite for a given equipment type

wintry quarry
#

and put scripts on those sepearet children

quiet dune
buoyant knot
topaz mortar
#
    case "MeleeWeapon1H":
        var entry = SpriteCollection.MeleeWeapon1H.FindSomething();
        Equip(entry, itemSO.EquipmentPart);
        break;
    case "Helmet":
        entry = SpriteCollection.Helmet.FindSomething();
        Equip(entry, itemSO.EquipmentPart);
        break;
}```
There must be a better sollution for this over writing 15 of these?
#

I simplified the code to better show my question

wintry quarry
#

or just a direct reference to a ScirptableObject where this is preconfigured

#

instead of using a CollectionName

quiet dune
topaz mortar
#

like I said, it refers to external code that I would rather not edit

#

I don't understand how a dictionary would help?

#

and there's no way to add a direct reference to the sprite, it's not referencing a sprite but an object defined by the external code

#

this would be sooo easy in PHP, does C# really not have a solution for this?

eager elm
#

Is this the same?

GameObject go;
if (go)
{ //Do something; }
-------------------
if (go != null)
{ //Do something; }
rare basin
#
if(!go)

is also the same as == null?

wintry quarry
#

Yes

#

Note this is only specifically for things that derive from UnityEngine.Object

#

this is due to operator overloading for that type, not anything built into C#

rare basin
#

got it thanks

rich adder
#

did you try what I sent?

bitter oar
#

but the problem is im constantly checking for an input

summer stump
bitter oar
#

i mean right now im running it in fixed update, and any time there is a change to the joystick it recognizes it, would that work in a coroutine?

charred spoke
bitter oar
#

so like this?

IEnumerator DriftToDirection()
    {
        if (driftTimeElapsed < driftDuration)
        {
            float t = driftTimeElapsed / driftDuration;
            moveDirection = Vector3.Slerp(moveDirection, moveDirection + cameraObject.right * inputManager.horizontalInput, t);
            driftTimeElapsed += Time.deltaTime;
        }
        else
        {
            driftTimeElapsed = 0;
            moveDirection += cameraObject.right * inputManager.horizontalInput;
        }
    }
wintry quarry
#

this will be a compile error, and also makes little sense

bitter oar
#

yield return null?

polar acorn
summer stump
bitter oar
polar acorn
bitter oar
#

i only want it to run when input direction changed

polar acorn
bitter oar
slender nymph
#

it would need to be looping if you intend to make it a coroutine that you only call when input changes

pulsar lodge
pulsar lodge
#

29 on howepatazi

slender nymph
#

where do you assign to cKey

polar acorn
pulsar lodge
#

object reference not set to an instance of object

bitter oar
summer stump
formal escarp
#

Im unsure on why my code is not working. It does not drop the item when the enemy is killed.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DropBrain : MonoBehaviour
{
    public Transform transform;
    public GameObject Dropear;
    public float vida = 1f;
    void Update()
    {
        if (vida >= 0)
        {
            void die()
            {
                Destroy(gameObject);
                DropCerebro();
            }   
        }
    }

    // Update is called once per frame
    void DropCerebro()
    {
        Vector3 position = transform.position;
        GameObject Cerebro = Instantiate(Dropear, position, Quaternion.identity);
        Cerebro.SetActive(true);
        Destroy(Cerebro, 10f);
    }
}
polar acorn
#

Where do you call die()

formal escarp
formal escarp
#

(Tutorial)

polar acorn
#

Link to it

summer stump
#

Is that gpt?

formal escarp
formal escarp
#

1:35

bitter oar
polar acorn
# formal escarp https://www.youtube.com/watch?v=yjZ5mLNll5M

Well I'll be damned. One of the actual cases of this being true. Congrats on being the fifth ever:

"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 138
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2023-12-7
#

You should probably delete everything this tutorial told you to do and find one that isn't terrible

formal escarp
#

Do i get a high five?

#

BTW. I was also like "this guy created a void inside a void? it works? huh" so i was not sure if i was tweakin or not.

polar acorn
rich adder
polar acorn
formal escarp
#

Is the tutorial that bad? im going to search for another one either way.

polar acorn
bitter oar
#

how would i check if the left stick has moved since the last frame? using new input system

rich adder
#

seriously i would take something down if it was like that

polar acorn
#

You can maybe get some of the concepts, but don't use any code from it, make your own

formal escarp
#

but anyways, thanks.

rich adder
formal escarp
rich adder
formal escarp
#

I love and hate coding

rich adder
#

otherwise its like blindly following someone in the woods until they leave you stranded

formal escarp
#

Sometimes im happy because i make stuff works, or i get errors and i know how to fix em. But sometimes i just wanna take my own face off.

rich adder
swift crag
#
void Foo() { }
int Bar() { return 3; }
polar acorn
swift crag
#

these are functions named Foo and Bar

#

Foo returns nothing and Bar returns an integer

bitter oar
swift crag
#

You can indeed declare a function inside of another function

void Foo() {
  void Bar() {
    Debug.Log("Hi");
  }

  Bar();
}

This would log "Hi" if you called Foo.

The reason that the example in the tutorial was bogus was because it tried to put an access modifier -- public -- on the local function

polar acorn
swift crag
#

An access modifier only makes sense when declaring members of a type. Local functions don't exist outside of the function they're defined in, so it makes no sense to put public there.

bitter oar
#

reworded my question

polar acorn
bitter oar
#

yes but the variable im storing it in will be updated every frame to the new input - how do i stop that?

formal escarp
swift crag
#

It's not very common.

formal escarp
#

Why would you do it tho? In which cases?

swift crag
#

I only do it when I have some logic that:

  • I need to use many times in a function
  • I won't use anywhere else
queen adder
#

Could yall help me ? My 2d character cant start the runinng animation unless it jumps first

queen adder
#

Do i have to uncheck exit time?

rich adder
#

not sure where the code part comes in

#

you have to send that and show your transition conditions

swift crag
#

if this is an animation question, ask in #šŸƒā”ƒanimation . please show us your animator controller when you do so

ruby python
#

!code

eternal falconBOT
loud topaz
#

Question: How does the scaling get from top to bottom when attaching the player to the "attacher" empty with (1, 1, 1) scaling. The Player was (1, 1, 1) before.

#

I need the player to stay uniform.

ruby python
#

Hi guys, not sure if this belongs here or in #āš›ļøā”ƒphysics is honest as it's a bit of both, but I'm having a bit of brain fog.

I have a player shooting at a door, the door then explodes into bits and I want the 'bits' to be pushed away from the direction of the shot that destroyed it (using the physics system.

I'm getting the direction of the shot with.....

Vector3 shotDirection = (explosionPoint.transform.position - playerFiringPosition.position).normalized;

and I know that I have to apply a force to each of the 'bits' but getting the direction of the force (opposite of my 'shotDirection' variable) is eluding my addled brain.

loud topaz
#

this is the code that happens, when i touch the mover.

ruby python
rich adder
loud topaz
#

yeah i know why, but what does it calculate. can i reverse that?

rich adder
#

also you might not want to parent it to a non-uniform scale

loud topaz
#

the "attacher" is uniform

#

that doesnt work?

rich adder
rich adder
#

your platform isn't uniform btw

loud topaz
queen adder
#

You know what gravity should we use ?

loud topaz
#

i want to know what happens when i parent to something non uniform. how does unity get to those scaling numbers on the player.

rich adder
queen adder
swift crag
loud topaz
swift crag
#

This can't be done in many cases.

loud topaz
#

yeah, i know that it is math obv šŸ˜„

swift crag
# loud topaz

Is the player parented to something before touching the platform?

loud topaz
#

nope

swift crag
#

oh, wait

#

MovingPlatform is scaled, right

#

It doesn't matter that the Attacher object is uniformly scaled

loud topaz
#

it is numbers given above

swift crag
#

Its parent is not. Therefore, the player's local scale will have to change when you parent the player to Attacher

#

If you scale the parent, that affects all of its children, too.

#

You should rearrange it like this:

#
Moving Platform <- [1,1,1] scale, player attaches to this
  Surface <- any scale you want, has the renderer and collider
loud topaz
#

Attacher > Moving Platform and Player

swift crag
#

Right.

#

This way, everything above the player has a nice uniform scale

loud topaz
#

i know, but how does unity get to those numbers.

swift crag
#

I don't know exactly how it works, because it's non-obvious for rotated objects

#

An object whose parent is non-uniformly scaled gets distorted as it rotates.

#

If the parent scale is [5,1,1], then the player is always being stretched 5x in the parent's X direction

loud topaz
swift crag
#

So as the player rotates, different parts of the player get pulled

#

whatever is lined up with the parent's X axis

#

I guess Unity tries to approximate a scale for the player that minimizes the change as you go from no parent to distorted parent

#

If the parent is uniformly scaled, it's easy

#

if you reparent to something at [2,2,2] scale, your local scale halves

#

your local scale is [0.5, 0.5, 0.5], which perfectly cancels out the parent's [2,2,2] scale

loud topaz
#

i see. thx ill fix that. was just curious what happens under the hood šŸ™‚

wintry quarry
#

!collab

eternal falconBOT
queen adder
#

how can i make it so my character cant jump in the air? only until it hits the ground?

fossil tree
#

hi my problem is the next i try make when i push a button he be retired of my list and a other random button be add at the list but currently when i push my button that just remove without adding a new one why? my code:

    {
        if(boutonController.boutonListe.Contains(1))
        {
            boutonController.boutonListe.Remove(1);
                int random = Random.Range(1,9);
                while (random == boutonController.boutonListe[0] | random == boutonController.boutonListe[1] | random == boutonController.boutonListe[2])
                {
                    random = Random.Range(1,9);
                    if(random != boutonController.boutonListe[0] && random != boutonController.boutonListe[1] && random != boutonController.boutonListe[2] )
                    {
                    boutonController.boutonListe.Add(random);
                    score++;
                    }
                    
                }
                
                
                

                
                
        }
    }```
summer stump
loud topaz
#

@swift crag fixed it šŸ™‚ player stays uniform after leaving the platform. thx for your help

fossil tree
#

and this is the error i got : ```ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <6073cf49ed704e958b8a66d540dea948>:0)
bouton5.OnMouseDown () (at Assets/bouton5.cs:41)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)

polar acorn
rare basin
#

did you use | on purpose or you meant ||

#

(just asking, this is not related to the index out of range error)

wintry quarry
#

there's no way it's on purpose

fossil tree
buoyant knot
# queen adder how can i make it so my character cant jump in the air? only until it hits the g...

Options:

  1. Use OnCollisionEnter/Stay to detect collisions, and filter the contents to specifically detect ground.
  2. Use GetContacts to get all the contact points for your collider/RB, and filter to see if you have a valid ground contact.
  3. Raycast/BoxCast/Cast/CapsuleCast downward, and check if you hit ground.
  4. Have a separate collider below character as a trigger, and use OnTriggerEnter/Stay to look for ground.
  5. Define a region under your character mathematically. Then call Physics2D.OverlapAreaAll to check if any valid ground is found there.
polar acorn
fossil tree
#

why not

summer stump
polar acorn
buoyant knot
#

because it has a different meaning

fossil tree
buoyant knot
#

| is bitwise or

#

you know how a number is stored in binary with 0 and 1?

polar acorn
rare basin
buoyant knot
#

| goes through each bit individually and gives the or for each in the final

rare basin
#

if you want a boolean or you use ||

fossil tree
#

oh ok i see

buoyant knot
#

so 0011 | 1000 makes 1011

short hazel
#

| also works with booleans, it's just less efficient because it does not short-circuit

wintry quarry
#

it simply doesn't short circuit

short hazel
#

It's not bitwise in this context

wintry quarry
#

it's only bitwise with numerical arguments

rare basin
#

how isn't it bitwise or?

polar acorn
summer stump
rare basin
#

but im talking in general

polar acorn
#

This is one of the reasons to avoid it by the way

#

because it behaves differently depending on whether your values are numeric or boolean

fossil tree
summer stump
wintry quarry
# rare basin how isn't it bitwise or?
int x = 5;
int y = 6;
int result = x | y; // This is bitwise or

bool x = false;
bool y = true;
bool result = x | y; // This is logical or

It depends on the argument types

rare basin
#

ik

short hazel
polar acorn
rare basin
#

@summer stump please how can i block you, you're just a trolling clown

summer stump
#

Gets so mad all the time lmfao. Really embarrassing for you
I'm sure thinking I'm a troll or clown will make you feel much better about being a bully
Typical behavior

#

Click my profile, then the three dots and click block

rare basin
#

ok done lmao

polar acorn
# rare basin ik

It's best to avoid giving "general" information about a specific topic when the general information does not apply

buoyant knot
#

šŸ¤”

fossil tree
polar acorn
#

you can see a list in the inspector

buoyant knot
#

idk i didn’t realize | was even implemented for bools

polar acorn
#

but that might not be this list

fossil tree
buoyant knot
#

since people explicitly use | |

polar acorn
wintry quarry
polar acorn
#

one of them having a list set does not mean all of them do

#

log it

buoyant knot
#

i assume because of operator order

wintry quarry
minor roost
#

is there a good tut to make game hub in unity where u can choose ur game

polar acorn
buoyant knot
#

oh. i didn’t realize | wouldn’t short circuit for bools

summer stump
polar acorn
wintry quarry
wintry quarry
#

The only reason you wouldn't want to skip SomeExpensiveFunction is if it had some other side effect besides returning a bool

buoyant knot
#

makes sense. I assume || also has a much higher priority when it comes to order of operations?

wintry quarry
#

They ahve the same priority

fossil tree
buoyant knot
#

that’s unexpected

wintry quarry
#

NVM I'm wrong, | is actually higher priority

polar acorn
buoyant knot
#

idk if I’m reading it backwards. shouldn’t = have very high priority?

fossil tree
#

this is the code ```if(boutonController.boutonListe.Contains(1))
{
boutonController.boutonListe.Remove(1);
int random = Random.Range(1,9);
while (random == boutonController.boutonListe[0] || random == boutonController.boutonListe[1] || random == boutonController.boutonListe[2])
{
random = Random.Range(1,9);
if(random != boutonController.boutonListe[0] && random != boutonController.boutonListe[1] && random != boutonController.boutonListe[2] )
{
boutonController.boutonListe.Add(random);
score++;
}

            }
            
            
            

            
            
    }```

and in the log i got this : ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <6073cf49ed704e958b8a66d540dea948>:0) bouton3.OnMouseDown () (at Assets/bouton3.cs:41) UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)

buoyant knot
#

nvm it’s like the opposite

fossil tree
polar acorn
#

the log I told you to add

obtuse veldt
#

Do I need "using System.Diagnostics;", because when I am using "Debug.log()", it gives me error CS0104 with "using UnityEngine;"
Ty for the help (I am very new to Unity)

polar acorn
#

that you said you added

fossil tree
wintry quarry
obtuse veldt
polar acorn
summer stump
wintry quarry
buoyant knot
#

Debug is also a class in System, which can be confusing

obtuse veldt
#

oh my bad ;p

summer stump
# obtuse veldt oh my bad ;p

Another one that may get you is using System.Numerics

UnityEngine has its own Vector3, and if you have that it can cause an ambiguity error

buoyant knot
#

but obviously if you’re using Unity, you want Debug in UnityEngine and not in System

#

i just turned off all automatic using namespace things

#

VS kept adding the most random shit to my code, making it fail during build

languid spire
tender stag
#

if i have procedurally generated terrain, how would i go about making the nav mesh

obtuse veldt
#

now i have CS0117 (Debug does not contain a definition for log)

polar acorn
polar acorn
#

There's no such thing as Debug.log

tender stag
buoyant knot
#

Debug.Log

rare basin
# tender stag how would i bake it through script after i generated map
Unity Learn

In this recorded live training session we show how to work with Unity’s Navigation tools at runtime. We will explore the publicly available Components for Runtime NavMesh Building and look at how we can use the provided components to create characters which can navigate dynamic environments and walk on arbitrarily rotated surfaces, including ene...

rare basin
#

wait its removed

buoyant knot
#

does the version of C# supported by Unity allow Records? I have been struggling with those.

rich adder
rare basin
#

im pretty sure its just

#

surface.BuildNavMesh()? surface being the NavMeshSurface

rich adder
#

just bake it from the NavMeshSurface

tender stag
#

yeah

#

one more thing

obtuse veldt
#

It worked! I don t have errors but it doesn t print what i want to

tender stag
#

if i have like a building system in the future

#

like when i place a wall

#

do i need to bake the nav mesh surface again?

#

thats kind of performance heavy

summer stump
rare basin
#

if you have a dynamic environment with walls, obstacles etc, then yes

summer stump
obtuse veldt
rare basin
tender stag
#

so its possible

#

alright

fossil tree
summer stump
eternal falconBOT
rare basin
#

@tender stag

obtuse veldt
summer stump
obtuse veldt
#

How to do that

summer stump
#

I recommend taking the pathways here
!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

obtuse veldt
languid spire
polar acorn
languid spire
#

typical

tender stag
#

is it normal for a wire arc to have these like points

#

like its not a perfect circle

wintry quarry
#

it's made up of line segments

tender stag
#

oh alright

#

so is this why i cant connect these lines to it?

#

technically its correct

#

we just cant see it?

wintry quarry
#

Seems plausible

tender stag
#

what does that mean

wintry quarry
#

It's possible you're correct, but based on just eyeballing this it's also possible your lines/positions/math are slightly off

#

it looks good though

tender stag
#

alright

tender stag
#

just in case

#

its not that long

sage mirage
#

Hey, guys! Does dropdown panels have OnClick event cuz I can't see them, I can only see On Value Changed (int32)?

#

or maybe I cant add this event somehow?

rich adder
#

or any of the Event Triggers could work

sage mirage
#

Oh, ok thanks!

#

Yes but on pointer click is a class.

#

I mean if there is any method that does that

rich adder
valid pulsar
#

been learning the unity input system and set up a way to rebind keys is there a way i can set a refrence to an action in inspector instead of making a ton of lines an going playerInputActions.PlayerMovement.action for each line. i was looking around and it seems like theres a way everting i found looks very convoluted

sage mirage
#

@rich adder It is a custom method

#

There is a class called OnPointerClick

rich adder
#

its in there

languid spire
rich adder
#

or that

sage mirage
#

What is the event trigger?

rich adder
sage mirage
#

Oh, I found it

#

The IPointerClick is the same as the trigger?

rich adder
#

yes they do exactly the same thing

#

one is code and one is a inspector component

weary moss
#

will "random.range(1, 10)" generate numbers from 2 to 10?

rich adder
#

no 1-9

weary moss
#

alright thanks

queen adder
#

I tried bitshifting the layer that I wanted, I tried checking everything it collides with and comparing the collided obj's layer

#

I tried the using the log to get the ground layer

rich adder
queen adder
#

yep, 100%

rich adder
#

oh, how do you know its hitting player

queen adder
#

I think I checked at least 50 times by now lol

#

debug.logs

#

on line 71

#

it says player

rare basin
#

show the ground layer in the inspector

rich adder
#

oh ok and how about your hierarchy

queen adder
#

1 sec

rare basin
#

and the player's inspector where he has the collider component attached to

queen adder
rare basin
#

what's the player's layer

queen adder
#

default

rare basin
#

can you show it

queen adder
#

I really feel like it should be an obvous fix, bit I just can't seem to find it

#

Collision matrix is checked too

#

oh

#

i got it

#

it seems like that it did collide with it

rich adder
queen adder
#

yep

#

seems like m_GroundHit.transform.... returns the object the script is attached to?

#

which kinda makes sense

#

but also doesn't

queen adder
#

well, then I dont know why m_GroundHit.transform.gameObject would return the Player

rich adder
#

maybe you have another script somewhere thats stuck on default šŸ˜†

queen adder
#

well I have to check that, but I highly doubt it lol

rich adder
#

i always use collider

queen adder
#

and now that I've restarted unity it doesn't return the player at all

rich adder
#

are you sure you weren't looking at some old logs or something

weary moss
#

is case better than just a bunch of if's stacked?

queen adder
#

naah, I always delete or comment out my logs after I'm done using them

#

Even made this scene to just have the player and the ground

rich adder
rare basin
weary moss
#

yea

rare basin
#

to maybe use a dictionary or something else

weary moss
#

what's a dictionary

#

in the programming that is

rich adder
#

its the same thing

queen adder
#

key : value pairs

rare basin
#

serialized dictionaries will become your best friend

weary moss
#

the documentation?

queen adder
#

just type in "Unity dictionaries" or "C# dictionaries" into youtube

rare basin
#

just google it

queen adder
#

its like arrays on steroids

#

sorta

spring coral
#

real quick, how would I check if the current gameobject is already destroyed? doing gameObject == null returns a missingref exception

#

assuming it does that because this.gameObject calls a backing field that tries to invoke the actual logic, but i want to check for null

#

i was thinking of a weird hack like caching the local gameobject instance, maybe that would work?

rare basin
#

what do you need it for

queen adder
#

you could make the variable nullable

#

so if its destroyed, and you set it to be null when it's destroyed

#

with like an event or something

#

you can do stuff

#

but if you use an event on destroy, you probably dont even have to check if its null

#

since the event would fire when it gets destroyed

polar acorn
#

But that's assuming it's either active or gone. This won't work if being disabled is a normal condition for it

queen adder
#

what exactly are you trying to do? we're just shooting in the dark tbh

queen adder
#

maybe that's what was causing it

#

Cause I just can't recreate it now

queen adder
#

But I made this scene just to test it

#

its literally just the player script running along with the input manager

rich adder
#

that doesn't necessarily mean logs got cleared

summer stump
queen adder
#

I set my console to clear the logs every time a scene runs

queen adder
#

so its always cleared

spring coral
#

and hmmm maybe the ondestroyed thing will work?

#

then just compare against that

summer stump
queen adder
#

like I said, you could just fire an event when it gets destroyed

spring coral
#

also the problem is that some code is running due to unitask, and it runs until even after the object is destroyed

rich adder
#

explaining the use case would prob help get better solution

polar acorn
# spring coral the object is destroyed

Yeah, once you call Destroy on it, it'll deactivate it right away, but the actual destruction happens later. If it's never disabled other than this condition, you can check for it being disabled. If it is, then it's in the process of being destroyed

spring coral
#

explained above a bit more of why its happening

summer stump
spring coral
#

the unitask explanation

#

heres the code

#

this runs at some point, but then something else triggers this gameobject to destroy earlier, but this is still running

#

i might just be able to cancel the task though tbh

rare basin
#

maybe try/catch in this case?

spring coral
#

alternative solution

#

i think this should hopefully work?

#

without the need to set a flag in ondestroyed

rich adder
#

dejavu

valid pulsar
# valid pulsar been learning the unity input system and set up a way to rebind keys is there a ...

looking into this more and found this https://forum.unity.com/threads/get-reference-to-an-inputaction-by-action-name.1020280/ which would work but is there a way to just select the action insted of this

solemn fractal
#

Hey guys, I have this code that makes my enemies move.. but it seems that in diagonal they are faster even using normalized. Why is that? ```cs
private void Move(){

    Vector3 MoveDirection = _player.transform.position - transform.position;
    MoveDirection.Normalize();
    _rb.velocity = MoveDirection * data.speed;

} ```
red kindle
#

where do I find assets for my game?

#

I appreciate that

rich adder
timber tide
#

normalize should handle magnitude

solemn fractal
#

yesterday I was having the same prob with my player mov and I fixed like that: ```cs
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");

    Vector2 vector = new Vector2(horizontalInput, verticalInput).normalized;

    transform.Translate(playerSpeed * vector *  Time.deltaTime); ``` here I go same speed even in diagonal
timber tide
#

no clue about rb methods though

solemn fractal
#

But now I need the same for the enemies but they use rb.velocity

solemn fractal
onyx blaze
#

I'm trying to select my button via script, but aren't working "OnEnable"
Only works when "Start"
I'm doing something wrong?

tawny cave
#

I attached a box collider to the bottom part of my player. I'd like to make the player object child of a moving platform when this specific collider is in collision with the platform (player standing on it), but I get some syntax error....

rare basin
#

you can call Select() on any Selectable

tawny cave
solemn fractal
#

Trying to instantiate this cs [SerializeField] private BulletBossTwo[] _bullet; but not being able. I get the error . I cant instantiate things inside an array ?

rare basin
#

wdym instantiate things inside an array?

#

you want to add them into the array after instantiating?

solemn fractal
#

no, I can do it another way but just wanted to know if I cant do it, because I get this error and not sure why.

rare basin
#

but what are you trying to do

solemn fractal
#

basically each bullet will go to a dif direction

rare basin
#

show the code

solemn fractal
#

and it is 4 bullets using the same prefab but the mov is inside the bullet script and I am instantiating it inside the boss script.. so I created an array to make sure they are 4 dif things . But I can try to do differently.

#
private IEnumerator shoot(float waitOne, float waitTwo, float waitThree, float waitFour){

        while (true){
            
            Vector3 _posRight  = new Vector3(transform.position.x + 7.5f, transform.position.y, transform.position.z);
            Vector3 _posLeft   = new Vector3(transform.position.x - 7.5f, transform.position.y, transform.position.z);
            Vector3 _posTop    = new Vector3(transform.position.x + 6.9f, transform.position.y, transform.position.z);
            Vector3 _posBotton = new Vector3(transform.position.x - 6.9f, transform.position.y, transform.position.z);

            _bullet[0]   = Instantiate(_bullet, _posRight, quaternion.identity);
            yield return new WaitForSeconds(waitOne);
            _bullet[1]   = Instantiate(_bullet, _posLeft, quaternion.identity);
            yield return new WaitForSeconds(waitTwo);
            _bullet[2]   = Instantiate(_bullet, _posTop, quaternion.identity);
            yield return new WaitForSeconds(waitThree);
            _bullet[3]   = Instantiate(_bullet, _posBotton, quaternion.identity);
            yield return new WaitForSeconds(waitFour);
        }
       
    } ```
#

movement of the bullets ```cs
private void Move(){

    Vector3 _directionOne   = new Vector3(_bossTwo.transform.position.x + 7.5f, _bossTwo.transform.position.y, _bossTwo.transform.position.z);
    Vector3 _directionTwo   = new Vector3(_bossTwo.transform.position.x - 7.5f, _bossTwo.transform.position.y, _bossTwo.transform.position.z);
    Vector3 _directionThree = new Vector3(_bossTwo.transform.position.x + 6.9f, _bossTwo.transform.position.y, _bossTwo.transform.position.z);
    Vector3 _directionFour  = new Vector3(_bossTwo.transform.position.x - 6.9f, _bossTwo.transform.position.y, _bossTwo.transform.position.z);
    
    if (_bullet[0] != null){

    _directionOne = transform.position.normalized;
    _bullet[0].GetComponent<Rigidbody2D>().velocity = _directionOne * _velocity;

    } else if (_bullet[1] != null){

    _directionTwo = transform.position.normalized;
    _bullet[1].GetComponent<Rigidbody2D>().velocity = _directionTwo * _velocity;

    }else if (_bullet[2] != null){

    _directionThree = transform.position.normalized;
    _bullet[2].GetComponent<Rigidbody2D>().velocity = _directionThree * _velocity;

    }else if (_bullet[3] != null){

    _directionFour = transform.position.normalized;
    _bullet[3].GetComponent<Rigidbody2D>().velocity = _directionFour * _velocity;

    }
} ```
wintry quarry
onyx blaze
#

Aren't selecting :/

rare basin
onyx blaze
#

The code are getting the right object

solemn fractal
#

but my question was, I cant instantiate things inside an array ?

rare basin
#

is BulletBossTwo a MonoBehaviour?

wintry quarry
#

You can Instantiate an individual "BulletBossTwo"

#

but not an array of them

#

if you want to do something for each member of the array, use a loop.

solemn fractal
wintry quarry
# solemn fractal ok thank you

As general advice, any time you find yourself "numbering" your variables or class names, such as:

  • _directionThree. _directionFour etc
  • BulletBossTwo
  • _bossTwo
    That's a STRONG indicator you should really be using arrays, lists and loops
rare basin
#

or dictionaries! šŸ˜„

wintry quarry
#

collections in general, and loops

solemn fractal
#

Got it, thank you guys.

rare basin
#

once i've discovered serialized dictionaries i can't dev without it

timber tide
#

my serialized dictionary keeps breaking my data that I got from the forums

onyx blaze
#

Debug.Log are retrieving the object, but aren't selecting in the screen

timber tide
#

I've just been loading the data manually at startup

rare basin
#

available on github free to use

onyx blaze
#

I set a coroutine and it's works \o
Just need to wait 1 frame

maiden current
#

Hey guys, I'm thinking about a Save System for my game.

I was thinking about making an interface to implement to every gameObject that needs to save / load data. Then, when saving the game I collect all items in the scene that have inherited the interface and call the save method.

I now have the data for all the scene, the thing is, to keep track of the data from other scenes I'll make an static persistent gameObject that contains all the variables to be saved from all scenes.

My doubt is the next. If I'm in a scene and I navigate to another for the very first time I would firstly save the current data in that static script and then when entering the other scene I would load the data I have in the hierarchy of that scene. If It's the first time I'm in that scene It would load uninitialized variables to the scripts in the scene.

To fix this I thought about doing a dictionary that tells If I have previously visited a scene, if so, then I can load, else not.

However I think I'm overthinking all this, could you bring me some light?

tawny cave
#

how do you get a public variable from another game object in a script ?

fossil gulch
#

You mean static variables?

#

Look that up

#

See if it’s what you mean

summer stump
#

Reference the instance and get the variable.
Drag and drop reference if you can

fossil gulch
#

Ooooooh thats what they meant

summer stump
#

You could do a static variable, but be very careful, most of the time it's not what you want
That would mean a single instance of the variable, and modifying it anywhere will modify it everywhere

fossil gulch
deep zealot
#

Found this error and am stunted;
"A local or parameter named 'obj' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter"

#

Pls explain

solemn fractal
rich adder
wintry quarry
queen adder
#

Hi there. Got a simple question because im in lack of knowledge. Im rotating an NPC towards another object which works well. I just wonder which value or calculation could be use to check if the rotation towards the target is acually done.

#
float singleStep = 1f * Time.deltaTime;
 newDirection = Vector3.RotateTowards(transform.forward, targetDirection, singleStep, 0.0f);
                    transform.rotation = Quaternion.LookRotation(newDirection);```
tawny cave
#

I actually want variables contained in a script attached to the object

#

but when I try to use target = GameObject.find() and then do target.variable, it doesn't work

summer stump
#

For example, if you drag an object with script Foo on it into:
public Foo foo;
It will reference Foo

If you drag it into
public Transform foo;
It will reference the transform

rich adder
tawny cave
#

the said platform is part of the scene, and the player is a prefab

weary moss
#

if i do:

if(value >= 5)
{
//do something
}
else if(value >= 2)
{
//do something 2
}

let's say the value is > 5, will it only run the If, or will it also run the Else If?

tawny cave
#

cuz I can only drag from the hierarchy with all objects and it's what it does

short hazel
deep zealot
# rich adder which line, show code

public int time_seconds = 5;

public List<spawnWhenCalled> objects;

void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
foreach (spawnWhenCalled obj in objects)
{
obj.Spawn();

    for (int i = 0; i < time_seconds; i++)
    {
      foreach (spawnWhenCalled obj in objects)
      {
        obj.Despawn();
      }
    }
  }
}
deep zealot
rich adder
#

lol thats a lot of loops

rich adder
#

anyway u named 2 local vars obj

#

in the foreach

deep zealot
rich adder
#

whats the point of this cursed code?

summer stump
#

Oh, if the player isn't in the scene at runtime, you need a different reference method. Grab it from wherever you instantiate it

tawny cave
#

well I know I must very dumb but cant figure out the right line for that (this one doesn't create a field in the inspector)

queen adder
deep zealot
# rich adder whats the point of this cursed code?

First create a list of game objects each with a script attached( this is so I can access the script) and then if player collide it will ativate the objects and after a number of time deactivate the objects

queen adder
#

But that if/else statement still does not make sense.

#

You should use If (value >= 2 && value < 5) {} elseif ...

deep zealot
rich adder
#

id only need 1 loop tho šŸ¤”

deep zealot
fierce shuttle
maiden current
queen adder
#

Still got my math question. Nobody got an awnser ? šŸ˜„

queen adder
#

Im rotating an object towards another object using: transform.rotation = Quaternion.LookRotation(newDirection);

which works well. But how can i verify if the rotation is done?

queen adder
#

Like using the angle between the objects rotation and a vector3

rich adder
#

afaik Quaternion overrides equality check

queen adder
#

No, because the the other object got its own rotation which is allways differend.

short hazel
#

Dot product between target direction, and transform.forward can do

#

If it's close to zero 1, then your directions are almost aligned

tawny cave
#

how do you get a vector that's relative to the world instead of a specific object ?

rich adder
#

oh thought == does the dot product for you

rich adder
queen adder
tawny cave
short hazel
#

Vector3.Dot(v1, v2)

keen hinge
#

Hey, I just really wanted to thank y'all for helping me on my project, I hope everyones having a good day :)

queen adder
#

AIght. Thanks. That works.

fierce shuttle
# maiden current Yeah, I'll save it in a JSON. I want to track player's coordinates, npc's intera...

Ah I see, a interface could work, maybe giving each npc, and other data you want to save an "ID" could work as well, then you only need to save the ID and the relevant data to some manager, the manager can then look for the NPC, item, etc with the ID and apply the data, unless you would rather have a different file for each NPC - you could also look into a pattern called "micro services", which could be a way to handle saving and loading without depending on game objects or scenes, and you could subscribe to scene load events to trigger the service, the service itself can keep track of what has or has not been loaded yet as well, if that is relevant - that is, if I am understanding the data your trying to save correctly

spiral oak
#

Hey, Im a bit lost right now. I'm researching about making my own libraries.
If I want to save some scripts I reuse in severa, projects, should I save them in a .dll file? Or what should I do?

summer stump
rich adder
spiral oak
maiden current
spiral oak
summer stump
cosmic dagger
spiral oak
summer stump
spiral oak
#

Well, in case I would make some own packages... I guess I could have a folder with some shared scripts between all packages. Is this a good idea?

chrome storm
#

Hello, i keep getting an error code "error CS1003: Syntax error, ',' expected" but i tried everything and nothing worked

#
    {
        jumpBufferCounter = jumpBufferTime;
    }
    else
    {
        jumpBufferCounter -= Time.deltaTime;
    }   ```
#

i prob forgot something stupid ;-;

chrome storm
#

(40,42)

#

and this script is 40 to 47

rich adder
eternal falconBOT
polar acorn
chrome storm
#

XD

polar acorn
summer stump
#

Does jump even return a bool? Usually it would return void, as it is an action. Poor naming if not

chrome storm
#

trying to fix that rq

polar acorn
chrome storm
tawny cave
#

is this the right method to close the game ? Didn't seem to work for me

tawny cave
#

Ah.

#

hum any way to have one that works in editor ?

rare basin
#

EditorApplication.playmodeStateChanged i guess?

#

note that will work only in the editor and you need pre-procesor directives if oyu want to make a build with it

lofty sequoia
#

EditorApplication.isPlaying ?

tawny cave
#

alright thanks !

tender stag
#

as u can see when the testVisionPosition isnt rotated in any way, the black line reaches the radius which is the white line

#

but when i rotate the testVisionPosition

#

it doesnt reach anymore

#

how would i make it reach?

#

like no matter at what angle it is

#

to just go until it reaches the visionRadius

chrome storm
#

Fixed

#

i got the red line

warped pendant
#

does anyone here use any type of mentor/coaching service for unity development they'd recommend?

eternal falconBOT
#

:teacher: Unity Learn ↗

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

rocky canyon
#

Self taught chest pound

chrome storm
#

alright this is what i got :P

rich adder
summer stump
#

Show the jump function

chrome storm
#

got this error now ;-;

#

Error CS0029 Cannot implicitly convert type 'UnityEngine.Vector2' to 'bool'

queen adder
#

correct vector2 is not a bool, you are using a vector2 where a bool should be

chrome storm
#

ah

abstract finch
#

How would I be able to make an object strafe arounda nother target? Similar to an enemy stalking the player around a perimeter?

abstract finch
#

I'm trying to use it alongside the navmesh pathfinding system

polar acorn
abstract finch
# polar acorn what vector

I would like the vector3 for the next position where they will move. In this case the next position to where they circle around the player. The arrow representing the movement the circle representing the target/player

chrome storm
polar acorn
chrome storm
#

if (rb.velocity = new Bool(horizontal * speed, rb.velocity.y))

polar acorn
chrome storm
#

thats the thing vs is telling me to change

polar acorn
chrome storm
#

isnt it like a thing with 2 values likes (isGrounded && !somethingidk)

polar acorn
#

a boolean is a yes or no

abstract finch
queen adder
polar acorn
#

Does it make sense to set rb.velocity to yes

chrome storm
#

;-;

chrome storm
modest dust
polar acorn
#

So, you're trying to set velocity to the yes-or-no answer of horizontal*speed, neither of which make sense

queen adder
#

a boolean is a type that can be either true or false

modest dust
modest dust
#

Either way, learning C# first will make learning Unity a lot easier

chrome storm
#

i was like im gonna throw myself in unity and learn everything there. XD

#

but yeah learning c# sound easier

queen adder
acoustic arch
#

im new to using raycasting

#

oh wai

#

oh nvm

silk night
#

!code

eternal falconBOT
true pasture
#

im so confused on how dividing 73/100 = 0. I poll them right after each other. what the hell.

meager gust
#

and it also rounds down

#

so 73/100 = 0.73 = 0

true pasture
#

thank you i was so confused

#

how would i fix that

meager gust
#

use floats

true pasture
#

can you divide two integers and get a float in c#?

#

with a special operator?

meager gust
#

try casting them to float first

#

float myFloat = (float)int1 / (float)int2

#

(float)int1 is a temporary cast. It doesn't permanently change int1 to a float

#

int1 is still an int after the operation

true pasture
#

that works for me

#

ty for the help

steep mist
#

i have no idea why i'm getting this or what to do about it

#

someone made a comment about it and i tried what i though the solution was with no improvement

meager gust
summer stump
steep mist
#

the editor says its fine

summer stump
fierce shuttle
summer stump
#

!ide

eternal falconBOT
steep mist
summer stump
meager gust
#

@steep mistWhat is VoxelData ?

#

it looks like you're trying to access a type

#

and not an object instance

summer stump
steep mist
#

all the way back here navarone and boxfriend helped me through that so the IDE config is good

summer stump
teal viper
steep mist
meager gust
#

I suggest you learn the basics of C#

steep mist
steep mist
teal viper
#

Go back to where they write/explain this part of code and follow it through.

steep mist
#

if i still can't i'm gonna do a side by side comparison and try his github code

teal viper
#

Or GitHub link(even better)

summer stump
#

Is VoxelData a static class? (I strongly assume not) Otherwise you just need to get an instance of the class/struct

steep mist
#

JOIN THE DISCORD SERVER!

https://discord.gg/aZgBgC2


This is part two of my tutorial series on coding a game like Minecraft in Unity. I think all the video issues I had in the first part are sorted! In this video we create our first chunk.

Any questions, feel ...

ā–¶ Play video
GitHub

Project files for a Youtube tutorial series on coding a game like Minecraft in Unity. - b3agz/Code-A-Game-Like-Minecraft-In-Unity

steep mist
summer stump
#

Well I see it was haha

teal viper
#
    public static readonly int ChunkWidth = 5;
    public static readonly int ChunkHeight = 15;

Make sure your VoxelData looks like theirs.

summer stump
steep mist
#
public static class VoxelData {

public static readonly int ChunkWidth = 5;
public static readonly int ChunkHeight = 5;
 public static readonly Vector3[] voxelVerts = new Vector3[8] {
teal viper
#

The file is not saved.

steep mist
#

that was the first thing i checked, multiple times even

#

maybe i need to restart unity or regenerate the files incase it "forgot"?

teal viper
#

It's not saved on both screenshots though.

#

In VS

steep mist
#

maybe then i only saved the one?

teal viper
#

Probably šŸ¤·ā€ā™‚ļø

#

Save VoxelData and make sure unity recompiles

steep mist
#

well its working now and i didn't do anything 0-0

#

maybe it was laggin' shrugs

meager gust
#

(consider setting up your IDE properly)

steep mist
#

boyfriend and navedea? helped me

teal viper
#

It does seem configured though. I'd just blame VS code. Use VS if you want a more reliable ide.

steep mist
#

space is the only reason i use VS code

#

regular VS plus all the other crap i got on here takes up precious space to develop and make assets for games

meager gust
#

I don't think it takes up that much space

steep mist
#

a catch 22, have shitty code ide but more space for assets or less space but better code

meager gust
#

when you save your files in regular VS, it sends a callback to unity

#

and updates everything

steep mist
meager gust
#

so you wont have issues like you just had

meager gust
steep mist
#

WOMP WOMP

summer stump
#

I see 804gb free over yonder