#💻┃code-beginner

1 messages · Page 159 of 1

rich adder
#

awesome! glad to hear its working

shell herald
#

idk what im doing wrong, but im getting a positive hit even though there cant possibly be anything between the player position and the posChange transform

https://hastebin.com/share/tahekutabo.csharp

polar acorn
#

Also, why are you using a position as a direction for your raycast?

shell herald
#

because i tried using Vector2.right and Vector2.left and it didnt make a difference so i just tried to do that, which also didnt work

polar acorn
#

Those would make sense, since they're directions

#

A position is not a direction, and treating it as such is going to give you odd behavior

#

Imagine drawing a line from 0,0,0 to the position of poschange, then grabbing that whole line and scooching it so the start point is on top of player. That's what you're checking

#

That doesn't really make a lot of sense

shell herald
#

how would i be able to get a direction between those 2 points then?

ionic zephyr
#

hey guys, I wanna add a cooldown for an attack in my game, should I use delta.Time, a corroutine?? any ideas?

polar acorn
#

Actually that thumbnail is pretty much all you need honestly

languid spire
#

omg a video just to say
direction = target - origin

polar acorn
shell herald
#

i just debug logged the tag of the collider, turns out, the raycast collides with the player its a child of. so i guess instead of "if (hit.collider != null)" i do "if(hit.collider != hit.collider.CompareTag("player") || hit.collider != null )" ?

polar acorn
languid spire
#

best check null first

polar acorn
#

Also that

solemn summit
#

Also probably use a LayerMask so you aren't just hitting yourself

timber tide
#

that's the fun part

eternal falconBOT
keen hill
#

Hi i get this error whenever my character gets close to the item so gets in contact with the collider the boll registeres and the debug message "Player in range" shows correctly but the another message player not in range shows all the time how can i fix it? if you want some more info let me know heres the code: https://gdl.space/getikunicu.cs thirdpersonmovement is my script so it registeres whenever a gameobject with that script collides

trim gulch
#

Hello, I'm quite new and I'm having a bit of a problem. I'm making a Top-down 2D game, however I have this problem where my movement is not constant, and sometimes the character accelerates more or goes slower than it should

polar acorn
languid spire
summer stump
ionic zephyr
#

okay, thanks

polar acorn
keen hill
#

should i compare the tag? maybe

#

so if it collides with something that has the tag only?

#

how can i fix it easly

trim gulch
polar acorn
# keen hill oh so it registers ground for example?

You're looping through all objects the sphere overlaps with, then checking if each of those objects has the ThirdPersonMovement component on it or not. That doesn't seem like what you want to do, so what is it you're actually trying to check for

keen hill
#

im trying to check if the player ONLY is in the radius so then i can enable the item name and image

#

im trying to get it to work so i can advance later

polar acorn
shell herald
#

does a layermask ignore that specific layer or only focus on it? and if its the latter, can i use more than one layermask on a raycasthit2d?

polar acorn
buoyant knot
#

why are you checking
if thing
else if not thing

#

just use if else

keen hill
buoyant knot
static bay
buoyant knot
#

he wants a debug log to know the first if evaluated false

#

either way, this should be handled by OnTriggerEnter

#

also no if statements are actually needed in his code at all

keen hill
#

so i just decided to go the hard way

#

but code it myself

#

to learn stuff

drowsy basin
#

I can't find a way to make it work Why?

polar acorn
short hazel
#

Moving the file somewhere else and back in Unity usually solves it

drowsy basin
polar acorn
buoyant knot
#

what you are doing is probably easily 100x more expensive

keen hill
#

couse it would've been 100x times easier too

#

i could use on trigger exit after

#

to disable the ui

buoyant knot
#

just define OnTriggerEnter

#

and use the argument, which is a collider

ionic zephyr
#

Do you guys know any way to check if an animation has finished? (I want to uncheck the characterMovement while animation is playing)

shell herald
#

updated my code to this. it now detects the hits properly, however the hit.transform.position is not where i d expect it to . instead of setting the position to be right before the collider, it is miles away

hexed granite
#

good evening I need help please I tried to make a script to make movements for a 2d rpg game but I can't correct myself and I would like to know if someone could correct me which is what don't go please

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

public class player : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    { public float moveSpeed;
   
    private bool isMoving;

    private Vector2 input;

