#πŸ’»β”ƒcode-beginner

1 messages Β· Page 763 of 1

flint rover
#

ok so what should i put then?

eternal needle
#

Yea thats what I meant with possibly doing something more than once per frame

rough granite
flint rover
rough granite
flint rover
rocky canyon
#

just add it as an Empty gameobject

#

if its in the scene you don't need a direct reference.. b/c its a static singleton instance..

#

you can call it from anywhere

flint rover
edgy sinew
#

Okay so...
Make an empty GameObject in the scene,
Call it "Singletons" or "Shared" - something that makes it clear, this is "one instance" stuff (static)
And add as a component, the Attack_Script (aka CombatManager)

Now you see how you have public Attack_Script instance ...
In the video he has... public static CombatManager instance

The static keyword there means, the instance exists for the entire time your project is running
So you could access it, like... Attack_Script.instance

#

ahh shit, yeah what @rocky canyon said πŸ‘†

#

Does he even have to have an instance of the component in the scene to access the static .instance? πŸ€”

flint rover
#

does anything change that its on IDLE in the animator and not a gameobject?

rocky canyon
#

yea thats what i was saying to do ^ lol

#

as long as its in ur hiearchy it doesnt really matter where

#

if u disable the gameobject or something u no longer have access to it..

edgy sinew
rocky canyon
#

was it not a monobehaviour?

edgy sinew
#

can't have a static monobehaviour right πŸ€”

rocky canyon
#

ohh no its a StateMachineBehaviour.. yup i have no idea about those..
im tapping out πŸ‘

#

ya i didn't notice htat

flint rover
rocky canyon
#

im not sure.. thats y i removed it

edgy sinew
#

ngl im tapping out too. this is too overcomplicated, for a basic "2D character sword combo" πŸ€·β€β™‚οΈ

flint rover
rocky canyon
#

the statemachinebehaviour thing i've never used. soo i dont wanna give misleading information

rocky canyon
edgy sinew
#

yeah i think it like, directly interacts with the Animator State

rocky canyon
#

lol Β―_(ツ)_/Β―

edgy sinew
#

shit that could be kinda useful .... hold on...

flint rover
#

should i just scrap the video and try find something new then?

rocky canyon
#

start out with simple animator stuff.. basic enum state machines.. and directly controlling the animator w/ booleans and triggers

rocky canyon
flint rover
rocky canyon
#

ya, i get that.. but even in college you want to build up to the more advanced things

edgy sinew
#

@rocky canyon wait this is kinda cool
Apparently it gives you callbacks for when Animator enters a state, exits a state, etc πŸ€”

rocky canyon
#

wanna be building off a solid foundation

#

no leaning tower of pesa's around here

rocky canyon
flint rover
rocky canyon
#

nah u didn't

#

thats why we're here 🧑

#

as a beginner i just did ur basic animator setup

  • use transitions to control when and how u transition and to what state
  • use animator parameters to control that stuff.. (booleans, triggers, etc)
#

then its just animatorReference.SetBool(Run, true);

#

but as you get more advanced you can def look back into behaviour trees and whatnot

rocky canyon
#

animator just gives u an opportunity to lessen ur work-load i guess

#

if ur down to learn

edgy sinew
rocky canyon
#

i recommend you get a state machine going first
πŸ’― you can take what u learn by building ur own statemachine and apply it to other things

edgy sinew
#

And with that, you can ... literally do anything. jump, swim, fly, attack, combo, combo cancel, etc

#

@flint rover
https://youtu.be/Als_d-UIgVo

Here's a slightly less outdated video with more details.
He builds an enum-style state machine (not inheritance / hierarchical) but it shows the idea which is the gold here

Here's how to use a State Machine in your Unity game. This is an excellent mechanism for keeping your code streamlined. NEXT VIDEO: https://www.youtube.com/watch?v=5s_gcWef4pY&list=PLydLF_SVNKYaY5YnH7amiEeiUAVWRBCu3&index=12

By using a state machine you can effectively control when your player in a walking state, versus a jumping state, versus ...

β–Ά Play video
flint rover
edgy sinew
# flint rover ok yeah great im just giving that document a read then ill watch this video and ...

Yes make sure to use an Enum - the video uses strings i think which is not as efficient
One of the first goals with state machines is to reliably track and manage basic movement states - idle, jog, jump

I would recommend to track it in OnGUI - try to avoid Debug.Log when possible, as it lags out the Editor.

// after setting up some Enum
private MyStatesEnum playerCurrentState;

void OnGUI()
{
    GUI.Label(new Rect(10, 10, 160, 20), "State: " + playerCurrentState);
}
rocky canyon
edgy sinew
#

Once you get idle, jog, jump working solid, then you can start to add stuff like,
"if player is in idle state, and attack button pressed, switch to AttackCombo1 state"
"if player is in AttackCombo1 state, and the attack button is held down, continue into AttackCombo2 state"

etc you see the idea how they chain together
the Enum way is a little hacky but, keep in mind the 4 main State Machine functions (verbose plain English used for clarity)

OnStateEnter, OnStateExit, DoThisEveryFrame, CheckIfNeedToSwitchState

wraith delta
#

@keen dew hey, i followed another approach, created a empty object children of player and set it's position to the center of the screen by code, so i just changed the ray origin to that object πŸ™‚ works fine with just 1 ray

#

it's like having a small floating robot near your with a ray hehehe

timid quartz
#

Hi there, I'm running into a problem where I have a skinned mesh renderer that's tposing in builds but works in editor. I've already tried marking the FBX as read/write enabled. Any ideas?

timid quartz
#

I solved it actually! I had to make sure that the model was placed somewhere so Unity would include it in the build.

swift crag
#

It's true that assets that aren't referenced in any scenes and that aren't in a Resources folder will not be included in the built game

grand snow
#

Yea something else must have been wrong like not playing any animations on it

timid quartz
umbral hound
#

Can I get some advice? How do you start working on a modular system you have no idea how to make? For example, I KNOW what I want it to do. I want standalone "zones" for each level or area, that have their own game logic flow. Like triggers, interactables that subscribe to the manager to dictate what happens, but logics wise, I have no idea how to do it

Please ping me if anyone replies

grand snow
timid quartz
#

it does!

#

it's the easiest way to do things like character creation IMO

grand snow
timid quartz
#

duplicate the skinned mesh renderer portions and swap out the shared mesh and shared material and presto, skinned mesh animation with swappable parts

wintry quarry
grand snow
timid quartz
#

you can't instantiate a skinned mesh renderer because the bone data isn't copied

grand snow
#

so then you spawn a prefab

timid quartz
#

to be clear my stuff does actually work, it was a "unity didn't package the mesh" problem which I solved

#

like, an asset inclusion build-time error

umbral hound
# grand snow Even to me this is too vague. Got any concrete examples of what you want to be m...

No I don't, but let me be more descriptive. Let's say I have made a trigger, where on trigger enter, it checks if it's active, or if the bool m_OnEnter is checked, then it checks for the player tag. Then it sets off an event handler. I want a system where you can set that trigger as a variable, then do

m_Trigger.OnEnter += SomeFunction;

Now, I know how to do that, but in terms of initializing the zone I'm in, I have no idea

grand snow
#

So you want a component to handle that work?

umbral hound
#

Let's say each area is a zone, and when you enter, it initializes all of the data for that zone. Triggers, doors, etc and what to do when they are interacted with

#

yes

#

Like I already have the logic all in my head for how that all works, but I just don't know how to write it

grand snow
#

So how about this:
PlayerTriggerEnter -> has event for when the player enters a trigger
AreaManagerBase -> base class that calls some virtual Init() func using PlayerTriggerEnter

#

Then you inherit from AreaManagerBase for each area class you create

umbral hound
#

But in terms how HOW that is initialized? Like do I need just some trigger that covers the entire zone, and make IDs for all the zones, and then go through all the IDs, and if that zone has that ID, initialize the zone with that ID?

#

That seems almost too easy

grand snow
#

Why do you need to perform setup work when a player steps inside some area?

#

Is this even needed?

umbral hound
#

Well that's the way they did it in Bendy and the Dark Revival

wintry quarry
#

what is a "zone"

#

are these rooms?

#

Should/could these be scenes?

umbral hound
#

A zone is a section of a game. It can be rooms, levels, etc

wintry quarry
#

that's pretty vague

#

you're making a specific game right

grand snow
#

If the player steps inside a room and you want a cutscene to begin and spawn a boss, id also use a trigger with some component that calls an event (and ensures it can only be called one time)

umbral hound
#

