#💻┃code-beginner

1 messages · Page 833 of 1

naive pawn
#

with isGrounded, if you're on the ground and jump is pressed, the upwards velocity gets set.
without isGrounded, if jump is pressed, the upwards velocity gets set.

viral bobcat
#

I understand why removing isGrounded allows me to air jump but not why it makes jumps higher

naive pawn
#

if you don't have the isGrounded check, you get to jump even while already in the air, and it seems like that JumpPressed checks the current state of the button, instead of whether it was just pressed down

viral bobcat
#

same result

#

i seperated pressing down and holding in inputhandler

#

they're basically different inputs

naive pawn
#

could you show that

viral bobcat
#

need to get around discord message size limit rq

naive pawn
#

the embed you were linked has a section called "Large code blocks"

#

consider reading that

viral bobcat
# naive pawn could you show that
private void OnEnable()
{
    actions.Enable();

    actions.Player.Move.performed += ctx => MoveInput = ctx.ReadValue<Vector2>();
    actions.Player.Move.canceled += ctx => MoveInput = Vector2.zero;

    actions.Player.Look.performed += ctx => LookInput = ctx.ReadValue<Vector2>();
    actions.Player.Look.canceled += ctx => LookInput = Vector2.zero;

    actions.Player.Jump.started += ctx => jumpDownRaw = true;
    actions.Player.Jump.performed += ctx => jumpHeldRaw = true;
    actions.Player.Jump.canceled += ctx => jumpUpRaw = true;

    actions.Player.Crouch.performed += ctx => crouchHeldRaw = true;
    actions.Player.Crouch.canceled += ctx => crouchHeldRaw = false;

    actions.Player.Sprint.performed += ctx => sprintHeldRaw = true;
    actions.Player.Sprint.canceled += ctx => sprintHeldRaw = false;
}

private void OnDisable()
{
    actions.Disable();
}

private void Update()
{
    // ---- JUMP SNAPSHOT ----
    JumpPressed = jumpDownRaw;
    JumpHeld = jumpHeldRaw;
    JumpReleased = jumpUpRaw;

    // clear edge triggers after snapshot
    jumpDownRaw = false;
    jumpUpRaw = false;

    // ---- CROUCH ----
    if (CrouchToggle)
    {
        if (crouchHeldRaw)
        {
            crouchToggledOn = !crouchToggledOn;
            crouchHeldRaw = false; // prevent rapid toggle spam
        }
        CrouchState = crouchToggledOn;
    }
    else
    {
        CrouchState = crouchHeldRaw;
    }

    // ---- SPRINT ----
    if (SprintToggle)
    {
        if (sprintHeldRaw)
        {
            sprintToggledOn = !sprintToggledOn;
            sprintHeldRaw = false;
        }
        SprintState = sprintToggledOn;
    }
    else
    {
        SprintState = sprintHeldRaw;
    }
}
#

i dont think the rest is relevant anyawy

naive pawn
#

please no.

#

this is a large code block.

#

use the section on large code blocks.

viral bobcat
#

oh mb

naive pawn
#

there's definitely something missing here.

viral bobcat
#

dont mind the comments i use them to remind myself what some things do bc i'm new

naive pawn
#

how is Jump set up?

#

the action

viral bobcat
naive pawn
#

that seems normal. have you tried debugging to see if it's getting into that if multiple times?

viral bobcat
#

the if inside jumphandler?

naive pawn
#

yes

viral bobcat
#

Only once per spacebar down and not when I press space midair

#

so yes it's getting into it only once

naive pawn
#

what if you don't have the grounded check

viral bobcat
naive pawn
#

not what i asked

#

see if it's getting into that if more than it should

viral bobcat
#

u are right, it triggers twice without isGrounded

naive pawn
#

