#💻┃code-beginner

1 messages · Page 484 of 1

wintry quarry
#

then you will get that behavior for free

iron mango
#

eventSystem.current.IsPointerOverGameObject() always returns true

#

i mean makes sense, in a game engine i always hover over a gameobject

queen adder
#

means you have a random image/graphic blocking the screen

iron mango
#

no

queen adder
#

disable all of your canvas

#

the gameobjects of canvas

iron mango
#

it only returns true when hovering over a gameobject

#

any

#

not only ui

queen adder
#

EventSystem only works on UI

iron mango
#

no

#

apparently not

#

i see it

iron mango
rich adder
iron mango
#

thank u
i didn't know that before

rich adder
#

you just add this component to the camera and you can get all the EventSystem methods on colliders, like OnPointerEnter etc

iron mango
#

ah yeah i removed it and now IsPointerOverGameObject works only with ui

i thought wtf this function is useless in a gameengine 😭 because you always hover over a gameobject hahah

timid ember
#

Why are my outputs not showing

#

the messgae box is on

#

i have no errors

#

wait

rich adder
timid ember
polar acorn
timid ember
#

vsc c#

rich adder
#

well Console.WriteLine wont work in unity btw

timid ember
#

i know

rich adder
#

so how you know those cases are hit ?

timid ember
#

ive been trying to run this on for 3 days now

polar acorn
#

It's very clearly C# because it's Unity

#

what actually runs this code

#

where is it

rain yarrow
#

Uhm idk which channel to ask something about converting a unitypackage to fbx, where d i ask?

rich adder
#

which gameobject is it on basically

timid ember
#

object?

#

main camera

polar acorn
rich adder
languid spire
rain yarrow
#

help okay

#

ty for telling me >_<

rich adder
#

unitypackages are opened inside unity

rain yarrow
#

Thats the thing i tried downlaoding unity and uh yea its too much for my pc

#

💔

timid ember
rain yarrow
#

so i was coming here to see if anyone could help me with it

timid ember
#

i tried sumthing simple

polar acorn
timid ember
#

default

rich adder
#

oh lord

languid spire
polar acorn
#

The only way those would be static is if you made them static

#

So, why did you do that?

#

Are you intending to call these functions yourself? If so, where?

rich adder
timid ember
#

even if i emove static, problem persists

#

the problem is my console doesnt display outputs

#

it displays errors

languid spire
#

there is still a static in there

timid ember
#

i downloaded all packages

polar acorn
rain yarrow
timid ember
timid ember
polar acorn
timid ember
#

how do i show it

polar acorn
#

Screenshot

timid ember
#

i dragged it there

polar acorn
#

like you've done multiple times already

timid ember
#

how do i sho a drag tho

polar acorn
#

Show the object

timid ember
polar acorn
#

with the component on it

timid ember
#

unsure if this is what you mean

polar acorn
#

Okay, now, did you actually run the game

rich adder
# rain yarrow

why cant you install unity real quick? importing a package wont be much processing power

timid ember
rain yarrow
#

oki

polar acorn
timid ember
#

ye

#

ur jesus

polar acorn
#

Show a screenshot of the game in play mode, with the console open, and this object selected

timid ember
#

ur allah

#

ur every god i know

polar acorn
#

Okay so the reason it wasn't printing is because you literally did not start the program

#

didn't think I'd ned to have explained that

timid ember
#

and im athiest thats hw big of a problem you solved

#

god bless you

rain yarrow
polar acorn
#

It took you three days to think of "run the game"?

timid ember
#

i was searching every website for a solution and they all talked about the box

#

checking message box

rich adder
rain yarrow
#

ah ok

#

i came here becauese i was hoping someone could try to do it for me >_<

polar acorn
#

Then you were mistaken

rain yarrow
#

oki

#

goodbye :)

timid ember
polar acorn
timid ember
#

debugged/saved

#

do i also have to remove the component and reattach

polar acorn
#

no

timid ember
#

wait ill try to restart

timid ember
steep rose
timid ember
steep rose
timid ember
#

i helped many people in blender when i was still a beginner man

#

so i thought

#

maybe he is as well

deft grail
timid ember
#

why u mad bro i just asked a dmb question im clearly a beginner

#

didnt know

steep rose
#

why would i be

timid ember
#

the lack of emotion through text

#

sry

rich adder
#

please use links for !code

eternal falconBOT
neon lynx
#

Is there a way to make a player can't press two or more specific keys at the same time? I coded it but doesn't work.

deft grail
#

directional movement?

rich adder
wintry quarry
#

Looks like it should work fine

neon lynx
wintry quarry
#

how are you validating it's not working

#

THere's no "error" that Unity would detect

#

Did you populate the restrictedKeys array properly in the inspector?

verbal dome
#

Make sure that its not a hardware issue also. Like a bad keyboard having trouble detecting multiple keys

wintry quarry
#

Note that your code only does Debug.Log when a key is pressed. It's going to be hard to tell if it's working from reading these logs since they will fly by so rapidly each frame

#