Yes

#

If I had to guess, I guess the manager is there to make sure that the game knows if you've already been there or not, and so if you load it, the game doesn't say "hey, they haven't been here before, deactivate everything"

#

Apologies, I'm bad at conveying thoughts

grand snow
#

Well we dont always have to explicitly disable things but it can be helpful sometimes
valve did this a lot in HL2, in route canal the guy you meet where you fight man hacks gets killed once you get far away enough

#

They have specific entities and an input/output system so it was easy to add such logic in map
We can do the same with UnityEvents

#

or you use custom components and Interfaces to invoke things on trigger enter

umbral hound
grand snow
#

That sounds like you want some kind of zoned loading system where things are split amongst many scenes/prefabs

#

Then it does make sense to have data to link these together and to know what to load in later

umbral hound
#

Oh so it is scene based, not just area based? I was assuming with how big the studio is in Bendy and the Dark Revival, every few rooms or two was one big zone

#

Wait yeah nvm it is area based because they made one scene for the entire studio

slow fossil
#

Hello,
I have a problem with my targeting system, where I have problems with my enemy deaths.
It just adds/removes an enemy to the kill list when something with a "canBeAttacked" tag enter it's range

    private void OnTriggerEnter(Collider other)
    {
        
        if (other.CompareTag("CanBeAttacked") && !enemiesInRange.Contains(other))
        {
            enemiesInRange.Add(other);
        }
    }
    private void OnTriggerExit(Collider other)
    {
        if (other == null) return;
        print("Something exited");
        if (other.CompareTag("CanBeAttacked") && enemiesInRange.Contains(other))
        {
            enemiesInRange.Remove(other);
        }
    }
    protected List<Collider> enemiesInRange = new List<Collider>();

Enemies in range represents the lists of all the enemies in the tower range, precisely, all the collider I detected when one of them entered of left my tower's range.

    void Attack()
    {     
        if (attackCooldown <= 0f && enemiesInRange.Count > 0)
        {
            foreach (Collider col in enemiesInRange)
            {
                if (col == null) break; // Works well until you have more than one enemy
                Enemy enemy = col.GetComponent<Enemy>();
                enemy.damage(damage);
                attackCooldown = attackspeed;
                print("I attacked " + col.gameObject.name + ". Life left : " + enemy.getRemainingHealth());
                
                break;
            }
        }

    }

I use this simple "attack" function that does try in the Update, to shoot the first enemy in it's enemy list until it theoretically triggers the OnLeaveTrigger.

    public SphereCollider rangeCollider;

    public void damage(float dmg)
    {

        this.health -= dmg;
        death();
    }

    public void death()
    {
        print("Man I'm dead");
        Destroy(gameObject);
    }

However, enemies needs to die and I don't think the destroy() really triggers the OnLeave

grand snow
umbral hound
grand snow
#

if you want light baking to not be annoying a f then you would put things in seperate scenes

umbral hound
#

Okay so for example then, there's a room where Audrey goes in, walks under a vent, and the vent smashes open with a dead ink creature hanging down, then a PA comes on. That could be a zone I guess

grand snow
#

You would split things up in a way that makes sense (e.g separated by doors or corridors)
Ofc the old way was just to have a loading screen to unload and load the new areas but there was always some "transition" point/area

#

Again, in HL2 it was selected carefully and meant each map needed to duplicate the transition area

wintry quarry
grand snow
worthy veldt
#

i need help on how to assign field in this context

#

its a pathing assist, to point where npcs should go to move to another area

#

perfect timing lol, its a level transition but mine is light 2D game so I just teleport them

wintry quarry
#

And what trouble you're having with doing so?

worthy veldt
#

i cant access the road, i leave comment on the code

wintry quarry
#

I only see one field in this code:
public Area[] areas;//location with road details

worthy veldt
#

sec

wintry quarry
#

you mean this?

        for (int j = 0; j < area.roads.Count; j++) //ERROR: Use of possibly unassigned field roads
worthy veldt
#

yea , how do i assign it properly with some default value ?

wintry quarry
#

I mean would a default value help you here?

#

It would be null and you'd get a NRE

#

how about:

        Area area;
        area.roads = null;
        bool found = false;
        for (int i = 0; i < areas.Length; i++)
        {
            if (areas[i].locationName == initialLocation)
            {
                area = areas[i];
                found = true;
                break;
            }
        }

        if (!found) {
           initialRoad = default;
           destinationRoad = default;
           return false;
        }
        //find the correct road element
        Road road;
        for (int j = 0; j < area.roads.Count; j++) //ERROR: Use of possibly unassigned field roads```
#

this is made a little more verbose/complex by the use of structs instead of classes, btw.

clear monolith
#

If anyone knows alot about fears to fathom type games, I appreciate if you write me πŸ™

wintry quarry
#

if Area was a class you could:

        Area area = null;
        for (int i = 0; i < areas.Length; i++)
        {
            if (areas[i].locationName == initialLocation)
            {
                area = areas[i];
                break;
            }
        }

        if (area == null) {
           initialRoad = default;
           destinationRoad = default;
           return false;
        }
        //find the correct road element
        Road road;
        for (int j = 0; j < area.roads.Count; j++) //ERROR: Use of possibly unassigned field roads
worthy veldt
#

i will assign value to roads later

#

what i mean is i could make another areas2 array initialized with default values, then load them with areas data from inspector. but is it possible to do it as it is with additional code ?

#

because how many location and road will be there is known

worthy veldt
amber warren
#

Hi could someone possibly help me please. Im trying to make these two vr potions the when mixed together (causing the shader to change colour into a mix of the two) and poured onto a gameobject cuases the game object to change texture. this is the code i have for tyhe flask and the texture one for the object however when tryoing to mix the potions the liquid just disapears

wintry quarry
#

Also:

  • Have you verified the code actually runs?
  • Are there any errors in the console?
radiant voidBOT
#

success @siennashroom muted

Reason: Sending too many attachments.
Duration: 29 minutes and 56 seconds

polar acorn
#

Another reason to use !code instead of a ton of screenshots

radiant voidBOT
worthy veldt
worthy veldt
#
for (int i = 0; i < areas.Length; i++)
{
    if (areas[i].locationName == initialLocation)
    {
        if (areas[i].roads != null)
        {
            for (int j = 0; j < areas[i].roads.Length; j++)
            {
                if (areas[i].roads[j].endLocation == destination)
                {
                    initialCheck = true;
                    initialRoad = areas[i].roads[j].startPosition[UnityEngine.Random.Range(0, areas[i].roads[j].startPosition.Length)];
                    destinationRoad = areas[i].roads[j].endPosition[UnityEngine.Random.Range(0, areas[i].roads[j].endPosition.Length)]; break;
                }
            }
        }
        else Debug.Log("this area has no roads"); break;
    }
    if (initialCheck) break;
}

return initialCheck;
#

i made it !

unreal imp
#

GUYSSSS can explain? there are too many script types, whats the use of each of them? πŸ˜…

wintry quarry
#

you only need to worry about MonoBehaviour if you're just getting started

#

that's all

unreal imp
rough granite
# wintry quarry That's only 4 types

Found out you can add more, not sure how much unity (the company not the game engine) likes that though nor do i know how to add other classes as a default in new projects.

grand snow
#

I dont think they care

rugged beacon
#

anyway to make raycast hit even the inside of collider ?

rocky canyon
#

Queries Hit Backfaces

rugged beacon
#

bet

#

i read about it it said only work on mesh collider?

rocky canyon
#

ohh.. well sounds like you might need to create some primitive's in blender or something

amber warren
#

! code

radiant voidBOT
chrome apex
#

so is there any way to avoid gimbal lock when using addTorque and 2 axis? Seems impossible

chrome apex
midnight plover
#

I am asking for the code to find out, if your gimbal lock is coming from addtorque or your calculation what torque you set

chrome apex
#

It just gets a mouse x and mouse y value and places them in a vector, that's all

midnight plover
#

Does it just call AddTorque with a correct axis and rotation under the hood?

chrome apex
#

yes

#

the problem is if I move my mouse diagonally up and to the side, the player drifts more and more on the Z

sour fulcrum
#

do you maybe need to be using AddRelativeTorque? (vague guess not sure)

chrome apex
midnight plover
#

So its calling addrelativetorque? or addtorque with some calculation

keen dew
#

You can't do it without complicated calculations to figure out the "real" torque

chrome apex
#

also, my rigidbody is frozen in Z but that doesn't seem to help

keen dew
#