    private void Uptade().
    {
        if (!isMoving)
        {
            input.x = Input.GetAxisRaw("Horizontal");
            input.y = Input.GetAxisRaw("vertical");

            if (input != Vector2.zero)
            {
                var targetPos = transform.positition;
                targetPos.x += input.x;
                targetPos.y += input.y;
        StartCoroutine(Move(targetPos));
            }

        }
    }
}

    IEnumerator Move(Vector3 targetPos)
    {
        isMoving = true;

        while (targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
            {
                transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
                yield return null;
            }
        transform.position = targetPos;

        IsMoving = false;
    }
rich adder
#

your method is outside the class

short hazel
#

I see some syntax errors and misspellings

languid spire
rich adder
#

yeah not likely this whole script is riddled with erros

ionic zephyr
summer stump
rich adder
summer stump
#

True, that would probably be as easy

keen hill
#

i understand if not just asking 😉

hexed granite
eternal falconBOT
eternal falconBOT
hexed granite
short hazel
#

Integrated Development Environment
Also called your code editor

hexed granite
#

Sorry🫤

short hazel
#

Which one of these are you using?

rich adder
#

google it and translate

#

Uptade

languid spire
cosmic quail
#

uptade

#

maybe its the same guy

long scarab
#

Hello, a simple question. How to handle closing app by X in either OS? Because I handle saving on exit in custom function on clicking proper exit button...
However when I tried OnApplicationExit handling and it does not manage to save stuff in time before the process/threads ends and therefore ends up in a mess.

hexed granite
long scarab
#

Must've missed than in my google research, thanks

timber tide
long scarab
#

Working on Win/macOS tho? Not just phones?

rich adder
languid spire
rich adder
long scarab
#

yeah well

#

in my googling I found out most people wanted to know this for phones

hexed granite
rich adder
eternal falconBOT
timber tide
#

ah, so you can't prevent ios from preventing terminating your program or something?

polar acorn
#

At no point do these guides have you writing code

timber tide
#

in that case you may want to save concurrently throughout

long scarab
#

Well yeah, I am autosaving automatically, but also wanted to save something on exit

hexed granite
languid spire
polar acorn
hexed granite
#

Sorry i am french i dont good understand

hexed granite
swift crag
#

what program are you using to edit your code?

polar acorn
hexed granite
ionic zephyr
#

sorry, its me again how can I wait until an animation stops to continue my characters movement

polar acorn
ionic zephyr
polar acorn
rich adder
hexed granite
# polar acorn so that is what you click

I looked at it and it tells me how to configure it and how to update it but all of it I have already done where it blocks it is when Try to launch the game on unity

rich adder
# ionic zephyr because is a corroutine necessary

coroutine is still pretty simple to do

Animator anim;
    IEnumerator WaitAnim()
    {
        anim.SetTrigger("Attack");
        //or anim.SetBool("Attacking", true);
        var animPlaying = anim.GetCurrentAnimatorStateInfo(0).IsName("AttackAnimation");
        yield return new WaitWhile(() => animPlaying);
        //do something else after attack
        //anim.SetBool("Attacking", false)
    }```
polar acorn
shell herald
ionic zephyr
languid spire
hexed granite
#

okay

swift crag
polar acorn
swift crag
#

that's a fun x-factor

polar acorn
#

And if it's logging 0, then it's 0

languid spire
shell herald
rich adder
polar acorn
#

Well, if it logs 0, then it's 0

shell herald
#

but i figured it out. i use hit.point.x and it works

polar acorn
#

You should probably put some sort of label in there and see which one is which

hexed granite
languid spire
hexed granite
#

Thanks i see

hexed granite
warm maple
#

Heya, so just curious about Time.deltaTime. In this code piece should i time the staminaDrain with Time.deltaTime?

        {
            playerStamina -= staminaDrain;

            playerStamina = Mathf.Round(playerStamina);

            staminaSlider.value = playerStamina;

            movementSpeed = sprintSpeed;
        }```

My taught process was that the stamina should be framerate independent, but when using Time.deltaTime the stamina doesn't decrease
rocky canyon
#

if a higher framerate is running that code.. their stamina is gonna drop much faster

timber tide
#

lol

polar acorn
languid spire
wintry quarry
timber tide
#

I like to bring up that one of the Dark Souls games tied weapon durability to framerate so those with expensive monitors at the same ran into situations where smacking a sword at a wall instantly broke it,

swift crag
#

staminaDrain is measured in units of stamina per second. Multiply it by deltaTime to figure out how much stamina to subtract in this frame.

warm maple
#

Ah that makes sense yeah, I was already thinking that I should use deltaTime here. Rounding up isn't that necessary I guess?

rocky canyon
#

then the round.. not sure about it

swift crag
#

Why are you rounding?

#

If you want to display a nice whole number, do that when you display the number.

ivory bobcat
#

If anything, you can round before you use the value. Don't round what's stored.

swift crag
#

did you read the warning message

polar acorn
#

What's the IDE say

keen hill
#

sry wrong screen

warm maple
#

I saw a general rule of using deltaTime is whenever you move an object. But from what I've seen and read it's more where you indeed want it to be frame rate independent. So I assume that if you were to shoot a gun you would want to * it with deltaTime too so someone doesn't shoot faster with a better pc, am I correct?

ivory bobcat
wintry quarry
# keen hill

exactly what it says. You are using the wrong method signature. Specifically you have Collider instead of the correct Collision parameter.

rich adder
# keen hill

well did you look at the correct signature then ?
Check the docs for the function

swift crag
rocky canyon
#

look up the correct OnCollisionEnter()

swift crag
#

You should think about it from a units perspective.

keen hill
ivory bobcat
#

Consider "what is the correct signature?"

rocky canyon
#

it doesn't use a "collider"

ivory bobcat
#

Google Unity On Collision Enter

polar acorn
# keen hill

It looks like the Unity message OnCollisionEnter has an incorrect signature

wintry quarry
trail fox
#

im tryna make a gun for a first person game but when i look up and down the gun model just goes further out and if i move my camera to the center its good again is this a feature or am i stupid https://gdl.space/uhipisivus.cpp

timber tide
wintry quarry
keen hill
rich adder
rocky canyon
#

did u even click the link ^ ?

rich adder
#

spoiler alert: no

keen hill
#

yes and im confused the same as i ware earlier

rocky canyon
#

why? theres an example on the page..

#

using the same function..

warm maple
rocky canyon
#

BUT.. with a different ( )

ivory bobcat
rich adder
swift crag
#

which is time-independent

#

let me type something out here...

rocky canyon
#
public class ExampleClass : MonoBehaviour
{
    public Transform explosionPrefab;

    void OnCollisionEnter(Collision collision)
    {
        ContactPoint contact = collision.contacts[0];
        Quaternion rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);
        Vector3 position = contact.point;
        Instantiate(explosionPrefab, position, rotation);
        Destroy(gameObject);
    }
}```

here is the function on the page.. that u said u looked at.
swift crag
#

deltaTime

rich adder
rocky canyon
#

||Colliders are not Collisions||

rich adder
#

but they need to understand why the signature is important

rocky canyon
#

look at ur void method.. and look at the correct one. and see whts different..

#

ya, after they discover Spot the difference then it can be elaborated on

ivory bobcat
# keen hill yes and im confused the same as i ware earlier

As shown by the link, the callback function used by Unity requires a signature with the type Collision as the parameter but your using Collider instead - Collider would be valid for On Trigger Enter but not On Collision Enter where we'd care about a bit more than just the other colliding object.

rich adder
#

especially when unity auto-calls those methods

rocky canyon
#

the signature? isn't it a method as well?

languid spire
#

lol, the way a method is declared is called it's signature

rocky canyon
#

this goes over signatures ^

#

well not really..

#

"The signature is the combination of the methods name and its parameter list"

languid spire
#

and the return type

rocky canyon
#

ahh yes AND the return type..

strange granite
#

can somone help me to start my journey on game dev... what to learn first how to make game egine and after that game development?... i know cpp... what to learn first

rocky canyon
eternal falconBOT
#

:teacher: Unity Learn ↗

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

rocky canyon
#

this java source is telling otherwise

rich adder
keen hill
#

im just getting confused cuz english is my second language

#

and i dont know most words

keen hill
#

when it comes to programming and stuff

swift crag
#

C# includes the return type.

rocky canyon
rich adder
rocky canyon
#

the method u wrote. and why its an error.. u have it trying to return a Collider

ivory bobcat
#

I've found that people become more aware about the terminology "signature" when attempting to overload but assume that the return type is a part of a functions signature - it's not.
If they did not really know the definition of signature before, they'd know it thereafter.

swift crag
#

Methods are declared in a class, struct, or interface by specifying the access level such as public or private, optional modifiers such as abstract or sealed, the return value, the name of the method, and any method parameters. These parts together are the signature of the method.

#

you'll have to take it up with Microsoft if you disagree in the context of C#

rocky canyon
#

some of unity's methods do return a collider.. but not OnCollision

swift crag
ivory bobcat
rocky canyon
#

sorry i was getting confused.. i always think of that as returning a Collision you can then access within the code...

#

but its not. b/c the void is the return type

swift crag
#

it receives a Collision object.

rocky canyon
#

yea, i got it now..

#

yea RECEIVES, like an Out

#

out Hit of a raycast for example

languid spire
#

no

rocky canyon
#

fuck

#

lol

swift crag
#

an out parameter passes a variable by reference to the called function and demands that something be assigned to it.

rocky canyon
#

ohh okay.. hang on im writting some of this down in a notepad doc

rocky canyon
#

ohh okay, so they are Arguments when Calling a function, and the arguments are wats used for the Parameters of the method beign called

swift crag
#

yes

rocky canyon
#

phew..

swift crag
#

arguments are what you actually pass in

#

parameters are what the funciton declares that it wants

rocky canyon
#

yea, okay i think i got those two.

ivory bobcat
#

Passed with arguments
Defined with parameters

swift crag
#

This probably varies from language to language

rocky canyon
#

alright.. so im solid on those.. its the outs, refs, and the receiving part i still need to freshing up on

ivory bobcat
rocky canyon
#

i get the receiving part like this functions brings in this variable to use within the body..

languid spire
#

and dont get started on params

rocky canyon
#

i can just work around that.. but refs and outs. always kinda confuse me still

swift crag
#

ref is the most general form. It allows you to share a variable with the function.

#

in is like ref but is read-only, and out is like ref but write-only

#

(and also demands assignment)

sage mirage
#

@rich adder Thanks for giving again the idea of Game States I was able to fix my problem and handle game flow properly. It is just like I see more organised way to handle game states rather than having bools everywhere and when something strange occurs to not know what you have to change in your bool values.

rocky canyon
#

ohh okay.. so i guess ref is shorthand for reference

swift crag
#

There are some other intricacies. For example, in allows you to pass non-lvalues (things you can't assign to, like a literal number)

#

hence ref readonly showing up in C#12

rocky canyon
#

i doubt ill need that anytime soon 😅

swift crag
#

yes. it shows up a lot in ECS code

#

it's useful if you need to share a large value type with a function

#

but you don't want it to be allowed to mutate the value type

buoyant knot
#

but aren’t value types not modified when going into a function, without a ref keyword?

swift crag
#

You want to share, like with ref

#

But you don't want any modification to happen

rich adder
rocky canyon
#

what function am i familiar with that uses ref.. Isn't there a MoveTowards or some lerp type function that uses ref

rocky canyon
#

i wanna practice with some of these

swift crag
#

It needs to be able to update the velocity argument.

rocky canyon
swift crag
#

that uses out

rocky canyon
#

imma practice these today..

rich adder
#

wait there was another one

rocky canyon
#

just realized how bad i am at them

swift crag
#

ref is used when the function must be able to read from and write to the reference

buoyant knot
#

would the compiler just know to effectively do the same thing as “in” if it already applies?

ivory bobcat
swift crag
rocky canyon
#

IDE's are pretty good at that already arent they/

buoyant knot
#

i guess it would make a difference with threads, right?

rocky canyon
#

hence why i get the "Never used" grey variables

swift crag
ivory bobcat
#

If you're writing code for others where you don't know what they'll be doing with it, you'll want to consider placing the correct constraints - it's no different from making everything public.

rocky canyon
#

could be a big ole refactor for sure

languid spire
rocky canyon
#

lol.. looks around curiously

#

id have ALOT of work going from solo to a team

#

thats all i know

#

unless i was the Team Lead! "Do as I do!"

swift crag
#

(:

languid spire
#

Solo dev -> Team lead. A marriage made in hell

ivory bobcat
#

If you're just writing for yourself, it's probably fine as long as nobody has to read it (or maintain it in the future) - it's not good practice though (my ocd kicks up)

scarlet hull
#

why there isnt SetSelectedTower(int) in buttons funtions?

rocky canyon
#

ya, im not gonna pretend im the best coder.. but i try to keep it as legible as possible

#

its a private function

#

its not gonna show on that list

scarlet hull
#

alright

edgy prism
#

Would anyone mind giving me some advice on animations currently calling an idle animation I want to be doing any time I'm not playing another like this:

void Update()
    {
        if(playerUnit.IsPlayingAttack == false && playerUnit.IsPlayingIdle == false)
        {
            StartCoroutine(playerUnit.PlayIdleAnimation());
        }
    }

The problem is as soon as I call my other animations im not actually stopping the idle animation and they're both trying to set sprites at the same time is there a way I can easily manage this?

public IEnumerator PlayIdleAnimation()
    {
        isPlayingIdle = true;

        float frameDuration = 0.0417f;

        foreach (Sprite sprite in Capta.Base.IdleSprites)
        {
            image.sprite = sprite;
            yield return new WaitForSeconds(frameDuration);
        }

        isPlayingIdle = false;
    }

This is the current idle function

rocky canyon
#

why are you not using the animation state machine w/ transitions?

#

couldnt u set those on a bool.. (bool true -> idle) (bool false -> transition to other)

edgy prism
rocky canyon
#

yes

edgy prism
rocky canyon
#

until now.. now its easier to toggle a boolean

#

lol

shell sorrel
#

if hard coding it would not use coroutines since its a continious thing

#

like starting coroutines from a update is kinda weird

edgy prism
swift crag
#

Sounds like you should store the current coroutine

#

you can add a Coroutine field and store the return value from StartCoroutine into it

rocky canyon
#

its always a good time to learn.. but yea theres code alterations u can do ^ also

swift crag
#

You can then pass it to StopCoroutine to cancel the existing coroutine

shell sorrel
#

or use Update for it, count time, and keep track of the current frame index

swift crag
#

I'd add a method whose job is to look for an existing coroutine, kill it, start a new coroutine, and save the resulting Coroutine

#

call it PlayAnimation

edgy prism
#

Am I better off carrying on as I am than using animator?

#

Your idea sounds like a fix Fen

rocky canyon
#

it would be simpler to use the animator in the long run.. esp if u have add any more states/animations (imo)

#

but i aint gonna say if its better 1 way or the other..

edgy prism
rocky canyon
#

yea but you can set parameters

#

and change those.. the animator just takes over

#

and does the transitions and stuff on its own

#

u basically just let teh animator animate.. and u tell it what data to use to figure out how to animate

shell sorrel
# rocky canyon

could always just pull from Any State instead of needing every combo of transitions

hexed granite
#

I need help with a step it tells me to the Common7/IDE directory then select become.exe where is it? @languid spire

rocky canyon
#

like isWalking = false; or speed = 1.4f;

#

or w/e

rocky canyon
#

i havent done one with the anystate node yet

fluid remnant
#

What is the minimal approach to Serializing dictionary in the inspector ?
I'd like not to use any plugins like Odin

rocky canyon
#

i should do that too

shell sorrel
fluid remnant
hexed granite
fluid remnant
edgy prism
rocky canyon
fluid remnant
rocky canyon
#

thisAnimator.parameter =
thatAnimator.parameter =

#

or even a list of animators

languid spire
edgy prism
rocky canyon
#

just look into it

rocky canyon
#

see if its something u may wanna start using..

#

or if ur method is better..

edgy prism
languid spire
#

'yes

rocky canyon
#

well say u just have 2 animations.. walk and idle.. instead of stopping the walk and starting the idle
you could just set 1 boolean for example.. isWalking = false;

hexed granite
#

Okay

rocky canyon
#

even with small states it can still be an improvement

hexed granite
rocky canyon
#

😦

hexed granite
#

WHY?

rocky canyon
#

b/c VSCODE ahem

#

nah im kidden.. lol

ivory bobcat
#

Haven't we been seeing this code all day?

rocky canyon
#

hes trying to get his editor fixed at this point i assume

languid spire
#

yep, still no configured IDE

edgy prism
rocky canyon
#

and he speaks French

hexed granite
#

Sorry 😭

rocky canyon
#

lmao, dont apologize for ur nationallity 👀

edgy prism
hexed granite
ivory bobcat
#

It's required to get help here

rocky canyon
#

VSCode is always more difficult to get set up than VSCommunity

languid spire
#

he said he was using VS not VSCode

hexed granite
#

why is it so hard in the tutorial it's simple

rocky canyon
#

ohh than not sure why? VSCommunity is usually really easy to set up

languid spire
#

screenshot Unity Preferences->External tools

languid spire
rocky canyon
#

Visual Guide ^

#

see if that helps u understand what u missed

hexed granite
#

I'm not much away from abandoning everything even though I've already done everything

rocky canyon
#

not the attitude that will garner much help tbh

ivory bobcat
#

What step were you on?

#

Oh step two (I can't read French)

rocky canyon
#

Step 1 Uninstall Visual Studio
Step 2. Reinstall Through the Unity Hub

#

most straight forward way I've seen it done..

ivory bobcat
hexed granite
#

in the video what he shows at 1 minute I don't

hexed granite
rocky canyon
#

so this?

#

that means that the Unity Package isnt installed in VS

gaunt harbor
#

I need your ideas.

I need to find a method, I have a point/crosshair in the center of the canvas, I want to detect when the point is aimed at an enemy/block/etc.

rocky canyon
gaunt harbor
rocky canyon
#

you need to install the Unity Game Development Kit, after that you can restart and u should be able to select in as Unity as your IDE in the Project Settings > External Tools

ivory bobcat
rocky canyon
#

Yea, everyones actually just trying to help.. B/c once you have it set up It will help you a lot

scarlet hull
#

i accedentally deleted the original layer

#

how do i fix this

rocky canyon
#

ctrl + Z to undo

scarlet hull
#

i tried it but

#

its not going back

rocky canyon
#

may have to remake it then

ivory bobcat
#

Can you show the console window?

rocky canyon
#

you only have (1) clip so far.. shouldnt be too hard to remake it

#

but ive never seen that error

ivory bobcat
#

This looks like a runtime error and not the something that you're showing us.

scarlet hull
rocky canyon
#
You have an Animator component that is being referenced.
At some point, you are destroying the Animator component.
Any scripts trying to reference the Animator component no longer can, because it has been destroyed.
An error occurs.
You need to prevent the Animator component from being destroyed.```
#