(btw your OnEnable and OnDisable seem like you expect this to be disabled/re-enabled, but that'll end up with stale event listeners since you never unsubscribe)

viral bobcat
#

thx for pointing that out

naive pawn
#

not the place for this.

delicate ferry
#

When the player dies, I do

var name = SceneManager.GetActiveScene().name;
SceneManager.LoadScene(name);

But I want to preserve the death count. How do I preserve state across scene loads?

naive pawn
#

you need something that persists across scene loads, that doesn't live in the scene
that could be a gamemanager that's DDOL or in a persistent scene for example, or a save file

naive pawn
#

dontdestroyonload

delicate ferry
naive pawn
#

try googling like, ddol/singleton gamemanager, i guess

sage mirage
#

@delicate ferry Just do this whenever you want to create a single global access point to your application/game, specifically you do it for managers because they are responsible in controlling things like UI, Game States etc
public static GameManager Instance;
and then you do something like

{
    Instance = this;    DontDestroyOnLoad(gameObject);           
}
else
{
    Destroy(gameObject);
}```
This is called Singletton Pattern. Keep in mind that each pattern has pros and cons. You dont have to make every class a singleton. This code btw will let your game objects persist across scenes, also something I didn't know before is that even if you change more than one scenes your objects will still be persistent because it actually stores your game object on a seperate scene called DontDestroyOnLoad and that's really cool.
delicate ferry
naive pawn
#

in a gamemanager script

#

you would have persistent stuff there

sage mirage
# delicate ferry Where do I put the code of gamemanager?

the instance declaration goes after your game manager class and you declare it as static. The if statements go in awake because we want the instance to be created at the moment your script is loaded/created when you play the game. If that's what you mean?

naive pawn
delicate ferry
#

But now in what scene do I put the gamemanager? Eventually my game will have multiple scenes

naive pawn
#

with this approach you'd have it in every scene for ease of testing

#

or if you only have it in one scene it'd be simpler but you wouldn't be able to play from other scenes directly

#

you could also use a persistent additive scene to avoid that issue but it's a bit more complex

delicate ferry
naive pawn
#

the state is preserved because the original object persists, not because it's in every scene

#

it being in every scene just means you can enter playmode from anywhere

sage mirage
# delicate ferry So if I have a gamemanager object in every scene with the same script, the state...

It's not efficient though at all. Just keep in mind that. That's very risky making more than one of the same managers in your game. I think we had a discussion about it with another guy. You always have to think about the Single Responsibility Principle and if you have duplicates you are breaking this principle that means harder to maintain and manage etc etc because imagine you have some references on one scene and some references on other scene for the same game manager you will probably have many null references because some objects dont exist on the other scene you have the duplicated game manager thats horrible approach.

naive pawn
#

wtf are you on lmao

#

punctuation, man..

sage mirage
#

Bro having the same managers on more than one scene is not efficient

#

XD

naive pawn
#

it literally doesn't matter

#

it's not related to efficiency at all

#

if you have references to objects in the scene, that is an issue of design - the gamemanager shouldn't care about stuff in specific scenes

sage mirage
#

What I am saying is just do the DDOL + Singleton dont create duplicates in all of your scenes.

naive pawn
#

so you're locked into opening 1 specific scene and going from there to test anything in playmode, sure...

#

having duplicates doesn't matter anyway if you have the Destroy(gameObject) set up correctly

limpid stratus
#

RuntimeInitializeOnLoad can solve both at once!

sage mirage
naive pawn
#

since you'd need a component instance

limpid stratus
#

if you don't need the editor to populate fields, then there's no problem

naive pawn
#

fair

#

actually, i feel like having an inspector would still be very useful for debugging purposes

#

if it's not a component you can't directly inspect it from the editor at all

#

i haven't considered this approach before so having a lot of thoughts lol

limpid stratus
#

Absolutely, and if I had to lean on one side, I definitely prefer having duplicates across scenes to avoid forcing a scene on load

#

Sorry, I meant absolutely to the first statement you made

That being said, you can init a GO and strap your component to it and then do your typical singleton logic from a method with the attribute above.

Then the only thing you're really losing is the ability to preset variables via the inspector

naive pawn
#

That being said, you can init a GO and strap your component to it and then do your typical singleton logic from a method with the attribute above.
i feel like this mix of approaches causes kinda more problems, does it not? (kinda minor problems, but relatively, more)
you'd have to retreive the component reference from that static method

or i guess you could have the component depend on the singleton logic rather than the other way around? thonk
eg either the method creates the singleton component, or the component is just for introspecting the singleton

limpid stratus
# naive pawn > That being said, you can init a GO and strap your component to it and then do ...

If you don't need persistent values defined via the inspector, then there's nothing stopping you from

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void Initialize()
{
  foo = new go
  staticInstance = foo.AddComponent<InstanceOfYourSingleton>
  DDOL(foo)
}

this way you can forget about it whenever you create new scenes, but you can't use the editor to populate fields. I guess you could still load the instance as a prefab if you really needed this

naive pawn
#

you wouldn't be able to grab the prefab reference

#

well, not easily

#

would need magic strings

limpid stratus
#

I don't follow. Why so?

naive pawn
#

well, how would you get the prefab reference from the static method lol

#

would need to go through eg Resources.Load instead of having a direct reference

limpid stratus
#

You can expose a static API that retrieves your content via whatever your preferred method is. I am not familiar with addressables so I can't speak for that but resources.load would work just fine

naive pawn
#

you'd need magic strings either way though, no?

#

wouldn't be able to assign a direct reference, is what i was trying to say

limpid stratus
#

Yeah, that's true I guess. I still advocate for it though. If they bother you so much, you can have a single magic string that acts as a point of entry to your data. Map it as a constant and forget about it. I understand where you're coming from though

naive pawn
#

i have a habit of wanting to rename/restructure/refactor a lot so i try to avoid magic strings like the plague lol 😅

limpid stratus
#

yeah, I hear you. You know what's good for you based on your flow, there's no arguing against that. For me, integrating singletons like this were a net positive, but I don't expect that to translate to all workflows

pastel cave
#

oh, unity can import aseprite files??

#

IT EVEN RESPECTS TAGS!!

solar hill
pastel cave
#

no, just surprised.

solar hill
#

this channel is for coding help

pastel cave
#

sorry, I'm so used to only using this channel lol

solar hill
#

unity-talk is for general unity questions

#

not a genchat

pastel cave
#

I see. I will keep my mouth shut then

naive pawn
spice burrow
#

I cannot find how I would check if the scroll wheel is being scrolled down or up using the new input system

naive pawn
#

actually i should ask, how are you receiving input?

#

so i can point you to the corresponding way to get mouse scroll

spice burrow
#

Thing is, I'm looking for something similar to the ispressed functions but for scrolling instead

naive pawn
#

on an InputValue or on an InputAction?

spice burrow
#

uhhh.... action, I think

naive pawn
#

just check the stuff you're reading isPressed/IsPressed on, see what type it is

#

or show the code if you can't find it

#

could also be InputControl, or maybe CallbackContext. i don't know the full list

ocean frost
#

for what does the .zero stand for?

#

Does it mean (0, 0, 0)?

cosmic quail
spice burrow
ocean frost
#

okkk!!! Thanks!!

spice burrow
#

Also works with Vector2

naive pawn
#

it's a prop that's just Vector3 zero => new Vector3(0, 0, 0);
it's the same as creating that yourself, just a handy shortcut that communicates a little more intent as well

ocean frost
naive pawn
#

what i wrote is how .zero is defined

ocean frost
naive pawn
#

it's not exactly that, but the same behavior

#

or in your own ide by using "go to definition" (ctrl+click the zero)

ocean frost
naive pawn
#

one is 2d and the other is 3d

ocean frost
#

tysm

#

makes sense

umbral hull
#

hey im unsure if this is possible but, i have 3 buttons, and i want to set a single variable based on which button is clicked. is that possible to do while only making 1 function for it? or do i need to make a separate function for each button?

cosmic quail
grand snow
#

UGUI button? even easier!

#

uitk? code only but easy still

viral bobcat
#

Is there a good guide to understand how ActionMaps, Input Handler and a tick based physics loop process inputs? (for FPS games)

naive pawn
#

there are input and inputsystem guides online and on unity learn, if that's what you're asking?

spice burrow
umbral hull
naive pawn
#

i don't think there's gonna be anything specifically for that, because.. that's not really a different usecase

umbral hull
#

im sorry whats ugui/uitk?

naive pawn
spice burrow
grand snow
naive pawn
#

im waiting for you to answer

#

there's multiple ways to get input in the inputsystem

#

i'm asking what you're using so i can tell you how to get scroll input in the same way

ocean frost
#

Does += mean take the current value and add 1?

naive pawn
ocean frost
#

like here

naive pawn
#

you might just want to go do some beginner c# tutorials instead of asking everything here

#

it will be much faster for you and for us

#

there are resources pinned in this channel

umbral hull
grand snow
umbral hull
grand snow
#

Ugui Button still has onClick

grand snow
#

Unless you call OnPointerClick on the button itself

umbral hull
#

rn im doing this (i solved my problem btw)

    public void ToHumanCount()
    {
        GameObject clickedButton = EventSystem.current.currentSelectedGameObject;

        if (clickedButton.name == "2 players")
        {
            PlayerAmount = 2;
        }
        else if (clickedButton.name == "3 players")
        {
            PlayerAmount = 3;
        }
        else if (clickedButton.name == "4 players")
        {
            PlayerAmount = 4;
        }

but i wanted to do it a different way originally

#

OnPointerClick...

naive pawn
#

why not just receive an int here and have the buttons pass on that int

grand snow
#

This is horrible wut

naive pawn
#

you can set that int in the event you set in the button

#

and yeah that is incredibly fragile

grand snow
#

Exactly

umbral hull
#

i was trying that originally but it wasnt actually changing

grand snow
umbral hull
naive pawn
grand snow
#

Id write an example but I'm on mobile rn

umbral hull
#
public int PlayerAmount;
public enum PlayerCount
{
    players2 = 2,
    players3 = 3,
    players4 = 4
}
public void SetPlayers(int players)
{
    PlayerAmount = (int)players;
    switch (players)
    {
        case 2:
            PlayerAmount = (int)players;
            break;
        case 3:
            PlayerAmount = (int)players;
            break;
        case 4:
            PlayerAmount = (int)players;
            break;
    }
}
public void ToHumanCount()
{
    ShowState(MenuState.HumanCount);
    SetPlayers(PlayerCount);
}

The problem is that idk what to really call in SetPlayers() and maybe something else i havent thought of

#

holup

grand snow
naive pawn
#

what even

#

you're overcomplicating this

#

you have the same logic in every branch of that switch

#

also this isn't even valid code?

#

i'm so confused what's going on here

umbral hull
naive pawn
#

yeah that's fair

ocean frost
naive pawn
naive pawn
ocean frost
#

It says +(Vector3 a, Vector3 b)

naive pawn
naive pawn
# umbral hull yes

the code should just be this then```cs
public void ToHumanCount(int amount)
{
PlayerAmount = amount;
}

delicate ferry
#

If I have an object flying at Velocity, iis this the vay to make it face the way it goes?

transform.rotation = new Quaternion(0, 0, Vector2.Angle(Vector2.up, Velocity), 0);
ocean frost
naive pawn
naive pawn
#

Velocity is the velocity vector?

delicate ferry
ocean frost
naive pawn
naive pawn
#

if you have angles, you could use something like Quaternion.Euler here, but it's an unnecessary step for this case.

umbral hull
naive pawn
umbral hull
#

huh?

naive pawn
#

this is what john was referring to

grand snow
#

They don't understand lambdas

#

I suggested a script to put on the buttons but who knows

delicate ferry
grand snow
#

I'm tired 😩

naive pawn
# umbral hull huh?

go to your button and set the onclick to tohumancount (you might need to remove and re-add it)
there will be a input box that shows up. that will be the int amount

umbral hull
ocean frost
#

Wrong channel, isn't it?

naive pawn
#

<@&502884371011731486> job post/spam

grand snow
# umbral hull no i do not

Make new script to store number, put on each button, get component in the on click listener and get value bam dynamic and shit

naive pawn
umbral hull
#

ohh i see

grand snow
#

I'm very aware of better designs but it beats using names

delicate ferry
naive pawn
#

no clue what that is

delicate ferry
#

But the vector is not zero

naive pawn
#

i'm not in your project with you

naive pawn
umbral hull
umbral hull
naive pawn
#

it's less work

delicate ferry
#

It's not anything in my project

naive pawn
#

ah, i see

grand snow
naive pawn
#

i guess make sure Velocity is valid before assigning that

grand snow
#

I presumed code sub

naive pawn
#

ah, i see.

#

i couldve been more specific

naive pawn
#

are you sure it's that frame thouhg

delicate ferry
naive pawn
#

try logging Velocity before you assign it to transform.forwards

umbral hull
#

thx guys sadTJ

naive pawn
delicate ferry
#

It's a 2d game

#

I want it to only transform z

#

Apparently I needed transform up instead

naive pawn
#

ah yeah, in 2d you don't typically want to change the forwards direction

delicate ferry
#

Anyways now I need transform.left

#

But apparently there's only transform right

ivory bobcat
#

Left = -Right

delicate ferry
grand snow
#

Big brain

prisma shard
#

Does anyone know if fog of war and a chunking system (For memory management) should be implemented at the same time? Because i think chunking drastically changes how AI move and things happen inside the fog of war of a chunking system where things arent being constantly updated but they still exist and do things persay

grand snow
prisma shard
#

It is. Nice i have no idea how to do this and i fear object geometry, environment, seed rng biomes, rng resource spawning etc is all intimately connected with the fog of war/chunking

#

Im so screwed

#

Im guessing this is the hardest part of everything maybe aside from balancing which is the real nightmare

#

Im likely going to hire someone for the balancing part. It will probably be expensive as well unfortunately to pay someone to do it. But if anyone is interested in a future job u can mark me in ur dms or whatever if its something any of u would be interested in working on

#

If I contact you please have a resume on balancing ready

thin lotus
#

Trying to reference a variable from another script in another game object like this:

using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Count : MonoBehaviour
{
    [SerializeField] TextMeshProUGUI textObj;    
    [SerializeField] private Chris Ref;

    

    void Start()
    {
        Ref.money;
    }```
it gives me the error ```Assets\Count.cs(5,7): error CS0246: The type or namespace name 'Chris' could not be found (are you missing a using directive or an assembly reference?)```
#

what did I do wrong here?

sour fulcrum
#

what is Chris

thin lotus
#

a Gameobject

sour fulcrum
#

no

thin lotus
#

that contains a script with the money variable

sour fulcrum
#

what is that script called

thin lotus
#

Click

sour fulcrum
#

then you might want
private Click Ref

#

you need a type, not a random name

thin lotus
#

i thought i was supposed to reference the gameobject, not the script

sour fulcrum
#

no, but even if you did you would do private GameObject Ref

thin lotus
#

alright, works now, thanks

#

that was a pretty obvious solution, and i tried things before asking, I swear!

#

alright now it says money doesn't exist in the current context

sour fulcrum
#

post your Click script code

thin lotus
#
using UnityEngine;

public class Click : MonoBehaviour
{
    float sizeincrease = 0.1f;
    int iterationCount = 3;
    float delayBetweenSteps = 0.02f;
    public int money;
    void OnMouseOver()    
    {
        if (Input.GetMouseButtonDown(0))
        {
            money += 1;
            StartCoroutine(ScaleOverTime());
            Debug.Log(money + " christonium");
        }
    }
    IEnumerator ScaleOverTime()
    {
        for(int i = 0; i < iterationCount; i++)
        {
            transform.localScale += new Vector3(sizeincrease,sizeincrease,0);
            sizeincrease += 0.1f;
            yield return new WaitForSeconds(delayBetweenSteps);
        }
        StopCoroutine(ScaleOverTime());
        transform.localScale = new Vector3(2,2,0);
        sizeincrease = 0.1f;

    }
}
#

also, the serialized field in vscode and the unity editor dont match

#

"Chris" is mentioned nowhere in the Count script and yet its the label for the serialized field

sour fulcrum
#

do you have errors and have you saved your script

thin lotus
# sour fulcrum do you have errors and have you saved your script

yes I've saved it, and these are my errors:
Assets\Count.cs(17,24): error CS0103: The name 'money' does not exist in the current context
the serialized field thing was weird to me so i deleted the script and copy pasted its contents into an identical one, now there are no serialized fields

slender nymph
#

you need to fix all compile errors before your code can compile

thin lotus
#

makes sense, I still dont know how to fix the error, it seems like i did it right?

slender nymph
#

in the code you pasted above it does look correct. but have you saved that too? (assuming that's even where the error is)

thin lotus
#

yeah, everything is saved

slender nymph
#

and are you looking at the Count.cs file?

thin lotus
#

actually, the Count script changed a bit from when i pasted it,

using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Count : MonoBehaviour
{
    [SerializeField] TextMeshProUGUI textObj;    
    [SerializeField] Click Ref;    

    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        textObj.text = money;
    }
}```
slender nymph
#

so this is where that error is. not in the Click class you pasted above. where have you declared money here

thin lotus
#

money is declared in Click

slender nymph
polar acorn
thin lotus
#

and (at least what i tried to do) was reference money from the Click script

thin lotus
polar acorn
#

You're getting the text variable from your textObj

#

Do that

thin lotus
#

holy crap, that's so obvious

polar acorn
#

Obvious enough to show that you should definitely go through the very basics again. There are some courses linked in the pins, go through them.

thin lotus
#

this is kinda my way of going through the basics, ive never gotten anywhere from courses, as I get bored and retain nothing

slender nymph
#

stumbling along until someone else tells you how to fix things isn't exactly a good way to learn anything

thin lotus
#

thats why i've been looking at documentation and old forum posts up until I hit this wall

#

but yes, thats correct

polar acorn
thin lotus
#

sure,
what I meant by not following courses was not going through lessons one by one doing the exact same thing it tells me to, instead of making my own thing along the way

stray anvil
#

so modern games
with no loading screen after mission finish and all
technically has whole game in one scene?

#

and loads next batch of assets during narrow passages or other hacky ways?

naive pawn
stray anvil
naive pawn
#

seamless loads are a thing, chunk loading is a thing, etc

stray anvil
#

that has no loading screen

naive pawn
#

there's so many ways to do it

sour fulcrum
#

additive scene loading

naive pawn
#

undertale doesn't have loading screens

stray anvil
#

in unity terms

naive pawn
#

could have either

sour fulcrum
#

you can have scene a loaded, load scene b, then unload scene a

naive pawn
#

might not even have separate levels

#

you're asking for a generalization that doesn't exist

stray anvil
#

how can change scene without loading or something?

sour fulcrum
#

you can have multiple scenes loaded at the same time

naive pawn
#

you can have loading without a loading screen

stray anvil
naive pawn
#

the question is way too vague to actually have a proper answer

stray anvil
sour fulcrum
#

not neccasarily

stray anvil
naive pawn
#

not just because of that, no

#

those are separate concepts

#

you can change scenes without a loading screen, you can have loading without changing scenes

stray anvil
#

by loading screen, i mean: finishing a level and u get to main menu or some other menu and then u start from some unique place

#

next level

naive pawn
#

what i said doesn't change

#

wasn't there that one spiderman game on ps5 where a scene change was completely seamless, for example

stray anvil
naive pawn
#

think of actual scenes irl

#

if you have, eg, the inside of a building that's disconnected from outside, then that could be a separate scene
if it's connected to the outside, then it wouldn't be a separate scene

stray anvil
#

hmm got it

#

so if i make a whole gmae in one scene, is that a bad practice?

naive pawn
#

you can have a single big scene by loading/unloading stuff within the world yourself, that is an option

naive pawn
stray anvil
stray anvil
naive pawn
#

i wouldn't care tbh

stray anvil
#

it's like this, u keep going forward without any transition or anything

naive pawn
#

it's just a question of game design

#

why would there be transitions there

stray anvil
#

like listed

naive pawn
#

not listed, no

#

again, this is way too vague

#

don't worry about this

#

just design it in a way that makes sense

#

it's all continuous in the same world? sure, one scene.

#

there are separate disconnected areas? sure, different scenes

#

it's not that deep

#

you should not be deciding whether to use one scene or multiple scenes

#

you should be deciding how you want your game to flow, and then the decision over how scenes go will just pop out of that

stray anvil
chrome apex
#

!code

radiant voidBOT
chrome apex
#

Why does this script not work:

 List <Vector3> MapPoints = new List<Vector3>();
    Vector3 lastPoint;
    float distanceThreshold = 5f;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        if (MapPoints.Count == 0)
        {
            AddPoint();
        }
    }

    // Update is called once per frame
    void Update()
    {
        float distanceSquared = (transform.position - lastPoint).sqrMagnitude;

        if (distanceSquared > distanceThreshold )
        {
            AddPoint();
        }
    }
    void AddPoint()
    {
        Vector3 currentLocation = transform.position;
        MapPoints.Add(currentLocation);
        lastPoint = currentLocation;
        Debug.Log(MapPoints.Count);
        //Debug.Log(lastPoint);
    }

The Debug for points.count always shows 0. Furthermore, it triggers every frame, whereas it should trigger only every x distance moved

keen dew
#

You're looking at some other log output. Change it to something more descriptive: Debug.Log("MapPoints count: " + MapPoints.Count);

tepid vessel
#

Guys any of you build some good working publishable or semi publishable quality level multiplayer game. How do you guys learn the multiplayer concepts using fusion, theres docs and stuff but some things like optimizing data thats sent over network or some industry standard methods. Are there any good resources which teach you in depth photon fusion and multiplayer in general (Not the basic two player spawned logic)

strong wren
tepid vessel
strong wren
tepid vessel
#

ohh

#

but they are all unrelated topics tho? Like not completely but to some extent

small summit
#

I am really confused, I've made a reference for the Transform component countless times, but for some reason Unity thinks the namespace doesn't exist? There's literally a reference to Transform in a different script in the same project that works fine

#

....wait. Ohhh my god I forgot to capitalise this instance the entire time, I didn't read what column the error was on, ahg

naive pawn
#

!ide

radiant voidBOT
naive pawn
#

it'll show you were the error is

#

also you shouldn't name a field transform, you won't be able to access the object's own transform lol. your ide will also warn of this if configured properly.

#

oh wait you're doing this.GetComponent<Transform>?

devout otter
#

why would anyone need its own custom property transform if you have it already out of the box?

naive pawn
#

why do you even have that transform field lol

#

you never need GetComponent<Transform>()

#

you can just do targetPlayer.transform @small summit

devout otter
#

i smell some shatgbt hallucinations in this approach 😄

naive pawn
#

targetPlayer doesn't seem to be assigned either lmao

stuck parrot
#
using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour
{
    private Rigidbody rb;
    private Vector2 moveInput;

    public float speed = 5f;

    void Awake()
    {
        rb = GetComponent<Rigidbody>();
    }

    public void OnMove(InputValue value)
    {
        moveInput = value.Get<Vector2>();
    }

    void Update()
    {
        Vector3 move = new Vector3(moveInput.x, 0, moveInput.y);
        rb.MovePosition(rb.position + move * speed * Time.deltaTime);
    }
}``` any idea why this is not working?
rich adder
stuck parrot
rich adder
naive pawn
#

are you getting any errors, check if OnMove is being called

stuck parrot
rich adder
#

the first thing you should've learned.. print logs..

naive pawn
#

nav just said how lol

#

Debug.Log

stuck parrot
naive pawn
#

you can with a debugger, but this is a quick and easy analog that's easier to explain for beginners

rich adder
stuck parrot
rich adder
stuck parrot
#

I thing it was this line rb.MovePosition(rb.position + move * speed * Time.deltaTime);

#

I have the feeling it only moved the rb position but left the player position in place (im not sure)=

rich adder
stuck parrot
#

but I couldnt write rb.MovePosition(move * speed * Time.deltaTime); like i did with character controller. But I dont know what the additional rb.position did, VS autofilled it and it gave me an error without it

stuck parrot
rich adder
dull phoenix
#

guys what is the best method to learn unity coding
not just basic funtions like advanced movement

dawn iron
#

can anyone help me how can i make the trail renderer curve smoothly? it only moves in square (sry idk how to expain it) like i cant make an s shape

radiant voidBOT
naive pawn
#

start from basics

dull phoenix
#

ty

rich adder
naive pawn
dawn iron
naive pawn
stuck parrot
naive pawn
rich adder
naive pawn
#

you don't actually learn much by just doing trial and error

dawn iron
stuck parrot
naive pawn
#

right because the issue was in the hierarchy, by the sounds of it

#

also isn't MovePosition just for kinematics

#

for a dynamic RB you'd be using velocity or AddForce instead, and those are relative

rich adder
#

oh wait thats trail renderer not line renderer, nvm scratch the thing about splines. mb

stuck parrot
# naive pawn for a dynamic RB you'd be using velocity or AddForce instead, and those are rela...

Ive read that rigidbody is more for objects and not the player so I will use character controller from now on. One thing at a time. also is that movement script good or is not good readign the input in update all the time? ```using UnityEngine;
using UnityEngine.InputSystem;

[RequireComponent(typeof(CharacterController))]
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;

private Vector2 moveValue;
[SerializeField] private float speed = 7f;

void Awake()
{
    controller = GetComponent<CharacterController>();
}

public void OnMove(InputValue value)
{
    moveValue = value.Get<Vector2>();
}

void Update()
{
        // directional movement
    Vector3 move = new Vector3(moveValue.x, 0, moveValue.y);
    controller.Move(move * speed * Time.deltaTime);
}

}```

naive pawn
#

you can definitely use RBs for players

dawn iron
naive pawn
#

is not good readign the input in update all the time?
not reading it constantly would mean your game is laggy

stuck parrot
naive pawn
#

they have some limitations, yes. everything else also has limitations

rich adder
#

pros n cons.
like everything else

naive pawn
#

some "limitations" in one context may also be benefits in others

#

don't just "oh i'm not using RB because some youtuber said so", figure out how you want your player to behave and go from there

rich adder
#

character controller is just easier in the sense that gives you the kinematic controller without having to do your own casts for collisions like kinematic RB

stuck parrot
rich adder
naive pawn
#

is CC able to send forces?

rich adder
#

you can use OnControllerColliderHit and use AddForce otherwise you do not move bodies no

naive pawn
#

yeah ok that's about what i expected

rich adder
bright hill
#

hey, i got a problem when gameobject is shot, the material on slot 0 should change material. at some reason particle system works fine, but material is not


using UnityEngine;
using UnityEngine.Events;

public class ScreenShootable : MonoBehaviour, IShootable
{

    public Material brokenMat;
    public ParticleSystem brokenParticle;
    public MeshFilter currentMesh;
    public MeshRenderer currentMeshRenderer;

    [Header("Events")]
    [SerializeField] private UnityEvent onShot;
    public void Start()
    {
        currentMesh = GetComponent<MeshFilter>();
        currentMeshRenderer = this.GetComponent<MeshRenderer>();


    }
    private void Reset()
    {
        
    }

    public void OnShot(RaycastHit hit, Gun source)
    {
        Material[] materials = currentMeshRenderer.materials;
        currentMeshRenderer.materials[0] = brokenMat;
        currentMeshRenderer.materials = materials;
        brokenParticle.Play(this);


        onShot?.Invoke();
    }
}```
keen dew
#
materials[0] = brokenMat;
bright hill
#

