#💻┃code-beginner

1 messages · Page 614 of 1

cold mist
#

the bullet is a prefab if that has to do with something

polar acorn
#

Put a log before you invoke the event, and put a log in SetHeadBool. Do both print?

wintry quarry
#

How do you mean? The pool needs to know how to create objects. This function tells it how.

polar acorn
#

So then it's working

#

It's setting that bool to true

cold mist
#

maybe that has to do with my bool location?

cold mist
polar acorn
rocky canyon
#

aaaah, ye the code is messed up and

polar acorn
#

If the log in SetHeadBool is printing, it's setting that bool to true

#

What makes you think it isn't

cold mist
#

won't change in the inspector

#

and if i print the bool value its false

quick pollen
cold mist
#

did i print correctly?

quick pollen
#

it doesn't matter tho, I'll do more research on this later

polar acorn
#

Whichever instance you dragged into here

cold mist
#

how do i change it to true instead of on

polar acorn
#

...?

cold mist
#

im confused

#

im calling the function via the inspector

polar acorn
#

You are changing the bool to true. This is not in question

#

The object you've dragged in to that event is getting its bool set to true

#

Is that the object you're looking at

quick pollen
#
    [Serializable]
    struct Projectiles{
        public Projectile projectile;
        public int minProjectiles;
        public int maxProjectiles; 
    }
    [SerializeField] List<Projectiles> projectileInfos;
    List<ObjectPool<GameObject>> ProjectilePools;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        for(int i = 0; i < projectileInfos.Count; i++){
            int temp = i;
            ProjectilePools[i] = new ObjectPool<GameObject>(
                () => CreateProjectile(temp),
                OnReturnedToPool,
                OnTakeFromPool,
                OnDestroyPoolObject,
                false, projectileInfos[i].minProjectiles,  projectileInfos[i].maxProjectiles
            );
        }
    }```
#

so hopefully this works

#

I just also need to make it so that it pre-generates all the objects beforehand

#

otherwise I get lagspikes when they are first created

#
            GameObject[] premadeObjects = new GameObject[projectileInfos[i].minProjectiles];
            for(int j = 0; j < projectileInfos[i].minProjectiles; j++){
                premadeObjects[j] = ProjectilePools[i].Get();
            }
            for(int j = 0; j < projectileInfos[i].minProjectiles; j++){
                ProjectilePools[i].Release(premadeObjects[j]);
            }```
this is also just such a stupid hack
eternal needle
eternal needle
quick pollen
cold mist
eternal needle
polar acorn
#

If you dragged in a prefab, you're calling that function on the prefab

quick pollen
cold mist
#

whoever gameobjects the script is attached to

quick pollen
#

I don't understand the difference

polar acorn
#

because MonoScript doesn't have any functions. It's a text file

#

You drag in an instance of a script, which is on a GameObject

cold mist
#

im draggin the script that is inside the gameobject

#

to call its function

polar acorn
#

You are telling it to call the function on that Cowboy

cold mist
#

i understand

eternal needle
#

i used it as a guide for my own object pool too

cold mist
#

but why does everything else works besides the boolean

#

i tried to print it in the update function

#

and its never set to true

quick pollen
rocky canyon
#

check ur conditions.. how many conditions have to be true for the bool to be true?

#

debug each one.. figure out which one is not working as desired

quick pollen
#

because I only really saw the objectpool functions that werent netcode related

polar acorn
#
  1. The Boolean is working
  2. If you're calling other functions on this same object, they're being called on that object, not any others
quick pollen
boreal umbra
#

How can i make a ring??

quick pollen
#

I don't know what I should do

#

it doesn't actually create objects

#

no clue why not

polar acorn
quick pollen
#

I create and I release them

eternal needle
rocky canyon
cold mist
polar acorn
#

Whenever the object with this script on it collides with an object tagged "Head", it will call SetHeadBool on the object you dragged in for that event.
Whenever the object with this script on it collides with an object tagged "Torso", it will call TorsoHitFunction on the object you dragged in for that event.

rocky canyon
#

still need more information

quick pollen
rocky canyon
#

u can use probuilder. but blender is my recommended as well

quick pollen
#

or maybe a better way to do it?

cold mist
rocky canyon
#

ring.. 🙂

polar acorn
cold mist
#

i swear im trying to

polar acorn
#

We've established, the boolean is getting set

cold mist
#

the bool is never set to true

polar acorn
#

It's doing exactly what you told it to

#

it's getting set to true on the object you've dragged in

quick pollen
boreal umbra
rocky canyon
#

id probably look for a model on the asset store if u have zero modelling experience @boreal umbra

quick pollen
rocky canyon
#

ohh for 2D u want an image tool.

#

like Gimp

#

or Photopea (online photoshop)

quick pollen
#

mspaint enthusiasts rise up

rocky canyon
#

also Unity Asset Store is CHOCKED full of 2D sprites

#

im sure u can find a ring on there

boreal umbra
#

Thanks bro

grand snow
#

Kenney nl has good stuff

rocky canyon
rocky canyon
cold mist
rocky canyon
#

might look there as well as kenny

polar acorn
verbal dome
polar acorn
#

But it is getting set to true on the instance you dragged in

rocky canyon
#

can he use Context in a debug to find the instance its changing?

polar acorn
rocky canyon
#

ahh okay 👍

polar acorn
#

I'm just trying to explain that the prefab and the object in the scene are not the same Cowboy

rocky canyon
#

ahh! one of those.. roger that 🫡

quick pollen
#

i mean i use win10

rocky canyon
#

its paywalled tho 😦

#

i just thought it was kinda wild.. since mspaint been nothing but vanilla for ages

#

also the dark theme

quick pollen
#

no matter when I release all the projectiles, they just get destroyed

rocky canyon
#

want to make a thread?

quick pollen
#

this is the last thing I need figured out, so idk if itd be worth

#

the rest I can handle myself

#

hopefully

rocky canyon
#

the only suggestion i have w/o digging deep into it would be to debug everything possible.. follow the logs.. until u see something that doesn't seem right

polar acorn
#