unity forums thinks it may be that ur destroying an animator

ivory bobcat
#

If you double click the error, does it take you anywhere?

rocky canyon
#

but yea im on the fence.. if it were me i'd save what i got and restart

#

if its still there.. then id look into it a bit more

#

unless u know that ur destroying an animator somewhere and not telling us about it

#

this doesnt look like a "Controller"

#

it looks like u put an animation Clip

#

where an animator is supposed to go

scarlet hull
rocky canyon
#

read my last post ^

#

oh wait

#

thats not it.. just testing and that is what it looks like if u Animated a GameObject

#

@scarlet hull ^ yea ignore that last post.. i thought they may be it but it looks the same on my project

scarlet hull
#

alr

rocky canyon
rocky canyon
#

besides the one on "GameObject"

scarlet hull
#

i have 2 on it

rocky canyon
#

ohhh

scarlet hull
ivory bobcat
#

I'm guessing that the object was destroyed but they're still trying to access it

rocky canyon
#

you have 2 "Animators" ?

#

on (one) object?

ivory bobcat
#

(code is likely necessary to solve this issue)

cinder lynx
#

Hi guys!! Quick question! I was following a Code Monkey tutorial when I got stuck into an error that probably the solutions is right in front of me. Basically I was implementing the asset "Input Actions" manually like he does on the video, then my C# code does not recognize the class "PlayerInputActions" could you help me? The video is Learn Unity Beginner/Intermediate 2023 (FREE COMPLETE Course - Unity Tutorial) - Code Monkey || Time of the video: 10:45:00

