#💻┃code-beginner

1 messages · Page 706 of 1

charred spoke
#

YesYouCan.gif

latent mortar
real grail
latent mortar
#

idk how to make a 2d game

real grail
charred spoke
latent mortar
charred spoke
#

Perhaps game development is not for you then ?

polar marsh
latent mortar
polar marsh
charred spoke
#

If you have finished the junior pathway you should have an idea of how to make pong. If not, sit down and break down the game into small problems then start tackling them one at a time

polar marsh
charred spoke
#

I was referring to the other guy who claims to have completed it

lofty mirage
#

I don't understand

#

don't you want to learn to make games?

fickle stump
#

@lofty mirage have you figured coroutines out?

lofty mirage
#

It was more to understand if there were some other ways of doing it I guess

#

but my "baseline" works

lofty mirage
#

If the latter, that's very nice! 🙂

fickle stump
lofty mirage
#

Oh no

#

go ahead haha

#

it was 50/50 so

#

Tell me

#

I'm very happy to help if I can

fickle stump
#

I lost the beeing nice gamble catcrymic

#

I think i figured it out.. gotta wait

lofty mirage
#

haahhahaa

#

Well basically if you use yield return you have to put the statements in a IEnumerator function

#

you can't start an IEnumerator function without StartCoroutine(IEnumFunc()); in my knowledge

#

the main important things I think

fickle stump
#

(public void StartCoroutine(int waitTime) { if (isCoroutine == true) { coroutine = WaitAndDisable(2); StartCoroutine(coroutine); } })

Wrote it like this and i think this fixxed this?

lofty mirage
#

Can you share WaitAndDisable too?

#

what did you change?

lofty mirage
fickle stump
#

( private IEnumerator WaitAndDisable(int waitTime) { yield return new WaitForSeconds(waitTime); })

lofty mirage
#

So what did you do different before?

#

Although I would rather write:
coroutine = StartCoroutine(WaitAndDisable(2));

lofty mirage
#

Isn't your end goal just to WaitAndDisable for 2 seconds?

fickle stump
#

nvm dind't fix it 😄

lofty mirage
#

In which case you would just write StartCoroutine(WaitAndDisable(2)) at the place where you want to WaitAndDisable 2 seconds

fickle stump
#

I'm still extremly new to coding so i'm just throwing paint at the wal and hope a masterpiece somehow comes int oexcistence

fickle stump
fickle stump
#

My issue is, that I'm having a button taht i want to click to continue with an animation but during the animation (which is the waitTime) I want to disable some ui element. This way I though there's a clean transition from color to black and then again from black to color

lofty mirage
#

disable, you mean so that it's not "clickable", or cannot be seen at all (and not clickable)

fickle stump
#

the later

lofty mirage
#

oh okay

#

do you know where in code you want to trigger the disable coroutine?

#

Maybe your UI button OnClick() triggers a function?

fickle stump
#

doesn't the coroutine disable itself after waitTime?

#

yeah it triggers the StartCoroutine fucntion

lofty mirage
#

well first of all I wouldn't call the function StartCoroutine()

#

because that is an in-built function name

#

so that may cause some problems

#

Maybe you can try:
OnClick() -> DisableButton()

using UnityEngine.UI;

private const WAIT_TIME = 2f;

[SerializeField] private Button myButton;  // you have to drag in the inspector

private void DisableButton() {
  StartCoroutine(DisableForTime(WAIT_TIME));
}

private IEnumerator DisableForTime(float waitTime) {
  myButton.enabled = false;
  yield return new 
WaitForSeconds(waitTime);
  myButton.enabled = true;
}
#

I just coded this on the fly on Discord for you

#

I think that should do it

#

don't forget using UnityEngine.UI

#

since I believe that you have a UnityEngine.UI Button element (?)

#

or is it just a gameObject?

#

if the latter, you can replace myButtonenabled by gameObject.enabled

fickle stump
#

so what I want to do isn't disable something temporary, but forever basically (if the player doesn't restart the level).
My intention is to waitTime, till the animation transition finished, then I'm going through two foreach loops: One to disable an array of Objects that shouldn't be active anymore after the anmation ended and one that enables objects that hsould then be visible

#

so I don't think disable button is the correct approach

lofty mirage
#

So you want to deactivate only after 2 seconds?

fickle stump
#

yes

lofty mirage
#

Maybe you can try:
OnClick() -> DisableButton()

using UnityEngine.UI;

private const WAIT_TIME = 2f;

[SerializeField] private Button myButton;  // you have to drag in the inspector

private void DisableButton() {
  StartCoroutine(DisableForTime(WAIT_TIME));
}

private IEnumerator DisableForTime(float waitTime) {
  yield return new 
WaitForSeconds(waitTime);
  myButton.enabled = false;
}
fickle stump
#

My button press:

  • Triggers an Animation
  • After x seconds disables ui
lofty mirage
#

so like this? (I updated DisableForTime)

#

you can replace the myButton.enabled by all the things you want to disable

#

here I put myButton data type because I don't know better your data structures

fickle stump
#

just game objects

#

so is setactive the wrong approach?

lofty mirage
#

SetActive() can work too I think

grand snow
#

to hide the whole button SetActive() is better
Otherwise changing the button interactable state is the other approach

fickle stump
#

Basically pressing the Button that's a child of Task_Front, disables Intro Anim and Background Black and trigger the Fade To Black Animation

lofty mirage
grand snow
fickle stump
#

i dont want to disable the button, but like everything .-.

grand snow
#

then do things to your parent container?

#

canvas group can be used to change the alpha of the whole object and its children

lofty mirage
#

Then like:
OnClick() -> DisableButton()

using UnityEngine.UI;

private const WAIT_TIME = 2f;

[SerializeField] private GameObject introAnim;  // you have to drag in the inspector
[SerializeField] private GameObject BackgroundBlack;  // you have to drag in the inspector

private void DisableButton() {
  StartCoroutine(DisableForTime(WAIT_TIME));
}

private IEnumerator DisableForTime(float waitTime) {
  yield return new 
WaitForSeconds(waitTime);
   introAnim.SetActive(false);
   backgroundBlack.SetActive(false);
}
#

What do you think of this @fickle stump

floral garden
#

Hi, i have a question , did a prefabs that need another instance like player component for it status or the gamemanager, it need to auto get it as yoou can’t drag and drop it in inspector

grand snow
#

There are many ways to do it, the beginner way would be to use a find in the player component.

floral garden
#

The best way is to use a script to create that prefabs then assign the ref it need ?

fickle stump
#

omg

#

my code was working the whole time

grand snow
fickle stump
#

i just fricked up the animation part

#

🤦

lofty mirage
floral garden
#

It happens don’t mind haha

lofty mirage
#

if it should be there since the start you can just drag and drog using a SerializeField

#

but if it's initialized during the game, then yes, you need to declare, initialize, and store the prefab in some variable in your script

floral garden
#

Nop, i try to make a dynamic spawn as it play on multiple scene but all my core systems is init only one time between scence change and at start but some is init later for optimisation MCSenkoThinking

lofty mirage
#

okay then scripted all the way then

floral garden
lofty mirage
#

wdym some variable itself?

#

You do use gameObject.function no?

#

function being whatever like .enabled etc.

worn peak
#

Would it be possible to make the start of an action depend on the keyframe of the animation? I wanna spawn a bullet at a specific time and was wondering, if I could use the keyframe of the animation to determine, when the bullet is supposed to appear

floral garden
#

Like trying to get the playerinputhandler that stored in the coresystem

#

!code

teal viper
eternal falconBOT
lofty mirage
#

Like a GameManager?

floral garden
#

Prevent multiple static instances

lofty mirage
#

What makes your PlayerInputHandler difficult to reference?

floral garden
#

(How we share code with past mod)

grand snow
#

if its a singleton then the player itself could retrieve the reference or just use the static field

#

otherwise as I said before, the class that performs the Instantiate() can also init state

floral garden
#

using System;
using UnityEngine;