oh thanks

light dune
#

how do I apply post processing to ONLY ui in URP?

naive pawn
upper token
#

Is there a way to make a functional DPAD for all these functions? I tried making invisible buttons to perform the actions, but it didn't work

naive pawn
#

are those animator params

#

it's kinda unclear what you're asking exactly

upper token
naive pawn
#

those are not gonna be relevant then

#

are you asking about onscreen controls for mobile

naive pawn
#

pretty sure there's an entire onscreen button/joystick thing you could use, try googling about that

upper token
naive pawn
#

you can probably use 4 onscreen buttons then

pale fiber
#

anyone knows Why isnt my Enum isnt showing up?
Im using a class as an container
and calling it in an Array

keen dew
#

You've only defined an enum type but there's no variable that uses it

#

You have to add something like public Direction dir;

pale fiber
prisma shard
#

Has anyone here actually made an impressive project out of spamming "If bools"? Whenever im done with this current game in the future id like to try it because it sounds interesting even if its super memory inefficient

#

My friend told me it would be possible to even make the entire Hearthstone game with If bools (aside from the visuals) which sounds nuts to me

keen dew
#

Not sure if you're trolling us or your friend is trolling you

prisma shard
#

I mean he is kind of a 'veteran' programmer and didnt sound like he was trolling