MY GAMEINPUT CODE:

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class GameInput : MonoBehaviour
{
    
    private PlayerInputActions playerInputActions
    private void Awake()
    {
        playerInputActions = new PlayerInputActions();

        playerInputActions.Player.Enable();
    }
    public Vector2 GetMovementVectorNormalized()
    {
        Vector2 inputVector = new Vector2(0,0); 
        if(Input.GetKey(KeyCode.W))
        {
            
            inputVector.y = +1;
            
        }

        if(Input.GetKey(KeyCode.S))
        {
            inputVector.y = -1;
        }
        
        if(Input.GetKey(KeyCode.A))
        {
            inputVector.x = -1;
        }

        if(Input.GetKey(KeyCode.D))
        {
            inputVector.x = +1;
        }

        inputVector = inputVector.normalized;
        
        return inputVector;
    }

}
 
rocky canyon
#

yea, im lost

rocky canyon
wintry quarry
#

Make sure you used the same name for your input asset

#

and that you have it generating the C# class

#

(and that you set it up in the first place)

scarlet hull
warm condor
#

Hey, I have this jumpSliding method that, well will allow th player to jump slide. The problem I have is that one of the if statments (the very first if statment), is being called repeatatly and then stopes, wehn it is only supposed to be called once and wait till it does it again. Here is the code:

        if (allowJumpSliding && Input.GetKey(KeyCode.S)){
            Debug.Log("dasdsadsadsa");
            rb.velocityX += direction * horizontalSpeedToJumpSlide;
            slide(direction);
        }
        else if (bottomCollider.IsTouchingLayers() == true && Input.GetKey(KeyCode.S) && Math.Abs(rb.velocityY) > verticleSpeedLimitToAllowJumpSlide && allowJumpSliding == false){
            allowJumpSliding = true;
            Invoke("setJumpSlidingToFalse", jumpSlidingTimeLimitValue);
        }```
How do I fix this issue?
rocky canyon
#

If you mean to change out the animator, then you need to reassign it when the one it references is destroyed.```
scarlet hull
rocky canyon
#

the other error on the forums seems to think that one gets destroyed. but the reference is still there..

scarlet hull
#

i accedentally

ivory bobcat
rocky canyon
#

so its causing an error

scarlet hull
#

deleted

#

base layer

#

and created a new one

wintry quarry
rocky canyon
#

delete the animator u broke

#

and remake it

cinder lynx
ivory bobcat
#

If you've skipped some steps, it'll not work.

scarlet hull
#

lemme ttry

cinder lynx
wintry quarry
#

and the settings of it in the inspector

#

you cut off too much in this screenshot

rocky canyon
rocky canyon
#

i need to know what u did to fix it 😄

cinder lynx
#

Sorry

ivory bobcat
wintry quarry
#

so what error are you getting?
And where did you put your code?

rocky canyon
#

i think they somehow deleted the base layer of an animator.. by having a 2nd animator?

#

thats what he said caused the error.. and i can't seem to delete mine.. i get a catch

#

maybe his editor didn't stop him?

cinder lynx
# wintry quarry looks fine

"The type or namespace name 'PlayerInputActions' could not be found (are you missing a using directive or an assembly reference?)",

ivory bobcat
wintry quarry
rocky canyon
hexed granite
rocky canyon
#

guess we'll never know.. like a tootsie pop

cinder lynx
#

Player gameobj

warm condor
wintry quarry
# cinder lynx

not where did you attach it. I mean where is the script itself?

#

What folder is it in?

#

Also I thought it was the GameInput script

#

not the Player script

wintry quarry
#

where is the GameInput script file itself?

wintry quarry
rocky canyon
#

if u only want the if statement to run once.. ur gonna have to probably set a flag

wintry quarry
hexed granite
rocky canyon
#

or yea GetKeyDown (registers on just the frame its pushed)

#

so swapping that out may be sufficient

cinder lynx
#

Idk whitch one do you want

wintry quarry
#

not with Unity/the code itself

#

regenerate project files I guess?

cinder lynx
wintry quarry
warm condor
rocky canyon
wintry quarry
rocky canyon
#

it just means like a boolean or something.. like

if(running && canRun)
//do ur stuff
canRun = false;}

cinder lynx
#

XD

rocky canyon
#

so at teh end of the first loop thru u set a boolean to say.. dont try again

cinder lynx
#

lmao

#

I just had to put vscode there again

#

idk why it's always putting vs2022 insted of vscode

#

Thanks

rocky canyon
#

^ yea its easy.. lol i really feel bad when someone can't get theirs set correctly..

rocky canyon
cinder lynx
#

idk

#

thanks again

rocky canyon
#

Praetor is the real MVP

faint osprey
#

List<List<int>> roomMatrix =
{
{0, 0, 0},
{0, 0, 0},
{0, 0, 0}
};
why is visual studio not liking this

rocky canyon
#

u trying to make recursive lists?

#

never done that.. not sure the gameplan here

faint osprey
#

im trying to make a list of a list of ints

rocky canyon
#

yea 😄 someone smarter has to chime in

brave compass
ivory bobcat
#

Nevermind

short perch
#

OnTriggerEnter doesn't work for me

#

is the thing itself supposed to be set to is trigger?

short perch
#

or is the thing it's colliding with supposed to be set to is trigger?

rich adder
#

well the function name is OnTrigger

#

what do you think

polar acorn
short perch
void dawn
#

system.badimageformatexception:format not executable (.exe) or library (.dll) is invalid

#

How do I fix

hexed terrace
#

this is a code channel, that's not code related (also... just google that exact error)

polar acorn
#

Context?

hexed terrace
keen hill
#

what type of a raycast should i do when doing third person pickup system i was thinking about a beam but thicker

#

so like a normal raycast but thicker

#

should i use a square cast?

hexed terrace
#

You mean box cast?

Why not just do a ray cast?

keen hill
#

cuz the way my cinemachine camera works

#

it would make it very awkward to have a small ray

#

