#💻┃code-beginner

1 messages · Page 371 of 1

topaz mortar
dawn wharf
#

i am unable to put the vfx in the scriptable object

astral falcon
dawn wharf
#

i think i found the problem's cause

topaz mortar
#

Why is Update not yellow?

night raptor
topaz mortar
#

nah just wondering

night raptor
#

guess its just the way your IDE work

topaz mortar
#

there must be some difference, might be nice to know

night raptor
#

I think its unity messages (Update, Start, OnCollisionEnter etc.) which doesn't get colored in Visual Studio but your own methods do

burnt vapor
#

Also, be careful with async void methods. Not handling async code can lead to unhandled exceptions and undefined behavior in your code.

quick pollen
#

hey! so I have this peculiar problem where I'm using Transform.LookAt to orbit these projectiles around the enemy, but the weird part is that the projectiles are getting more and more distant every second

#

imma send code in a sec

#

I do

            transform.LookAt(_orbitPoint);
            transform.forward = -transform.right;```
hexed terrace
#

It's nothing to do with the lookat

quick pollen
#

to rotate the object around the point

quick pollen
hexed terrace
#

because lookat does roation, not movement

quick pollen
#

the velocity is a constant

hexed terrace
#

you have a rigidbody on the projectiles.. you can see they have velocity in all axis..

quick pollen
#

and I just make the projectile move in the direction its facing

hexed terrace
#

share all your !code

eternal falconBOT
quick pollen
#
    void FixedUpdate()
    {
        time += Time.deltaTime;
        if(time < _orbitAfterSeconds || _orbitAfterSeconds <= -1){
            Vector3 angleVelocity = new(0f, _baseModifier * directionOverTime.Evaluate(time), 0f);
            Quaternion deltaRotation = Quaternion.Euler(angleVelocity * Time.deltaTime);
            rb.MoveRotation(deltaRotation * rb.rotation);
        } else {
            transform.LookAt(_orbitPoint);
            transform.forward = -transform.right;
        }
    }```
#

the upper part is responsible for other stuff

#

basically for the projectiles to go out

#

and for the velocity I do rb.velocity = transform.forward * moveSpeed;

hexed terrace
#

where

quick pollen
#

in a projectile handler script

#

I can send you the whole script but 90% of it is just hit detection

#

and enable/disable events

#

I use an animationcurve to set thespeed, but in this case the velocity is a constant

languid spire
#

I'm confused, if you are setting velocity why are you surprised that the position is changing?

hexed terrace
#

'tis

quick pollen
#

the problem is that its straying further and further away

hexed terrace
#

it still has velocity for it to move farther and farther away

languid spire
#

'but the weird part is that the projectiles are getting more and more distant every second'

#

that is position changing caused by velocity

quick pollen
#

yeah, but they shouldnt be getting more and more distant if they're meant to orbit

languid spire
#

but that is not what you are doing

hexed terrace
#

but they still have velocity in the direction to move them away

quick pollen
#

what's a better way of creating orbiting then?

#

where the projectiles form a circle that doesn't change it's radius?

languid spire
#

you need to set the direction of your velocity along the arc of the orbit

quick pollen
#

and how do I get the arc of the orbit?

languid spire
#

calculate it, it could be as simple as a circle

quick pollen
#

my idea is that I don't change the direction of the velocity, I change the direction of the projectile, if that makes sense

#

I only apply velocity on the Z axis

#

I just change the Z axis

#

I don't apply velocity on the X axis as an example

#

the projectiles always move forward

languid spire
#

unfortunately, this IS rocket science

quick pollen
#

I know

#

but I don't want to calculate some relative gravity stuff

#

also im afraid to see what happens if my enemy moves

languid spire
#

I really dont think that the laws of physics care very much for what you do or do not want

quick pollen
#

yeaah thought so

#

some of them speed up, others slow down

#

how could I calculate the....

#

I actually semi-know how to calculate the circle

#

I just don't know how to implement it

#

I can calculate the distance between the projectile and the orbitPoint to get a radius

#

and technically you can already use that to get the arc of a circle

#

how do other games do it?

#

I know other games where they have projectiles orbiting an enemy

languid spire
#

99% of the time they fudge it, and ignore physics completely

quick pollen
#

tbf I wouldn't mind ignoring physics for this one

#

I really don't want to get into rocket science to keep an orbit

languid spire
#

easy enough, define a fixed path, either circle or elipse and lerp along it

quick pollen
#

I just don't know how to calculate that fixed path

#

the projectiles don't start out in a circle

#

so I can't use that

languid spire
#

you got a radius, that gives you a path

#

if you have 2 radii, that gives you an elipse

quick pollen
#

idk how the formulas work for that

languid spire
#

so research

quick pollen
#

not to mention I probably want to use velocity for it

#

which is uhh

#

idk

languid spire
#

velocity is physics

quick pollen
#

well okay

#

I just want to apply some translation

languid spire
#

you cannot only do half physics, it's all or nothing

quick pollen
#

like theres a function called transform.RotateAround

#

I was hoping thatd help

#

and ngl I'm having issues understanding the documentation

#

actually it cant be it i dont think

languid spire
#

forget Unity for one moment. Go and look at basic geometric methods and then see how they can be impemented using Unity

quick pollen
#

also, if I have a constant velocity going left, and I have the circle constantly looking towards a point, why isn't the orbit perfect?

#

the velocity doesn't change, the arc doesn't change

quick pollen
#

I know I probably need some cosine and sine function to make it go in a circle

quick pollen
#

how would I even go about implementing a gravitational constant

#

I know it's 9.81 but how would that help

#

or mass

languid spire
#

both are done in Unity physics

quick pollen
#

I only need unity physics to make the object move forward

#

I want to change the direction of forward

#

if that makes sense

languid spire
#

and I told you, it's all or nothing, you don't get to chose which bits of physics apply

hexed terrace
#

Easiest way to do this would be to put the projectiles under a parent.
Rotate the parent.
Move the projectiles out to the distance you want, don't move them, the parent rotation will do that for you.

quick pollen
#

thats a smart way too actually

#

tho idk how to even find a parent object

#

as in

#

the projectiles are prefabs

hexed terrace
#

you give them a parent when spawning them

quick pollen
#

how can I find the orbitpoint without using FindObjectOfType

hexed terrace
#

look up the instantiate docs

quick pollen
hexed terrace
#

er.. no

quick pollen
#

and my main problem is still finding the object

#

because i cant serialize it

#

what if I want some projectiles to orbit around X, and others to orbit around Y?

ornate lynx
#

hello, how can i change a tile on a tilemap when i click a button?

quick pollen
hexed terrace
#

how do you know where to spawn them now?

quick pollen
#

I have a script for spawning projectiles and it has a transform parameter

hexed terrace
#

there you go, why would it differ now?

quick pollen
#

well I need to overwrite some things then

hexed terrace
#

there's also no need to spawn each projectile... have 1 prefab, which is the parent with all projectiles below already.
Spawn the parent where it needs to be, have a class on the parent which then deals with rotation and moving the projectiles outwards

quick pollen
#

this is basically what I do

#

idk if it makes sense at first sight

quick pollen
#

shoot i pinged mb

fervent abyss
#

hey is there any way to do a transform.Find but with parent objects? transform.Find("App Window/Layouts/" + currentAppName)

#

or do i just do it reversed

rich egret
#

!codr

#

!code

eternal falconBOT
fervent abyss
#

whut

dusky zenith
#

If you want to specifically find a child by this current object's parent, you can use transform.root.Find()

dusky zenith
dusky zenith
#

I made a mistake, sorry, if you want the parent not root, use transform.parent.Find()

fervent abyss
#

oh okay thanks!!!

rich egret
#

Hi, my plan in the function: MoveChildToParent is to delete the desired item from the string, but for some reason it randomly deletes another item
https://gdl.space/enoyuqojeq.cs

dusky zenith
rich egret
#

The purpose of the script is to take the name of an item and put it in a string

#

There are 3 types of strings as you can see

#