public class NPCDialogueTrigger : MonoBehaviour
{
    #region Script Parameters
    [Header("Visual Cue")]
    [SerializeField] private GameObject visualCue;

    [Header("Ink JSON")]
    [SerializeField] private TextAsset inkJson;
    #endregion

    #region Fields
    private DialogueManager _dialogueManager;
    #endregion


    #region Unity Methods
    private void Awake()
    {
        visualCue.SetActive(false);
    }
    #endregion


    #region Methods
    public void SetInkJson(TextAsset newInkJson)
    {
        inkJson = newInkJson;
    }

    public void SetVisualCue(bool active)
    {
        if (visualCue != null)
            visualCue.SetActive(active);
    }

    // Trigger dialogue with this npc
    public void Interact()
    {
        if (inkJson == null)
        {
            Debug.LogWarning("No Ink JSON assigned to this dialogue trigger");
            return;
        }

        if (_dialogueManager != null)
        {
            _dialogueManager.EnterDialogueMode(inkJson);
        }
        else
        {
            // Auto Set Dialogue Manager if not set before
            if (CoreGame.Instance)
            {
                _dialogueManager = CoreGame.Instance.GetService<DialogueManager>();
            }
        }
    }
    #endregion

    #region Implementation
    #endregion
}

grand snow
#

ops

floral garden
#

I don’t know how to share with past mod

grand snow
#

you missed the 3 ticks at the start

teal viper
#

This is long enough to be shared via a paste site.!code

eternal falconBOT
lofty mirage
#

' ` '

#

this character

#

3 times

floral garden
#

Oh thx

worn peak
lofty mirage
# floral garden Oh thx

but sorry, I'm not too familiar with managing multiple scenes variables / objects at the moment

floral garden
#

Oh no problem

grand snow
#

I dont think there is more to say

floral garden
lofty mirage
#

Oh btw

#

I noticed you use the region thing

#

what is the point of it?

#

Just to click on region to "close" the visual for the code region in the IDE?

dull grail
#

Can someone give a direction where to look to make seamless 2d world like in Starbound, where player reach edge of the world and could just move forward without changing his position in code?

teal viper
#

And the player position is likely reset somewhere. Possibly on these edges.

dull grail
#

Thank you

lofty mirage
#

Yeah that seems to be the most likely

rugged beacon
#
    public static T CloneInstance<T>(this T obj) where T : class
    {
        var json = JsonConvert.SerializeObject(obj);
        return JsonConvert.DeserializeObject<T>(json);
    }

anyone has a better way of cloning a class instance beside creating a constructor with all the fields?

fickle stump
#

Someone got an idea how I can prevent clicking on UI, while a certain UI is active?

#

basically while my book is active, I don't want the user to be able to click on the buttons at the top left and the bottom right

hexed terrace
#

an image covering everything that blocks stuff you don't want to be clickable.

timber tide
#

disable the canvas raycaster is a quick solution

#

canvas groups I think have a sub property for that too?

hexed terrace
#

yep

fickle stump
#

and i'm so gonna take that xD

hexed terrace
#

Making it black and giving it 50% - 75% alpha helps make it obvious too

fickle stump
#

Ah wait this is the coding chanel, my bad

#

U're right, thank you

hot wadi
#

What do u guys usually use OnGUI() and GUI skin for?
I find the Canvas system is way more efficient when it comes to many UI tasks

sour fulcrum
#

nothing

grand snow
#

no one uses ongui for game ui anymore

sour fulcrum
#

actually i lie

i use it for a little debug console built into my package because i didnt wanna mess with prefabs in a package

grand snow
#

if its not real game UI its okay.
UGUI or ui toolkit are the 2 choices

sour fulcrum
#

i wish it was viable tbh

#

i like it's ability to avoid relying on components

grand snow
#

well ui toolkit only needs a component to draw the ui document

sour fulcrum
#

i get why its great in fully fledged projects but i have zero interest in using ui toolkit rn because i (afaik) can't do it all in c#

hexed terrace
#

You can do UITK editor stuff all in C#

#

I do not know if that's the case for game UI with it

#

either way, doing it all in C# or with USS/ UXML(?) .. it's an awful lot of code

grand snow
#

you can build ui with code for both but its gonna be a pain, more so I think for ui toolkit

sour fulcrum
hexed terrace
#

It's been prob 2yrs since I was messing with UITK editor stuff, I remember struggling to get the right element.. had to keep going into the debugui builder thing and going down all the various trees etc

silk night
#

yeah as soon as you get more complicated UI you dont want to do it in c#

#

UGUI is perfectly easy to learn and use

#

UITK isnt there yet imo

sour fulcrum
silk night
#

component pilled?

hexed terrace
#

that's unity though - everything is components

sour fulcrum
#

Like a majority of it is heavily reliant on monobehaviours utilizing transform positions

hexed terrace
#

RectTransforms!

grand snow
#

ui toolkit probably did the right thing and stopped using a gameobject for each element

silk night
sour fulcrum
#

If you want to stray away from Unity's own collection of monobehaviours i think there's not too much your actually reliant on (couple colliders and renderers, maybe some physics stuff). with the UGUI stuff though it's heavily tailored towards that setup

#

i'd prefer to control a lot of that stuff in code directly

silk night
#

no not really, you can recreate basically everything from a button to text to scrollviews

#

you can even look at the code of how unity did it, its included with the UGUI package

sour fulcrum
#

It's a tough ask when you have to deal with topics like batching and font renderering, unless i have been missing stuff

silk night
#

then stop reinventing the wheel 😄

sour fulcrum
#

i mean sure but that wasn't my point 😛

grand snow
#

immediate mode gui is convenient to code but not really ideal for a game perf wise

#

so ideally you migrate to a supported ui solution

#

Unity would love you to use ui toolkit but i've yet to change

hexed terrace
#

Doesn't have world space UI yet, not possible for anything VR or AR

grand snow
#

yea not sure how thats not possible yet, even via rendering to some render texture

silk night
# grand snow Unity would love you to use ui toolkit but i've yet to change

After going through the torture of using ECS when they announced it first useable and managed to make their own guide video obsolete after a mere 2 months and cancelling multiple solutions they praised in high tones to be the next big replacement, I dont touch new things in unity with a 10 foot pole until it has some adaption

grand snow
#

ECS has always puzzled me, they go to such amazing efforts to make c# be like a native lang and engine features seem to need whole new versions to even be usable with it

silk night
#

oh no the current version of ecs is fine and it makes sense they have to rewrite a bunch of engine features on the new coding style

#

but the way the handled the introduction was abysmal

grand snow
#

I've tried it but not had a big need to use it just yet. hopefully it improves more to be easily usable with most features

silk night
#

We currently still use the gameobject approach but our pathfinding runs on ecs in the background and then syncs the position to the enemies

grand snow
#

why not use burst jobs, seems like you almost are already

silk night
#

i mean its uses bursted jobs and data is handled on the ECS approach, its an entirely decoupled system from our normal code

grand snow
#

sounds like you have entities there for no useful reason but its working

#

unless they keep state re used all the time for pathfinding

silk night
#

yeah its not pathfinding that just runs once and we are done, its recalculating everytime the player walks more than 0.5 units and has local avoidance

latent mortar
fickle stump
#

ok i think i'm loosing it:
Shouldn't this literally toggle the object on mouse 0 click

fickle plume
# latent mortar Yes but I cant

No need to drag this out again. If you want to learn start with the link you've been provided, you can find comprehensive Pathways courses there.

hexed terrace
fickle stump
#

what does this last part do?
!toggleObject.activeInHierarchy if it's not active in hierarchy I set it Active, but does it also disable it?

sour fulcrum
#

toggleObject.activeInHierarchy is a bool, ! "flips"/"reverses" the bool

#

if on, off
if off, on

lofty mirage
#

Well here you have a list/array of objects

#

if it's active, it's made unactive (and conversely)

#

imagine a flicker

#

but each flicker "tick" is a function call

grand snow
#

wha

#