keen dew
#

Filling your code with if statements is the Yandere dev meme which people usually invoke when talking about bad code

naive pawn
#

every logic structure boils down to a branch or jump anyways

#

it's possible in the computer science sense, not the software engineering sense.

prisma shard
#

Whats the limitation, is it too many bytes, does it make the stack super slow?

naive pawn
#

both of those are irrelevant

#

the limitation is it's impossible to read and keep everything in your head

prisma shard
#

yea i guess thats a more immediate problem lol

naive pawn
#

it doesn't reflect more complex logic patterns, so you can't utilize those to make it easier to comprehend

summer bear
#

It would be AWFUL to read

#

readable code is super important

#

There's a running joke of people coming back to their project after 1-2 months and not knowing wtf their code is

solar hill
daring island
#

Video player plays the video looped, until i need to disable the gameobject, and when enabled again - the video doesn't play again. In a script tried to prepare and play - no effect. Why is that?

tranquil basin
#

Hey guys I have a problem.

#

I deleted the C++ file that allowed Unity to open my projects.

#

I dont remember which version to download to get it back.

naive pawn
#

can you not just reinstall the editor/hub if you corrupted it

tranquil basin
#

Its just some file is missing which prevents it opening a unity project.

sour fulcrum
#

i dont think anyone can help you with that one lol

