#💻┃code-beginner

1 messages · Page 703 of 1

frigid sequoia
#

How?

eternal needle
# frigid sequoia How?

You go the same route as a regular singleton in c#, except instead of creating a new instance, you load it. There should be a few tutorials out there online exactly for this

nova kite
#

is there a way to avoid what they'd probably call drilling when passiing functions to other scripts?

i have a PlayerStats script and there is a TakeDamage method there

and i need to call that method inside the enemy attack state script

and for that to work i have to first call the enemy state machine, over there make a public field for the player state machine assign it in the inspector, call it, make a field to initialize the player stats script there call it and then call the take damage function, that can not be the easiest way to do this lol

StateMachine.playerStateMachine.playerStats.TakeDamage(attackDamage);

teal viper
nova kite
#

that's a lot of code i need to show in order to explain it😅 what's the norm for showing long code here again

#
using UnityEngine;

public abstract class PlayerState
{
    protected PlayerStateMachine StateMachine;
    protected Animator Animator;
    protected PlayerStats PlayerStats;

    public PlayerState(PlayerStateMachine stateMachine)
    {
        StateMachine = stateMachine;

        Animator = stateMachine.GetComponentInChildren<Animator>();
        PlayerStats = stateMachine.GetComponent<PlayerStats>();
    }

    public abstract void Enter();

    public abstract void Update();

    public abstract void Exit();
}
#

but this is the player state script

#

it's a blue print for every state i make for the player

teal viper
#

State machines need to be as generic as possible, not caring about where, when and how they are used at all.

nova kite
#
using UnityEngine;

public class PlayerStateMachine : MonoBehaviour
{
    [Header("Current State")]
    [SerializeField] private PlayerState currentState;

    public PlayerStats playerStats;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        currentState = new PlayerMoveState(this); // Initialize with a default state

        currentState?.Enter();
    }

    // Update is called once per frame
    void Update()
    {
        currentState?.Update();
    }

    // Method to change the current state
    public void ChangeState(PlayerState newState)
    {
        currentState?.Exit(); // Exit the current state
        currentState = newState; // Set the new state
        currentState?.Enter(); // Enter the new state
    }
}

and the state machine handles the states

#

is that not what i did?

teal viper
#

Why is there a class specifically for PlayerStateMachine how is it different from the enemy. Ideally, use the same state machine by all characters in the game, whether they are players or npcs.

nova kite
#

how would the transitions work tho?

#

because on the player state machine i call the move state as default

#
using UnityEngine;

public class EnemyStateMachine : MonoBehaviour

{
    [Header("Current State")]
    [SerializeField] private EnemyState currentState;

    [SerializeField] public PlayerStateMachine playerStateMachine;

    public Transform [] patrolPoints;

    public Transform playerPosition;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        currentState = new EnemyPatrolState(this); // Initialize with a default state

        currentState?.Enter();
    }

    // Update is called once per frame
    void Update()
    {
        currentState?.Update();
    }

    // Method to change the current state
    public void ChangeState(EnemyState newState)
    {
        currentState?.Exit(); // Exit the current state
        currentState = newState; // Set the new state
        currentState?.Enter(); // Enter the new state
    }
}

while here i call the patrol state on default

teal viper
# nova kite ``` using UnityEngine; public class PlayerStateMachine : MonoBehaviour { [H...

This feels very weird. It's unclear who owns what and what "component" in the system is where in the dependency chain. State machine would usually be on top living directly on the character or some other object that updates it. States should definitely not hold onto state machines as fields. At best they could be provided with it in the methods that the sm calls on these states.

nova kite
#

are you saying i studied it all wrong then😭

#

i spent so much time..

#

they said you need a blue print for each state

fickle stump
#

Hi!
I'm having an UI Element with buttons, that instantiates an object, depending on their index and attaches said object to my mouse cursor.
What I want to do now, is hover that object over other objects and press left click in the trigger zones (that works fine so far!). What I do need help now, is, how can I swap two gameobjects? My trigger zones contains an object, that showcases the outline of an object which could be placed there, but when i left click on that object i want to delete the placeholder and place the object I have on my mouse! (I do know how to destroy the placeholder object :D)

nova kite
#

a state machine to handle the states

#

and the states themselves

fickle stump
#

Sorry for itnerrupting you gyus btw

nova kite
#

no worries!

#

i dont own the channel haha

#

||(yet)👀||

teal viper
nova kite
#

wait im not doing that??

#
 public void ChangeState(EnemyState newState)
    {
        currentState?.Exit(); // Exit the current state
        currentState = newState; // Set the new state
        currentState?.Enter(); // Enter the new state
    }
#

doesnt this do that

#

and then i conditionally call the change state method:

using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UIElements;

public class EnemyPatrolState : EnemyState
{
    public EnemyPatrolState(EnemyStateMachine stateMachine) : base(stateMachine) { }

    NavMeshAgent agent;

    int nextDestinationPoint = 0;

    public override void Enter()
    {
        agent = StateMachine.GetComponent<NavMeshAgent>();
    }

    public override void Update()
    {
        if (!agent.pathPending && agent.remainingDistance <= agent.stoppingDistance && agent.velocity.sqrMagnitude == 0f)
        {
            {
                nextDestinationPoint = (nextDestinationPoint + 1) % StateMachine.patrolPoints.Length;

                agent.SetDestination(StateMachine.patrolPoints[nextDestinationPoint].position);
            }
        }

        if (Vector3.Distance(agent.transform.position, StateMachine.playerPosition.position) < 10)
            StateMachine.ChangeState(new EnemyChaseState(StateMachine));

        Animator.SetBool("Walking", true);
    }

    public override void Exit()
    {

    }
}
#

in the individual states

teal viper
# nova kite is there a way to avoid what they'd probably call drilling when passiing functio...

Anyways, back to your original problem.

  1. You should make a TakeDamage method in the character class(ideally shared for all characters, player or not). Then call character.TakeDamage when youwant to apply damage to a character. The logic of calling the same method in stats should be handled internally to the character.
  2. Provide a reference of the character to whoever needs to deal damage to it, instead of letting it get it via a convoluted chain of references.
teal viper
nova kite
#

yes but the problem is the enemyAttackState is not attached to any game object and is not a monobehaviour so i can't directly assign things to it

#

it's only being called by the state machine

#

that's the only way it runs

teal viper
nova kite
#

omg right the constructor!

#

basically like i do here right?

using UnityEngine;

public abstract class PlayerState
{
    protected PlayerStateMachine StateMachine;
    protected Animator Animator;
    protected PlayerStats PlayerStats;

    public PlayerState(PlayerStateMachine stateMachine)
    {
        StateMachine = stateMachine;

        Animator = stateMachine.GetComponentInChildren<Animator>();
        PlayerStats = stateMachine.GetComponent<PlayerStats>();
    }

    public abstract void Enter();

    public abstract void Update();

    public abstract void Exit();
}
#

passing the animator and playerStats

#

wait is it good to do that tho if not all state need it?

teal viper
teal viper
nova kite
#

i think that script is not properly named tbh haha it just holds a lot of functions😅

#

oof it's too long to send

#
    // Method to handle player death
    private void Die()
    {
        Debug.Log("Player has died.");
        // Here you can add logic for player death, like respawning or ending the game
    }

    public int GetCurrentStamina()
    {
        return currentStamina;
    }

    // Method to restore health
    public void RestoreHealth(int amount)
    {
        if (currentHealth >= maxHealth)
        {
            currentHealth = maxHealth; // Cap health at 100
            return;
        }

        currentHealth += amount;

        PlayerUI.SetHealth(currentHealth);
    }

for example

#

from PlayerStats

#
// Method to take damage
public void TakeDamage(int amount)
{
    currentHealth -= amount;

    PlayerUI.SetHealth(currentHealth);

    if (currentHealth <= 0)
    {
        currentHealth = 0;
        Die();
        return;
    }        
}

// Method to use stamina
public void UseStamina(int amount)
{
    currentStamina -= amount;

    if (currentStamina < 0)
        currentStamina = 0; // Prevent stamina from going below 0

    PlayerUI.SetStamina(currentStamina);

    lastStaminaUseTime = Time.time; // Record the time when stamina was last used
}
teal viper
#