One way to check if this is working:

    private void Update()
    {
        CheckRestrictedKeys();

        
        if (!areKeysBlocked)
        {
            Debug.Log("Doing movement");
            HandleMovement();
        }
        else 
        {
            Debug.Log("Multiple key presses detected. Not moving!");
        }
    }```
#

That will be a bit more readable than what you have right now

#

You'll want to make sure Collapse is turned off in your console as well

wraith phoenix
#

Greetings everyone,
I can no longer drag files into my Unity Editor Project folders to import new sprites or any assets. When I do so the circle with a slash through it appears.
I can import assets manually by right-clicking on my Project Folder.
I believe the project may be starting in admin mode, but I can’t figure out how to prevent it from doing so.

-I uninstalled/reinstalled Unity entirely, and the same issue is still happening.
-New/old projects do not have this issue
-I did drag an asset directly into my project directory rather than through the editor. The bug has been present ever since, but I do not know if that is the issue
-The project was synced with Google Drive, but I have unsynced the project
-I have tried duplicating the project entirely, but the error still occurs

At this point, it seems like only one project is stuck in admin mode or something else.
Does anyone have any ideas?
Could there be a startup/temp/main script that needs to be manually changed?
Is there a way a single project can be started in admin mode?

rich adder
#

try making new project that works, then import the broken one as a unitypackage, see if that works

wraith phoenix
#

Ok, let me see if I can figure that out. Thank you @rich adder

rich adder
wraith phoenix
#

So I need to export my previous project first? Or, does this automatically happen and that's how Unity organizes it's internals?

rich adder
wraith phoenix
#

Great documentation! I'll get to work on this real quick and post back soon

wraith phoenix
#

importing now

#

Looks like I need to update the renderer and input controller but aside from that it has worked!

rich adder
#

nice!

#

i wonder if something in project settings got borked or even library folder?

wraith phoenix
#

Thank you for the help @rich adder !

wraith phoenix
rich adder
#

whats the last thing you did before it broke?

wraith phoenix
#

It occured right after I tried to backup the game to google drive so I could work on it via laptop over vacation.

rich adder
#

oh how did you back it up ? like some type of file sync or something

wraith phoenix
#

I didn't REALLY see anything happen right away. But after two weeks on vacation, when I returned home and tried to drag in some new sprites I created, the bug was present

rich adder
#

weird..maybe it was just library folder that needed deletion n rebuilt ? worth a try ig

wraith phoenix
# rich adder oh how did you back it up ? like some type of file sync or something

Very roughly lol. I use Google Drive on my computer and have a shared drive directly synced. I gave permission to also sync the google drive to my game project folder (which now I see would of been smart to make a copy since this is the first test).
I was essentially trying to make a simpler version of Unity Version Control where I didn't have to check-in changes every time

wraith phoenix
rich adder
rich adder
wraith phoenix
#

Yes, I need to learn Git.
Desktop version was pretty friendly.

wraith phoenix
rich adder
wraith phoenix
rich adder
#

yup. Library folder is harmless(mostly cache files), that's why we don't commit to it via GIT / vc n its bulk of size

queen adder
#

trying to declare a scriptableObject that ive already made, in my last code (dumpsterfire to be fair) this exact line works but here SO doesnt exist

#

ive probably forgotten a step

languid spire
queen adder
#

yeah ive done that

wraith phoenix
queen adder
#

im basing this on the old satan child of a script we made last time

rich adder
queen adder
#

ive only declared SO here

rich adder
#

what you shown, no you declared a reference to SO

languid spire
#

your scriptable object script

queen adder
#

OOH WAIT

rich adder
#

where did you define you class

queen adder
#

nonono okay i got it

#

yeah i realyl do suck at naming things

rich adder
#

SO is horrible name yes

queen adder
#

i assumed SO was shorthand for scriptable object or something but thats

#

literally what i named it yeah

#

fixed

rich adder
#

they just have some special functions in unity

wraith phoenix
rich adder
wraith phoenix
#

I cannot drag in new sprites. The bug still persists

rich adder
#

hmm yeah idk.. its possible something else that isnt in lib maybe..project settings ? 🤷‍♂️

#

as long as new project works 😆

languid spire
wraith phoenix
wraith phoenix
wraith phoenix
#

As a note, I have successfully dragged a few of those sprites into other projects

languid spire
# wraith phoenix

The problem would appear to be with you picking up, not dropping into Unity

wraith phoenix
languid spire
#

Elaborate what? Is the image not sufficient to show the item has not been picked up correctly?

wraith phoenix
#

dragging and dropping works fine into other projects. It doesn't work for this one

languid spire
#

Also I'm not sure what your Unity Assets folder is but it seems rather odd

wraith phoenix
#

Google drive sync

#

Seperate from my project

#

So I can share with my artist

languid spire
#

Unity does not play well with these types of follders

wraith phoenix
#

That's why I also showed the download folder. But definitely learning it doesn't link the sync files that much

#

Here is a video of me doing the same thing with another project

wraith phoenix
rich adder
#

the google drive one probably messed up folder permissions and unity is reading whatever permission was set

wraith phoenix
#

Defintely agree there

#

I can't figure out how to adjust the permissions for the Unity project though

#

I've tried a few different methods but permissions are not my forte

wraith phoenix
# wraith phoenix I've tried a few different methods but permissions are not my forte

Recap in case it helps:
-I uninstalled/reinstalled Unity entirely, and the same issue is still happening.
-New/old projects do not have this issue
-I did drag an asset directly into my project directory rather than through the editor. The bug has been present ever since, but I do not know if that is the issue
-The project was synced with Google Drive, but I have unsynced the project
-I have tried duplicating the project entirely, but the error still occurs

languid spire
wraith phoenix
#

folder works fine in other projects though/

#

copying over the whole thing that is

#

The issue in the bugged project seems to be when I synced it with Google Drive

#

Even after unsyncing it, the permission seems to be messed up.
Now I cannot 'read/write' new files into the project

#

Any thoughts on how to reset the permissions?

sage mirage
#

Hello, guys! I have a problem you know. So, I am making currently a horror game. So, what I want to make is when the player collects an item to change the task, so somehow I have to connect tasks with items inside my game. At the start of the game, I have a key inside the house, and when I am taking that key I want the first task to change.

This is my interaction method, so when I press the E button I am collecting the item.

Interactor.cs

{
    Ray ray = new Ray(interactionSource.position, interactionSource.forward);
    RaycastHit hit;

    if (Physics.Raycast(ray, out hit, interactionRange))
    {
        Interactable interactable = hit.collider.GetComponent<Interactable>();

        if (interactable != null)
        {
            interactable.OnInteract();
            StartCoroutine(DisplayFoundItemText());
        }
    }
}```
and 

Interactable.cs
```public class Interactable : MonoBehaviour
{
    public virtual void OnInteract()
    {
        Collect();
    }

    public void Collect()
    {
        gameObject.SetActive(false);
    }
}```
#

Something like a task/quest system I ve never done that before very unfamiliar with that

main karma
#

hello, so I did nothing but test my game, and suddenly the editor started taking up EVERYTHING
any idea why

#

like the game lagged suddenly and when I looked the editor decided to eat my game

#

I also get this error

#

and this one

dense pike
#

Hii

main karma
rocky canyon
# main karma

anytime you see UnityEditor in the stack-trace.. just assume it'll be fixed with 1 of 3 advancing steps..

  1. Reset Layout(s)
  2. Reset Unity
  3. Reset PC
    then for extra credit:
    *. Delete ** \Library\ ** folder
tranquil hollow
rich adder
tranquil hollow
main karma
rich adder
short hazel
#

Particles can be emitted in world space (a setting on the particle system), so the emitted particles don't follow the object they were emitted from

#

Requires no code or hierarchy changes

verbal dome
#

It kinda looks like it's in local space, but previous particles stay where they were when the character rotates, so I'm a bit confused

rich adder
#

that is if they don't want the particle to follow, i bit confused if they meant just rotation or pos too lol

main karma
verbal dome
#

Looks like it's already in world space tbh, but the emitter shape (Shape module) is rotating with it

verbal dome
main karma
#

I think you'd just have to unparent it and then either use a position constraint (although I've never used one) or make a simple script that says
yourParticle.transform = player.transform - offset;

#

in some update

#

because parenting changes the position and rotation of the object and I'm assuming @tranquil hollow want's to move it along with the player and not rotate

#

@verbal dome btw I heard parenting isn't allowed for multiplayer games, is that true?

rich adder
verbal dome
rich adder
#

notice how its in "Advanced topics " 😛

#

working on this myself (have a CTF project)

verbal dome
#

Netcode docs look pretty good 👀

rich adder
#

yea! we actually have header tags that work here

#

link to specific sections . wooo

#

I use the same documentation software, I believe its Docusaurus

vocal quiver
#

guys i need help my camera is not working properly basically it is showing something else in scene view and something else in game view and my scripts arent the reason because i disabled them and the issue is still there.

vocal quiver
verbal dome
#

Type t:camera in the scene hierarchy search to see if you have an extra camera

vocal quiver
#

I checked and there is no camera other than the main camera

verbal dome
#

Is there an Animator involved?

vocal quiver
#

wait u were right

#

there were 2 cameras

#

idk how but when i typed camera in the hiearchy i found 2

#

thx guys

dense pike
#

Anyone fancy helping me with a script

frosty hound
#

Just ask your question

dense pike
#

I need a script where the zombie will play attack animation when in range of player

frosty hound
#

You need? This server doesn't do handouts.

eternal falconBOT
#

:teacher: Unity Learn ↗

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

steep rose
#

and learn the animator system

deft grail
vestal adder
#

im not sure where to start when making a scrolling text effect

#

im not sure how to explain the effect well but i mean like whats in undertale when any text shows up and it slowly reveals itself

rich adder
vestal adder
#

i know how to explain it now it should look like its being typed in

#

yes like that

rich adder
#

you can loop through each char in the string and add delay between

vestal adder
#

that makes sense thanks

cosmic dagger
vestal adder
#

i ended up doing that

#

i would have searched myself but diddnt know the name of the effect so could not