wintry quarry
tough cedar
#

i dont understand what i did wrong on line 35 when following this tutorial 😭 its copied word for word

sour fulcrum
#

but is it copied letter for letter 🙂

slender nymph
#

you're looking at the wrong place to see where you copied wrong 😉
-# hint: look at the declaration and your other uses of that variable

naive pawn
wintry quarry
naive pawn
#

where's digi to update the counter...

#
"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: 203
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2026-04-13
tough cedar
naive pawn
#

they are not the same

wintry quarry
#

yours is not the same

naive pawn
#

and through context we can infer there is also another line that is not the same

wintry quarry
#

And from this error etc we can tell that there's at least one other line, higher up in the file, that is also not the same

tough cedar
wintry quarry
#

and it will work

#

not just on line 35

#

but in the whole file

naive pawn
naive pawn
#

your line 29 is different, but it doesn't error, because you have another line that is also different

wintry quarry
naive pawn
wintry quarry
# tough cedar i have

go back over the whole file. You copied it wrong earlier on and now you're paying for it.

tough cedar
#

OH MY GOD I SEE IT NOW.

#

its upper case instead of lower case 😭

#

sorry guys cry

naive pawn
#

this is like a rite of passage for beginners ngl

pale fiber
#

Is there any way I can get around needing a Return for each outcome?
Im trying to make it so the rooms can't Back to back spawn
but when trying to restart the selection proccess it still requires a return
which if I give it 'NewRoom'
its gonna do the same room anyways
if I return 'GetRandom()' then it causes a stack overflow

#

I tried making a Vaildator fnction but it essentially moves the problem

ivory bobcat
#

The function definition that you've set requires something to be returned of type GameObject - so yes, something has to be returned. You can try returning null if anything but it would depend on your needs

ivory bobcat
#

Also, recursively attempting to select a different random room isn't favorable. Instead, maybe have some sort of secondary collection with your values that you'd simply randomize and iterate to select random rooms.

#

An example of what I meant, where you'd then simply iterate the collection. Note that this example would have every element selected at least once etc.
There are other approaches, if duplicates or other constraints are necessary.

#

The first loop simply populated the array. Second loop did the shuffling.

wintry quarry
#

Oh sorry I'm answering a structural question but you have a logic issue too

#

Shuffling a list is a much better approach

pale fiber
#

I have it like that so I I can give direction values so It knows better to not circle in on its self down the line

pale fiber
ivory bobcat
#
var oldRoom = newRoom;
newRoom = PossibleRooms...
if (oldRoom == newRoom)
    ...```Relative to your previously shown code, fixing the if statement could be done so by caching and comparing the new vs old.
neon sable
#

is unity lighting system just buggy?

#

i just had my entire lighting system completely stop working until i duplicated all the objects

sour fulcrum
#

no

neon sable
#

then what just happened

sour fulcrum
#

not sure

neon sable
#

i assumed i messed with a value of them

#

but ctrl+d fixed them

#

so 1:1 of the original object

sour fulcrum
pale fiber
ivory bobcat
# pale fiber so Shuffle my possible rooms array?

You would normally shuffle a copy of your collection but if you've only got four rooms, it probably isn't worth it to do so.. Just copy the collection and modify the new collection to have the previous element moved to the first element or something so that you aren't able to select it again. Note that this would eliminate the first element as a possibly target on first use.

#

I've got to run, good day.

pale fiber
#

good day

tough cedar
#

what am i doing wrong now 💔

swift crag
#

i'm guessing you didn't misspell the word in your own script

#

i.e. you write int remaining; (or something similar) elsewhere

#

rather than int remanining;

tough cedar
polar acorn
swift crag
#

you should certainly pay attention to the exact error you're getting

tough cedar
tranquil basin
teal viper
swift crag
#

explain what you actually did

tranquil basin
polar acorn
#

So, reinstall and it will be back

tranquil basin
#

Give me a moment I wanna copy and paste the error I got last time.

tranquil basin
#

Wait I think I got fix for my problem.

polar acorn
#

Have you restarted your PC

tranquil basin
polar acorn
#

Clear out your temp folder and then try again

slender nymph
#

also make sure you actually have space on the C: drive

tranquil basin
teal viper
tranquil basin
#

Guys I fixed it by switching to the latest Unity version.

naive pawn
tranquil basin
#

Like I literally showed you guys the error message i got when trying to install a new unity.

#

I was trying to do what you guys told me the whole time it just wasn't working.

naive pawn
open crater
#

Guys how to resize a sprite for a top down square tilemap? Idk why when i drag the sprite in the palette and select it, the sprite is smaller than the squares on the tilemap. I want the sprite size to be the same as the square size

open crater
#

Ok sorry

stuck parrot
#

what is your workflow when creating scripts? Since I am not good at coding I create the base with no variables and logic and write down to do's and I figure out how to make that logic happen. for example here I am trying to make a interaction with NPC, signs, objects and more ```cs using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerInteractor : MonoBehaviour // On Player, is checking if interaction is possible
{
// Variables

public void OnInteract(InputValue value)                                          // Is called by the Input System when "Interact" button is pressed
{
    if ()
    {
        
    }
}

}