The issue is that when the character is tilted on one axis, you actually don't want it to rotate on the other axis but that rotation should be adjusted as well

chrome apex
#

seems to me like I will need to correct Z rotation each frame after applying torque to x and y

midnight plover
#

ah, its frozen in Z? that can lead to gimbal lock. as Nitku says, its like hard setting only two axis and therefore overriding the correct quaternion calculation for the resulting orientation

chrome apex
chrome apex
#

nope, I'm still to the side when unchecking freeze rotation

midnight plover
chrome apex
chrome apex
keen dew
#

If you add both X and Y rotation to a character it'll always also rotate on the Z

#

so you can't just "naively" do X and Y rotation and expect that Z will not change

chrome apex
keen dew
#

It's not quite the same but it's somewhat similiar if you move a character horizontally and vertically at the same time, it will move diagonally even though either of the two movements are not diagonal by themselves

#

Don't use torque to rotate the character

#

If you really want to use torque, I'm sure there are articles on the internet how to do it. But there's no simple solution that you could just apply to fix it

chrome apex
#

I didn't have these problems with the character controller

chrome apex
sour fulcrum
#

if internet is useless you are not good at interacting with it

keen dew
#

Usually characters rotate using torque only on the Y. Rotating up and down is done with the camera so that the player doesn't bonk on things when looking up and down

chrome apex
chrome apex
#

I found one alleged solution but it's in js and I'm too stupid

hardy prairie
#

i love using unity

midnight plover
radiant voidBOT
sour fulcrum
#

not much we can do with just errors, let alone errors with only half the message

sour fulcrum
hardy prairie
#

Assets\Scripts\ThiefAI.cs(8,13): error CS1069: The type name 'NavMeshAgent' could not be found in the namespace 'UnityEngine.AI'. This type has been forwarded to assembly 'UnityEngine.AIModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' Enable the built in package 'AI' in the Package Manager window to fix this error.

#

idk what happened

#

i restarted unity editor and now i have this error

midnight plover
#

did you update unity?

hardy prairie
#

Assets\Scripts\PhysicsItem.cs(11,13): error CS1069: The type name 'Rigidbody' could not be found in the namespace 'UnityEngine'. This type has been forwarded to assembly 'UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' Enable the built in package 'Physics' in the Package Manager window to fix this error.

hardy prairie
#

i did absoulutly nothing

#

i just reopened unity

midnight plover
#

Is it only those four errors?

hardy prairie
#

and they wernt there before

#

i reopened unity i got a message saying i have compiler errors

midnight plover
#

What does your IDE say when you open those scripts?

hardy prairie
#

let me chack

hardy prairie
#

according to ide there are no errors

midnight plover
#

what happens, when you try to update those lines, just rewrite them with a space or something and save them?

hardy prairie
midnight plover
#

Good point ignoring cap errors πŸ˜„ Did you backup your project?

hardy prairie
#

(I created the project yesterday)

midnight plover
#

Ah, id back it up and delete the library folder and see what Unity does

hardy prairie
#

but i gotta go somewhere

#

so when i come back i will reopen and see

#

what will happen

midnight plover
#

Good luck to you

hardy prairie
indigo thorn
#

Hello, I can't submit my project in Step 6 on this page:
https://learn.unity.com/pathway/junior-programmer/unit/manage-scene-flow-and-data/tutorial/submission-data-persistence-in-a-new-repo?version=6.0
Tried uploading a picture or a video, but the api returns a 400 Bad Request everytime:
{errorCode: "InvalidParameter", message: "The given parameter is missing or invalid", target: "stepId"}
I can't continue the Pathway, any solution?
Edit: Asked in General as it's not really code related...

Unity Learn

Free tutorials, courses, and guided pathways for mastering real-time 3D development skills to make video games, VR, AR, and more.

indigo thorn
#

Yes sorry, I edited to mention I also asked in General, I was following the programmer Pathway that's why I came here by reflex, sorry

sharp solar
#

is c# the best language ever

fast relic
#

there isn't a "best language ever", really

sour fulcrum
#

but c# is pretty neat tho

fast relic
rough granite
sour fulcrum
#

i've (casually) used c#, java, python, lua, php (html, css and sql i guess), gdscript and a tiny bit of c++ and i vastly prefer c#

sharp solar
#

i like python more than assembly, i like luau more than python, and i like c# more than luau

fast relic
sharp solar
#

function overloading is absolutely sick

#

solves so much mess

fast relic
#

that's a pretty common feature i imagine, no?

sharp solar
#

python and luau do it with if statements which is ugly

fast relic
#

oh yeah awful

sharp solar
#

also the type system in luau doesnt really like it

naive pawn
sharp solar
#

i like that in c# types are like a part of the language, in luau it feels like the code and types are 2 seperate things, and types are just to help you remember what you called your methods

naive pawn
#

c/c++/c#/java have overloading, js/ts/python/lua/bash don't, for example

fast relic
rough granite
coral patio
#

Hello. Is there some default way to handle jumping colliders in 3d? as dumb as this sounds but we didn't think about it but obv when you jump your character gets a tad smaller and the visual would technically allow you to move forward but it is blocked due to the collider being full size

slender nymph
#

you could just make the collider smaller

grand snow
coral patio
lament stone
#

i need help about physics or idk why but same jumping code i used earlier doesnt work now mass and default gravity project settings are normal:
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}

naive pawn
#

are you getting errors

lament stone
#

no it just glides in air

#

and force is too weak

#

even if its 20 or above

naive pawn
#

do you have other forces acting on the rb? is the velocity being set? is the transform being modified?

lament stone
#

rb.linearVelocity = yeniHiz;
only this yeniHiz is a vector3 btw that manages w a s d controls

naive pawn
#

and how do you calculate that vector?

#

!code

radiant voidBOT
lament stone
#

if (Input.GetKey(KeyCode.W))
{
yeniHiz += transform.forward * hiz;
}
like this

#

S is -transform.forward *hiz; and it keeps going like that with -transform.right transform.right

hardy prairie
# midnight plover Good luck to you

ok restarting my laptop worked and my heart litrally came in my throat because it opened a emty scene named untitled and i though i lost all my progress

#

but no i had to open sample scene

slender nymph
lament stone
#

will it fix if i turn it into vector3.fwd vector3.right vector3.left vector3.back

#

its the same thing...

lament stone
#

yenihiz is a vector3 0,0,0 hiz is speed

hardy prairie
rough granite
hardy prairie
lament stone
#

πŸ˜„

naive pawn
naive pawn
hardy prairie
swift crag
#

that just provides a direcetion

#

there is nothing inherently wrong with that

#

It will be slightly incorrect if the rigidbody has interpolation enabled, since the transform will be lagging behind the actual position of the rigidbody

lament stone
naive pawn
#

add rb.linearVelocity.y to the velocity vector that you're applying

hardy prairie
naive pawn
#

if you're referring to a stronger down gravity, that's a separate thing.

#

please stop recommending random irrelevant things.

hardy prairie
swift crag
swift crag
#

Unity's default gravity matches real-world gravity. This will seem wrong if...

  • ...you're used to, say, Roblox's default gravity (which is extremely strong)
  • ...your objects are very large
swift crag
#
Vector3 projected = Vector3.ProjectOnPlane(horizontalVelocity, Vector3.up);

This method discards the part of the vector that matches the second vector

#

Very useful for turning a tilted direction into a flat one

#

(e.g. if you move relative to the camera, and the camera is looking at a downward angle)

lament stone
swift crag
#

However, you then immediately told it that its Y velocity should be zero

lament stone
#

i get it thanks

hardy prairie
#

guys how does transform.setparent work

naive pawn
#

like, the internals? or what it actually does?

#

for the latter, well.. it just sets the parent

hardy prairie
#

like it doesnt matter where the code is

naive pawn
#

unless it's circular, i guess

#

why would it matter

#

if it's executed on the main thread, it'll do what it says it'll do

#

that's.. how code works

swift crag
hardy prairie
swift crag
hardy prairie
#

steal stuff like a thief

hot wadi
#

A thief would likely have a grabbing mechanic and an inventory system

hardy prairie
#

i just need to make the stealing part

hardy prairie
rough granite
polar acorn
#

And what does any of this have to do with the original question of SetParent

hardy prairie
hardy prairie
hot wadi
#

It's just a suggestion. Yeah, one item would not need an inventory

#

Just simple grab and hold

hardy prairie
#

and you lose once the thiefs have stole items worth over 100,000$

compact sandal
#

I'm looking a tutorial which makes a custom pass volume, but i only see global, box, sphere and convex mesh volume. Was it removed or is it just a package which im lacking?