right now im testing it

#

and thats how im casting my ray

cosmic dagger
keen hill
#

okay thanks 🙂

hexed terrace
#

The image doesn't really show why a raycast wouldn't work, but its neither here nor there.. use ☝️

rocky canyon
#
        dragging = Input.GetMouseButton(0);
        objectToTrackMousePosition.SetActive(dragging);
        float dist = Mathf.Infinity;

        //update mouse position
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if(Physics.Raycast(ray,out hit,dist))
        {
            lastMousePosition = hit.point;
        }
 
        objectToTrackMousePosition.transform.position = lastMousePosition;``` nice and simple so far
#

now, every x amount of distance (i was debating on distance vs time) it'll drop a waypoint on the position.. then i'll draw the shape

#

i need to make some states now, i have a camera script that moves the camera around when i click and drag. or maybe a simple bool will do it

#

if a unit is selected i'll just disable the camera script

buoyant knot
#

@timber tide for some reason, my OnBeforeSerialize gets called whenever I enter play mode. 😦

timber tide
#

Ah shoot does it :(

#

I wonder why

buoyant knot
#

idk

#

I just want a method to be called when I'm done making edits in inspector

#

and I can't make a custom editor script for this without screwing up the ruletile editor

timber tide
#

Maybe make your own method that finds all method implementations of InspectorDebug()

real merlin
#

hello so i'm getting nullreferenceexception on line 22 (second image) and i do not know what that means or how to fix it can anyone help ?

timber tide
#

and make big button that you press

rocky canyon
#

means ur trying to do something with something that isnt assigned..

#

it knows theres a spellmanager.. but its not assigned.. its null

real merlin
#

what does assigning it mean

#

oh wait

rocky canyon
#

it means telling it what instance of that script

#

that ur using

#

and also.. dont use the exact same name as the name of the class

real merlin
#

i miss-drag-and-dropped the script

#

in the serializefield

real merlin
rocky canyon
#

its gonna get confused if the name and the type are the same name.. as u have spellmanager forboth

#

well the type has to be exactly the same as the file name..

#

change the name.. not the type.

#

spellmanager mySpellManager;

#

mySpellManager.cast()

real merlin
#

alright i'll try it

#

thank you very much

buoyant knot
#

actually, I forgot I already have a custom editor lmao

olive lintel
#

hey guys, I have a question in regards to network RPCs. I've tried to RPC an array of different "gun shot info" structs, however I have received the error message shown below. Is the only way to RPC this information by using a series of individual RPCs for each gun shot info in sequence? many thanks.

real merlin
#

i need a way to reference my class inside a function that is inside that class, i tried using the code in the image bellow but unity doesn't like it

rocky canyon
#

this <-- would be the instance of the class within that class.. wouldnt it?

real merlin
#

yeah..

rocky canyon
#

unless u need a new version of it

#

either way, the IDE doesn't yell at me. maybe u shouldn't use a var b/c u already know its a spellmanager

#

spellmanager s = new spellmanager();

real merlin
#

i did not know the this thing existed

real merlin
#

thank you again !

rocky canyon
#

yea, this, this.transform etc

#

just means this exact copy

real merlin
#

i can't use it inside a static function tho

rocky canyon
#

ya, b/c a static function can only exist once..

real merlin
#

what does that mean ?

rocky canyon
#

if its a static function inside of that class.. and u try to make a (new) one.. you now have (2) static functions ** of the same function **

#

which u cant do

real merlin
faint osprey
#
        for(int i = 0; i < roomCount; i++)
        {
            horizontalChoice = Random.Range(0, 2);
            verticalChoice = Random.Range(0, 2);
            if (i > 0)
            {
                while(horizontalChoice != leftCheck || horizontalChoice != rightCheck)
                {
                    horizontalChoice = Random.Range(0, 2);
                }

                while (verticalChoice != upCheck || verticalChoice != downCheck)
                {
                    verticalChoice = Random.Range(0, 2);
                }
            }
            upCheck = verticalChoice - 1;
            downCheck = verticalChoice + 1;
            leftCheck = horizontalChoice - 1;
            rightCheck = horizontalChoice + 1;
            roomMatrix[verticalChoice][horizontalChoice] = 1;
        }``` i dont understand how this is giving me an infinite loop
polar acorn
faint osprey
#

integers

polar acorn
faint osprey
polar acorn
faint osprey
#

yeah

#

but it wouldnt go on infinitly

polar acorn
#

Then I don't know how you think this could end:

while(horizontalChoice != leftCheck || horizontalChoice != rightCheck)
                {
                    horizontalChoice = Random.Range(0, 2);
                }
#

If it's not equal to left check OR its not equal to right check, you loop

#

If left check and right check are different numbers, it is impossible to be equal to both to get out of this loop

faint osprey
#

yeah and each time im changing its values which could make it the same as left or right

faint osprey
polar acorn
faint osprey
#

oh wait

polar acorn
faint osprey
#

no it does need to be and

polar acorn
#

If horizontalChoice randoms into 1

faint osprey
#

i was getting them mixed up

polar acorn
#

it is no longer equal to left check so it loops

shy rain
#

Hello , ive wanted to ask how can i make a transition from a 3D-scene to a 2D-scene?
I'm mainly asking because ive had an idea that upon interacting with an Object/NPC , it would trigger an transition from the 3D-Space to 2D-Space to play an An Animated interaction with the object/converstation with the NPC.

#

this is short visualization of the transition in my mind

buoyant knot
#

look at mario

#

Paper Mario and Mario Odyssey both did that

#

in terms of physics, that is going to be rough, because 2D and 3D physics systems are totally different

shy rain
#

oh nuts

#

i am aswell an absolute begginer , i got into unity since last week or so
i just thought making something like this would be fun but no idea where i could start so ee

timber tide
#

whats happening here

#

just ripping a mesh in half?

rich adder
#

the original scene becomes still image and rips to reveal 2d game?

timber tide
#

oh yeah I remember that

#

it makes it into a texture probably then renders on a quad

shy rain
rich adder
#

I would start getting the 2 scenes working first then worry about the transition effect later

timber tide
#

there is like a transition in a split frame where you do notice of it happening

shy rain
polar acorn
# shy rain this is short visualization of the transition in my mind

You could have the camera output to a render texture, put that texture on a Quad that has this tearing-in-half animation, and behind it have your new scene. When you need to change scenes, you have the active camera take a snapshot and then additively load the 2D scene, drop in the animated ripping quad, and then quietly unload the original scene. Actually a pretty involved system, but it'll make for a cool effect.

Things to learn:

  • How to output a camera to a render texture
  • Spawning an object with the render texture as it's material's main map
  • Asynchronous scene loading, including having a "transition scene" (that is normally used for a loading screen)
#

But definitely work on getting the scenes on either end working first before you make the transition effect. It won't do much good unless there's stuff to load on either end

shy rain
#

alrighty!

shy rain
#

and i bet it would be an easier time

#

and even better i could mix both 3d and 2d objects withing the same space giving me more stuff to mess around

faint osprey
#