noble forum
#

Hi

#

how do i make my player fall when he is descending the stairs for example

#

I mean the player falls but very very slowly

eternal needle
# noble forum I mean the player falls but very very slowly

the reason your player is falling right now is due to the rigidbodys default gravity settings. id toggle use gravity off and control what you want it to be yourself. right now you have no control over it.
check the slope of what the player is on, then set the velocity accordingly

ancient karma
#

can anyone point me to why this script is preventing me from rotating the camera?

    void Update()
    {
        Vector3 offset = new Vector3(distance, distance, distance);
        transform.position = player.transform.position + offset;

        if (Input.GetKey(KeyCode.Q))
        {
            transform.RotateAround(player.transform.position, new Vector3(0, 1, 0), rotateSpeed);
        }
        if (Input.GetKey(KeyCode.E))
        {
            transform.RotateAround(player.transform.position, new Vector3(0, 1, 0), rotateSpeed);
        }


        transform.LookAt(player.transform);
    }
#

The camera should orbit around the player when you use Q and E, but instead while pressing Q or E it temporarily moves the camera rotateSpeed degrees (3 in this case) around the player, and then returns to its original position when you let go

keen dew
#

The first two lines should be in Start, and the camera should be a child of the player object so that you don't need to set its position manually

ancient karma
#

but wouldnt making the camera a child of player also associate it with the players roation?

#

I want the player to be able to rotate independently of the camera

#

I might have forgotten to say that lol, it's late meowsweats

keen dew
#

The hierarchy is usually like this:

  • Player container
    • Player model
    • Camera
#

You move the player container and rotate the player model

ancient karma
#

hmmm, ok yeah. I did think of that but said what I have works and went with it. I'll try rearranging it

#

oh lol thanks for pointing out the Start thing, I didnt notice I was dumping new vector3's everywhere in memory

keen dew
#

That's not a problem

ancient karma
#

Oh so that isn’t leaking memory?

keen dew
#

No, vectors are structs

ancient karma
#

Oh wait it goes out of scope every frame and I guess gets cleaned up

neon ivy
#

if I have a reference to a class with data and a variable with a new instance of that same kind of class.
is there a quick way to copy over the variables or do I have to set them one by one?
if I just set the new instance to the data it'll change the original data if I change variables in the instance which I don't want.

languid spire
neon ivy
#

cloning method it is, could just make a constructor that takes the class itself in as a parameter now that I think about it like that.

languid spire
#

remember you have shallow and deep copy options.
Shallow copy creates new primitives but leaves the references
Deep copy creates both new primitives and references

neon ivy
#

ahhh had to check the syntax rq, thanks UnityChanThumbsUp exactly what I need

stiff fjord
#

may sound stupid but how do i use oncollisioneenter2d too do smth like this

astral falcon
languid spire
#

Also, do NOT nest methods

astral falcon
#

Oh jeez, didnt even see that 😄 yeh, rare case of local nested methods 😄

languid spire
#

which is gonna be a problem seeing as temp is a local variaible, so basically the whole code is nonsense

stiff fjord
astral falcon
#

Maybe read, what Steve wrote abot NOT nesting methods like this

stiff fjord
#

ok

#

ty steve

languid spire
#

btw temp is a terrible name for a variable. Try to make your names meaningful

stiff fjord
#

just realised it should be a boolean too

fickle wagon
#

How can I scroll sprite renderer objects left and right like we use horizontal ScrollView for Canvas with images?

burnt vapor
#

Though usually you'd use an enum then (with more states)

stiff fjord
#

i got this although when i click lefthshift nothing is printed in the terminal

#

lol

#

didnt call it

weak cedar
#

What would be a smart approach to outline the edges of a polygon prism? Using a linerenderer or a shader

fossil drum
fossil drum
weak cedar
#

It does, I'll check it out ty

#

Any free wireframe shaders you know of?

eternal falconBOT
keen needle
#

https://gdl.space/efecorudiq.cs
I want to make a mechanic to clean objects. This code works on PC and when I connect the VR to the PC, but when I build it in the VR it doesn't do anything. any idea why it happens.

wraith phoenix
#

Is it feasible to use Unity's Animation Editor to flip sprites on the x-axis?
I rigged up a couple animations doing this but the 'flip x' stays engaged even when an animation is triggered where it has been turned off.
Seems like I need to flip x again but that doesn't really work in the animator.

Is this why I see most people flipping sprites with code rather than the GUI or am I doing something wrong?

keen needle
#

I don't know how to debug the VR build

teal viper
#

Also, should be able to attach the debugger.

fossil drum
weak cedar
#

Is there a way to see if I have correctly created two submeshes? I'm trying to set materials in the meshrenderer and it doesn't work, so I want to see if my submesh algoritm actually generates submeshes or not

verbal dome
#

Yeah here:

weak cedar
#

Yea it says I have two submeshes

#

Any way to see them seperately?

#

Or the mesh logic doesn't work like that idk

verbal dome
#

Not sure how to do that without assigning materials to a mesh renderer

#

You can show your mesh !code and I can take a look

eternal falconBOT
weak cedar
#

        int[] frontFaceTriangles = new int[(sides - 2) * 3];
        for (int i = 1; i < sides - 1; i++)
        {
            frontFaceTriangles[(i - 1) * 3] = 0;        
            frontFaceTriangles[(i - 1) * 3 + 1] = i * 2; 
            frontFaceTriangles[(i - 1) * 3 + 2] = (i + 1) * 2; 
        }

        mesh.subMeshCount = 2;
        mesh.SetTriangles(triangles, 0); 
        mesh.SetTriangles(frontFaceTriangles, 1); 

weak cedar
#

This code is supposed to seperate the front face and the rest into submeshes

fossil drum
# weak cedar Actual edges

Also, just FYI, unity has a wireframe view if this is not something you want to ship with your game, but just to debug.
Cause it seems like you are debugging things atm.

weak cedar
verbal dome
#

I have some wireframe shader in my project, IIRC it comes from some HDRP sample or something - I can take a look in a moment

weak cedar
#

Just FYI I don't want to see through my prism

#

I just want my prism's edges to be outlined/highlighted

verbal dome
#

See if you have this shader:

weak cedar
#

Is it see through

verbal dome
#

No

#

It does change color based on distance though, I didn't remember it does that

#

Yeah probably not useful since you can't really edit it

#

Could replace lines 132-134 with a solid color for the wire instead, since you don't need the distance-based coloring

jaunty obsidian
#

how can i solve cinemachine lag in 2d

jaunty obsidian
#

ok

hasty tundra
#

I need to reference the z rotation of an object in script, but whenever i try to it goes to a value between 0 and 1 instead of the value it is in the inspector. How do i get the inspector value instead

wintry quarry
slender nymph
# hasty tundra I need to reference the z rotation of an object in script, but whenever i try to...

what you see in the inspector are the euler angles, not the actual rotation. however you also don't typically want to use the euler angles for logic because they are interpreted from the quaternion that actually represents the rotation at the time you access them. you would be much better off manually tracking the rotation by keeping a float that represents the current Z rotation and read that and also use it to assign the rotation

wintry quarry
#

But yeah trying to get the inspector value is a bit of a fool's errand. It's better to use something like Vector3.SignedAngle, or track it yourself yes.

