#💻┃code-beginner

1 messages · Page 776 of 1

hot wadi
#

Performance wise, they are not too far apart. If u find the built-in object pool too intimidating, I would say practice with the oldschool

polar acorn
#

pooling

slender nymph
#
  1. it's pooling not spooling
  2. making your own object pool is more complicated than just using the built in one
tired python
hot wadi
#

For new dev, I think the built-in pool is quite ambiguous. It hides how the pool internally works, so it may get confusing

tired python
#

you know what screw this, even if it takes me a whole week to implement it i will do this then

hot wadi
#

But basically they are similar. Both use Stack or List

astral cedar
#

how do i get an action map that is not currently selected?

tired python
spring snow
#

unity is hard bro

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

public class CusCursor : MonoBehaviour
{
    public bool locked;

    void Start()
    {
        Cursor.visible = false;
        locked = true;
    }

    void Update()
    {
        Vector3 mousePos = Input.mousePosition;
        mousePos.z = 0f; // z is 0 for 2D

        // Convert screen position to world position
        Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
        worldPos.z = 0f; // make sure z stays 0

        transform.position = worldPos;

    //stops working here
     if (Input.GetKeyDown(KeyCode.L))
    {
        if (locked)
        {
            Cursor.visible = true;
            locked = false;
        }
        if (!locked);
        {
            Cursor.visible = false;
            locked = true;
        }
    }
    }

    
}

litterally everything is working other than the booleans

slender nymph
#

read through this logic and tell me what you think is happening in a single frame here. assume locked == true

if (locked)
{
  Cursor.visible = true;
  locked = false;
}
if (!locked);
{
  Cursor.visible = false;
  locked = true;
}
spring snow
slender nymph
#

let's assume i put a Debug.Log call right after that code, what will it print if all it prints is the locked variable?

#

remember, read through all of the logic here

spring snow
slender nymph
#

what specific value is it going to print

spring snow
slender nymph
#

incorrect. read through the logic again

spring snow
slender nymph
#