ive been trying to wrestle with this for a while so any thoughts on the matter would be appreciated i know its probably not the best method of going about it but i wanna try and finish it``` public List<List<int>> roomMatrix = new List<List<int>>
{
new List<int> {-1, -1, -1},
new List<int> {-1, -1, -1},
new List<int> {-1, -1, -1}
};

public List<List<bool>> roomsVisited = new List<List<bool>>
{
    new List<bool> {false, false, false},
    new List<bool> {false, false, false},
    new List<bool> {false, false, false}
};

// Start is called before the first frame update
void Start()
{
    roomCount = Random.Range(3, 6);
    for(int i = 0; i < roomCount; i++)
    {
        horizontalChoice = Random.Range(0, 2);
        verticalChoice = Random.Range(0, 2);
        if (i > 0)
        {
            while (roomsVisited[verticalChoice][horizontalChoice] == true)
            {
                while (horizontalChoice != leftCheck && horizontalChoice != rightCheck)
                {
                    horizontalChoice = Random.Range(0, 2);
                }

                while (verticalChoice != upCheck && verticalChoice != downCheck)
                {
                    verticalChoice = Random.Range(0, 2);
                }
            }
        }
        upCheck = verticalChoice - 1;
        downCheck = verticalChoice + 1;
        leftCheck = horizontalChoice - 1;
        rightCheck = horizontalChoice + 1;
        roomsVisited[verticalChoice][horizontalChoice] = false;
        roomMatrix[verticalChoice][horizontalChoice] = i;
    }``` im trying to make a loop that will choose a starting point in my list of lists of ints and lable that 0 then choose an adjacent point (either above or below or left and right) then lable that 1 and so on until i reach the required amount without going back on myself
polar acorn
faint osprey
faint osprey
#

there not assigned at start

polar acorn
#

So they're all 0

#

meaning the loops can never end

faint osprey
#

well no cause they get updated before the loops even happen

polar acorn
#

Oh, there's an i > 0 check there

#

So, let's think this through. They're at 0 to start. Let's just focus on horizontalChoice and leftCheck and rightCheck

faint osprey
#

right ok

polar acorn
#

If horizontalChoice randoms into 0, then leftCheck becomes -1 and rightCheck becomes 1.
If horizontalChoice randoms into 1, then leftCheck becomes 0 and rightCheck becomes 2.

#

Actually, hang on, are you still getting an infinite loop or is your issue that it's not doing anything

#

because that outer while loop should never run. At no point are you ever setting any value in roomsVisited to true

faint osprey
#

roomsVisited[verticalChoice][horizontalChoice] = false; omg im setting it to false

#

ugh

#

ok so now it sometimes works perfectly

#

and sometimes goes into an infinite loop

polar acorn
#

You have a situation where you have no possible choices that result in a roomsVisited of false

stable lagoon
#

how do I fix this?

polar acorn
#

Try reinstalling the package

polar acorn
# faint osprey wdym sorry?

You have hit a situation where roomsVisited[0][0], [0][1], [1][0], and [1][1] are true and those are the only possible values you can get

#

so it's always true

small helm
#

Hi guys, I have two scenes loaded at the same time with LoadSceneMode.Additive, each scene has a camera in it but i want each camera to only see the things in its respective scene, right now everything is visible at the same time to all cameras. How can I fix this? I am very new to unity

stable lagoon
faint osprey
polar acorn
#

horizontalChoice and verticalChoice can literally only be 0 or 1

faint osprey
#

no 0, 1 or 2

polar acorn
#

Those are the only possible values they can be

faint osprey
#

how

polar acorn
#

Because int Random.Range is max eclusive

faint osprey
#

ohhh right

polar acorn
faint osprey
#

so i need to change them all to 3 then

small helm
#

am I allowed to ask my question in more than one channel if it's an appropriate channel

faint osprey
#

its still running infinitely tho

polar acorn
#

you are in a position where all possible values for your roomsVisited are true

faint osprey
#

so its not infinite looping now

#

however on odd occurances the path is not adjacent tiles

#

i think the issue is

#

is that technically say my starting point is [1][1]

#

that means vertically [0] is valid and horizontally [2] is valid making the next point [0][2] which is not adjacent

#

but i wouldnt know how to fix that

timber tide
#

What are some ideas to keep a large script with numerous members clean from your header space? I've been just cramming them all into structs even though I'm not exactly passing them anywhere. A lot of my methods act directly on the member variables without parameters for the sake of simplicity. Only problem I dislike is it does create more line space as I've gotta use another dot operation to access it all.

#

As much as I may dislike setting up header files, it does keep your scripts pretty shiny

shell sorrel
#

what do you mean by header files?

#

like its not C

#

if you are just talking about all your fields and stuff and keeping it organized

#

i tend to try to not have 1 class handle too many different things, and when i need it to i will just keep fields used by sets of methods close to those methods and use regions to group

buoyant knot
#

@timber tide I solved it. I just made a custom editor, where I only defined an override for OnInspectorGUI, to call a public method. It still calls way too many times, but at least it only calls when I’m editing it.

young anvil
#

would anyone be willing to kind of "teach me unity" and how to get started with c# for unity on a 1 on 1? i have slight knowledge of c++ if that helps any

timber tide
shell sorrel
#

Also nothing wrong with just using composition, can just have a few other objects in your thing for handle different features of it

#

If lines start getting long a few getter props can handle that

buoyant knot
small helm
#

What do these above the cameras mean

rich adder
small helm
#

why does one of the cameras not have a small icon above it

timber tide
#

I cache all my values

#

when you think of modifiers from like hundreds of items, it's hard to just get item stats each time you do like an attack

queen adder
#

Im quite doing that, just updating parameters at certain times

#

but im quite doing the hardcoded for everything

#

like if i got a double damage buff, i update recalculate the strength fully

timber tide
#
namespace Stats
{
    public enum StatValueType
    {
        Flat = 0,
        PercentAccumulate = 100,
        PercentMulti = 200,
    }

    [Serializable]
    public abstract class StatValue<T> where T : Enum
    {

        public StatValue(T statType, StatValueType valueModType, float value)
        {
            StatType = statType;
            StatValueType = valueModType;
            Value = value;
        }

        [field: SerializeField] public T StatType { get; private set; }
        [field: SerializeField] public StatValueType StatValueType { get; private set; }
        [field: SerializeField] public float Value { get; private set; }
    }
}```
I stick to mostly a flat, percent accumlative, and multi for the majority of formulations
queen adder
#

that's neat

#

so like it's smart to autodecide how it handle the stat update

#

rather than you manually handling how you plug in the extra buff you add

timber tide
#

mods are like blocks where you shove one in and recalculate on one specific method

ivory bobcat
#

Well, you'd normally have:

  • some base value
  • some stacking multipliers
  • some non-stacking multipliers
  • some constants
    etc
queen adder
#

i love the fact that a lot of rpg did this very nicely

shell sorrel
#

i tended to just implement buffs and debuffs as just a stack of objects, that all have various methods for the stats they effect that each accept and return a value to modify

ivory bobcat
#

Yeah, just loop through them and evaluate then later combine - possibly many different stacks as well.

timber tide
#

buffs have been tricky to implement because snapshotting stat references is a pain (think of abilities still lingering on the scene)

#

I'm not sure how I want to handle that

mental grail
#

im having trouble making my bullet damage the player because when i hit the enemy it takes damage but when i get rid of all its helth there in an error Destroying assets is not permitted to avoid data loss. If you really want to remove an asset use DestroyImmediate (theObject, true); UnityEngine.Object:Destroy (UnityEngine.Object) Enemy:TakeDamage (int) (at Assets/Scripts/Enemy.cs:19) Bullet:OnTriggerEnter2D (UnityEngine.Collider2D) (at Assets/Scripts/Bullet.cs:20)

#

and also even though i have in my start function health = 100 it doesnt update and i just has negitive health

ivory bobcat
#

Likely you're referencing an asset instead of an instance in the scene.

rich adder
queen adder
mental grail
rich adder
# mental grail yes

well something like this basically is wrong

 public GameObject myPrefab;
    void Method()
    {
        Destroy(myPrefab);
    }```
queen adder
#

but now im just trying to redo my main parameter handling

rich adder
#

you have to destroy the copy

#

use instantiate

mental grail
ivory bobcat
#

Likely your referenced enemy was the prefab and not the enemy in the scene

rich adder
ivory bobcat
#

Also, this would imply you've only got one.

#

The error occurred because you told the prefab to go destroy itself.