The problem is with the function MoveChildToParent

dusky zenith
rich egret
#

It just deletes another item name for some reason

#

I can show you a video if it's hard for you to understand

dusky zenith
#

Sure

rich egret
#

Sorry, I didn't notice the code was out of date

    {
        Transform parentTransform = parentObject.transform;

        foreach (Transform child in destinationObject.transform)
        {
            if (child != parentTransform)
            {
                child.SetParent(parentTransform);
                Debug.Log("Child " + child.name + " transferred to parent object: " + parentObject.name);
            }
        }

        lastTransferredPlayerChild = "";
        lastTransferredWeaponChild1 = "";
        lastTransferredWeaponChild2 = "";
        PlayerPrefs.DeleteKey("LastTransferredPlayerChild");
        PlayerPrefs.DeleteKey("LastTransferredWeaponChild1");
        PlayerPrefs.DeleteKey("LastTransferredWeaponChild2");
        PlayerPrefs.Save();
    }```
#

I keep trying to make it only delete one item but it doesn't work for me

dusky zenith
# rich egret

So the problem is that all the strings got emptied?

dusky zenith
#

That's what your code does, when you call that function, you have

        lastTransferredPlayerChild = "";
        lastTransferredWeaponChild1 = "";
        lastTransferredWeaponChild2 = "";
        PlayerPrefs.DeleteKey("LastTransferredPlayerChild");
        PlayerPrefs.DeleteKey("LastTransferredWeaponChild1");
        PlayerPrefs.DeleteKey("LastTransferredWeaponChild2");
        PlayerPrefs.Save();```
#

You delete the all the strings at once

rich egret
#

I know, how can you make one specific item be deleted?

dusky zenith
#

You can add an if condition to check if the object's name here is equal to lastTransferredPlayerChild then delete that and then add an elseif doing the same for lastTransferredWeaponChild1 and so on

lime pewter
#

Hey, all! I'm currently working on a tile-based liquid system using cellular automata and am wondering if anyone would have any suggestions as to how I could potentially go about creating a "pooling" system, creating the actual gameobject with all coordinates and total volume of the pool recursively would be quite easy, but I am wondering particularly how I could potentially create a visual representation of that pool, currently each "tile" is a separate gameobject using it's own logic which I could easily again recursively conform into a "pool" when it settles, however creating a custom shape which represents the "pool" seems to be more challenging, if anyone who's smarter than me has any suggestions as to how I could do that, any advice would be amazing! Currently the main concept would be to calculate layer-by-layer and creating a custom mesh based on those coordinates, however that becomes an issue if a single "pool" layer is obstructed by a tile.

lime pewter
# lime pewter

currently my system settles each tile to an average value, however since all tiles are still actively checking it's surroundings (when it doesn't necessarily need to) it is quite laggy. Ideally the pooling system creates a general shape that stores the total maximum volume and it's current volume and would simply lower the mesh as liquid is removed and raise the liquid based on if the pool is added to, if multiple pools connect it would recalculate the entire pool's geometry I assume.

dusky zenith
#

This is an example of what i mean

stuck palm
#

i have this marker, which checks for things in the middle. how can i make it so it checks towards the pointed corner?

Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(_camera, _transform.position);
        PointerEventData eventData = new PointerEventData(EventSystem.current)
        {
            position = screenPoint
        };
        var results = new List<RaycastResult>();
        EventSystem.current.RaycastAll(eventData, results);
        bool foundCharacter = false;
        foreach (RaycastResult result in results)
        {
            if (result.gameObject.CompareTag("CharacterSelect"))
            {
                if (result.gameObject.TryGetComponent(out cb))
                {
                    _playerInputController.selectedCharacter = cb._characterInfo;
                    if (!characterHovered)
                    {
                        source.PlayOneShot(hover);
                        characterHovered = true;
                    }
                    foundCharacter = true;
                    break;
                }
            }
        }
rocky canyon
#

has readme always been here?

languid spire
rocky canyon
#

🤯 im blind lol

#

i thought it had been way up top

rocky canyon
#

anyway, morning kind folks 👋

#

time to get to it

strong wren
#

hey im using the Child_Light GameObject to spawn more enemies

#

is there a way to spawn them in without having them as a gameobject?

#

like prefabs

#

but i need the code to be attached to it but i cant

rocky canyon
#

u need some script to do the spawning..

strong wren
#

just a way to spawn them in without having them in the game scene

rocky canyon
#

how u reckon that would work?

devout bone
#

So im tryign to make a simple pickup system using a tutorial i found online but for some reason the cube objects that i input become invisible to the player when in game mode

strong wren
rocky canyon
#

u would have a reference to the prefab u want to spawn on the script doing the spawning

strong wren
#

ye but the prefabs dont have the code and crap

rocky canyon
#

perhaps a static class of some kind

#

GameObjectSpawner.Spawn(prefabToSpawn, Vector3.zero, Quaternion.identity); mebe

strong wren
#

not what im really looking for

#

the code that ih ave works but is there a way to attach code to prefabs?

rocky canyon
#

yes?

strong wren
#

how doe?

swift crag
#

i don't understand your question

#

or your problem

rocky canyon
#

same boat friend

strong wren
#

see diff beetwen a game object and prefab

#

idk how to edit it

swift crag
#

The second is not a prefab

rocky canyon
#

u double click the prefab and it opens the prefab view

swift crag
#

That's the importer settings for your model asset.

rocky canyon
#

u edit it there

swift crag
#

The importer does produce a prefab asset from the model.

strong wren
#

oh do i just drag the gameobject in the project files?

swift crag
#

But you can't modify it -- it's read-only

rocky canyon
swift crag
#

What you can do is create a prefab variant out of the model prefab.

strong wren
#

yeah well i tried that too

rocky canyon
#

^ prefab variants are nice

strong wren
#

and had an issue with it

swift crag
#

and what was the issue?

strong wren
swift crag
rocky canyon
#

u have to reference the prefab as u instantitate it

swift crag
#

they will never be able to reference scene assets

strong wren
#

this is supposed to have the player thing

swift crag
#

ever

strong wren
swift crag
#

no

rocky canyon
#

and change the parameters via that referenence

swift crag
#

because then they wouldn't be referencing the player in the scene

#

You need to do this.

#

Instantiate the prefab, then tell the new instance about the player.