swift crag
#

can you show us what you're looking at?

compact sandal
#

well... in this video you'll learn how to make a dope damage screen effect in Unity.
subscribe for a cookie :)
shader and code https://github.com/Mohammad9760/Unity_Special_Effects

I'll show you how to create a full-screen shader for a damage screen effect using shader graph that works both in HDRP and URP.

Support me on Patreon β†’ https://ww...

β–Ά Play video
swift crag
#

and where are you seeing "global, box, sphere", etc. ?

#

oh, I see

#

can you add a Custom Pass Volume component to an existing object? the menu item may have moved

#

I believe Custom Pass Volumes are HDRP-specific. I only see this in a URP project.

#

which would explain the issue

compact sandal
#

ohhhh, that makes sense.

#

Do i switch to HDRP or is there a URP alternative?

swift crag
#

I just don't know the exact feature you need

#

(the name alone sounds promising :p )

#

I think you just can't use the Volume system to control when a custom pass applies

#

I vaguely remember figuring this out for a game jam a few years ago

compact sandal
#

alright. Thanks for the help

shadow rain
#

This isnt really code but could someone tell me how to fix this like Ive tried doing the empty gameobject thing but I js dont get it

#

supposed to be the other way if u couldnt tell

digital haven
#

I'm working on a video game and I wanna transfer all my assets from one version to the other from a separate computer. I keep getting errors on the part where I need the character to move and handle its script when I transfer to the new version.

So I tried moving my assets to the old version and keeping the scripts the same, but it still causes me errors.

I want to know how I can transfer all the assets I've changed in my new version to my old version without ruining my scripts. Any thoughts?

Note: the new version has the patterned flooring and lighting. The old is the grey floor with the model in the middle that has all its scripts and commands set so it can move with my Xbox controller.

rough granite
shadow rain
#

its upside down

#

ik its stupid but im thick

rough granite
#

Do you have code that affects its rotation?

shadow rain
#

its literally bc of this

#

but how can I fix this

#

the green arrow is pointing down

#

when I need it to point up

#

ik its bc of how the model was made and that

#

ive tried doing an empty game object but that hasnt really worked

swift crag
#

you can now freely rotate the child

#

spin it around so that it aligns with the parent's axes

shadow rain
#

ive tried that but like due to the way my pickup script works it js doesnt let the player pick it up

#

im trying smth else rn tho

edgy sinew
#

sometimes to achieve the desired results, you have to move some things around Unity

swift crag
#

then it's time to modify the system πŸ˜‰

shadow rain
#

fixed it

#

js used a cube and disabled the mesh renderer instead of using an empty

swift crag
#

you can put a collider on the parent object, yeah

slow viper
#

Hello i am seeking help with programing problem. The problem is about saving system in unity the player will save some postion in JSON file but when i go back to main menu and back to the game the player will spawn some were else than i saved

slow viper
#

to dms or here

rough granite
#

Here

#

!code

radiant voidBOT
slow viper
wintry quarry
#

also an explanation of which components are in which scene(s)

#

and are you using additive scene loading?

slow viper
#

i will send the whole code system this was just SaveManager

wintry quarry
#

What about:
DataHandler
PlayerMovement?

#

actually this is the same file you sent above

#

Oh I see they're all in the link

slow viper
#

Is the link ok?

wintry quarry
#

Can you answer about the scenes?

#

Are you transitioning between scenes here? Are you using additive scene loading?

charred monolith
wintry quarry
# slow viper Not using Aditive and yes

DataManager doesn't seem to be DDOL, even though you are storing a static Instance property for it.
So most likely DataManager is simply being destroyed when your scene is loaded

#

and then a new one is loading but all the new one does in OnEnable is subscribe to sceneLoaded

#

it won't actually run the code for loading the scene

charred monolith
wintry quarry
#

You can verify this with some basic logs

slow viper
#

i have all of the manager in one core scene that dont uloands and the object that have the datamanager have parenting object with dont destory on load

sage token
#

anyone know a good website to make UML class diagrams?

versed stump
wintry quarry
#

Ok so the parent is DDOL

#

What debugging have you done for this?

slow viper
#

the were same so i tried to log the position that he loads and this position was diffrent

high summit
#

Is there a channel where I can ask about why my light cookies are not working in unity?

#

Sorted, was disabled in URP settings

stray junco
#

hey guys i got a question, i want to get into programming unity but idk where to start

#

im trying to make something simple like a rhythm game

swift crag
#

unity provides a bunch of tutorials at !learn

#

was that the wrong shortcut

#
Unity Learn

Free tutorials, courses, and guided pathways for mastering real-time 3D development skills to make video games, VR, AR, and more.

#

close enough

stray junco
#

ahh alr thank u so much

swift crag
#

I'd get comfortable creating basic interactions first (so, making a little platformer game will help a lot)

#

The main thing you need to do in a rhythm game is display notes and then decide if the player's input lined up with a note

#

There are a few gotchas here (e.g. what if the game freezes for a bit? the music might get out of sync)

stray junco
#

yeah thank u i had been searching for a tutorial for something like this but most of them are pretty old and look pretty bad too

swift crag
#

Coyote Time is a trick where the player is allowed to jump for a moment after falling off a platform

#

(modeled after our beloved Wile E. Coyote, who can float midair until he notices he should be falling)

#

Instead of having a boolean called canGrabBallLeft, I'd create a field called lastLeftGrabTime

#

If you decide the player can grab the ball, store Time.time into it

#

When the player tries to actually perform the grab, check if lastLeftGrabTime + 0.5f > Time.time

#

this would give you a half-second grace period

#

(oops, had the condition backwards; fixed)

stray junco
#

this is gonna sound so dumb but do u maybe have rhtyhm game tutorial thing i could learn from?

#

these tutorials dont seem to teach me how do anything remotely close too what i want to do

#

sorry

swift crag
#

I don't know of any (and I haven't made a rhythm game before)

#

You're going to want to get some general experience first, though

stray junco
#

theres like 50+ i see

#

wait nvm i found it

#

thank u anyways

terse granite
#

Hey, when it comes to scale of 2D or 3D objects, do you guys use absolute size or scale factor?
Any rule of thumb when to use what?

swift crag
#

I create all of my models (3D) and sprites (2D) to have the appropriate size at a scale of 1

#

for example, if a sprite is meant to be 1 meter tall and has a PPU (pixels per unit) value of 64, then the sprite must be 64 pixels tall

#

similarly, I get the scale right in Blender, rather than tweaking it after importing

#

I've thought about this when designing variably-sized characters

#

I can see some value to having everyone be equally large at a scale of 1 and then just growing or shrinking them

#

(rather than baking those size differences into the armatures and models in Blender)

swift crag
terse granite
swift crag
#

Notably, if you're using 3D physics, that's the default unit scale

terse granite
swift crag
#

The only place where units have no meaningful world-size is on screen-space UI

#

where one unit is generally one pixel

swift crag
rough granite
swift crag
swift crag
#

so you need to nail down a PPU (how many pixels takes up one unit of space in the world) as well as how big your viewport is going to be

#

(I mean, you can absolutely mix pixel sizes if you want...)

#

it's not necessarily awful, but it often is, haha

swift crag
#

it can also be 5 meters wide, 3.333333 meters wide, etc.

#

(the Pixel Perfect camera components figure that out for you)

#

but this is all irrelevant if you aren't doing pixel art

terse granite
swift crag
#

a one meter cube that weighs 1kg would be quite low-density, yes :p

rough granite
#

But its only 1kg in unity

swift crag
#

Unity physics often feels floaty because you've got the wrong numbers

#

(well, note that it doesn't model actual air resistance, so mass doesn't really matter)

#

rigidbodies do have drag, but this drag doesn't grow as fast as air resistance does

#

you can model it yourself tho

ripe shard
rough granite
rough granite
#

What how is it ive used unity for a year and a few months now and not heard of this :/

ripe shard
#

it wont ever be fully realistic without adding your own (complex) simulations, but it gets you closer

ripe shard
rough granite
ripe shard
#

the "Temporal Gauss Seidel" solver is somewhat required if your objects have large mass differences.

#

after all PhysX is a generic collison solver and query engine, and it makes a lot of compromises to achieve that generality. Unless you truly need the native performance of the N-body collision solver, you can build a custom force simulation yourself, easily, on top of the query API. Generic collisions with restitution and friction always are complicated though.

lunar coral
#