I mean, there are many issues I can point out. But I feel like at this point it would mean rewriting most of your project.

nova kite
#

should i transfer all this logic somewhere else?

#

or is only the name of the script misleading

#

i think this mess happened because i discovered state machines only after doing all of this haha

teal viper
#

Player stats should deal with player stats. There shouldn't be "die" and similar methods that are related to the character as a whole, not just it's stats. "Die" in the context of stats is just setting health to 0. Nothing less, nothing more.

teal viper
nova kite
#

i only did that because i initiazlied all the variables in the same script😅

    [Header("Player's Movement")]
    public float walkSpeed = 5f;
    public float runSpeed = 10f;
    public float crouchSpeed = 3f;

    [Header("Player's Forces")]
    public float gravity = 10f;
    public float jumpForce = 5f;
    public Vector3 velocity;

    [Header("Player's health")]
    private int maxHealth = 100;
    private int currentHealth;

    [Header("Player's stamina")]
    private int maxStamina = 100;
    private int currentStamina;
    private float lastStaminaUseTime;
    private float StaminaRegenerationRateTimer;

    [Header("Player's UI")]
    public PlayerUI PlayerUI;

    [Header("Mouse")]
    public float mouseSensitivity = 2f;
    public float lookLimit = 45f;
    public float rotationX = 0f;
#

so i said might as well make the methods here to access them

teal viper
#

Accessing a stat is fine. It's part of the stats object responsibility

nova kite
#

i meant accessing easily in the same script haha

teal viper
#

Ah, right it's called player state. This is definitely a misleading name especially since you're using it around state machines.

nova kite
#

instead of froma different script

#

nono PlayerStats

#

i also have a PlayerState

#

which is this:

using UnityEngine;

public abstract class PlayerState
{
    protected PlayerStateMachine StateMachine;
    protected Animator Animator;
    protected PlayerStats PlayerStats;

    public PlayerState(PlayerStateMachine stateMachine)
    {
        StateMachine = stateMachine;

        Animator = stateMachine.GetComponentInChildren<Animator>();
        PlayerStats = stateMachine.GetComponent<PlayerStats>();
    }

    public abstract void Enter();

    public abstract void Update();

    public abstract void Exit();
}

#

this one is clean haha

teal viper
#

Why is it a state even? What does it represent logically? Can a character transition into or out of it? So, like can a player become an enemy?

nova kite
#

no this is the blue print for every player state

#

its all abstract

#

which from my understanding forces every script inhereting from it to have these methods

#

while also being able to pass it thigns via the constructor

teal viper
#

Then maybe a StateDefinition or something is a more appropriate name. But then again, I'm not sure why you need it in the first place.

nova kite
#

thats true haha

nova kite
#

i learned it from a few videos

#

i was lost at first too

teal viper
nova kite
#

hmm so it's more about C# than Unity?

teal viper
#

Not C# even. The same applies to many OOP languages

nova kite
#

So if i want to have a greater understanding of it i should look up C# OOP videos?

#

oh it's handled the same?

nova kite
#

across languages

#

i see, thank you!

#

i thought it's a Unity thing lol

teal viper
nova kite
#

Thank you!!

#

that clears things up

teal viper
#

A big part of it comes from experience, but learning the OOP principles can get you started.

nova kite
#

i barely ever scratched the surface with that so it will defiitely be helpful!

twilit slate
#

Sorry for interrupting, can someone help me really quick. I've been trying to make a rocket league type game and ive been trying to make a system where the goal effect color can change depending on which side it lands. But it just refuses to change color

eternal needle
eternal falconBOT
twilit slate
#

I have just solved them and the particles still dont change color

polar acorn
twilit slate
#

I have no idea. Because everylast script has the effect refrence. but every attempt I make to change the color doesn't work. It just stays white.

polar acorn
#

So, did you check?

#

What did the log say

twilit slate
#

I don't mean to be annoying but how do i have it log the color

#

I'm not good at this i'm sorry

digital parcel
#

guys so now i wanna see what my main camera prespective looks like but idk how to change it, now my game section i mean the circle sign one its showing backgroundcamera prespective but i want it to show main camera prespective like the arrow one

#

do you guys know how to change it?

frosty hound
#

Also consider not using Free Aspect mode and changing it to 16:9.

twilit slate
polar acorn
twilit slate
#

Red

digital parcel
#

and yeah i've scale it to 16:9

polar acorn
twilit slate
#

My bad. It says this

polar acorn
#

Okay, so that's more what I was expecting. This shows you're not using values in the 0-255 space and that your alpha is not 0. Where in the code are you logging it? Send it via !code instead of a video this time

eternal falconBOT
twilit slate
polar acorn
twilit slate
nova kite
odd holly
#

how do I fix this?

rich ice
#

get rid of system.numerics or just manually pick which one you're using by typing out the full name

naive pawn
#

why do you even have Numerics imported

#

it was probably a suggestion that you accidentally accepted?

odd holly
#

I figured it out using google

#

I forgot to check back here before google Im sorry 😭

nova kite
#

anyone knows why am i still taking damage even tho im not withing the collider?

what this does is calling this script on a specific frame of the enemy's animation and it's calling this overlapSphere function to see what it would collide with and then check if one of them has the player tag

#

but even when im outside of range that i visualized for debugging it tags me

sour fulcrum
#

Have you chucked a debug log in that function

nova kite
#

logging what?

sour fulcrum
#

That it happened

nova kite
#

it all works perfectly the only problem is that i still get hit when above it

#

you can see the healthbar in the video haha

sour fulcrum
nova kite
#

i can show its code

#

it calls this function

#

from another script

teal viper
#

Add logs. If you see it printed twice when it's supposed to be once, look at the callstacks

sour fulcrum
#

You claim your still taking damage even though your not in the collider

that means

A. you are in the collider
B. something else is giving you damage
C. some other weird thing etc.

#

you need to narrow down what exactly is happening in order to determine why it should or shouldn't be happening

nova kite
#

i see, lemme see what i could add

#

could the size of that sphere be off even if i pass it directly in the code?

brazen oxide
#

maybe your collider's size is bigger than the actual object?

sour fulcrum
eternal needle
sour fulcrum
#

log to see if the sphere check is even running ^

nova kite
#

ohh

eternal needle
#

also dont use ?. on unity objects

#

in that hit.GetComponent

nova kite
#

oh does that not check for null?

sour fulcrum
#

it's a weird unity quirk-ish

nova kite
#

oops haha

eternal needle
#

https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Object.html

The null-conditional operator (?.) and the null-coalescing operator (??) are not supported with Unity Objects because they cannot be overridden to treat detached objects objects the same as null. It is only safe to use those operators in your scripts if there is certainty that the objects being checked are never in a detached state.

sour fulcrum
#

just dont use that ? syntax on UnityObjects (monobehaviours, scriptableobjects etc.)

#

it's a relatively niche thing and easy to not know

nova kite
#

oh god i gotta change it in so many places XD

eternal needle
#

it seems the docs were updated because it never stated when its safe to use before, although it was already kinda obvious

nova kite
#

i used it in the state machines too😭

eternal needle
#

but either way I wouldnt use it because you could think its safe while its not, leading to hard issues to debug. for consistency sake too

sour fulcrum
#

easy to fix in a little bit

eternal needle
#

this is literally not possible to be null

nova kite
#

i added it everywhere just in case hahaha

#

cuz i hate the if (!null) it's too bulky XD

teal viper
#

Is currentState even a MonoBehaviour or unity Object?

#

If not, then it's fine to use ?

nova kite
#

how is this for logs?

sour fulcrum
#

A little much but more is better than less

#

check the problem and see what logs run or dont run

eternal needle
#

!code also, this is a pain to copy for writing examples

eternal falconBOT
nova kite
#

all passed

sour fulcrum
#

is that what should happen

nova kite
#

yup! the script runs it hits all nearby objects

#

finds the one with the player tag

#

and gives it damage

sour fulcrum
#

did the problem occur

nova kite
#

when i jump above it? lemme see

#

same logs when jumping above it