swift crag
rocky canyon
#
  spawnedObject.target = whatever;```
swift crag
#

you need to pass a rotation as well if you pass a position to Instantiate

rocky canyon
#

oops

rocky canyon
devout bone
#

The cube is supoast to be visible for the player and it is as long as its not on the pickup layer which i need it to be on since i want it to be an interrectible object

rocky canyon
rocky canyon
wintry quarry
devout bone
rocky canyon
#

sounds like a conflict with the layers u have set up

#

why not just use a different layer?

#

theres quite a few of em..

#

Interactable sounds good

devout bone
#

So i just set the camera to the pickup layer?

wintry quarry
#

No you change the culling mask of the camera

devout bone
#

Im confused

wintry quarry
#

To include that layer

devout bone
#

Thx

#

It works

#

Thank you

strong wren
#

im reading the thing from unity how and im not rlly understanding nothing

#

like whats Example? private example i never heard of that and im getting an error every time i use it
whos foo? the player or the thing that follows the player

#

i know that im supposed to read the bottom part

swift crag
#

it's showing you a pattern

rocky canyon
#

they're anything u want them to be

swift crag
#

you're going to need to get used to seeing placeholder names

rocky canyon
#

as long as they're<Type>

undone rampart
#

it shows you the difference between using a gameobject reference and using directly the component reference, Example and Foo are just examples for a component and function, those can be anything

strong wren
swift crag
#

you can do anything

#

[SerializeField] Florp ridiculouslyLongNameThatYouShouldNotUse;

#

they're placeholders

#
[SerializeField] A a;
strong wren
#

but then what is private? like yes if i am saying private GameObject then that game Object is private

swift crag
#

you can do that too

rocky canyon
#

nothingWrongWithASolidLongName;

strong wren
undone rampart
rocky canyon
#

means u can only access that field within the script it was declared/defined

swift crag
strong wren
#

im not asking what Private means im asking whats private in for example Player _player

swift crag
#

but you literally just said you know what it means

rocky canyon
#

it means what we said Applied to Player

#

in that example

strong wren
#

i dont think im explaning it right

swift crag
#

you aren't, no

#
private TypeName fieldName;

This declares a field called fieldName that holds a TypeName.

#

Only code within the same type (so, the same class) can see it

strong wren
#

ok

#

yeah but when i use
[SerializeField] Player PlayerBody; it just gives me a big fat error

swift crag
#

okay, and what is the error?

#

you can't just stop at "it gave me an error"

strong wren
swift crag
#

then there is no such thing as Player

#

you don't have a class named Player

#

If all you need to do is tell the instances where the player is, you can give them a Transform

#

But you probably want to have a "player" component

rocky canyon
#

or use ur actual script name that u have for ur player

strong wren
#

wait in this code im calling on another class?

rocky canyon
#

yes

swift crag
#

read the entire page again

rocky canyon
#

Example.cs

swift crag
#

it cleraly explains exactly what is what

strong wren
#

well that explains alot

cosmic dagger
# strong wren

The type: class, struct, interface, enum, must exist when using it to declare a field (variable) . . .

rocky canyon
#

you've been around a while.. u been coding without knowing this?

swift crag
#

If you don't know how classes work, you probably want to consult !learn ..

eternal falconBOT
#

:teacher: Unity Learn ↗

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

strong wren
swift crag
#

well what would it be talking about..?

#

the only other ways to create new types is declaring structs and enums

rocky canyon
#

yea, thats what we're saying tho.. by looking at the code and using context clues u can figure out whats happening..
if you have the fundamentals.. but i think u may be lacking a bit of information.. so i agree with the !learn content

eternal falconBOT
#

:teacher: Unity Learn ↗

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

swift crag
#

and all component types are classes, because they all derive from the Component class

cosmic dagger
swift crag
#

oh right, interfaces! i forgot interfaces!

rocky canyon
#

oh snap.. i couldn't kill it with codeblock interesting

swift crag
#

!‍learn

#

perfect

rocky canyon
#

😐 ive been bested

worthy merlin
#

https://gdl.space/pewesarida.cpp

I am trying to make a clamped velocity script that will clamp the velocity at a select amount so I am not beaming through my level. I got the forward velocity to work but for some reason my sideways velocity will not go to the correct maximum or minimum. Its always maxing at 1.14?

rocky canyon
cosmic dagger
wintry quarry
rocky canyon
#

ohh 2D oof

#

well theres always a way..

rocky canyon
worthy merlin
#

yeah

#

clamped is being called in my FixedUpdate

#

I can get the full script if you want

rocky canyon
#

can u share a snippet of ur logic?

swift crag
#

btw, you can just use Vector2.Project instead of dotting and multiplying

rocky canyon
swift crag
#

that'll also save you a few lines since you can use ClampMagnitude

rocky canyon
#

whoa, epic clamp function

worthy merlin
#

I hope 😢

wintry quarry
# worthy merlin clamped is being called in my FixedUpdate

One thing is if you're using AddForce that doesn't get applied until the physics simulation and isn't visible to your clamp. It's annoying as hell hence why I made a whole asset (partially) to make this simpler. Ofc it's only for 3D sadly

swift crag
#

additionally, gravity is applied in the physics update

#

so you miss out on that

rocky canyon
#

simulated physics ftw glad i use a CC most days

wraith hornet
#

guys, how to calculate new position from rotation (mathematics.quaternion) , float3 (position ), and speed ?

swift crag
#

you can rotate a float3 with a quaternion

wintry quarry
wraith hornet
swift crag
#

so you can rotate a forward vector with your rotation

worthy merlin
#

Ok I'll see what I can do witht he Vector2.Project and clamp magnitude.

swift crag
#

then multiply that by your speed

wintry quarry
#

If so it's:

Vector3 vel = rotation * Vector3.forward * speed;
Vector3 newPos = Time.deltaTime * vel + oldPos;```
swift crag
#

(or the equivalent mathematics functions here)

#

AAAAAAAAAAAAAAA

#

yeah, one of the overloads is quaternion and float3

worthy merlin
swift crag
#

oh, is there not one?

#

it'll work the same

#

you'll just have to cast back to vector2 (either implicitly or explicitly)

gleaming kraken
#

is vscode deprecated or something? heard it doesn't work anymore

swift crag
#

you use the "Visual Studio Editor" package now

#

hang on i need to take a photo of a cool bug

#

got it

gleaming kraken
swift crag
#

!ide

gleaming kraken
#

okay bet

eternal falconBOT
gleaming kraken
#

thank you

swift crag
#

make sure to uninstall the "Visual Studio Code Editor" package if it's present

gleaming kraken
swift crag
#

Yes. That's the old, deprecated package.

#

Also, you need to be on a least 2021

#

(see the VS Code section of that bot message; it goes through everything)

gleaming kraken
#

alright, thank you.

cosmic dagger
swift crag
#

Newer versions of unity don't install it at all

#

for a while you got both installed, which was annoying

#

VSCode works great now. I used to have a lot of trouble with it

#

the Visual Studio Code Editor package produced project files that required VSCode to...i'm not really sure, use older analysis/.NET? I'm kind of confused about that actually

#

it was slow, though

gleaming kraken
#

i prefer vscode over vs cause of how lightweight it is

swift crag
#

it would take several seconds to do completions

#

You also had to manually install analyzers

#

it was still fiddly, though

#

I still have that analyzer DLL in my project. I should delete that and make sure it wasn't actually being used still...

worthy merlin
fervent abyss
#

hey is there any way to do a transform.Find but with parent objects? transform.Find("App Window/Layouts/" + currentAppName)?

swift crag
#

sure, just go up to a parent

#

transform.parent

swift crag
#

however, comma,

#

maybe there's a better way to do this

#

e.g. having a dictionary to look up app windows with

fervent abyss
#

like transform.parent and path to way up?

wintry quarry
#

So no need for a search

languid spire
fervent abyss
swift crag
#

your problem was more likely that you're digging around in the hierarchy

#

which is very brittle

rocky canyon
#

a generic type function that doesn't care about anyhting but the values u give it and could run it thru that whenever

outer hollow
#

Hey guys, I wanna buy a desktop pc to start programming in Unity. Mostly 2D Games. What specs should I start with? I don't wanna spend a kidney on a PC

outer hollow
#

I have an old laptop, really old one. i5-6300U, 8GB DDR3, no gpu😂

rocky canyon
#

u dont need much.. 4 gig of ram.. i5, windows7 or higher graphics card with dx10 @outer hollow

wraith hornet
#

how about mathematic quaternion to float 3 ? how to do it ?

rocky canyon
#

but thats bare minimum.. i'd get atleast an 16 gig machine

outer hollow
#

I can get like a 4060 Ti or smth but I just dont really think Ill need it

rocky canyon
#

1060 would be good enuff

outer hollow
#

Ik, so what should i get

#

Really?

rocky canyon
#

something with atleast 4gb of vram

outer hollow
#

Wow, unity doesnt need much today

outer hollow
rocky canyon
#

u said u want 32

outer hollow
#

I want but idk if i need it😂

rocky canyon
#

i run 32.. but 4 would be the minimum. 16 is reccomended

outer hollow
zenith cypress
#

Windows will not enjoy 4gb LUL

outer hollow
#

Yh😂

rocky canyon
#

facts.. but its possible

outer hollow
#

Also true

swift crag
#

More memory is useful for running multiple things at once

#

like Blender and Substance Painter

rocky canyon
#

if ur like me and u multitask with 2 monitors

swift crag
#

it also means more files get cached

rocky canyon
#

u want as much ram as possible

#

but atlas i dont have 64 😢

worthy merlin
wraith hornet
#

sometimes i open 3 unity projects at once

worthy merlin
#

