#💻┃code-beginner

1 messages · Page 842 of 1

radiant voidBOT
rich adder
#

screenshots wise you can show inspector of which object has this script

cosmic sable
#

ohh mb

solar hill
#

how are you assigning projectileFood?

#

are you dragging it in from the scene or from your project folders?

cosmic sable
#

it's on the player, whenever I press space it spawns and move forward

rich adder
#

ima guess projectileFood is dragged from scene

solar hill
#

you have a public field in the inspector

#

on that script, the "projectileFood" field, are you dragging the banana or whatever from the scene hiearchy, or from your project folders

cosmic sable
#

the hierachy i guess

rich adder
#

you're working with a clone that eventually gets destroyed

#

cloning a destroyed objects isnt good lol

solar hill
#

if it is, drag it from the project folders, instead of hiearchy

#

if not, make it one, and then do that

cosmic sable
#

oh yeah, I tried using the object from the prefab in project not from the hierachy and it fixed it

#

damn

#

thanks

#

🙏

neat prairie
#

nah, just generally in terms of the input receptiveness; I don't have a "debounce" timer for jumping

naive pawn
#

you typically don't need to debounce single discrete inputs

left jacinth
#
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Timeline;

public class Meteor : MonoBehaviour
{
    public Rigidbody rb;
    public GameObject splash;
    private Vector3 pos;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    private void Awake()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        rb.linearVelocity = new Vector3(0, -10, 0);
    }

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.name == "Player")
        {
            ScoreTracker scoreTracker = ScoreTracker.Instance;
            Destroy(collision.gameObject);
            scoreTracker.gameOver();
        }
        else
        {
            GameObject s = GameObject.Instantiate(splash);
            splash.transform.position = gameObject.transform.position;
            ScoreTracker scoreTracker = ScoreTracker.Instance;
            scoreTracker.addScore();
            Destroy(gameObject);
        }
    }
}

for some reason this code is instantiating the splash to a random location instead of where the meteor lands

rich adder
#

oh wait

left jacinth
#

i could just lock rotation to check that

rich adder
#

you're setting the position of the prefab/object splash not the new instance doh

left jacinth
#

yeah i need to make the splash appear where the meteor touches

rich adder
#

you have to set s not splash

left jacinth
#

ah

solar hill
#

s.transform.position

naive pawn
#

you can also set the position directly within the Instantiate call, btw.

left jacinth
#

works now, thanks

left jacinth
naive pawn
#

what was the error?

left jacinth
#

let me recreate it

#

cannot convert Vector3 to UnityEngine.SceneManagement.Scene

GameObject s = GameObject.Instantiate(splash, gameObject.transform.position);

naive pawn
#

recheck the signature you're using. if you supply the position, you also have to supply rotation

left jacinth
#

alright

polar acorn
#

Find ones that list position, and see what else you need to include as well

naive pawn
#

for "no rotation", you can use Quaternion.identity.

left jacinth
#

this is more complicated than just moving after instantiating

naive pawn
#

it really isn't

left jacinth
#

alright it works now, and I have it assigning the position at instantiation

cosmic dagger
#

there's really no reason to cache the ScoreTracker instance since you only call one method . . .

left jacinth
#

I call two

#

gameOver() and addScore()

naive pawn
naive pawn
#

i personally don't see an issue with it though shrugsinjapanese

grand snow
#

The best solution would be to grab a ref to ScoreTracker in Start/Awake

naive pawn
#

it's equivalent to not extracting it into a variable, but it's not like, overly/unnecessarily verbose or anythinf

left jacinth
naive pawn
#

you most likely did it wrong then

grand snow
naive pawn
#

or the instance isn't set early enough, especially with additive scenes

left jacinth
#

I just did:

ScoreTracker scoreTracker = ScoreTracker.Instance;

in Awake() but it gave me an error, don't remember what it was

#

that was the only difference

#

oh but Start happens after Awake and Awake may be too early to be able to call the instance

grand snow
#

yes!

left jacinth
#

i'll try it in Start

grand snow
#

solutions such as manual initialisation or DI frameworks result in better designs but singletons are great to start with and for small projects

left jacinth
#

yeah it's giving me an in-code error that scoreTracker does not exist in the current context

#

All i did was move the code from earlier into start

naive pawn
#

it needs to be declared in the class body, then only assigned to in the method

left jacinth
#

i see

#

that fixed the errors

#

yeah it works fine, thanks for the simplification

#

I think i understand better now

grand snow
#

interesting way to explain scope but it works 😆

left jacinth
#

i learn weird

topaz gorge
left jacinth
#

I can stream it to a vc if you want to see it

topaz gorge
#

Yeah im down to see it

left jacinth
#

where are the voice channels

topaz gorge
#

Good question, now your bring it up i don't think they have any

#

kinda wild

left jacinth
#

there's the auditorium which I shouldn't be in

#

i opted into educators cuz I thought that was so I could be taught, not teach

left jacinth
#

I see

#

that's too bad

topaz gorge
left jacinth
#

anyways now the droplets make a circle appear that spreads out and if it touches you you die

left jacinth
#

next I think i'm going to make the character point in the move direction

real thunder
#

I thought that expandable and fast to make are on different ends of the spectrum

#

yeah that talk was long time ago

topaz gorge
naive pawn
left jacinth
#

i was going to use inverse tangent with the inputs to change the player's rotation but 0/-1 is the same as 0/1

#

not to mention the undefined

topaz gorge
naive pawn
solar hill
#

In my opinion voice chat and screensharing can be bit of a crutch for people

#

people dont want to go through the proper steps of explaining their issue

topaz gorge
naive pawn
naive pawn
naive pawn
left jacinth
#

i used Quaternion.LookDirection or whatever

naive pawn
#

it handles the discontinuities in normal arctan

left jacinth
#

you see this is when a stream is helpful, like when trying to show someone something that isn't easily said

naive pawn
#

no, definitely not

#

again, that's ephemeral

topaz gorge
naive pawn
#

if you want to showcase via video you can screen record it and send it

naive pawn
left jacinth
#

anyways the movement is WASD from above and the camera doesn't move, I need the capsule to pint the direcxtion of movement

topaz gorge
naive pawn
#

right, i'm saying it's still not 0 or 1, or 0-1

topaz gorge
naive pawn
left jacinth
#

also Quaternion.LookRotation didn't work

polar acorn
night raptor
polar acorn
topaz gorge
#

i know if you want a analog with magnitude you have to clamp01()

night raptor
#

~~non-negative 🤓 ~~

naive pawn
topaz gorge
#

If the Input Vector is normalized, would magnitude not give 0 or 1, cause thats what i have in my game and it works perfectly like that

left jacinth
#

it's a vector3 because it's in 3d space

naive pawn
topaz gorge
naive pawn
#