I don't know if that's a problem (there's a lot of context) but you're doing array stuff and from what you describe the wrong things are being referenced

quick pollen
#
    GameObject[] premadeObjects;
    void Awake()
    {
        for(int i = 0; i < projectileInfos.Count; i++){
        premadeObjects = new GameObject[projectileInfos[i].minProjectiles];
        for(int j = 0; j < projectileInfos[i].minProjectiles; j++){
              premadeObjects[j] = ProjectilePools[i].Get();
        }
    }
    }
    void Start()
    {
        for(int i = 0; i < projectileInfos.Count; i++){
            for(int j = 0; j < projectileInfos[i].minProjectiles; j++){
                ProjectilePools[i].Release(premadeObjects[j]);
            }
        }
    }```
#

this is what I'm doing rn

quick pollen
#

oh wait

#

I can see the issue

#

fuck

quick pollen
#

its not what I meant to do

#

I don't know how to do it though, I basically need a list of lists

cold mist
#

@polar acorn thank you 😭

faint agate
quick pollen
eternal falconBOT
quick pollen
#

Inline coding

faint agate
#
//               //The MonsterCloseScreenEffect start coming in the closer the monster gets.
        int Minmin = 0;
        int Maxmax = 20;
        int test = (int)Mathf.Lerp(Maxmax, Minmin, dist);

        float lerpedMonsterCloseSE = Mathf.Lerp(MonsterCloseSE_START_AMOUNT, 1.25f, test);

        _materialMonsterCloseSE.SetFloat(_MonsterCLoseSE, lerpedMonsterCloseSE);


Helo, I have some code here that should change material float based on "dist" . dist is an int and its how close the player is from another object simply(x to 0 and 0 being im next to the object). What im trying to achieve is the closer the player gets, the more the material float should smoothly change until I'm next to the game object and the material float hits its target 1.25f. In my code im trying to start tracking the dist at 20 and see if player is getting closer so i can smoothly change the float.

#

I already havve dist working somewhere else fyi

quick pollen
#
    {
        Debug.Log(projectileInfos);
    }

wtf?

#

shouldnt this be at least debugging Null if it didnt exist?

#

I don't get anything logged

wintry quarry
verbal dome
#

Null doesnt print "null", it just prints an empty string

wintry quarry
#
        float t = Mathf.InverseLerp(Minmin, Maxmax, dist);
        float lerpedMonsterCloseSE = Mathf.Lerp(MonsterCloseSE_START_AMOUNT, 1.25f, t);```
@faint agate
quick pollen
#

cuz rn I don't get anything

#

as if my start function was completely ignored

slender nymph
#

then the object is not active in the scene

verbal dome
#

Then this script component does not exist in the scene or is not active

quick pollen
#

Awake does get called though?

#

Awake works, Start doesn't

#

even though the object is active

slender nymph
#

then the component is not active

quick pollen
#

and no errors show up

#

hold up, wtf

#

something is disabling my object

#

nevermind, im stupid

#

ty for the help tho!

#

no wonder it didnt release

#

now for some reason my OnDestroyPoolObject is being called instead of Release....

faint agate
#

i felt close 😭 🫡

rocky canyon
quick pollen
#
ObjectPool<GameObject> objectPool = new(
                () => CreateProjectile(temp),
                OnTakeFromPool,
                OnReturnedToPool,
                OnDestroyPoolObject,
                false, projectileInfos[i].minProjectiles, projectileInfos[i].maxProjectiles
            );```
https://pastebin.com/3dp1V6Nz
#

in this case, minProjectiles is 10 and maxProjectiles is 100

#

first I get 10 returns, then 10 destroys

wintry quarry
#

That sounds like your pool maximun is set to 10

#

Double check your parameters with debug.log

quick pollen
#

i doubt that it should be destroying ALL of them, still

#

ill try that

#

nope, its correct

wintry quarry
#

Destroy should only be happening if you try to return something to the pool and the max number is already in the pool

quick pollen
#

yeah, exactly

#

which is why I'm confused

#
Debug.Log(projectileInfos[i].minProjectiles);
            Debug.Log(projectileInfos[i].maxProjectiles);
            int temp = i;
            ObjectPool<GameObject> objectPool = new(
                () => CreateProjectile(temp),
                OnTakeFromPool,
                OnReturnedToPool,
                OnDestroyPoolObject,
                false, projectileInfos[i].minProjectiles, projectileInfos[i].maxProjectiles
            );```
#

10 and 100 gets printed

#

so I seriously don't understand

#

I can even remove the projectileInfos[i].minProjectiles, projectileInfos[i].maxProjectiles part

#

it doesnt matter

#

still gets destroyed

#

seriously 0 idea what's going on

#

this is all I get

grand snow
#

Have you used a debugger yet?

#

I use object pool often but I usually just define the construction, get and release functions and its fine.

quick pollen
quick pollen
#

thanks for that!

west garnet
#

How could i achieve this: from the main canvas you press enter, you switch to the first level selection ( 2nd canvas ) you scroll down and can go to the 2nd one, and scroll up if you want to go back, and enter to select the level, how would you guys suggest me to do this?
my code ( https://scriptbin.xyz/ocofiwadet.cs ) is still not working so i want to try other ways

Use Scriptbin to share your code with others quickly and easily.

rocky canyon
#

simply use 1 script..
go to this scene when Enter is pressed..

use that script on all ur canvas's
whichever one is enabled has the version of the script that goes to the scene u want it to..

west garnet
fleet venture
#

How do i use JsonUtility.FromJson with a list?

slender nymph
#

the list cannot be the root object, it must be part of some other struct or class

fleet venture
#

i foudn a helper online but that didnt work either

slender nymph
#

the list cannot be the root object

fleet venture
#

why not

#

thats valid json isnt it

slender nymph
#

as in, JsonUtility cannot support that

fleet venture
#

💀

#

thats stupid

#

so what do i do now

slender nymph
#

if you need that then use a different json library like json.net

fleet venture
#

i hate unity sometimes

rocky canyon
#

what im saying is use (1) script

using UnityEngine;
using UnityEngine.SceneManagement;

public class EnterKeySceneLoader : MonoBehaviour
{
    [SerializeField] int sceneIndex;

    private void Update()
    {
        if(Input.GetKeyDown(KeyCode.Return))
        {
            LoadScene();
        }
    }

    private void LoadScene()
    {
        SceneManager.LoadScene(sceneIndex);
    }
}```
fleet venture
rocky canyon
#

u can change the sceneIndex to w/e u want.. each canvas having its own version of the script.. w/ the scene that corresponds assigned

slender nymph
fleet venture
#

it works the same as any other c# project? like just using nuget?

slender nymph
#

it's a package you can install via the package manager

fleet venture
#

oh okay

west garnet
rocky canyon
#

thats another issue all together

#

many ways to do that i guess

west garnet
rocky canyon
#

but say they're big UI Panels..

#

with the art and description or w/e
you could enable it off screen or enable it right when u need it

west garnet
#

then i made that over complicated script which didnt work

west garnet
rocky canyon
#

something like this is what iwas thinking... (the ones off screen technically dont need to be enabled until ur ready to use them)
soo if that were the case.. then just having different version of the script on each Element that u enable/disable would be simple enough

#

or, you'd need a bigger system keeping track of which one is focused/selected

fleet venture
#

it feels like thats not it

rocky canyon
#

and then u'd check using a switch statement.. instead of a big ole nasty if-else chain

rocky canyon
#

oh u are keeping track of what canvas is selected and using a switch statement

#

why the issue w/ loading a scene with that?

west garnet
rocky canyon
#

what about the log?

west garnet
#

the debuging only managed to show that on enable was on

fleet venture
west garnet
#

the rest didnt show

#

and the keys didnt do anything

rocky canyon
#

so no

Debug.Log("EnterPressed is working");
?

west garnet
#

nop

rocky canyon
#

if onenable runs and that doesn't then no input is received

west garnet
rocky canyon
west garnet
#

but idk how can i make it work

rocky canyon
#

unless this is wrong

#

but idk bout the new system

west garnet
rocky canyon
#

or try re-creating ur map and trying again

west garnet
#

im working with a few classmates that use it but they dont know the error too

west garnet
fleet venture
#

How do i install this package? this is super confusing

west garnet
#

i mean

#

not show a error bc it didnt work xd

fleet venture
#

i think i got it finally

rocky canyon
#
private void Update()
{
    if (Input.GetKeyDown(KeyCode.Return))
    {
        Debug.Log("Enter key was pressed!"); //EnterPressed();
    }
}```
queen adder
#

Will Invoke(method, time) sync up with a timer like this:

        if (timeLeft > 0)
        {
            timeLeft -= Time.deltaTime;
        }

Called from different places, unrelated

polar acorn
#

Probably not. Two copies of that same script won't even necessarily sync up

#

Floating point precision being what it is

queen adder
#

Alright then lol

#

I hate working with timers

polar acorn
#

You're never going to be able to make a timer more precise than your framerate

#

So, as long as you can get them to sync up on the same frame, it should be fine

eternal needle
#

if you're doing the same math across different instance, the results should be the same. the results just may not be precise to what the actual answer should be

#

this is what i mean, the results are the same but floating point precision makes the result wrong.
https://dotnetfiddle.net/1h21m1
floating point precision isnt like a randomness that each float gets affected by

polar acorn
#

I was thinking maybe stuff would get rounded differently due to imprecision, but you're right, they'd all get rounded the wrong way. So they'll sync with each other, but might all be a different time than you expect

eternal needle
#

online sources say that different devices might get rounded differently, so it might be an issue in like multiplayer or whatever other use case

#

I always wondered how true that is but I really cant be bothered looking so low level

grand snow
#

well with native code it can differ what instructions are used between compilers but if its still mono id expect this to be consistent

queen adder
#
var rounded = Mathf.Round(value);
cooldownText.text = value.ToString();

How can I get it say "3.4" instead of just "3", but also not "3.4575317", if you get what I mean, im not really sure how to even search this up.
Dont wanna be annoying with these sort of questions so I apologize.

sour fulcrum
sour fulcrum
#

Aside from making my own UpdateManager that handles it, is there a direct way for things to subscribe and unsubscribe from Unity’s runtime update loop?

wintry quarry
queen adder
sour fulcrum
wintry quarry
#

In general for normal game stuff it's overkill yes.

sour fulcrum
#

Heard ty

#

I probably do want to cook up my own updatemanager then 🙂

wintry quarry
#

It's usually more useful when you're doing something special like a custom network framework or custom hardware based input or something along those lines

kindred iron
#

guys why does flashlight camera and character get bugged like they turn insanely speed when i write this code in flashlight

IEnumerator FollowCamera()
{
    transform.rotation = Camera.main.transform.rotation;
    transform.position = Camera.main.transform.position;
    yield return null;
}
slender nymph
#

why is that a coroutine? it runs those two lines of code and then waits to do nothing

polar acorn
slender nymph
#

remember, coroutines do not delay the code they are started from (with the exception of yielding the StartCoroutine call in another coroutine)

kindred iron
slender nymph
#

well right now this coroutine won't delay anything

kindred iron
kindred iron
polar acorn
#

You want it to snap to the camera? It is

kindred iron
#

they turn insanely speed when i write this code in flashlight

#

i meant

polar acorn
kindred iron
#

char turns like everywhere

#

even tho i dont turn

polar acorn
#

If that's, like, 180 degrees, it's gonna flip instantly

slender nymph
kindred iron
#

insanely uqick

polar acorn
#

How do i know when im ready for a game jam?
Yes.

slender nymph
slender nymph
#

finish a thought before sending a message

kindred iron
#

it looks to up down right left

kindred iron
slender nymph
#

it is doing exactly what your camera is doing

kindred iron
kindred iron
crisp moon
polar acorn
#

If this object is doing anything other than snapping to exactly the main camera's rotation, it's not this code doing it

kindred iron
#

the problem goes off

polar acorn
#

Have you considered the possibility that you're snapping between two points every frame and that's causing it?

#

In that case, getting rid of either snap would fix it

#

Maybe you should share !code

eternal falconBOT
kindred iron
#

thats all the code of flashlight

using System.Collections;
using UnityEngine;

public class FlashlightScript : MonoBehaviour
{
    public bool hasFlashlight = false;
    public KeyCode flashKey = KeyCode.F;

    private GameObject character;
    private GameObject Flashlight;
    private Light Light;

    private void Awake()
    {
        character = GameObject.FindGameObjectWithTag("Character");
        Flashlight = character.transform.Find("Flashlight").gameObject;
        Light = Flashlight.GetComponent<Light>();
    }

    void Update()
    {
        if (Input.GetKeyDown(flashKey))
        {
            ToggleFlashlight();
        }

        StartCoroutine(FollowCamera());
    }

    void ToggleFlashlight()
    {
        if (hasFlashlight && Flashlight != null)
        {
            Light.enabled = !Light.enabled;
        }
    }

    IEnumerator FollowCamera()
    {
        transform.rotation = Camera.main.transform.rotation;
        transform.position = Camera.main.transform.position;
        yield return null;
    }
}
polar acorn
#

For one, that coroutine does nothing, you can just put those two lines in update.

#

Take a screenshot of your unity window, with this object selected and visible in the hierarchy and inspector

kindred iron
slender nymph
#

btw just adding a waitforseconds isn't going to give you the behavior you want because after the wait, it will still snap to the exact position and rotation of the camera

broken nest
#

Hey, I want to give an angle to an image in script, do I have to use quaternions for that?

polar acorn
#

And this object's rotation is rotating to meet the camera

#

which means the camera is rotating to maintain its relative offset

slender sundial
#

how would i make it so that an animation plays only when the gameobject hits a certain Z-cord?

kindred iron
kindred iron
polar acorn
#

But that's not the issue

#

Since you don't even have a wait

kindred iron
#

yeah that gives the delay

polar acorn
#

Right now, your issue is that your camera is chasing its own tail

slender nymph
kindred iron
polar acorn
kindred iron
#

and my char tp's so somewhere else when i start the game, when i add this code

kindred iron
polar acorn
kindred iron
#

normally i supposed to be in this hous thing

#

but i tped here

#

im in void

#

when i add rotation code

polar acorn
#

Are you still snapping the object to the position and rotation of one of its children

#

because if so that's gonna cause all sorts of problems

kindred iron
#

wdym

#

the code is same

polar acorn
#

As I said, the object with this script on it is a parent of the camera, and it's snapping that object to the camera's position and rotation

#

child objects maintain their relative position and rotation from their parent as the parent moves

#

So your object is pulling a Lorax and lifting itself up into space

kindred iron
#

as i said

polar acorn
kindred iron
#

no i moved the flashlight

#

mb i didnt say it clear

polar acorn
#

So the script is still on the parent object

kindred iron
#

at the new photo

polar acorn
#

and nothing has changed

kindred iron
#

i wanted to show u

kindred iron
polar acorn
kindred iron
#

of course it did

kindred iron
polar acorn
kindred iron
#

what should i do now

#

i didnt get it

polar acorn
#

Don't make an object snap to the rotation of one of its children

polar acorn
# kindred iron i didnt get it

Okay, let's do a demonstration. Stand up, hold your left arm out to one side.
Now, keeping your arm stiff and straight out, spin your entire body until your are looking in the directon of your arm. Do not twist your hips or move your shoulders, only use your feet to turn

kindred iron
polar acorn
#

The flashlight object has nothing to do with this

#

you're rotating the player object, which is a parent of the camera, to the direction the camera is pointing

kindred iron
#

but i guess i got what u mean

#

hold up

polar acorn
#

You keep your arm straight out

#

Use your feet to rotate your whole body until you're looking in the direction of your arm

#

Do you ever actually reach it

#

or do you just spin there with your arm out forever

kindred iron
#

oh i guess i got it

#

but i dont do it in my script

#

do i?

polar acorn
#

That is literally exactly what you are doing which is why I said so

kindred iron
#

in flashlight script right?

polar acorn
#

Every frame, you snap the player object to the rotation of one of its children

#

Yes, the script we've been talking about the whole time, that one indeed

polar acorn
kindred iron
#

i snap the childrens pos to the player object

#

wait

#

NOOOOOOOOOOOO

#

I GOT IT NOW

#

I TRY TO ROTATE THE PLAYERRRR

#

NOT THE FLASHLIGHTTT

polar acorn
kindred iron
#

now instead of turning player which i made it wrongly normally i wanted to rotate the flashlight, i rotate flashlight

#

yeah

polar acorn
#

I hope you appreciate the red marker I did that freehand with a mouse

kindred iron
#

i do

#

i really appreciate bro

#

tysm for helping me

#

and taking time to help me

#

i have 1 more question

#

Flashlight.transform.rotation = Camera.main.transform.rotation;
this flashlight's transfroms rotation doesnt turn to cameras rotation

slender sundial
#

"The referenced script (Unknown) on this Behaviour is missing!"

what does this message mean?

polar acorn
kindred iron
#

even tho i rotate my camera when i look at the transform, the transfrom rotation position is 0 why?

kindred iron
wintry quarry
slender sundial
#

should i just delete the gameobject reupload it onto the scene and attach all the components again?

polar acorn
kindred iron
#

@polar acorn hold up mb i forgot to turn on the script

#

yes it worked tysm bro

slender sundial
polar acorn
slender sundial
#

ah it fixed

#

but that didnt change the base problem I have

#

I'm trying to make it so that my gameobject only plays its animation when it reaches a certain Z coordinate

#

Y cord i mean

polar acorn
#

if statement

slender sundial
#

yea I put one

#

would you like to see the code?

polar acorn
#

Sure

#

!code

eternal falconBOT
slender sundial
#

public class ShackleUnlock : MonoBehaviour
{

    private Animator animator;

    [SerializeField] private string animationTrigger = "PlayAnimation";

    void Start()
    {
        animator = GetComponent<Animator>();

        if (animator == null)
        {
            Debug.LogError("Animator component not found on this GameObject. Please add one.");
        }
    }

    void Update()
    {
        if (transform.position.y <= 0)
        {
            if (animator != null)
            {
                animator.SetTrigger(PlayAnimation);
            }
            
            this.enabled = false; 
        }
    }
}```
polar acorn
#

Log when you set the trigger, see if it's running

slender sundial
#

which debug code is that?

#

I'm sorry I'm a super beginner

#

Debug.log()

#

Debug.log(nice)?

#

would that work?

polar acorn
#

Debug.Log should literally have been the first line of code you wrote

hardy maple
#

I think
animator.SetTrigger(PlayAnimation);
should be
animator.SetTrigger(animationTrigger);

slender sundial
wintry quarry
#

in your code editor?

slender sundial
wintry quarry
#

If not you need to configure your code editor.

#

!ide

eternal falconBOT
wintry quarry
#

Follow the link for the one you're using^

grand snow
#

there should be a test to prove your ide works to talk in this server 😆

wintry quarry
wintry quarry
#

and the reason you have a compile error is because your code is wrong, and it would be showing the error in the unity console

slender sundial
#

mk

#

Im using BBEdit is that bad?

wintry quarry
#

yes

#

IF you're on mac use Rider

#

or VSCode if you prefer

slender sundial
#

im on mac so aight

slender sundial
wintry quarry
#

you also likely won't get your IDE working properly until after you get that compile error fixed, ironically

#

so you'll need to fix it first

slender sundial
polar acorn
slender sundial
grand snow
slender sundial
wintry quarry
rough lynx
#

How do you mess up that bad lmaoo

slender sundial
#

nvm it just changed places

native widget
#

web builds does not update depending on computer framerate

slender sundial
#

@wintry quarry i got it configured

#

But its not showing any errors I made on my code

wintry quarry
#

show a screenshot of your unity console

#

Like i said earlier you may have to fix all your errors before the configuration gets picked up properly

#

from there on it will highlight errors

slender sundial
#

it should be in the animator

wintry quarry
#

so there's nothing that would show in the IDE

slender sundial
#

yea

#

so what did I screw up?

wintry quarry
#

You mean these?

slender sundial
#

yes

#

a new error popped up

wintry quarry
#

click on one of them to see the full error message

#

it will say where in the code that is

#

actually nvm I know where it is

#

You would have to show your animator window

#

to show what you named your parameters

polar acorn
slender sundial
#

@wintry quarry some thing else came up

wintry quarry
#

yeah yeah we know that part

#

show your animator

#

actually that's looking like now you're trying to use ResetTrigger on a parameter that is not a trigger

#

so again - showing the animator will help

slender sundial
#

i mightve found the problem

#

hold on i could be wrong

wintry quarry
#

click on that

slender sundial
#

btw when I try to add a motion it wont let me add the animation of the lock opening

wintry quarry
#

looks like it's an int parameter

#

or float

slender sundial
#

because its legacy and not generic

slender sundial
wintry quarry
#

it should be a trigger if you want to use REsetTrigger with it

polar acorn
slender sundial
#

i fixed it so its a trigger now

#

its still doing it automatically

#

but the fact that I can't add a motion to the animator state because of rig might be why

polar acorn
#

Does your transition actually check the trigger

slender sundial
polar acorn
rugged beacon
#

whats the approach for pooling different bullets or is it good idea to try to pool different bullets

queen adder
#

hey peeps

perhaps not so much in unity

but in general is CUDA a good skill for an aspiring game dev?

I am a senior web dev trying to change careers

GPU algorithms have me fascinated at the moment but not sure what I could actually do with them

wintry quarry
#

it also gets you thinking in the massively-parallel way

ripe shard
#

most gamedev is not dealing with compute shaders unless you make something thats never been done before on a large scale

queen adder
#

building a standalone raytracer atm

i guess i have a solution looking for a problem kinda situation

i just want to learn compute shaders / massive parallelism

slender sundial
#

i probably know the problem tho

wintry quarry
#

learn compute shaders in unity if you want to use Unity

#

not CUDA directly

slender sundial
#

and I cant put one in because my animation is in legacy not generic

wintry quarry
ripe shard
# queen adder thanks exactly what i meant

a common use case for compute shaders is VFX Graph (particle effects) and GPU based instancing & rendering without CPU involvement (say for grass on terrains), and similar situations. But obviously, both are "solved" problems

slender sundial
#

brb

wintry quarry
#

I used compute shaders and the job system for a Satisfactory-like game to handle t he items on the conveyor belts (of which there could be millions)

timber tide
#

I really think that satisfactory should have cut a lot of the logic on thebelts considering how easy they desync with multiplayer

#

no clue how it's all serialized, but they work for maybe an hour then you need to restart the server

ripe shard
wintry quarry
#

I think it works a lot better now than it did at the early access launch

wintry quarry
#

the simulation is all jobs

timber tide
#

oh yeah totally, that game was very unplayable in the betas for multi

wintry quarry
#

but getting all the positions and rotations right for rendering is a compute shader

ripe shard
ripe shard
timber tide
#

it was their selling point, well, the alpha release video had it in the spotlight

wintry quarry
#

maybe I'll pick it up again later

ripe shard
ripe shard
timber tide
#

factory games are still an enigma to me. Having this huge world where you're constantly calculating some product, but it needs to be stateless because otherwise it wouldnt be playable

ripe shard
#

they arent stateless

wintry quarry
#

definitely not stateless haha

ripe shard
#

you just need a neat way to query the simulation and only display and fully simulate the visible part of it

#

the primary issue they have, performance wise, is that they are graphs, and graphs have issues with data locality

timber tide
#

I was thinking it just calculated everything only when you're in range, which would take in account of the time you previously visited

slender sundial
#

@wintry quarry I changed it to generic and it doesn't play but when it gets to the required y coordinate the animation still doesn't play

ripe shard
queen adder
ripe shard
#

they actually do have locality

#

in satisfactory belts have a limited length, also creating locality

#

then you often have limits on how many edges can be attached to a node, allowing you to use fixed size buffers

slender sundial
#

found the problem

ripe shard
#

but even without locality, absent visuals, you can still heavily parallelize that stuff and run it on background threads, so little impact on FPS just from the sim

queen adder
#

i am tempted to make a city simulation (not really a game) using cuda. see how far i can get before i give up

#

just stuff enums into textures (enums if cuda. my cpp is pretty good)

#

not working on a product just learning

ripe shard
#

great for learning

#

you need to be careful with cpp-thinking, can be helpful in some places and misleading in others, depends a lot on what kind of cpp it is

cold mist
#

@polar acorn hey

wild island
#

I'm trying to port a sort of cities skylines clone of mine from c++/opengl to Unity and I'm mostly a Unity noob

Can someone clear up a few things for me?
-Can't really use most of the editor, since everything is created by the user, there are no 'scenes'
-I can't really use GameObjects + MonoBehaviors because of performance (will likely switch to ECS)
-Can't really use the normal importing pipeline because I want users to mod in custom assets (ideally without needing the UnityEditor)
-Can't use Prefabs since you can't create them at runtime
-Can't use ScriptableObjects since the user can't change them at runtime
Anything I'm missing?

cold mist
#

ive figure it out that i needed a static variable

#

and that it was only affecting the prefab

#

sorry about this morning

wild island
#

I will basically have to find a good importer library, handle meshes/textures myself and instantiate gameobjects/ECS entities myself, right?

#

Currently I'm a bit paralyzed because I was planning to write the classical unity way of doing things first, then profile and slowly port to a ECS implementation which handles assets at runtime, but just trying to automate importing assets using GLTFast seems to require me to switch to the fully custom approach instantly

teal viper
#

Other than that you mostly assume correctly. The only thing that I should note is that you will still need scenes. Or at least one scene. Since your game actually need to run in some space.

#

Honestly, it sounds like maybe a full game engine isn't a great approach for you

#

Might want to look at some engines that only provide rendering capabilities.

wild island
#

Yes, I do find writing simulation heavy code probably benefits more from c++, at least if you can grog the language
The main things I wish to utilize are the rendering backend, and some general quality of life that the engine would ideally still provide

#

Like I implemented PBR and bloom pretty well, but my shadowmapping was bad and I had trouble implementing LOD and culling efficently for huge numbers of instances
Supposedly ECS + UWP has a good implementation for me

wild island
# teal viper Well, you'll find that most existing engines follow the same approach. Importing...

I do understand that ex. decoding pngs at runtime is bad (though many indie games seem to do that actually), for most games it makes sense to do it the unity way
But I still feel like they could allow to include a few common import/exporters in the build as an option, and allow packing runtime-loaded assets into bundles you can save
Im not sure what problems this would cause other than giving you more code to ship and it being a bit slow if you do it on startup

sour fulcrum
#

They do offer runtime loaded assetbundles, just not without editor involvement

#

In theory I suppose it’s possible to create them yourself but i think that’s maybe against some aspect of unity tos?

teal viper
sour fulcrum
wild island
wild island
teal viper
wild island
sour fulcrum
#

Yeah Meshes are the one major thing that come to mind for something like this

#

everything else is pretty manipulatable at runtime

#

(i'm the author of a fairly big custom content api for a popular unity game so i know a handful of things about this kinda jank :P)

wild island
#

May I ask which one?

sour fulcrum
#

LethalLevelLoader for Lethal Company

wild island
#

Oh hey, I've recently got into lethal!
Amazing game and amazing mods, though I haven't tried custom level yet

#

even uploaded a very simple 'more scrap during weather' mod because the two I found were broken myself

sour fulcrum
#

Oh nice 😄

#

But yeah it uses assembly injection and assetbundles to allow authors to make custom levels, interiors, enemies, items etc. without the need for custom code

#

The workflow is pretty rough given that the game wasn't designed for that kind of thing but there's a lot you can do for this kind of thing

native widget
#
        inputActions.Player.Look.performed += ctx => mouseX = ctx.ReadValue<Vector2>().x * rotateSpeed * Time.deltaTime * mouseSensitivity;
``` Do I need deltatime here? This is in the `Awake()`
slender sundial
#

could someone help me with this animation

#

im trying to make it so that it only plays when it reaches a certain y cord

#

but the animation just doesn't play when it reaches it

wild island
native widget
eternal needle
gaunt sandal
#

ah, got it, i'll take it down

slender sundial
#

could someone help me with this animation its supposed to activate when y <= 0 but when it reaches that point it doesnt play the animation

wild island
slender sundial
#

aw man no ones helping me im cooked

eternal needle
slender sundial
#

so im making a lock opening animation and basically you have to click on it and it moves down along the y-axis

#

when y <= 0 its supposed to play an opening animation

eternal needle
slender sundial
#

but when I click enough for that to happen it doesnt play the animation

acoustic belfry
#

what's a way for make "object a" modify a value from "object b" or make it enter into an state?
i mean, i know how to do it "if they are being touched" but not if not

#

like this, but with only happening if this thing gets activated

 {
     if (collision.transform.TryGetComponent(out EnemyBase enemy))
     {
         enemy.TakeDamage(riflebulletdamage);
         Destroy(gameObject);
     }
 }```
acoustic belfry
teal viper
acoustic belfry
teal viper
#

Well, does the player know of the enemy at some point?

acoustic belfry
#

elaborate... i mean, technically only in this part

#
    if (hitEnemy != null)
    {
        if (hitEnemy.TryGetComponent(out EnemyBase enemy))
        {
            enemy.TakeDamage(meleeDamage);
        }
    }
    if (hitProyectile != null)
    {
        if (hitProyectile.TryGetComponent(out MortemRifleProyectile enemy))
        {
            enemy.Parry();
        }
    }
}```
#

its when the overlapbox of the meele touches an enemy

#

causing it to enter into that state

#

and well, the rest is history

teal viper
#

Ok, so it depends on what combat system you have. Some games would lock 2 characters in combat each one would have a field for "current target or something".
Alternatively, if it's something that needs to be done on character death(which is presumably caused by the other character attack), the attacking player reference could be retrieved from the attack data.

acoustic belfry
#

its a plataform run and shot

teal viper
#

You could also cache all the enemies you hit or got hit by in the last few seconds, minutes, and when a character dies, it let's all the people that hit it lately know.

copper matrix
#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class KillCounter : MonoBehaviour
{
int kills;
int scary;
public bool gotkilled;
public bool BuffReceived;
UI_Bars HealthScript;
DealDamage DamageScript;

public TMP_Text ScaredText;
public TMP_Text KilledText;



// Start is called before the first frame update
void Start()
{
    BuffReceived = false;
    HealthScript = GameObject.FindWithTag("Player").GetComponent<UI_Bars>();
    DamageScript = GameObject.FindWithTag("Player").GetComponent<DealDamage>();
    kills = 0;
    scary = 0;
}

// Update is called once per frame
void Update() {

    if (scary >= 5 && !BuffReceived) {
        HealthScript.Buffff();
        BuffReceived = true;
        
    }
    if (kills >= 5 && !BuffReceived) {
        DamageScript.ReceiveBuff();
        BuffReceived = true;
    }

    KilledText.text = kills.ToString();
    ScaredText.text = scary.ToString();
}


public void AddKill() {
    kills++;
    Debug.Log("killed" + kills);
}

public void AddScare() {
    scary++;
    Debug.Log("scawwed" + scary);
}

}

so the Debug.Log works fine ingame in the console but idk why the tmp is like buggy? sometimes it get stuck. not even at the same number.

teal viper
#

You can also subscribe to a events on a character that you hit, so that when it dies, you receive an event.

acoustic belfry
#

that sounds usefull af

teal viper
#

Well, you already have an attack mechanic, so you have the reference at that point. Add it to a list along with a timestamp or something. Then in update, check the timestamp and of it has been too long, remove the reference from a list.

#

Very simple.

teal viper
#

Then the other character can do whatever you want with it.

acoustic belfry
teal viper
#

Struct

#

Or was it with small s?🤔

acoustic belfry
#

wat

teal viper
#

This is C# basics. I suggest you go over the C# basics before continuing.

#

I mean, it could be a class as well. But structs fit better here to avoid needless heap allocations.

copper matrix
#

(same question but its more clean) so the Debug.Log works fine ingame in the console but idk why the tmp is like buggy? sometimes it get stuck. not even at the same number.

eternal falconBOT
teal viper
copper matrix
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class KillCounter : MonoBehaviour
{
    int kills;
    int scary;
    public bool gotkilled;
    public bool BuffReceived;
    UI_Bars HealthScript;
    DealDamage DamageScript;

    public TMP_Text ScaredText;
    public TMP_Text KilledText;



    // Start is called before the first frame update
    void Start()
    {
        BuffReceived = false;
        HealthScript = GameObject.FindWithTag("Player").GetComponent<UI_Bars>();
        DamageScript = GameObject.FindWithTag("Player").GetComponent<DealDamage>();
        kills = 0;
        scary = 0;
    }

    // Update is called once per frame
    void Update() {

        if (scary >= 5 && !BuffReceived) {
            HealthScript.Buffff();
            BuffReceived = true;
            
        }
        if (kills >= 5 && !BuffReceived) {
            DamageScript.ReceiveBuff();
            BuffReceived = true;
        }

        KilledText.text = kills.ToString();
        ScaredText.text = scary.ToString();
    }


    public void AddKill() {
        kills++;
        Debug.Log("killed" + kills);
    }

    public void AddScare() {
        scary++;
        Debug.Log("scawwed" + scary);
    }
}
#

what i mean with buggy is when i kill the enemys the counter works fine (as well as the debug function)
but the Scare Enemys counter stops randomly counting (stuck at 0,3,4) BUT the debug function still counted correctly

teal viper
#

Can you record a video showing the issue with the logs visible?

copper matrix
#

which tool is good for recording?

cosmic dagger
rich adder
copper matrix
#

did the video got compremised?

cosmic dagger
# copper matrix

Well, you are constantly receiving an error in KillCounter . . .

copper matrix
#

thats reffering to line 36

#

and thats reffering here

cosmic dagger
# copper matrix

You're getting a null reference error. You need to make sure the variable is assigned. Yes, you assign it in Start, but it can still be null if nothing is found . . .

copper matrix
#

I dont wanna sound stubborn or sth but i wanna understand „why“ like the debug works and im working with the same int?

#

(Trying the fix the null error rn)

cosmic dagger
teal viper
#

And since the debugs are in different method, they are printed to the console correctly.

#

If something goes wrong, always suspect errors in console first.

#

And fix them before moving on to other solutions

rocky canyon
#

TLDR: never ignore null reference errors..

#

fix them b4 moving forward

cosmic dagger
copper matrix
#

What i did was instead of saying tag i put it in as a public gameObject and it worked

copper matrix
cosmic dagger
crimson ibex
#

Hello. I was experimenting with using UnityEvents instead of writing all listener code myself. I noticed a exceptional high delay in reloadig/re-compiling game ( when i save changes or press play). Is it in my head only, or was it due to unity events ? I have 18 listeners for 18 game obejcts attaching themselves.

rocky canyon
#

i wouldn't know generally.. but you could always use the profiler and see how long the scripts taking

#

vs w/e you had before

slender sundial
#

ok so I have this code that is supposed to play an animation when the gameobject hits a y-cord of at most -1.2f and stays there for 3/4 of a second. The debug code shows that the entire script works, timer and everything, and the animation trigger gets set. But the animation doesn't play. Is there a problem with my animation trigger or something?

wintry quarry
#

Show us...

slender sundial
#

yea i tried but

rocky canyon
slender sundial
#

it exceeds my character limit...

rocky canyon
#

whats all this noise?

slender sundial
#

ill send a ss of the code

rocky canyon
#

its the diff

wintry quarry
eternal falconBOT
wintry quarry
#

Do not send ss

rocky canyon
#

but not sure how/why it got enabled

#

or what its doing..

#

wait... is this hooked up to my repo?

#

soo... these gonna stick around until i commit?

slender sundial
#

idk its still too long

sour fulcrum
#

no

slender sundial
#

maybe i send a link or sum?

sour fulcrum
#

there you go

slender sundial
#

oh

rocky canyon
#

you said the trigger/param gets modified

#

soo does ur Condition of the transition have the same?

slender sundial
#

well can someone help me with this code its supposed to play an animation when it stays at a y coordinate of -1.2f or less for 3/4 of a second. The debug logs say that everythings working, the timer is starting and the animation trigger is being set, but for some reason the animation just doesn't play, is there something wrong with my triggers?
Code for reference: https://scriptbin.xyz/genawenugu.cs

Use Scriptbin to share your code with others quickly and easily.

wintry quarry
slender sundial
wintry quarry
#

It's weird that you're resetting the trigger each frame

rocky canyon
#

ahh ya, that ole classic

#

ya that spams the animation

wintry quarry
#

Anyway once the trigger is set it's up to your animator

rocky canyon
#

if you'll select the gameobject during runtime you'll be able to see where and how the transition/animation is fuggered up, just there in the animator window #💻┃code-beginner message

#

just a tip

queen adder
#

For something like these re-usable timer functions, is an interface a bad choice over something like an override function?

public interface ITimer
{
    public bool BasicTimer(...) {...}
}

(Just in your opinion)

slender sundial
#

alright so I'm trying to figure out how to connect the animation trigger in my scrip tto the animation trigger in my animator so that when the gameobject hits a y coordinate of -1.2f or less, it plays an animation.
Here's the code: https://scriptbin.xyz/genawenugu.cs

Use Scriptbin to share your code with others quickly and easily.

wintry quarry
queen adder
#

Yeah I’ve never really used delegates or C# events or whatever, I guess it’s finally time

queen adder
slender sundial
polar acorn
polar acorn
slender sundial
slender sundial
polar acorn
#

Look at the animator controller while the game is running. It should show you what state you are in

rocky canyon
#

well if the animator works correctly is it the animation clip itself?

slender sundial
#

it starts with entry going to placeholder empty state

#

then when the y-cord is met it does the transition to the play animation state

#

are my arrows messed up maybe?

slender sundial
#

im looking at the preview and the gameobject just isnt moving could that have something to do with it?

polar acorn
slender sundial
polar acorn
#

Does your animation state actually have a clip set

polar acorn
#

If it's entering the state when you want it to, and it's staying there, the code is working, the transition is working, and it's in that state

slender sundial
#

yes

#

its giving the "The referenced script (Unknown) on this Behaviour is missing!" message but that would be a script problem which it isnt

polar acorn
#

Seems like it's all working. My guess is the clip isn't correct. Are you sure this animation clip actually animates anything

slender sundial
#

if you look at it in inspector it plays the animation

#

but the preview in the transition doesnt show any movement on the objec

polar acorn
#

Make that animation state the entry state. Does it do the animation you want on startup

slender sundial
#

so it must not actually animate anything

polar acorn
#

Then the issue is the clip and this has nothing to do with the code

slender sundial
#

yes

#

but i have it set to the same object that is being animated in the motion field of the state

#

do you want an ss of the animation state?

#

@polar acorn Im so fr I can't find anything wrong with the clip

#

The referenced script on this Behaviour (Game Object 'Cylinder.001') is missing!
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

this is the message im getting

#

damn looks like my help vanished

#

RIP

crimson ibex
rocky canyon
real thunder
# native widget web builds does not update depending on computer framerate

🤔 Interesting, I searched about that and seems you are right, deltas are not very accurate at WebGL
I just used them naively in two games and saw no issues whatsoever, quick search only gave me themes where one have weird game timers behavior when game is not focused, and the other had weird physics right after the game is loaded; I seemed to bypass that because I always have tiny extra loading bar and not allowing to play unfocused.

cosmic dagger
#

How do you check if the raycast hits anything?

queen adder
#

the ray works, and the hit does get filled (the selector shit is also correct)

cosmic dagger
#

This returns true if the ray hit a collider. Otherwise, false . . .

#

If false, then set the color to normal . . .

queen adder
#

Oh yeah my bad I forgot to put it outside the raycast itself

#

Sorry havent slept in over 12 hours

#

Thanks

cosmic dagger
queen adder
#

Yeah

rancid tinsel
#

could someone explain this in more detail? ive never heard this mentioned before

rich ice
hot laurel
#

its an object so its preferable to cache it instead creating it every use

teal viper
north kiln
#

Strings that are just specified in code are interned and the same string declared somewhere else in code is shared

#

Only strings that are constructed dynamically will allocate

teal viper
#

Yeah, so there's not much point in this "optimization".

north kiln
#

The optimisation in the code above is bullshit, yes

teal viper
#

Aside from maybe making it easy to access and modify during development.

grand snow
#

well using a const for it is better but there is no perf or build size benefit

north kiln
#

I don't really think a const is any better unless it's used elsewhere

grand snow
#

Reminds me of a purchased package I had to deal with where this person SHARED 1 single int for all for loops

sour fulcrum
#

"better"

looks inside
no benefits

hot laurel
#

or maybe the person who wrote that code has backing in other language where CLR doesnt optimize string allocation

grand snow
#

eh probably not, it takes time to learn properly what things matter and what doesn't

rugged beacon
#

what's the use of Vector2 direction in CircleCast?
is it a capsule then ?

quasi sierra
#

Hey i have a weird problem. I have a character shooting a projectile with a rigidbody and capsulecollider. the projectile is bouncing off an object with a boxcollider but in my OnCollisionEnter, nothing gets triggered, not even the Debug.Log at the beginning.

rich ice
eternal falconBOT
quasi sierra
#

aswell as the colliders

rich ice
#

is the OnCollisionEnter supposed to be on the Crossbow?

#

in most cases, you would put it on the projectile object

quasi sierra
#

i thought because the crossbow generates the projectile`?

rich ice
#

oh, that's the issue then. OnCollisionEnter will only detect collisions for the object it is placed on

quasi sierra
#

so i should add another script for the bolt itself?

rich ice
quasi sierra
#

fair enough.

sour fulcrum
quasi sierra
#

my script crashed on this tho
Rigidbody boltRb = currentBolt.GetComponent<Rigidbody>();

rich ice
#

whats the error?

quasi sierra
#

nullreference

rich ice
#

the bolt either doesn't have a rigidbody on it or currentBolt has not been assigned

quasi sierra
#

the prefab has a rigidbody

#

thats my boltcollision script

sour fulcrum
#

not jordan's response is objectively the answer you are looking for, code can't help change that

#

if that code is throwing an NRE it's either one of those two options

quasi sierra
#

well, how do i assign currentBolt would be my question 😮

rich ice
#

you likely just need to replace currentBolt with gameObject

quasi sierra
#

sometimes i want to give back my degree and start sweeping hallways...

#

of course my bolt knows it is currentbolt 🤦‍♂️

#

thanks! its working now

#

mmh a little addon question. Why does it bounce off rigidbody but sticks in colliders?

#

ok i am in developer hell. i removed the rigidbody off a box standing in the scene and now my bolts dont fly anymore

#

what kind of joke is this

rich ice
quasi sierra
#

mmmh gonna head over there. but the part about not flying at all is really weird

#

the box isn't even linked to the bolt in any way shape or form

rich ice
#

coconut moment

quasi sierra
#

absolutely like this

strong wren
#

||The file exists, but removing it does not affect the game||

grand snow
#

wow who knew removing an asset that is used would cause problems 🤔

#

and its probably not a jpg but vtf

rancid tinsel
hot laurel
quasi sierra
#

I un-coconutted it!

grand snow
rancid tinsel
#

especially if you're using that string in many places

hot laurel
grand snow
#

the point of using a constant is so you change it in 1 place vs many. Its not a "shared variable" when compiled though so talking about optimisation is meaningless

#

so lets stop

novel kraken
#

i was following youtube tutorial for basic 3d fps game, got to a point where to do gravity for the player so that he falls when not grounded, when playtesting, the player starts going in the air, how to fix?

real thunder
#

I want to bring up that using int.ToString() is way worse than creating let's say 1000 strings in memory from 0 to 999 and then doing myStringArray[int]

#

form a garbage generating perspective

slender nymph
wintry quarry
#

in other words - copy the tutorial correctly!

cosmic dagger
novel kraken
cosmic dagger
novel kraken
wintry quarry
#

changing it there won't affect anything now that it's been serialized

novel kraken
#

i only have experienece in css and html, never did game development

novel kraken
wintry quarry
#

it means open your unity editor

#

click on your object with the script on it

#

look at the inspector

#

and change the gravity value there

novel kraken
#

oh this, i already done that, its - in the inspector

wintry quarry
#

you should probably go through !learn to learn the basics

eternal falconBOT
#

:teacher: Unity Learn ↗

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

novel kraken
wintry quarry
#

can you describe the "floating" more?

#

Is it falling upwards? Or something else

novel kraken
cosmic dagger
# novel kraken

Also, for some reason you are assigning gravity to Time.deltaTime, then adding gravity to playerVelocity.y. That cannot be correct . . .

wintry quarry
#

ahh yes

#

that's it

#

you did = instead of *

novel kraken
#

OHH

#

thanks that probably is it

#

yes, that was it

#

thank you very much, does anyone know some good video tutorials for begginners with some explanation as to what does what? the only tutorials ive found are made in a way where guy writes stuff with no explanation and im left to just copy his code

#

-offtopic- if i were to do a just a walking videogame with cool building to explore, should the building be done with all the shapes etc availible or is there some other more proper way?

slender nymph
#

should the building be done with all the shapes etc availible
what does that mean

edgy tangle
#

I think he is asking whether it’s feasible to make his game idea entirely using engine shape primitives

#

To which the answer is: the better you want it to look, the more the answer becomes “no”

novel kraken
#

if i would want to recreate a real life building to be walkable ingame, what would be the best way to do it?

wintry quarry
novel kraken
#

oh alright, ill try in blender then

#

wait, i have the 3d building scan availible

#

it would need some polishing maybe

rancid tinsel
#

in theory, if the random number rolls the same number twice here, what happens? does it make 2 with the same name, and windows then gives it a "(1)" in the name?

wintry quarry
slender nymph
#

what happens depends entirely on what you are doing with that string. i would assume you're just writing to the file so it would overwrite the existing one

wintry quarry
#

you have to show us what you're doing with that

grand snow
# rancid tinsel

No os will do what you suggest 😆
It will probably just override the file or fail as it already exists.

#

Ill be nice. You could do Random.Range(int.MinValue, int.MaxValue) but its better to try to use the time (e.g.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()) combined with some other num to avoid saving duplicates.

rancid tinsel
red igloo
#

So I made it so when your grounded your drag remains the same and when your not grounded your drag decreases so the player can jump. I tried it out and it works but when I jump the player moves incredibly fast how can I fix that?

https://paste.ofcode.org/4PgegV7pNErqbZ7aqbQdZH

https://streamable.com/6jmxks

Watch "PlayerController - SampleScene - Windows, Mac, Linux - Unity 2022.3.26f1_ DX11 2025-02-28 15-30-00" on Streamable.

▶ Play video
rancid tinsel
violet oracle
#
using UnityEngine;

public class MovementScript : MonoBehaviour
{
    public CharacterController controller;

    public float speed = 15f;
    public float gravity = -9.81f;

    Vector3 velocity;
    
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        Vector3 move = transform.right * x + transform.forward * z;
        controller.Move(move * speed * Time.deltaTime);

        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
    }
}
grand snow
#

you can use the time in other ways such as DateTime.Now.ToString("YYYYMMDD_HHmmss")

violet oracle
#

im following the exact tutorial 😭

wintry quarry
violet oracle
slender nymph
grand snow
#

Its certainly not random if we use the current datetime as a number/string but we know its always moving forward and its often better to have in files like this
@rancid tinsel

#

DateTime.Now.ToString("YYYYMMDD_HHmmss") is good as it will sort ascending by time for us 🙂 (format string may be wrong)

rancid tinsel
#

didnt know you can format it like that, thanks!

grand snow
#

Id prefer foobar_20250228_161401.txt instead of foobar_3i20483028472034802.txt

rancid tinsel
#

yeah i agree

rich ice
rancid tinsel
#

so with this i essentially drastically shrink the possibility of duplicates right?

#

its super overkill for what im doing but id like to learn best practice anyway

rancid tinsel
#

1 D too many whoops

polar acorn
#

Do you intend to have multiple of these being made a second?

wintry quarry
#

Guid.NewGuid().ToString()

rancid tinsel
#

like Rob said though, its easier to identify like this

#

I think combining both is sort of "best of both worlds" though

polar acorn
#

Instead of just adding a random number, you could just... check if a file exists before writing and append a (1) to it if it does

wintry quarry
#

that gets dicey because what if the (1) already exists!

polar acorn
#

Like, if you really don't want to use GUIDs and you're creating multiple in a second

polar acorn
wintry quarry
#

either way you need a while loop then

rancid tinsel
#

oh no im not disagreeing with using GUIDs

#

i meant that ill actually use a guid instead of random.range there, and that way i can still see them by the dates

#

like this

#

wait i got rid of the date 😭

#

my brain

#

like this sorry

#

without one of the Ds ofc

grand snow
#

date is not guaranteed to be unique either but how big of an issue depends on if you have seconds or milli seconds in it

#

and ofc a users date can change

#

err you put the guid inside the date time to string()

rancid tinsel
#

thanks for spotting that

red igloo
kindred iron
#

Guys why does waitforseconds work at the beginning of the game and not everytime. It supposed to wait 2.5 secs or?
And when i put waitforseconds line under the rotation code, it doesnt even wait at the beginning of the game, why?
The Code Is:

void Update()
{
    if (Input.GetKeyDown(flashKey))
    {
        ToggleFlashlight();
    }

    StartCoroutine(FollowCamera());
}

IEnumerator FollowCamera()
{
    yield return new WaitForSeconds(2.5f);
    Flashlight.transform.rotation = Camera.main.transform.rotation;
}
polar acorn
kindred iron
#

yeah

#

why does it happen so?

#

can u explain to me pls?

polar acorn
#

Here's what this code is doing:
Every frame, it starts a timer that waits 2.5 seconds.
Once that timer is done, it sets the Flashlight's rotation to whatever the camera's rotation currently is.
Then, next frame, the next timer you set is done, so that one sets the flashlight's rotation to the camera's.
Then, next frame, the next next timer you set is done, so that one sets the flashlight's rotation to the camera's.
Then, next frame, ...

kindred iron
#

oh

polar acorn
#

End result: You've made a system where the first 2.5 seconds of the game have no camera following, then it's as if you put it in update

kindred iron
#

btw why doesnt it wait when i put the waitforseconds line under the rotation code line

polar acorn
#

it sets the rotation, waits 2.5 seconds, does nothing, and ends

kindred iron
#

oh yeah u are right

cosmic dagger
#

You'd be telling it to rotate first, then wait. That's backwards . . .

smoky river
#

do i use this channel for stuff about assets and how to add code to them

smoky river
#

which one is for my topiuc

#

unity-talk?

rich adder
#

try asking question first?

polar acorn
#

I don't know, is your question related to beginner coding concepts in Unity?

smoky river
#

i downloaded this asset pack and i don't know which script is supposed to be for the movement and jump animations and i want to know how to apply it onto the character with my script

polar acorn
#

That seems like something you'll need to check the documentation for that asset to determine

smoky river
#

im guessing this is the code for it right?

rich adder
smoky river
smoky river
eternal needle
eternal falconBOT
rich adder
eternal needle
#

also nobody knows what code you're talking about (nor do i think anyone wants to go through it). if you have problems with an asset, contact the person who made it

eternal needle