sour fulcrum
#

is that what should happen

nova kite
#

and only these logs when running away from it

#

so the problem seems to be only vertical

nova kite
#

vertically

glossy carbon
#

Good morning everyone

sour fulcrum
#

I mean more literally

nova kite
glossy carbon
#

new Nooby question 🙂

eternal needle
# nova kite i added it everywhere just in case hahaha

Imo its also pretty bad to throw in checks everywhere just to avoid errors. Ill use the state machine as the example but this applies to everything. in your state machine, do you explicitly want to allow a null state where an enemy cannot do anything? this seems like the game would be in a broken state if this was possible, yet your code would not notify you of this when testing because theres no error

sour fulcrum
#

you tested scenario 1: not jumping, logs reflect intended behaviour
you tested scenario 2: jumping, do logs reflect intended behaviour?

the thing with this kinda issue is it doesn't really "matter" what the code is actually doing, it's narrowing down if the code is doing what your want it to do or not

Your either failing to tell it to do the right thing or your succeeding in telling it to do the wrong thing

glossy carbon
#

I have added these to a sprite of a space station that im trying to make collision detection for a space ship but its not working and my spaceship just flies right over the top :s. Ive watch a bunch of vids and looks on forums but im missing something still

nova kite
glossy carbon
#

sorry im sure this is simple to you guys but i just cant seem to see what ive missed

sour fulcrum
nova kite
#

omg right cuz im not assigning anything in the inspector XD

nova kite
sour fulcrum
#

if something needs to not be null hiding the problem away with a null check doesnt fix it

#

sometimes the cars gotta crash if its broken

eternal needle
nova kite
#

ill just remove them haha, but any ideas for the sphere?😅

sour fulcrum
#

again you gotta look at your logs

nova kite
sour fulcrum
#

whats happening that shouldnt be happening
whats not happening that should be happening

#

i mean this code wise

nova kite
#

but it's all perfect from the logs🥲

glossy carbon
sour fulcrum
eternal needle
nova kite
#

that it's all giving the values im expecting

nova kite
#

vertically

#

Debug.Log($"Y difference to shockwave: {yDifference}, max allowed: {maxHeight}");

polar marsh
nova kite
#

is there no different way to do this btw

#

like just using the on collider enter🥲

#

or is it not possible with the OverlapSphere

nova kite
eternal needle
nova kite
#

oh wait

#

should it be kinematic

glossy carbon
nova kite
#

i think he means like literally how it's moving in the game

#

that you said it wont collide

eternal needle
glossy carbon
#

you nailed it the ship needed a collidor

nova kite
#

oh lol

glossy carbon
#

its working now thank you

#

can you add more than one collider to sprites?

#

as i want the space station to have docking areas but i need a collider with a trigger to run a script right?

#

also is there a way of only seeing the spaceship so i can adjust the collider without all the busyness on the screen?

silk night
#

also if you want the icons there removed, you can temporarily turn off gizmos at the top right above the scene view

odd holly
#

How do I fix this...?

sour fulcrum
#

conditions dont use ;

odd holly
#

Im just dumb...

glossy carbon
bright zodiac
naive pawn
#

i mean those aren't exactly exceptions, just different contexts

#

it's not that conditions don't use ;
it's that control flow statements take 1 statement and a ; can serve as that statement

bitter charm
#

ok sorry

native flame
#

is the character controllers isGrounded check essentially useless or do I just not know how to use it?

silk night
#

it would be beneficial if you describe what issues you are having with it

naive pawn
#

the isGrounded check basically checks if it hit the ground, not if it's currently near the ground

#

so if you don't apply gravity, it's basically hovering 0 units above the ground and not actually on it

native flame
#

hmmm okay, thanks for the tip

#

rn i only have gravity applied if !isGrounded

#

ill try it out

silk night
teal viper
#

I'd avoid using character controller at all.

native flame
silk night
#

yes, in that case it would be better, really depends on your game

naive pawn
#

which one is "superior" depends on your intent and the possible level layout

silk night
#

if you have a flat world and you just want to check if you can jump again a raycast is fine, if you have edges your suspicion is right

reef patio
#

the animator is being hard on me for a 3d character

native flame
#

did u say please?

reef patio
hexed terrace
reef patio
#

Something broken.

#

I'll go there.

#

Thanks.

odd holly
#

my little smooth brain cant understand what Im supposed to do...

north kiln
#

Also, local variables should be camelCase, not PascalCase

teal viper
odd holly
frail hawk
#

so you are making a game without knowing how to make one

teal viper
odd holly
#

it worked before

teal viper
#

Then take your time

odd holly
#

I was in another game jam before and it turned out well

teal viper
#

Well it doesn't seem so.

odd holly
#

This is the tutorial

#

Im pretty sure I have the same thing as it

#

So I don’t know why mine isn’t working

north kiln
odd holly
#

The pm is because they were talking GetSlipeMoveDirection from the PlayerMovement script but I just coded the Slide in the PlayerMovement script from the start

#

I don’t know if that messed it up or not

frail hawk
#

can you show the whole script as code

odd holly
#

I can show my code but not the video

frail hawk
#

yeah, that

odd holly
#

The whole script or just the part Im talking about?

#

The whole script is like 300 lines so I don’t think it’ll fit in a discord message

frail hawk
#

!code

eternal falconBOT
odd holly
#

I dont know why it copied like that

frail hawk
#

this doesn´t help, it is missing the important part you are talking about

odd holly
#

It is…?

frail hawk
#

just use a code bin

north kiln
#

Presumably because you failed to paste it between the backticks. Use a paste site instead.

odd holly
north kiln
#

use a paste site instead

odd holly
#

how do I do that...?

frail hawk
#

scroll up and read what the bot posted

north kiln
#

I've already pointed out the problem and linked a resource, but it seems to be ignored in favour of this mad

#

The code in the magenta scope has no idea about the code in the blue scope

odd holly
#

so how do I make them know about eachother...?

north kiln
#

You don't

odd holly
#

I put the code in the website thing

#

now what do I do...

north kiln
#

You declare things in an outer scope if two inner scopes need to use them. As the code in your tutorial has done

odd holly
#

I think Im just blind because I literally do not see any difference between the tutorial and my code

north kiln
odd holly
#

Besides the pm

odd holly
keen dew
#

How do you think are these even remotely similar

odd holly
#

does the pm thing really matter...?

#

I thought that if I just put all the code in the folder it was reffering to I wouldnt have to deal with that

keen dew
#

the other line

odd holly
#

there is not way Im this much of a dummy...

#

Im just blind

frail hawk
#

you are not blind you just have to read what people and the dyno bot post

#

and before diving into game dev, at least learn a few basics of c#

odd holly
#

Hmm…. This is the toughest game of spot the difference ever…

#

Now I really dont know the difference

#
    {
        if (!OnSlope() || rb.linearVelocity.y > -0.1f)
        {
            rb.AddForce(InputDirection.normalized * SlideForce, ForceMode.Force);
        }

        else
        {
            rb.AddForce(GetSlopeMoveDirection(InputDirection) * SlideForce, ForceMode.Force);
        }
    }```
#

really only difference I see is the pm.

north kiln
#

And now what's the error

drowsy flare
#

I'm using the ColorCurves class in a Volume, to change the look of my game.
It all works well when configuring the TextureCurve from the editor. But I just can't understand how to configure it from code. Any ideas?

Edit: nvm sorted it

odd holly
north kiln
odd holly
#

idk what that means 😭

#

Im very bad with vocabulary

wintry quarry
#

int x;

#

This is a variable declaration

#

All your variables need them

#

Where is that done for InputDirection?

keen dew
#

Now you just removed the Vector3 InputDirection = ... line instead of moving it in the right place

#

look at the tutorial, find where it is there, and put it in the same place

odd holly
wintry quarry
#

Sounds like a problem!

odd holly
#

maybe thats the problem...

north kiln
#

And hence that's why it says it doesn't exist

odd holly
exotic cypress
#

guys i have a problem that do not print my text in unity's console.

slender nymph
#

is that component attached to a gameobject in the scene

#

they're passing a string variable

odd holly
#

I didn’t realize what they did

#

I didn’t read the full thing just the end

odd holly
#

You have to have it attached to something in the scene

slender nymph
#

*in the scene, not just in the project

#

hence why i specified "in the scene" in my question

exotic cypress
odd holly
#

I forget vocabulary

odd holly
#

I think that would work

slender nymph
eternal falconBOT
#

:teacher: Unity Learn ↗

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

odd holly
#

Now Im even more confused

#

I don’t have any errors but the thing it’s supposed to do isn’t happening

#

its supposed to make it where when you slide down a slope it doesnt do this wierd bouncy thing

#

but its still doing it

#
    {
        if (!OnSlope() || rb.linearVelocity.y > -0.1f)
        {
            rb.AddForce(InputDirection.normalized * SlideForce, ForceMode.Force);
        }

        else
        {
            rb.AddForce(GetSlopeMoveDirection(InputDirection) * SlideForce, ForceMode.Force);
        }
    }```