it should work so its probably just not called to begin with

north kiln
#

either that or a parent is inactive and it's trying to toggle the child

grand snow
#

oh yea, danger of not using activeSelf

fickle stump
#

yeah i found the isuse i think but this just confuses me more lol. For some weird reason I can only toggle it from the top and not from the sides of the object oô

grand snow
#

those weird mouse events are kinda shit

#

its better to use a collider + event system + IPointer events

manic sparrow
#

when doing aiming from a top-down camera, do i make a separate script or do i connect it to the camera itself or the player its following

fickle stump
grand snow
#

yea that system is funny and I dont fully know its rules

fickle stump
#

Aparently it's because of cinemachines near clip plane beeing too low

grand snow
#

those monobehaviour mouse functions have nothing to do with cine machine

fickle stump
#

then i'm confused why it suddenly works after i adjusted the nearclip plane

#

lol

#

oh

#

i know why 🤦

#

I've put invisible triggers between the camera and the object to check if an object leaves my grid

#

and the ray from the camera constantly hit those triggers therefor i was unable to click on the objects, since they were behind the invisible trigger. Using the near clip plane the camera ignored the triggers infront and went straight onto the objects

grand snow
#

If you use the event system way you can specify the layers it uses

#

(requires a physics raycaster as well to work)

fickle stump
#

Ok kind of a weird question but are you able to access a prefab via script and manipulate it during runtime?
My idea would be to have two buttons which can change the material of the prefab that will be instantiated.

#

the problem why i can't access the to instantiate object is because I first render a third material on it

#

(actually I think i can just use the buttons and on button click increase the index of a count and depending on the index before instantiating, assign the material [index])

silk night
#

but no, in a build editing a prefab would not be possible, the code for that is in the Editor assembly which is stripped during build

grand snow
#

thats not true. you can load the prefab asset and manipulate it but that will only survive till that loaded copy is GD'd

#

I dont know if unity re uses the same instance or not but probably a bad idea

silk night
#

Arent the methods for that in the editor assembly?

grand snow
#

you can load a prefab and modify the GameObject instance but its not actually modifying the stored state

silk night
silk night
#

sorry, misstyped "yeah" as "you" 😄

grand snow
#

tldr dont bother and modify the prefab instance post spawn

fickle stump
#

now that i think of it

#

ah no the way it currently works is that its loading the materials again from the prefab

#

so i somehow have to tell the object that will be instantiated that after placing it (mouse click), it should instead get the material that i selected earlier but not sure how i would do that

silk night
#
public class SpawnedObject : MonoBehaviour {
  public MeshRenderer Renderer;
}

public class Spawner : MonoBehaviour {
  public SpawnedObject Prefab;
  public List<Material> Materials;
  public int WhichMaterialToUse = 0;

  public void SetMaterialIndex(int i) {
    WhichMaterialToUse = i;
  }

  public void Spawn() {
    var spawned = Instantiate(Prefab);
    var spawned.Renderer.material = Materials[WhichMaterialToUse];
  }
}```
#

Just a simple example, then you just have to set the buttons up to use the SetMaterialIndex function

#

Unless I understood your problem wrong 😄

hexed terrace
#

public SpawnedObject Prefab;

This is the best way to spawn prefabs, don't declare them as GameObject - declare them as a component on the root, so you get a reference to that with the spawning.

grand snow
#

(unless using addressables where we cant 🙁 )

shell sorrel
#

depends on how you load things

grand snow
#

yea if you load the prefab then instantiate yourself it works

#

I dont get the benefit using InstantiateAsync() when the fuckers cant release themselves

shell sorrel
#

i find i do not use it often, also often i am not using addressable references either

#

since i am loading a bunch of stuff via a tag somewhere then doing stuff with it in the future

hexed terrace
grand snow
#

yea its just an extra get component

#

as long as you remember to release the gameobject later its fine

hexed terrace
#

addressables are horrible to work with, if stored remotely - hate them

grand snow
#

Ops this local thing has a remote dependency fuck you!
The effort I had to put in to ensure this didnt happen was mad

shell sorrel
#

are fine no worse then assetbundles owrkflow for remote stuff

fickle stump
#

Just gonna ask for the sake of it

#

How much of beginner are adressables

#

Because this is the first time hearing that

grand snow
#

0 much is beginner

hexed terrace
#

They're not for beginners

#

Beginners won't be doing anything that needs them anyway

shell sorrel
#

its more a feature only needed to learn about when a game gets big or for production etc

fickle stump
#

Okay then i'll try avoid to do that and work wuth the basic first

shell sorrel
#

it will jsut add confusion learning it before having a good grounding in other stuff

fickle stump
#

Altight cheers, gonna steer away from them for now then

#

Maybe in 1-2 years

fickle stump
#

Thats what i tried to communicate hahs

#

Actually a good question actually, when would you consider people not beeing beginners anymore?

silk night
shell sorrel
rocky canyon
#

imo ur always a beginner in certain aspects.. theres things you'll do more often then others.. and some things you may never use

#

mixed bag

silk night
#

Whenever I have to look at shadercode I feel like a programming toddler again 😄

#

thank god for shadergraph

shell sorrel
silk night
shell sorrel
grand snow
#

Its worth being able to write shader code as some things still need that

silk night
grand snow
#

though be warned, urp/hdrp lit shaders will make you go mad

shell sorrel
#

yeah current game is using heavily stylized shading

fickle stump
shell sorrel
#

so i more or less wrote the whole lighting model in a few includes so it can be called from shaders in a simlar way as the surface shaders of the past

silk night
rocky canyon
#

might as well be alchemy to me.. (atleast for now)

shell sorrel
#

even know i prefer writing shaders in code now, learning with the graph i think is best

#

you get to see the output for each and every step which is huge when learning it

grand snow
#

Shaders can seem difficult at first as its different vs cpu code

silk night
#

only thing ill have to stick my nose into is compute shaders

shell sorrel
#

really i think most people just treat it like this weird black box and never look at the details

floral garden
#

!code

shell sorrel
#

alot of it is just math straight up math and thats it

eternal falconBOT
grand snow
#

I guess you can but you need to understand at some point how the end result is being produced by a shader 🤔

#

Ofc simplest is uv -> sample texture -> output color

shell sorrel
#

now things get complex due to complex problems to solve not the shader part its self, like a full PBR lighting model is alot of stuff write and learn

#

where like ramp shading, cel shading or like a lambert+blinn is like 100loc of hlsl or so

fickle stump
#

Fun story: kinda sad but I'm actually a game deisgn student and i hope pray that I'll land a position in the industry as a leveldesigner and right now I also try to stick my nose into a bit of coding, just to understand everything atleast a little bit c:

#

(and ofc i have to submit projects for uni, so i kinda have to code)

hexed terrace
#

How long have you got left?

fickle stump
#

1 1/2 years

shell sorrel
#

good you got some time left, hopfully the industry will rebound by then

fickle stump
#

1 year was everything non game related, then had two semester/courses for game related stuff, then an internship at a completly different branch cuz yey internships and now two larger projects and my bachelores and I'm done

fickle stump
#

The leveldesign thing is just something I always wanted to do at some point in life. Doesn't have to be in the next 2 years or sum

shell sorrel
#

so QA into design is fairly common

hexed terrace
shell sorrel
#

problem with design is most studios do not need many

fickle stump
#

and here I'm getting told so many ppl need leveldesigners catcrymic

shell sorrel
# hexed terrace I think it's gonna take longer

think large studios will not rebound for a long time, but i can see more like mid sized indie and AA starting up to fill a void in the near future. Hard to say, like a lot of talent was cut loose but also getting investment is very hard right now

silk night
silk night
#

yeah well then you have the choice of berlin, munich, cologne and hamburg as the big 4 in game dev

#

Also if you are considering europe in general poland and netherlands are good places to be

shell sorrel
#

it is crazy how much stuff changes, like way harder to get dev jobs now, vs a decade ago i accidently got a dev job

silk night
fickle stump
#

literally as soon as im about to graduate theres an influx of people joining hte industry

fickle stump
#

are u guys gamedev in the industry or is efveryone doing htis as their freetime fun

hexed terrace
#

think large studios will not rebound for

silk night
#

Did this for fun for about 6 years while doing web dev, then got an offer from a game company and switched, doing it professionally since 2019 now

summer shard
#

hi, my power went out mid coding and when i booted up the project it showed like the script references and said 'The associated script can not be loaded' and i've removed the script from the objects and tried to add it again but it's not on the list, the name of the file is the same as the class name so idk what's the problem

thorn imp
#

is there a max size for native arrays? when i make my native arrays too big they seem to break. idk if its an issue with my code or native arrays start to break with too much memory stored

eternal falconBOT
hollow slate
summer shard
summer shard
polar acorn
silk night
hollow slate
#

oh, that's right.

summer shard
silk night
#

as you made the properties protected it seems like some kind of inheritance was planned

dull grail
#

Does unity hierarchy not saved by a git normally? I've made a lot of mistakes and decided to regenerate project from git but now i see empty hierarchy

shell sorrel
#

hierarchy is part of the scene, so did you save the scene and commit it

#

or did you open the correct scene again after getting the project from git again

dull grail
#

Oh, looks like they weren't added to vc, only see scenes.meta and empty scenes folder. Thank you

grand snow
#

ops

floral garden
trail heart
naive dirge
#

Sorry!

dense ridge
#

I NEED SOMEONE WHO KNOW HOW TO MAKE A GTAG FAN GAME

polar acorn
dense ridge
#

What was that for

polar acorn
#

You looked like you needed the info

#

I assume it was on and you couldn't figure out how to disable it

dense ridge
#

I did

#

I'm trying to make I gorilla tag fan game

#

Do u know someone

polar acorn
#

Yes. You.

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

dense ridge
#

Ok

frail mango
#

i'm feeling pretty stupid, how can I refine the position of my object?
When I target the tile I want to place the pointy arrow thingy at (mouse cursor at that moment is at purple circle), the way I'm rounding off the MouseToWorldPosition values make it appear I suppose rounded off to the closest number (cuz math) which places the tile to the lower left of where I actually want it to be targeted.

Now I totally suck at math, which is obviously a very good trait for any programmer to have, but how should I go about actually placing it on the tile that the mouse is hovering over, rather than rounded off to the wrong spot.

The code I'm currently using is

Vector3 screenToWorldPos = Camera.main.ScreenToWorldPoint(new Vector3(Mouse.current.position.x.value, Mouse.current.position.y.value, Mathf.Abs(Camera.main.transform.position.z)));
transform.position = new Vector3(Mathf.Floor(screenToWorldPos.x), Mathf.Floor(screenToWorldPos.y), screenToWorldPos.z);```
#