hi, I have a problem in my game, I've an interacting system with doors and once I run the game/enter playmode, the doors open themselves, https://paste.ofcode.org/psG53awizPxGSqHdFskPWu here's the door script, I call OpenDoor() function when the player interacts with the door

#

the only problem is they open themselves at the beginning but after it works pretty well

grand snow
#

You should be using an animator variable (bool) and state transitions to control the open and close animation playing instead

#

also why are there loads of random new lines in the code?

wintry quarry
lunar coral
wintry quarry
#

btw:

if (!open) {
}
else if (open) {
}```
Can just be:
```cs
if (open) {
}
else {
}```
lunar coral
grand snow
wintry quarry
lunar coral
#

what does it change? 2 lines less

grand snow
#

You shouldnt use triggers but a bool

wintry quarry
#

no it's more logically correct

#

the else if implies there can be other states besides true or false

#

and may lead to coding errors like adding other else conditions

#

it's also less performant (negligibly)

#

definitely not a lines of code thing

lunar coral
#

ohhhh

grand snow
#

If you use a bool for the open state it will be easier to let the animator transition back correctly to the new state

lunar coral
#

I thought you meant the style with tghe }{

wintry quarry
#

no sorry

#

that was just poor formatting

lunar coral
#

tbh I wanted to make an else too, one if one else if and one else, its just a basic script

#

there will be another way to open the door

wintry quarry
#

Anyway - can you show us the state machine lol

lunar coral
#

I'm not going to compare with the bool variable only

forest horizon
#

@wintry quarry

lunar coral
#

and what would the bool help with tho? I mean I know it'd be better but there are a lot of people that use Triggers for everything

#

this probably isn't the cause of the issue

sour fulcrum
grand snow
# lunar coral

You need a transition from open -> close and also close -> open that uses your bool
You want to setup exit time on the transitions to work as you desire (to either wait till the end of the animation or be allowed to transition at any time)

#

Now this introduces a new issue btw. If your animations are to open and close the door, you need a third animation that is either empty or static for the default state of the door

#

This should be the default state. This will prevent the door from playing an opening or closing anim when the game starts

lunar coral
lunar coral
sour fulcrum
#

I got no beef with you homie im just saying no one else has an issue either, asking basic questions is just a good way to solve problems. Animation stuff like this is a pain in the ass so i totally get your frustration

lunar coral
#

and for the default state, making an empty state wouldn't work?

grand snow
#

Hopefully this is making sense

lunar coral
lunar coral
#

@grand snow I've just changed it to work with a bool "open" variable, and it does the exact same thing as before

#

I think the entry state opens the doors, I don't know though

grand snow
#

(in play mode)
I presume the default state or transitions are incorrect

lunar coral
grand snow
#

If how the door is at the start is closed, you only need a transition to "open" that uses the bool "open"

lunar coral
#

the doors open themselves at the beginning without me interacting with them

#

I have a script that has a bool variable called open, I set it to false in Start() method, then in the Update() I've an if and an else condition, if (!open)
{
animator.SetBool(boolName, true);
open = true;
src.PlayOneShot(openSound);
}
else
{
animator.SetBool(boolName, false);
open = false;

        src.PlayOneShot(closeSound);
    }
grand snow
#
  • animator transitions have no conditions set
  • something tells the door to open on game start
  • empty state has an animation assigned
#

Im thinking one of these

slender nymph
#

it's flipping back and forth every frame

lunar coral
slender nymph
#

also in the first frame that Update runs you tell it to open

lunar coral
grand snow
#

There was no use of Update() in the code sent last?

slender nymph
lunar coral
lunar coral
#

I changed the script too, the other one was too complex for nothing, I use has exit time set to 0.75 instead

grand snow
#

You can also add logs to know when the door is told to open (or use a debugger)

lunar coral
grand snow
#

well something is wrong clearly and im out of ideas

lunar coral
#

and when I tell you there are no issues with the things you mention, I'm sure about what I'm saying,I'm not lying to you you know

slender nymph
#

have you actually verified using logs and/or breakpoints? because your assumptions could be wrong

lunar coral
#

for me, as there are no issues in the scripts, it probably comes from the entry state in the animator state but there are no animation clips assigned so its weird

lunar coral
slender nymph
#

then show it

lunar coral
slender nymph
#

didn't think it was needed
when debugging it is almost always needed so you aren't making incorrect assumptions

lunar coral
lunar coral
slender nymph
#

i mean logs and/or breakpoints are always needed when debugging

grand snow
#

"What is telling my door to open?"
add a breakpoint and find out!

slender nymph
#

add logs to the OpenDoor method, ideally useful logs that provide relevant information and not just a useless string that tells you the method has been called

lunar coral
slender nymph
#

then congrats, it isn't this code doing it

#

it's most likely either some other code or your animator setup

lunar coral
#

the problem most likely comes from the entry state

lunar coral
#

it's the animator setup for sure

#

bruh, I was so much improving, making cool things and now I can't animate a door, my brain is washed

slender nymph
lunar coral
# lunar coral

here it is, the transitions conditions are open == true if it's towards the open state and the other way around for the other state

slender nymph
#

that does not show the transition, that shows you have selected a transition and are looking at the animator parameters

#

you have conveniently cropped out the actual important information which is on the right in the inspector window

lunar coral
slender nymph
#

ITT we learn about sarcasm

#

anyway, the only way for it to transition to open is if your animation parameter is set to true. so something is setting it true somewhere, whether that's from being true by default, or some code somewhere, that is the only way this is happening

lunar coral
lunar coral
#

and there is nothing changing it.... in any scripts

#

isn't it possible to be the entry state?

#

I know this shouldn't be it as there is no motions/animation clips

slender nymph
lunar coral
#

but this is the only thing left...

slender nymph
lunar coral
# slender nymph don't make assumptions.

it's a project I've made 2 days ago, there are like 5 scripts max, 3 of them are for the player Controller and the 2 others are the one I showed u, and it seems to have nothing setting the bool to true...

slender nymph
lunar coral
#

okay wait

#

false

forest horizon
#

whenever i download the unity assistant i get these errors and it ruins the whole project i dont understand

lunar coral
#

on PlayMode

#

and the doors are opened

slender nymph
#

select the object that uses this controller

lunar coral
forest horizon
#

i couldnt solve this issue

lunar coral
#

Im going to rec and show u

slender nymph
# lunar coral I am

show that object's inspector because this isn't showing the object in any state

lunar coral
#

does it show any revelant informations? or did I crop out the actual important information again? if I did,I'm really sorry I'm trying my best

slender nymph
#

are there any components on that pivot's parent object?

forest horizon
#

@slender nymph can you check the screenshot i sent up above

slender nymph
#

don't ping people into your issues. your question is also not an issue with your code and therefore does not belong in this channel

forest horizon
#

where does it belong

slender nymph
forest horizon
#

well i am not receiving anything

#

and can you not be rude ?

slender nymph
#

point to where i was being rude

forest horizon
#

its not what you say its how you say it

#

whatever

slender nymph
#

i'm not going to offer empty platitudes just to soothe your ego

forest horizon
#

ego

slender nymph
forest horizon
#

can you reread your messages and think if there was a nicer way to say the things you said?

lunar coral
slender nymph
#

so the pivot object's parent also has an animator?

lunar coral
slender nymph
#

i am referring to the one between the "doors" and the "pivot_1" object

lunar coral
#

All the doors have a pivot Parent gameobject which has the animator component with the animator controller that I showed you and they all are the child of the doors empty gameobject

lunar coral
slender nymph
#

your hierarchy goes doors > Wood Door_1 > pivot_1. I am asking about the middle object

lunar coral
#

The one above is the whole door gameobject, which contains the pivot + frame + door

#

The pivot is the parent of the door as the door is the only thing that should open and close, the frame is the frame, so around the door, and both the frame and the pivot are the child of a parent gameobject which contains the whole door, and then all those door containers so the doors are the child of the doors empty gameobject

slender nymph
#

I am asking if that object has any components

#

Also, you have confirmed that you did not mix up your animations, right?

lunar coral
lunar coral
forest horizon
#

i solved it thanks for nothing buddy boxfriend

stone heron
#

no need to be rude

polar acorn
#

An important lesson

molten mantle
#

indeed

forest horizon
#

the point is, i read his older messages and he is very unpolite

#

i did not say those things because he didnt help me

#

no one has to help no one

#

and he was already on the chat so pinging is not the problem

#

not against the rules

polar acorn
#

and is against the rules

slender nymph
slender nymph
fading dune
#

Hey everyone! Not sure if this is the right place to ask, but I’ll give it a shot.

I’ve been using Screen Space - Camera for my UI for a while, but I recently switched to Screen Space - Overlay. That change ended up breaking some of my mouse position logic.

From what I understand, I should now be using Input.mousePosition, which seems to work, but I’m not entirely sure if that’s the correct approach.

I also have an icon that follows the cursor with a set offset, but the offset now seems to be in pixels, so it changes depending on the screen resolution.

If anyone has some advice or resources on how to handle this properly, I’d really appreciate it!

grand snow
lunar coral
#

Ohhh my bad I pinged you, didn’t intend to do so…

#

Sorry

slender nymph
#

It's only against the rules to ping people you aren't currently in conversation with

#

Anyway, just to confirm, this issue affects all doors with this animator+animation controller, or only this one?

true pine
#

this code looks like it'd operate perfectly fine, so why is it giving me spread that looks like the second image?

meager steppe
#

im wondering for the access control cloud code , json thing is this a valid urn ? ""Resource": "urn:ugs:cloud-code:/v1/projects//modules/","

#

cloud code is but i cant find about modules

wintry quarry
#

Also you could just do playerCamera.transform.forward no need for the viewport point thing

true pine
true pine
true pine
wintry quarry
#

that tells me that your code is using the value of spreadOffset

true pine
#

oh wait

wintry quarry
#

I want to know what that value actually is

true pine
#

wait not that one the line above it

wintry quarry
#

ok what's the value of spread

true pine
#

that's the one I change between weapons, it was 10 in the screenshot

wintry quarry
#

Can you show the shooting code that uses this function?

frigid sequoia
#

Apparently neither 1 or 0 correspond to any id on the animator, even tho it has quite literally just one bool, am I missing something? How do I know the id of the parameter?

wintry quarry
#

(which is what the string version of the function uses under the hood)

frigid sequoia
#

Shouldn't this work and be faster than looking for a string? Or I just don't understand this?

wintry quarry
#

You can use StringToHash to get the int

#

then you can use that int and it will be faster yes

#

The animator maps parameter names to ints with that hash function

frigid sequoia
#

But they are not ordered ints? Just random values that I don't know?

wintry quarry
#

exampkle:

int jumpParamHash;

void Start() {
  jumpParamHash = Animator.StringToHash("Jump");
}

void Jump() {
  animator.SetBool(jumpParamHash, true);
}```
frigid sequoia
#