Tried clamping magnitude with a positive and negative projection vector3 but clearly wasn't it

rocky canyon
zenith cypress
rocky canyon
#

^ brother from another mother

swift crag
#

ah, if you want separate forward and backward velocities, you need to handle forwards and backwards separately

#

...which actually calls fot a Dot, haha

rocky canyon
swift crag
#
float forwardDot = Vector3.Dot(upwardProjection, transform.up.normalized);

if (forwardDot > 0)
  clamped = Vector3.ClampMagnitude(upwardProjection, maxForwardVelocity);
else
  clamped = Vector3.ClampMagnitude(upwardProjection, maxBackwardVelocity);
#

like so

worthy merlin
#

gotcha lol. Also the 1.14 value on my sidestraifing is still happening both ways. Very unsure how to get it workin

swift crag
#

The magnitude of a vector is always positive

#

so your code around lines 21-36 doesn't work

twilit cliff
#

I'm facing a problem related to the Image that is getting destroyed. When I run the game, on the game scene I have a settings icon Button and when I click on it, it shows the settings screen, within the settings screen, I have "Restart, Resume, and Home" Buttons. When I click on the "Restart Button, it's destroying the Settings Screen Image and the script. Can someone help me fix this issue. I want the Settings Screen Image to remain on scene

Game Manager Script: https://gdl.space/ejumahivat.cs
SettingsImage script: https://gdl.space/eyituvegav.cs

swift crag
#

maybe you're rotated a bit?

#

in that case, you'd see a lower Y component when moving sideways

#

since some of your sideways movement is in the X direction

worthy merlin
#

Even if, when its set to 50 its still doing 1.14 and the z is 0 with y being nearly nothing

rocky canyon
swift crag
#

perhaps something else is interfering

twilit cliff
worthy merlin
#

roger, will check

rocky canyon
#

actually if u load a new scene that settings screen wont exist anymore

#

a different instane of it would..

twilit cliff
rocky canyon
#

didnt u say u didnt want it destroyed?

#

im confused now

worthy merlin
twilit cliff
swift crag
#

whether you're going up or down

rocky canyon
swift crag
#

and where is this settings object located?

rocky canyon
#

hes loading a new scene directly above it ^

swift crag
#

yeah, if it's in the old scene, it's going away

rocky canyon
#

ur gonna have to find a way to tell the new scene what state its in

#

or make ur settings stuff its own scene.. and keep it loaded

#

load ur game scene on top..

#

something like this... where u have a scene loaded at all times w/ ur settings stuff

twilit cliff
# rocky canyon im confused now

@rocky canyon @swift crag Please allow me to explain:

Settings Screen image is initially set to inactive and when I load the game, click on the in-game settings icon, it sets the settings screen image to active within which I have 3 buttons (Restart, Resume, and Home).

When I click on the Restart Button, it's destroying the instance and from the Game Manager script (both settings screen image + settings Image script) due to this reason, if I click again on the in game settings icon, it's not showing the settings screen image

worthy merlin
swift crag
#

you're already doing that for the GameManager

twilit cliff
rocky canyon
#

i think thats ur answer.. unless u wanna rewrite ur settings menu

twilit cliff
rocky canyon
#

its a gameobject innit?

twilit cliff
#

Should I attach a script to Canvas itself that contains DDOL?

rocky canyon
#

DDOL(urobject);

#

coulddo it in the gamemanager

#

since it already has a reference to it

swift crag
#

you're moving the entire object the settings menu lives onto into the DontDestroyOnLoad scene

rocky canyon
swift crag
#

and you don't want to just move the object with the image, yes

twilit cliff
#

It's a canvas Image

swift crag
#

you could put a component on the canvas that moves its object into DontDestroyOnLoad

rocky canyon
#

doesn't matter what it is..

#

its a gameobject thats all tha tmatter

worthy merlin
#

You are right, something funky with my addforce. Its adding a force but keeps clamping at 1.14 instead of going higher

twilit cliff
#

@swift crag @rocky canyon thanks a lot guys ❤️🙏

rich egret
#

Hi

rocky canyon
#

Helwo 👋