(i'll give you a hint, there are two reasons why that is incorrect)

slender nymph
#

read through the logic one line at a time.

spring snow
# slender nymph read through the logic one line at a time.
if (locked) //checking if locked is true
{
  Cursor.visible = true; //makes mouse visible
  locked = false; //locked is now false
}
if (!locked); //checks if locked is false
{
  Cursor.visible = false; //hides cursor
  locked = true; // locked is true now
}
slender nymph
#

now that you have those comments there, read through the logic and actually apply those steps in your head

spring snow
#

ok

#

What i want: if locked = true then hide mouse

line 1. if locked is true then do this
line 2. since locked is true set the mouse to visible
line 3. now the mouse isnt locked

line 4. checks if locked is false
line 5 - 6. if locked is false then hide cursor and locked is now true

#

i might be stupid

#

since im running on 3 hours of sleep

#

but i dont see the issue

slender nymph
#

have you considered continuing through the rest of the code? don't just stop because you think you know the answer, finish evaluating the lines

spring snow
#

i edited it

slender nymph
#

which of the two issues did you fix though (assuming by "edited it" you mean you fixed an issue)

spring snow
#

i get it now

#

its running both lines anyways

#

i added debug to both if statements and it sets it to false then true

#

thanks guys/girls

slender nymph
#

yes because they are independent if statements. your second if statement is also unrelated to the block of code below it, but i'll let you see if you can figure out why that is (hint: your IDE should be telling you that too)

spring snow
#

but when i did elseif it came up with an error

slender nymph
#

that's likely because of the issue i just mentioned

spring snow
#

is it like else if or elseif

#

ill try both

spring snow
#

@slender nymph is it because i put a ; which cancles the second if statement

#

ok imma try without it

#

yoooo

#

it works now

#

yay

#

thank you

polar acorn
spring snow
#

i mean it as a metaphor

polar acorn
#

instead of an else

spring snow
#

atwhatcost oh

polar acorn
#

What situation could you have where neither code block runs?

spring snow
#

yea i see what you mean now

spring snow
#

makes sense

#

thanks

slender nymph
#

even better would be remove the if statement entirely because it isn't really necessary anyway. you can set Cursor.visible to locked and then !locked to locked

#

and that's assuming you even need the locked variable for something else, otherwise you can just toggle the value of visible

spring snow
#

not right now

#

but eventually

#

also it's going to be a pause function eventually so i'll just keep it for now

slender nymph
#

let's put it this way, you have a variable that is basically serving a very similar purpose to the property on the Cursor class you are changing. at least with regard to your logic, i understand actually changing that property toggles whether the mouse cursor is visible. but that property also tells you if the mouse cursor is visible or not
and you can just change its value each time you press your input instead of checking what the value is to change it to the opposite of that

tired python
#

so i watched this video again, and i think i know how pooling works. so basically you need to setup four methods:-

  1. a method to create objects
  2. a method to reenable objects with the right properties
  3. a method to deactivate objects based on your needs
  4. a method to destroy objects.
    what i don't understand is why is the guy taking _pool references insides the different scripts. i don't get it

Show your Support & Get Exclusive Benefits on Patreon (Including Access to this project's Source Files + Code) - https://www.patreon.com/sasquatchbgames
Join our Discord Community! - https://discord.com/invite/aHjTSBz3jH

By the end of this Object Pooling tutorial, We will have replaced a projectile spawn setup from a simple Instantiate and Dest...

▶ Play video
slender nymph
#

again, it is pooling not spooling. it's even in the thumbnail and title of that video you linked

tired python
#

sry, i think it's become a bad habit of mine to do that, i just subconciously do it...

#

specifically from 8:03

#

whatever he does in the Bullet and BulletSpawner script to set up the pool ain't making sense

slender nymph
#

just keep watching, he'll explain why later

rocky canyon
# spring snow ```C# if (locked) //checking if locked is true { Cursor.visible = true; //make...
private bool paused = false;
        if (Input.GetKeyDown(KeyCode.P))
        {
            paused = !paused; // flip state once
            // if paused was false now its true
            // if paused was true now its false

            // now we can do the appropriate thing
            if (paused)
            {
                CursorController.Instance.UnHideCursor(); // unhides and unlocks cursor
            }
            else
            {
                CursorController.Instance.LockCursor(); // hides and locks the cursor
            }
        }```
one trick i learned that makes it simple is to flip the boolean first (before any checks)
and then check with an `if/else` so it only checks once..
slender nymph
#

but basically it's so that the bullet can return itself to the pool

rocky canyon
#

i believe something like that was mentioned up above as well.. just happened to have my code easily accessible so wanted to show the code.. might give u some insight

tired python
#

at 17:05

#

do i need to know exactly how it is that the bullets are getting added to the spool?

slender nymph
#

something needs to be able to put the bullet back in the pool otherwise it will never end up back in the pool, which of course would mean using a pool is pointless

tired python
#

oh wait, when he _pools.gets(), that's when he creates a copy or smth?

languid pagoda
#

anyone have any idea what this is?

i have only one editor script using assetdatabase loadasync and its in an editor window that isn't even opened. this ones being called once per frame inside of the PlayerUpdate loop

#

its causing lag spikes even in an ampty scene I can watch the frames drop from 500 down to 85 for half a second then jump right back up

stark vessel
#

Anyone have a function to take a collider and get all colliders that overlap with the one put in?

slender nymph
#

what kind of collider

stark vessel
#

any Collider type

#

Im using a MeshCollider if it needs to be one type

#

but a general method for any Collider would work

slender nymph
#

ah, that's the one that you can't do this for. any other shape would work because of the OverlapXXX methods on the physics class (you don't pass in a collider but it's the same concept)

stark vessel
#

? Is there no method for seeing if a Collider overlaps another Collider? If so, you could loop through all colliders

slender nymph
#

that's what the physics methods are for

stark vessel
#

I wanted Collider not Physics
My object doesnt use physics Im moving is manually

slender nymph
#

by "physics methods" i mean the methods on the Physics class, the ones that query the state of the physics scene to detect colliders in specified areas

stark vessel
#

Is there no method on it that works to let me see if two colliders are touching??

languid pagoda
#

not for mesh colliders

slender nymph
#

are you trying to find out if a collider touches something or are you trying to find out what is overlapped by a collider because those are different things altogether

#

but yes, there is no method for mesh collider shaped physics queries

stark vessel
#

I want to know either could work, If I know how to check if two are touching then I can make it check for all touching but I'd rather all touching if possible

#

what is the point of a meshcollider if it cant detect collision also

slender nymph
#

how about this, explain what the actual purpose here is so the real solution can be suggested

stark vessel
#

I want to detect all objects touching my bullet object to damage them

languid pagoda
#

use a raycast

slender nymph
#

that's not even necessary. just use an OnCollisionEnter or OnTriggerEnter

astral cedar
#

why if i add a tag to an object it wont collide with raycasts?

languid pagoda
slender nymph
#

why not

languid pagoda
#

They move to fast and they can cross the collider in between physics step

slender nymph
#

then congrats, you get to use the physics queries previously mentioned

stark vessel
#

my bullet is just a prjectile it can move slow (like it dodes right now)

languid pagoda
#

Its pretty frowned upon to use colliders and rigidbodies for bullets

stark vessel
#

im not using a rigidbody

astral cedar
stark vessel
astral cedar
#

i did this in another game engine and worked beautifully but i had to optimize like hell

languid pagoda
#

so your options are raycast

astral cedar
#

you could use a spherecast to """"simulate"""" a hitbox

stark vessel
languid pagoda
stark vessel
#

also when did rigidbodies come up im talking about colliders

languid pagoda
slender nymph
#

at this point you've already received your answer, physics queries will do what you are trying to do

stark vessel
#

why is it so hard to detect if two things are colliding

languid pagoda
#

Its not

slender nymph
#

i didn't say anything at all about a rigidbody, did i

stark vessel
#

I thought yall said both needed to be rigidbodies for that to work

slender nymph
#

that was russell who said that about OnCollision/TriggerEnter.
neither of which is a physics query

languid pagoda
#

In order to call oncollisionenter the physics system has to be moving the bullet. So that means either use a raycast like I suggested or use a rigidbody(terrible way to do it)

warm ridge
#

hello guys

stark vessel
slender nymph
#

how is that relevant

stark vessel
# slender nymph

So i use a physicsquery to detect all collision objects inside of my Collision object

stark vessel
languid pagoda
#

it doesn't make a difference

#

everything I said was true

stark vessel
#

ok

slender nymph
#

oh no, someone called your projectile by the name of a different projectile. that means the suggestion won't work

stark vessel
#

i never said that

languid pagoda
#

like bro atp go back to tutorials

#

read the docs

#

idk

#

use a raycast and call it a day

warm ridge
#

im just starting to learn Unity do you have any resource recommendations?

slender nymph
#

or preferably the cast that is the closest shape to the actual projectile

slender nymph
radiant voidBOT
polar acorn
slender nymph
#

or none at all and only using physics queries

polar acorn
slender nymph
#

but yeah, primitive would be much better than a mesh collider in this case, especially considering when you move a collider without using a rigidbody it recreates that collider every physics update

languid pagoda
#

if its moving fast it can move past the collider between physics steps youll have inconsistent hit detection if you use colliders for this at all

polar acorn
languid pagoda
#

does continous totally remove this issue or just make it less noticable?

tired python
#

so...i tried implementing pooling and i am pretty sure that i am very close to it, thing is, i can't get the ducks to destroy

#
using Unity.Mathematics;
using UnityEditor.ShaderGraph.Internal;
using UnityEditorInternal.VersionControl;
using UnityEngine;
using UnityEngine.Splines;
using UnityEngine.Pool;

public class enemyAni : MonoBehaviour
{
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    [SerializeField] private SplineAnimate aniSpline;
    [SerializeField] private Animator animator;
    private SplineContainer containsSpline;
    private ObjectPool<GameObject> _pool;
    void Start()
    {
        aniSpline.Completed += onComplete;
        containsSpline = gameObject.GetComponent<SplineContainer>();
    }

    // Update is called once per frame
    void Update()
    {
        if (CalculateTangent() < 0.0f)
        {
            animator.SetBool("isGoingLeft", true);
        }
        else
        {
            animator.SetBool("isGoingLeft", false);
        }
    }
    
    void onComplete()
    {
        //Destroy(gameObject);
        _pool.Release(gameObject);
    }

    public float CalculateTangent()
    {
        float tratio = aniSpline.ElapsedTime / aniSpline.Duration;
        float3 tangentVector = containsSpline.EvaluateTangent(aniSpline.Container.Spline, tratio);
        return tangentVector.x;
    }

    public void SetPool(ObjectPool<GameObject> pool)
    {
        _pool = pool;
    }
}
#

the part of the code which previously(before implementing pooling) dealt with destroying the gameObject was //Destroy(gameObject). now, instead of the script doing the destruction, i set the pool to destroy it when the time is right

#

somehow or the other though, it's returning
NullReferenceException: Object reference not set to an instance of an object enemyAni.onComplete () (at Assets/Scripts/enemyAni.cs:37)

#

where line 37 is exactly where the spool decides whether it needs to destroy some objects off or not

#

using .Release(gameObject)

eternal needle
#

either you aren't setting it at all or onComplete is running before SetPool

tired python
eternal needle
eternal needle
tired python
#

the Duck prefab present in heirarchy is the gameobject i am trying to spawn. it has EnemyAni script attached to it. the spawner script isn't attached to this Duck gameobject, instead, it's attached to something else

eternal needle
tired python
#

oh god

eternal needle
#

you aren't getting the EnemyAni script attached to the duck. Look at your CreateDuck() method

timid saddle
#

So I’m trying to figure out how lists work and I can’t figure out how to use them to do what I want. Can anyone help me?

1 - I want to make a list of all game objects with a certain tag that are close and in view of the camera. I know how to check if an object is close and in view of the camera when I have a set GameObject variable I can check, but I don't know how to add multiple objects to a list based on that.

2 - I also need to find which object in the list has the lowest or highest x or y value on this Vector3 “Vector3 directionOfObject = transform.InverseTransformPoint(theObject.transform.position);” which is based on their position, and be able to set a “GameObject” variable equal to that object.

This script is connected to the camera

viral magnet
#

every time i tryto configure VS code it doesnt work

slender nymph
viral magnet
#

i did that

#

like 3 times

slender nymph
#

i linked to troubleshooting steps for you to take

#

they will work provided you actually followed the steps to configure it

shell sorrel
#

don't you want to link the VS Code ones ?

viral magnet
#

yep

#

i use vscode

shell sorrel
viral magnet
#

tt

slender nymph
#

next time you should actually read the page instead of immediately dismissing the instructions without looking and you could have seen it was wrong yourself 😉

viral magnet
#

still doesnt work.

#

i spent like 5 hours on this yesterday

slender nymph
#

follow the troubleshooting steps

viral magnet
#

in this server

#

ill send u all the screenshots

#

its external

#

i got the thikng

slender nymph
#

have you gone through the troubleshooting steps at the bottom of the page that was linked

viral magnet
viral magnet
tired python
viral magnet
#

C# and C# dev kit are both newest version

#

i have th .NET sdk 9

#

but it does say this every tim

#

ms-dotnettools.csharp: Trying to install .NET 9.0.11~arm64~aspnetcore but it already exists. No downloads or changes were made.
visualstudiotoolsforunity.vstuc: Trying to install .NET 9.0.11~arm64 but it already exists. No downloads or changes were made.

uneven lake
viral magnet
#

because im on m1

tired python
viral magnet
#

i mdzn mw

#

m2

#

i downloaded it from VS studio

uneven lake
viral magnet
#

i cant even code cuz my visual studio aint working

tired python
#

i think the ducks aren't being reactivated and that's the issue

solar hill
#

why even ping an individual

#

also dont crosspost

solar hill
eternal needle
tired python
solar hill
#

its not rude but i am not that invested so i think ill pass unless something comes up i can explicitly help with lol

tired python
eternal needle
#

us staring at a video isn't productive, especially when we can't see the full context like when you press space. (nor does anyone want to really go through that).
You should gather the information you can. The only thing I will note though is it does look like the ducks are set active right after being set inactive

shell sorrel
viral magnet
tired python
viral magnet
#

should i downlkoad any of these

#

so like if I press g

#

it doesnt give me game object or aything like that

#

it just gives me global

tired python
#

ahh shiii, discord doing discord stuff

eternal needle
tired python
#

oh understandable

eternal needle
#

id really just follow the example closer on the object pool docs, assuming your spawner logic looks different. the screenshot you sent doesn't show most of the methods used in the constructor of the ObjectPool

viral magnet
#

can anyone good at VSC help

tired python
naive pawn
#

have you done the instructions i gave

viral magnet
#

i did

#

😭😭😭

#

i told you

#

i did it yesterday too

#

i sent you all the screenshots with al the instructions

#

my C# dev kit doesnt hve any output

tired python
# eternal needle well I do see a log for it. it's slightly hard to read considering collapse is o...

i think i might have an inkling of what the problem is. So basically when an object on a spline reaches the end of the spline, OnComplete() gets called once. but what happenss if the same object were to reach the end of the spline, then because of the pooling, it became deactivated and then reactivated. i am assuming, that since it already passed through the spline once, its spline animate isn't gonna work again because it's not in a loop mode...instead, its just a one time thing...

#

so even though it gets enabled, its spline animate doesn't work because it has already been used once

#

@eternal needle @slender nymph @solar hill thx for helping

viral magnet
#

i follow a video tutorial step by step

#

bro what is this

#

this app sucks

uneven lake
#

Hello,
I am not able to enter the answer to this equation which is a part of my game , Can someone help please

viral magnet
#

what is the problem

#

you cannot type it in?

#

or cannot submit the answer to review

mint flicker
#

Hi I'm wondering if there's a way to make this more optimized as my game is running like a potato I think the main cause is the animated wheat being copy and pasted and maybe a way for the scene loading to be faster

#

Video isn't displaying correctly

viral magnet
#

visual studio code is the worst coding platform ever

thorn ginkgo
#

Good afternoon. I am trying to follow a 2D game tutorial and am having trouble with a tile palette. On the tutorial video, the person added a tile to the palette and it filled the entire grid. However, when I add the image, it only fills up a tiny portion of the grid. Does anyone know how I can get that grid tile filled in? I am on the latest Unity, and the tutorial is from 2022.

#

I can supply the image png if necessary

solar hill
#

would be a lot more helpful if you just linked the tutorial

solar hill
rugged beacon
#

change the sprite unit

mint flicker
#

got it

solar hill
#

the video still isnt playing, at least for me, but what i said earlier still applies...

"you should use the profiler to diagnose any performance issues yourself"

mint flicker
#

oh i will see

solar hill
thorn ginkgo
# solar hill would be a lot more helpful if you just linked the tutorial

Here is the link
https://youtu.be/_24TfxaPWlI
You want 27:43 timestamp or so on the video

An Aussie's full guide to following the "RoguelikeDev Does The Complete Roguelike Tutorial" challenge!

💰🔗 Feel like Supporting Me 🔗💰
ᐅ Github Sponsor
https://github.com/sponsors/Chizaruu
ᐅ Patreon
https://www.patreon.com/thesleepykoala
ᐅ Unity Store Affiliate
https://prf.hn/l/WoLYBoQ

🔗 Relevant Links 🔗
ᐅ Unity Hub Do...

▶ Play video
rugged beacon
#

no, just change the sprite pixel unit

thorn ginkgo
#

Please elaborate

rugged beacon
#

if your sprite 10x10 change the thing to 10

thorn ginkgo
#

It is currently at 100 pixels per unit

#

What would you suggest?

solar hill
rugged beacon
solar hill
thorn ginkgo
#

Thank you. That is one mystery solved. I have not fixed the original issue of the fog-of-war not truly working, but I can remove the fog png as a possible cause

bright wren
#

Hi, working on a retro shooter. The tutorial has everything in 3-D. Though the goal is to have billboard sprites for enemies and projectiles just not sure how to swap out the 3-D model with a billboard sprite?

thorn ginkgo
#

Letting folks know, I resolved the problem. I was using an incorrect range in a for loop (typo while following the tutorial)

solar hill
#

thats about it

spring snow
twin pivot
spring snow
#

i see people making games in like 1 month or sum and it looks good but its prob cuz they use premade assets

#

i use premade assets but its because i cant draw for crap

viral magnet
#

what net and sdk sould u use for rider and unity

fickle plume
radiant voidBOT
rich adder
candid abyss
#

Hi, I'm using this script to play an audio (using On enter function in insepctor) whenever the character enters a trigger area. It plays sound fine, but problem is, it also plays it when I exit it.

Further, if I assign a function on On exit, it doesn't work.

I am following Prototyping tutorial from Unity. They said if you don't know coding yet, you can use these scripts which would work without any changes.

#

Is there something wrong with code? Or maybe I'm doing something wrong.

#

I've IsTrigger checked on for the trigger box:

rich adder
candid abyss
#

Unity tutorial scammed me?

rich adder
candid abyss
#

Then later, it says:

We have also created the following three custom script components, which you can use alongside the character controller to handle different interactions. These will give you some flexibility so you don’t have to choose the exact same interactions that we did.

#

The script I'm using is part of these 3 scripts included in that project. They themselves didn't use it in the project, so maybe not enough users noted the issue.

#

This is a screenshot of that sample project. I can see that issue here. Looks like the person who created this simply forgot to change that particular statement.

candid abyss
#

Yeah. I would have never solved it unless I had started learning basic coding. It confused me for a full day.

#

I'm almost done with Creative Core tutorials. After that I'd learn some basic coding.

#

Prototyping is the last tutorial series in that course.

hot wadi
#

The tutorial does not seem to specify the expected behavior

#

So yeah, take some time to understand how the code should work as u intended

rich adder
#

but yeah that mistake slipped through the cracks, someone rushed it out ? who knows..

charred bear
#

so im just getting started in learning how to code C# in VS 2026 and im following a tutorial from 9 years ago... is there a reason why the references page looks so different? im not sure if he wrote the namespace stuff himself or if it just looks different because of the versions

#

not to mention im missing "assemblies" from the solution explorer

north kiln
#

!cs

radiant voidBOT
charred bear
#

oh im surprised that's a thing

#

thanks

hot wadi
#

U have all sort of things on discord. Just have to do ur research

candid abyss
rough granite
#

Though if your question is a code problem in unity i would recommend just asking here

#

Since unity has many of its own libraries

livid frigate
#

my code looks fine right? there isnt anything out of place ive looked multiple times and im having an issue where the animation gets stuck on the last frame after just 1 click

midnight plover
midnight plover
midnight plover
livid frigate
#

@midnight plover this is what happens

#

it apprently doesnt turn attack 1 to false for some reason

midnight plover
livid frigate
#

yeah ill try that see if that works

chrome apex
#

Let's say I have a complex mesh with a mesh collider and a hole inside.

Can I do a sphere/box cast and create an object with a collider shape of the mesh collider, but only inside those bounds? Or just get the collider somehow without making an object

livid frigate
#

thank you so much dude! i love you lol

trim eagle
#

Used Cinemachine FreeLook for my project and its good but because the player movement script uses Input.GetAxis and transform.Translate to move but the jump code uses Rigidbody.AddForce.
And because of that the player jitters when jumping if the Cinemachine Update method is using Late update. And if i change the update method to fixed update player jitters when moving. I managed to"""fix""" this by setting the Update method to Fixed update instead and putting the movement code (Input.GetAxis and transform.Translate) in to Fixed Update()
I was wondering if its bad putting the movement code (Input.GetAxis and transform.Translate) to Fixed Update()

patent vortex
tender mirage
#

It behaves differently then update in more then 1 way as well, if i recall.

#

you'll have less problems using the correct one for their intended purpose

naive pawn
#

you're using transform.Translate on a rigidbody? that's wrong, you'll be fighting the rigidbody and you'll have desyncs

#

the jitter is probably from that

#

input should be taken on Update
continuous input (ie "is x held down") could be in FixedUpdate
addforce should be in FixedUpdate
instantaneous forces could be in Update

viral magnet
#

hi

#

can anybody help with this error message

#

InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
UnityEngine.Input.GetKeyDown (UnityEngine.KeyCode key) (at /Users/bokken/build/output/unity/unity/Modules/InputLegacy/Input.bindings.cs:418)
Bird.Update () (at Assets/Bird.cs:17)

#

i can provide my script if necessary

#

i think its because im using legacy code

midnight plover
viral magnet
#

yep

#

so whats the new input system

#

can you tell me pls

#

i swtiched to input system package to both

midnight plover
viral magnet
#

i switched to both

midnight plover
radiant voidBOT
# naive pawn !input
How to Set Input

To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling

• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.

desert vault
#

Is my code correct? I just learned it today. Sometimes player can't jump...

radiant voidBOT
naive pawn
#

Move should only be called once per frame.

desert vault
naive pawn
#

!collab

radiant voidBOT
# naive pawn !collab

:loudspeaker: Collaborating and Job Posting

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

late hawk
naive pawn
#

why what, exactly?

late hawk
#

are you developer?

naive pawn
#

no, ive never coded in my life

finite lotus
#

lmao

pearl current
#

Happy thanksgiving everyone! May your bugs cease to exist 🦃

soft stone
#

I have made a small unity project for my college submission, but when my friends try to download the exe from the google drive, It shows an error, UnityPlayer.dll Not found... How do I fix this?

frail hawk
#

is that a coding question?

soft stone
#

Look I didnt find any other channel that specifically targets this error, Would appreciate if someone helps though

frail hawk
hearty girder
#

Hey,

I have downloaded unity like a hour ago and started following a tutorial to get to know the basics and in the tutorial they used addforce to a object to move it left and right but when i press D the force does not get added. has there been a update or something?

astral cedar
#

to make sure it works add a " print(Input.GetKey("d") " above the if statement to check if the input is really the problem

hearty girder
#

ahh i get this error

astral cedar
ivory bobcat
astral cedar
#

you should switch to the new input system instead, but it takes way longer than you think

hearty girder
#

Is there a tutorial about how to use the new input system?

astral cedar
hearty girder
#

Alright

frail hawk
#

whatever tutorial you are follwing there, please stop wasting your time with it

#

they are not even making use of Axis

hearty girder
#

Its a tutorial from 8 years ago 💀

frail hawk
#

yep i can see that

#

i´d highly recommend you learn the new input system instead, along with how to use axis

astral cedar
#

https://www.youtube.com/watch?v=ONlMEZs9Rgw this one explains everything about it, its very useful for me and the guy explains it very well

In previous videos, we've already talked about how we ditched Rewired in favor of Unity's new input system. In today's video, Thomas goes over the basics of the new input system, and how you can get started with it on your own.

Timestamps:
00:00 What's an input system?
00:28 Why not the old?
01:29 Setting up movement
09:47 Setting up actions
1...

▶ Play video
hearty girder
#

I am studying software development and next period i am going to learn game development in unity so i already wanted to take a look at it and learn a bit.

frail hawk
#

sounds cool.

astral cedar
hearty girder
#

is the new movement system default or do i need to install it like the video?

astral cedar
#

you need to install it

hearty girder
#

Alr

crisp quest
#

ping me if someone answer me

frosty hound
crisp quest
#

What is iso view could you pls explain in simple words ?

astral cedar
#

how do i add delay to the code?

frosty hound
#

It's an orthgraphic projection where there is no depth.

#

It's useful, in this case, for aligning things.

astral cedar
frosty hound
#

You either use a coroutine which lets you yield to time, or you track time in your Update function and do something when it surpasses an amount.

astral cedar
#

anyway im gonna check what are those

frosty hound
#

I don't know what time1-time2 means, but if you don't want to use a coroutine, then you need to track the accumulated time manually yes.

astral cedar
frosty hound
#

By the way, if you're using time to buffer something like that, that's going to be bad news in the future.

#

Why do you need to wait 3 seconds to start the game, for example?

astral cedar
astral cedar
#

so i just get used to it

brave robin
#

Another would be to add Time.deltaTime to a float in Update, and check if that exceeds your target duration
Time.deltaTime is the amount of time spent in the last frame

astral cedar
#

that would work too

#

maybe is even less complicated

round coyote
#

Hi, I need help. I’m making a cleaning game, and I’ve projected stains onto the ground using a Decal Projector. However, I don’t know how to clean them realistically, like erasing a drawing inch by inch so it actually feels like cleaning.

I tried using Shader Graph, but I couldn’t figure out the correct way to implement it, and I ended up failing. Can someone please help me understand how to properly create this cleaning mechanic?

Thanks in advance!

eternal needle
flint wind
#

Hello, I’m having an issue with the playable director. I have it set to after one playable director finishes playing, another one plays. But the problem is that for some reason, the wrap mode for one of them keeps setting itself to hold in play mode. even after I set it as none in the editor.

fierce junco
#

hey i am making a multiplayer prop hunt game in vr on unity does anyone have like a tutorial or code or smthin or maybe make a video on how to

astral cedar
fierce junco
#

like of how to set up like a prop hunt gun

astral cedar
charred monolith
astral cedar
#

also just for curiosity, are you willing to make this multiplayer or a sort of simulator?

fierce junco
astral cedar
charred monolith
fierce junco
#

im quite new to unity

astral cedar
fierce junco
#

ive only started recently

astral cedar
#

btw you should create a raycast hit variable, then do an actual raycast and store that in it (by doing Physic.Raycast(position, direction, out variable).

then get the game object and from here get the material/ mesh component

#

if you dont know how to code it then you should look for both raycasts and components tutorials

fierce junco
#

what should i search to find the right tutorial

astral cedar
#

components are a bit generic so any tutorial (even about specific things) should be okay, and for the raycasts just search a raycast hit tutorial

fierce junco
#

when i watched a tutorial it mostly just talks about using it to make wall collision

rich adder
frosty yarrow
hearty girder
#

But thank you

frosty yarrow
# hearty girder Yeah already did that

oh okay great job but fact never give up whatever you stuck with ask me or anyone you know here because unity is not easy + do a tutorial game found in youtube do 2 of them then start with simple games untile you start with you dream game and learn more while you are working

hearty girder
frosty yarrow
hearty girder
#

Maybe layer i wanna try first

obsidian river
#

Who should I contact for help?

slender nymph
#

!ask

radiant voidBOT
# slender nymph !ask

:thinking: Asking Questions

:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.

-# For more posting guidelines, go to #🌱┃start-here

tardy parcel
#
DateTime startTime = DateTime.UtcNow;

TimeSpan diff = DateTime.UtcNow - startTime;

if (diff.TotalSeconds > 3 )
{
   // your magic goes here!
}
waxen adder
#

Been playing with rigidbodies and could use some info on some things.

  1. In real life, static friction needs to be overcome for an object to move. As far as I can tell, with a high mass rigidbody with a super high static friction value, it still moves when pushed by another object, albeit very barely. Maybe that's a code issue on the pushing side of things? Not sure, the static friction values are stupidly high rn.

  2. What goes into creating different speeds of descent from gravity with rigidbodies? I can have two objects with mega different masses and they fall at the same speed.

mystic flume
#

anyone know to get rid black box that deletes letters after i backspace

sour fulcrum
#

insert key toggles that

mystic flume
sharp solar
mystic flume
#

Anyone know what clampmagnitude does because i can not understand it.

rich adder
#

its doing some" heavy lifting" math for you
all in relation to Pythagoras, trig and unit circles

#
Vector2 v = new Vector2(4, 4);
Vector2 r = Vector2.ClampMagnitude(v, 2);
// r ≈ (1.4142, 1.4142)```
so like it normalized then x max
rough granite
# sharp solar Insert key takes another life

My god insert key bullied me for about a year of on and off existence before a friend noticed i had it on and called me insane and i was like idk how to turn it off/on it just happens

spring snow
#

is this a efficient way to learn c#

  1. See something i want to make
  2. use tools like youtube, reddit, chatgpt
    3.remake the system but don't use any tools and go by memory
  3. when i get stuck i focus on learning that specific thing
  4. repeat
rich adder
waxen adder
#

Usually with chatgpt responses, the final script is completely different because of my own programming preferences. Occasionally it spits out something that I like first try

rich adder
# spring snow wdym

youtube is ok if you find right courses.. but mainly you should avoid reddit / gpt (its mostly where it scrapes data anyway)

spring snow
spring snow
rich adder
#

google / research, filter out your results to confirm accuracy

#

don't blindly trust what a chatbot spits out

spring snow
spring snow
#

im just learning how to script enemy ai now so i'm getting into the deep side of c# notlikethis and i want to make sure i learn the right way so i don't need to struggle learning better ways in the future

rich adder
#

what you mention doesn't sound c# specific, there is a distinction between Unitys API and C#

#

C# is the core language, unity just uses it for api to talk to the c++ engine

spring snow
#

ehh makes sense i guess

waxen adder
waxen adder
#

I think there's literally a MoveTowards function for transforms right?

spring snow
#

i'm just doing a binding of issac remake prototype for now

spring snow
waxen adder
#

Since there is some physics to his movement

rich adder
spring snow
spring snow
rich adder
#

there is no "unity c#" only specific concepts of unity like Gameobjects etc. but its still c# classes and all

#

if you want to know c# properly use something like microsoft learn site or others like w3schools. Break down the bigger /specific problems into simpler to solve generalized ones

#

and always check Unity docs for unity specific things

waxen adder
spring snow
waxen adder
#

Oh did you do rigidbody too?

spring snow
#

i'm currently trying to figure out how to change public varibles from a raycasthit2d

spring snow
spring snow
spring snow
rich adder
waxen adder
spring snow
rich adder
#

the raycasthit gives you the collider of object you can search that component on

spring snow
#

i'll come back once i get this working

uneven lake
#

Hello everyone, i was just completed building my unity project but mistaakenly i deleted few files which contained the Materials files which are supposed to give colors to the object, can someone please help fixing it

rich adder
#

dont crosspost

astral cedar
spring snow
# rich adder https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Component.TryGetCo...

got it working thanks

    void Shoot () {        
        Debug.Log("Shooting raycast...");
        RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.up, 1f);

        if (hit){
            Debug.Log("Something was hit");
            Debug.Log(hit.collider.gameObject.name);

            GameObject hitObject = hit.collider.gameObject;
            Enemy enemyScript = hitObject.GetComponent<Enemy>();
            if (enemyScript != null) {
                enemyScript.CurrentHealth -= 1;
                Debug.Log("Enemy health: " + enemyScript.CurrentHealth);
            }
        }
        else {
            Debug.Log("Nothing was hit");
        }
    }
}
#