So I pretty much do that on awake, got it

#

I just don't get the why

wintry quarry
#

otherwise if you rearranged the parameters suddenly your code breaks, as do parameter IDs being saved to files, sent over networks, etc

wintry quarry
frigid sequoia
frigid sequoia
wintry quarry
#

the hashcode function is a static function

#

it's just based on the string

wintry quarry
#

definitely not random

frigid sequoia
#

Where is it looking for that string?

#

Can I not have two animators using the same string?

wintry quarry
#

it's running a hash function on the string data

wintry quarry
#

that's a bad primer actually

#

delves into jargon too quickly

frigid sequoia
wintry quarry
#

maybe ask chatgpt about hash functions a bit

frigid sequoia
#

I just wanna know, here, for example, it is returning me a hash for that string; that string can be in many animators, but I am not referring any in particular, so, what is that hash code asociated with?

wintry quarry
#

that's all

#

"Play Fadeout"

frigid sequoia
#

Ooooh, now I get it

wintry quarry
#

the hash function maps strings to integers in a consistent way

frigid sequoia
#

But that's basically the same than looking for a string but with extra steps right?

tough lagoon
#

Mmm lets say you are pulling a string animation bool reference from two scripts. A hash would let you target one more specifically.

#

But its more like a unique identifier

wintry quarry
frigid sequoia
#

Yeah, yeah, I thought it was getting a direct reference to the parameter in the animator as an int in a list

#

But I guess it just generates a hashcode for a particular string and you just type that isntead

#

But that just seems worse to me

tough lagoon
#

I would've assumed it was an int based on order, but a hash makes sense.

#

You could probably go your whole career without needing to use one, but i find i use them a lot more with custom asset importers etc.

frigid sequoia
#

It would have then to get the string from the hashcode, then search by string, instead of just searching by string which was the part I was trying to avoid cause that's usually kinda slow

#

I am confused by how so many parameters on some components have to be accesed by string search instead of having a direct path

#

But what do I know, I am total newbie

timber tide
#

animator is special and yes the string stuff is annoying

#

similarly, loading by string / path values

wintry quarry
#

the params are stored by hashcode

#

when you use strings it goes to the hashcode then to the param

timber tide
#

but the hash idea is probably as good as you're getting. Ideally I would like if the animator exposed the enum that was created inside of the blend tree

tough lagoon
#

I personally wouldn't worry too much about that unless you really need to zero in the performance. 95% of performance issues will come out of your rendering, physics, disk ops and things of that nature.

Sometimes the readability is more important than the small performance gain.

But it is highly valuable knowing how it works, should you find out you do need to do it at some point. Imho anyway.

frigid sequoia
zenith cypress
#

Chage the order, now your index is wrong in all usecases. Meanwhile the hash won't have that problem and is unique to that name LUL

frigid sequoia
frigid sequoia
#

You usually add more, but do not remove that many

tough lagoon
#

I mean, if you are applying these changes in hundreds of animation controllers in an update loop - yes its going to be a problem. But setting a bool is probably being done once in a few seconds to a single controller.

timber tide
#

You can also add another layer and map an enum in your script to that string value, so you'll just end up modifying that value inside of the enum

#

but the string to hash idea is very similar and I would just do that

rain solar
#

i have a chunked world built with an oct tree and I am currently bottle necked by the traversal i do every frame to check which chunks need to be loaded. The traversal itself is already efficient but because its called every frame it drops the fps. What is the solution to this?

#

i could run it on a seperate thread but that requires locking the world too much and the fps drops would still be present

#

the traveral is for every node that intersects a given spherical area, ensures all child nodes exist down to leaf size (1 chunk). For each missing leaf chunk within the radius, it queues a ChunkRequest if it’s not already loaded or being loaded

#

so it does a ton of extra work because almost all chunks are already loaded but i dont know a better way

rain solar
#

to find what

wintry quarry
#

to find the bottlenecks in your algorithm

rain solar
#

the bottle neck is the algorithm itself, finding microoptimizations isnt gonna help

wintry quarry
#

How do you know what is and isn't a major or micro optimization without using the profiler?

#

Profiling is step one of any optimization

rain solar
#

yeah ive profiled it and done the micro optimizations

wintry quarry
#

Can you show the profile?

rain solar
#

i dont have it no more

wintry quarry
#

make a new one

rain solar
#

mk

wintry quarry
#

showing the code will also be helpful of course

rain solar
#

its not in C#

#

i can profile it again though

wintry quarry
frank rover
#

Am I inter rupting something

rain solar
#

nah u good

wintry quarry
#

ALso 3, please don't share code as screenshots

#

!code

radiant voidBOT
frank rover
#

Ok

placid jewel
#

What is the code meant to do that it's not?

frank rover
#

It is souposto deal dammage when you walk in to it but it isn't detecting that it is walking into it

#

I'm bad at spelling

wintry quarry
#

For Unity you need to use Debug.Log

frank rover
#

That is what vs said to do

wintry quarry
#

Sounds like probably VS is not configured properly for Unity

#

Or it just gave a bad AI suggestion

#

that you followed

placid jewel
wintry quarry
#

The first step would be fixing your log statement

#

and running the game again

#

and seeing if it prints

#

if it doesn't, you've messed something up in the scene setup

hearty vale
#

It's my first time chatting here, but I just wanted to say that I took 2h to find out that my project had a problem bcs I forgot to put "=" in playerRB = GetComponent<Rigidbody2D>();

I love programming

wintry quarry
#

(You are running the game with the Console window open, right?)

frank rover
#

yes

wintry quarry
placid jewel
frank rover
#

yes

placid jewel
#

Have you changed the line to Debug.Log? Does the debug statement execute?

frank rover
wintry quarry
#

A Rigidbody2D is required for OnTriggerEnter2D

placid jewel
#

it could be there and just not shown right?

wintry quarry
#

could be, sure

frank rover
#

now it prints

wintry quarry
#

i'm guessing it's not though

hearty vale
placid jewel
wintry quarry
#