#

what difference

#

The only difference I see is the timer which Im 99% sure is optional and the pm. which I dont think I need

#

because pm. refers to the PlayerMovement script because the tutorial used two seperate scripts but I just put the slide code in the PlayerMovement script because I didnt think it would change anything

naive pawn
#

debug some values and check the flow to make sure it's what you expect

odd holly
#

I am very bad at vocab

silk night
#

what IDE are you using?

odd holly
silk night
#

!vscode

eternal falconBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

silk night
#

set it up properly and then you can attach the debugger to unity

#

so you can see values of variables in real-time

naive pawn
silk night
naive pawn
silk night
#

im not familiar with vscode, so no idea

naive pawn
#

it's the same thing in VS

#

not sure about rider though

silk night
#

just wasnt sure if highlighting is maybe working by default
and yeah im using rider, so neither familiar vs nor vsc 😄

naive pawn
#

i can't actually find examples of unconfigured rider in this server lmao

silk night
#

cause rider brings plugins by default, its basically made to use with unity 😄

odd holly
silk night
silk night
naive pawn
#

it's less flexible but less setup

odd holly
#

I got a debug session earlier

#

but its just breaking now

silk night
#

also a video or something would be good to see what it does rn, "this weird bouncy thing" sounds ominous 😄

sharp mirage
#

how would i implement a 1 second cooldown to using this coroutine

#

my brain aint working rn

naive pawn
odd holly
#

wait Ill turn it into an mp4

naive pawn
naive pawn
#

it's [mask](link) or [mask](link "hover text"), btw

silk night
#

yeah i typed something and then pasted that over it, instead of pasting over it converted the old text to a link title 😄

#

"new" function of discord

naive pawn
#

new "function" of discord

#

i really want to be turn that off lmao

silk night
# odd holly

then i would first check the result of the GetSlopeMoveDirection

odd holly
#

the guy in the tutorial said it supposed to do the bouncy thing and gave the fix but I implemented the fix and its still doing it 😞

sharp mirage
#

whoops

#

thanks

naive pawn
#

oh you're following a tutorial?

#

make sure you're following it accurately then

silk night
placid bay
#

hey everyone, im trying to make a 3d movement system and i almost have it working my only problem is when walking or jumping into the side of an object the player physics doesnt work very well as it will float or not move side to side. to fix this i added a physics material that removed friction from the block and this worked great but i only want it to affect the side of the object and not the top so i can still walk on it fine. or if someone thinks there is a better way of doing it the please lmk, thank you in advance.

raw tulip
#

Everytime I commit to my branch on github then another person merges, it always causes merge conflicts n blows up the repo, is this a common problem in game dev or is this my issue?

slender nymph
#

sounds like you're modifying the same files at the same time which is usually something you'd want to avoid. but you should also make sure you set up your repo to use unity's unityyamlmerge tool to help with handling merging yaml files (like scenes and prefabs)

grand snow
#

Merge conflicted scenes can sometimes be merged manually but often not so making use of prefabs more helps

raw tulip
grand snow
#

I have done this before where I make a duplicate, pull changes, resolve using theirs and copy/re do my changes

silk night
grand snow
#

There is this tool from unity to merge yaml but I never got it to work

sharp mirage
silk night
sharp mirage
#

and then under that i can do my if statement right?

silk night
#

your input handling already checks if isRolling is false and doesnt do anything otherwise

sharp mirage
#

yea but lets say the player is trying to roll again but its on cooldown for that 0.5 wait period

silk night
#

yeah the variable turns to false AFTER that 0.5s allowing the player to jump again AFTER it

#

or do you want to buffer the jump?

#

so if he presses in that 0.5s he waits until after the cooldown and then jumps?

sharp mirage
#

nah none of that i just want the game to let the player know that they cant roll in that 0.5 period until its done if they do try to do so

#

a buffer isnt a bad idea tbf

silk night
#

do you want to put out a warning sound / message to the player?

sharp mirage
#

yep

silk night
#

you can do that in the else branch of your input if

sharp mirage
#

alright

silk night
#

unless you only want to show it in the 0.5s, that method i described would output it during the whole jump if the player presses again

sharp mirage
#

like so?

silk night
#

then it would output also if the shift key is not pressed 😄

#

do else if (isrolling == true) (pseudo code)

sharp mirage
#

oh yeah

#

well

odd holly
#

Yeah this singular bug that people will barely ever even run into has taken like 2 hours of valuable ass game jam work time so Im just going to move on

sharp mirage
#

rolling being true doesnt necessarily mean that its on cooldown right

#

because what im doing is just yield waiting 0.5 seconds after ive reset the collider size

silk night
#

it means the player is currently rolling OR its on cooldown

sharp mirage
#

yep

silk night
#

oh then you can work with a new variable that says isRollOnCooldown

#

you set it to true before the 0.5s wait, and false after

sharp mirage
#

could do

#

but hold on why did u suggest to put the wait for seconds before is rolling = false

#

should it not be at the end

silk night
#

because in your current version you can roll again once isRolling = false

#

so it wouldnt wait for the 0.5s

sharp mirage
#

ahh yeah

silk night
# sharp mirage ahh yeah

You can either work with a 2nd variable as I said above or you can implement a simple state system for the roll

basically a variable that contains an enum:

    public enum RollState 
    {
      Ready = 0,
      InProgress = 1,
      OnCooldown = 2
    }

    void Update()
    {   // If roll button is pressed and player isn't already rolling start the roll coroutine  
        if (Input.GetKeyDown(KeyCode.LeftShift) && playerattributes.rollState != RollState.InProgress)
        {
            if (playerattributes.rollState == RollState.OnCooldown)
            {
              // Notify player roll is on cooldown
              return;
            }
            StartCoroutine(Roll());
        }
    }

    private IEnumerator Roll()
    {
        playerattributes.rollState = RollState.InProgress;
        playerattributes.PlayerCollider.size = new Vector2(originalsize.x, originalsize.y / 2);
        yield return new WaitForSeconds(playerattributes.RollTimer);
        playerattributes.rollState = RollState.OnCooldown;
        playerattributes.PlayerCollider.size = originalsize;

        yield return new WaitForSeconds(0.5f);
        playerattributes.rollState = RollState.Ready;
    }

sharp mirage
#

im not familiar with enums and state systems tbh

#

ill look into them

silk night
#

enums are easy to understand, you can see it as "names for numbers" and you store that number in a state property, then you can react on the current state

sharp mirage
#

yep

#

kinda feels like boolean with extra steps

silk night
#

a boolean with more values 😄

#

what i did above cant even really be called a state system, its a very very simplified

uncut echo
#

Hello, can someone help me pls ? I'm my second prototype / learning game, with actual movements in 3D. Getting this error:
Assets/Scripts/InputManager.cs(8,13): error CS0246: The type or namespace name 'PlayerMotor' could not be found (are you missing a using directive or an assembly reference?)

Code:

using UnityEngine;
using UnityEngine.InputSystem;
public class InputManager : MonoBehaviour
{
    private PlayerInput playerInput;
    private PlayerInput.OnFeetActions onFeetActions;

    private PlayerMotor motor;

    void Awake()
    {
        playerInput = new PlayerInput();
        onFeetActions = playerInput.OnFeet;
        motor = GetComponent<PlayerMotor>();
    }
    