using Mathf.Abs for the Z position because it's currently set to -10 and I didnt want the offset to be hardcoded whenever I change the camera position above the grid

#

the grid by the way, is just a tiled sprite

#

(i wont have access to my pc for the next 3ish hours or so so I'll be responding via phone)

vagrant mist
#

Is it bad practice for now to have an EnemyTypes script that looks like this...

public class EnemyType : MonoBehaviour
{
    public enum Types
    {
        Melee,
        Ranged,
        Tank,
        Flyer
    }
}
polar acorn
vagrant mist
#

idk, didnt know that was an issue, I was doing it to reference in my EnemyHealth script and EnemyPathfinding script to assign different health values and chase behavior without giving each enemy their own script or sharing the same stats

polar acorn
#

You can make a file that contains just an enum

timber tide
#

Use a namespace

polar acorn
#

it doesn't need to be inside a class

rough granite
vagrant mist
vagrant mist
rich adder
#

they are constants so it becomes part of the class

rough granite
rich adder
#

eg EnemyType.Types.Melee

#

sometimes it makes sense to only keep within a specific class, sometimes it doesn't

vagrant mist
timber tide
#
namespace Entity
{
    public enum EnemyType
    {
        Melee,
        Ranged,
        Tank,
        Flyer
    }
}

namespace Entity
{
  public class Enemy: Monobehaviour
  {
    [SerializeField] private EnemyType enemyType;
  }
}```
polar acorn
#

The file can literally be just the enum

#

an enum is a type, it doesn't need to be in an outer scope

timber tide
#

I'm lazy I just stick it in global usually

vagrant mist
rich adder
#

being in the same file doesn't make any difference

timber tide
#

Doesnt matter if it's in the same script, but you can have that in a different script

#

Monobehaviours however do require to be in different scripts and SOs

#

cause Unity

rich adder
#

yea the only thing Unity cares about is not putting Two MB or SOs in the same file

timber tide
#

As in no two monos

polar acorn
rich adder
#

imo in the same file is poor organization

timber tide
#

Nice to have a EnumUtility script, otherwise nesting them

vagrant mist
#

I dont have a general Enemy class script atm, just separate ones that handle their health, pathfinding, and damage individually.

#

how would I assign one of the enums to different enemy Objects?

grand snow
#

components are good but i would not go that granular myself

polar acorn
vagrant mist
#

so like in the EnemyHealth script, I would put

enum Types types;

then

types = 
rich adder
rich adder
#

the Types enum becomes the type

polar acorn
#

This shows both how to define an enum, and how to create a variable of the enum type

vagrant mist
vagrant mist
# polar acorn

[SerializeField] private EnemyType enemyType;

is an example of how it would look in a script

#

correct?

polar acorn
#

Yes

#

that would be creating a variable of type EnemyType and assigning it the name enemyType

rough granite
polar acorn
#

It currently does not hold a value

#

You would need to assign it, probably in the inspector

rich adder
#

and when not assigned, by default the first item is used.
so by default enemyType would be Melee

#

Value types are never null

polar acorn
#

Right, my bad. I wanted to emphasize that declaring it is different than assigning it and chose my words poorly

vagrant mist
#

can you just drag and drop the enum file in the inspector and assign it there?

rich adder
#

its like saying , do I need to drag the integer class to assign public int myNumber

polar acorn
#

You don't drag it anywhere

#

It allows you to create a variable of that type in other scripts

vagrant mist
polar acorn
#

Put a variable of that type on a script

#

then look in the inspector

vagrant mist
#

alright

manic sparrow
#

do you guys have any guides to recommend regarding learning scriptable objects, monobehaviors, game objects, their differences and discerning when to use what?

vagrant mist
#

I can assign the enums, that was so difficult to comprehend for the first time

eternal falconBOT
#

:teacher: Unity Learn ↗

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

rich adder
#

and !docs

eternal falconBOT
manic sparrow
timber tide
#

Monos require game objects, scriptable objects do not.
Monos exist in the scene or as a prefab in your directory, SOs can only exist in your directory or inserted as a property into a game object

#

Also worth learning the differences between just plain c# data vs a scriptable object

red igloo
#

I'm making a first person games using cinemachine. I am making it follow the player by doing this > vCam.transform.position = transform.position; this works but how can I change the Y position? when I press play it changes the Y position.

rich adder
#
var targetPos  = transform.position
targetPos.y = whatever;
vCam.transform.position = trargetPos``` or 
`vCam.transform.position  = transform.position + new Vector3(0, yOffset, 0)`
#

I thought Cinemachine already had such components you can play with offsets though 🤔

remote lynx
#

pipeline design pattern and typed registration is goat

#

😍

grand snow
#

Cinemachine does yes

serene oriole
#

do you guys know how to fix this error

foggy yoke
foggy yoke
serene oriole
#

idk how to code ;9

sour fulcrum
serene oriole
#

how do I use the new input manager

sour fulcrum
#

have you googled it

serene oriole
#

no

foggy yoke
#

Google is your best friend

sour fulcrum
#

did you know you can google it

slender nymph
foggy yoke
serene oriole
#

-ye

fleet prairie
#

any tips I have to make a small game as my FYP in like a year (3D game) any ideas. I really want to do this so does anyone have a roadmap (Also I dont want to use chatgpt or any AI tools I want to learn as I make the game)

serene oriole
#

thks

slender nymph
eternal falconBOT
#

:teacher: Unity Learn ↗

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

fleet prairie
ivory bobcat
fleet prairie
#

easy on the perfomance

#

nothing to high-fidelity

#

its sort of like a backrooms type game

#

with a few unconvential gimmicks

fleet prairie
foggy yoke
#

yep

#

that'll take you years

#

im joking

#

but multiplayer is REALLY hard

fleet prairie
#

Iam curenntly working on a prodecurally generatred maze atm

#

and liek I created a simple fps character sript

#

following a video

keen onyx
fleet prairie
#

had to skim though like 5-6 videos to get actuall understand it

#

but when I did it was so satisfying

fleet prairie
#

scared me there for a bit

foggy yoke
#

I think you shouldn't start with a fully fletched multiplayer game.

fleet prairie
#

so I first go with a singleplayer

#

right?

foggy yoke
#

I would

#

but that's my preference

fleet prairie
#

I mean not gonna lie thats actually a good idea

foggy yoke
#

you could tackle multiplayer

fleet prairie
#

first comeplte the game on single player

#

and then transition to multiplayer

#

never thought about it like that

foggy yoke
#

yes, but once again, multiplayer is REALLY REALLY hard to make

fleet prairie
foggy yoke
keen onyx
fleet prairie
#

I really appreciate it

foggy yoke
#

Of course

#

Ask any time!

sour fulcrum
late phoenix
#

Does anyone know why this keeps showing up, im kinda new to Unity.

sour fulcrum
#

Just learn yourself with google and learning resources.

fierce crow
#

so im following a tutorial about how to create a action system and these are the two functions to subscribe and unsubscribe Action delegates to a static dictionary and in the tutorial they are putting a wrapper function on it.
the problem is I'm not sure if the "wrappedReaction" in the subscribe and unsubscribe function are really equal and subs[type].Remove(wrappedReaction); will work or not

timber tide
#

Well, have you tried it?

#

Tutorial really trying you save you line space that's for sure

fierce crow
#

actually it's me trying to save line space because i'm not familar with these kinds of syntax. and yea i should probably try it before asking :(

timber tide
#

Alternatively, instead of using ScreenToWorld, you could just make yourself a large quad collider as the grid you raycast upon, or use Plane

subtle sedge
#

if i wanted to create a game similar to paper mario i would have to use unity 3d version right?

timber tide
#

ye, but secretly Unity is always 3D anyway

frail mango
#

here's a shitty phone recording

timber tide
#

start debugging the values you get back

fierce crow
subtle sedge
#

i really want to recreate pokemon black and white in unity tho

#

but i have to learn 3d stuff ;-;

timber tide
#

3D is easier than 2D

sour fulcrum
frail mango
subtle sedge
timber tide
viral flax
#

Quick question, what's the best way to fire ray-cast from inside a trigger (collider) and still hit it?

For instance, you have a trigger representing Water, and you get different reaction from shooting at it and from within it.

timber tide
#

Now I question if overlap would work if it doesn't intersect at all

rich adder
#

rays by default dont detect the inside of collider but you can enable

timber tide
viral flax
#

I should probably mention that In this case it's a 'blind' cast, so I am not casing against any particular entity, I am only testing if something gets hit by the raycast; generally a collider.

sour fulcrum
#

why

rich adder
#

maybe they're doing a laser alarm that goes off when object goes in it 😛

viral flax
#

I gave one example. Another is for instance a ladder trigger - the player presses USE on the ladder and attaches themselves to it. Once inside, they can dismount by pressing USE on the same ladder, but if I'm already inside the trigger, I will never hit it with a normal raycast.

sour fulcrum
#

but why do you need to raycast while your inside the ladder

viral flax
#

How else do I detect what object is the player looking at? I'm looking for reliable methods for this exact purpose.

sour fulcrum
#

when you are on a ladder

#

do you want to know that the player is technically looking at the ladder trigger collider

viral flax
#

Well, ideally the collider and the ladder trigger are the same thing. Of course I can offset the collider or add additional entity for no reason, but that's just bad design - it's incredibly easy to create discrepancy. Of course, the representation of the ladder is different from the ladder trigger.

timber tide
#

when you enter the ladder you'd probably want to subscribe to it with OnTriggerEnter so this way you know you're inside of the collider

sour fulcrum
#

Well, ideally the collider and the ladder trigger are the same thing.
What do you mean by this? That also doesn't really answer my question

timber tide
#

as long as you're subscribed you know you're inside of the collider

#

otherwise it seems bounds is the idea, otherwise nav's idea of backface checking but it means your ray must intersect completely

viral flax
#

It currently works similar to HL2 in my case. You can either attach yourself to the ladder if you interact with it from a distance, or by jumping/touching it. That's just the way it is designed, and I only need the simple operation of detecting what entity the player is looking at, including if they're inside the collider.

#

It's not a matter of debating the design, but finding ways of raycasting from the inside of a collider and hitting it.

sour fulcrum
#

in source players are not inside the ladder collider

stark prawn
#

im making a scene manager but i dont want to add each scene a manager what should i do

viral flax
sour fulcrum
#

no?

lament drum
#

hi guys so I'm trying to make my character go up and down the Y axis in unity and the code works but it doesn't move inside the game pls help me.
Here's the code

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

public class FirstPersonFly : MonoBehaviour

{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("Jump!");
        }
    // Fly ??
        
        float moveSpeed = 40.0f;
        float dt = Time.deltaTime;
        float dy = 0;
        if (Input.GetKeyDown(KeyCode.Alpha8) == true) 
        {
            dy += moveSpeed * dt;
        }
        if (Input.GetKeyDown(KeyCode.Alpha2) == true)
        {
            dy -= moveSpeed * dt;
        }

        // float Vertical = 0f;
        // if (Input.GetKey(KeyCode.Alpha8)) Vertical -= 1f;
        // if (Input.GetKey(KeyCode.Alpha2)) Vertical += 1f; 
        // 
        // transform.Translate(new Vector3(Vertical * Time.deltaTime, 0, 0));
        
    }
}
sour fulcrum
#