faint osprey
#
    {
        while(inMainSequence)
        {
            var heliumPush = Instantiate(Helium, UICan.transform);
            heliumPush.GetComponent<Rigidbody2D>().AddForce(Random.insideUnitCircle * heliumSpeed, ForceMode2D.Impulse);
            yield return new WaitForSeconds(heliumSpawnRate);
        }
    }```
im using this to spawn a sprite and then propell it in a random direction inside a unit circle however the problem is is that it doesnt launch at a consistant speed each time because it doesnt propell it in a random direction on a unit circles edge. so how would i fix that
slender nymph
#

normalize the Vector2 returned by Random.insideUnitCircle

faint osprey
raven hill
#

Hi, I'm trying to make camera rotate during a wallrun, but it always rotates towards one direction (presumably towards 0, 0)

#
private void Update()
    {
        CheckForWall();
        WallrunInput();
        if(Input.GetKey(pm.jumpKey)&&!pm.grounded&&pm.readyToJump)
            wallJump();

        if(isWallrunning)
        {
            playerCam.transform.localRotation = Quaternion.Euler(playerCam.transform.localRotation.x, playerCam.transform.localRotation.y, wallrunCameraTilt);
            orientation.transform.localRotation = Quaternion.Euler(0, 0, 0);

            if(Mathf.Abs(wallrunCameraTilt) < maxWallrunCameraTilt && isWallrunning && isWallRight)
                wallrunCameraTilt -= Time.deltaTime * maxWallrunCameraTilt * 2;
            else if(Mathf.Abs(wallrunCameraTilt) < maxWallrunCameraTilt && isWallrunning && isWallLeft)
                wallrunCameraTilt += Time.deltaTime * maxWallrunCameraTilt * 2;
        
            if(wallrunCameraTilt > 0 && !isWallLeft && !isWallRight)
                wallrunCameraTilt += Time.deltaTime * maxWallrunCameraTilt * 2;
            else if(wallrunCameraTilt < 0 && !isWallLeft && !isWallRight)
                wallrunCameraTilt -= Time.deltaTime * maxWallrunCameraTilt * 2;
        }
    }```
slender nymph
#

!code

eternal falconBOT
wintry quarry
#

you're putting a square peg into a round hole here - it's meaningless.

#

rotation and localRotation are quaternions, they are not euler angles.

turbid rain
#

hi, if anyone has spare time can you help me while I'm sharing the screen?

slender nymph
#

you would be much better off just !ask ing your question here and providing any relevant screenshots/videos instead of expecting someone to privately help you with a screen share

eternal falconBOT
lapis frigate
#

!code

eternal falconBOT
lapis frigate
#

https://gdl.space/acipatosul.cpp
https://gdl.space/menawuqowu.cpp
Yo, I have these 2 codes, the top 1 is basically the Unit for the stats and numbers for the player and the enemy and the bottom is the battle system script for my turn based combat game, I'm trying to write each enemy a diffrent behavior in a unique script but I dont know where to start. any help?

#

like I just need some guidence to how I start

teal viper
lapis frigate
#

how do I code a unique behavior to each enemy

#

Like I have the enemy prefab

#

and all the diffrence I can make between each enemy is the stats numbers

#

via script component

teal viper
lapis frigate
#

I mean, I have no expirience with AI at all but the thing is I'm not sure how do I even change the enemy's stats from the other script

#

like If I want to create new attacks / skills for them. I dont know how to attach them

frosty hound
#

You need to actually know how you want your AI to behave, in plain english, before you can start actually figuring out how to create it.

teal viper
teal viper
lapis frigate
#

I just want to know how do I change their behavior manualy before I get into AI

lapis frigate
#

For example I have this enemy prefab and I added a goblin script, and lets say I want him to heal every time he gets lower than 50% hp

#

or like just have to options and choose at random

#

I just want to learn how to do that before I get into AI in general

teal viper
#
if hp < maxHP * 0.5f
  heal

At the very basic level, something like that. It's all very basic coding.

lapis frigate
#

yes I know but I mean like

#

I want it to be diffrent for each enemy

#

and I dont know how do I do that in diffrent scripts

teal viper
ivory bobcat
#

Have different scripts do different things?

teal viper
lapis frigate
#

how do I attach the behavior from that script to the battle system

ivory bobcat
#

Reference the goblin script from the battle system script and do whatever you're needing to do with it.

teal viper
lapis frigate
#

its like the battle manager

teal viper
#

What does it do?

lapis frigate
#

it controls the state of the battle like who's turn it is and what options do I have

teal viper
#

And what's it's relationship with the ai behavior?

lapis frigate
#

and it has a few method for player skills

teal viper
#

And what's it's relationship with the player?

#

You realize, that we can't help you with things specific to your project, unless you provide details on them?

lapis frigate
#

and its contains the methods for the enemy's and the player's turn

#

and what happens in those turns

teal viper
#

Then call the enemy's methods. And each enemy behavior script would provide a different implementation. As easy as that.

lapis frigate
#

Lets say I want to create inside the goblinScript an EnemyAct method that inside that method is what is the enemy is going to do in its turn

teal viper
#

Make Unit a base class, and implement it for different behaviors. For example public class GoblinUnit: Unit. Each of such classes would implement their own TakeDamage and HealHP behaviors.

lapis frigate
#

how can I attach it to the battle system without refrencing the code

teal viper
lapis frigate
#

I mean

#

if i'll have like 100 diffrent enemies I'd have to refrence a 100 differnt behavior codes?

#

and even if I do that how do I know which behavior method do I choose?

#

a 100 if statements?

teal viper
teal viper
burnt vapor
#

Only the different enemy types would need a new script. That's very normal for a game

teal viper
teal viper
lapis frigate
#

what is oop

teal viper
#

Object oriented programming. Or Object oriented design.

lapis frigate
#

can I get all of the enemie's script in an erray?

#

then just like use the one i need each time?

teal viper
#

No. You probably shouldn't do that.

lapis frigate
#

like a library i think its called

teal viper
#

Learn oop, and you'll see how easy it is to solve your problem.

faint osprey
#

what is the refrence to Pos x i cant find it

lapis frigate
teal viper
# lapis frigate tbh I dont think u still completly understand me but maybe there is something I ...

I do understand you completely.
In your battleManager you'll have something like:

IEnumerator EnemyTurn()
{
  foreach( Unit enemy in enemies)
    enemy.Act();
  //....

Then you'll have a base Unit class:

public abstract class Unit
{
  public abstract void Act();
}

Then you'll have many derived classes, for example:

public class Goblin : Unit
{
  public void Act()
  {
    //goblin turn logic
  }
}

And for example another different behavior:

public class GoblinHealer: Unit
{
  public void Act()
  {
    //goblin healer logic
    //heal it's alies
  }
}
lapis frigate
#

aight then I'll stick to that example just need to learn wha foreach and abstract class are

teal viper
#

I'd suggest going over the C# basics, if you don't know what these are, before trying to continue your project. You can't get far if you don't know how to code.

lapis frigate
#

all i know about c# is from school

midnight meteor
#

hello , can i add a box collider to a UI image ? and then use onmousedown ?
i don't wanna use buttons

lapis frigate
#

which isn't the best way to learn I guess

teal viper
lapis frigate
#

I guess you are right

#

The fact I got pretty good grades in my finals and still dont not shit about c# means something

faint osprey
#

how do i refrence Pos X of rect transform

lapis frigate
#

maybe about me or maybe about school idk

midnight meteor
bronze token
#

hi, im trying to learn and implement ml agents in unity
so does it matter if my pythons version is 3.12 whereas the ml agents documentation stresses on the fact that i should have 3.10.12 instead?

#

i just wanna confirm

teal viper
# lapis frigate maybe about me or maybe about school idk

Honestly, you don't need school to learn programming and/or gamedev. And just learning at school is not enough to make you a programmer/gamedev. The most important quality of a dev is being able to constantly learn and improve yourself.

teal viper
teal viper
teal viper
midnight meteor
teal viper
midnight meteor
#

will learn more about it then

#

thank you

teal viper
#

Though, if it's for mouse interactions with scene objects, I'd still raycast manually from a script, just to have more control over it.

midnight meteor
#

i tried using raycast but honestly too complicated for my 2 brain cells
so i just been using box colliders + onmousedown

faint osprey
#

can particle systems block buttons from being clicked

teal viper
#

Are these UI buttons? Is the particle system parented to the canvas and has graphic component/s?

faint osprey
teal viper
rough venture
#

Here's a question. I've heard that Physics.CheckSphere is bad. is Physics.OverlapSphere and Physics.SphereCast bad too?

verbal dome
#

None of those are 'bad'. They all do different things

rough venture
#

I remember hearing something about it looping through all colliders in the scene. Is that true?

verbal dome
#

CheckSphere when you need to know if anything is hit, but don't care what it is
OverlapSphere when you need to know each collider that was hit
SphereCast is just a thick raycast

verbal dome
rich adder
verbal dome
#

There's some spatial structure that allows the engine to only check for nearby colliders

rough venture
#

Wow, okay. I've been scared of 3D for no reason then...

rich adder
#

not surprising , premature optimizing kills any project early

rich adder
# rough venture Wow, okay. I've been scared of 3D for no reason then...

one thing to note , for the Ovelaps or the ones that return more than 1 result then you absolutely should be using the nonalloc version of it.
The performance gain is actually incredible if you saw the profiler, ofc allocating a new array is more expensive than having a fixed one ready to go

rough venture
rich adder
#

correct

rough venture
#

Alright. I can't seem to find one for SphereCastAll. Only a nonalloc for SphereCast

rich adder
#

thats cause if its non-alloc its returning usually multiple ones

#

thats the whole point of prefixing the array with length as field

#

SphereCastNon alloc is SphereCastAll without alloc lol

#

basically you would declare how much you want allocated for example
private RaycastHit[] results = new RaycastHit[30]; // 30 is plenty for some use cases or even less

#

some non-alloc will want to declare them as Collider[] instead, always check the docs

#

they always return an int aka the amount actually found

rough venture
#

Thank you so much for the great explanation

#

One last thing though 😅 If the player (blue) does a spherecast at its position, will the read object hidden behind the green wall be registered? or what?

rich adder
#

yes

#

you would do an additional raycast to check if between you and red is wall

#

oh nvm that you said spherecast not overlap

#

it works just like a ray (a thicc one :P)

#

it will hit wall and stop

rough venture
#

Ah, alright. I was wondering about that

#

So overlapsphere if I want all colliders within the sphere?

rich adder
#

yeah overlaps I usually use for "whats around me" then check for wall blocking visions with ray

#

or maybe an explosion, etc

rough venture
#

Perfect. Thanks once again. I feel ready to get to work

rich adder
#

np. goodluck 🫡

woven crater
#

can you have multiple curve in a single animation curve object?

rich adder
#

naw

woven crater
#

👌okay

cosmic dagger
#

no react gifs . . .

woven crater
#

okay 👌

scenic saffron
#

how else do i compare vectors?

rich adder
#

anyway compare the magnitude

echo ruin
#

Hello. I have added a movementDisabled bool to my Player Movement script, so that I can disable the movement in certain coroutines. It works if I set it to private, however, I need it to be public, so that it can be used by other scripts, but when I make it public, it gets overridden in the inspector, and I can't use it as intended. What do I do?

scenic saffron
steep rose
rich adder
#

thats like saying classA < classB . Its nonsense

scenic saffron
#

so i have to compare each number on their own?

rich adder
#

that or the magnitude

#

cc.velocity.magnitude < myV3.magnitude

#

sqMagnitude is prob more performant

#

depends what you're comparing too, if its distance or something there is V3.Distance etc

#

or you can do
var myNumber = 3f
cc.velocity.sqrMangitude < myNumber * myNumber

stuck palm
#

why does bool point to the Boolean class? is there a way i can make my own classes do something like that too?

rich adder
stuck palm
#

no idea why its saying dark souls LOL

rich adder
stuck palm
#

just wasnt sure how to google that question

#

thats interesting

#

not sure why you'd do that but

#

can you use a variable name as a variable?

rich adder
#

like
int x = 10;
x somethingElse = 3; ?

dont think c# allow that no

stuck palm
#

seems to let it happen

hollow field
#

Is there an easyway to get the specific key pressed?

stuck palm
#

this seems to work?

hollow field
#

@verbal dome I have googled and I cant find anything

rich adder
hollow field
rich adder
hollow field
#

thats not what I asked

#

I want to know what key is being pressed

#

I dont want 100 if statements for every key input

#

Is user pressing a key? yes -> get the key they pressed

rich adder
#

you have to loop through the keycodes and see which one was pressed, its not diffcult

#

making if statement for each one is not smart

languid spire
fickle plume
#

This is how to handle it with old Input system. If you want to just get any key input use new one

stuck palm
#

how does unity create the nameHash for animator states?

rich adder
stuck palm
verbal dome
#

I wonder if Input.anyKey + Event.current.keyCode works

stuck palm
#

i was going to try and use the same hash system to generate the same IDs

final pelican
#

I'm slowly but surely getting the hang of what to do for the board but I'm having 2 problems. The player won't go to certain nodes that are neighbors to the one they are next to sometimes and the player won't move the given dice roll but can only move one space at a time as well as the debug shows it twice with one right and the other not what was shown on the die. How do I fix these problems?

https://gdl.space/uyaviwuzoh.cs (Dice)
https://gdl.space/iciniralem.cs (Pathfinding)

wintry quarry
#

if those neighbor nodes aren't randomly chosen, then it won't let them go there

#

isn't that intentional?

final pelican
wintry quarry
#

GetPossibleMoves is doing that. The nodes are chosen randomly in GetNextNode

lofty sequoia
#

Been trying to print out the correct Type that a script is in a custom editor, but it prints the type as monoscript or something other than the correct type. Is there a way to drag in a script and print out its type?

I'm using sourceGameObject = EditorGUILayout.ObjectField(sourceGameObject, typeof(UnityEngine.Object), true);
where sourceGameObject is a UnityEngine.Object.

final pelican
wintry quarry
#

No idea why you're doing any randomness there

final pelican
rich adder
stuck palm
wintry quarry
#

In fact the whole way you're using the dice roll in that function also doesn't make sense

rich adder
#

that static method is external to cpp backend (StringToHash)

final pelican
stuck palm
wintry quarry
#

The actual spots you can move next have nothing to do with the dice roll

#

unless I'm missing something

#

Not sure I understand what you're going for here

rich adder
final pelican
stuck palm
rich adder
#

without it, there is no way to replicate it lol

errant pilot
#

Guys why does my debug give a nullreferenceexception?

wintry quarry
#

The actual handling of how many times the playe can move should be separate

rich adder
wintry quarry
short hazel
#

Yep it is, which means StartAttack was called before Start

errant pilot
rich adder
#

how do you know start is running in the first place?

short hazel
#

If the exception points to the Debug.Log line, it's the only thing that can be null

final pelican
rich adder
# errant pilot ? 😭

put a log inside start, then put a log before the log with the dictionary. See which one runs first

kindred marsh
#

Dont understand the error

rich adder
rich adder
errant pilot
rich adder
errant pilot
#

start
then second
then null

short hazel
#

Post the full exception message, make sure to include the stack trace with it

languid spire
errant pilot
errant pilot
#

i debugged all i can

#

its all Peck

rich adder
#

always write that in the log next time
Debug.Log($"attack value {attack} ")

#

never assume

short hazel
#

Log: attackMethods != null and attackMethods[attack] != null. Make sure it logs as true for both

languid spire
#

Also, when debugging, output some actually useful information, not just strings

errant pilot
#

This gives me a nullreferenceexception?

#

wtf 😭

short hazel
#

You need &&

rich adder
#

use &&

#

this way if first one fails, it doesnt run second

short hazel
#

So it means attackMethods is null, if yours throw

errant pilot
#

now its false

#

so the second is the problem

short hazel
#

Either

rich adder
#

your Action is null ?

errant pilot
#

my action is a method thats written

short hazel
#

Please use two separate logs, so the values are differentiated!

errant pilot
short hazel
#

Yes

errant pilot
#

Debug.Log(attackMethods[attack] != null);
this gives me the error

short hazel
#

And the first log? Gives you false or true?

errant pilot
#

Action means method no?

errant pilot
short hazel
#

Okay so the dictionary is null

errant pilot
#

but i initialise it no?

#

and i give it values in start

#

and it runs

short hazel
#

Yes but you call Attack on something that did not run Start

errant pilot
short hazel
#

ie. Your other script is referencing the wrong instance

languid spire
#

you are not calling the method on the prefab rather than the instance are you?

short hazel
errant pilot
#

lemme check

#

guys im more than sorry i swear 😭

#

i named the variables in a similar i got confused

#

thank you so much my bad!

tall girder
#

Hi could you help me with unity 2d game.. I want to make a pause menu on all scenes but its no react on "ESC" or if the pause menu show the button making a blank background XD

#

i make prefabricate pausemanager where i added a script with dont destroy gameobject

#
{
    public static bool gameIsPaused = false;
    public GameObject pauseMenuUI;
    public static PauseMenu instance;

    private void Start() 
    {
        instance = this;
    }
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Escape))
        {
            if(gameIsPaused)
            {
                Resume();
            }
            else
            {
                Pause();
            }
        }
    }

    public void Resume()
    {
        pauseMenuUI.SetActive(false);
        Time.timeScale = 1f;
        gameIsPaused = false;
    }

    void Pause()
    {
        pauseMenuUI.SetActive(true);
        Time.timeScale = 0f;
        gameIsPaused = true;
    }

    public void LoadMainMenu()
    {
        // SceneManager.LoadScene("MainMenu");
        SceneManager.LoadScene(0);
        Time.timeScale = 1f;
    }

    public void QuitGame()
    {
        Debug.Log("Quitting Game...");
        Application.Quit();
    }
}
stuck palm
#