/*
To Do's:

  • when interaction button is pressed, check the interaction
  • make the interaction possible if theres actually an interactive object in front
  • if the object is interactable, check what type of interaction is needed (NPC, Sign, Object, Item, etc.)
  • read the information stored on the interactable object (name, text, image, etc.) and return it to this script
  • Display whatever was returned as debuglog
    */``` how would you do it? is that a beginner friendly way or am I overdoing it?
naive pawn
#

that seems about right

stuck parrot
# naive pawn that seems about right

great to hear that im not a complete idiot 🙂 now I know that the right way to do that is raycast, but I never worked with then and dont know how they work. My idea is to give the player a cube that has its collider set to trigger and the mesh renderer off, so i can use that as the detection zone for interactions. would that work?

naive pawn
#

why would it need a meshrenderer

#

you can just have a boxcollider on its own

stuck parrot
#

if i have an actual box i can see whats goin on

naive pawn
#

you can draw debug and gizmos and such as well, you don't need the meshrenderer

#

boxcolliders have wireframes when selected as well

stuck parrot
naive pawn
#

should be able to see them in scene view

stuck parrot
naive pawn
#

are gizmos disabled?

stuck parrot
open crater
#

Guys what's the best way to create a 2d platformer? Tiles or just items? And if we consider tiles, how to create tiles with a collider/rigidbody/scripts and other components?

#

Im talking about 2d

naive pawn
distant orchid
#

Where are they pinged at?

naive pawn
#

for tile collision you can use a tilemap collider+composite collider

austere crypt
naive pawn
open crater
naive pawn
#

not really what i said

#

the tilemapcollider will already make collider shapes for each tile

#

the composite collider merges the shapes together

#

this isn't about grouping tiles

#

both of these colliders would be on the tilemap, not individual tiles

open crater
#

Hmm i'll go check tutorial to understand better

#

Ty 🙂

#

@naive pawn just another question, can i have separate things made of tiles that behave in a different way? For example a level with a platform composed by 4 tiles in a row and then a square with 2x2 tiles that moves up and down?

#

Can i use same tiles but different colliders for this?

rich adder
#

they'd have to be on a separate tilemap if you want separate colliders

#

or just make it a regular prefab and apply it with the prefab brush

#

they won't be traditional tiles though

open crater
#

Ok

prime egret
#

I have a problem with not being able to stop a moving object. I would like to post the code snippet here but i dont know how to create the little code window.

naive pawn
#

!code

radiant voidBOT
prime egret
#
if (cueBallRigidbody.linearVelocity.magnitude < 0.2 && hasBeenHit)
        {
            cueBallRigidbody.linearDamping += Time.deltaTime * 0.3f;
            if (cueBallRigidbody.linearVelocity.magnitude < 0.02f)
            {
                cueBallRigidbody.linearVelocity = Vector3.zero;
                hasBeenHit = false;
                cueBallRigidbody.linearDamping = 0;
                gameController.OnCueBallStopsMoving();

            }
        }
        velocityText.text = "Velocity: " + cueBallRigidbody.linearVelocity.magnitude.ToString() + ";Has been hit: " + hasBeenHit;

this code is in my update function. I also have this debug text, which let me know that the ball is not instantly stopped when hasBeenHit is false. It sort of jitters around for a few seconds before stopping

#

i also am applying some damping at this low speed to simulate how a ball rolling on cloth stops when it has lower speed

wintry quarry
prime egret
#

why is it not instantly stopping when reaching the threshold

wintry quarry
#

Isn't it rolling?

prime egret
#

yes but i have it so that the speed will gradually decrease

wintry quarry
#

rolling is angular velocity, not linear. So it's going to keep a bunch of energy even if you are setting the linear velocity to 0

#

the rolling then will give some linear velocity back due to friction (because that's how rolling works)

#

long story short - if you set angular velocity to 0 too it will stop faster

prime egret
#
if (cueBallRigidbody.linearVelocity.magnitude < 0.2 && hasBeenHit)
        {
            cueBallRigidbody.linearDamping += Time.deltaTime * 0.3f;
            if (cueBallRigidbody.linearVelocity.magnitude < 0.02f)
            {
                cueBallRigidbody.linearVelocity = Vector3.zero;
                cueBallRigidbody.angularVelocity = Vector3.zero;
                hasBeenHit = false;
                cueBallRigidbody.linearDamping = 0;
                gameController.OnCueBallStopsMoving();

            }
        }
#

it still goes backand forth between the hasBeenHit variable being true and false

#

even after setting the angular velocity to 0

wintry quarry
#

i have no idea how it gets set to true

prime egret
#
if (Input.GetKeyUp(KeyCode.Mouse0))
        {


            cueBallRigidbody.AddForce(shotPowerAndDirection, ForceMode.Impulse);
            changeCamera();
            //start decalarating
            mousePressedTime = 0f;
            hasBeenHit = true;
        }
``` It gets set to true when i apply a force "hit" the ball.
wintry quarry
#

if this is the only place you set it to true, then you must be releasing your mouse

#

otherwise - you probably forgot about somewhere else it's being set

prime egret
#

it gets set nowhere else. i will try to do by pressing a keyboard button instead

wintry quarry
#

If so you must be mistaken

#

I'd also recommend using Debug.Log instead of an in-game UI element, you'll get more information like the full sequence of events.

prime egret
#

i added a debug.log and you can still see its being printed twice

naive pawn
#

try adding a debug log to where you're setting hasBeenHit

prime egret
#

okay yeah now it shows it has been set to true twice

#

stil dotn understand how this can happen since getkey up only runs the frame that the key gets lifted

slender nymph
#

make sure you don't have more than one copy of that component in the scene

limpid stratus
#

if it's called in fixedupdate, then step can happen several times over the course of a frame

slender nymph
#

that's unlikely though, unless they are getting sub-50 fps. but it also wouldn't be as consistent

prime egret
#

i am calling it in the normal update

limpid stratus
#

right click the script in your project folder and select find references in scene

#

see if you get more than 1 hit

prime egret
#

is the problem that i am referencing this game object by doing:

public GameObject cueBall;
```?
naive pawn
# prime egret

this would seem to indicate that you have it set to true twice, then you set it to false twice.
the second time you set it to false shouldn't happen, if it were on the same component.

do you perhaps have multiple components of this same type?

#

try adding a context to your logs (eg Debug.Log("...", this);), then check if each of the logs are coming from the right object

naive pawn
prime egret
#

yeah i had the script set to two different gaem objects one being the camera and the other being the actual cueball

#

now it only sets it to true once and stops it moving once

#

i actually have no idea how i managed to do that

#

Thank you

#

however its still needs some time to completely be set to 0

#

from here on its zeroes

cold slate
#

i have a lot of "the referenced script (unknown) on this behaviour is missing" warnings

#

is there a way to fix them without messing the scripts

naive pawn
#

did you do something to cause that, like moving .meta files (or not moving them)

cold slate
slender nymph
#

did you move the .meta files as well?

cold slate
#

i believe i did

#

at least some of them

#

but they may not be in the right place

slender nymph
#

well that would be the problem then

cold slate
#

is it difficult to fix them?

slender nymph
#

if you're using version control, it's really just a matter of reverting to the last good commit. if you're not then you need to check to see if the old .meta files are still available and move them to the right place. if they aren't then you need to fix the broken objects manually

simple hawk
#

can I use unity version control instead of git? not that familiar with version control and wanna just get it set up quickly (forgot to set up git at start of project and getting a headache with lfs)

wintry quarry
simple hawk
#

awesome, thank you

#

I might be making progress with LFS, but ive a feeling something will go wrong lol

solar hill
#

what?

#

can you not spam random memes please

idle saffron
#

Hi, i am a beginner and im having a problem with calling a void which belongs in a game object, being called from a prefab as i cant make a reference. Ive tried using static but i cant get that to work either, what should i do?

solar hill
#

what is it specifically you are trying to do

#

how are you trying to do it

#

and whats happening, vs what is supposed to be happening

slender nymph
polar acorn
#

<@&502884371011731486> spammer

frosty hound
#

?ban 1374720700363051122 Ignoring warning for off topic

eternal falconBOT
#

dynoSuccess zi_danee was banned.

idle saffron
# solar hill and whats happening, vs what is supposed to be happening

so i have a prefab which has already been spawned in the same scene as a gameObject. When the gameObject collides with the prefab, a script within the prefab needs to call a void subroutine in the script of the gameObject. However since it is a prefab, i cannot make a reference to the gameObject im pretty sure. I have tried making the void subroutine a static, but i cant get that to work either.

solar hill
#

of course you can make a reference with the gameobject, you just need to use that instance of it

#

since you are working with collisions you have a simple way of doing it

slender nymph
solar hill
#

you can do something as simple as

void OnCollisionEnter(Collision collision)
{
    // make sure whatever you hit has the script you need to call
    MyGameObjectscript targetScript = collision.gameObject.GetComponent<MyGameObjectScript>();
    if (targetScript != null)
    {
       // call whatever you need to do here!
    }
}```
slender nymph
#

or use TryGetComponent which combines those two lines into one call

idle saffron
#

thx

echo palm
#

Yall to freeze the app can I js use like setspeed(0)

#

Or time.freeze()

idle saffron
#

the void im trying to call is push which is in Birdscript and this is written in PushScript but it isnt recognised? -ignore if the trigger stuff is incorrect

idle saffron
#

it is the void subroutine im trying to call located in Birdscript

polar acorn
#

Is this OnTriggerEnter2D in Birdscript?

idle saffron
#

no this is in PushScript

grand snow
echo palm
#

How

grand snow
#

first thing from a quick google search

echo palm
#

Oh ok

polar acorn
echo palm
#

I'm just gonna follow the brackeys tutorial

polar acorn
#

Do you have a reference to the Birdscript you want to call this function on

idle saffron
#

not yet, this was what i was trying to work out

prisma shard
#

Can any Jetbrains users confirm that it has different "problems" spotted than VS code? Jetbrains brings up lines of code not being used by anything, problematic namespaces etc that i do not see in vs code

polar acorn
idle saffron
polar acorn
idle saffron
#

oh, Bird

polar acorn
#

Is it always a specific object that exists in the scene before you start play mode

prisma shard
polar acorn
eternal needle
prisma shard
#

should have stuck with vs code

eternal needle
prisma shard
#

If these are just typo errors and stuff is there a way i can just easily transfer this to an AI or something enmass

#

I cannot be assed to go through like 500 files like this

eternal needle
#

the "Namespace does not correspond to file location" is not something people commonly do in unity regardless