rich egret
#
    {
        Transform parentTransform = parentObject.transform;

        foreach (Transform child in destinationObject.transform)
        {
            if (child != this.transform)
            {
                child.SetParent(parentTransform);
                Debug.Log("Child " + child.name + " transferred to parent object: " + parentObject.name);

                if (child.name.Equals(lastTransferredPlayerChild))
                {
                    lastTransferredPlayerChild = "";
                    PlayerPrefs.DeleteKey("LastTransferredPlayerChild");
                }
                else if (child.name.Equals(lastTransferredWeaponChild1))
                {
                    lastTransferredWeaponChild1 = "";
                    PlayerPrefs.DeleteKey("LastTransferredWeaponChild1");
                }
                else if (child.name.Equals(lastTransferredWeaponChild2))
                {
                    lastTransferredWeaponChild2 = "";
                    PlayerPrefs.DeleteKey("LastTransferredWeaponChild2");
                }
            }
        }

        PlayerPrefs.Save();
    }```

Anyone know why it doesn't work?
fossil drum
#

What doesn't work?

rocky canyon
#

explain doesn't work

rich egret
#

!code

eternal falconBOT
rocky canyon
#

jeez

#

bookmarks ppl lol

worthy merlin
#

Its adding forces consistantly. There is no drag or gravity so very weird

zenith cypress
worthy merlin
#

oh its my spacebreak somehow. I forgot to add a xAxis condition to the coupling if statement 🤦‍♂️

warm condor
#

Hi guys, so I have this problem when setting a variable (AccelerationProgress) to zero when the current state is walking or running (meaning right when the player starts walking OR starts running, that variable becomes a zero). The problem is that in my line on code, if the player is walking and then runs, then that variable will not be set to zero. I have no idea what I can do to solve this issue, but I do feel like storing the current state and the previous state and then comparing them might solve this issue. Before doing that tho, I just want to confirm with you guys if that is a good solution or if you have another easier solution.
Here is my line of code:
if (CurrentState != State.Running.ToString() || CurrentState != State.Walking.ToString()) AccelerationProgress = 0;

rich egret
fluid roost
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

fluid roost
#

!docs

eternal falconBOT
amber grove
#

I cannot seem to connect my movement functions to the Events in my Player Input component. They are public and I have no compiler errors at the moment and I believe the correct script is attached (as in it is definitely the correct script unless I am misunderstanding what that slot is meant to take).

(not sure if this is the right channel. Feel free to let me know if this should go somewhere else and I'll delete and repost it over there)

rare basin
#

to match the delegate

languid spire
amber grove
rare basin
#

you need to drag the instance

#

not the script from the assets files

amber grove
vocal sail
#

I have a problem when using event system, I want to broadcast a event on Start().
Putting the subscribe part of other scripts doesn't work, the Start() method from the Manager script might executed before the other subscribers.
Then I moves the subscribe part of subscribers from Start() to Awake().
But it collides with the Awake() function in the Manager script to initialize a instance of itself, the subscribers cannot find the instance of the Manager.
So what is the optimal way of doing this?

polar acorn
# rich egret

If lastTransferredWeaponChild1 is not being set to blank, then child.name is not equal to it

#

So log both of those and see what they are

twilit pilot
# vocal sail I have a problem when using event system, I want to broadcast a event on Start()...

you need to think about the lifetime or your objects and the order that your logic is supposed to run in - generally, Awake is for constructing the script/object itself, and Start is for initialising it with references to other scripts/objects, a couple things you can do:

  1. Call things when you want to call them. If you have a few objects that need to do things in order, and you're spawning them in/out/whatever else, have a method to organise that, e.g
void Initialise() {
    Manager manager = CreateManager();
    List<Child> children = CreateChildren();
    foreach (var child in children) {
        child.Initialise(manager);
    }
}
  1. Rely on Awake/Start, but set the script DefaultExecutionOrder to guarantee which script runs first https://docs.unity3d.com/Manual/class-MonoManager.html
vocal sail
chrome tide
#

what do you think is the best way to handle items in a player inventory? is List<GameObject> fine for holding items?

young fossil
#

Hey, so I've been wanting to make an AI for a capture the flag demo. I have been researching GOAP and it seems that is too much for what I need, yet a basic FSM solution is still not effective either

twilit pilot
polar acorn
young fossil
#

So trying to find a middle ground between GOAP and FSM. Behaviour trees is another solution but struggling to see the advantages of that

vocal sail
young fossil
chrome tide
vocal sail
twilit pilot
summer stump
twilit pilot
#

perhaps you should share the code you have currently as it doesn't make much sense

cosmic dagger
vocal sail
young fossil
slender nymph
#

muse behavior exists and is free

summer stump
young fossil
summer stump
young fossil
amber grove
#

I am still trying to get this player input component working. For some reason the move call seems to want to call a function with a signature that lacks any input value... but surely that isn't right? I need the input value from the move input to know which of the four directions the player is moving. I am very confused... How do I get the Vector2 into the function if the function may not have any variables in the signature?

Code Link:
https://pastebin.com/1dLzxNNs

#

(I got OnMove into that slot by commenting out the content of OnMove and cutting out InputValue then saving and only then was it available... when I added all that stuff back in it now says the function is missing)

summer stump
#

The parameter needs to be CallbackContext
As it says in your image
"Move (CallbackContext)"

slender nymph
amber grove
slender nymph
#

your OnMove method needs a parameter of type InputAction.CallbackContext

amber grove
slender nymph
#

wtf are you even referring to there?

#

i am referring to this method: public void OnMove(InputValue input)
the type of the parameter needs to be InputAction.CallbackContext

#

not InputValue

amber grove
#

In my current function there is a parameter InputValue. Is what you're talking about meant to replace that or is it seperate.

#

Ah. Replace. Alright.

slender nymph
#

were you somehow confusing the parameter's name input with a type? because if so, you may want to refresh yourself on the basics of c# to learn the difference between types and identifiers

amber grove
warm condor
#

Hi guys, so I have this problem when setting a variable (AccelerationProgress) to zero when the current state is walking or running (meaning right when the player starts walking OR starts running, that variable becomes a zero). The problem is that in my line on code, if the player is walking and then runs, then that variable will not be set to zero. I have no idea what I can do to solve this issue, but I do feel like storing the current state and the previous state and then comparing them might solve this issue. Before doing that tho, I just want to confirm with you guys if that is a good solution or if you have another easier solution.
Here is my line of code:
if (CurrentState != State.Running.ToString() || CurrentState != State.Walking.ToString()) AccelerationProgress = 0;

slender nymph
#

oh god why are you storing the state as a string instead of just using whatever type State.Running and State.Walking are?
anyway, more info about how you are transitioning from states would be helpful to determine the best way to go about this

warm condor
#

with numbers?

slender nymph
#

is State an enum?

warm condor
#

yes

slender nymph
#

then use that

#

there is no reason to convert it to a string to store it in a variable

warm condor
#

oh I see. I will change that

warm condor
slender nymph
#

sure, use a bin site like the bot shows 👇 !code

eternal falconBOT
warm condor
#

@slender nymph the issue is on line 87 on the function ResetProgressionValues

slender nymph
#

holy hell this is a mess. you're going to need to refactor this if you want to do this in a sane way because you'll need to check what state you are transitioning from when you go to transition into the Walk or Run state
or if you just want a bandaid solution, you can just check what the current state is when you go to call Run() or Walk() and just reset the AccelerationProgress if you are in the opposite state

rich egret
warm condor
slender nymph
#

with an if statement

summer stump
#
private State myCurrentState

if (myCurrentState == State.Running)

Or a switch if you have a bunch of states (I did not look)

warm condor
#

yes I am aware of that, but I don't know what the condition must be to check if they are in the opposite states

slender nymph
#

aethenosity just showed you

#

by "opposite state" i am just referring to those two states you are having trouble with

slender nymph
#

you would be much better off if you built a proper state machine where you transition into a state explicitly and explicitly transition out of it as well instead of this just possibly random hopping into and out of states with no control over what happens when you enter/exit a state

#

these simplistic if/else chain state machines don't allow fine grained control over what happens when you enter or exit a state and so you end up with spaghetti when you try to do anything deeper than just moving in a specific way during a state

swift crag
#

adding a SetState method that handles the transitions can help with that. I use that for systems that are just a few fixed states.

warm condor
#

im sorry, this is the first time I have used an enum. When ever I use an enum, I always use .ToString. just one more question, aethenosity used cs State.Running and compared that value to myCurrentState, then how is myCurrentState being saved

wintry quarry
#

It's a variable

timber tide
#

strings and enums are identifiers. So technically making an enum into a string is quite redundant

wintry quarry
#

It's saved... in whatever scope it's declared in.

#

But yeah no reason to use ToString most of the time.

warm condor
warm condor
wintry quarry
#

It's a State

#

enums are custom types

#

they're datatypes just like int string SomeClass MonoBehaviour etc

#

State myCurrentState; is a variable of type State named myCurrentState

slender nymph
#

using State as the type for your CurrentState variable was the first thing i suggested to you

warm condor
#

yea your right 😅 I didn't seem to understand what you meant here

summer stump
#

You simply set it by:
myCurrentState = State.Running

slender nymph
#

you're just creating a whole bunch of garbage and unnecessary conversions when you ToString an enum just to store it in a variable. you're also likely increasing the amount of memory you are using in many cases when doing that since an enum is just a regular integer with a fancy nametag at compile time so it's just 4 bytes where as the strings vary in size based on the number of characters

summer stump
#

Or whatever state you want

warm condor
#

ok well thank you! ill apply these changes

ivory bobcat
#

Strings are also slower to compare and use more memory - for the most part.

swift crag
#

you also lose some sanity checks from the compiler

#

someString == "totally bogus name!!!" is fine

#

myEnumVal == MyEnum.IMadeThisUp is a compile error

warm condor
swift crag
#

i'm talking about a bogus name

summer stump
swift crag
#

"i made this up" was misleading since the entire thing is made up :p

warm condor
#

ahh well yea that makes sense

swift crag
#
MyEnum.ThisValueDoesNotExist
#

this is not a pipe

polar acorn
timber tide
#

One of the more useful uses of enums is it's got type constraints, so you aren't just comparing some raw string values

swift crag
#

a cool thing about enums is when you use them in a switch expression

#
int result = myEnumVal switch {
  MyEnum.Foo => 1,
  MyEnum.Bar => 2
};

You get a warning if you skip any enum values

#

Annoyingly, you also get a warning if you don't have a default case (because it's possible to cast an int into a bogus enum value that doesn't exist)

#

i turned that off

#

that way, if I introduce a new enum value, all existing switch expressions get warned for missing the new value

#

adding a default case winds up hiding the problem!

timber tide
#

oh yeah they look nice in switch statements too is always a plus

swift crag
#
    public float ToSliderValue(float value) => kind switch
    {
        Kind.Linear => value,
        Kind.Logarithmic => Mathf.Log(value, 2)
    };

    public float FromSliderValue(float sliderValue) => kind switch
    {
        Kind.Linear => sliderValue,
        Kind.Logarithmic => Mathf.Pow(2, sliderValue)
    };
timber tide
#

I used to really abuse the heck out of strings, but enums are life now.

#

Probably some bad python habits

rocky canyon
#

enums are epic

#

i'd call singletons life over enums doh

warm condor
#

I have to start learning how switch statements work in C#

swift crag
#

It's not a switch statement!

#

It's a switch expression

#

an expression is something like 3 + 4

#

statements contain expressions, amongst other things

#
switch(myEnumVal) {
  case MyEnum.Foo:
    result = 1;
    break;
  case MyEnum.Bar:
    result = 2;
    break;
}
#

a similar switch statement

whole lark
#

hi, does someone know how to fix this error? 😅

swift crag
#

The proper name of that class is TMPro.TextMeshProUGUI

#

You can either:

  • write the full name, including the namespace
  • add using TMPro;
slender nymph
eternal falconBOT
swift crag
#

(and do that, yes)

#

it should be suggesting a fix

warm condor
slender nymph
#

Why are you doing that

warm condor
#

I want an if statment that will reset the AccelerationProgress only once untill these conditions are met

summer stump
#

If you are running or walking then set acceleration progress to 0 every frame? (Assuming update)

slender nymph
#

Just check if the current state is running when you want to start walking and vice versa

#

Two separate checks

#

Or take my better advice of completely refactoring to a more robust state machine that has entry and exit methods for each state so you have better/more extendable control over everything

warm condor
#

I don't know how to make that tho. What is a state machine and an exit method?

#

and how do I apply it to what I am trying to do?

warm condor
white yew
# warm condor I don't know how to make that tho. What is a state machine and an exit method?

A state machine runs specific behaviour for an object when it's assigned to. Think of it like Turing machine, it loads a specific class for the appropriate type, that runs specific design behaviour for that state, and then exit when either the manager that holds the state machine decided to load a new state to it or when the state have specific instruction to load a new state after it's finished with it's behaviour. Here's a video that cover about state machine in Unity: https://www.youtube.com/watch?v=G1bd75R10m4

Sign up for the Level 2 Game Dev Newsletter: http://eepurl.com/gGb8eP

In this video, I'm going to teach you how to code a simple State Machine in Unity.

#Unity3d #UnityTutorial, #GameDevelopment

Have you ever written a method with two paths of execution? It probably had an if statement based on a member variable, right? But then your requirem...

▶ Play video
gleaming kraken
#

i still wonder to this day how the hell the rollercoaster tycoon dev made the game in assembly

#

and im over here struggling with c#

white yew
# gleaming kraken and im over here struggling with c#

Not all great assembler programmer started to work in game industry. They had experience of failure and tries before they were able to pull off such great success.

Not to mention, but I recall a developer in Activision talked about the Z-depth bug in World of Warcraft (or was it something else?), where a character would be clipped over a wall, due to of how the game engine handles the draw implementation between the environment and the playable character.

rich adder
#

c# is pretty forgiving and there are soo many ways to do something

gleaming kraken
#

i truly hope i dont pull a yandere dev

#

and get clowned on for poor code

#

but i have so many else ifs

#

and dont know how else to implement it

white yew
#

C/C++ requires extensive care with memory management and code structure. C is very abstracted, C++ includes classes and object orientated programming is made possible, but comes with high risk cost of memory violation. C# makes it memory safe, but at the cost of performance dealing with garbage collector.

You are in a beginner channel, where it should be easy to ask for help and recommendations.

rich adder
gleaming kraken
#

5 else ifs

#

i think that's an issue

rich adder
#

I had bigger

white yew
# gleaming kraken but i have so many else ifs

If you have too many conditional statement, then consider refactoring it down to simplier statement.

I think the best way to approach C# is to make your game as simple as possible, describe what your game absolutely need to function, and then branch out from there. If you start C# by detailing a function that doesn't impact your entire game, then you need to take a step back and focus on your pillar of the game.

rich adder
#

switch is the same thing as a bunch of else if

zenith cypress
#

Under a certain amount. Then it becomes a jump table if possible

white yew
#

Becauae the neat thing about C# is that once you describe the abstract class of what your game does, you can create override class and inherience to define specific behaviour for your game. E.g. An IPlayer interface can be applied to a character or vehicle, depends on how you define it.

rich adder
#

I would say interfaces are more on the Composition side of things than inheretence

molten dock
#

for something where theres lots of different enemies which do different damage and effects

#

what would be a clean way to code that

rich adder
#

thats a very vague question

molten dock
#

cause i can only think of a big script of if statements

rich adder
#

what way "clean"

cosmic dagger
#

whoa, that's a big one . . .

molten dock
#

like if tag = guy 1 if tag = guy 2

#

on and on like that

#

mb sorry for being vague

rich adder
#

each enemy should have their own behavior and not having to check any tags or anything

cosmic dagger
#

simple solution is to use OOP (inheritance) for the enemy classes . . .

rich adder
#

maybe here you can use Inheretence or abstracting the class

#

override the methods in each enemy etc

cosmic dagger
#

better solution is to create separate classes and stack them on enemies to create their specific behaviour . . .

rich adder
#

indeed. Unity is component based, make a bunch of components

woeful dawn
molten dock
#

i will look into those things thanks guys

molten dock
amber grove
#

I am getting 6 The referenced script (Unknown) on this Behaviour is missing! errors and I haven't the slightest clue what the problem is. I have checked all my scripts and the public class is indeed named the same as the script file and I can't find any object which does not have it's script component attached correctly... also the errors do not highlight or indicate toward any asset or gameobject. How does one debug such an error?

cosmic dagger
# molten dock could you explain this a little more please

e.g., i have two turrets: both have a Shoot component and a FindTarget component, but TurretA has a Rotate component while TurretB does not. this means TurretA can find targets in range as it swivels while TurretB can only find targets that come into its range—since it doesn't rotate. by stacking components, you can add/remove functionality, and this changes their behaviour . . .

rich adder
#

or you saved changes of script during playmode

amber grove
rich adder
#

there is nothing to fix then

#

its not gonna be there again

#

the old script because now its a different script as far as computer cares

amber grove
#

hmm. I kept getting it. Might be a comedy of errors on my part though.

rich adder
amber grove
#

It's probably fine.

rich adder
#

so yeah just be aware of saving script changes while in playmode it will happen

#

you just restart the simulation and ur good to go

cosmic dagger
# molten dock could you explain this a little more please

the same applies to enemies. all of them will have a base Enemy script, but you can add individual components to give them different behaviour. adding a Jump component will allow any enemy with that component to jump, while others will not. each GameObject will have a separate instance of Enemy; you can use prefabs to give certain enemy types different values for attack, damage, health, etc . . .

woeful dawn
#

That's general idea behind having component base architecture. Don't be afraid of having multiple scripts, just try to not couple them to much.

molten dock
#

Is component another word for script

#

I get it now tho thank you

woeful dawn
#

in most cases with unity it will be interchangeable: scripts / monobehaviours / components.
but scripts can also be other stuff. like scriptable object or just plain c#

rich adder
#

if its on a gameobject, its a component

amber grove
#

For some reason the button variables in this script are not serializing (I think that's the right term) in the editor. I want to be able to tell the buttons whether to be visible in this script and so need their object but I am not able to get a slot for them.

https://pastebin.com/8mqxjDti

rich adder
#

wrong Button class

#

using UnityEngine.UIElements;
should be
using UnityEngine.UI

amber grove
#

damn. it really were that simple weren't it. Thank you very muchly.

rich adder
amber grove
#

hmm... I get the feeling I may have switched it to UIElements because it looked like that had the ability to change the object's visibility. UnityEngine.UI.Button seems to lack the ability to change that.

rich adder
#

yeah don't think there is a need for UI Toolkit buttons to be in inspector, they constructed different than old GUI with binding and all that

rich adder
amber grove
#

Doh. If I'm doing that I should have the gameobject as the variable. Pardon me.

rich adder
#

you can access the gameObject

#

from component

#

every component has a .gameObject property

amber grove
woeful dawn
#

I believe it was something like gameObject.SetActive(false); but can't check that right now

amber grove
#

yeah that's right. I've got that.

rich egret
#

Hi

#

!code

eternal falconBOT
rich egret
#

How to fix it? 🤔

polar acorn
rich egret
rich egret
#

I know 💀

summer stump
rich egret
#

I just went to try to fix the code after I wrote it and I didn't look at the discord

#

I have no reason to lie 😅

ember tangle
#

What is a good way to troubleshoot the input system slowing down?

rich egret
#

@polar acorn

    {
        Transform parentTransform = parentObject.transform;

        foreach (Transform child in destinationObject.transform)
        {
            if (child != this.transform)
            {
                child.SetParent(parentTransform);
                Debug.Log("Child " + child.name + " transferred to parent object: " + parentObject.name);

                // Logging the values for debugging
                Debug.Log("Comparing child.name: " + child.name + " with lastTransferredWeaponChild1: " + lastTransferredWeaponChild1);
                Debug.Log("Comparing child.name: " + child.name + " with lastTransferredWeaponChild2: " + lastTransferredWeaponChild2);

                if (child.name.Equals(lastTransferredPlayerChild))
                {
                    lastTransferredPlayerChild = "";
                    PlayerPrefs.DeleteKey("LastTransferredPlayerChild");
                }
                else if (child.name.Equals(lastTransferredWeaponChild1))
                {
                    lastTransferredWeaponChild1 = "";
                    PlayerPrefs.DeleteKey("LastTransferredWeaponChild1");
                }
                else if (child.name.Equals(lastTransferredWeaponChild2))
                {
                    lastTransferredWeaponChild2 = "";
                    PlayerPrefs.DeleteKey("LastTransferredWeaponChild2");
                }
            }
        }

        PlayerPrefs.Save();
    }```