ill change the music eventually

rich adder
#

sure not a bad start, some of the code is redudant

spring snow
rich adder
#
if (hit) {
    GameObject hitObject = hit.collider.gameObject;
    Debug.Log($"{hitObject.name} was hit");
    if (hitObject.TryGetComponent(out Enemey enemy)) {
        enemey.CurrentHealth -= 1;
        Debug.Log($"Enemy health: {enemy.CurrentHealth}");
    }
}```
spring snow
#

delete it before i read it

rich adder
spring snow
#

it was a joke kinda

#

im trying to figure out how to optimize it myself so im not reliant on other sources of code

rich adder
#

hmm.. as long as you didn't use gpt to write it in the first place

spring snow
#

only a yt tutorial on raycasts and unity docs

#

the links you sent

rich adder
#

just wanted to point why those changes might be better afterwards thats why.. it could be self explanitory but importantly try to avoid for example redudant / writing things twice

spring snow
crisp quest
#

whats the prob?

rich adder
#

also wassup with those very specific decimals 😵‍💫

spring snow
#

also is this good optimization?

    void Shoot () {    
        RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.up, 1f);

        if (hit){
            Debug.Log("Hit:" + hit.collider.gameObject.name);
            Enemy enemyScript = hit.collider.gameObject.GetComponent<Enemy>();
            if (enemyScript != null) {
                enemyScript.CurrentHealth -= 1;
                Debug.Log("Enemy health: " + enemyScript.CurrentHealth);
            }
        }
        else {
            Debug.Log("Nothing was hit");
        }
    }
}
rich adder
#

just study the one I sent and then compare

spring snow
#

ok

rich adder
#

sure you don't need hitObject but the point was not to repeating the thiing twice in both the log and access component

spring snow
#

what does the dollar sign do in Debug.Log($"{hitObject.name} was hit"); and Debug.Log($"Enemy health: {enemy.CurrentHealth}");

rich adder
#

thats important, so when you change one you don't have to remember to change it at every spot, thats why variables exists

rich adder
sour fulcrum
#
Type myInstance = gameObject.GetComponent<MyType>();
if (myInstance != null)
    //Code using myInstance

and

if (gameObject.TryGetComponent(out MyType myInstance)
    //Code using myInstance

do the exact same thing btw, the latter is just a cleaner way of writing it

crisp quest
spring snow
rich adder
#

you are like teleporting a camera each time you press and it pressed done

waxen adder
rich adder
spring snow
rich adder
#

the function TryGetComponent returns a bool, so if it found it puts the component in a variable through the out

spring snow
spring snow
#

thanks guys

#

im gonna figure out how to do enemy movement myself with MoveToward but thank you for helping me understand stuff

rich adder
#

might wanna start look into navmesh 2d by h8man or learn basics of a*
or use A* pathfinding project

#

MoveTowards works for very basic things and usually teleports through solid

#

or gets stuck if you got rigidbody on it

crisp quest
rich adder
#

rotating mainly

crisp quest
# rich adder rotating mainly

ummm i guess you dont get it , i want to make smtg like when i click RMB then camera changes its position on my desired place

#

i guess it is simple explanation

waxen adder
#

Oh is the mouse free during this?

#

Like can it move normally on screen?

crisp quest
rich adder
#

it happens quickly

#

KeyDown happens in 1 frame

#

then runs else right after

crisp quest
crisp quest
rich adder
crisp quest
rich adder
#

thats why it helps to explain it better what you want to do

#

if you want it to stay there then you cannot use that else statement on the next frame

#

but again hard to tell a solution if you don't explain what the mechanic is here , it may even exist a better way than whatever it is you're doing now

crisp quest
hallow sun
#

use GetMouseButton instead of GetMouseButtonDown so that it lasts as long as you hold the button instead of just the first frame

#

if its supposed to be a toggle then use a bool and make GetMouseButtonDown switch its value

crystal heath
#

Is it worth using Cinemachine for a first-person view? I want to smooth the camera, and it seems easier with it.

crystal heath
#

Alright, I give it a try 😄

#

only thing scares me is i have to use an empty game object as target

rough granite
midnight plover
crisp quest
midnight plover
#

!learn

radiant voidBOT
crisp quest
midnight plover
crisp quest
#

wait....what.....its whole damn tutorial and im here crying about it and experimenting

midnight plover
#

It might be outdated at some points, but should still be valid for most parts

crisp quest
#

hmmm outdate is just the changed its position on UI , lol

hexed terrace
#

there's quite big changes between cinemachine v2 and v3

nimble apex
#

after doing research i found out making my own GUID for asset referencing is still the best solution, because its very stable and compatible, so im heading back to my own custom GUID system again

this is more of an editor UI optimization problem, how can i automatically generates the string (or key of the dictionary) when i try to add element on inspector?

#

because by default it wont generate itself right?

nimble apex
#

thank you

#

👍

undone wave
#

just to be sure, this "new List<>()" doesn't cause any data leaks, right?

#

collider2d.Overlap(new List<Collider2D>()) > 0

naive pawn
#

managed objects usually won't, sure

#

i don't see the point of it though

undone wave
#

apparently the Overlap function doesn't work unless I add that

naive pawn
#

yeah, but why not have it as a member so you don't have to construct a new one every time

undone wave
#

I just didn't have any use for the results so I added that as a temporary workaround

naive pawn
#

fair enough, i guess

undone wave
#

Is it "better" to just have it as a member?

lyric rapids
#

Hi I have small problem understanding unity, we got an app made in unity from different comapny. I have an template of a dropdown list, I see it's posisitoned around center of the screen and it has anchor to top center of it, but dropdown renders in the top of the screen not the template. Doesnt matter how I change the anchor, dropdown always renders in the same position

#

I can see that instead of top being 1450 its bottom 1450

gloomy heart
lyric rapids
#

Anchored position is 751 right?

gloomy heart
lyric rapids
#

Dropdown is deleted from the scene the second I click outside of it

#

And is created when I click Input 4

#

I guess pressing on Dropdown visible under Input 4 creates new template

#

GameObject* based on the template

#

Okay, I had to put template under this Dropdown and play with Y and Pivot, thanks a lot

#

But now I have different issue, every now and then Unity shows loading bar, after it it shows pop ups like if it just opened (MCP server and some package info) and it crashes my app with these logs

thorn yacht
#

@sour fulcrum Enemy enemy = Instantiate(creeperPrefab, creeperSpawn.position, creeperSpawn.rotation, transform); activeEnemies.Add(enemy); enemy.BeginCreeping();

#

the creeperPrefab is assigned via inspector

sour fulcrum
#

this is how you post c# snips on discord btw

thorn yacht
#

I double click on the prefab that's in that field, and its walkSpeed is 0.6f

sour fulcrum
#

debug log creeperPrefab's walkSpeed before the instansiate line

#

and debug log enemy's walkSpeed after the instansiate line

thorn yacht
#

Good idea

#

Both values say 1.2f

sour fulcrum
#

gives prefab override energy related stuff but you'd have to provide more screenshots etc. if you need help narrowing it down

thorn yacht
#

I changed absolutely nothing other than removing the prefab from the inspector, and re-adding the same prefab from the project window to it

#

And now it has the correct value of 0.6f

#

Do changes made to prefabs not take effect unless you remove and re-add the reference? I thought the whole point of prefabs was to not have to do that

earnest ibex
#

where can i ask for help?

sour fulcrum
thorn yacht
#

That's why I was confused haha

sour fulcrum
#

(as in something you've done has caused this accidently, not that its a unity fault)

#

can't say forsure what happened

sour fulcrum
earnest ibex
thorn yacht
frosty hound
earnest ibex
#

sorry

#

im like really new and need some help, my 2d player keeps spinning when it goes into walls

#

how do i like stop that

gloomy heart
stray knoll
#

Hi

#

"Hi there! If you’re looking to update a Gorilla Tag custom map, I can definitely help point you in the right direction. Adjusting textures and repositioning or removing scene objects is a normal part of polishing a level, and it’s great that you’re focusing on the visual and structural details.

Before you get started, make sure any work you do is within the game’s allowed modding guidelines and only used in approved custom-map environments. If you’d like feedback on your map layout, texture choices, or general workflow, feel free to share what you’re working on. I’m happy to help with guidance and best practices."#💻┃code-beginner message

sour fulcrum
#

is this ai

gloomy heart
crisp quest
#

guys i want to switch my camera in between by pressing a specific button with using cinemachine in my 3rd Person shooter game . how to do it?

#

help please

gloomy heart
crisp quest
limpid thistle
#

Why cant i move this file?

gloomy heart
#

it might be locked by another process

crisp quest
hexed terrace
#

that is in Unity, not windows explorer

earnest ibex
#

my move tool has theese arrows, how do i make it move freely again?

#

like the X and Y arrows (im working in 2D)

gloomy heart
#

what?

earnest ibex
#

like its

#

idk i pressed something now it uses those arrows where i have to go updown then left right instead of moving the sprite freely anywhere with my mouse

gloomy heart
#

look for toolmode toggle or check gizmo

earnest ibex
#

thanks

tame juniper
#

Hello, im making some UI for my game, and am trying to put a shadow image beneath the ui button, but also be a child of the object, how can i do this?

tame juniper
#

oh, didnt know that existed, thanks!

#

it works

gloomy heart
tame juniper
#

this is unrelated, but while coding in unity, i randomly get this thing where when selecting, it replaces the current character ive selected, instead of your normal add a letter next to it, anyone know what im tlaking about?

gloomy heart
#

i don't get it

cosmic dagger
tame juniper
#

where is that 😭

#

sorry im dumb

#

oh wait

#

hang on

cosmic dagger
#

above the arrows on the keyboard . . .

tame juniper
#

omgah thanks

#

is that just a thing in general and not in unity

cosmic dagger
#

yes, it's not unity-specific. just normal . . .

tame juniper
#

lel my bad

#

well thanks though it worked

stark vessel
#

is it normal for rigidbody objects to float above the ground? Because my player is like half a unit above the floor and it really messes up the game because I don't want my player half their height in the air

keen dew
#

Why would it be normal

#

Either your setup or code is wrong

stark vessel
#

only happens if i make my own gravity

#

wait

cosmic dagger
stark vessel
#

I think my raycast was too long

polar acorn
stark vessel
#

my playet thought it was on the floor oops

gloomy heart
stark vessel
#

yes thats what I said

#

now I must figure out the mystery of why in the world my player is bouncing... do the physics modify the force when an object hits a floor or wall?

gloomy heart
#

physics material maybe

stark vessel
#

How do I change that theres nothing mentioning a material on this rigidbody thing

its a separate component aint it

#

no?

frail hawk
#

what are you even asking?

gloomy heart
stark vessel
#

ohhh tehre it issss

sour adder
stark vessel
#

no bounce, and yet my player still boUNCESSS

stark vessel
keen dew
#

If this again happens only with your custom gravity code and not with the default setup then it's again something you've done wrong in the custom code

stark vessel
#

I removed custom gravity and friction altogether im gonna let unity do that

I STILL BOUNCE I SET BOUNCINESS TO ZERO WITH MINIMUM BOUNCE??? WHERE IS THE BOUNCE COMING FROM??

#

also friction is at 99/100 WHY AM I NOT EXPERIENCING FIRCTIONNNNN

#

this isnt scripting

#

gonna go to the physics channel

astral cedar
stark vessel
#

|:

polar acorn
stark vessel
#

gravity

#

rigidbody

polar acorn
#

That doesn't answer the question. By which method are you making the character move

#

Are you setting velocity, using moveposition, or add force?

#

or something different entirely?

stark vessel
#

moveposition

polar acorn
#

So, you're giving it a specific position to move to every frame. Are you factoring in friction into that math?

stark vessel
#

no

polar acorn
#

So that would be why you're not getting friction

stark vessel
#

I use the material's friction

polar acorn
#

If you want realistic physics, you're going to need to use realistic movement, meaning AddForce

stark vessel
#

Oh ok

#

so far my movement doesnt work ): im gonna get that fixed

and then everything ekse

#

its my friction isnt it

frail hawk
#

use a proper physics based movement

stark vessel
#

I am

polar acorn
#

MovePosition exerts forces, but doesn't respond to them. It's so you can have a more specific point-to-point control while still being able to push and collide with things

stark vessel
#

im not using that

#

im using AddForce

polar acorn
#

Yeah, that will let you get some friction from the object that you're colliding with

stark vessel
#

yep 👍 now I need to make my player actually nice to control

#

especially mid air

#

I want the player to have a lot of friction but for friction to almost fully go away when I am trying to move

crisp quest
#

what is wrong with my code ? why it is not working?

frail hawk
#

could you tell us what pdf means

crisp quest
frail hawk
#

and now tell us what is not working.

crisp quest
#

someone help please

frail hawk
#

you need 2 floats where you store your axis value and then add the Mouse X / Y to them

naive pawn
#

!code

radiant voidBOT
crisp quest
crisp quest
frail hawk
#

you override them every frame

naive pawn
crisp quest
#

or wht

naive pawn
#

formatted properly, sure. or, since you're asking about quite a large chunk, see the "large code blocks" section

crisp quest
round citrus
#

so im making this galaga "remake" thing for a school project-like thing. any idea why the projectile prefab only spawns like 1/15 of the time when i press the button to spawn it? (movement.cs is for the player character, being where the projectile spawns at, and bulletmovement.cs is pretty self explanatory

#

ill try to record it in a sec

frail hawk
#

you have the user Input inside FixedUpdate, that should be the reason why your Input is not being detected every frame

round citrus
#

code's probably pretty messy as its basically just a concoction of code from different tutorials but yeahhhhhhhhhhhh

round citrus
frail hawk
#

movement also doesn´t work fine but you just don´t notice it because it is not as frame dependent as the instantiating method. You´d change it to Update() instead

round citrus
#

so changing FixedUpdate to Update, or making a new group or whatever its called?

frail hawk
#

we need to see the whole script as code

#

pasteofcode is cool

stark vessel
#

is there a good way to apply friction on my own? with code? I want to make it so I slow down faster when I stop walking

frail hawk
#

just click on the link slap your code into the empty field select c# and paste, then share the link

crisp quest
#

this is my script

frail hawk
#

yeah kind of but it is confusing that you use 4 floats. you only need Xcursor and Ycursor

Xcursor += MouseX
Ycursor -= MouseY
stark vessel
#

how do I apply friction with code

frail hawk
#

and multiply theem with a sensitivity float of choice

#

with the king float which is in your case 1 and doesn´t make sense but ok

crisp quest
frail hawk
#

yeah declare these 2 floats at class variables as you have yawn and yak

#

you want to keep these values outside of update method

crisp quest
frail hawk
#

for example yes, but i used pseudo code, do it right

crisp quest
crisp quest
frail hawk
#

can you show your current code

crisp quest
#

it is same as before , i didnt change anything cause im understanding by you first

#

still take it (it is same)

frail hawk
#

we also need to clamp the Y axis

stark vessel
#

is there a way to make my horizontal movement be capped

frail hawk
#

what do you mean by capped?

crisp quest
#

reason?

frail hawk
#

so you can store the value and add current value to it

crisp quest
#

ummm i guess i need a tutorial just to undrstand this " += and -+ "things

frail hawk
#

is it working now or not

#

also these are c# basics
myFloat += value is same as myFloat = myFloat + value

crisp quest
frail hawk
#

do you have any errors in your console you are using the old Input class

crisp quest
#

camera is following but not moving as we want

crisp quest
frail hawk
#

yeah but we did not touch any of the moving code , you only wanted the rotation

#

why not use cinemashine actually

crisp quest
frail hawk
#

you said it is rotating so it indicates that it is working

crisp quest
# frail hawk why not use cinemashine actually

i want to use cinemachine but it is too complex for me to understand or you can say that i dont have anyone to teach me or guide me towards it , i tried it before too but i had hard time doing what i want from it so

frail hawk
#

take a look at cinemashine it is really powerfull

crisp quest
round citrus
#

trying to make the movement more accurate to the original

frail hawk
#

!code Elate

radiant voidBOT
round citrus
#

the movement code is attached to the message i replied to

#

oh wait i should probably post the updated version

frail hawk
#

you are using transform.position this is not the right way to move your gameObject, you´d have to use physics based movement instead

round citrus
stark vessel
#

how do I multiply only the x of a vectorrrrr

crisp quest
#

suggest me some guide for the cinemachine

frail hawk
crisp quest
#

it is really hard and complex for me to understand

frail hawk
slender nymph
crisp quest
#

ig taht is how it is done

white matrix
rocky canyon
#

where do you call the Move() function from?

naive pawn
#

!code

radiant voidBOT
rocky canyon
#

btw, thats just (1) piece of the puzzle.. it has the methods you need like the Move() function but it isn't called within that script..

#

looks like Brackey's 2D Character Controller script.. (he creates other scripts in that tutorial)

white matrix
#

im now watching and it worked btw so nvm but thank you

stone whale
#

If I have a scene with objects laid out in front of a perspective camera like this, with their local forward vector pointing about- How can I take that forward vector and convert it to a 2D one from the camera's perspective? So it's described exactly how I see it on the flat screen? Green is up, red is mostly to the right, blue is between them etc etc?

keen dew
candid anvil
#

french ?

plain hound
#

hey yall can someone explain to me

#

is the documentation for Mathf.Repeat wrong?

#

it says "loops value t so it's never larger than length and never smaller than zero"

#

but if you do mathf.repeat (3,3) it returns zero

#

3 is not larger than 3

gloomy heart
#

They won't be publish wrong documentation

rough granite
plain hound
#

yeah but it says never larger

#

not never larger or equal

#

set occurred

rough granite
#

If you read the example they give in the doc they explain if the value is the same as the length it'll be zero

"In the example below, the value of time is restricted between 0.0 and just under 3.0. When the value of time is 3, the x position will go back to 0, and go back to 3 as time increases, in a continuous loop"

#

Example

using UnityEngine;

public class Example : MonoBehaviour
{
    void Update()
    {
        // Set the x position to loop between 0 and 3
        transform.position = new Vector3(Mathf.Repeat(Time.time, 3), transform.position.y, transform.position.z);
    }
}
plain hound
#

you're right

#

it might be that the documentation is correct

#

and it's just the embedded comment on the function is wrong

#

i didnt think of that

#

anyway now i know the behaviour is not as described there, ty

cosmic dagger
# plain hound

What part of that comment (embedded description) is wrong?

rough granite
#

From the looks of the examples it give it looks like all it does is get the remainder of a time and devider no? What is the point of this function if this is the case

plain hound
rough granite
#

Which in code is the same as doing float Remainder = t % length;

plain hound
#

however it actually loops when t is equal to length

#

as well

rough granite
#

This function is just a beautified modulo, why

#

Most useless Mathf function ive seen yet

cosmic dagger
#

☝️ are you saying it doesn't do this?

plain hound
#

im saying that i checked the description of the function to determine what my len value should be

#

and i got it wrong because the behaviour of looping when t is equal to length is not mentioned

#

thats all

#

the comment omits this

#

it says larger

#

instead of "larger or equal"

#

which is different

#

thats all

#

i just came in to check if anyone else has encountered this

cosmic dagger
#

oh, i gotchu. you expected t to remain at the value of length instead of starting back at 0 . . .

plain hound
#

ya

cosmic dagger
# plain hound instead of "larger or equal"

as @rough granite mentioned, it's a modulo operation. when t is equal to length, the remainder is 0, therefore it resets. also, i believe that 0 is inclusive, and the length is exclusive, so it never actually reaches length, but resets when it's close enough . . .

torn wraith
#

I didn’t realize this would be 2inchs (50mm) when i had ordered itsadok

#

It’s roughly 2600pages

wicked cairn
torn wraith
astral void
#

Hey y'all, I'm trying to code in a script where I can put in a bunch of data. The plan is to have one script with access to lists of a large number of things in the game, and then the rest of the game can access it. I use this script to place everything inside of it. here is what I've got:

using System.Collections.Generic;
using UnityEngine;

public class ContentDrawer
{
    //contains all of the games data that isn't part of the core functionality. Here to be added to.
    public static List<StickerData> StickerList;
    public static List<GameObject> CharacterList;
    public static List<StatusData> StatusList;
}

I made this version. Ideally I would use scriptable objects to add new objects in the editor and then drag them in. However, I don't think this implementation does that, as per the Not Letting Me Do That. So how would I do it instead to let me assign things from editor into a script that holds all the data?

I have two other ideas since now I'm thinking this approach might just be... not good. One is to instead to define all of the data within the script instead of in the editor, in code. Issue with that is that there are some things I don't know how to get in the code... Like Images. Each StickerData contains an Image and I don't know how to code that in without "getting" it from a folder, and I don't know how to do that either... it also feels like a fragile system. Plus I don't think I'm high enough level in programming to really do that, since folders are different on different devices and such...
Other idea is similar, ignore this "content drawer" and pull the scriptable objects from the folders themselves, which I also don't know how to do.
Third idea is to make it not static and place the script in the scene but that just feels so messy and like there's better practice.
any advice appreciated :3

wicked cairn
torn wraith
#

I might just be expecting too much of myself as I haven’t had enough experience to be at where I expect to be, if that makes sense

wicked cairn
spiral summit
#

they say i need to destroy and initialize but i don't understand what i need to do

wicked cairn
# spiral summit

The code you highlighted, use CTRl+X to cut it, then you can use CTRL+V to paste it. It needs to be inside of the { } brackets for example

{
Destroy()
}

spiral summit
#

awesome, now i know how to use Ctrl + X to cut

sour fulcrum
# astral void Hey y'all, I'm trying to code in a script where I can put in a bunch of data. Th...

Generally i've used scriptableobjects to hold all of that stuff, then 1 scriptableobject to hold all the holders and a single monobehaviour singleton that contains a reference to that, a rough example being

public class ScriptableManifest<T> : ScriptableObject
{
  [field: SerializeField] public List<T> Content {get; private set; } = new List<T>();
}
public class ScriptableManifestManifest : ScriptableObject
{
  [field: SerializeField] public ScriptableManifest<StickerData> Stickers {get; private set;}
  [field: SerializeField] public ScriptableManifest<StatusData> Statuses {get; private set;}
}
public class GameManager : MonoBehaviour
{
  //Typical singleton stuff you can find online

  [SerializeField] private ScriptableManifestManifest mainManifest;
  public static ScriptableManifestManifest Manifest => Instance.mainManifest;
}
astral void
#

what does public class ScriptableManifest<T> mean? I see <T> but I've never actually understood what it is...

sour fulcrum
#

So you don't have to dive too deep into them to get this going but that syntax (the <letter>) is called a Generic

#

The general idea is you can use generics to construct code where you don't actually have to know and care about the type that code will be referencing

#

almosttt like a kinda placeholder

astral void
#

Idk what generic means 😔

#

but mostly what I'm seeing here is... it's the same as the idea I said I didn't wanna do?

#

My old version had the script as a monobehaviour on an object in scene with all the scriptable objects in lists, ofc with it being a singleton

sour fulcrum
#

The difference between that and this is that while yes the initial reference is tied to the scene (the ScriptableManifestManifest in the gamemanager) the rest of the references are owned by the scriptableobjects outside of the scene

#

in theory you could load that manifestmanifest via resources.load if you really don't want anything in the scene

astral void
#

hmmm ic

#

would it be viable to try to create the lists directly in the script and get images from folders somehow? or is that too complicated? I just feel like surely I can do that

sour fulcrum
#

and if you want that original snippet for convience, you could manually setup up kinda "forwarders" by doing

public static class Content
{
    //contains all of the games data that isn't part of the core functionality. Here to be added to.
    public static List<StickerData> Stickers => GameManager.Manifest.Stickers.Content;
    public static List<GameObject> CharacterList => GameManager.Manifest.Characters.Content;
    public static List<StatusData> StatusList => GameManager.Manifest.Statuses.Content;
}
sour fulcrum
polar dust
#

You know how youd write List<float>();? The type there is generic, it's List<T>();

sour fulcrum
#

i don't know if this visualization helps understand generics much but for example here the T is kinda placeholder value for whatever you actually use when referencing and/or defining the ScriptableManifest<> class

astral void
#

so here, defining Stickers in ScriptableManifestManifest is passing in StickerData to ScriptableManifest?

#

the most confusing part to me is why we're using ScriptableManifest at all

#

I thought surely we could just do List<StickerData> and List<StatusData> directly because it seems the same to me?

astral void
sour fulcrum
# astral void so here, defining Stickers in ScriptableManifestManifest is passing in StickerDa...
  1. The Type yes.

  2. You could absolutely do direct lists in the ManifestManifest and functionally in this context it would be the same result, yes.

The reason I do it and the reason I recommend to do it is to further separate each type of "Content" into it's own thing with it's own responsibility.

eg. should this one big scriptableobject be in charge of the list of every type of content? or should each type of content have it's own kinda "leader" which talks to the big scriptableobject

astral void
#

oh wait I think I know what you mean?

#

I would create a scriptable object for each list

#

and populate those lists

#

and then the manifestmanifest has each of those lists separately

#

okok got it

#

I think this should work!

#

thanks a lot!

sour fulcrum
#

No worries, let me know if you have any questions 😄

astral void
#

ofc :3

#

oh I do have a question

#

what is a manifest? I seem to be poor at googling ._.

torn wraith
sour fulcrum
#

it's not a c#/unity specific term or anything

astral void
#

ohhhhhh ic

#

I thought it was I was so confused

#

ManifestManifest 😭

sour fulcrum
#

Very fair

sour fulcrum
astral void
#

keep getting this error when trying to create a ContentDrawer scriptable object. Here's my code:

using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "DataDrawer", menuName = "ScriptableObjects/DataDrawer")]
public class DataDrawer<T> : ScriptableObject
{
    [field: SerializeField] public List<T> Content {get; private set; } = new List<T>();
}

this just doesn't work. In comparison, this does:

using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "DataDrawerDrawer", menuName = "ScriptableObjects/DataDrawerDrawer")]
public class DataDrawerDrawer : ScriptableObject
{
    //contains all of the games data that isn't part of the core functionality. Here to be added to.
    [field: SerializeField] public DataDrawer<StickerData> Stickers {get; private set;}
    [field: SerializeField] public DataDrawer<StickerData> Characters {get; private set;}
    [field: SerializeField] public DataDrawer<StickerData> Statuses {get; private set;}
}

no issue here. not sure why. Not sure what's different... I might be misunderstanding the purpose of this SO. but now I'm confused how I'm supposed to populate the list otherwise...

sour fulcrum
#

I'm sorry I forgot one small thing with this that you only have to do because Unity is silly

#

so c# wise this is all good but on unity's end for the data drawers you need to make a script per type of drawer you want to use to "define" the generic that's going to be used, eg.

StickerDrawer.cs

[CreateAssetMenu(fileName = "StickerDrawer", menuName = "ScriptableObjects/StickerDrawer")]
public class StickerDrawer : DataDrawer<StickerData> {}

CharacterDrawer.cs

[CreateAssetMenu(fileName = "CharacterDrawer", menuName = "ScriptableObjects/CharacterDrawer")]
public class CharacterDrawer : DataDrawer<CharacterData> {}
astral void
#

omggg boooo

#

"generic type" (doesn't work)

sour fulcrum
#

its cuz Unity wants a straight and direct answer on what that thing "is"

astral void
#

yeahhhhh
this is just less cool now 😔

#

ty anyway

sour fulcrum
#

its still worth it imo

hard warren
#

anyone know why I can't do

using System.IO;
.
.
.
var dbPath = Path.Combine(Application.persistentDataPath, _saveFileName);

and need to do this instead?

var dbPath = System.IO.Path.Combine(Application.persistentDataPath, _saveFileName);
teal viper
hard warren
hard warren
#

but this is okay

teal viper
#

Do you have a class named Path in your project?

hard warren
#

ah...

#

so that is why

#

ok thx. i understand now

teal viper
#

Yes. Compiler would prioritize types in your namespace/assembly.

hard warren
#

should i add name prefix to my class then?

teal viper
astral void
# sour fulcrum so c# wise this is all good but on unity's end for the data drawers you need to ...

can I put these in the same file? I get this warning "No script asset for CharacterDrawer. Check that the definition is in a file of the same name and that it compiles properly." which I assume is because it's all in the same cs script. I can see why it doesn't like that but it isn't an error and I don't think the script reference matters anyway? alternatively if this is "bad practice" I'll change it to different scripts as well 😔

sour fulcrum
#

one file per

#

its silly

#

it may actually cause problems iirc

astral void
#

😢

astral geyser
astral void
#

dunno what that means

#

so probably not

chrome wadi
#

I'm pretty new to Unity... I gave my player a character controller. I implemented Jump. Now when I start my game, my capsule stays in place with the collider, everything is correct, but the velocity for the ground check just keeps falling. I did everything in the tutorial exactly as mentioned, but I'm just not getting anywhere.

using UnityEngine;

[RequireComponent(typeof(CharacterController))]
public class PlayerMotor : MonoBehaviour
{
    private CharacterController _controller;
    private Vector3 _velocity;

    [Header("Movement Settings")]
    public float walkSpeed = 5f;
    public float sprintSpeed = 8f;
    public float gravity = -9.81f;
    public float jumpHeight = 1.6f;

    [Header("State")]
    public bool isSprinting;

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

    private void Update()
    {
        ApplyGravity();
    }

    public void Move(Vector3 input)
    {
        float speed = isSprinting ? sprintSpeed : walkSpeed;

        Vector3 move =
            transform.right * input.x +
            transform.forward * input.z;

        _controller.Move(move * speed * Time.deltaTime);
    }

    private void ApplyGravity()
    {
        if (_controller.isGrounded && _velocity.y < 0f)
        {
            _velocity.y = -2f;
        }

        _velocity.y += gravity * Time.deltaTime;
        _controller.Move(_velocity * Time.deltaTime);
    }

    public void Jump()
    {
        if (_controller.isGrounded)
        {
            _velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }
    }
}



// from PlayerController.cs

    private void Update()
    {
        HandleMovement();
        HandleJump();
        _motor.ApplyGravity();
    }
frail hawk
#

do you want only gravity when you are grounded?

#

where did you find that code?

#

and you dont need 2 scripts for this.. you could handle all of it in the PlayerController instead of calling methods from another script.

tame juniper
#

hi! im making a upgrade tree ( or trying to ) and wondering how i can make loads of diffrent costs and texts without making tons of scripts, is that possible?

#

i can provide some scripts if need be

#

heres my button cost, thats the one im going to try tackle first as it seems the hardest

astral void
#

Scriptable objects is probably the way to go

#

You can then make a bunch of other objects to be used in the same script and just change the variables for each

frail hawk
frail hawk
#

as Cozies also pointed out

tame juniper
#

thanks 👍

frail hawk
#

one small advice, use TextMeshPro instead Text for crispy looking Text

tame juniper
#

i like the style of it, once everything works im gonna add some pixel filters and such, but thanks for the advice!