#

you dont need to go through 500 files lol, just hide the warnings or pretend they dont exist

#

usually your IDE would have some kind of autofix button though. Like at least in visual studio i remember there was a keybind that'd clean up the file and would automatically fix spacing + remove unused usings which is what most of your warnings are

#

Also it suggests names starting with _ which i personally hate using. You shouldn't change your whole style because an IDE has a small 20x20 yellow triangle

winged widget
#

I'm having problems with github, does someone have some free time to help?:))

solar hill
#

ask away

teal viper
#

Just ask your question. Nobody is going to dedicate their time to a problem they don't know anything about.

winged widget
#

mb

#

I'm merging my branch into the main branch

#

and my colleague is doing the same

#

but when we do that, some of our scenes, prefabs, sprites, etc; dissapear

#

and we tried to merge again, and nothing happened

#

we've been here for 3 hours trying to figure this out

teal viper
#

Are you committing the meta files properly as well?

winged widget
winged widget
prime jackal
# prisma shard i dont see these kinds of issues in code vs

as a jetbrains user this also happens to me as it introspects the entire project including packages you import with its own opinionated warning system
you can really quickly get rid of those, though, and if you get used to it it can be extremely good. I don't know how you live with VSCode honestly, I've never had good intellisense there

prime jackal
winged widget
#

let me check

#

sorry if this problem is too obvious, it's my first time using github

prime jackal
#

from what i've heard, merging can generally be a nightmare sometimes

winged flame
#

Hi I'm new to Unity and I've been crashing out for 30 mins because my gun rotation isn't working, I was wondering if anyone could help me out with a quick solution since ChatGPT is wasting my time with solutions that don't work.

I took this model, and my gun is following where my mouse is, which is fun but since everything is pointing right as a standard (the gun also moves up and down with my mouse), it would only make sense that when my mouse goes on the left side of my character, my character flips and looks to the left while also pointing my gun to the left. For my character it works perfectly fine but my gun also kinda mirrors but it's upside down instead of mirroring. Not sure if I can also share my code since it could make my message very long.

teal viper
prime jackal
teal viper
winged widget
#

Basically we were working on different prefabs and I deleted the scene that was no my colleague's branch

teal viper
#

Or you didn't explicitly delete anything, yet it was gone on your colleague side?

#

Which one?

winged widget
#

i wasnt remembering the exact process

#

I just tried to open the main again

#

I'm having this problem now

teal viper
# winged widget I'm having this problem now

That means that the scene asset ID has changed. What likely is happening is that you and your colleague created these scene independently OR did not sync it with each other initially, so it was basically 2 separate scenes with the same file path - the ID is different. Then each one of you kept on committing the id that is correct on their side, basically breaking the project for the other person.

winged widget
#

Oh://

teal viper
#

At least that's one plausible explanation

winged widget
#

The seconds options seems to be what happened

#

Is there some way to solve this?

#

Since we both have important things on our scenes

prime jackal
#

I'm no expert so this might be wrong, but you could both rename the scene as something else so you can merge it and have 2 versions, then manually go in and stitch things together

winged widget
#

We did that but it had problems again://

#

I gtg now
Its pretty late here

#

I’ll be working tomorrow with a fresh head (no so much since i have to publish the project tomorrow as a school project)

#

Thank you guys for your time and patience to be here helping us!

#

Have a great week bye!

winged flame
#

I appreciate the quick response but it hasn't really helped me any further. Maybe my scripts can clear up what I'm dealing with

I'm using PlayerFlip to handle the player's visual orientation left or right based on the mouse position relative to the player.

And PlayerAim rotates the weapon toward the mouse position so the gun always points at the cursor.

at this point I have absolutely no clue on how to fix this annoying issue. ChatGPT keeps telling me to seperate body flipping and weapon aiming completely by only using PlayerFlip to mirror the character visually and PlayerAim to rotate the weapon in world space without any additional flipping or scale changes but eventually leads me to an issue that's even worse or that's just messing everything up

winged flame
prime jackal
prisma shard
#

I am sorry thats just absolutely braindead software design

prime jackal
prisma shard
prime jackal
prime jackal
dire pawn
#

sorry, accidentily deleted it

prime jackal
prisma shard
dire pawn
#

I'm wanting to make a private VR Chat world from KH3 to make Kingdom of corona

prime jackal
#

#notsponsored i even only have the noncommercial version right now

dire pawn
dire pawn
#

I looked there 😅

#

Is there a way to contact mods to ask without having to ping them?

prime jackal
dire pawn
modern lodge
#

this server does not help with VR chat or mods, please find a VR chat specific server

dire pawn
#

not mods, assets

prime jackal
dire pawn
#

map rips are just assets/worlds taken from a game to use in things like Unity

prime jackal
#

I don't think you're going to find those here

teal viper
#

Basically steal other people's work. We don't support this topic here.

dire pawn
#

Oki, sorry for wasting your time. I'm only 16 and my mom doesn't want me spending money on assets. Sorry again/gen

winged flame
#

Okay My Little Pony actually helped me out more than you think. Now it works exactly how I wanted it to. What I did was add this script WeaponFlip to my WeaponPrivot.

#

Thank you for your time <3

sage summit
#

Hello! I'm really struggling trying to understand the concept of event handlers, I'm currently following a 10 hr course of making a game (CodeMonkey) and I'm really confuse as to why certain codes exist and what it does. This is the current which works too.

slender nymph
#

!code it also helps to actually point out which specific code you don't understand

radiant voidBOT
rough granite
slender nymph
#

Also it's much easier to be able to view long blocks of code in another tab and be able to refer back to it

rough granite
sage summit
#

Oh, I didn't realize that's how it looks like

slender nymph
#

that's a mobile screenshot and is how it always appears on mobile

rough granite
#

ahh guess that kinda makes sense but both the functional websites absolutely suck on mobile ~_~
the other point is fair though

naive pawn
sage summit
#

Sorry ! I don't really know how to use those websites. First time here and really desperate too.

naive pawn
#

paste your code in, save, copy the link, paste the link here

rough granite
naive pawn
#

also you can't do other stuff in discord (asking for context, answering other questions, answering unrelated chats) in the meantime without resetting scroll

#

also no search

#

also no folding

sage summit
rough granite
# sage summit https://paste.myst.rs/j21aimz6

it also helps to actually point out which specific code you don't understand
you never specified what the problem was other than "struggling trying to understand the concept of event handlers"
(prolly my fault)

sage summit
#

Sorry! I don't really know what question to ask because I don't really understand it well myself. I only understand that it's good for decoupling, but I guess i'm struggling to read and understand it?

naive pawn
#

so im noticing that use of EventHandler and i don't think ive seen people use those before.. you can typically just use simpler delegates, especially given that you aren't using any of the passed arguments

#

having an Action<Vector2> would probably be simpler and more direct data flow

naive pawn
#

otherwise it's kinda hard to help a vague question

sage summit
naive pawn
#

the += there is a subscription
the performed is an event

when you subscribe, you're telling it to also call that function when the event fires

#

it's like assigning a method that should be called, but it's += to preserve any listeners that have already subscribed

sage summit
#

So, when I press interact, it performs the function Interact_performed? And what does the OnInteractAction?Invoke do?

naive pawn
#

Invoke is firing the event

rough granite
#

firing is a new one
cant tell if you mean calling it, or fire like what an employer does (ie unsubing it)

naive pawn
#

the ?. makes it not do anything if it's null, which it would be if nothing has subscribed

sage summit
#

So in player.cs, GameInput_OnInteractionAction is listening to that event?

naive pawn
#

it's listening to OnInteractionAction, yeah

sage summit
#

I see so it's like a red light green light thing? Press a button and it goes green and everythign thats looking at the light will do their own thing?

#

Sorry I learn from weird analogy way

naive pawn
#

you could imagine it like that, sure

sage summit
#

Okay I kinda get it now, thanks !

naive pawn
#

hmm that analogy feels maybe more like polling

#

could say it's like making a post or sending a message and whoever's subscribed gets a notification

empty steppe
#

Hello

#

Should i write the code lines that i learn?

#

In notes or something

eternal needle
# empty steppe Should i write the code lines that i learn?

You'll quickly memorize relevant code and syntax over time as youre typing it in real work. Copy pasting it from a file isnt going to help you memorize it
Though if you find it easier in terms of accessing quick notes or links to documentation, then sure.