Like this?
#

If you ask, they don't respond

slender nymph
#

give them more than like 10 seconds to respond. parsing that giant block of code and trying to figure out why you've chosen to do any of this in this manner is going to take a minute

summer stump
#

Especially considering you ignored digi for hours

rich egret
summer stump
rich egret
amber grove
# rich egret It was not on purpose 😅

Also it is worth scrolling back to see how people responded to the original time you posted the question before reposting it to see if you've already been answered... people tend to get annoyed if they are repeating themselves at a brick wall.

rich egret
languid spire
#

you know, I dont see any difference in that code from the last 3 times you've posted it

polar acorn
#

Also you don't have to ask "like this" you can just run the code

rich egret
rich egret
polar acorn
rich egret
polar acorn
# rich egret

So, since it matches the second one, it blanks that one. Since it does not match the first, it doesn't blank that one

#

That seems to be exactly the behavior you've coded in

ember tangle
#
{
    if (Input.GetKey(KeyCode.W)) //move forward
    {
        newCameraPosition += transform.forward * cameraMoveSpeed;
    }

    if (Input.GetKey(KeyCode.S)) //move backwards
    {
        newCameraPosition += -transform.forward * cameraMoveSpeed;
    }

    if (Input.GetKey(KeyCode.D)) //move right
    {
        newCameraPosition += transform.right * cameraMoveSpeed;
    }

    if (Input.GetKey(KeyCode.A)) //move left
    {
        newCameraPosition += -transform.right * cameraMoveSpeed;
    }

}``` Is this not frame independent? It slows down massively the more game logic I have.
#

The entire Input system is suddenly sluggish

polar acorn
ember tangle
#

In the Update() method

polar acorn
#

So, why would it be framerate independent?

rich egret
polar acorn
#

You're calling it in Update and not using any sort of deltaTime

polar acorn
#

and that appears to be what's happening

rocky canyon
rich egret
swift crag
#

if you add a constant amount to your position every frame, your speed will depend on your framerate

rocky canyon
#

more frames, more +=s

polar acorn
#

Which end of that comparison isn't the value you expect it to be

rocky canyon
#

yesh

rich egret
ember tangle
swift crag
#

fixedupdate would be a bit of a hack

polar acorn
swift crag
#

you'd still want to factor in deltaTime there

rocky canyon
#

true u should scale it for smoother movement

swift crag
#

and camera movement should absolutely be happening in Update, not FixedUpdate, or you'll get a horribly jittery camera

swift crag
sterile radish
#

this script currently checks if i can click a bar or not using a timer. everytime i click the bar, it does a function however when i can't click it, the timer counts up to its intended value and when it does, i can click. however it doesn't seem to to be doing that for some reason?
https://hatebin.com/bqfyyrqeye

rocky canyon
#

ya, what i mean tho if he scales it he can keep it in Update();

#

but he didnt even know of fixedupdate.. lol soo he learned a bit heh

#

kinda all ties together, when i was learning knowing when to scale w/ deltaTime and when not to.. and how the update loops all work was like 1 big session

swift crag
#

even if you use it in FixedUpdate, you should multiply in deltaTime; otherwise you move 50 times faster than you intended to

dense root
#

I'm a bit confused on how to approach this systems problem for a Pokemon clone. What's the best way to handle battle states?

Do I create a BattleManager that changes the game state depending on whether or not they are in battle? If so how do I toggle the active game state?

The way I'm doing it right now is toggling between the two cameras which is very janky and buggy.

Any thoughts appreciated.

ember tangle
#

because it doesnt work at all

slender nymph
#

your cameraMoveSpeed might just be super small because you were probably previously compensating for it being in Update

ember tangle
#

I've left the method in Update() while I tested * Time.deltaTime; and the camera not longer moves at all

rich adder
slender nymph
ember tangle
#

0.1f, but shouldn't it still move a bit?

rich adder
#

oh lord

slender nymph
#

that would move one tenth of a unit per second

rich adder
#

say your speed is 5, lest say 0.23(deltaTime) thats about 1.15
5 * 0.23

polar acorn
ember tangle
#

Alright this is starting to make sense lol

slender nymph
#

cameraMoveSpeed should be the number of units you would like for it to move per second

ember tangle
#

I have so much fixing to do now that I know this lol

rich egret
#

Can you give me an example of the part that needs to be changed in the code? 🤔

polar acorn
sterile radish
#

this script currently checks if i can click a bar or not using a timer. everytime i click the bar, it does a function however when i can't click it, the timer counts up to its intended value and when it does, i can click. however it doesn't seem to to be doing that for some reason?
https://hatebin.com/bqfyyrqeye

polar acorn
#

You described several behaviors without specifying which one isn't happening

lime pewter
lime pewter
# lime pewter

Hey, for some reason in my water cellular automata simulation script randomly some of my water objects, are disabling their script and collider, does anyone know if "gameobject".isActive = true/false overrides a potential boolean variable I have declared which would be causing that?

#

That is the only thing I suspect could be doing that.

polar acorn
lime pewter
polar acorn
lime pewter
polar acorn
sterile radish
lime pewter
#
disabled
UnityEngine.Debug:Log (object)
LiquidScript:OnDisable () (at Assets/Scenes/Liquid Testing/LiquidScript.cs:297)
UnityEngine.Object:Destroy (UnityEngine.Object)
LiquidScript:PoolJoinPool (UnityEngine.Vector2) (at Assets/Scenes/Liquid Testing/LiquidScript.cs:229)
LiquidScript:CheckPool () (at Assets/Scenes/Liquid Testing/LiquidScript.cs:166)
LiquidScript:WaterSimulation () (at Assets/Scenes/Liquid Testing/LiquidScript.cs:292)
LiquidScript:FixedUpdate () (at Assets/Scenes/Liquid Testing/LiquidScript.cs:36)
#

Would this be due to the "Destroy"?

#

It should be destroying the gameobject all-together not disabling no?

polar acorn
lime pewter
#
foreach (Transform child in transform.parent)
        {
            if(child.transform.parent.childCount == 1)
            {
                Destroy(child.transform.parent.gameObject);
                child.transform.parent = GetLiquid(gameObject.transform.position, joinDirection).transform.parent;
                //child.GetComponent<LiquidScript>().isActive = false;
            }
            child.transform.parent = GetLiquid(gameObject.transform.position, joinDirection).transform.parent;
            //child.GetComponent<LiquidScript>().isActive = false;
        }
``` here's the script that seems to be calling the destroy, does Destroy() recursively on children not destroy them?
polar acorn
lime pewter
solid bough
#