    void FIxedUpdate()
    {
        Vector2 input = onFeetActions.Move.ReadValue<Vector2>();
        motor.ProcessMove(input);
    }

    private void onEnable()
    {
        onFeetActions.Enable();
    }
    private void onDisable ()
    {
        onFeetActions.Disable();
    }
}
slender nymph
#

do you have a component called PlayerMotor

silk night
#

also your FixedUpdate, OnEnable and OnDisable methods are capitalized wrong, just as a sidenote

slender nymph
#

seems like a case of unconfigured !IDE

eternal falconBOT
uncut echo
#

ty

uncut echo
slender nymph
#

that is a gross misunderstanding of what is going on here. you should stop what you are doing and follow the beginner pathways on the unity !learn site (after you've configured your IDE of course)

eternal falconBOT
#

:teacher: Unity Learn ↗

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

uncut echo
#

alright, thank you

uncut echo
polar acorn
uncut echo
#

A script that handles the player movement system ?

polar acorn
uncut echo
#

Im so dumb 😂

#

I thought it was a Unity module

slender nymph
#

here's a fun fact: the name of the script file has nothing to do with the class inside. your class is not named PlayerMotor

silk night
#

After seeing the other script, i am betting $5 on a capitalization error!

slender nymph
#

that or it's still named NewBehaviourScript or whatever the default name is

uncut echo
#

It was my "public class" that was called "NewMonoBehaviourScript". ty guys

#

C# is so different than other languages

silk night
slender nymph
uncut echo
#

I mean in the logic

slender nymph
#

logic is the same across all languages because logic does not fundamentally change

uncut echo
#

😌 😮‍💨

vital vault
#

how to get mouse pointer position like that

slender nymph
#

for what purpose

vital vault
silk night
#

its usually 0-1 based, not -1 - 1

slender nymph
#

you just need to convert from screenspace to viewport coordinates

silk night
#

i mean with simple math you can get the other range, but i dont see a reason 😄

slender nymph
#

but it would give 0-1 not -1 to 1

vital vault
shell sorrel
#

what you want is viewport coords they are 0 to 1 but you can easily remap to -1 to 1 if needed

sharp mirage
silk night
silk night
sharp mirage
silk night
#

also for a float, never check if its == or != a specific number

#

always do greater than or smaller than checks with <, >, <=, >=

#

oh wait, your last condition will never be false because of what i just wrote, you subtract Time.deltatime from it, you are below 0, not exactly 0

sharp mirage
#

oh so i could just do <= 0

silk night
#

yes

#

well in the case of the message you want > 0

#

because you wanna check if there is still some cooldown time left

sharp mirage
rocky wyvern
#

what are we meant to do for concave colliders on an rb?

#

I just want a physics enabled bowl lol

silk night
#

you can break the mesh up into multiple smaller colliders

#

there are also assets in the store that do that for you automatically, not sure if there are any free ones though

shell sorrel
#

not too hard to break up a shape in blender to a bunch of convex ones

#

you just end up with a lot of edge shapes making up concave curves

rocky wyvern
#

is for a sphere where you want it somewhat accurate

#

for like a box sure

polar acorn
gray rivet
#

im so confused whats wrong with this code 😭

rough granite
#

Secondly you are applying 2000 "force" each fixed frame without input meaning your player is moving uncontrollably each fixed frame

gray rivet
#

oh no i changed that in the variable tab

#

down to 300

rough granite
#

It's still moving uncontrollably each frame cause its outside of an input statement

#

Unless that's intended

gray rivet
rich adder
gray rivet
#

i think i know why

rich adder
#

AddForce is already moved on fixed ticks

gray rivet
#

embarrassing

rich adder
# gray rivet

the time isnt relevant. bad tutorial is a bad tutorial regardless

rough granite
#

AddForce already has its own fixed time and you have it in FixedUpdate witch is also fixed time

gray rivet
#

this is his and its working perfectly fine

rich adder
#

another garbage brackys tutorial, what a surprise

rocky wyvern
rough granite
rough granite
gray rivet
#

okay i got it

#

so let me see if i can try and fix this myself

#

wit hur help obv

#

idk what im saying

rich adder
#

its very simple, just remove Time.deltaTime from all the AddForce calls.. this way the numbers also don't have to be cranked up so high

naive plank
#

Hey! I'm using unity's animation rigging package in combination with normal animations. Since im using the rig building I can no more rotate the whole armature in the players local space, how would I go abound replicating the same effect?

naive plank
#

mb

gray rivet
#

what else would be making this not work? (sorry for being a pest im just really new)

rich adder
#

also the second addforce is going to keep running if D is not pressed

gray rivet
#

is that big enough

rich adder
#

You'd have to go and switch it to Both, or OLD only, to be able to use Input class

gray rivet
#

Where can i change that

rich adder
gray rivet
#

i think i found it

polar acorn
#

I feel like we should get a bot command for that one

#

Since they changed the default input type it's like 90% of the questions here any more

gray rivet
rich adder
gray rivet
#

yeah that makes sense

rich adder
#

in time you should learn the new input system though, its far better and not that much more difficult

gray rivet
#

where can i find stuff on it?

rich adder
eternal falconBOT
#

:teacher: Unity Learn ↗

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

rich adder
gray rivet
#

thanks man, this will not be the last u will be hearing from me

hot wadi
#

If I use OnTriggerEnter or OnCollisionEnter in a parent object with Rigidbody, does it automatically detect collision on all child objects with colliders?

rich adder
hushed ice
#

Just made myself a working tech demo, it’s largely 2D but I want to have a minigame in another scene in a 3D world space. I read it’s possible but I can’t make heads or tails of it, no matter what I do the camera still appears to be in a 2D mode

hexed terrace
#

Don't use an ortho camera

rich adder
hushed ice
#

No that’s the first thing I did, no change

hexed terrace
naive pawn
#

you changed the actual camera component, and not the scene camera, right?

hushed ice
#

I appreciate that thank you

hushed ice
hushed ice
#

I’ll be sure to post in the right channel if I have issues. Posted in here cause I saw there might be a code component to it

rancid tinsel
#

any idea why the removing bit doesn't work? trainLength points to the value that I'm changing, so there definitely are more trainCars than trainLength, yet they're not being removed.

umbral bough
#

Hey, I am testing Unity 6.3 and noticed that I have to explicitly do this now in order for the default map to be active:

InputSystem.actions.actionMaps[0].Enable();

I am positive this wasn't the case in 6.0, am I mistaken?
Again, it's the default map that should be project wide.
If this is a bug, where should I report it?

rancid tinsel
naive pawn
#

also for future reference, !code

eternal falconBOT
rancid tinsel
rancid tinsel
naive pawn
#

it being text just makes it easier to reference

ruby python
#

Hi all, I'm looking at building a dynamic bullet impact system, simply put if a bullet/raycast hits a type of object, a certain type of impact/decal is played/placed (at the moment my prototype is using tags), but I need to to also work on a terrain and be dynamic based on the terrain layer the bullet/raycast hits.

Would anyone have any pointers, or a resource (tutorial etc.) on how to achieve such a thing please? I'm not really sure what the search term should be for el goog

rich adder
ruby python
# rich adder I've seen people use the texture / some type of mapping with that to play speci...

Yeah, that's what I was thinking. The problem is, everything I've found ONLY applies to terrain, and I can't see how to apply it to gameobjects etc.

But, typically, I have just found something from llam academy and seems to look like what I want to do.

https://www.youtube.com/watch?v=kT2ZxjMuT_4

A common need in video games, to increase immersion of the player, is to add some effect when an impact is made. Using this system whenever an impact is made by any arbitrary action in your game, you can simply call SurfaceManager.Instance.HandleImpact() and this system will utilize Scriptable Objects to determine which effects to play. This all...

▶ Play video
rich adder
#

ya tbh its even easier on materials/ gameobjects than terrain so you're covered then, their videos are good so i'm sure that will work well

ruby python
#

Yeah, it's looking promising so far.

nimble apex
#

if i want function A to always listen and execute whenever function B is called, i use events rather than action right?

#

trying to use event approach as it can be less expensive?

grand snow
#

both are the same

#

events are better because then anything can subscribe to be notified when "event a" happens

naive pawn
#

events are just a specific use of actions

nimble apex
#

i have an implmenetation actually

    public override void OnNetworkSpawn()
    {
        InputManager.Instance.EnableControl();
        MoveInput += InputManager.Instance.joystickCore.OnDrag;
    }
    
    private Action<PointerEventData> MoveInput = (PointerEventData evt) =>
    {
        Vector2 input = InputManager.Instance.joystickCore.Direction.normalized;
        if (input == Vector2.zero)
        {
            input = InputManager.Instance.playerInput.Player.Move.ReadValue<Vector2>();
        }

        Debug.Log(input);
    };```
#

u can assume timing has no issue and ignore backend/network stuff, that isnt important here

grand snow
#

public event Action MyEvent; 😃
public Action MyShitEvent; 🙁

rich adder
#

ya use event keyword

#

also prevents outside classes from invoking this

nimble apex
#

ok

#

ohhhhh i see it became pink now

naive pawn
#

what theme makes it pink?

rich adder
#

and make it public otherwise no one can sub to it 😆

grand snow
#

event keyword enforces certain restrictions making it more reliable for event usage

nimble apex
#

this is actually "callback"

rich adder
grand snow
#

best reason

rich adder
grand snow
#

fancy list of function pointers

rich adder
#

"calling back" some code through delegate

nimble apex
# grand snow fancy list of function pointers
    public void OnDrag(PointerEventData eventData)
    {
         //use event data (onpointerdown)
    }```

you can treat this as void start()
```cs
    public override void OnNetworkSpawn()
    {
        InputManager.Instance.EnableControl();
        MoveInput += InputManager.Instance.joystickCore.OnDrag;
    }```

```cs
    private event Action<PointerEventData> MoveInput = (PointerEventData evt) =>
    {
         Debug.Log(input);
    };```

i still need to invoke moveinput right? even if its registered to OnDrag(), like the debug log inside wont call if i dont make invoke somewhere else?
#

btw moveinput doesnt even need pointer event data, im making it 1 param only because if i dont do that i cant register action to OnDrag

grand snow
#

you can use a anonymous func to sub

#

event += (blah) => OtherFunc();

nimble apex
#
MoveInput += (PointerEventData evt) => InputManager.Instance.joystickCore.OnDrag(evt);```?
grand snow
#

can be the other way too im sure you can figure it out:
event += () => OtherFunc(null);

half lantern
#

hi, i'm making a multiplayer game. Currently, I have a time manager script which has public events. It handles the game time and invokes the events at the right time. Right now, there are 8+ events. Lots of different scripts have subscribed to each event. Is this bad practice? If so, is there any alternative?

shell sorrel
#

seems fine

#

events is way better then having it calling stuff all over

half lantern
#

isnt that high coupling or something (im not sure what its called)

shell sorrel
#

just keep in mind even if the objects are disabled the events still will get called

#

also coupling will happen, its just controlling where it is

grand snow
#

well duh

rich adder
half lantern
#

the time manager has a variable for the time, and when a certain amount of time has passed, it invokes an event

#

most of the events are invoked on the server but some on the client. for the ones on the client, i send a client rpc to invoke them

stoic summit
#

https://pastecode.io/s/brq9775q

hi, this code works as intended, just looking for a peer review so I can improve if possible. Meant to be a code based alternative to unity's in built animator because I hate its guts.

nimble apex
grand snow
#

Did you subscribe multiple times?

#

Subscriptions remain until you unsubscribe manually OR set the whole event to null

nimble apex
#
    public override void OnNetworkSpawn()
    {
        InputManager.Instance.EnableControl();
        MoveInput += () => InputManager.Instance.joystickCore.OnDrag(null);
    }

    private void Update()
    {
        MoveInput.Invoke();
    }```
grand snow
#

seems a bit pointless in that example

half lantern
#

when you guys program large projects how do you make ur code clean. do you follow a set of rules?

half lantern
#

im a beginner to netcode but im trying to make a mutliplayer game

nimble apex
half lantern
#

thank you so much

nimble apex
#

data only available and generated on OnDrag()

grand snow
#

if the event subscription is external to the class declaring it then it makes sense

nimble apex
#

i want MoveInput execute itself once whenever OnDrag() is called everytime, so it should be 1 on 1

moveinput should not invoke by any code other than OnDrag() execution

grand snow
#

I have a class button with the event "OnClick". other things can then subscribe to the event to do stuff when the button is clicked. This is great because Button does not need to know about the other code

#

You have done it backwards 😆

nimble apex
#

if i invoking it on update when its binded with onDrag() , when onDrag is active

its 1+1 : 1+1 , then it will be 2 on 2?

#

i think so lol

grand snow
#

you are invoking the event MoveInput which will CALL () => InputManager.Instance.joystickCore.OnDrag(null);

nimble apex
#

😭

grand snow
#

joystickCore should instead have an event such as "OnDragged" that you invoke when OnDrag() is called so then OTHER things can react to OnDrag() calls.

#
public event Action OnDragged;

public void OnDrag()
{
  //drag stuff
  OnDragged?.Invoke();
}
#

something else can know when OnDrag() is called and do stuff

nimble apex
#

ty 👍

grand snow
#

hopefully that makes more sense to you now

nimble apex
#

yeah

vital vault
#

how to make buttons clickable even with Time.timeScale = 0?

grand snow
#

animations?

#

if using unscaled time it will work normally

vital vault
#

i want to add pausing to my game

grand snow
#

Yea but I dont think their functionality changes with time scale, animations may be afffected if using scaled time

trim burrow
#

Hey, Im new to unity so watching some basic tutorials, i have a problem tough, When i create a new c# script my script generates with less code then it does in the tutorial. How do i fix this? I know i could type the missing stuff out manualy but it would save time and be a lot less annoying if i dont have to
Im not getting functions like start and update and it dosnt generate with monobehavior


public class Test
{
    
}
polar acorn
rich adder
trim burrow
#

Ah, okay thank you guys!

half lantern
#

Has anybody here looked at galactic kittens sample for unity netcode?

#

If so, how did you use it as a learning resource?

rich adder
half lantern
#

like 2D space shooter?

rich adder
#

thats one of them sure, if you combine all of them you get a pretty good understanding how to approach each problem you want to solve

half lantern
#

how should i use them tho? just read through the code

rich adder
#

well yeah and how specific things are handled

half lantern
#

how did you learn unity netcode

rich adder
#

there is no like step by step or anything, unity did not handle netcode like that . Maybe the intro on docs, but to a point thats understandable you need a minimum amount of exp before doing multi

half lantern
#

ok thank you

rancid tinsel
#

is there any way to get a Vector3 position of a random point in an area?

rich adder
rancid tinsel
rich adder
#

there are several ways to do this. Also you have to consider what kind of area

rich adder
#

if circular there is Random.insideSphere

#

or if you want something boxy Random.Range or colliders etc.

rancid tinsel
# wintry quarry What shape area?

any - in my case it would probably just be a flat plane (its meant to be a waiting area that a navmeshagent goes to, rather than a single point)

wintry quarry
rancid tinsel
#

plane it is

wintry quarry
#

for a flat plane you'd just use Random.Range twice

#

once for x and once for y or z

#

to pick a coordinate

#

that's all

#

If the plane is not axis-aligned, you'd pick a random point in local space like that and then essentially rotate it with either Matrix4x4 or a rotate Transform using TransformPoint

rancid tinsel
#

wait so what should I reference for the area, the transform?

wintry quarry
#

not sure what you mean specifically

#

you could also do it with Lerp if you define the plane by two corner points - it depends how you want to define the plane

rancid tinsel
#

so ive got the transform reference, and then when i want to get a random point within that transform, what do i call?

wintry quarry
#

well the Transform doesn't have points "within" it

#

you'd have to provide extra information like the extents of the area you want a random point within

#

Where is the Transform's pivot in relation to the random area?

rich adder
#

bounds or colliders work also

rancid tinsel
#

i am so completely lost

#

im asking whether its a collider, transform or what should be the type for the area? im guessing collider if transform doesnt have points

rich adder
wintry quarry
#

it just really depends how you want to define this area

rancid tinsel
wintry quarry
#

there are many, many ways to do it

wintry quarry
rancid tinsel
#

oh true - ill try to remember that for next time

mossy cloud
#

i am working on a multiplayer project and my only goal is publishing on steam, so what multiplayer framework i need to use. i am trying facepunch but its not feels right i am stuck on a steam relay socket creation for days. the game lobbies are probably gonna be around 40-60 person. should i use steamworks.net or go with facepunch? i wanna use steam relay sockets for privacy and security and make my game fully steam integrated.

mossy cloud
half lantern
#

what are you supposed to do if a client leaves half way through the game in unity netcode

nimble apex
#

u need a more specialized channels , not here

hearty sigil
#

Im trying to make a snake like game in 3d.

For the trail can I use the trail renderer component in any way to create a collidable object? or should I instantiate objects from the player character?

#

or any other advice for an easier way to do this would be appreciated

subtle sedge
#

whats the best way to make a dialouge system in unity?

#

i heard some people used ink files for dialouge and some said json (even tho i cant find a single video of somenoe use json to make dialouge in unity)

frail hawk
grand snow
frail hawk
#

but you said 3d , how are you going to handle that

frigid sequoia
#

Am I dumb? Is this not valid?

slender nymph
#

what does the error(s) say

frigid sequoia
#

That the syntaxis is wrong???

#

But no?

slender nymph
#

what does it actually say, not a vague paraphrase of the error

frigid sequoia
#

"," was expected

subtle sedge
polar acorn
slender nymph
warm palm
#

Just went to open Unity today to continue my "roll a ball" tutorial and I'm met with this message:

frigid sequoia
#

What?

warm palm
#

Anyone know what this is?

frigid sequoia
#

I just want to have a shortcut call to that reference

polar acorn
#

You can only use the => notation for functions or properties

slender nymph
#

are you trying to declare a property for the class or are you trying to declare a local variable

frigid sequoia
#

How do I do that?

polar acorn
#

not fields

polar acorn
# warm palm

If reinstalling doesn't fix it you probably don't meet the system requirements

warm palm
polar acorn
frigid sequoia
#

I think??

warm palm
#

I have Windows 11 Home that came with the computer brand new

slender nymph
frail hawk
slender nymph
polar acorn
slender nymph
#

what they wrote is supposed to be a local variable but they've used the syntax for declaring a read only property. removing a single character turns that into a valid declaration for a local variable
||>||

warm palm
#

It just stops here

#

and says this

polar acorn
rich adder
polar acorn
# warm palm

Yeah probably OS related. If it can't install the program at all that sounds like a windows thing

slender nymph
# polar acorn Wait _is_ it a local variable or is it a property

it's supposed to be a local variable which is why they are seeing the error. if it were declared at the class level then there wouldn't be an error because it's valid syntax for writing a read only property
(it's valid expression body syntax for a read only property)

rare topaz
#

Is there a way to scatter prefabs onto a terrain (like the literral prefab, not just the mesh attached, like the scripts and everything)

warm palm
#

So unity doesn't work properly on windows or are you saying my windows has something wrong with it

polar acorn
rare topaz
polar acorn
rare topaz
warm palm
#

Do you have any idea how to fix this I know it's OS related not Unity technically but everything else works fine on here literally only unity that's had an issue

polar acorn
rare topaz
#

full object

warm palm
#

ok

polar acorn
#

The point of terrain tree instances is that they aren't full GameObjects

rare topaz
rare topaz
raw tulip
#

I want to make fpsarms and fullbodymesh depending on who isowner, where would I put the arms? The GreezyPlayer has the animation script

rich adder
#

whats with all the network questions..

raw tulip
wheat pebble
slender nymph
raw tulip
silk night
warm palm
tidal lagoon
#

I need help finding out how to look at objects from the left in the scene I have a video

polar acorn
tidal lagoon
#

can I send the video

#

because its hard to explain

frigid sequoia
frigid sequoia
slender nymph
#

how do you declare a local variable

#

like just as an example, declare a local variable of type int and assign it a value in the same line

tidal lagoon
#

private float variable = 1f; is this what your asking

silk night
frigid sequoia
#

Like just this??

#

But this is not really pointing to anything

slender nymph
#

notice how in both cases now you are using the assignment operator = and not the expression body operator =>

slender nymph
silk night
#

are you asking how to rotate around the object?

frigid sequoia
#

But like I don't want the new variable to be equal to the thing, I want it to point to the thing so I can modify the thing from there

slender nymph
#

wdym by "modify the thing"?

#

because even if it were a property you still wouldn't be able to change the object referenced in that variable you used in the assignement

tidal lagoon
# silk night are you asking how to rotate around the object?

so when I press the top right thing it at 11 seconds, it looks at the left but flips it, I want to be looking at the left of the object and orbit around it as if I'm looking at all the sides. An example is walking around a chair and facing it

slender nymph
#

you would still only be able to modify its public properties/fields

silk night
polar acorn
#

What do you mean by "normally", that seems pretty normal?

silk night
#

it does, your perspective is rotated

#

+y is usually up

tidal lagoon
#

when I mean normally I mean walking around a chair and looking at it

when I look at the left wall of the cube it rotates it or flips or something

ive seen a video where the person is looking at a object and is flying around it while facing it

silk night
#

thats because you are standing sideways in the room looking at the chair 😄

#

you start looking at the cube from the top, ofcourse it flips when you then switch to the side

tidal lagoon
#

yeah, how do I make it not do that and look at the cube like the video

silk night
#

can you send your first video again?

polar acorn
#

It still seems like you're just doing normal camera movement so I'm not sure what the issue is

silk night
#

your up arrow is not pointing up

tidal lagoon
#

what do you mean

silk night
#

the way the arrows point is backwards, not up

tidal lagoon
#

according to the youtube video, am I doing what the guy is doing 7 seconds in

polar acorn
#

I literally do not see anything wrong with this

silk night
rich adder
#

is this local or world ?

tidal lagoon
#

nothings wrong with the movement I just want to know how to look at it without making it flip the camera and stuff

tidal lagoon
tidal lagoon
#

local

marsh vale
#

idk why mine doesnt work

#

does it have to do with outdated tutorials or something

rich adder
silk night
polar acorn
# marsh vale idk why mine doesnt work
"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: 191
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2025-07-31
silk night
ivory bobcat
ivory bobcat
silk night
tidal lagoon
#

how do I fix the orientation

silk night
#

make sure on the cross top right the green Y arrow is pointing up

#

and then rotate the cube so the upside of the cube points the same way

tidal lagoon
#

this will fix the scene camera

silk night
#

yes

tidal lagoon
#

Thanks

sweet pendant
#

Yo who knows how to make a grabbing system, like making a system where you can grab a box or smth

wintry quarry
#

Lots of people know how to make one.
Do you have a specific question?

sweet pendant
#

Yes

#

How do u make one

wintry quarry
#

Usually using raycasts

sweet pendant
#

Can someone post a code here so I can understand

wintry quarry
#

Like any problem you'll need to break it down into parts:

  • Detection of an object in range in front of the player
  • The "grabbing and holding" part
wintry quarry
# sweet pendant Can someone post a code here so I can understand

just posting arbitrary code won't help you much. Basically:

  • For the detection of the obejct you would use a raycast
  • For handling the input, you would use normal input functions like Input.GetButtonDown
  • For holding/grabbing, you would either teleport the object to a specified position in front of the player each frame, or use physics e.g. setting velocity to move the obejct towards that point each FixedUpdate
polar acorn
sweet pendant
#

Does it work

polar acorn
wintry quarry
#

if you want to only be able to grab objects you're looking directly at, you would use a Raycast

sweet pendant
#

K thanks man

#

Ill try doing these things

thorn kiln
#

Oh dear, what's happened here. This exact same code worked fine in a previous project.

#

Ah, I see

polar acorn
thorn kiln
#

Yeah, just noticed that

#

Auto-complete can screw you sometimes

wintry quarry
rancid tinsel
#

!code

eternal falconBOT
rancid tinsel
#

and I mean like over 10 instantly

subtle sedge
#

kinda random but what are yall working on rn?

rancid tinsel
#

oh

#

integer rounds down

teal viper
native seal
#

is there any case where its better for the logic script to have direct access to the UI or should I always just have the UI reference the logic script and subscribe to its events?

#

minor detail i know

thorn kiln
#

Rather than setting the transform position for all 4 bounds to keep something in bounds, is there a way to keep something within the bounds of a plane?

#

Cause all I'm looking to do is keep the ball within this square plane, so I'm wondering if there's an easier way to do that

native seal
#

you could use OnTriggerExit maybe?

native seal
#

and make a big collider

thorn kiln
#

Hmm, I was wondering if there was data in the plane I could use

native seal
#

what do you mean data in the plane?

thorn kiln
#

In my brain I'm just thinking there has to be data that tells unity where the planes X and Z axis stop, but maybe I'm just making that up and all it knows is it's position and scale

teal viper
teal viper
native seal
#

if you want physics wouldn't invisible colliders just be easier though?

umbral parcel
#

Could someone help me about the game scale?

#

once i put it on full screem it got like this

thorn kiln
#

Yeah, it's got a mesh collider. How do I find info on the bounds for it?

native seal
#

.bounds usually

#

for all things with geometry

umbral parcel
#

but when i keep it on the editor it stays normal

thorn kiln
#

Hmm, this might be too ambitious for my current skill level

native seal
#

what exactly are you trying to do? make it bounce around the edges?

#

or if it touches the edges it stops completely, are you using physics?

thorn kiln
#

Nah, make it so it can't go past the edges

native seal
#

so the 2nd one?

#

no physics

thorn kiln
#

I'm using transform.translate for x and y, but I'm using addforce for jumping

#

If that matters at all

native seal
#

so you want effectively "invisible" walls?

thorn kiln
#

Yes

native seal
#

simplest way is just make invisible boxcolliders around the edges

#

but it can be easily done using the bounds of the meshcollider of the plane

thorn kiln
#

I'd need to see how it's written to understand

native seal
#

in an update loop you would check the position of the ball and compare it to the world bounds of plane, if they are over then set the position of the ball to the edge

#

but you would have to account for the radius if you dont want clipping, etc

thorn kiln
#

Probably too complicated for me right now. Someone should help Okane instead 😂

native seal
#

i would just make boxes around the edges 😂

thorn kiln
#

Probably easier, but I like the idea of precision

native seal
#

no reason they aren't precise?

native seal
thorn kiln
#

I could also make it precise with transform.position, but I liked the idea of something that would adapt if I made the plane bigger, and also wouldn't require me to make 4 if statements and 4 variables

umbral parcel
native seal
#

wait maybe edge colliders are 2d only

thorn kiln
#

Yeah, I suppose, but I'd also like to be able to code the solution. Putting an invisible block in the way feels like the easy way out 😂

#

Like how they couldn't get trams in fallout working so they just make the tram a helmet and attatched it to an NPCs head 😂

native seal
#

you could make a meshcollider and invert the normals so it acts like walls, that would require code

#

it could also be super easily resized to the plane size in code

thorn kiln
#

I'll probably leave it then since I don't understand some of those words yet

native seal
#

haha, you could always ask AI to give an example to understand the code

polar acorn
#

Spawn an object, put a box collider on it, scale it to the size you want and you're good

thorn kiln
#

GPT gave me something, but I'm probably getting lost in the weeds here

native seal
#

i just dont see why you need to do something that unity physics already does and probably does better

#

if its the resizing, you could make a simple script that resizes the boxes exactly to the borders of the plane

thorn kiln
#

How can I explain this....
Imagine someone only knows how to do addition
You ask them to get the result of 6 lots of 10
They'd just say "10 + 10 + 10 + 10 + 10 + 10 = 60"
And then you're like "you know multiplication is a much better way to do that?"
And the asnwer is no, they don't, because they don't know multiplication yet

native seal
#

i understand but in this case that multiplication is not only much better but its much easier than addition

#

if you insist on using code you would do what I said above

shell sorrel
#

just use physics or if you want to control the transform directly just get the bounding box of the plane and use that compute your movement limits

thorn kiln
#

And yet, this is what I actually understand how to do at my current level.

        if (transform.position.x > xBounds)
        {
            transform.position = new Vector3(xBounds, transform.position.y, transform.position.z);
        }
        else if (transform.position.x < -xBounds)
        {
            transform.position = new Vector3(-xBounds, transform.position.y, transform.position.z);
        }
        else if (transform.position.z > zBounds)
        {
            transform.position = new Vector3(transform.position.x, transform.position.y, zBounds);
        }
        else if (transform.position.z < -zBounds)
        {
            transform.position = new Vector3(transform.position.x, transform.position.y, -zBounds);
        }```
shell sorrel
#

all colliders and mesh renders have a property to get these bounds

#

getting xbounds then -xbounds makes no sense and would be just wrong or twice what you want

#

also instead of using if's using Mathf.Clamp will be much easier to read

#

you can construct a new vector where the x and z axis are clamped using the max and min x z and z of the bounds

native seal
odd holly
#

I need some help

thorn kiln
#

Not really, but like I said, it's coding that I don't understand, I already know how to put a big invisible box in the way to stop something, that's easy, but I don't really learn anything from doing it

native seal
#

ah i see

thorn kiln
shell sorrel
#

not everyones game uses physics directly even in a heavily movement based game i am doing for work all movement is our own logic

odd holly
#

I was coding a timer into a combo attack I have in my game, I want it to give you a certain amount of time to hit the enemy 4 times or it resets the value, snd I got it working where when I press the attack button the ComboTimer counts down, but currently it doesnt work like a clock, if decreased a little bit each time I press the key, but I want it to fully activate the timer with just the first click…

shell sorrel
thorn kiln
#

Possibly, but I haven't learnt about clamp, so you know

shell sorrel
#

the min and max values you would jsut get from the bounds of the renderer

#

like everything else in Mathf its a pretty simple basic math function

native seal
#

clamp is more of a math concept not coding

shell sorrel
#

its like if you combined a min and a max or if you just did conditinals for the lower and upper range

#

<@&502884371011731486>

north kiln
#

!softban 1400114281630142598 bot spam

eternal falconBOT
#

dynoSuccess joanna_dwayne0928 was softbanned.

shell sorrel
#

i mention add or subtract since some people like starting timers and 0 and counting up to a duration others like setting the timer to duration and working down to 0

native seal
#

I feel like im heading into manager hell. I previously have used ScriptableObjects for inventories since it allows me to plug the inventory into anything that needs it, for example the players inventory into the shop without it needing a reference to the whole player. However, SOs are awkward to save and serialize and are also a headache to create an runtime (for example a randomly spawned chest's inventory). Im instead going to make inventories just a POCO so they can easily be created at runtime, but now I have the issue of things needed references to them. would a InventoryManager singleton be a bad idea for this? It feels like everything needs a manager haha

shell sorrel
#

coupling happens at some point its your choice where that happens

#

but yeah i would just handle things like that that do not require unity features with just regular objects as well

native seal
#

so go down the route of an inventory manager? i guess another solution would be dependency injection but i dont really like that in unity tbh

shell sorrel
#

find with unity really most projects end up with some sort of manager singleton type stuff going on

#

since in unity you do not control the entry point like you would in a traditional application so its harder to pass dependencies down the stack

#

personally i would try and still get control over when its created and not just let the singleton pattern create it. Perhaps have 1 object that contains constructs and holds reference to a bunch of stuff like this

#

but yeah i am not really a fan of dependency injection frameworks either, rather just pass things around myself or provide a other way

native seal
#

for example, with my UI, the object holds a prefab of the window and the UI manager spawns the window on a canvas that all other UI goes on

shell sorrel
#

i thought you were purely talking about the data representation of inventory

native seal
#

well my point is that I would structure it in a similar way

#

object holds data about what kind of inventory, etc. calls Singleton.Create(data) which returns the instance it created

#

then the singleton can manage interactions between inventories