they are snapped onto the face unless im mistaken

viral flax
#

You are mistaken. There is a trigger.

sour fulcrum
#

i am aware there is a trigger

viral flax
#

Good. That doesn't have any relevance to the problem. I will try to search for the answer elsewhere.

sour fulcrum
#

okay..

stark prawn
sour fulcrum
#

(was relevant)

timber tide
trim burrow
#
    {
        if (slowedDown == false)
        {
            Time.timeScale = time;
            slowedDown = true;
            Debug.Log("sloweddown");
        }
        else if (slowedDown == true)
        {
            Time.timeScale = 1;
            slowedDown = false;
            Debug.Log(slowedDown);
        }
       
    }

        (This is inside an update function)
        if (Mouse.current.rightButton.wasPressedThisFrame)
        {
            SlowTime(0.1f);
            slowedDown = false;
        }```

Why dosn't the debug message show up in my console when i right click? The time slows down correctly but for somereason i dont get the debug message
timber tide
#

but if you have references to the main scene on scene change it will lose them on the manager

#

so if each scene has unique data for the manager, then maybe making a unique manager for each is the idea

stark prawn
#

but i cant add the functions of the scene manager that in another scene

timber tide
#

right, so manager each scene it is, otherwise you need to dynamically link it all at runtime

#

ex. change scene -> level scene gameobject on awake call thes scene manager and binds itself to it

stark prawn
#

I wanna add a function of the scenemanager in game scene but in gamescene i have no scenemanager game object. So i cant add it manuelly that is the problem. is there any good solutions besides adding each scene a manager

timber tide
#

what needs to be added to the scene manager on scene load

frail mango
stark prawn
#

when i load another scene i want to use the same scene manager for the other scenes scene changing button

timber tide
#
public class SceneChangingButton: Monobehaviour
{
  private void Awake()
  {
    SceneManager.ChangeButton = this;
  }
}```
#