(fy it's spelled "Damage", one 'm')

frank rover
#

It works now

#

Thank you

placid jewel
# frank rover Thank you

No worries, also I know it's not what you were asking for but just fyi Dammage -> Damage, Ammout -> Amount (I assume) (in the heal function)

green snow
#

I'm having an issue with raycasting, the firepoint -> raycast end works fine if i'm shooting something far away but when I'm shooting up close or on the ground then there's an issue

placid jewel
#

Can you send your code? @green snow

#

!code

radiant voidBOT
green snow
#

sec

#
var weaponEntity = SystemAPI.GetComponent<ProjectileWeapon>(player.ValueRO.ControlledCharacter);
                    var weaponLtw = SystemAPI.GetComponent<LocalToWorld>(weaponEntity.WeaponEntity);
                    float3 firePoint = weaponLtw.Position;

                    var cameraTransform = SystemAPI.GetComponent<LocalTransform>(player.ValueRO.ControlledCamera);
                    float3 cameraForward = MathUtilities.GetForwardFromRotation(cameraTransform.Rotation);
                    
                    var projectileEntity = ecb.CreateEntity();
                    int vfxIndex = bulletManager.Manager.Create();

                    var rayLength = 200f;
                    var rayStart = cameraTransform.Position;
                    var rayEnd = cameraTransform.Position + cameraForward * rayLength;
                    
                    var raycastInput = new RaycastInput
                    {
                        Start = rayStart,
                        End = rayEnd ,
                        Filter = CollisionFilter.Default
                    };
                    
                    PhysicsWorldSingleton physicsWorldSingleton = SystemAPI.GetSingleton<PhysicsWorldSingleton>();
                    var hits = new NativeList<RaycastHit>(Allocator.Temp);
                    physicsWorldSingleton.CastRay(raycastInput, ref hits);
                    
                    Debug.DrawRay(raycastInput.Start, raycastInput.End);
                    
                    float3 dir = math.normalizesafe(raycastInput.End - firePoint);

                    ecb.AddComponent(projectileEntity, new FirePointRaycast
                    {
                        VFXIndex = vfxIndex,
                        StartPoint = firePoint,
                        EndPoint = raycastInput.End,
                        Direction = dir,
                        Speed = 100f 
                    });
#

that's where i'm sending the first ray from center camera

#

 private void Execute([ChunkIndexInQuery] int chunkInIndex,
                RefRW<ThirdPersonPlayerFixedStepControlSystem.FirePointRaycast> ray,
                Entity entity)
            {
                float3 currentPos = ray.ValueRO.StartPoint;
                float3 newPos = currentPos + ray.ValueRO.Direction * ray.ValueRO.Speed * DeltaTime;

                bool reachedEnd = math.dot(newPos - ray.ValueRO.StartPoint, ray.ValueRO.EndPoint - ray.ValueRO.StartPoint) >=
                                  math.lengthsq(ray.ValueRO.EndPoint - ray.ValueRO.StartPoint);

                var hitList = new NativeList<RaycastHit>(Allocator.Temp);
                var input = new RaycastInput
                {
                    Start = currentPos,
                    End = newPos,
                    Filter = CollisionFilter.Default
                };

                if (PhysicsWorldSingleton.CastRay(input, ref hitList) && hitList.Length > 0)
                {
                    reachedEnd = true; 
                }

                hitList.Dispose();

                var vfxIndex = ray.ValueRO.VFXIndex;
                var vfxData = BulletManager.Datas[vfxIndex];
                vfxData.Position = newPos;
                BulletManager.Datas[vfxIndex] = vfxData;

                if (reachedEnd)
                {
                    Debug.Log("Reached End");
                    BulletManager.Kill(vfxIndex);
                    Ecb.DestroyEntity(chunkInIndex, entity);
                }
                else
                {
                    ray.ValueRW.StartPoint = newPos;
                }
            }


#

and i'm moving the second raycast from fire point to the center camera end raycast by the speed

#
float3 newPos = currentPos + ray.ValueRO.Direction * ray.ValueRO.Speed * DeltaTime;
#

another gif showing the ray debug in the sceneview

#

not sure what's the issue :/

wintry quarry
#

really not for the beginner channel

green snow
#

ah thought i'd post here since it's mostly math related

green snow
#

fixed it, my issue was when I casted the first ray here physicsWorldSingleton.CastRay(raycastInput, ref hits); I didn't check if I hit anything so I could set what I hit to my target position

primal steppe
#

Does anyone know a way to deform a plane so that it conforms to the shape of a modified terrain in Unity?

midnight plover
lunar coral
lunar coral
#

@slender nymph as I'm really clueless, I asked chatgpt and he told me the problem comes from the empty state and I should make "close" state as the entry state

#

well, that doesn't change anything

naive pawn
#

maybe don't use chatgpt for stuff

lunar coral
naive pawn
#

what was the issue you had?

#

it's sounding like an animation issue rather than a code issue, but i don't have full context

lunar coral
lunar coral
#

all the doors have no scripts, no interactions, the only thing present is an animator

naive pawn
#

ok so why are you here

lunar coral
naive pawn
#

this is the code channel

sour fulcrum
#

atp they are probably preferred here

#

or a thread

#

this has some history

lunar coral
# naive pawn ask in <#502171313201479681> then lol

well, think a little, go up in the conversation, figure out why I've started the conversation here, and why would I want to continue the conversation with someone I was talking with in a different channel

sour fulcrum
#

theres extended convo from earlier

naive pawn
#

that doesn't excuse using the wrong channel, no

lunar coral
naive pawn
#

conversations with specific people don't really exist - or well, don't need to exist - in these support contexts. what matters is questions, and the questions need to be in the right place

#

you just said it's not code related, so this channel is the wrong place if that's the case

naive pawn
faint osprey
#

is anyone familiar with graph toolkit if so how do u set the ouput port values of a node

tender mirage
#

I'm currently working on a tile generating function which determines which type of tile is spawned and passes it to the generator function

my question was. since this script can run pretty often (everytime you dig down) it can be abit heavy. Does adding return early to it stop the rest of the code from running hence increasing performance?


//if spawned tile is dirt, don't assign anything
 if (randomTile == 1)
 {

     //Generate dirt
     GenerateTile(x, y, tileBase[1]);

     return;

 }
 else
 {
     //MinMax spawn position
     int minFt = tileBaseManager.dataFromTile[tileBase[randomTile]].minFt;
     int maxFt = tileBaseManager.dataFromTile[tileBase[randomTile]].maxFt;


     //Can only spawn between tiledata fts -4 because spawner is 4 tiles below - 1 for clarification
     if (ft > tileBaseManager.dataFromTile[tileBase[randomTile]].maxFt + spawnOffsetPos - 1 && ft < tileBaseManager.dataFromTile[tileBase[randomTile]].minFt + spawnOffsetPos)
     {

         //SpawnRate
         int spawnRateNum = Random.Range(0, tileBaseManager.dataFromTile[tileBase[randomTile]].spawnRate);


         if (spawnRateNum == 0)
         {
             //Spawn tile
             GenerateTile(x, y, tileBase[randomTile]);

             return;
         }
         else
         {
             int emptyTileRate = Random.Range(0, 16);

             if (emptyTileRate == 0)
             {

             }
             else
             {

             }

         }

     }
rich adder
tender mirage
# rich adder which return you talking about ? it will stop whatever is underneath sure, if y...

for some reason the script didn't properly show up but here it is. i added some early return ends when i could. is this a nessecery and good practice if i don't want rest of the script to run

//if spawned tile is dirt, don't assign anything
 if (randomTile == 1)
 {

     //Generate dirt
     GenerateTile(x, y, tileBase[1]);

     return;

 }
 else
 {
     //MinMax spawn position
     int minFt = tileBaseManager.dataFromTile[tileBase[randomTile]].minFt;
     int maxFt = tileBaseManager.dataFromTile[tileBase[randomTile]].maxFt;


     //Can only spawn between tiledata fts -4 because spawner is 4 tiles below - 1 for clarification
     if (ft > tileBaseManager.dataFromTile[tileBase[randomTile]].maxFt + spawnOffsetPos - 1 && ft < tileBaseManager.dataFromTile[tileBase[randomTile]].minFt + spawnOffsetPos)
     {

         //SpawnRate
         int spawnRateNum = Random.Range(0, tileBaseManager.dataFromTile[tileBase[randomTile]].spawnRate);


         if (spawnRateNum == 0)
         {
             //Spawn tile
             GenerateTile(x, y, tileBase[randomTile]);

             return;
         }
         else
         {
             int emptyTileRate = Random.Range(0, 16);

             if (emptyTileRate == 0)
             {

             }
             else
             {

             }

         }

     }
rich adder
#

actually both are kinda pointless rn (unless you have more code outside these if)

tender mirage
# rich adder actually both are kinda pointless rn (unless you have more code outside these if...

They can run pretty often which was my concern, i had to optimize the code to make my game playable again.

but yeah i've added alittle more below the Spawnratenum

//Generate special tile
if (spawnRateNum == 0)
{
    //Spawn tile
    GenerateTile(x, y, tileBase[randomTile]);

    return;
}
//Generate dirt or empty tile
else
{
    int emptyTileRate = Random.Range(0, 16);


    if (emptyTileRate == 0)
    {

        //Generate dirt
        GenerateTile(x, y, tileBase[1]);

    }
    else
    {
        //Generate empty
        GenerateTile(x, y, null);

    }

}
#

if you say it''s pointless i should like you said probably

#

test out if theres any

#

difference

rich adder
#

so return just stops the rest of the entire function you have this code in

tender mirage
#

oh thanks for noticing. thats alittle oversight

#

i made.

limber bolt
#

hello, listen I have a raw image in the UI and I want that if I click in certain position, it make something different than if for example I click in other object

#

Im not sure how to do that

rich adder
rough granite
#

Yeah souldn't use box colliders on ui

rich adder
#

if you want different sections to click on you can just make addtional Images as hitbox, and turn the Alpha down

limber bolt
rich adder
#

the concept is the same, you can turn down alpha so they're still clickable but see through

limber bolt
#

thanks, ill try!

low copper
#

I have a slider that is calling ChangeBitrate() as shown in the attached image. The code is as simpe as can be :

    public void ChangeEncoder(float value)
    {
        Debug.Log("Changing Encoder to: " + value);
    }

It runs on change but only passes the value 0. I have this exact script working on another element without issue. The only thing I noticed strange is for some reason it is showing an input within the "On Value Changed" editor component...I don't know why it is showing that...it is set to 0

low copper
#

Sorry....I don't know what that means

rich adder
slow viper
#

Hello can somene pleas check my code if it si right https://paste.mod.gg/ksiwnziyjeog/0 i was trying to make working save sytem but is is not working and i dont know why when i save palyer position and go back to the menu a spawns at diffrent position than i saved

low copper
#

Ahhh...ok...I see that it appears twice in the list.

#

Will test now

#

@nav : Thanks so much that was it

rich adder
#

also consider putting more logs / make them in english when you request help so people can also understand what you're logging

slow viper
#

ok i will change it to englih

#

english

rich adder
#

ie is Load / save printing etc.

slow viper
#

Loaded postiont in fist time netering the game is Loaded player position: (-30.26, -13.17, 0.00) Current player position: (-9.39, -13.17) and saved position is Saved player position: (-9.22, -13.17, 0.00) and if i go back to menu and to the game the position is Loaded player position: (-9.22, -40.01, 0.00)

wintry quarry
#

it makes it difficult to tell what order your logs are printed in

slow viper
#

yeah but if i turn it off the there are 2 audio liseners in you scne mesege wont stop spaming

wintry quarry
#

so get rid of one!

slow viper
wintry quarry
#

The part where it's changing is after loading and before saving

#

so the position is being modified in the game itself or in the saving process

slow viper
#

i can send you the video how it looks in game but dicord wont let me send it if i dont have nitro so are there other ways to send it?

true jacinth
#

I am incredibly green to coding and programming any good video series to watch I want to learn and get at least decent at it?

slender nymph
#

there are beginner c# courses pinned in this channel and the pathways on the unity learn site are a good next step to learn how to use the engine

nimble laurel
#

Hi all, I'm trying to learn the cloud code stuff and in the last day or so I can no longer see my CloudCodeService logs in the Dashboard -> CloudCode-> Logs,
but... If I go to Projects-><ProjectName>->Theres a banner for Diagnostics(View Diagnostics)-> Then finally -> Logs. Then I can see the cloud code logs i used to see in CloudCode-> Logs...
Anyone know if this was changed or if I might've hit some weird button somewhere in the last 2 days..
I hope that made sense πŸ€¦β€β™‚οΈ

slow viper
forest cosmos
#

Hi.
We take input in update and use that to move using fixed update is using rigidbody.
so taking bools in update, checking in update and then reseting their values.

midnight zealot
#

@swift elbow

forest cosmos
#

Any easier way? New Input system does it well?

swift elbow
rough granite
swift elbow
swift elbow
forest cosmos
#

I mean its annoynig to reset bools after everything happens

#

I get jumppressed = true in update

#

after jump i have to reset it to false.

midnight zealot
#

@rough granite I really dont know πŸ™

swift elbow
forest cosmos
#

oh okay

forest cosmos
#

before i just did everything in update

midnight zealot
#

@swift elbow so you mean i should click on "IsTrigger" ?

rough granite
swift elbow
#

isnt that what they said?

midnight zealot
#

@swift elbow it does not work and nothing is printed in the console :/

rough granite
naive pawn
rough granite
naive pawn
swift elbow
forest cosmos
rough granite
forest cosmos
#

oh okay

#

thank you

verbal dome
#

No need to do it in 3 different places when it is done anyway

forest cosmos
#

Oh yes

#

thanks for pointing it out

hoary ice
#

hello

#

im stupid

cosmic quail
spice burrow
#
        {
            transform.position += Vector3.right * speed * Time.deltaTime;
        }

        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
        {
            transform.position += Vector3.left * speed * Time.deltaTime;
        } ```

Anyone know how to smooth this movement a little? (as in rounding the movement by introducing a bit of acceleration (and deacceleration, havent rlly decided on how that would be implemented tho))

I'm very new.
tender mirage
spice burrow
#

Thanks a lot!!! I'll def look into that.

#

You sure seem like you love typing a lot.

tender mirage
#

I hehe, yeah, i was typing an example. but if that's not what you want

#

i can stop.

spice burrow
#

You can keep doing that, I'd love an example

tender mirage
#

Alright.

cosmic quail
spice burrow
cosmic quail
spice burrow
tender mirage
#

float playerSpeedX = Mathf.SmoothDamp(playerSpeedX, playerMaxSpeedX, ref velocityX, acceleration); //this also contains more methods which aren't required but grant you even more versitility

//If that's abit too much here's a another example


//Progress repressants the value that's gonna be applied in between playerSpeedX/playerMaxSpeedX
//and progress is a 0/1 between value. if progress is 0.5f then players speed becomes 2.5f
float playerspeed = 0;
float playerMaxSpeed = 5;

float playerSpeedX = Mathf.Lerp(playerSpeedX, playerMaxSpeedX, progress)



//If you're familiar with vectors yet you can also use
//Vector3.Lerp
//Vector3.SmoothDamp

spice burrow
#

oh dang that is a whole lot

#

will look into it

tender mirage
#

Yeah. although you can just use rigidbody.linearVelocity which handles physic movement

#

for you

#

instead of manually moving the object

#
RigidBody rigidbody;


//this gives your object velocity movement
rigidbody.LinearVelocityX = 3;

//Alternatively this gives you more of a car like force that can accelerate.
rigidbpdy.AddForceX(3);


spice burrow
#

huh. alright.

#

reading a bit about mathf.smoothdamp now :)

tender mirage
#

Mathf.SmoothDamp is the way to go for smooth moment or variable changes. that''s an good call

spice burrow
#

alright, i kind of get how it works.

spice burrow
#

stupid question

tender mirage
#

Yeah everything has a logical reasoning. to calculate movement you would have to do that constantly

#

every frame

spice burrow
#

i plug the playerspeed variable in place of the speed variable I had, right?

#

Seems logical

tender mirage
#

Not sure. that depends on what your speed variable looks like

spice burrow
#

it's just a public float right now

#

with a number

tender mirage
#

oh, then yeah

#

although probably specify if it's purpose is for x or y movement if you havn't already

spice burrow
#

I don't see how that would work??

tender mirage
#

That's how it works. I was skeptical when i first got into it as well. the first paramater repressents the current variable, that's just how it works.

you need a starting point which is your current speed and a goal which is the target speed.

rough granite
#

never seen any ide accept that

#

especially in the same scope

spice burrow
#

mine certainly does not

tender mirage
#

well that's how i handled it and it works perfectly fine.

rough granite
spice burrow
#

also why do you write "ref" in your example

polar acorn
polar acorn
tender mirage
tender mirage
spice burrow
#

hmmm alright wait

polar acorn
tender mirage
#

i think we're just confusing him more.

polar acorn
#

that's what Magic was referring to

tender mirage
#

although i want to be called out if i'm wrong on something

#

so this is kinda conflicting