empty steppe
#

maybe if i learn stuff like input

#

I should type down what getkeydown or getaxisraw etc..

eternal needle
#

Usually youd just go to the documentation anytime you need a refresher on what stuff does

#

It'll likely just take you longer to find your notes file compared to googling getkeydown unity

empty steppe
#

Idk tbh

#

Like yes the code is explained if i left click it but i don’t really know where to search in the first place without googling

eternal needle
#

If you have no clue at what the class or methods would be called, google a high level concept of what you want to achieve + the word unity. You'll find results

empty steppe
#

Just a quick question

#

Is there like a place i can find the built in input names?

silk night
#

you mean for UI elements?

empty steppe
#

Yeah

#

(Horizontal, Vertical, etc..)

naive pawn
night raptor
#

Well, technically all inputs would be part of UI, not GUI though. I agree it isn't very clear what is asked here

naive pawn
rare jolt
#

i want my enemy to move around the player but i don't know how to calculate the angle for the enemy to move left or right

#

X = Cx + (r * cosine(angle))
Y = Cy + (r * sine(angle))

naive pawn
#

could you be more specific about what you want the enemy to do exactly

rare jolt
#

oh i found the solution. nvm

#

i just want to set my enemy position based on an angle with the player as the radius point.

real thunder
#

So I am a little confused with the parent constraint component

#

I wanted to spawn a thing and attach it to the body part

#

anyway the point is it spawns properly, in actually behave like it's attached, however, the moment it gets attached it changes it's rotation in a way I don't expect

#
        ParentConstraint constraint = stickie.GetComponent<ParentConstraint>();
        constraint.rotationAtRest = stickie.transform.rotation.eulerAngles;
        constraint.translationAtRest = stickie.transform.rotation.eulerAngles;
        constraint.SetSource(0, new ConstraintSource{sourceTransform = assumed_hit_hitable_part.transform , weight = 1});
        constraint.locked = true;

piece of code I expect to work

#

I am probably misusing the component

wintry quarry
#

constraint.translationAtRest = stickie.transform.rotation.eulerAngles; this is definitely not right

#

translation is an offset in position

wintry quarry
real thunder
#

I will attach a small video in a minute

#

but I don't want to fiddle with them actually being children

#

I think I am starting to get it

#
ParentConstraint constraint = stickie.GetComponent<ParentConstraint>();
        constraint.SetTranslationOffset(0, assumed_hit_hitable_part.transform.InverseTransformPoint(stickie.transform.position));
        constraint.SetRotationOffset(0, (Quaternion.Inverse(assumed_hit_hitable_part.transform.rotation) * stickie.transform.rotation).eulerAngles);
        constraint.SetSource(0, new ConstraintSource{sourceTransform = assumed_hit_hitable_part.transform , weight = 1});
        constraint.locked = true;

way more inconvenient than I expected but it works

rich adder
#

this isn't the place.

#

!collab 👇

radiant voidBOT
# rich adder !collab 👇

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**

serene seal
#

return ItemCosts[itemID];

item costs is a dictionary how would i parse it using a number

serene seal
#

but

Argument 1: cannot convert from 'int' to 'string'
#

sorry should have sent that at the start

polar acorn
#

So your dictionary is keyed off of a string, not an int

open crater
#

Guys how to DEFINITELY delete a tile in my tilemap palette?

#

2d of course

#

Idk why a pink square appear

serene seal
polar acorn
#

To access a dictionary element, you have to give it a key

#

You choose what type that key is

#

You've chosen string

serene seal
#

oh ok i understand now i was thinking of lists

wintry quarry
serene seal
#

yeah but for what im doing a dictionary is easier

open crater
#

Guys how to DEFINITELY delete a tile in my tilemap palette? Of course im talking about 2d. Idk why I have a pink square on my palette, i tried to delete the sprite.

open crater
#

Umm sorry? Calm down

polar acorn
#

You're not getting answered here because it's not a coding question

open crater
polar acorn
#

It's the same answer

open crater
#

I mean less rude than the other one

rich adder
#

get over it

open crater
#

It's a matter of education. nvm

drowsy tiger
#

Has anyone used Obi Rope?
I want to extend the rope based on a rigidbody dynamic attached to the end particle via particle attachment. The ObiRopeCursor supports extending, but its just length rather than actually following the pull on the end of the rope

stuck parrot
#

whats an alternative to ckeck for grounds using rigidbody? cs // ground check isGrounded = Physics.Raycast(transform.position, Vector3.down, groundCheckDistance); depending on the terrain or the players mesh i need a different distance. is there a reliable way or do I guess the value until its working?

rough granite
#

could have a second longer raycast that decides the distance for the ground check based off the type of ground beneath it

rough granite
#

were you not asking how to handle different terrains for the ground check (assuming they need different values, for whatever reason)

#

of course you are going to need to test values to see what feels like the best for the distance of the ground check

verbal dome
#

Why not just do one raycast and check its distance

stuck parrot
verbal dome
#

You can detect a raycast hit, but do nothing if it was too far.
RaycastHit.distance

#

So just do one raycast with the max distance

#

Or I'm majorly missing something here

rough granite
verbal dome
#

It's not super clear what theyre asking

chrome apex
#

I have a mapping system that charts out my movement by making line renderer points and all that good stuff.

But I am having trouble dynamically rotating the map based on the player's rotation such that up on the map matches player's forward.

It's a world space map held on a device in hand. There is also an issue of rotation on all axes since this is about diving and I can orient the player in any way.

This is tripping me up

rough granite
# verbal dome It's not super clear what theyre asking

it isnt, i read what they said as "i have multiple different terrains and each one has it's own distance for the ground check that feels the best. How can i know which value i should use for it if they are all different"
but even then yeah one raycast that's just long with a value to see if the distance is less than would work

stuck parrot
verbal dome
#

(Or OnDrawGizmosSelected probably)

stuck parrot
naive pawn
#

docs, generally

rough granite
verbal dome
rich adder
#

fun fact, unity has built in Queries/Casts gizmos built in the Physics Debugger

verbal dome
#

That's true, though I meant more for tweaking it in the scene view/prefab editing

#

@stuck parrot Magic has a point too, you could always just have code that calculates the ray origin from the character's collider values

#

I also usually prefer spherecast, not raycast

stuck parrot
verbal dome
#

Like what if you are standing on a tiny gap and the ray goes through that?

#

Now it thinks you are in the air even tho youre not

stuck parrot
# verbal dome Now it thinks you are in the air even tho youre not

can I just add an empty as a child of the player and add a box collider set as trigger underneath the player? this way I can control it and actually see it. by the way OnGizmoDraw doesnt seem to work for me ```private void OnDrawGizmos()
{
Gizmos.color = Color.green;

Vector3 origin = transform.position;

Gizmos.DrawRay(origin, Vector3.down * groundCheckDistance);
Gizmos.DrawSphere(origin + Vector3.down * groundCheckDistance, 0.1f);

}```

rich adder
stuck parrot
rich adder
# stuck parrot I do have that

check what I suggested earlier, use the physics debugger enable the queries tab and check what it shows there. must be in playmode tho for that iirc

stuck parrot
rich adder
stuck parrot
#

I enabled all but I dont see anything. But back to the jumping, is raycast a good practise or should I use a small box collider underneath the player? That way tiny gaps in the terrain would not cause issues

rich adder
#

using colliders is the worse method imo

stuck parrot
rich adder
#

raycasts can be made thicker by using a different shape instead of "RAY"

#

ray is just a line

#

boxcast, spherecast etc

stuck parrot
#

good to know, are raycasts only "shot" when for example I press jump or are they there all the time?

naive pawn
rich adder
naive pawn
#

the physics system has no knowledge of you pressing jump

stuck parrot
stuck parrot
stuck parrot
naive pawn
#

is it perhaps obscured by other objects

#

uh hm i guess debug stuff would be drawn on top

#

so hopefully that wouldn't happen

naive pawn
#

have you tried extending the distance a ton?

naive pawn
stuck parrot
#

I also figured out why the physics debugger didnt show anything the first time. I didnt knew it has to stay open, tought it was just settings

verbal dome
#

Is the issue that you aren't seeing the ray when casting downwards (positive value * Vector3 down)?

#

Is it starting from the collider's edge exactly? It might register as a hit