that's the dynamic solution for 1 scenemanager singleton with DontDestroyOnLoad

stark prawn
#

what does changebutton mean

timber tide
#

"other scenes scene changing button"

stark prawn
#

ohhh

timber tide
#

Idk, any data you wanna bind, it needs to be done on scene load in awake. Just a solution, there's many others

lament drum
stark prawn
#

but i have more than one button in a scene

timber tide
#

well. gotta do it for them all then

stark prawn
#

i want to add manually

timber tide
#

or, just make a scene manager on each scene and drag those references on the inspector <--- easier

stark prawn
#

ok ill add scene manager to all scenes

#

can i ask one more question

#

i want to make a button from a sprite

#

but when i add component i cant click it

#

should i use ui for it

#

or is there any other way i can use

#

just sprite

timber tide
#

you need to look into how to raycast a spriterender

#

UI stuff already includes raycast logic, but if using UI doesn't make sense then you probably shouldnt

timber tide
eternal needle
lament drum
#

oh

#

so to make it move my character I gotta call it inside? I thought I just needed to drag and drop the code on it sorry

stark prawn
#

i want to add a text on sprite square how can i add

polar acorn
eternal needle
plain oasis
#

Anyone knows how to chain multiple formatter together in smart string? For example, {0:formatterA():formatterB()} something like this.

grand snow
#

what is a smart string 😆

wintry quarry
#

I think they mean string interpolation

grand snow
#

you can use string.Format() to replace named placeholders such as {0}

#

otherwise yea with string interpolation you can provide a ToString() format str like you did kinda

#

If its mad just do .ToString()

#

$"{thing.ToString(Func())}";

plain oasis
grand snow
#

then you do need string.Format()

#

Unless the unity localisation can do extra functionality

plain oasis
wintry quarry
polar acorn
plain oasis
#

Can not find the syntax in the documentation.

polar acorn
#

$"Damage is {(attack + 3.5*5).toString("0.00")}"

grand snow
#

string.Format() is easier as you know what you are getting

#

"Damage: {0}, other shiz: {1}"

#

and as its ordered it works good in translations

plain oasis
#

string.Format is C# right? I was trying to avoid coding directly to allow designer/translator to do that inside the localization file.

grand snow
#

the {0} tokens go in the actual string

wintry quarry
grand snow
#

they do have to know what they stand for

#

when ive used gridly i leave an example in the context column

plain oasis
#

passing {0} directly meaning {0} is the calculated result? Which mean I need to hardcode the calculation inside code?

grand snow
#

yea in code you need to provide what {0} is replaced with

#

if you want actual maths in string thats a whole other ball game

#

I recommend not trying to do that

wintry quarry
plain oasis
#

I have already achieved that by writting a custom formatter for smart string.

#

Just not sure if native smart string can have chained formatter

stark prawn
grand snow
#

you may need to change the render layer and or layer order

#

(on the tmp text)

vocal urchin
#

I'd like to be able to visualize systems when I'm making new systems or doing big refactors. Do yinz have any way you like to accomplish that? Any good tools?

faint narwhal
#

anyone know how to combine multiple splat maps together in a .shader file so you can add more than the 4 RGBA layers to your material? this is what I have so far as you can see in the screenshot but I'd like to add more layers but I need another splat map so that I have more color channels available to assign as a layer.

grand snow
frail mango
rough granite
#

so silly question but is there a way to keep two value types from different class to equal each other without needing to call it in update each frame? ie keeping the float playerHealth to equal the CurrentHealth in the other playerHealth = StatsController.CurrentHealth;

grand snow
#

nope, you have to either copy the value when the other changes or keep it in some class that both objects can reference

#

float is a value type so always copies

rough granite
#

this feels kinda inefficient though

grand snow
#

yea it is so you should stop 😆

#

its also going to give you bugs and problems, how do we know what value is the "real" one?

#

have this data be kept in a class instance that multiple things can reference

#

then its a non issue

sour fulcrum
#

This yearns for properties

rough granite
#

had no clue what i was doing even though this was only 10 months ago

rough granite
sour fulcrum
#

with properties you can do

PlayerHealth { get => StatsController.CurrentHealth; set => StatsController.CurrentHealth = value; }

Then you can touch PlayerHealth like it’s a field but it’s actually two functions in disguise that just point to/forward the statcontroller value

rough granite
grand snow
#

a property with a get and set is not a variable

#

its a fancy getter and setter function

rough granite
sour fulcrum
grand snow
rough granite
#

what's the => do in this case

polar acorn
#

Properties are a pair of functions in a trenchcoat pretending to be a variable to get into an R-rated movie

grand snow
sour fulcrum
#

You define a get for what happens when you want to read from a property and you define a set for when you want to write to a property

rough granite
#

does it matter that it's declared at the same time as when the reference for StatController is in the class? or no since it's not a var

grand snow
#

the getter and setter are just functions so it can do stuff with a class field (and other stuff a function can also do)

#
public float SecretFloat => secretFloat;
private float secretFloat;
polar acorn
sour fulcrum
#

We solve the problem of you syncing 2 values by just having 1 value accessible from two different points

grand snow
#

back to the actual topic, you can keep the data in a class instance and use it via that or declare a property to "aid" in using that to avoid doing that weird copy in Update() @rough granite

#

check the docs for more info about properties if needed 📖

rough granite
#

will do, another question though SO's can there only be one instance of them in a scene like static classes or can i make multiple instances?

polar acorn
#

Each file on disk you've made from an SO is one instance of that SO

#

it lives in a file rather than in a scene

grand snow
#

and you can reference a scriptable object file as much as you want

rough granite
#

so if i wanted to reference a SO class would just giving it's name work or do i need the specific instance :?

floral garden
grand snow
#

err

rough granite
grand snow
#

I sense miss understanding 🙏

polar acorn
#

Probably.

rough granite
floral garden
#

sorry

rough granite
grand snow
#

scriptable objects are a way to define a new asset type with data you want, just like a material or model or texture

floral garden
#

oh I see

rough granite
# rough granite probably lol

what would the best way of having a single instance class that doesn't need to be strictly referenced by using, but can be used by many different classes (and not static) [SerializeField] StatsController StatsController;

rough granite
rough granite
grand snow
#

you can probably just have a normal class to hold these stats

floral garden
#

I forget what is a singleton MCSenkoThinking

#

a static instance ?

rough granite
polar acorn
grand snow
#

^ the singleton pattern is good but more applicable for a MonoBehaviour

#

Perhaps a class to hold stats is used AND you have a reference of it in a singleton game manager?

rough granite
#

but does having it as a basic class limit it to one instance :?

grand snow
#

no?

rough granite
#

:/

floral garden
#

whut ?

grand snow
#

Learning c# only with unity can lead to these weird thoughts 😆

sour fulcrum
#

MonoBehaviours are base classes with a couple layers of inheritance stacked up on it

rough granite
sour fulcrum
#

base class -> Object -> Component -> Behaviour -> MonoBehaviour

floral garden
#

oh

grand snow
floral garden
#

learning something new

grand snow
#

but everything can be an object

rapid laurel
#

guys, can someone help me? I am making my first game, I added a Character Selection screen, but when I load the player character into the game, while the character is walking it changes back to the default skin. How do I make the animation change according to the skin selected?

floral garden
#

i like this advice

floral garden
rapid laurel
floral garden
#

the best way is using sprite resolver + sprite library

#

i am working on it so i can't help you more anibabyblush

rapid laurel
#

thank you for your time

fickle stump
#

Me handing in my exams like:

floral garden
#

what have you send ?

fickle stump
#

nawh :c
SO! Question: You guys think it's a good way to learn with books, courses or just start something and try working from there

fickle stump
floral garden
#

theory and practice is 2 different thing

nova kite
#

Hey! Do you guys know of any great sources to not just learn about the SOLID approach but also understand how to develop your own logic to implement it? I really like it but having a hard time coming up with it myself.

floral garden
#