is there a way to get the fields of a class as a variable?

#

like a list or something

rich adder
rich adder
polar acorn
#

Instead of all of those

rich adder
#

ah yes dictionary thinksmart

stuck palm
rich adder
stuck palm
#

apparently you can achieve it with reflection

wintry quarry
wintry quarry
#

There are much better ways

stuck palm
wintry quarry
#

I guess for editor script it's different

wintry quarry
#

Unity already does the reflection. Can you use the SerializedObject api?

stuck palm
stuck palm
wintry quarry
real merlin
#

i've got a really stupid beginner problem
so i'm trying to make my stupid capsule jump with this code :

public class playerMovement : MonoBehaviour
{
    public Rigidbody rb;
    public Transform ptransform;
    [SerializeField] float xspeed = 1f;
    [SerializeField] float zspeed = 1f;
    [SerializeField] float jumpforce = 1f;
    

    private void FixedUpdate()
    {
        rb.velocity = (Input.GetAxis("Vertical") * xspeed * ptransform.forward.normalized) + (ptransform.right.normalized * Input.GetAxis("Horizontal") * zspeed);
        rb.AddForce(0f, jumpforce * Input.GetAxis("Jump"), 0f);
    }
}

the jump works alright i guess but the problem is that when it falls, it falls really slowly, i get what the problem is, setting the velocity to whatever that thing the y velocity 0 every update, so gravity doesn't do it's thing properly, but i really don't know how to get around it i could use some help on that

wintry quarry
#

and use that as the new velocity

polar acorn
#

Store that input bit in a Vector3, then set that vector's Y value to the current velocity, then set velocity to that vector

real merlin
#

oooooh

#

that's smart thank you so much

brave turtle
#

what's the significance of Unity's Object, Component, Behavior, MonoBehavior, and ModelPlug to each other?

brave turtle
#

oh maybe that pertains to something more specific

wise spoke
#

Is it possible to color a sprite in an only one color?

short hazel
wintry quarry
#

And the main question... is a bit vague. IDK how to answer it.

brave turtle
#

ya ignore that. it's a custom class for attaching objects together

#

i see a lot of MonoBehavior being used, but the higher hierarchy classes are unclear to me

wintry quarry
#

Object is the base class for every managed Unity object, including all of the above and more

short hazel
brave turtle
#

alright i'll read that

stuck palm
wintry quarry
stuck palm
#

whats PPtr

rich adder
stuck palm
#

same for poth

#

both

#

its a pointer apparently?

wintry quarry
stuck palm
#

also an asset object

wintry quarry
#

ok this must be related to some special handling uNity does for UnityEngine.Object reference fields..

#

Maybe if you do:

property.objectReferenceValue.GetType()``` ?
stuck palm
#

it works now though! so thats what matters

#

i dont like using AI but for editor scripts i dotn really midn

wintry quarry
#

Well what does GetFieldType do

stuck palm
#
private Type GetFieldType(SerializedProperty property)
    {
        // Get the type of the property from the SerializedObject
        // We use reflection to get the type of the field in the MoveList
        var moveListType = selectedMoveList.GetType();
        var fieldInfo = moveListType.GetField(property.name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy);
        return fieldInfo?.FieldType;
    }
wintry quarry
#

I see

#

yeah reflection on the enclosing type

#

Which kinda defeats the purpose of using SerializedObject etc but whatever

brave turtle
#

so Object exists for Unity to acknowledge a given object in the inspector?

stuck palm
#

even if its dirty and i didnt make it myself 😅

wintry quarry
brave turtle
#

i'm guessing the rest pertains to low level business between C# and C++?

wintry quarry
stuck palm
#

how can you serialise a dictionary?

wintry quarry
stuck palm
#

i forgot to do that

#

will do

stuck palm
#

can you put dictionaries in a scriptable object?

#

i have tried, but i have no way to check if its working or not

rich adder
#

they're just regular classes, nothing special about them

stuck palm
#

because it doesnt show up

rich adder
#

you can use 2 structs to iterate through it or add something and do .count

slender nymph
#

unity cannot serialize dictionaries, you'll need to use a custom solution if you want a dictionary to be visible in the inspector

wintry quarry
#

and they will work on a ScriptableObject

#

and in any case - wdym by "there's no way to check if it's working or not"

#

The inspector is just the inspector

#

things still exist if they're not in the inspector

stuck palm
wintry quarry
#

You don't need to put it in the framework's assembly

#

put it in your code

#

don't modify the framework

stuck palm
#

okay i'll tryy that

wintry quarry
#

you should almost never be modifying the libraries and packages you're using

tired grove
#

I have a dumb problem, I'm using this code to procedurally animate my character and so far it works and looks normal, but I want the legs to move over to where they're supposed to be instead of snapping over like how this code makes them do. Tried using rightleg.translate(Vector2.right) but that just moves the bone downwards instead of to the right, and also i dont know how to add my stepdistance variable to that

verbal dome
#

You could just Vector3.MoveTowards to move it over time

#

For example, for each foot you could have an empty object (or a predefined Vector3) that marks the resting position of that foot

#

Then you can do leftLeg.localPosition = Vector3.MoveTowards(leftLeg.localPosition, leftLegRest.localPosition, Time.deltaTime * someSpeedMultiplier)

tired grove
#

Got it, thank you

blazing mauve
#

can sp,e

eternal falconBOT
frigid schooner
#

I am trying to config my vscode to unity, I followed the website, downloaded the package but it doesnt seem to work

frigid schooner
rich adder
#

there are other steps

#

also you should remove the old Visual Studio Code Editor one

frigid schooner
#

its just this no?

rich adder
#

remove this one, make sure you select the correct vsc version in external tools

#

close vsc and regen project files after

frigid schooner
#

it says cant remove bc other installed package or features depends on it

#

Inside dependencies, it says used by Engineering

rich adder
#

remove it

frigid schooner
#

what does the engineering package do

rich adder
#

it installs all those packages for each IDE

#

if it removes the visual studio editor one too add that one vs package again

inner quartz
#

Hello everybody, please help me, how to make an optimize code of text update? I also have a data loading system, where dictionary or static variables are can't be used. I think I need delete all this code... It looks so bad...

inner quartz
# polar acorn What is the problem with it?

I do not know how to combine the code. I used to have a container that my text display worked well with. But after adding a new system for loading and saving data, I had problems with this script, since the container can no longer be used, and the script itself, where my currencies are stored, cannot act as a container

rich adder
#

pretty sure unity/vs should warn you about that

#

use awake instead

inner quartz
rich adder
#

MonoBehaviours or UnityEngine.Object derived objects are handled by unity already hence Awake for initialization purposes

frigid schooner
#

tried multiple times, shows this message

slender nymph
#

did you install the .net SDK then restart your computer?

amber spruce
#

how can i check if the collision for ontriggerenter2d is in a certain layermask

slender nymph
amber spruce
#

k thanks

#

hey so i want to make game difficulty for my game and im guessing enums might work but i havent really used enums before do they only provide a list or can i set a enum to one of the choices?

teal viper
amber spruce
#

so how exactly would i use it to store what difficulty the game is currently at?

#

ah nvm i think i see

teal viper
amber spruce
#

yeah i just checked them lol

torpid snow
#

PLEASE HELP MY CAMERA IS INVERTED (LEFT MOVES RIGHT, RIGHT MOVES LEFT, ETC.)

#

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

public class PlayerCam : MonoBehaviour
{
public float sensX;
public float sensY;

public Transform orientation;

float xRotation;
float yRotation;

// Start is called before the first frame update
void Start()
{
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
}

// Update is called once per frame
void Update()
{
    //Get mouse input
    float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
    float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;

    yRotation += mouseX;

    xRotation += mouseY;
    xRotation = Mathf.Clamp(xRotation, -90f, 90f);

    //Rotate cam and orientation
    transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
    orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}

}

slender nymph
#
  1. !code
  2. don't multiply mouse input by deltaTime, that is wrong because mouse input is already framerate independent so doing that multiplication just makes it dependent on the framerate again and leads to inconsistent and stuttery camera controls
  3. if the horizontal rotation is inverted then just subtract instead of add . . .
eternal falconBOT
torpid snow
#

How do i do that third thing (Mind you ive been following a tutorial so i am taking in about half of this info)

slender nymph
#

- instead of +

torpid snow
#

Alrighty so my vertical is now working all good, but the horizontal is still backwards..??

slender nymph
ancient karma
#

#💻┃unity-talk message In regards to this,

    private void OnCollisionEnter(Collision collision)
    {
        //remove bullet
        Object.Destroy(gameObject);

        //deal damage
        if(collision.collider.CompareTag("Hurtable"))
        {
            collision.gameObject.GetComponent<HealthController>().hurt(damage);
        }
    }

this is what I have for handling hitreg

ancient karma
#

rigidbody with an initial velocity, continuous collision detection

#
    public void Fire()
    {
        if (lastShotTime == 0 || Time.time > (lastShotTime + (60 / fireRate))) {
            Rigidbody newBullet =  Instantiate(bullet, transform.GetChild(1).position, Quaternion.identity);
            newBullet.GetComponent<BulletScript>().setDamage(damage);
            newBullet.velocity = transform.forward * velocity;
            lastShotTime = Time.time;
            roundsRemaining--;
        }
    }

this is the code that handles that

steep rose
#

how fast are you shooting this rigidbody

#

and how small is it

#

from what im seeing, that looks like raycast bullets (from how fast they are going)

ancient karma
#

default capsule size, and by how fast do you mean how often or velocity?

swift elbow
#

velocity

ancient karma
#

80f

#

That might be insanely fast, I havent really figured out how to tune it into a good value

steep rose
#

are you calling Fire() in Update()?

ancient karma
#

Yes

#

or, kind of

steep rose
#

put it in FixeduUpdate()

ancient karma
#
    void Update()
    {

        if (Input.GetMouseButton(1))
        {
            RaycastHit hit;
            Ray ray = camera.GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                this.transform.LookAt(hit.point);
                activeWeapon.transform.LookAt(hit.point);
                aimLine.enabled = true;
                aimLine.SetPosition(0, activeWeapon.transform.GetChild(1).position); //x,y and z position of the starting point of the line
                aimLine.SetPosition(1, (hit.point + new Vector3(0,0,0))); //x,y and z position of the end point of the line
            }

            if (Input.GetMouseButton(0))
            {
                attack();
            }
        }
        else
        {
            aimLine.enabled = false;
        }
    }

    void attack()
    {
        activeWeapon.GetComponent<WeaponScript>().Fire();
    }
steep rose
#

put attack() in FixeduUpdate()

#

you put all rigidbody related items in there

#

since it is on the physics update

#

and it is also framerate independant

ancient karma
#

I should probably also do that with my player controller too right, since its rigid body forces

steep rose
#

so 80f is actually more like 1000f due to Update being frame dependant

ancient karma
#

oh lordy

#

I see now

steep rose
#

and it will change on how much or how little your framerate is

amber spruce
#

hey so for my game i want to proceduraly generate the levels so i can make it endless and the game is basically there are squares you can grapple onto to swing and every once and a while there are walls and im really not sure how i can make it so the squares and walls are generated via code.
here is a image of what a hand made tiny portion of a level for testing looks like

deft grail
#

and X within the cameras view

amber spruce
#

yeah but how would i do that 1 endlessly and 2 how do i deal with making them because i dont want to have it like 1 is made every second because if you go to fast then some might not form but if i just have them go without a cooldown the whole screen eventually will be full of them

deft grail
#

so they are always visible to the player if he goes forwards

amber spruce
#

like i dont want it to just generate 1 every x amount of time

deft grail
amber spruce
#

ok

surreal pecan
#

Im making a spaceship that shoots (prefab) bullets (Bullets is named Cannon)

frosty hound
#

I always wonder why people never acknowledge the answer, but have no trouble being redirected to another channel.

surreal pecan
#

but... how do you do this without showing it in the scene???

frosty hound
#

I don't know what you're talking about. The issue is you have no object in your scene called Cannon, yet you are GameObject.Find("Cannon")....

#

It's not finding it, thus it's throwing an error when you try to GetComponent<Transform>() off of a non-existent object.

frosty hound
#

That has nothing to do with your error

#

If you're following some tutorial, I suggest doing it properly?

surreal pecan
frosty hound
#

Link this tutorial

covert owl
#

so im following this CodeMonkey guy on youtube and i get this error and i dont know why?

deft grail
#

you cant do that

covert owl
#

did it used to work like that?

deft grail
#

the tutorial either doesnt use private or make this Vector3 method outside

deft grail
cosmic dagger
cosmic dagger
covert owl
#

i did, i put it side by side and notthing is diffrent

deft grail
#

screenshot the tutorial code if you can

cosmic dagger
covert owl
deft grail
#

notice the brackets {}

cosmic dagger
covert owl
cosmic dagger
#

look at the open and closing braces . . .

deft grail
cosmic dagger
covert owl
#

ohhhhhhhhhhhh

cosmic dagger
#

literally look at the code line-by-line . . .

#

don't just assume it's the same; actually check . . .

covert owl
#

i did

#

im just a blind idiot

covert owl
#

just in case, does anyone have a tutorial on Grid Making, like the kind for building placing for 2D?

steep rose
#

is that not what you are doing?

covert owl
#

It is, I just like to look at other ways it's done and find use the ones I thinks is better

rich adder
covert owl
rich adder
steep rose
#

dunno who "Tamara" is

covert owl
#

I looked it up and the most prominent thing that popped up was "Tamara Makes Games" YT channel

steep rose
#

okay

half gulch
#

hey guys, quick (probably) question, here's a little snippet of code, line 11 is never hit, and I'm a little confused as to why it would just be skipped over, I'd really love if someone could give me some insight https://hastebin.com/share/xuzoqokupu.csharp

wintry quarry
eternal needle
half gulch
#

my bad, this is assuming line 10 is hit

wintry quarry
#

The other possibility is that line 10 is throwing an exception

half gulch
#

and line 10 is fine

wintry quarry
#

Then line 11 is also running

#

You're mistaken

#

Add another log after it to prove it to yourself

half gulch
#

ah, you're right, I do have an error, I just didn't notice because when I debug from hooking Visual studio normally the error also pops in visual studio, since I can't alt tab to unity, interesting how that works

#

Thanks for the tip

bold nexus
#

how to fix it

#

thnk for eveeryone

wintry quarry
#

it's telling you how to fix it right in that message.

queen adder
#

Is there a way to check if a mesh collider fully engulfed another collider?

wintry quarry
#

If they are all contained, you can say it's "fully engulfed"

#

it's not perfect - but a good estimate

queen adder
#

yea, im currently doing that, just transforms that does pointoverlaps (raycast with no direction)

wintry quarry
#

raycast won't work

queen adder
#

but it feels ugly

#

why?

#

is it different in 3d?

wintry quarry
#

Yes

#

Notes: Raycasts will not detect Colliders for which the Raycast origin is inside the Collider

queen adder
#

oh I see

wintry quarry
queen adder
#

Dont know that one

wintry quarry
#

But yeah for 3D to check for a point overlap you would do this:

bool PointOverlapsCollider(Collider c, Vector3 point) {
  Vector3 closestPoint = c.ClosestPoint(point);
  return closestPoint == point;
}```
#