why can't i apply the object to the prefab?

lime pewter
#
Destroy(gameObject);
``` for that matter I am also calling this on the direct gameObject
polar acorn
#

If that's what you want to do there are better ways to do it

lime pewter
# polar acorn So, you loop through all child objects of this object's parent, then, if any of ...

Yeah, that is all it's doing. I am currently just mocking up the final version it's pretty sloppy at the moment, but essentially I have a pooling system, that disables the script attached to inactive liquid in a "pool" to save resources, except instead of connecting pools it is just disabling the script on gameobjects leaving me with multiple pools that are empty anyways, it really doesn't make a whole lot of sense to why to me currently.

#

There's not really a reason why these shouldn't be destroyed, only occasionally they get destroyed which seems odd.

polar acorn
lime pewter
polar acorn
#

So, I think you should cache the current parent object, change the parent, then destroy the old parent

lime pewter
#

I guess I was assuming that the parent being "destroyed" wouldn't destroy the children.

lime pewter
#

Actually, would swapping the Destroy and parent swap, just move the child and still have the old reference to destroy or do I need to fully cache it to a variable then empty it?

polar acorn
#

As it is know if you just swapped the lines all that would happen is you'd destroy the new parent object and everything on it

lime pewter
#
foreach (Transform child in transform.parent)
        {
            GameObject tempParent;
            if(child.transform.parent.childCount == 1)
            {
                tempParent = child.transform.parent.gameObject;
                child.transform.parent = GetLiquid(gameObject.transform.position, joinDirection).transform.parent;
                Destroy(tempParent);
                //child.GetComponent<LiquidScript>().isActive = false;
            }
            child.transform.parent = GetLiquid(gameObject.transform.position, joinDirection).transform.parent;
            //child.GetComponent<LiquidScript>().isActive = false;
        }
lime pewter
#

Honestly the "parent" will have it's own script enabled on it which can selfdestruct when empty later on anyway, so even if it's sloppy it'll be changed later. I appreciate the help!

crisp heart
#

following a tutorial on converting meshes to terrain, it said to put the script in unity's editor folder in the project under assets, but i cant the editor folder?

polar acorn
summer stump
crisp heart
wraith seal
#

i have a problem with a script and i dont know what the problem is

#

why are those hilighted red

polar acorn
wraith seal
polar acorn
#

Are you getting this error in the unity console or just the IDE

wraith seal
#

both

polar acorn
#

It seems like you have two classes named Mover that both have a function PrintInstructions

polar acorn
# wraith seal

Oh, this is a different one. You have two PrintInstructions functions in one class

wraith seal
#

thats my whole script

polar acorn
#

Do you have any other classes named Mover

wraith seal
#

in this script or in general?

polar acorn
#

Anywhere

wraith seal
#

not sure i dont think so

#

thats my unity page

polar acorn
wraith seal
#

yes

#

i tried removing things and saving restarting saving and what not and its still showing all sorts in red

#

it was showing earlier the update and start as red

polar acorn
#

Try deleting your PrintInstructions function in this class. Is the line in start still showing an error?

wraith seal
#

saved it and its still red

polar acorn
#

No, keep the line in start. Remove the function entirely

wraith seal
polar acorn
# wraith seal

You definitely have another mover class in your project

wraith seal
#

i dont know how tho

wraith seal
polar acorn
wraith seal
#

okay

#

found the problem

#

here

#

there was another mover

#

but i have no idea how it appeared there

#

@polar acorn thank you tho for the time and effort i just was a bit blind

solid bough
#

i have a timestop method that on collision changes Time.timeScale
i have a method that just plays a prefab with an animation on a button press

if i press the button when the timestop method plays my game permanently slows down, as if it never left the coroutine

they share no variables, objects, anything

has anyone had that happen to them?

woeful dawn
#

Time.timeScale is static

eternal needle
solid bough
polar acorn
prisma nexus
#

Could anyone help me with this problem? Ive been wanting to make the player who wields 2 guns have the guns allways point to where you are looking so that they allways look where you will hit. But when I have been using this script to try to make them face where the camera points, They are still rotating but not actually looking where I want them to look.

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

public class LookAtCursor : MonoBehaviour
{
public Camera mainCamera;
Ray ray;
RaycastHit hit;

void Start()
{

}

void Update()
{
    Ray ray = mainCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
    RaycastHit hit;

    if (Physics.Raycast(ray, out hit))
    {
        Vector3 targetPoint = hit.point;

        transform.LookAt(targetPoint);
    }
}

}

#

I want the guns to be pointing directly at where the crosshair is showing

ivory bobcat
#

Place a small cube at the hit point and see if it's where you think it is else print/draw the ray and hit point.

prisma nexus
#

I did try a debug.log and the position looked right

#

but i can try placing a cube to make sure

ripe orchid
ivory bobcat
# ripe orchid

You should fix the errors from the top to bottom - the first error simply says you've got other errors.

#

For starters, it's suggesting that you're missing a directive or assembly reference

ripe orchid
#

Ok can you explain what it means bro that why I sent it because i don’t understand what it means

#

What do I have to do to remove these errors

prisma nexus
ivory bobcat
queen adder
#

I have a rotating sun. It sets at (-1.5 X) and rises at (-1.5 X) because it goes all the way around. I need to switch the day/night bool each time it hits (-1.5 X)

if(sun.transform.eulerAngles.x == minX) {switch bool}

Doesnt really toggle, probably because it skips that exact value. How can I do this then?

prisma nexus
spare mountain
#

might be easier with a visual though

ivory bobcat
summer stump
# ripe orchid

Just like with Start earlier, you have another duplicate called OnUnityAdsDidFinish

ivory bobcat
#

I'm not certain how to explain it without simply writing/editing code - which is something I'm not willing to do.

queen adder
spare mountain
queen adder
spare mountain
queen adder
spare mountain
#

kk

ripe orchid
#

What could be the problem for that

ripe orchid
#

I literally wrote the exact same thing

ivory bobcat
summer stump
ivory bobcat
#

I've only seen the money manager script and not the ads manager script - not sure why it was shown rather than the ads manager script #💻┃code-beginner message

ripe orchid
#

And this is the error im getting

ivory bobcat
#

Did you save?

ripe orchid
#

Yes

ivory bobcat
#

Clear the console

ripe orchid
#

How do I do that

cosmic dagger
#

uhh, by hitting the clear button . . .

ripe orchid
#

On mac btw

ivory bobcat
queen adder
# spare mountain kk

I works now:

        float xRot = sunTrans.rotation.eulerAngles.x;

        if (xRot >= sunriseAngle && xRot <= sunsetAngle)
        {
            day = true;
        }
        else day = false;   
ripe orchid
spare mountain
queen adder
#

Thats right, thanks

spare mountain
#

np

ivory bobcat
#

Maybe you're missing some setup with Unity Advertisements

ripe orchid
#

How do I do that

ivory bobcat
ripe orchid
#

One more error left

#

Does anyone knows what I can do with this one

teal viper
#

!code

eternal falconBOT
rocky gulch
#

what is the equivalent of

  for (a,b) in zip(datA, datB) :

in unity

#

how does one do "zip" in unity

teal viper
#

What language is that?

#

I'd assume it's a map of some sorts? If so, then C# equivalent is a dictionary.

cosmic dagger
summer stump
#

Looks like python? It's been a whiiiile, but they do the colon at the end of a for ?

formal escarp
#

but i may be wrong.

wintry quarry
#

It's definitely Python

#

anyway this is definitely not a Unity question at all, it's a C# question

#

but there's not really a direct equivalent for the (a, b) list comprehension deconstruction you've got there.

#

That's all python @rocky gulch

#

The real answer is step back and explain what your ultimate goal here is, because the Python way of doing things:

  • Isn't going to work directly in C#
  • Is likely not very efficient in a game
ripe orchid
teal viper
eternal falconBOT
teal viper
#

And !ide

eternal falconBOT
teal viper
#

You should be able to see the compile errors in the ide

ripe orchid
#

So what should I do to remove the error

#

Do you know why it’s showing

wintry quarry
ripe orchid
wintry quarry
# ripe orchid How do I make it exist

Either you don't have the ads package installed, or you're following examples or tutorials for a different version of the package than the one you installed

#

so either:

  • install the thing you didn't install
    or
  • Find tutorials or examples for the thing you did
teal viper
#

To add to that:
The tutorial probably covers the required dependencies and how to install them

ripe orchid
#

It not really a tutorial my college gave it to me for a assignment