You need to understand how it work then you can implement it by yourself

#

Tuto is a way but in code, you have a lot of way to archive a fonction

#

Some more optimism, other more easily or shorter

teal viper
nova kite
#

Like I know the premise

#

And separation of logic

#

But it’s hard to visualize it and make the flow chart and diagram🥲

rough granite
#

when you try and implement something what are you thinking?

nova kite
nova kite
#

And then everything I learned the past week mixes in my head and I’m like “should I use a scriptable object for this? Or an interface? A static? Composition inheritance instance?” And then I don’t know which to choose

teal viper
teal viper
rough granite
nova kite
#

But if it’s truly just experience I guess I’ll have to crawl through it for now🥲

nova kite
nova kite
teal viper
nova kite
#

But I often gets stuck on the digram alone🥲🤣

nova kite
#

And then I learned all the advanced techniques and OOP principles

#

And it’s much less overwhelming this way I really like how organized it makes it in my brain

rough granite
teal viper
nova kite
#

Ohh wow! You went as far as learning the physics for it too

nova kite
rough granite
nova kite
#

I feel you on that, I don’t even wanna touch physics or math logic for now🤣

rough granite
#

annoyingly enough it's hard to find just straight physics equations on google

nova kite
#

It takes me two hours just understanding reading code that implements physics calculations lol

faint narwhal
nova kite
#

Would using GPT for SOLID logic only help?

#

Like spitting code at me to iterate over

teal viper
nova kite
#

Oh I revamped the script altogether haha I copied all of them into legacy dupe scripts and I’m re building it from the ground up😅

#

I made like 13 scripts that handle things separately using interfaces

#

I love interfaces tbh haha

teal viper
rough granite
#

what's SOLID logic :?

nova kite
#

Or structure

teal viper
#

Solid don't dictate any of this.

nova kite
#

I watched in a video that it was said in a way of like “not violate the rules of the solid system” something among those words

teal viper
#

They're just guidelines to keep in mind when you implement your own structure.

nova kite
#

Yes guidelines haha

#

I like it, it gives me like a base to go off of

#

Something to follow

#

So I don’t just free roam and make a mess

rough granite
nova kite
#

Next I really want to learn Events and State Machines because I believe they will be helpful too

nova kite
#

I for interface

teal viper
rough granite
#

well no i know that but i mean is this the silly principle that people use for why they have silly naming conventions such as the I for interface and _ for private variables or whatever

nova kite
#

I like the I but dislike the _ 🤣

rough granite
nova kite
#

It lets me know what the blue print is and what no to attach to game objects

#

At first I disliked interfaces because I was like “I really need to make a whole script for like 10 lines of code?” But then I saw how much it organized everything

cyan crescent
#

Does anyone use Yarn Spinner here? How can I trigger an interaction dialogue using an action key without running it at the beginning of the game? Just played around with it yesterday and just started coding last week, any basic help would be appreciated.

mystic flume
#

i just finished learning vector3 and raycasting what should i do now

rough granite
mystic flume
mystic flume
slender nymph
#

rather than studying random topics, consider going through a structured course that teaches you the concepts you need to understand in a structured/ordered manner such as by using the pathways on the unity !learn site

eternal falconBOT
#

:teacher: Unity Learn ↗

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

wintry quarry
lofty mirage
#

motivationally speaking

floral garden
#

Makz a game depend what you want to make

median mortar
#

Hi guys, could there be an issue with the representation of eulerAngles in code?
I'm trying to limit the rotation on the X-Axis of my object by converting the presumed new rotation to euler, check if the rotation on X-Axis is greater than my desired maximum and clamp it. But when putting the values to the log, I can see that the value is increasing up top 90° and than decreasing, while Z is flipping from 0° to 180° whenpassing that point. Inspector gives me values between 0 to 180.

float XInput = inputVector.x * _config.RotationSpeedX;
float ZInput = inputVector.z * _config.RotationSpeedY;

Quaternion rotation = Quaternion.AngleAxis(ZInput * deltaTime, motor.CharacterRight);
rotation *= Quaternion.AngleAxis(XInput * deltaTime, Vector3.up);

Vector3 tmpRotation = (rotation * currentRotation).eulerAngles;
Debug.Log("Quat to Vector3: " + tmpRotation);
// Never reached since my MaxAngle of 150° is never reached
if(tmpRotation.x > _config.MaxAngle)
{
    tmpRotation.x = _config.MaxAngle;
}

currentRotation = Quaternion.Euler(tmpRotation);

Quat to Vector3: (89.03, 232.89, 0.00)
Quat to Vector3: (86.19, 52.88, 180.00)

wintry quarry
#

You cannot generally isolate a single Euler axis and do logic with it. All three axes are inextricably linked and cannot be treated in isolation.

median mortar
#

Any suggestions how to limit X-Axis rotation then?

#

I know that Quaternion multiplication isn't cummutative, so maybe reversing the order gives me the same values as the inspector

wintry quarry
#

Do not try to rely on Euler angles

#

Seriously

#

You're setting yourself up for sadness

wintry quarry
median mortar
#

Maybe defining a max rotation using Quaternions and comparing via Quaternion.Dot?
_maxXRotation = Quaternion.AngleAxis(MaxAngle, motor.CharacterRight);

#

Oh, RotateTowards could be helpful, forgot about that

balmy vortex
#

Does anyone here have a 3d player movement script for unity I could borrow?

#

doesn't need to be anything special, just something that works

wintry quarry
balmy vortex
wintry quarry
#

It works right out of the box

#

That's sort of the point

floral garden
#

Crosspost?

naive pawn
#

posting the same question across multiple channels'

floral garden
#

Oh i see

astral flame
#

Hi everyone, I have a problem with my code. It doesn't detect the name of my other code. It says it was not found.

grand snow
north kiln
#

Show the declaration of the other class

astral flame
teal viper
#

Looks like a different assembly

north kiln
#

It looks like it's in a different assembly

grand snow
#

Looks like CarControllerNPC is not detected as a class in the project (based on the colour of stuff)

#

probably "miscellaneous files"

north kiln
#

Could just be VS, check if it compiled in Unity

#

If it did, restart VS

patent wedge
#

i'm having this issue and it driving me insane!!! so i'm doing a boxcast for placing objects but for some reason the hit.point is slightly to the left?! here's my code

Physics.BoxCast(Cam.position, heldObject.GetComponent<MeshRenderer>().localBounds.extents, Cam.forward, out RaycastHit hit, heldObjectRot, RaycastDist, placeLayer)

but weirdly spherecast works?

north kiln
#

Also it is generally concerning to me when people name a mask "layer" 😭

patent wedge
grand snow
#

you miss understand, a mask is a set of layers you want the boxcast to use

patent wedge
floral garden
patent wedge
#

the cube in front is where it's been placed.

north kiln
#

It's unclear where the hit point would be from that view, it looks like it hits the ground completely flat

#

Maybe it would make more sense to you if you placed the cube at Cam.position + Cam.forward * hit.distance

#

Which would be the centre of the box hit position iirc

patent wedge
north kiln
#

I'm not sure what you mean

patent wedge
north kiln
#

I don't really get what left or right is, the box is casted against a surface in the direction, and the distance it travelled can be used to get the centre of the new box

sour fulcrum
#

why do you think the hit point is offset

how are you spawning that cube

median mortar
#

Finally got the rotation clamped, forget Euler and just cancel Input if necessary

private void SetRotation(ref Quaternion currentRotation, float deltaTime)
{
    float XInput = InputVector.x * _config.RotationSpeedX;
    float ZInput = GetZInputClamped();
    Quaternion rotation = Quaternion.AngleAxis(ZInput * deltaTime, motor.CharacterRight);
    rotation *= Quaternion.AngleAxis(XInput * deltaTime, Vector3.up);
    currentRotation = rotation * currentRotation;
}