This takes advantage of the fact that ClosestPoint will return the same point we input if it's inside the collider

ancient karma
#

I'm a bit confused on manipulating translations in relative space through code. I'm trying to make a sliding door, this is the code I've got.

    private bool sensorActive = false;
    [SerializeField] private GameObject leftDoor;
    [SerializeField] private GameObject rightDoor;
    private Vector3 leftDoorTarget;
    private Vector3 rightDoorTarget;
    public float openSpeed = 2f;

    // Start is called before the first frame update
    void Start()
    {
        leftDoorTarget = leftDoor.transform.position;
        rightDoorTarget = rightDoor.transform.position;
    }
    // Update is called once per frame
    void Update()
    {
        leftDoor.transform.position = Vector3.Lerp(leftDoor.transform.position, leftDoorTarget, Time.deltaTime * openSpeed);
        rightDoor.transform.position = Vector3.Lerp(rightDoor.transform.position, rightDoorTarget, Time.deltaTime * openSpeed);
    }

    void openDoor()
    {
        leftDoorTarget = leftDoor.transform.position + new Vector3(0, 0, -2);
        rightDoorTarget = rightDoor.transform.position + new Vector3(0, 0, 2);
    }   
    void closeDoor()
    {
        leftDoorTarget = leftDoor.transform.position + new Vector3(0, 0, 2);
        rightDoorTarget = rightDoor.transform.position + new Vector3(0, 0, -2);
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player")) {
            sensorActive = true;
            openDoor();
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if(other.CompareTag("Player"))
        {
            sensorActive = false;
            closeDoor();
        }
    }

That seems to translate it on the global Z axis though. I've been looking at the docs on TransformDirection but I dont understand how it gets used

#

local Z axis should be the correct direction to open in always since its relative to the parent, if I understand that correctly

wintry quarry
#

It's assigning a value to some variables you have

#

And it's using world space positions to do so

ancient karma
#

whoops, forgot some context

wintry quarry
#

You should show the rest of the code

wintry quarry
#

If you want to move objects relative to their parents you would use localPosition instead of position

ancient karma
#

ah! thats what I was missing

#

yup, went to that and it works perfectly

#

I was looking at all sorts of transform methods and stuff. What a simple solution. Thanks for the help

eternal needle
ancient karma
#

Thats a good idea. I just did something similar for the close position because I found that it didn't fully close if I entered and exited the trigger repeatedly too quickly

fringe plover
#

I dont understand how SmoothDamp works, when i set speed to 100 its very slow, but when i set speed to 0.01f its really fast

shell matrix
#

hello, i have a issues, and somebody help me saying to put the script on game-object, but i put it

eternal falconBOT
astral falcon
#

I guess, using a custom material with render queue being above should do the trick?

rotund garnet
#

is there some way to still have these in my code? - they are just for a debug log, to visualize output from my code...

#

when i "Ctrl + s" i get this:

astral falcon
faint sluice
rotund garnet
#

would that work?

primal jewel
rotund garnet
primal jewel
#

C# compiler generally likes UTF-8-encoded source files, so saving as UTF-8 would be fine.

resave this file as Unicode in order to maintain your data

#

Just "Unicode" is ambiguous, could mean UTF-8, UTF-16, etc.

astral falcon
#

Sometimes platforms can cry about it too, when you switch between win and mac or something, but if you are workin on your own anyways, you can just convert them

primal jewel
#

Line endings are a different matter

astral falcon
primal jewel
#

Encoding issue is orthogonal to platform's line ending preference

vale geyser
#

so after reinstalling my editor I still have the same errors:

slender nymph
magic panther
#

I have this weird issue with sprite scrolling. This script works perfectly fine, besides the Awake function. In it, it's supposed to set a random initial value to the scroll of any axis where it's intended, as in set in the public imageScrollSpeed variable. The value changes to what it should, even while incrementing it, but the offset is not applied, only the small changes in the Scroll function. Why is this happening?
Class

astral falcon
deft grail
#

not sure if thats what you want, probably not

magic panther
#

wait

#

I'm stupid, this only returns integers, so I can't see it working

#

my bad yall

deft grail
magic panther
#

yeah, now it works

#

thanks tho :)

wraith sequoia
#

I am importing 3 textures. Since I am doing this, pressing the play button takes much longer and is stuck on "Importing assets" (like 15-20 seconds each time)
Does anyone know what the reason for this might be?

languid niche
#

do you guys know a solution to this unity tutorial, i have done all the fixes but the spin script is not working the bomb and the coin are orbiting around something, the same script is working fine on baloon though

deft grail
cerulean tulip
#

What are directions?