mental grail
mental grail
ivory bobcat
#

Because the referenced enemy was a prefab

mental grail
#

i see my mistake lol

faint osprey
#

i dont understand how i can get an infinite loop sometimes but then it work normally other times

#
    {
        new List<int> {-1, -1, -1},
        new List<int> {-1, -1, -1},
        new List<int> {-1, -1, -1}
    };

    public List<List<bool>> roomsVisited = new List<List<bool>>
    {
        new List<bool> {false, false, false},
        new List<bool> {false, false, false},
        new List<bool> {false, false, false}
    };

    public List<List<bool>> roomsValid = new List<List<bool>>
    {
        new List<bool> {false, false, false},
        new List<bool> {false, false, false},
        new List<bool> {false, false, false}
    };

    // Start is called before the first frame update```
#
    {
        roomCount = Random.Range(3, 7);
        for(int i = 0; i < roomCount; i++)
        {
            horizontalChoice = Random.Range(0, 3);
            verticalChoice = Random.Range(0, 3);
            if (i > 0)
            {
                while (true)
                {
                    if (roomsValid[verticalChoice][horizontalChoice] == true && roomsVisited[verticalChoice][horizontalChoice] == false)
                    {
                        break;
                    }
                    else
                    {
                        horizontalChoice = Random.Range(0, 3);
                        verticalChoice = Random.Range(0, 3);
                    }
                }
            }

            upCheck = verticalChoice - 1;
            downCheck = verticalChoice + 1;
            leftCheck = horizontalChoice - 1;
            rightCheck = horizontalChoice + 1;

            for(int a = 0; a < 3; a++)
            {
                for (int b = 0; b < 3; b++)
                {
                    roomsValid[a][b] = false;
                }
            }

            if (upCheck > -1)
            {
                roomsValid[upCheck][horizontalChoice] = true;
            }
            else if (downCheck < 3)
            {
                roomsValid[downCheck][horizontalChoice] = true;
            }
            else if (leftCheck > -1)
            {
                roomsValid[verticalChoice][leftCheck] = true;
            }
            else if (rightCheck < 3)
            {
                roomsValid[verticalChoice][rightCheck] = true;
            }

            roomsVisited[verticalChoice][horizontalChoice] = true;
            roomMatrix[verticalChoice][horizontalChoice] = i;
        }```
teal viper
faint osprey
#

so idk what to do

teal viper
#

It looks like the pause button and should be on your toolbar at the top.

faint osprey
#
                {
                    if (roomsValid[verticalChoice][horizontalChoice] == true && roomsVisited[verticalChoice][horizontalChoice] == false)
                    {
                        break;
                    }
                    else
                    {
                        horizontalChoice = Random.Range(0, 3);
                        verticalChoice = Random.Range(0, 3);
                    }
                }``` its cause its not getting to the break inside the if
#

but idk why it should

teal viper
#

roomsValid is always true or roomsVisited is always false. Check the values of the vertical and horizontal choice and the elements inside these arrays. It's really a simple thing to debug.

ivory bobcat
#

Combinations can repeat so this could take a while stepping through the code 🥹

gaunt ice
#

Prove that there are always valid choices after i > 0

ivory bobcat
#

Just to eventually determine that none were valid and not visited

faint osprey
#

its the adjacent tiles

ivory bobcat
#

I'm assuming this is a grid maze generation where there are corner cases with valid rooms that have been previously visited though.

faint osprey
ivory bobcat
#

So how many times should it try if there are no more valid/non-visited rooms?

teal viper
faint osprey
teal viper
ivory bobcat
#

Unless you've got something prior that escapes if no neighbors are valid/un-visited

faint osprey
teal viper
faint osprey
# teal viper Then you need to investigate the place where you expect them to be set to valid.
            downCheck = verticalChoice + 1;
            leftCheck = horizontalChoice - 1;
            rightCheck = horizontalChoice + 1;

            for(int a = 0; a < 3; a++)
            {
                for (int b = 0; b < 3; b++)
                {
                    roomsValid[a][b] = false;
                }
            }

            if (upCheck > -1)
            {
                roomsValid[upCheck][horizontalChoice] = true;
            }
            else if (downCheck < 3)
            {
                roomsValid[downCheck][horizontalChoice] = true;
            }
            else if (leftCheck > -1)
            {
                roomsValid[verticalChoice][leftCheck] = true;
            }
            else if (rightCheck < 3)
            {
                roomsValid[verticalChoice][rightCheck] = true;
            }``` which is here but that should work fine
ivory bobcat
gaunt ice
#

There is only one true valid room after each iteration

teal viper
teal viper
#

Also what ティナsaid.

ivory bobcat
#

I'm guessing they're randomly picking rooms though and that the unwanted behavior occurs when no rooms meet the conditions to continue UnityChanThink

faint osprey
teal viper
#

You set all the rooms to false there. But only set to true one of them.

faint osprey
#

oh should they not be else if's

teal viper
#

Probably. We don't know the intention behind that code.

#

You should tell us.

faint osprey
#

ok that fixed it

#

thanks guys

ivory bobcat
# faint osprey ``` while (true) { if (roomsV...

Instead of randomly picking two sets of three numbers an unknown amount of times, maybe add the selectable rooms to a pre allocated list and randomize the order. You could then remove the first element until a valid element was found or escape when no more is available.
Note: to avoid allocation, just have a list with a capacity of 9 and clear it before adding the next set of rooms for testing.

rotund vapor
#

how would i make a trigger teleport an object to that trigger's y position when the object goes into that trigger?

timber tide
#

can use OnTriggerEnter or Spherecast an area

polar acorn
rotund vapor
#

ok, thanks! 🙂

vestal ether
wintry quarry
# vestal ether is this java or c#

From this context alone impossible to tell. it's valid in both languages. Seeing as we're on the Unity server, very good chance it's C#.

eternal siren
#

does anyone have good documents on raycasting?

frosty hound
plush chasm
#

EDIT: FOUND THE ANSWER ... Preferences -> Asset Pipeline -> Auto Refresh -> Enabled
(original problem.. I am not sure if this is the right place but... I just updated project to Unity Version 2022 and I noticed if I save a sprite in paint.net unity will not show the changes anymore until I run the game. Is there a way to see sprite changes even if the game isn't running again?)

bold mica
#

Anyone know why my SceneManager.LoadScene() isn't working in a built version of my game?

Pressing the start button works in the unity editor as expected, but once I build the project, that button just not longer works anymore. It seems to affect the buttons with a certain script onclick? as the other buttons work but i have no idea. Anyone have any pointers or possible fixes?

wintry quarry
#

does it respond to the mouse at all (tinting etc)? HAve you checked the log files?

#

putting a Debug.Log in there and seeing if it shows in the logs would be a good start

bold mica
#

cant check if it responds to the mouse because i disabled that

#

i will try a debug log real quick

vestal ether
bold mica
winter prawn
#

What was the issue?

bold mica
#

basically

#

i was trying to save data and read data right

#

and i did that by writing and reading to a txt file

#

but on the built version, something was different I guess, and an exception was getting thrown whenever I tried to write to the file, because it didn't exist according to unity.

#

then because of that it didnt run the line under it, which was to load the next scene.

magic fern
#

Hello, I am new to unity and new to C#, I am trying to do simple first person movement and so far it was going good with a youtube tutorial using unity's imput system, the problem is that tho the video said it could also be used for 1st person games, the tutorial only focused on third person, and I dont know how to implement the 1st person camera and mouse imput into the script. Everything else works fine (jumping, moving and gravity)

#

these are immages of my code ^ (sorry for the mess)

#

and here an image of the imput actions

#

thank you in advance

teal viper
#

Look up a tutorial for a first person controller and switch between the 2 modes.

magic fern
#

so redo the whole thing?

#

cause I tried implementing the camera from a different video into my script and it didnt work

teal viper
#

No need to redo everything. Just add the first person logic additionally(maybe even in different script) and switch between them.

magic fern
#

Got it thanks

gaunt harbor
#

if (Physics.Raycast(Cam.transform.position, Cam.transform.TransformDirection(Vector3.forward), out hit, Range) && hit.transform.tag == "Enemy")

Does anyone know which of each code I can expand the detection area?

summer stump
#

Like SphereCast

teal viper
#

I don't get what I want
Is very deep.🤯

gaunt harbor
#

LOL

#

I can't translate well into English

teal viper
#

I mean that's fine. It's a common problem in this channel anyway

#

The "don't get what I want" part

gaunt harbor
gaunt harbor
teal viper
gaunt harbor
#

yeah : (

dusty coral
dusty coral
#

how to ignore it?

north kiln
#

Don't ignore it. Physics.Raycast returns a boolean, act on the boolean and don't read hit if it's false

#

also, understand the value of stack traces and everything else in the troubleshooting section of that site, so you can see how obnoxious it is to provide an exception without showing the line numbers

dusty coral
gaunt harbor
vital lintel
#

Hello, Everyone. I was curious on what the best methods for saving, accessing, and modifying large amounts of text for a text based game would be. In this case, player makes a choice in the beginning of the game, and later down the line it'll display a certain text if the player chose option A, or a different one if they chose option B, etc. The game will be filled with such choices and differences. From what i found, hard coding it is probably not the best method and i was curious if there was a better way?

undone rampart
dusty coral
#

there's no errors anymore but it still cant recognize that the object is an entity

north kiln
dusty coral
#

its just a layer mask

north kiln
#

You'll have to use a plain int to represent a single layer

dusty coral
#

why is the ui not snapping to the top left when i full screen?

undone rampart
# dusty coral its just a layer mask

there is actually no point of detecting the layer mask in that if, you can just put a mask on the raycast directly and it will only become true if hits the specified layer

undone rampart
eternal needle
undone rampart
eternal needle
undone rampart
#

put a tag on the enemy and compare the tag of the gameobject hit by the raycast

eternal needle
undone rampart
#

its a lot cleaner to compare a tag then compare a layer

#

like visually

rich adder
eternal needle
#

I feel they're just talking about the logic being simpler? Not really a good justification for mixing the 2 systems

undone rampart
#

its basically

if (hit.collider.CompareTag("Enemy") {}

vs

if (hit.gameObject.layer == 3) { }
rich adder
#

if(hit.collider.TryGetComponent(out Enemy enemy))

undone rampart
#

and if you accidentally change the order of a layer that whole thing can break

undone rampart
rich adder
#

remembering to put tags on things is a pain

eternal needle
# undone rampart and if you accidentally change the order of a layer that whole thing can break

The same can be said about the tags, if you change the string. But its insanely easy to just write one piece of code which stores the values for either. Regardless, you're talking about how the code looks which imo shouldnt even be a factor. You now mix 2 systems and anyone that helps on the project has to wonder what will use a tag and what will use a layer. When you want to use physics stuff for the object as well, are you gonna create a tag and a layer?

#

The GetComponent code as well works, but layer based is much faster.

undone rampart
#

personally, i use layers as filters and tags for detection

eternal needle
#

A raycast has both a filter and is used for detection, again mixing the systems

#

Or just any physics function in general like overlap or any cast

undone rampart
#

¯_(ツ)_/¯

#

i filter the object hit by the cast with layers, then check whats what with tags

rich adder
#

that makes no sense, the tag check relies on the hit from raycast.
Also raycasts are def not expensive lol

jaunty heath
#

oh it doe not make any sense, i missed the using of HIT in the 2nd if.. facepalms hard nevermind me 😐

#

ill just delete that to be sure :p

rich adder
#

allgud just thought I'd point that out lol

jaunty heath
#

what is this "thinking first" y'all been talkin about? sigh 😛

rich adder
jaunty heath
restive ore
#

what do i do with unity, im completely new to coding not even a single time i code before

#

not my first time i tried Godot before it was easy man

eternal falconBOT
#

:teacher: Unity Learn ↗

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

north kiln
#

There are resources pinned to this channel

kindred halo
#

playerVelocity.x = Mathf.Sqrt(hit.normal.y * playerSpeed);
I'm basically performing a wall jump
Whenever I press jump I want to jump on the wall's normal direction
But required argument is a float
Is while the normal is a vector
is this how I should be doing it?

teal viper
#

Hit normal y would be 0 for a vertical wall.

#

Wdym by "jump on the wall's normal direction"? If you just want to use the normal as the direction then set your velocity to it * speed.

kindred halo
#

you mean like this?
jumpVector = hit.normal * speed;

#

idk why the player just jumps up

kindred halo
kindred halo
rich adder
dusty coral
#

how to adjust animation loop interval?

kindred halo
rich adder
rich adder
#

not sure where the code question is

flint estuary
#

hello someone can help me i dont know i make the state machine for the enemy can someone can help me i need the enemy patrol the area after 5 secons the enemy make the animation of idle and patrol again when he see you chase after the player someone can help me with that?

rich adder
#

or coroutine is easier for timer

flint estuary
rich adder
late bobcat
#

Hello there everybody, i've a question. I wanted to play the game i created in unity with my friends online. How should i do that? I can host the server on my pc if needed. Just wanted to try the game out with some friends

frosty hound
flint estuary
tepid summit
#

Can i please get some help?
The issue/problem: 'GameObject' does not contain a definition for 'canMove' and no accessible extension method 'canMove' accepting a first argument of type 'GameObject'.
My Code (watch out its a long one):

    public GameObject CoilyBoily;
    public float speed = 20f;
    float xRotation = 0f;
    

    public LayerMask layerMask;
    
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        CoilyBoily = GameObject.GetComponent<CoilyBoily>();
    }

    void Update()
    {
        float xAxis = Input.GetAxis("Mouse X") * speed * Time.deltaTime;
        float yAxis = Input.GetAxis("Mouse Y") * speed/2f * Time.deltaTime;
        xRotation -= yAxis;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);
        Mathf.Clamp(yAxis, -90, 90);
        player.Rotate(0f, xAxis, 0f);
        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
    }
    void FixedUpdate()
    {
        RaycastHit hit;
        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
        {
            CoilyBoily.canMove = false;
        }
        else
        {
            CoilyBoily.canMove = true;
        }
    }```
flint estuary
rich adder
tepid summit
#

its a bool on my script

rich adder
#

pretty sure you wanted CoilyBoily not GameObject

late bobcat
frosty hound
tepid summit
rich adder
#

so declare it properly

rich adder
eternal falconBOT
frosty hound
tepid summit
flint estuary
late bobcat
#

@frosty hound https://www.youtube.com/watch?v=stJ4SESQwJQ that's what i'm looking for i think?

Netcode for Unity is an amazing real-time multiplayer solution, which is part of the wider Unity Gaming Services.

Checkout Netcode: https://on.unity.com/3blzOy3

In this video you'll learn:
How to get started with Netcode
The different between server & client authority and when to use each
How to write performant network code
How to use Networ...

▶ Play video
flint estuary
#

thats the scripts because i dont know how i put links

tepid summit
#

its free

rich adder
rich adder
#

its not rocket science

late bobcat
#

@tepid summit do you have some sort of tutorial to set it up?

rich adder
#

no dude, click the links in the bot message

late bobcat
tepid summit
flint estuary
#

idk

late bobcat
tepid summit
#

ok

#

import it to your project and come back to me

tepid summit
rich adder
tepid summit
#

here

hexed terrace
tepid summit
#

right

#

so what do you suggest

rich adder
#

they just told you..