private float GetZInputClamped()
{
    float input = InputVector.z;
    if (input == 0f)
    {
        return 0f;
    }

    float angle = Vector3.SignedAngle(Vector3.up, motor.CharacterUp, motor.CharacterRight);

    if ((angle > _config.MaxAngle && input > 0f) ||
        (angle < -_config.MinAngle && input < 0f))
    {
        return 0f;
    }

    return input * _config.RotationSpeedY;
}
patent wedge
sour fulcrum
#

homie

ivory bobcat
sour fulcrum
#

any chance the amount your offsetting the cube vertically also happens to be the same amount its going sideways? 😛

patent wedge
ivory bobcat
#

Are you perhaps placing it not relative to the hit point or the hit point with some offset?

median mortar
patent wedge
sour fulcrum
#

i mean

#

thats the problem tho

patent wedge
keen dew
#

If that's the default Unity cube, its pivot point is at the center of the cube. So of course if you place the center of the cube at the hit point which is at ground level then the cube will be placed halfway in the ground

sour fulcrum
patent wedge
sour fulcrum
#

yup

#

post the code spawning and setting the cube

#

the code from that screenshot

patent wedge
# sour fulcrum post the code spawning and setting the cube

i did! but i'll do it again

if (Physics.BoxCast(Cam.position, heldObject.GetComponent<MeshRenderer>().localBounds.extents, Cam.forward, out RaycastHit hit, heldObjectRot, RaycastDist, placeLayer))
                {
                    Debug.Log(heldObject.GetComponent<MeshRenderer>().localBounds.extents);
                    if (Vector3.Angle(Vector3.up, hit.normal) < 75)
                    {
                        Transform obj = heldObject.transform;
                        obj.SetParent(null);
                        // obj.position = hit.point + (hit.normal / 2);
                        obj.position = Cam.position + Cam.forward * hit.distance;
                        obj.rotation = heldObjectRot;
                        heldObject = null;
                        isHolding = false;
                    }
                }
sour fulcrum
#

cool

#

i haven't seen any evidence of the hit.point being wrong

#

you are offsetting it wrong

#

wait huh

#

obj.position = Cam.position + Cam.forward * hit.distance;

#

what do you think this is doing

patent wedge
median mortar
#

I still don't get why you use hit.normal / 2.
hit.normal gives you a direction, you need to define a distance by multiplying, i.e. at least the half-height of your cube

north kiln
patent wedge
sour fulcrum
#

hit.point is not off center.

patent wedge
sour fulcrum
#

nope

north kiln
#

It's not off centre, the cube hits the ground and whatever the first place on the cube that hits is what's returned

#

Your screenshot had the cube hitting the ground flat, so that point could be anywhere on the bottom face

median mortar
#

You are doing a BoxCast, so the first part of the box that touches the normal sets the hit.point

keen dew
#

I think they expect the hitpoint be at the middle of the boxcast on the ground, at the red X. But it's at the blue X which is an arbitrary point because the boxcast hits the ground flat on

north kiln
#

Which is a large area that you're just saying is off centre because you don't understand

sour fulcrum
#

i agree with what your saying just curious

charred spoke
#

Is the cube a child and perhaps the parent is being placed ?

median mortar
#

I would use BoxCast to see if something fits between stuff, not to spawn objects.
Do a Raycast and then an Overlap check for your box size

north kiln
#

My suggestion gets the centre of the cube. If they wanted the centre of the face that hit that's also possible, but at this point I'll be leaving instead

patent wedge
north kiln
#

Because a sphere doesn't have a flat face?

median mortar
keen dew
#

The sphere hits exactly one point, at the red X in the picture

patent wedge
sour fulcrum
north kiln
#

Then my suggestion was that.

ivory bobcat
# patent wedge but mine is!

The hit point isn't assigned by you but rather the physics system. It's value is that of where the point of contact was made. How you choose to use the data would be dependent on your needs. The point of contact (any point that makes contact - any point) is where the contact was made. If you're wanting the center instead, perhaps try raycast rather than box cast.

grand snow
#

🤦‍♂️

sour fulcrum
north kiln
median mortar
#

@patent wedge Do a Raycast and then check with Physics.OverlapBox if your Box fits at the hit.point.
If it doesn't collide with anything, spawn the cube

patent wedge
patent wedge
ivory bobcat
#

Any point where the two objects make contact.

sour fulcrum
#

if your driving and you hit someone on a bicycle the hit.point is where the car contacted the bicycle, not the centre of the car

north kiln
#

Distance is the distance the cast travelled, not the distance to the hit point

sour fulcrum
#

now if you drop a crate off a building onto the street multiple "points" on the bottom of the crate might hit the concrete at the same time

sour fulcrum
north kiln
patent wedge
#

Thx everyone for your help.

median mortar
#

Use a Raycast+OverlapBox or something

slow hollow
#

I am pooling a bunch of meshes in and out of player view, I decided to disable/enable collider and mesh renderer, but as I do so but spikes seem to be bigger and profiler generally more dense on low amplitudes.

Is it generally a bad idea to disable/enable or am I just doing something wrong elsewhere?

hexed terrace
#

Toggling the active state is better than destroying/ creating.

Why are you toggling those components though? Just toggle the root/ parent gameobject

slow hollow
#

for collider im scared that i will spawn something that moves on it and it will roll away for no reason (while the mesh is reshaping) xD

hexed terrace
slow hollow
# hexed terrace this is occlusion culling which Unity does for you

no no, it does my calculations while pulled away, i.e. pcg generating next heightmap etc, thats why i keep the parent active. when its back into view for reshape i make the mesh visible again, adjust vertices, calculate bounds etc

i was just wondering if its better or worse to actually use disable + enable. the implementation doesn't really matter tbh

hexed terrace
#

better or worse than..

floral garden
#

Pool system then ?

#

It better to do enable + disable than create/ destroy as it cost more

#

You can also load everything then disable it after, so you will not have the frame lag because of shader calcul

slow hollow
#

the alternative is clipping the camera so the player doesn't see that im moving chunks around

ivory bobcat
#

I'm assuming you've verified the performance with the Unity profiler.

slow hollow
ivory bobcat
#

Check the profiler

slow hollow
#

like, do others suffer when they do this?

hexed terrace
#

it's something you're doing

ivory bobcat
#

Check with the profiler instead of guessing.

night raptor
slow hollow
ivory bobcat
#

Colliders, so they may be getting removed from the physics simulation

night raptor
slow hollow
#

thanks

#

kinda gonna rush it because its for my thesis, I think im overthinking the smallest things

night raptor
slow hollow
night raptor
slow hollow
night raptor
#

I again don't know what you mean

#

also pooling by moving out of view is quite odd, generally you would just deactivate the object so it would disappear from all the systems (rendering, physics etc.)

vale lintel
#

Is there any way I could get someone to watch me code and explain the basics? Complete beginner and YouTube tutorials aren’t doing it for me

hexed terrace
#

only for £££/$$$

vale lintel
#

Alright thank you

eternal falconBOT
#

:teacher: Unity Learn ↗

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

frail path
#

i am watching a tutorial from a couple years ago and i am running into a problem with this line of code. How do i fix this????

#

it doesnt like the top line

sharp mirage
frail path
#

i started yesterday

grand snow
slender nymph
grand snow
#

we need a bot to auto reply with these links

slender nymph
safe elm
#

yo guys how do i solve this

naive pawn
#

!install

eternal falconBOT
#
When Unity fails to install checklist
  • Make sure you have enough space including on C: drive.
  • Check that it's not being blocked by antivirus/security programs.
  • Look through the logs for a real reason why the setup fails they are pinned [here](#💻┃unity-talk message).

If you still have issues, perform a clean install in another location:

  • Install the Hub and Unity in a non-system drive or a clean new folder in the root of C: drive.
  • Failing that use the recovery Refresh option or reinstall OS entirely then repeat the previous step.
solid oyster
#

when i use the toggle box, the glow prefab switches intensity, but only when i select it in the project window, and it does not update the glow on my other prefab, even though it does when i change the intensity manually

#

what is going on?

#

also im trying to get the toggle to stay check wehn leaving the scene but im failing so far