if you want to support like, nudging small amounts on a controller (which don't get me wrong, is completely optional), normalizing the vector would remove that distinction - in that case you would clamp its magnitude to 1

naive pawn
naive pawn
tender vapor
#

@bleak elk is a potential scammer <@&502884371011731486>

chrome depot
#

if i was to get into coding, where would i start?

left jacinth
#

i'll send them to you

topaz gorge
left jacinth
#

oh sorry yeah the input is a vector2, the movement is a vector3 though

fickle plume
topaz gorge
naive pawn
naive pawn
topaz gorge
#

Its wild cause i developed VR games XD

left jacinth
#

i just clamped the movement

left jacinth
#

of course starting very simple

topaz gorge
left jacinth
#

yeah I want to make something with similar fighting to blade and sorcery, but with monstrous enemies, a drawing based magic system, and an open world with quests and squad multiplayer

#

my two gripes with b&s were always that it was too similar each time and that the enemies were cut and dry

topaz gorge
#

indeed

left jacinth
#

anyways now that i've clamped it I need to learn about the move direction stuff

#

are you not able to add quaternions?

topaz gorge
left jacinth
#

yeah, here's the line:

rb.rotation = new Quaternion(90, 0, 0, 0) + Quaternion.LookRotation(movedirection);
left jacinth
#

ah

topaz gorge
#
Quaternion rotationA = Quaternion.Euler(0, 45, 0);
Quaternion rotationB = Quaternion.Euler(0, 30, 0);

Quaternion combined = rotationA * rotationB;
left jacinth
#

it isn't changing the rotation of the object though

topaz gorge
left jacinth
#

what does that mean

topaz gorge
# left jacinth what does that mean
Euler angles are rotations represented as 3 separate angles:

X = pitch
Y = yaw
Z = roll

Usually measured in degrees.

Unity internally stores rotations as quaternions, but Euler angles are easier for humans to understand, so Unity lets you convert a Vector3 of Euler angles into a quaternion using

Quaternion.Euler(x, y, z)
left jacinth
#

unfortunately the rotation of the object is still not how i'd like it to be

topaz gorge
#

Is it super fast

left jacinth
#

it works if just using w or a or s or d but not with two at once

left jacinth
topaz gorge
left jacinth
#

hold on

topaz gorge
left jacinth
#

of course

#

I need to swap the z direction for the y that should be it

#

because a Vector 2 is in (x,y) while a vector3 is in (x,y,z) with y being up

topaz gorge
#

right but when your actually rotating up and down thats your X axis, when rotating left and right thats your Y axis

naive pawn
left jacinth
#

i see

naive pawn
#

think of quaternions as rotation actions, not rotation directions

naive pawn
#

that's not going to be a meaningful thing unless you're a mathematician

#

in general you should not be touching the quaternion members, only eulerangles or direction vectors

#

(or composing quaternions by multiplying them, that's also valid - eg having a yaw rotation then a pitch rotation. note that quaternions multiply in on the left, and quaternion multiplication is not commutative)

left jacinth
#

should I use Mathf or should I find another method

naive pawn
#

for what exactly

left jacinth
#

to calculate the rotation value the player should have

naive pawn
#

Mathf is an entire group of methods

left jacinth
#

Mathf.Atan2

naive pawn
left jacinth
#

it has a vector2 input that gets clamped

left jacinth
#

at this point i should just use a bunch of if statements or whatever that condition thing is

#

a switch

left jacinth
#

okay i'm lost. when i use
transform.forward = _moveDirection.normalized;
it doesn't rotate it in the direction of movement

#

it does rotate it, but not in the right direction

naive pawn
#

oh was this the swizzle thing

left jacinth
#

swizzle?

naive pawn
#

you're working in 3d, right?

left jacinth
#

yes

naive pawn
#

do transform.forward = new Vector3(_moveDirection.x, 0, _moveDirection.y)

naive pawn
left jacinth
#

i actually did this earlier. the problem is i need to rotate the capsule so that it is horizontal instead of vertical so you can tell it is turning

#

wait...

naive pawn
#

not sure what you mean by that

left jacinth
#

i'll show you

queen vale
#

Gotta add some glasses

left jacinth
#

the capsule is upright, and seen as it is cylindrical, I need to turn it sideways to look like the bug I'm going to implement

#

I guess it won't be a problem once the bug is in

#

just thought of a solution

naive pawn
left jacinth
#

I might as well make the bug and import it as the player object

olive moon
#

im still new to coding, can someone help me with small problem?

teal viper
olive moon
#

im so sorry, i was seeing if i can get someones attention first

#

i got UI text boxes im tring to modify with script and im having abit of an issue with doing it. im getting this error tho and im not fully sure what it means

#

sorry i forgot the code

naive pawn
#

!code for future reference

radiant voidBOT
naive pawn
#

are you trying to set the text of the text boxes or the contents of the array there?

ivory bobcat
# olive moon sorry i forgot the code

The type string doesn't have any field or property named text. What exactly are you trying to do? I'm pretty certain you either aren't wanting an array of strings or aren't wanting to access some non existent text property - you're probably wanting an array of text boxes instead.

olive moon
#

i got these that Im trying to set with numbers, ik my code is probably messy but i through each cycle of the for loop i want the numbers that are generated to go to the corasponding textboxes

#

the image i feel might have been useless but idk, im sorry

#

i wanted to try doing this way instead of doing it individualy for each number slot but i screwed it up i think

ivory bobcat
#

What exactly are you trying to do with that for loop?

olive moon
#

how would an array of textboxes work?

ivory bobcat
#

I'm assuming you're instead wanting to somehow evaluate which element is currently active and do something relative to said element.

olive moon
#

i was looking over it, im bit confused now

naive pawn
#

the array you have right now is of plain strings, not related to any component or other variable

olive moon
#

Oh for some reason my phone wasnt showing all the messages, I see then now mb

naive pawn
#

instead of the field name Slot1, you should go for Slots[0] where you can have the number be a variable and it'll still work

olive moon
naive pawn
#

it is not, no

olive moon
#

Oh I feel stupid

naive pawn
#

symbols (variable/field/class/method names, etc) are separate from strings (content)

#

so not sure where you got this idea, are you following tutorials?

olive moon
#

I getting my info from the official unity documentation and w3schools. That's about it

naive pawn
#

have you gone through at least unity essentials?

#

on unity learn

olive moon
#

Briefly ya

naive pawn
#

anyways 1 is not the same as "1", in a similar way, Slot1 is not the same as "Slot1"

#

you could just have a serialized Slots array that holds the references. anytime you have a bunch of thing1, thing2, etc where they should be treated similarly is likely a code smell

#

also instead of the hardcoded i <= 4 you should have i < Slots.Length

olive moon
#

Wait how would I like the textmeshprougui to the number slots on the ui?

naive pawn
#

in the inspector?

olive moon
#

Yes

naive pawn
#

you can assign arrays by multiselecting the elements you want to target and then drag them onto the field name, iirc

#

itll set the array to the selection you have

#

otherwise you can press the + to add a slot where you can drag in a single object normally

olive moon
#

It doesn't allow me to multiselect them and add it to the box

ivory bobcat
#

If there aren't a lot, you can also add them one by one. Other than that, you can do something like this (first random YT video found to illustrate process)
https://youtu.be/I_-JjIcs4QQ?si=gM8I7yHR7xsVhBfE


My first course on Augmented Reality app development with Unity2022 is now live on Udemy. Get your free copy here:
https://www.udemy.com/course/no-code-ar-appdev-unity2022/?couponCode=CF9B12C63FE7BEE55484
-------------------------------------------------------------...

▶ Play video
olive moon
#

Thank you

#

There is a bug ive been experiencing, the inspector keeps going black and idk why. I couldn't find any fixes or info online

ivory bobcat
#

You'll need to somehow illustrate the behavior

olive moon
#

The bug or the other thing?

olive moon
#

Its kinda random when it happens and idk why causes it but it keeps happening

naive pawn
olive moon
#

Im on windows

left jacinth
#

for some reason this code is not instantiating the button. The button is assigned to tryAgain, and the script is connected to the canvas.

using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class ScoreTracker : MonoBehaviour
{

    public TMP_Text scoretext;
    public TMP_Text gameover;
    public int score = 0;
    public GameObject tryAgain;
    public static ScoreTracker Instance { get; private set;}
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Awake()
    {
        Instance = this;
        gameover.text = "";
    }

    public void addScore()
    {
        score += 1;
        scoretext.text = "Score: " + score.ToString();
    }
    public void gameOver()
    {
        gameover.text = "Game Over!";
        GameObject btn = GameObject.Instantiate(tryAgain, new Vector3(0,-75,0), Quaternion.identity);
    }

}
#

at least i cannot see the instantiation

languid pagoda
left jacinth
#

wouldn't the parent automatically be the canvas

languid pagoda
#

why?

#

check the hierarchy

left jacinth
#

because the script is attached to the canvas

languid pagoda
#

nope

#

it will parent to nothing if you dont tell it to as far as I am aware

left jacinth
#

alright well how do I parent it

naive pawn
#

Instantiate is a static method, it has no context as to the current method or component or GO

languid pagoda
naive pawn
languid pagoda
#

yeah honestly thats the right call and then you are going to have to get a reference to the rect transform to position it. I dont think the position passed to instantiate will automatically covert to UI position

naive pawn
#

(also you don't need to qualify Instantiate as GameObject.Instantiate, btw. it's on Object, so a MonoBehaviour will have unqualified access)

naive pawn
#

it wouldn't be anchoredPosition, i guess

languid pagoda
naive pawn
#

instantiate isn't in worldspace

#

it just takes the position, whether it's in worldspace or screenspace is up to the context of the object itself

left jacinth
#

what should I add to the instantiate field to add it as a child of the canvas

naive pawn
#

(it's not a field)

languid pagoda
#

GameObject btn = GameObject.Instantiate(tryAgain, canvas);

naive pawn
left jacinth
#

bruh i thought you said i could do it when instantiating

naive pawn
#

you can

#

there's a signature that receives the position and also the parent

left jacinth
#

in the same line of code as the instantiation?

naive pawn
#

yeah

languid pagoda
naive pawn
#

hence why i said to check for a signature that does what you want

naive pawn
naive pawn
left jacinth
#

i'm assuming i have to define the parent earlier like i do with rigidbodies

languid pagoda
naive pawn
left jacinth
languid pagoda
naive pawn
left jacinth
#

okay

languid pagoda
languid pagoda
naive pawn
#

let me guess, you put in the parent first

languid pagoda
#

Ok I was wrong

#

my mistake

naive pawn
#

what does the error say? that you can't convert transform to Vector3, and quaternion to transform?

make sure to also read the error lol, a mistake i've certainly made many times before 😆

#

anyways bottom line you should care what docs say

left jacinth
#

should I be using any dot operators for this or should I be able to just import yhe canvas as a variable and then add the variable to the instantiate()

naive pawn
#

you don't need to import anything

left jacinth
#

so no public whatever canvas

naive pawn
#

again, consider which object you want to be the parent

#

that isn't an import, but no, you don't need that either

naive pawn
left jacinth
#

vocabulary voshmabulary (i'm just bad at remembering that)

naive pawn
languid pagoda
#

I really wish the ui in unity would get an update. The fact you have to write code to enable UI elements is crazy to me

#

data binding to variables would make ui a ton easier to set up

left jacinth
#

i am completely missing the reference to the canvas

#

also unfortunately the documentation gives no example of a parent

naive pawn
languid pagoda
#

why are you instantiating the ui anyways

#

this can just be enabled/disabled when needed lol

left jacinth
#

i want toe button to appear when you die

naive pawn
languid pagoda
#

yes create the UI leave it in the canvas always and just disable/enable it when needed

left jacinth
#

gonna turn inside out

naive pawn
left jacinth
#

so i guess so

#

i'll look at how to enable and disable buttons

languid pagoda
teal viper
# left jacinth vocabulary voshmabulary (i'm just bad at remembering that)

It's not just vocabulary. It's important concepts. If they were for example house appliances your situation would be similar to not knowing what a fridge is. Just knowing that it exists and somehow related to storing food, while missing important info like that it requires electricity to work and how you can open and close it.
And if someone tells you to take some food out of the fridge you'll be like "from a what??"

#

Point is. Vocabulary is important.

left jacinth
#

i'm aware

#

it's more like that I know that a fridge is an object that stores food and keeps it cold and i know how to use it but not that it's called a fridge. the problem comes when you need to reference what you're talking about in conversatioon or when looking it up

teal viper
#

It's not just about conversations. Knowing the proper concepts and vovab helps organize the info in your head, makes it understand it better. In fact, remembering vovab is directly related to understanding how something works, since you have to over it again and again.

left jacinth
#

i don't disagree that it's important

#

also what i was referring to was making a GameObject variable

#

outside of problems, my game is mostly complete aside from sounds

olive moon
#

I just did alittle tuning and fiddling around with it and it full works now. Thank you all for helping me

lyric cloak
#

whats the best place to start coding 2d top down games ,ive done scratch before but that was really begineer stuff so i wouldnt count it .Any tutorials that teach you from zero?

radiant voidBOT
lyric cloak
#

unity learn doesnt really help me though

lyric cloak
#

woops

#

just didnt know where to put it since i wasnt sure what channel was the right one

naive pawn
teal viper
polar acorn
topaz gorge
# lyric cloak unity learn doesnt really help me though

I get what you mean, but the thing is, is that theres not much thats going to magically help you, like yes are there other things that might explain something a little bit better sure. But the only way your gonna actually learn from something is seeing what is being done and trying to use it and also apply it in a different way to get a fundemental understanding.

topaz gorge
# lyric cloak unity learn doesnt really help me though

This stuff isn't easy, don't listen to what youtube videos say about oh unity is easy, half the youtubers that use unity can't even use it correctly and farm people to buy there half baked courses. But you can absolutely do it if you don't mind putting in the effort and dedication not only learning the engine inside and out but taking the time to mess things up.

magic copper
#

guys can anyone help me with enemy ai T^T ive been doing it for days and its not fine

teal viper
magic copper
teal viper
#

That's not really enough info to say anything... Also, try rp focus on one issue at a time.

burnt vapor
#

Code problems require the actual code to be shared, or it just becomes a whole lot of guesswork and questions

radiant voidBOT
magic copper
naive pawn
magic copper
errant breach
#

Hello ! i have a weird issue with my AI.
So basically, to make it move, i add force like that :

owner.rigidBody.linearVelocity = new Vector3(owner.actualSpeed * isFacingLeft, owner.rigidBody.linearVelocity.y, 0);
Every tiles on my level are the same, placed at the same high...
But for some reason, my AI sometime stop when changing tile, as if they where touching a wall and im a little bit lost.
Here's my full code : https://pastes.dev/GIRJLWNh61

If someone can give me suggestion on why this issue happen, i would be glad, my version of unity is 6000.0.62f1

wintry quarry
#

If so you can use 2D physics and CompositeCollider2D to merge all your colliders into one shape, which solves this issue

#

If you must use 3D, the best approach is merging the colliders but there aren't built in tools for doing that in 3D

errant breach
#

=======================
I FIXED IT ! ( Thanks @wintry quarry, i'll take note of you're suggestion for sure !)

sage mirage
teal viper
errant breach
sage mirage
errant breach
#

FSM ? 😅

sage mirage
#

Oh thats a problem

naive pawn
#

a finite state machine is a stateful machine that has finite states

errant breach
#

I see some "fsm" here and there but idk what it does, my friend just told me "u do it like that and here u go :>" xD

sage mirage
#

Finite State Machine it is a mode basically and it works in combination with the State Design Pattern. It is a way to tell your AI change your internal state based on the current state you are in so if something happens it will be notified and change its state.

#

Instead of using if else spagetti

#

and do enum based transitions

errant breach
#

and i have states !

errant breach
sage mirage
#

Yes maybe it works but it will be hard to maintain I mean its a bad practice FSM is the best approach here or probably you could make it with AI Behavior Trees I assume.

#

AI Behavior Trees is something I am trying to learn right now

errant breach
#

Oh- i see what you mean now. Im just starting to learn FSM so i might have made things poorly !

sage mirage
#

Can I see your FSM just I am interested how you have created your AI State Transitions.?

celest depot
#

Hello guys.
https://paste.ofcode.org/hELAy2pCRgQczcWF3C2Eup
I have been testing the responsiveness of the particle systems for my spaceship movement to simulate real life RCS thruster activation. But, there is a problem. When I press the key for hover up or down, the particle systems that were assigned for hover movement did not play at all. When I try surge, strafe, and roll, all of the particle systems could play without any problem. So, I think there are problems that I cannot detect.

sage mirage
#

your code is all else if else if and no data structures at all

split mason
#

is there some place or a way where i can study systems developed in games built with unity? like different systems like quest system, tutorial or more advance systems?

celest depot
sage mirage
# split mason is there some place or a way where i can study systems developed in games built ...

There isn't a book or something, but you can always practice System Design and Decomposition and all these stuff its all about breaking the problem into sub problems and solve these sub problems seperately to find the solution to the main problem (divide and conquer) its all about experience and having a good clean game architecture using Design Patterns and data structures that are efficient to use for each system. Do you know about Design Patterns and Data Structures at all?

#
            {
                up1.Stop();
                up2.Stop();
                up3.Stop();
                up4.Stop();
                down1.Stop();
                down2.Stop();
                down3.Stop();
                down4.Stop();
            }```
#

I see you have all of them stopped here its on release right? Is it what you expected it to do?

#

so when you hold them they dont play?

#

basically what I see there is isPressed you dont have to press

#

you have to hold

#

no?

celest depot
#

I've never heard about the practice. For the breaking the problems, I did. Originally, the ships have 12 scripts for 6 dof after I solve the problems one by one. I decided to combine all because of the particle system activation. Short story. When 1 particle system share 2 scripts, one of them will 'win' and the other, not.

sage mirage
#

so I didn't understand

celest depot
sage mirage
#

you want it to play the particles when you hold or press the keys?

#

I assume whenn you hold them

sour fulcrum
#

The quick answer here is your code is designed in a way where you should be using wasPressedThisFrame and wasReleasedThisFrame to toggle your stuff instead of isPressed, which will stop stuff "fighting" over which wins or not

celest depot
split mason
celest depot
sage mirage
sour fulcrum
celest depot
#

Alright, I will try if it work

sage mirage
# celest depot Oh, should I use wasPressedThisFrame or wasReleasedThisFrame or both?

For one of my projects I did it like this.
bool inputThisFrame = playerControls.UI.AnyInput.WasPressedThisFrame(); but it was for UI basically. So, you have to store your input using the was pressed this frame on a bool and then check if (inputThisFrame) and do your logic inside the if statement, but really your codebase is too dirty just a feedback. You said you are a beginner so I recommend learning how to use Data Structures and some Design Patterns at the beginning. Go search for Singleton, Arrays and lists at the beginning.

celest depot
#

Btw, this is the ship.

#

I've stuck with the RCS activation for weeks. I did try with PID controller and... It kinda work but with the wrong way.

#
Unity Discussions

Hello! I’m a beginner and have a problem with making my spaceship stop when there is no gravity. My idea is to make the ship to go forward when the Up key is pressed, and when i release the key, it will stop. Currently i have made it to go forward when the Up key is pressed, and when the key is released, it goes backward to decrease the spee...

sage mirage
#

The problem is you are trying to create something very complex when you dont have experience in creating something simple XD

celest depot
sage mirage
#

I have noticed that all beginners when starting Game Development they just overengineer things out and are trying to create their dream game and thats completely fine but you wont be able to make it and you will just waste time if you have no experience at all you will stuck on problems like this copy pasting code and wont be able to understand a line of code. I dont want to kill your motivation or something I just want you to understand. And no even though you are willing to create it you wont be able right now. START SMALL and grow gradually do not overcomplicate things in your head thats my advice.

rocky gulch
# sage mirage I have noticed that all beginners when starting Game Development they just overe...

Indeed it is, discovering "optimizations" and OOP made people thought that its a good practice and should be used at all times. As beginners i think people are more latched on the fact that having a more optimized approach is always better, not knowing that most of the times it may lead to limitations.
As for engineering,
IMO its just that we cant create something without knowing what we need and there is no such thing as a (god) system where it accounts for every single case as it will eventually be gated by design decisions. At most youll probably get a "template" of the said system as a base

Just my thought as a beginner lol

mighty sigil
#

I've encountered a physics instability after build (where the FPS are 120), but not in editor (where they are ~300), I've made sure to that all the code is called in fixed update there are some parts that aren't dependent, but they still shouldnt cause such impact as to break the behaviour. any guesses on why that may be?
https://pastes.dev/GCKhHwqxu7

#

The functions that arent called in this file's FixedUpdate are called rarely (so I am sure that they don't cause the issue)

naive pawn
#

what's gunFrontTarget?

#

in relation to the rb

eager sun
#

Hi everyone
I'm creating a Unity game using an FPS controller with a CharacterController, but I'm having an issue.

My player capsule keeps falling infinitely as soon as I start the scene.

I already tried:

adding a Plane as the ground
checking the CharacterController on the capsule
checking the player starting position
verifying the movement and gravity script

But the problem still happens: the player never lands and is never grounded.

Does anyone know what could be causing this?

naive pawn
mighty sigil
kindred dome
#

patent hehehe

keen dew
#

What exactly is the instability? How does it behave?

naive pawn
#

are the body and gun colliding

kindred dome
#

you could put them on separate layers and exclude them from each other to check

naive pawn
#

(btw, why does the gun need to be an rb)

sage mirage
mighty sigil
mighty sigil
naive pawn
#

is the rb set to interpolate

mighty sigil
#

Both are,
also continuous collisions, but the issue doesn't really have anything to do with collisions

errant breach
rocky gulch
mighty sigil
naive pawn
#

this is half debugging and half curiosity, can you show a video of this

mighty sigil
#

I'll do one better, side by side of in editor and in build

naive pawn
#

it kinda seems like ToTargetSpringForce is essentially a damped harmonic oscillator

sage mirage
#

you know when you have copy pasted

mighty sigil
#

Yeah, except there's also a second dampening function, but I'll merge them later

sage mirage
#

Thats why you cant copy paste code even though in College or Unviersity because professionals know if the code is yours or not its very obvious

rocky gulch
#

I see some "fsm" here and there but idk what it does, my friend just told me "u do it like that and here u go :>" xD
he did say that he doesnt know what it is, it might be a system from one of his colleague or friend

sage mirage
#

he said then oh yes I am using FSM and I thought he is experienced at one moment

mighty sigil
#

You can guess which is expected/unexpected behavriour.
Cuts are to match the recordings of the same weapon being used.
Looking around with the player is to show how despite movement it's still way more stable.

errant breach
#

Of like... not coding myself ?

#

If yes, i use SVN so i guess i can send you every code progression of the last 14 days

#

I am in fact getting started on StateMachine, and a friend of mine told me the basis... But i writted all myself, so if you see my code as something stolen / "not made by me", well i take it as a compliment, it means that i did well 😆

mighty sigil
#

Oh come on, nobody codes themselves (I'm not saying you're not tho! it's just a hyperbole) especially nowadays and/or begginers. Copying code is nothing new

errant breach
#

Well, to be transparent, my friend did helped me sometime when i was stuck, and i also received help on this server, but bruh-

rocky gulch
#

no need to be personal, its a discussion channel

sage mirage
# mighty sigil Oh come on, nobody codes themselves (I'm not saying you're not tho! it's just a ...

No, you are wrong! You have to be able to code yourself and you can achieve it by practicing and understanding logic instead of just copy pasting code without even knowing what it does. Its different when you copy paste code and thats it and different when you are copying it and trying to write it down on your own and understand the logic and why it works this way and actually do your own decomposition to figure how a specific system works for example.

mighty sigil
# keen dew What exactly is the instability? How does it behave?

Here is a GIF with the issue.
The guns should maybe oscilate a little bit before reaching a stable equalibrium.
They do not in the build, and I'd just increase the damping.
But they DO in editor when FPS are around ~300, which means that the behaviour is probably frame rate dependent

rocky gulch
#

have you setup angular damping? im not familiar with this actually

mighty sigil
#

There's both angular damping in a way in my code + regular Unity angular damping. Setting the Unity angular damping higher fixes the issue, but makes the guns way too sluggish to aim

mighty sigil
fair cedar
#

this line for some reason does not move me in the right direction, even though with Debug.DrawLine(transform.forward) i did get the right direction transform.Translate(transform.forward * verticalInput);

naive pawn
fair cedar
#

that works

#

what if you want to Translate() not locally?

#

not that i need it

naive pawn
#

you would pass in Space.World to specify what space to base the vector on, as shown in the second signature

fair cedar
#

is this also a bad way of moving the character on a spherical surface? because if i increase the speed it goes into orbit...

naive pawn
#

-# i mean, that's what happens when you go fast around a sphere

fair cedar
#

fair

naive pawn
#

make sure you're moving the forward vector to be tangent to the surface, i guess

#

though for a small enough planet, a large enough deltatime, and a large enough speed, it'd go into orbit anyways

rugged beacon
naive pawn
languid pagoda
#

I am running into a weird issue while trying code a full body fps controller. The camera is attached to the head and I am using IK to stablizle the camera and keep the camera from bobbing and moving with the character models animations. This works great. Now when I expand on my IK code to hold the gun in "hip fire" mode the gun has to be position above the character models shoulder to have the gun positioned correctly in first person view, now the issue I am running into is when I implment the hands into my ik code you can tell the gun is positioned higher to the characters arms and the character model looks like its reaching upwards to hold the gun. If I lower the gun to where the arms look normal you can only see a small part of the guns barrel from first person perspective. Any advice on how I can fix this?

naive pawn
rugged beacon
#

maybe u can try keep the cam seperate out of the model? or you want the camera affected by animation somehow ?

languid pagoda
# naive pawn doesn't seem like a code question. most of the time first-person animations don'...

Oops I thought I was in Unity Talk my mistake. most games do not use a 3rd person model some games do. Dayz/escape from tarkov are examples that do. Its supposed to be a fully body aware so player can see their torso/legs. Most games would get around this with the usage of a second camera. HDRP does not support camera stacking, so adding a second camera tanks FPS by like 80 even tho its set up to only render the gun.

rugged beacon
sour fulcrum
languid pagoda
#

The real issue I am running into is with camera perspective I have no issues getting the gun where it needs to be, but the problem is the gun needs to be above the players shoulder in order to be positioned correctly for the players perspective

naive pawn
rugged beacon
#

what about move the cam to a desired position when switch to first person

sour fulcrum
languid pagoda
sour fulcrum
languid pagoda
# sour fulcrum Maybe both depending on the game?

Possibly I am unsure how this would work though. For example if I use FPS arms and a gun for the camera view and just torso + legs for the full body part you'd see the massive gap between torso and arms when you look downward with the gun

#

Dual cameras is how other games handle this however since there is no camera stack on HDRP its an instant 80 fps loss to fix this using 2 cameras.

languid pagoda
#

The gun is on its own layer, the second camera is set up to only render the gun layer the main camera set up to render everything

#

I also tried using custom passes instead of a second camera but that doesn't solve anything because the custom pass just operates off the cameras perspective

sour fulcrum
#

Honestly no, sorry. I just say that because I know Lethal Company doesn't have any inherit issue with multiple camera usage and i'm doing some modding stuff that pushes how much is being rendered pretty heavily lol

#

I know thats not super helpful 😅

languid pagoda
sour fulcrum
#

Positive

languid pagoda
#

and your positive its an HDRP game?

sour fulcrum
#

Yessir

languid pagoda
#

interesting

#

im honestly about to decompile escape from tarkov and see how they did it 🤣

sour fulcrum
#

Oh, for reference it's doing some render texture stuff

#

Tarkov isn't HDRP

languid pagoda
#

I know but I am curious if they're using the dual camera trick to fix this or something else completely

#

maybe they used another option to resolve this i am not aware of

#

ok so tarkov uses FPS arms and then legs + 2 cameras to make them render correctly together

#

not an option in hdrp unfortunately unless I want the game to run at 40 fps

#

I might honestly juust have to change the project to use URP which I guess is fine but then I lose out on volumetric lighting

sour fulcrum
#

have you tried render texture stuff?

median hatch
#

does anyone know why this keeps happening

#

ever since updating to 6.4 i keep getting this fucking black inspector

#

and nothing fixes it

#

i swear to god

sour fulcrum
polar acorn
#

If the editor is hitting a null reference exception, it might not be able to render

polar acorn
median hatch
polar acorn
#

Okay, so, internal code. Try updating

fickle plume
languid pagoda
sour fulcrum
#

yeah like camera -> RT -> canvas rendered by main camera

languid pagoda
autumn zodiac
#

So i created this day light script:


[ExecuteInEditMode]
public class LightingManager : MonoBehaviour
{
    [SerializeField] private Light DirectionLight;
    [SerializeField] private LightingPreset Preset;
    [SerializeField, Range(0, 24)] private float TimeOfDay;

    private void Update()
    {
        if (Preset == null)
            return;

        if (Application.isPlaying)
        {
            TimeOfDay += Time.deltaTime;
            TimeOfDay %= 24;
            UpdateLighting(TimeOfDay / 24f);
        }
        else
        {
            UpdateLighting(TimeOfDay / 24f);
        }
    }

    private void UpdateLighting(float timePercent)
    {
        RenderSettings.ambientLight = Preset.AmbientColor.Evaluate(timePercent);
        RenderSettings.fogColor = Preset.FogColor.Evaluate(timePercent);

        if (DirectionLight != null)
        {
            DirectionLight.color = Preset.DirectionalColor.Evaluate(timePercent);
            DirectionLight.transform.localRotation = Quaternion.Euler(new Vector3((timePercent * 360f)-90f, -170f, 0));
        }
    }

    private void OnValidate()
    {
        if (DirectionLight != null)
            return;

        if (RenderSettings.sun != null)
        {
            DirectionLight = RenderSettings.sun;
        }
        else
        {
            Light[] lights = GameObject.FindObjectsByType<Light>();
            foreach(Light light in lights)
            {
                if(light.type == LightType.Directional)
                {
                    DirectionLight = light;
                    return;
                }
            }
        }
    }
}

But i also wanted to make that at night you get a moon and during the day you get a sun, but i have no idea how i could do that

lean summit
#

!code

radiant voidBOT
crystal agate
#

question, I have 2 public voids attached to buttons but they don't do anything? they don't print the debug log I put in either

polar acorn
crystal agate
#

oh the logs actually are appearing, it was collapsed earlier

#

the buttons still do nothing though

polar acorn
#

If the logs are printing, the functions are being run

crystal agate
#

this is the function its supposed to run

polar acorn
#

Considering this is an IEnumerator, and you're not starting the coroutine, I'm not sure what you're expecting to happen

sour fulcrum
sour fulcrum
#

Your first screenshot

crystal agate
#

ohhhh

#

yeah i see whats going on now thank you

#

i changed this script like so many times this week already i forgot it needs start coroutine

verbal dome
gleaming ivy
#

hi, everyone

verbal dome
#

@autumn zodiac Also you could use animation curves for the rotations for more control

autumn zodiac
#

Alright thx, i'll take a look into that

gleaming ivy
verbal dome
#

What are you saying?

gleaming ivy
#

I think u are perfect man

verbal dome
#

Alright cheers

gleaming ivy
verbal dome
#

This isn't a dating room

sour fulcrum
#

Gotta put the marble game in your tinder profile it’s clearly a hit

gleaming ivy
verbal dome
#

That's Osteel 😭

sour fulcrum
#

Fuck i need to go to bed 😭

verbal dome
#

Not the first one to confuse us though

gleaming ivy
verbal dome
#

Maybe stop the spam before mods step in

sour fulcrum
#

(they are not real)

gleaming ivy
#

good, u are not stupid. but u are ...

verbal dome
gleaming ivy
polar acorn
#

I think you can tell ChatGPT to type like a ten year old nowadays

verbal dome
#

True

sour fulcrum
#

Yeah AI has killed that kinda assumption

gleaming ivy
sour fulcrum
gleaming ivy
#

yes

#

buy

verbal dome
#

Aaand gone

cerulean sigil
#

does anyone know how to make it so that a collider2d still detects collisions but does not create physics feedback? basically my character can throw a new gameobject (that has a Rigidbody2D component because I need to use linearVelocity on it). On collision between the throwable and player I want the throwable to be destroyed BUT i dont want the player to be knocked back, currently my player gets flung on collision with the throwable and i cant find a solution (sorry if this doesnt make much sense)

polar acorn
#

So, you'd make your player kinematic so it can push things around, but not get flung away by a collision

cerulean sigil
#

ahh okay ill give that a try thank you <3

fickle plume
pliant dome
#

Is there a way to layer an animation on top of another animations on a 2d sprite?

#

Like I want to have a slash animation on top of the players sprite animation

fickle scaffold
pliant dome
fickle scaffold
lean pelican
#

I'm having some issues with materials when importing an .obj file, what would be right channel for that question?

vernal thorn
#

for some reason the player looks jittery while cam is moving


public class Cam : MonoBehaviour
{
    public Transform Maus;
    public Vector3 offset;

    public float smooth = 0.1f;

    private Movement move;

    void Start()
    {
        move = Maus.GetComponent<Movement>();
    }

    void LateUpdate()
    {
        Vector3 target = new Vector3(
            Maus.position.x + move.lastDirection * 6 + offset.x,
            Maus.position.y + offset.y,
            transform.position.z + offset.z
        );

        transform.position = Vector3.Lerp(transform.position, target, smooth);
    }
}

My player uses rb2D.velocity and FixedUpdate too move

slender nymph
#

is the player's rigidbody set to interpolate?

vernal thorn
night raptor
night raptor
#

Also I have little clue what that target calculation does. At least multiply the smooth by deltaTime. It still won't be perfectly framerate independent as highlighted here for example: https://www.youtube.com/watch?v=LSNQuFEDOyQ

lament raft
#

I dont know what i did wrong.

grand snow
lament raft
#

Oh......

#

Thank you

night raptor
#

funct fact: GameObject.rigidbody used to be a thing among other such references so one wouldn't have to call GetComponent to get it. It was removed on Unity 5 and only .transform was left

polar acorn
#

Because Transform is the only component that all game objects are guaranteed to have

main tree
#

been trying to learn multithreading using the job system to prototype a 1000 entity's on screen at the same time using character controller cant seem to figure it out or get it working, if anyone can help or teach how to use it properly i would appreciate it

radiant voidBOT
grand snow
#

Ideally you ditch character controller and atleast aim to perform transform changes via the handle only in jobs

teal viper
#

I think the main misconception here is what is being heavy. Your job doesn't really all that heavy of a work. Most of the CC overhead is likely involved in resolving collisions during movement, not in calculating velocity and such.
This is a typical mistake of premature optimization. Optimizations should be based on profiling results. Not unconfirmed assumptions. Such that you don't try to optimize thing that isn't being the bottleneck in the first place.

main tree
#

so it ur saying that the bottleneck might be cc and the physics is expensive? and that should using transform? @teal viper @grand snow

soft lodge
#

Can someone help quick! I used a version from 2022 and i saved and tried to open it up the project but it was not there. Instead i went to the file where i keep it and it said i wasnt using the right version. I updated it and everything was gone
I’m genuinely about to give up after i spent 5 hours in it

soft lodge
slender nymph
#

don't crosspost

teal viper
soft lodge
teal viper
#

Ironically, there appears to be an experimental Character Controller package specifically for ECS. Thanks for the unambiguous naming, unity... That one is intended for ECS, but it doesn't seem like you're using it.

strong wren
round fjord
#

how can we use delegates in our game?

rich adder
inner hollow
#

Hello, I am working on a project thru Unity (I have never used Unity before, this is a learning process for me). I am trying to get the Rod asset to rotate with a click and drag, but when I use raycasting, the rays hit the parent object, called ViceAssm. I currently have everything but the Rod in the Default layer, and the Rod itself in its own layer called the Rod layer, but I am still stuck. Could I have some help, please? If I am talking in the wrong channel, I am sorry, I just joined and I need someone to redirect me to the correct channel.

rich adder
#

Which Rod ? Is it a GameObject in your hierarchy

inner hollow
#

Yes, its full name is "ViceWorkingAssembly - Rod", and it's under "ViceAssm"

inner hollow
rich adder
# inner hollow

Is your game view able to see it hard to tell from screenshot

inner hollow
#

My game view is a little rudimentary right now, but I am able to see the rod through the main camera.

#

This is what I see in the game view. Clicking on the rod causes the console to say "Hit: ViceAssm" instead of the rod

rich adder
inner hollow
#

The script is able to run

valid heath
#

I'm trying to destroy all the children of an object. is there any reason why neither of these approaches work? children is a List of game objects that gets cleared and then filled whenever a player moves tiles. They still appear in the scene view and the project hierarchy, so I'm confused as to why Destroy() isn't working.

#

the line separates two different methods of doing it that i've tried, im not deleting them twice lol

#

I can verify that the children list is empty, and that the loops are running

rich adder
inner hollow
#

The only thing in the "Rod" layer is just the Rod asset, I am not sure what you mean by colliders

teal viper
#

And do you see any errors/warnings in the console when that runs?

inner hollow
teal viper
# valid heath no

I'd suggest printing the names of the destroyed children or maybe even the object ID to make sure these are the objects you're actually looking at.

rich adder
inner hollow
#

The Rod asset has the raycast script

rich adder
inner hollow
#

Sorry I saw online that the stuff in the game was called an asset, so I have just been calling the game objects that. The ViceWorkingAssembly - Rod game object has the raycast script

teal viper
# inner hollow

It seems like a compound collider case, so hit.transform would return the transform of the object with RB. If you want rod to be independent, it needs to have its own RB.

#

Or try hit.collider instead.

rich adder
#

Ahh just realized there's a rb on root obj

valid heath
wintry quarry
left jacinth
#

This code isn't sending "Attack" to the debug log, so it must not be recognising the button being pressed. any help?

using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerAttacks : MonoBehaviour
{
    public Rigidbody sword;
    public Vector2 direction;
    public InputActionReference dir, atk, def;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        direction = dir.action.ReadValue<Vector2>();
    }

    // Update is called once per frame
    void Update()
    {
        {
            if (atk.action.IsPressed())
            {
                Debug.Log("Attack");
            }
        }
    }

    private void Atk()
    {
        if (direction.x == -1)
        {
            Debug.Log("Attack");
            if (direction.y == 0)
            {
                Atk1();
            }
        }
    }

    private void Atk1()
    {
        sword.rotation = Quaternion.Euler(0, 0, 90);
        sword.angularVelocity = new Vector3(1, 0, 0);
    }
}
wintry quarry
#

You need atk.action.Enable(); somewhere

left jacinth
#

ah

wintry quarry
#

you also have extra brackets for some reason

#

and your direction is only being read once in Start

left jacinth
#

lots of stuff

#

thanks

inner hollow
# teal viper Or try `hit.collider` instead.

I used hit.collider, but it did not seem to work, so I added the rod's own rigidbody. I added the rb and a connector joint so the rod stays with the ViceAssm as it translates, but the rod now seems to drift as the rod translates.

#

I was able to get the rays from the raycast to hit onto the rod game object, but I do not think "hit.collider == transform" is correct because the if statement is still not passing

teal viper
teal viper
#

Though, I'm still not sure if collider returns the correct one in the compound collider case.

inner hollow
inner hollow
left jacinth
strong wren
#

@kindred grail This server is not for collabs. You can help people for free by publicly engaging with questions people are posting here.

left jacinth
#

i figured it out

#

neeevermind

#

got it

inner hollow
#

I got the rod to stop drifting, the only thing I need to do I think is figure out why the if statement I have for hit.collider is not working

teal viper
inner hollow
#

Oh ok yes I can do that

#

This what I have so far; while going into the game, I clicked on the rod, and it says in the console that the rod has been clicked, but it does not say "hit", which is inside of the if statement

left jacinth
#

how do i un-normalize a vector

teal viper
teal viper
left jacinth
#

when i take inputs I want pressing w and a to result in the vector (-1, 1)

teal viper
#

Unless you store it separately.

inner hollow
#

Oh ok sorry I don't know C# or Unity well, so I just used collider.transform, and that's what led me to the API message

teal viper
left jacinth
#

it comes normalized regardless

teal viper
#

Comes from where?

left jacinth
#

it reads the input vector of a 2d vector input for wasd

inner hollow
#

The if statement I do not think works. I do not see "hit" in the console

teal viper
inner hollow
#

Yes, I changed it to how you said with the hit.collider.transform

#

Unless I misinterpreted what you said?

teal viper
#

That's not how I said. Check my message above again. I even provided a code snippet.

#

hit.collider - > hit.collider.transform

inner hollow
#

Oh 😭 wow sorry abt that

teal viper
#

I never mentioned you need to modify the right hand side.

inner hollow
#

You mentioned that I did not need the get component though

teal viper
#

Yep. That you don't need for sure.

inner hollow
#

Oh ok

left jacinth
#

hold on i may just be able to use round()

inner hollow
#

I am not sure how well I can describe this, but when I try rotating the rod, there are very slight rotations, and it becomes offset from the ViceAssm. The ViceAssm also has minor translations when I try rotating the rod. I have never seen this before. Sorry about this, I did not realize fixing this one issue would lead me down a rabbit hole like this

teal viper
#

Making the rb dynamic and adding joints forces it into being processed by physics independently.

inner hollow
#

I am trying to model a manual milling machine. Currently I am trying to implement a working vise and table, which I will later use to add more components of a mill.

#

Ok, yes the kinematic toggle works now. For some reason it didn't earlier; thank you

#

The rod has been fixed, from my knowledge. Thank you to those who have helped me! I will take my leave :o] 👍

rugged beacon
teal viper
stuck palm
#

how can I draw shapes? I want to make a hitbox viewer and would like an OnDrawGizmos style method where I can draw something every frame

#

this would be for the build, not the editor

real thunder
#

is there like online bitmask converter for int 32

night raptor
#

what is bitmask converter? I'm sure there are loads of tools which convert from binary to int32 if that's what you mean

real thunder
#

yeah I just realized

#

I basically just need to convert bits into int which is... simple I guess

unborn jungle
#

am i allowed to ask c# debugging questions about a convoluted setup,
if its godot and not unity?
even if its an implementation that is majorly a custom system and not stemming very much from any innate feature of either unity or godot,
like a wavefunction collapse algorithm implementation, with a custom tile grid definition

#

i'm making my brain explode over my condition logic

night raptor
unborn jungle
real thunder
night raptor
real thunder
#

thing is NavMesh mask unlike LayerMask can't be represented as coherent Unity class, only as int, so

#

I want to check if NavMeshHit is on area 8

night raptor
real thunder
#

I suppose the code to get int would be navmesh_area_mask = 1 << 8

#

but I would like to be able to get value outside of code to insert it in the inspector

night raptor
#

LayerMask.value converts to integer/reveals the underlying bitfield

#

I haven't used the navigation package enough but I assume the areas are totally separate from the layers so serialized LayerMask would show the layers which are unrelated, I see. It would work but the names would be totally wrong

real thunder
#

huh yeah that would work

#

interesting

naive pawn
#

0b00000111 here the first 3 layers, 0-2 are selected while 3-7 are masked out
these count from the right, like how in decimal you have the units place, then tens, then hundreds, etc from the right

#

in this case if there were more than 8 layers, the rest would also be masked out

real thunder
#

I mean I don't understand what system is this written

naive pawn
#

binary

real thunder
#

why 0 b and 1

naive pawn
#

0b is a prefix saying the number will be binary

#

like how 0x can be used to write hexadecimal literals, eg 0xF0 -> decimal 240

real thunder
#

(yes I am clueless)

#

so this is what those thing actually mean huh

#

makes sense now

#

well navmesh got 32 bits

naive pawn
naive pawn
real thunder
#

that I know

#

I found what I was trying to find, I think

naive pawn
#

the unity huh how page also has a converter

#

ah wait it doesn't convert to decimal

naive pawn
#

if you're writing them as decimal in your code you're just creating more work for yourself

#

use binary literals or bitshifts

real thunder
#

to clarify I want to be able to put that into default inspector

#

can I?

naive pawn
#

one sec

#

i have a few ideas but im not 100% on any given one, so gotta check first lol

naive pawn
#
class Example : MonoBehaviour {
    public X n;
}

[Flags]
enum X
{
    A = 1 << 0,
    B = 1 << 1,
    C = 1 << 2,
    D = 1 << 3
}
night raptor
#

I mean the cleanest way to enter these bitmasks in inspector while allowing changes in the area list would be to have something similar to that of LayerMask but for navmesh areas. You could make similar int wrapper class and make a PropertyDrawer for it which uses EditorGUI.MaskField. The way the NavMeshAgents m_WalkableMask is implemented could be a good reference implementation: https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/Inspector/NavMeshAgentInspector.cs. It is up to debate whether that is worth the hassle instead of that enum trick which seems very neat

naive pawn
#

the enum thing does introduce a second source of truth which is always a potential pain in the future

misty merlin
#

Has anyone seen this or know what is causing it? I left the editor open over night and came back to this error on repeat

naive pawn
#

does it persist after restart?

real thunder
#

thanks

misty merlin
naive pawn
#

well if i had to guess from the info thus far, just seems like some system broke because it was on for too long

naive pawn
#

i don't have a version installed that's ≥6 though

sour fulcrum
#

oh cute

naive pawn
#

unfortunate that it doesn't have preview screenshots

sour fulcrum
#

bet its not implemented into unityevents 😄

naive pawn
#

can someone test that out and screenshot that, i want to see how it is lol

real thunder
#

tbh I gonna use just copypasting value from a converter for now but for the future where I would use that for more than one script I will consider using flag enum and stuff

#

does collider bounds min max shifting depending on rotation?

naive pawn
#

yes, because bounds are axis-aligned

naive pawn
night raptor
#

But I can definitely see how that could work nicely in many cases, maybe just not very useful in this particular case

real thunder
#

how reasonable is the idea to make a huuge class containing all methods(behaviours) and data mob AI could do and then make children utilizing only parts of it?

#

I think of making a system where I could easily recombine different pieces of logic

#

can't think of something better other than going away from OOP which looks like alot of effort

cosmic dagger
real thunder
#

on second thought

#

Here is the raw madness of my code for what I got now
https://pastes.dev/gQqkQgHFgq
I mean it works but it's more of a draft of what should be I guess
Because it's very painful to expand and change
I guess I need some advices on how exactly to split it into classes

#

here is base and child classes

celest depot
#

https://paste.ofcode.org/kf87Hv8YKZFSsJJyvUnWVq hello guys. need some help here. yesterday, i asked for some help and i did change my script and the particle system worked based on their assigned role. but i faced a new problem. after i press the button and the ship stopped, the particle system keep playing when they should stop play. Is there any problem that i did not detect here? I tried to fix the problem for hours, but nothing worked.

real thunder
#

I guess you meant to use !IsPressed() or something
I dunno I don't use this input system

celest depot
#

When I use IsPressed, the particle system for yaw movement will play and stop while the particle system for strafe did not play at all. I did use that kind of code yesterday

#

Before I change to wasPressed and wasReleased

#

After I solved one problem, another one will pop out.

real thunder
#

I don't know what was wrong before, but this is what's wrong now

celest depot
real thunder
open stratus
#

Hi all

naive pawn
open stratus
#

can anyone tell me what is problem ???? my screen : 1280 by 720 but even I reach the edge it say 802

celest depot
naive pawn
#

ah wait

open stratus
#

I use OnPointerMove(PointerMoveEvent evt)

naive pawn
open stratus
#

OK thanks

dry pulsar
#

Anyone knows why I cant switch my Cameras?

twin cloak
#

on both of them

#

so you reverse what is current the active toggle is

wintry quarry
#

"set it to whatever it already is" does nothing

twin cloak
#

activeSelf = what is the status right now?

So you are basically saying: "Set the status to be what it is already now"

#

adding a ! will do "set it to the opposite of what it is!" which will swap your cameras

dry pulsar
#

Kk tysm guys

wintry quarry
dry pulsar
autumn verge
#

what's the distinction between a prefab and a scene?

solar hill
grand snow
#

many gameobjects + lightmapping data

autumn verge
#

I just made a change to 2 object in a main scene. I've installed a unity extension called asset diff, which will go through yaml files and output what changed in a human readable way. however I don't see the change reflected in the assetdiff output, nor do i see that it parsed the scene file, just one prefab file

solar hill
#

whats the prefab file called?

autumn verge
#

in git, the only diff is in the file that houses the scene itself

solar hill
#

and is your scene saved?

autumn verge
#

yes i've saved it

solar hill
#

if you changed their transforms in the scene then the scene file will show a change

#

and are the objects prefabs or just non prefab objects in the hiearchy?

grand snow
#

e.g. changing a var to 5 from the prefab current value

autumn verge
#

i just changed properties of objects in the scene

grand snow
#

unity doesnt always write changes to disk right away

autumn verge
#

i'm not entirely sure if what i changed is a prefab or non prefab object

solar hill
#

well it sounds like you changed a prefab

#

if the scene isnt showing changes

autumn verge
#

no the scene is

#

liek my changes work

#

i'm just confused why assetdiff isn't picking up the change

grand snow
#

if the change is still there does it matter?

polar acorn
#

Did you actually change a scene object or a prefab? If you have a 100% unmodified prefab with no overrides, it wouldn't surprise me that changing the prefab wouldn't change anything in the scene

grand snow
#

^ that is what should happen

polar acorn
#

It probably just has a pointer like "I got one of these guys in the scene" and lets the prefab handle it

autumn verge
#

i just wanna only commit that small change and not a whole mess of stuff

grand snow
#

then check your source control detected changes

#

instead of a rando tool

autumn verge
#

right, except like the diff in the scene is massive

#

which is confusing

polar acorn
grand snow
#

okay send a screenshot of the object in question in your scene

autumn verge
#

there wasn't, except the change i made

#

but unity is werid

polar acorn
#

So, if you changed something in the scene, and there's differences in the scene file, then what is the problem?

grand snow
#

inb4 fuck ton of unapplied prefab changes

polar acorn
#

That sounds like what you would expect

solar hill
#

supposedly

polar acorn
autumn verge
#

This is my gitkraken window, an example of the diff from there

grand snow
#

hmm yes changes and stuff

#

stop worrying about it

autumn verge
#

This is assetdiff

#

and i'm confusd about the difference

grand snow
#

one gameobject could be fucking massive in the scene file

#

ONLY if you use prefabs and apply all changes possible will your scenes be small

#

If you have no legit reason to even worry about this then stop

#

(such as collaboration with others)

autumn verge
#

i'm worried about long term maintainability

grand snow
#

see above message

#

utilise prefabs as much as possible to make scene change conflicts less likely

#

as use of many prefabs will ensure its easier to avoid conflicts with others

autumn verge
#

it took me 4 hours to get to a state where the project worked after the last guy left and i don't entirely sure why it started working lol.

grand snow
#

Sometimes you also just have to communicate who can work in a scene (unless you have unity VC scene merging)

autumn verge
#

same like when this branch i have to merge back into master

#

that's going to be a shit show

#

thing is that the way this was originally designed, there's one massive scene for the landing menu etc

grand snow
#

well i wont repeat myself more

autumn verge
#

i hear you

grand snow
#

split up stuff, be smart. use many scenes + prefabs to make stuff easier

#

sometimes a scriptable object to move out config from a prefab/scene helps too

autumn verge
#

i'm not sure if ill have time todo a major refactor this summer, but ill ask my prof

#

to clean it all up

swift crag
#

did you rearrange objects in the scene?

#

i'm actually not sure exactly how Unity decides to order each object in the scene file

#

(e.g. is it hierarchy order or FileID-based?)

#

notably, if you're editing a scene from an old project, Unity could produce huge changes in the scene when it reserializes it

autumn verge
#

i only checked out the branch and opened the project

swift crag
autumn verge
#

the issue is how to make the most of a shitty situation since there won't be that many more changes to it this summer

swift crag
#

If you want to minimize future version control churn, then consider AssetDatabase.ForceReserializeAssets.

I believe you can call it without arguments to reserialize everything in the Assets folder.

This will produce an enormous commit, of course, but you're getting it all over with at once.

#

I use this on my personal projects, so that I can more easily understand my diffs

naive pawn
swift crag
#

Making it a pre-commit step would prevent any "stale" data from ever making it into the repository. It is an appealing idea.

#

I'm just running it whenever I feel like lol

#

(even with this, Unity finds ways to insert random garbage into my commits)

#

yes, please generate new refids for some random hdrp asset, thank you!

naive pawn
#

a few times ive seen tilemaps get reserialized or some stuff shifted around i just discard the changes lol 😅

#

they do keep coming up, so this seems like a good idea to clear that up, thanks

#

if/when i get back to that project....

brisk robin
#
{
    private float starttime;
    private float looktime;
    private Quaternion startrotation;
    public override void EnterState(FPSPlayerStateManager manager)
    {
        starttime = Time.time;
        looktime = .25f;
        startrotation = manager.fpsplayer.transform.rotation;
        Debug.Log("We have entered peek behavior");
    }``` I'm having trouble with this class, which is of the Abstract class FPSBehavior State, where Unity crashes whenever I attempt to enter this state. I have other similar states that don't crash. Is there something here that seems like an obvious culprit?
slender nymph
#

if by "crash" you mean it freezes, then you should connect the debugger, cause it to happen again, then using the debugger you can Break All (the pause button), and taking a look at the main thread you'll see where it's actually getting stuck at.
if i had to guess, i'd say something else in this class is causing an infinite loop or infinite recursion (assuming it is actually caused by this class)

brisk robin
#

I mean the entire unity editor crashes, so the debugger hasn't worked

slender nymph
#

so the entire editor closes?

brisk robin
#

The entire editor freezes and I have to use task manager to stop it

slender nymph
#

then do what i said. connect the debugger first, then cause the freeze

wintry quarry
#

Or it's a red herring

brisk robin
#

Which debugger? The frame debugger?

slender nymph
#
calm nacelle
#

Hello, which is the most appropriate server to ask for help regarding coding in Unity?

slender nymph
#

here

calm nacelle
#

Ok, thanks!

cosmic dagger
#

unless it's super advanced crazy code genius stuff, then here would be fine . . .

calm nacelle
#

I'm not sure if it's advanced code since I'm a beginner in Unity programing, but I think is an intermediate question

cosmic dagger
calm nacelle
#

Ok thanks... So I was using Claude to learn the basics on how to create a Card game in Unity, and so far its being great, the AI made very few corrections... Anyway, I wanted to create a mechanic just like in Pokémon TCG Online, where you can attach an "item" card to the creature, or above the other card already on the board (DropZone)... That's where the AI began to get lost, it can't seem to fix/find the problem... So for instance I was looking for the simplest path I could use to make this mechanic possible in my game.

brisk robin
# slender nymph then do what i said. connect the debugger *first*, then cause the freeze

Ah, you meant a debugger in visual studio. Got it. ```public override void UpdateState(FPSPlayerStateManager manager)
{
while (Time.time - starttime < looktime)
{
manager.fpsplayer.transform.rotation = Quaternion.Lerp(startrotation, Quaternion.Euler(manager.triggerdata.hostilerotation), (Time.time - starttime) / looktime);
manager.DefaultWalk(manager.movespeed);
}

}``` seems like this was the issue. It was getting stuck at this While line. Changing it to "If" fixed the problem, but why is While wrong here?

slender nymph
#

the loop will run to completion before any other code can run. since the condition never changes, the loop can never complete, so no other code can run, and therefore the frame can never end (hence the freeze)

brisk robin
#

Oh, I would need a "Yield" line to tell it to wait until next frame to keep running the loop?

slender nymph
#

if it were in a coroutine, yes. since this is presumably called each frame, simply switching to the if statement like you've already done is sufficient

abstract pelican
#

Why did I start writing like this everywhere there is a singleton?

rich adder
#

im guessing its because its an uninitialized static rn

abstract pelican
rich adder
strong wren
#

I believe this is related to domain reloading

#

You need to reset static references if your project does not have domain reload enabled

rich adder
#

weird, I always have domain reloading off and never seen this

strong wren
#

I believe this analysis is provided by project auditor, which is included by default in new Unity versions.

rich adder
#

ahh makes sense then

abstract pelican
#

I used it once when I saw the news about it.

strong wren
#

Did you turn it off at some point? It should be enabled by default in projects created before Unity 6.6

#

Project Auditor might complain anyway as this option is expected to be removed in 6.8

pure flame
#

I m having an issue when trying to use InputActions.CallbackContext where whenever I add it to a script the input manager no longer recognizes it and I get a MissingMethodException: Method 'player_script.OnInteract' not found error when uusing that button.

#

code in question

naive pawn
#

the input manager? that's an old system thing, what exactly are you referring to?

pure flame
#

sorry no I meant the new input manager

naive pawn
#

there's nothing in the new system called that to my knowledge, can you show the thing you're referring to

pure flame
#

I am using the new input manager using the send messages sytem to link my script to the input actions system. But when I attempt to use the callbackcontext function it fails when I call it in runtime

naive pawn
#

yeah that's not called input manager

naive pawn
pure flame
#

apologies meant the new input system

naive pawn
#

there's a name right there lol

#

you can just say player input component and that'd be much clearer

#

the new input system has more options than just the player input

pure flame
#

it is 3 in the morning i am new and they are all very similar in name

naive pawn
#

it helps to be precise.

#

especially because they're all very similar

#

also, consider getting rest. self-care is a very important part of learning 😉
stuff will be much easier to work with once you have a refreshed mind

pure flame
#

working on a group final due tonight

naive pawn
#

ah, another one.

#

wait aren't you 3 hours overdue then

pure flame
#

nope still have 21 hours

naive pawn
#

ah

magic copper
#

https://pastes.dev/cfTrfK9fFE im using clade to generate script and like i wanted her to switch the run to jumpscare whenever player is in particular range where jumpscare include the camera and the animation starts with the enabling of the ai camera but when im close to her it shows no camera rendering

fair cedar
#

is it possible to make a post and ask questions here at the same time or is that considered cross posting?

keen dew
#

Make a post where?

real thunder
#

so I have prefabs such as: UI, Camera, Player
and I would really like them to cross reference each other when I add them on new scene
what is the most reasonable way to do that?
I mean I can do that on Awake but it's kinda... suboptimal?

eternal needle
real thunder
#

makes sense

#

I was trying to to assigning on OnValidate but that was not very optimal either despite working

eternal needle
#

OnValidate is for the editor

naive pawn
real thunder
#

I mean I ain't spawning new UI and player on playing

naive pawn
#

oh wait prefabs, nvm

#

Awake with ExecuteAlways is an option

real thunder
#

I probbaly can do that on Reset since it runs each time I add something

#

but then the order I add prefabs on scene starting to matter

naive pawn
#

since it runs each time I add something
what? add something to what?

real thunder
#

won't it run each time I put something in scene?

naive pawn
#

Reset runs when a component is added to a GO, not when a GO is instantiated

real thunder
#

oh

eternal needle
#

in which case it really doesnt matter how you do it, performance doesn't matter if its editor only. As long as it doesnt hinder your development

#

Although id wonder what you're actually doing in OnValidate in that scenario

naive pawn
#

you could also have them exist in an additive scene and not bother with having them in every scene

real thunder
eternal needle
#

If they just exist in the scene, honestly just take the 5 seconds to drag the reference

real thunder
#

each scene

#

assuming I remember each cross reference

eternal needle
#

If you have a ton of scenes where this becomes an issue, then you shouldn't have them exist in the scene in the first place

#

you should spawn them via code