#💻┃code-beginner

1 messages · Page 586 of 1

grand snow
timber tide
#

the camera on the player could be creating some problems too if it's being moved in fixed

#

try just playing with what cinemachine has first

grand snow
#

but as we all keep saying, the order is clearly wrong

#

Update() and FixedUpdate are often enough but you have a few things to juggle here

#

Id personally use the event i sent twice but im gonna sleep soon

cosmic dagger
#

you shouldn't mess with the script execution order. there isn't a need to . . .

frigid sequoia
#

It's normal that this method is blacked out if I just call it from the InvokeRepeating?

fast copper
#

How hard is it to make a decent basic inventory system?

frigid sequoia
cosmic dagger
#

how hard it is to implement depends on your knowledge of C# and Unity . . .

eternal needle
fast copper
cosmic dagger
frigid sequoia
#

Then I just do it once?

cosmic dagger
frigid sequoia
#

Like do I place that on Start?

cosmic dagger
#

i would check out the method in the Unity docs to see how it's used . . .

frigid sequoia
#

I did, I do not understand

cosmic dagger
frigid sequoia
#

I just place it on start?

#

And it would repeat the call every second until I cancel it?

slender nymph
#

put a log in the method invoked by InvokeRepeating to see when it is called

cosmic dagger
slender nymph
#

then you can try different ways of using InvokeRepeating to see which suits your needs best

cosmic dagger
fast copper
cosmic dagger
frigid sequoia
frigid sequoia
#

And yes, I can blindly add prints and try for like half an hour to see how it exactly works, for sure, but it's always like way clearer if I ask people that already know the stuff, u know?

cosmic dagger
slender nymph
cosmic dagger
#

that sounds like it repeats, as in, InvokeRepeating . . .

frigid sequoia
#

But besides, that's not even what I asked in the first place

slender nymph
#

what part of "Invokes the method methodName in time seconds, then repeatedly every repeatRate seconds." is not clear?

cosmic dagger
#

also, the description says it invokes (calls/executes) the method in the time you specify (1 sec), and then repeatedly every n secs (1 sec) . . .

frigid sequoia
#

I asked if it's intended for a method that is called from an InvokeRepeating to be balcked out

slender nymph
#

you're not calling the method anywhere in your code, so yes.

#

the compiler has no idea that the string you are passing to InvokeRepeating has anything at all to do with the method in your code

frigid sequoia
#

Why does it even use a string instead of a method prompt?

#

Seems kinda weird

cosmic dagger
slender nymph
#

because it uses reflection rather than an Action. if you want something with better compile time checking, then write a coroutine instead

frigid sequoia
cosmic dagger
#

i was feeding you information the entire time to help explain what it does. never did i say, "read the book, and just figure it out . . ."

frigid sequoia
cosmic dagger
frigid sequoia
#

So in what case should I use the InvokeRepeating then?

slender nymph
#

When you want to use strings and reflection instead of a better option

cosmic dagger
#

you also asked if you should use it in Start and the docs show it being used in Start . . .

frigid sequoia
cosmic dagger
night mural
frigid sequoia
#

So this is a right way to use it or in this case should be more like.... making the Corourine loop indifently without stopping it?

#

Cause I always used it like that, and I realize now I might have been using it entirely wrong

#

Like that's intended to be always running on the background right?

#

This would be a better use of it???

earnest wind
#

Are u calling the IEnumerator every frame??

rich adder
frigid sequoia
earnest wind
frigid sequoia
#

I used to just clear it entirely after each iteration

cosmic dagger
frigid sequoia
earnest wind
#

There is no need for loops

void thicket
cosmic dagger
frigid sequoia
#

Oh, ya, I am fucking dumb, I duplicated it

frigid sequoia
earnest wind
frigid sequoia
earnest wind
frigid sequoia
#

Of course

earnest wind
#

Would honestly be easier

sand schooner
#

I have a Sphere Collider on a game object as well as the game object having the tag "JumpPowerUp", and in my player controller I have a onCollisionEnter method. In that method I have: if (collision.gameObject.CompareTag("JumpPowerUp") //Change scene but when my player bumps into the game object, the scene does not change. Any ideas?

rich adder
void thicket
rich adder
#

also why LoadAsync in a Synchronous method..

sand schooner
#

The event does get called, but its saying the colliders gameObject is the parent of the parent of the actual game object

void thicket
sand schooner
#

The parent object has a rigidbody yeah

sand schooner
#

And the logs said the colision was with "Cube" whenever my player colides with "JumpPowerUp"

void thicket
#

That's not how Rigidbody should be set up

sand schooner
#

Would removeing the rigidbody from Cube solve it?

rich adder
#

child colliders become part of parent rigidbody

void thicket
#

What even is Cube there

#

Why everything is under it

sonic osprey
#

Does anyone know how to code with C#

sand schooner
#

Cube is pretty much the ground, it spins and the player has to stay on it

sonic osprey
#

and is willing to help me with my vr game

rich adder
sonic osprey
#

Ok

rich adder
#

no need to spam all the channels

sonic osprey
#

):

#

kk

#

mb

rich adder
#

if you want to learn there are resources pinned

sand schooner
#

Looks like removing the rigidbody from cube fixed it, tbh not sure why cube has a rigidbody in the first place

void thicket
rich adder
#

if it spins then you should keep it as rigidbody but rotate using the MoveRotation or angularVel

void thicket
#

You have to play with Math ™️

sand schooner
#

I tried to find a good way to make it work, and the best way I found is to have the player as a child of the cube, that way when the cube rotates, the player moves with the cube

#

but open to suggestions

rich adder
sand schooner
#

how do you mean?

rich adder
#

as mentioned you have to do a bit of math between both velocities and whatnot

void thicket
#

Unity hierarchy and physics simulation world works separately

sand schooner
#

interesting

strong wren
#

I didn't look at the actual problem you were trying to solve, but saw the CM related execution order discussion and figured it could be helpful.

mellow zenith
#

ive just started game development and am working on a dummy game but its not working is someone able to help me
Im trying to make a building system similar to Hay Day or Clash of Clans and I have a tilemap and grid, but I cant figure out how to move/place objects

sand schooner
#

also thank you @void thicket and @rich adder

mellow zenith
#

I am not able to move the object around

#

it only places at 0,0

rich adder
#

show code

mellow zenith
#

in here?

rich adder
#

yea ⏬

eternal falconBOT
mellow zenith
#

im not sure if i have linked everything correctly in unity I believe thats the problem because i followed a tutorial

rich adder
#

unless you were supposed to put physics raycaster

#

can you send tuto link

mellow zenith
#

An easy tutorial on how to make a grid based building system in Unity. You don't need to write a custom grid! The system works with standard Unity tilemaps. It implements grid snapping and placement checking. As an example, I used an isometric grid but it will work for any 2d grid.

Get the project files - https://www.patreon.com/posts/project-...

▶ Play video
#

idk if I have to do isometric bc thats what she did, but I want to have my game 3d so i used rectangular tilemap

rich adder
mellow zenith
#

thats what i was thinking

#

but my button is on a canvas

#

is a canvas UI?

rich adder
#

yes

mellow zenith
#

maybe i cant move it because the whole screen is UI

#

maybe i should follow this video instead?
https://www.youtube.com/watch?v=l0emsAHIBjU

In this Unity 3D tutorial start creating a Grid Building System. First we will use Grid component to calculate a cell position for our mouse pointer position to use it in our placement system. Next we will expend the system with a custom grid shader and an object placement and removal system. At the end of this tutorial you will have a grid plac...

▶ Play video
rich adder
#

its possible, you can just place logs and see whats happening

mellow zenith
#

yeah ive done a ton of debugging

rich adder
#

also are you using Orthographic or Perspective

#

Perspective is better to use Plane or ScreenToRay instead of ScreenToPoint

mellow zenith
#

im pretty sure Prospective

rich adder
mellow zenith
#

of right yeah Prospective

#

so you would recomend Prospective?

rich adder
rich adder
#

they both have their own look

#

3D Ortho comes out to something like Hades

void thicket
#

Perspective view*

mellow zenith
#

YAYYY i got something working

frigid sequoia
#

What would be the best way to... make an entity begin the cast of an spell onto a target, but if midway, the target moves out of range, or dies, the cast is canceled early?

#

I could do a Coroutine and stop it if any of those cases happen, but... checking that every frame seems kinda like not the best choice...

rich adder
mellow zenith
#

I got the mouse position in the game represented by a sphere but cant get CellToWorld working

mellow zenith
#

determining what cell is selected

rich adder
#

what exactly isn't working

frigid sequoia
#

I mean, I have an script that manages like all the skills and which they should be using, then one separate script for each skill on it's own. I am thinking I could make the specific skill just send back a order to the manager to tell it that it's casting something that needs X seconds and needs X target and once the casting time is finished it could send a proper confirmation to the skill to send the actual effect, or cancel it before hand, cause checking the Update of just the manager is way better than for each different skill

#

The issue I see there is that I couldn't really tell later on wtf it's supposed to be casting, since pretty much all casts would use the same

#

So probably supermessy if I want to add visuals for it later

mellow zenith
night mural
#

it sounds like you should have a casting system a la WoW which allows for interrupts and stuff

frigid sequoia
#

Not for enemies though

mellow zenith
#

NVM

#

i got it

night mural
#

while the cast is active, it's totally reasonable to check for invalidation every frame (but also up to you how you want to do that specifically, like WoW lets you finish the cast even if they go out of range and does an extra, more generous range check at that point)

#

especially so if you want to let players interrupt, since you want immediate feedback for something like that

frigid sequoia
#

The issue comes when I do it on the update on the skill itself

#

Since it would mean I am doing it simultaneously for every casteable skill, no matter if they are even being casted

night mural
#

no, i wouldn't do that

frigid sequoia
#

If I can avoid it I would rather not have an update for those

night mural
#

you'd want each unit to be able to do a cast, which would be for a particular skill, but they should only have one cast active at once

#

one update running for the current cast

#

(per unit)

frigid sequoia
#

The Update of the AbilityManager just straight up stops early if it's casting something, meaning anything under there would not be even considered, since it's casting something already

night mural
#

so only one unit can cast something at once?

#

or this is on every unit?

frigid sequoia
#

That's on all of them

night mural
#

I guess I'm not seeing the issue then

frigid sequoia
#

The issue is where the fuck do I check for the "target is no longer valid" to stop a cast early

night mural
#

probably what you want to do is replace the IsCasting boolean with some kind of 'Current cast' data structure which references the active skill, current time, etc. and can be interrupted by this, instead of trying to have each skill manage itself

frigid sequoia
#

That.... would kinda mean I need to do a superclass for all casteable abilities, so I can pair them together

timber tide
#

check every frame

#

well, fixed probably better

night mural
#

you don't have to do it that way, you could alternately just reference the monobehavior that is the 'current' skill

#

since it sounds like monobehavior is already a 'superclass' that all your abilities derive from

frigid sequoia
#

Then how I get data like... how long it takes or how much range it has?

#

I kinda need that to do the checks

night mural
#

you could read it off the monobehavior or have some kind of Validate method that you pass the relevant data into

#

maybe the Tick method of a skill accepts parameters

frigid sequoia
#

I cannot see that, can you provide an example?

night mural
#

I'm not sure that would help since your approach of just handling everything in the tick for the ability seems like it would be ok

night mural
timber tide
# frigid sequoia I cannot see that, can you provide an example?
public class SpellSO: ScriptableObject
{
  [field: SerializeField] public int Damage { get; private set } = 1
  [field: SerializeField] public float CastTime { get; private set } = 1
}

public class Spell: Monobehaviour
{
  [field: SerializeField] public SpellSO { get; private set }
  
  public void Initialize(SpellSO spellSO)
  {
    SpellSO = spellSO;
  }

  public bool Cast(Vector3 point)
  {
    //If we want to use a cast time that can be interupted the easiest way is to just
    //let the manager access the SO/Data and grab the cast time directly then coroutine
    //on the manager and if it succeeds then we Cast()
  }
}
#

Few ways I can think of doing it but the comment probably easiest

#

I don't think there should be any sequencing local to the Spell

#

Actually dont like the coroutine idea

frigid sequoia
#

Ok, so here what I did, and think it should kinda work? But surely it will not, but I am way too tired to debug it now, so it's gonna be tomorrow to see if it actually does the job

icy sluice
#

does anyone have a code for RCS?
or a way to calculate force required to NOT flip vehicle when thrusters are not directly under center of mass

west lynx
#

I just did the delete of shame... looked at how the old code worked and decided to remake it from scratch better was so far into the version of how I wanted to build my code then realized that no matter how I hammered it, it was just never going to work like I wanted... so I finally decided to pull the plug and bulk deleted 2 days of work on it and will build it from the old version piece by piece rather than trying to start from scratch 😭

#

@icy sluice
ultimately any thrust not pointed directly AT the center of mass is just applying a torque (as well as pushing the mass) to it so if its flipping it over you have to counter that torque with other thrusters that add up to the desired anti-torque value

icy sluice
frigid sequoia
west lynx
#

right. you have to break each thruster down into its pushing and torque components you can do sin/cos with the angles or the dot product from the thruster angle (normalized) and the direction to the COM. (normalized) it will be from 0 to 1 0 means its pure torque, 1 means its pure thrust. just do this calculation for every thruster you have. if you end up with uneven torque values (meaning it will try to flip) you can see how adding a new thruster will change it if you calculate it as you go

icy sluice
buoyant finch
slender nymph
#

be more specific than "it doesn't work"

buoyant finch
untold shore
#

Hey, quick problem I'm having. I have a script in which my variable is supposed to change by checking another script (both are bools, so just checking if they should change to false/true), but even if the other is true when the new script is called on. Both scripts related are in this paste of code, being separated with ///. https://paste.ofcode.org/pP26Fg6c2Na9nv7w5mJrhn
The thing that I want to change is "SpecialCardScriptCelestialBond", which continuously says false even after the other script is called. Any ideas? Please @ me if you respond, thanks!

coral junco
#

!code

eternal falconBOT
dreamy wren
earnest bear
#

Hello,
I have a very very strange problem.
I am using the default Unity character controller, and moving it with the "Move" function.
I am having a problem that, even if I pass a Vector3.zero to "Move", if the player is in certain positions, he starts to move a little and after a couple of minutes you can definitely see it moved
I am sure the problem comes from the Move function because if I don't call it, there is no movement. I tried passing a Vector3.zero but it still moves.
If that helps, the CharacterController has a parent GO that never moves, just for organization purpose.

Has anyone encountered anything like that? At first it looked like a float error, but it doesn't make sense?

mellow zenith
#

@rich adder THANK U FOR HELPING ❤️

ivory bobcat
#

I'm assuming you're passing a value that you believe is zero but isn't.

earnest bear
#

The code is very simple and I am sure it is correct.
I used a debugger breakpoint, the value is zero
I even changed the code to controller.Move(Vector3.zero) and moved the player using the editor gizmos, same problem.
Commenting the Move fixes the problem
The change is very small but adds over time, that's why I thought it was some floating point error problem
I will share the code later if it can help, but it is very simple, I get the player input as a vector2 and us it in the Move

verbal dome
ivory bobcat
#

Does commenting the line out and moving the object with Gizmo still reproduce the unwanted behavior?

buoyant finch
#

hello can someone pls help me in making a grid based movement for my player https://paste.ofcode.org/g2dAAQSBufP3RiYPTGjG2W so I tried this but it doesn't work like the player doesn't align to the tile and has variable speed upon moving
btw each tile is 12*12

verbal dome
#

You left out some important code, like what are you setting targetPosition to

foggy crypt
#

Hello. I have this problem with Animator Transitions.
When the player turns to the right, and turns back to Idle State - The position of the camera is a little off.
Like the animation did not complete or something.

Here's the video for more context

buoyant finch
verbal dome
buoyant finch
verbal dome
#

You are setting it to its own position. How would that make it move?

buoyant finch
verbal dome
#

To the position you want to move to, obviously

#

Where did this code come from? Do you understand what it does?

buoyant finch
#

not on targetPosition seeing it just now

#

thx a lot

verbal dome
#

If you want grid based movement, you should not do whatever you are doing in HandleInput.
A key press should set your targetPosition to a position on the grid

#

And I see nothing related to a grid here. You can use the Grid component or an array

buoyant finch
verbal dome
#

Lerp has nothing to do with grids

#

It just lets you smooth the movement between grid cells

buoyant finch
soft creek
#

Hi i have a porble, i don't have any audio source and i receive an message, what i can do for the mesage desapear? Thanks

verbal dome
#

Type t:audiolistener in the hierarchy search to find them quickly

soft creek
#

oh, thanks 😅

buoyant sentinel
#

guys, why does it look like this?

#

the black dots on the thing

fickle plume
#

Corrupted. Restart editor and PC perhaps

#

Maybe need driver update too

buoyant sentinel
#

all my drivers are up to date

fickle plume
verbal dome
#

Unity went into braille mode lol

buoyant sentinel
#

i am new here

broken lintel
#

need some help with my dialogue system, for some reason, once the dialogue is done, I can't close the dialogue box. I'm such a noob <.< been stuck on this for so long

ivory bobcat
#

This is the coding channel, you'd provide any necessary code with your question.

ivory bobcat
#

Where do you attempt to close the dialogue box?

#

I'm assuming line 52 of the dialogue ui script

broken lintel
#

yea

stuck field
#

ResponseHandler > Line 90: Calls dialogueUI.CloseDialogueBox()

#

If the response object is null

keen owl
#

Set it to false once the dialogue is finished

stuck field
#

Meaning at the end, your method would need another option "Close" and, they click that, no more dialogue after that (returns null, so it closes)

#

Although you do that when no responses are there as well

broken lintel
#

oh, I get it now :0

stuck field
#

tempResponseButtons.Count > 0

#

But that's the response box

#

So I'd say, yeah, just add a reponse "Close" that has no more valid dialogue after it

broken lintel
#

oki

#

thanks!

stuck field
#

np

tiny wind
#

my console keeps saying theres a null reference in line 69, but I dont see anything wrong here, or Im not seeing what is wrong here, can anyone jhel

verbal dome
#

I see like 4 things that could be null on that line

#

Although the first two would throw an error on the previous line

tiny wind
#

please do tell

tawdry nymph
#

you are calling methods that could also be null somewhere

#

if you click the error there might be more lines

verbal dome
ivory bobcat
#

Anything before a dot operator (member access operator) could potentially be a null and throwing those errors

tiny wind
# verbal dome ``Melee`` component and ``components``
using UnityEngine;

public class Melee : MonoBehaviour
{
    [SerializeField] private float speed;
    private float direction;
    private bool hit;
    private float lifetime;

    private Animator anim;
    private BoxCollider2D boxCollider;

    private void Awake()
    {
        anim = GetComponent<Animator>();
        boxCollider = GetComponent<BoxCollider2D>();
    }
    private void Update()
    {
        if (hit) return;
        float movementSpeed = speed * Time.deltaTime * direction;
        transform.Translate(movementSpeed, 0, 0);

        lifetime += Time.deltaTime;
        if (lifetime > 1) gameObject.SetActive(false);
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        hit = true;
        boxCollider.enabled = false;
        anim.SetTrigger("hit");

        if (collision.tag == "Enemy")
            collision.GetComponent<Health>().TakeDamage(2);
    }
    public void SetDirection(float _direction)
    {
        lifetime = 0;
        direction = _direction;
        gameObject.SetActive(true);
        hit = false;
        boxCollider.enabled = true;

        float localScaleX = transform.localScale.x;
        if (Mathf.Sign(localScaleX) != _direction)
            localScaleX = -localScaleX;

        transform.localScale = new Vector3(localScaleX, transform.localScale.y, transform.localScale.z);
    }
    private void Deactivate()
    {
        gameObject.SetActive(false);
    }
}

this is the Melee and Components is just a [Serializedfield] Transform

verbal dome
#

This doesn't prove that slashes[FindSlash()] has a Melee component.
It also doesn't prove that components is assigned

ivory bobcat
#

With A.b.c.e.f, characters A to e can be null and throw an exception

ivory bobcat
tiny wind
#

oh wait no I see it now

#

FindSlash is missing a thing

#

idk how to describe it but I know whats missing

#

thanks yall

#

okay nvm it did not fix it

#

dammit

ivory bobcat
#

Have you figured out what was null? (far more important than trying random things)

#

To figure out what was null, log the parts before using them. An example: cs Debug.Log($"A: {A}"); Debug.Log($"b: {A.b}"); Debug.Log($"c: {A.b.c}"); Debug.Log($"e: {A.b.c.e}"); A.b.c.e.f = ... //NRE thrown

#

If any were blank, they would be the null

narrow tinsel
#

I am new, is there easy way to save something that I did when the game was started (tweaking some
values)

ivory bobcat
#

You could probably write it on disk or if in the Editor, to some Scriptable Object instance.

narrow tinsel
tiny wind
#

unrelated but how do you type like this?

verbal dome
#

Put `` on each side

tiny wind
#

slash[FindSlash()

#

ahh

#

thxx

tropic dust
#

Why can't I import things into nor play this animation?

tawdry nymph
#

it needs to be in an animation controller which is assigned to an animator on a scene object in order to play it

tropic dust
#

can you walk me through that I'm pretty new lol

tawdry nymph
#

first you add an animator component to the gameobject you want to animate

#

that gameobject also needs to have a sprite renderer in this case since you're trying to animate a sprite

tropic dust
#

mhm

tawdry nymph
#

you then create a new animationController asset

#

and assign it to the animator component

#

then open the animationcontroller (double click) and drag the animation into it

hard lodge
#

does this wok on gui? becaus it doesent even print. Any idea?

astral falcon
hard lodge
#

on a gui

astral falcon
#

GUI in terms of OnGUI() or a Canvas UI?

fickle plume
upper yoke
#

Ah sure thanks

cunning hornet
#

Hi! Imma attach a video down below. So ,everything was fine until i added a animator to my weapon script. In the video , when i pick up the weapon ,( when i didn t have the animator in the script) it would pick up the weapon at my camera view and i could shoot ,relaod etc. Now , i can still shoot, reload , but , the weapon with the idle animation is all the way up , as you can see in the video. I ve no ideea how to make it so that i can pick up the weapon , have the idle annimation and still be at my camera view

rocky canyon
#

its best to animate the gun within a container.. (outter gameobject wrapper).. that way all the animations are relative to that object..

#

for example reload animation would be red.. (within the green object)
the green object wouldn't be animated.. (for example it'd be rotated up and down for when u look up and down)
the green can rotate w/o affecting the animation of the red.. and the red can animate w/o affecting the transform of the green

#

also not sure ive ever seen someone rotate the actual capsule up and down when looking in a particular direction..

#

that would also follow similar guidelines

cunning hornet
#

Ooh okay

#

thanks a lot

rocky canyon
buoyant finch
rocky canyon
#

ya, thats' how u'd do "Recoil" for example

#

but it still applies. (do this within a wrapper object)

#
  • Gun Object
    • Actual Graphics <-- animate this
desert plinth
#

Will my code not work if I use an "obsolete" function / variable?

rocky canyon
#

possibly. but unity/ide will complain about it until ur not

#

like rb.velocity still works..
altho u should be using rb.linearVelocity by now (if ur using newer versions)

desert plinth
# rocky canyon like `rb.velocity` still works.. altho u should be using `rb.linearVelocity` by...

I see. But the issue I'm having is that I'm trying to change the emission rate and start speed of a particle system. If I use the outdated versions of the variables, VS gives me no errors, but if I write it like this:

ParticleSystem.MainModule main = new ParticleSystem.MainModule();
main.startSpeed = Mathf.Sqrt(speed);
ParticleSystem.EmissionModule emission = new ParticleSystem.EmissionModule();
emission.rateOverTime = Mathf.Sqrt(speed);

particle.main = main;
particle.emission = emission;

... which is the "proper", "newer" and not outdated way, VS gives me the errors you can see in the image.
It just says that the attributes are read only. Is there another way to change the attributes that isn't outdated?

rocky canyon
desert plinth
rocky canyon
verbal dome
#

It never was like that

#

And I doubt it has changed

swift crag
#

You never assign to it, yes

rocky canyon
swift crag
#

the particle system modules are a bit funny!

rocky canyon
#

yea they are..

#

(╯°□°)╯︵ ┻━┻

desert plinth
swift crag
#

one sec, I talked about this just a few day sago

#

Starting from here

verbal dome
#

Yeah they are structs and I guess they just work as a "handle" to the actual data

swift crag
#

Correct. The struct is just a way to interact with the particle system.

#

It doesn't actually contain the data

rocky canyon
#

ya, i hate dealing w/ particles/postprocessing/materials etc

#

i always have to fiddle with it til i get it workin

swift crag
#

is it mean to say S K I L L I S S UE

#

dammit, messed it up

rocky canyon
#

lmao.. irony

swift crag
#

😭

desert plinth
#

Well. The intended use works. With the outdated variables.

rocky canyon
desert plinth
#

But I don't mind, as long as it works.

swift crag
rocky canyon
#

problem would be upgrading to a version that DOESN'T respect the obsolete stuff

swift crag
#

constructing your own main module struct makes no sense. there is no particle system it's associated with

earnest bear
desert plinth
swift crag
swift crag
# desert plinth

that's just telling you the correct way to set the start speed property

#

See here for an example.

rocky canyon
#

lol.. "depenetration" added to my lexicon

swift crag
#

It is a bit of a non-conventional workflow. You get a struct, modify it, and then...don't assign it!

earnest bear
desert plinth
earnest bear
swift crag
grand snow
#

Hooray for native code wrappers

swift crag
desert plinth
rocky canyon
#

is the VFX graph any easier to work w/

#

modify via classes

earnest bear
#

But, the charactercontroller is a child of a non moving gameobject
And I discovered now that if I put the character controller in the root of the scene, this problems disappears.
What could it be?!

serene barn
#

Hello, so I'm stuck on a 3d input system and I'm getting now where following a tutorial on yt. So if possible I would like some help.

#

Im new and I don't know a lot of it

#

spent hours trying to get it to work by it has fallen to the floor real quick

#

I gotten rid of it, rather just start from scratch

#

Basically the goal right now. Move the character and have it pick up or Move an object

grand snow
#

Good solution! I'm glad they account for this and let you update things manually

serene barn
#

yea, and if possible (you dont have to do it) can we do a screen share. I have troubles following word for word.

#

unity invoke system, yes.

grand snow
#

Please make a thread my guys

#

No one makes threads here 😭

left sail
#

hello ! I would like to know why when I play I spawn with the car under the map, and when I move forward it controls my character instead of the car

tawdry nymph
astral falcon
left sail
astral falcon
#

did you WRITE any code?

left sail
astral falcon
#

then !learn is your place before coming here.

eternal falconBOT
#

:teacher: Unity Learn ↗

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

astral falcon
#

These channels are meant to be for devs bringing their code and getting help with it. Not to teach you how to code in general

left sail
astral falcon
#

Well, feel free to stick to your attitude.

left sail
tawdry nymph
left sail
#

wait

earnest bear
tawdry nymph
left sail
tawdry nymph
#

hello ! I would like to know why when I

earnest bear
#

Character controller moving when passing a Vector3.zero to Move

pure drift
#

does anybody know why my scene looks like this when i play it works all fine

astral falcon
#

you should at least know the UI of the software you are using

pure drift
#

yep i should do that thank you though for the answer

lament harness
#

how do you remove anti aliasing in unity 6

#

i cant find it in project settings

serene barn
#

so how would I check if player is on the ground, and then have them jump from the ground and only from the ground

rocky canyon
#

if its Built-InRenderPipeline it'll be just below where the URP asset would be

serene barn
#

Can someone help me make an ground check?

#

or tell me how to

rocky canyon
#

explain urself a bit more..
3d, 2d.. side scroller/platformer/ fps?
capsule or box? etc

serene barn
#

3d sorry

#

box

rocky canyon
#

capsule are usually best colliders for a character.. jus sayin

serene barn
#

im just starting with this

lament harness
rocky canyon
#

theres many methods u can use..
Raycasts
SphereCasts(etc)
OverlapSphere

rocky canyon
#

those are the two most simple

lament harness
#

ty ill try following a tutorial on that

rocky canyon
#

theres some links for them in my github readme

astral falcon
serene barn
#

So I got ray casting to work and to detect the ground but I'm not happy with the results as the capsule keeps tipping over. Is there any other solution with ray casting I can use?

timber tide
#

clarify what you mean by tipping over

serene barn
#

Like gravity decides to tip it over

timber tide
#

are you using any unity* physics

rich adder
#

if you have a rigidbody, you have to lock your rigidbody rotation constraint

serene barn
last edge
#

question, so i have a gun and bullet script it successfully collides and destroy when attacking enemies yet it phases through walls and platforms.

how can i get the bullet to destroy on impact? (i set the bullet as destroy on collision yet it is not detecting the terrain.

any guesses on what im doing wrong? (they are also on the same layers)

#

i also tried to add in a collider2D to my objects as well

swift crag
#

Does your bullet have a Rigidbody2D on it?

last edge
#

yes

humble quarry
#

hey guys, i want to get into procedural animation sometime in the future, how advanced is it?

swift crag
last edge
last edge
swift crag
#

It's a kinematic rigidbody.

#

That means that it will not produce collision messages when it strikes a collider without a rigidbody

#

(or a collider with another kinematic rigidbody)

#

You can use a separate trigger collider. This will let you receive messages when you hit any collider

last edge
#

gotcha ty

#

fixed

#

but now new issue lol how do i make my bullet so that it doesnt send enemies and objects flying upon contact?

rich adder
last edge
strong sorrel
#

I'm coding an volume slider for my game. What should the range be for the audio mixers? 0dB -80dB? is there a formula i should use?

rich adder
#

I think its Mathf.Log10(sliderValue) * 20;

strong sorrel
rich adder
#

havent used Slider in ages, i usually use Image component set to Slider mode lol

strong sorrel
#

haha okay perf

strong sorrel
rich adder
#

then it stretches as big as you need and looks crisper than slider

#

ofc you can use circular sprites and all that too

lean lichen
#

how do I set a integer to be a specific number when I start the game? I want WeaponHealth to start at 100

grand snow
rich adder
#

so in the future if you want it to start at 200 you need to do that in the inspector, unless the script is reset thru inspector or deleted and added again

serene barn
#
private void Jump_started(InputAction.CallbackContext context)
{
    Debug.Log("I've Tried to Jump. ");
   
    Ray ray = new Ray(transform.position, -Vector3.up);

    Debug.DrawRay(transform.position, Vector3.down * playerHeight, Color.red);

    if (Physics.Raycast(ray, out hit))
    {
        if (hit.collider.tag == "ground")
        {
            float height_above_ground = hit.distance - 0.5f;


            if (height_above_ground > 3)
            {
                input.CharMov.Disable();
            }
            else if (height_above_ground < 1)
            {
                input.CharMov.Enable();
                playerBody.AddForce(Vector2.up * jumpPower);
            }
        }
    }
}

is there any better way of doing this?

rich adder
#

why did you use -Vector3.up with Ray but Vector3.down for DrawRay..

#

weird inconsistency there

serene barn
#

thats is what im wondering

#

is there a better way to keep the player to the ground to prevent endless jumping

rich adder
#

I mean it works the same it just weird

rich adder
#

isGrounded = Physics.Raycast(etc..

hot laurel
#

and layermasks insted of tags

sand sonnet
#

If i want to make a mobile game, what should i choose when making a new project (This is a clicker game btw)

serene barn
rich adder
serene barn
#

im kinda done going down that rabbit hole

rich adder
#

eh 10 shit videos can do more harm than good

hot laurel
#

its not rabbit hole

serene barn
#

i've been down the video hole for weeks on end before and im not going back

sand sonnet
#

cant find it on the unity list...

hot laurel
#

rabbit hole would be using dissasembler to read managed .dll IL code to see how it works

rich adder
serene barn
rocky canyon
#

anything you're learning about is a rabbit hole...

#

if u dont wanna go down it.. then shouldn't expect to learn whats at the bottom

serene barn
#

they also just thrown everything i had known out the window

rocky canyon
#

no.. its still important.. maybe not for the exact thing ur currently doing..

#

but no knowledge is a waste

rich adder
lean lichen
rich adder
open folio
#

The type or namespace name 'CanvasScaler' could not be found (are you missing a using directive or an assembly reference?)

i get this error even though i imported using UnityEngine.UI

anyone know the fix?

serene barn
sand sonnet
#

Should i choose 2D Mobile when wanting to make a game for mobile (clicker game)

lean lichen
rich adder
#

you're not on a good start

hot laurel
serene barn
visual linden
#

Let's remember that everyone learns differently and in different paces,
and try not to be too rude or dismissive dogjam

swift crag
rich adder
swift crag
#

you need to be able to look at new information and learn from it

rich adder
sand sonnet
#

@edgy sinew ur saying that if i want to make a mobile clicker game, you want me to do Universal 3D?

#

oh ok, so it woul dbe the right choice. Sorry dont want to mess anything up lol.

visual linden
#

Universal 2D is probably what you want. But these are presets regardless and just sets up some packages and editor layouts for you. You can easily start with Universal 3D and do 2D, or vice versa, if you're somewhat at all familiar with Unity.

swift crag
#

The important difference is that the 2D template will set your project up with a special 2D renderer, which supports things like 2D lights.

#

(at least, it will in newer versions of Unity -- I forget when that was introduced)

sand sonnet
rich adder
#

still debatable if BiRP might be more lightweight for mobile than 2DURP

sand sonnet
#

oh yeah, and you can rename projects after you start one as ive got 0 clue on what the name should be

lean lichen
#

anyways im still learning

sand sonnet
rich adder
lean lichen
grand snow
sand sonnet
rocky canyon
rich adder
sand sonnet
rocky canyon
#

just another possibility

rich adder
sand sonnet
# rocky canyon just another possibility

hm yeah, i think the hardest part is choosing what the game should be about and like how to get started as once you get started your kind of on a role really.

visual linden
grand snow
rich adder
#

it also tanked my FPS for some reason for the urp renderers

sand sonnet
rocky canyon
rich adder
sand sonnet
rich adder
#

yea! though personally I would go with something inbetween like Flappy Burd and alike

rocky canyon
rich adder
#

physics are funn to play with

sand sonnet
#

@rich adder if you type up Business Empire Richman, thats the sort of game im going to base it off of

rich adder
#

yeah those seem more involved

visual linden
rocky canyon
#

thats a business/economy simulator basically

sand sonnet
sand sonnet
verbal dome
#

I watched that game's trailer and it has an AI generated voice aah

rocky canyon
#

Idle game basically

rich adder
#

had gamearts that use AI generated images tho

rocky canyon
rich adder
#

this new trend needs to die

visual linden
sand sonnet
rich adder
rocky canyon
visual linden
rich adder
#

yeah the flood waters have been open

rocky canyon
#

oh there is...

#

but u have to fight with ur wallet.. rather than ur words

rich adder
#

ban AI movement

#

lol

rocky canyon
rich adder
swift crag
#

Yummy!!! Slop!!!

rocky canyon
#

i miss when AI voices sounded like computers

swift crag
#

more slop please!!

rich adder
serene barn
#

i really can't get this, i got a layer mask and a if statement checking if the player is less then or equal to 1 but that is where i got stuck

swift crag
serene barn
rich adder
#

show what you wrote

serene barn
#

it should probably be equal to 1

swift crag
#

Okay, so step back and describe what you want to do

#

No code: just what the game is going to do

rocky canyon
#

u only need a raycast with a length of (long enough to reach the ground)
if it hits anything in the ground Layer ur grounded..

rich adder
#

Im hoping you actually use a layermask and not a layer int..

serene barn
#
 private void Jump_started(InputAction.CallbackContext context)
 {
     LayerMask ground = LayerMask.GetMask("ground");
     if (player.transform.position.y <= ground)
     {
         
     }
 }
rich adder
#

oh jeez.

#

put the layermask IN the raycast

swift crag
#

no, hold up

#

I want Mixity to first explain what they want to make the game do

serene barn
#

all im doing is checking if the player is on the ground (or on any flat ground surfaces) and allowing them to jump. if they're not on the ground they continue to fall till they hit ground

rich adder
#

"how to overcomplicate a ground check with jump 101 " lol

serene barn
swift crag
serene barn
#

yes

#

or any flat surface

rich adder
#

isGrounded = Physics.Raycast(etc..

swift crag
#

So, you need a way to decide if the player is on the ground.

There are several ways to do that. One of them is to shoot a ray downwards and see if it hits anything.

true owl
true owl
#

someone correct me if im wrong but isnt the new input system the standard now

rich adder
serene barn
#

i will just not right now

swift crag
rocky canyon
#

[SerializeField] LayerMask groundLayer; <-- can assign in inspector

  // get position to start raycast
    Vector3 rayOrigin = transform.position;
    rayOrigin.y += characterController.height / 2;

    // set distance raycast will travel
    float rayLength = characterController.height / 2 + 0.2f;

    // check if raycast hits or misses
    if (Physics.Raycast(rayOrigin, Vector3.down, out RaycastHit hitInfo, rayLength, groundLayer))
    {
        // we hit something in the ground layermask
        // we can assume we're grounded
        // we can use hitInfo for details about the hit
    }
    else
    {
        //not grounded
    }
rich adder
#

they got raycast code already they just wrote extra stuff

rocky canyon
true owl
#

is a good way of checking if the player is dead from falling down a hole, to just make a big trigger under the stage or is there a better way?

rich adder
#

also would probably put the raycast in Update with a bool so you can use that bool in jump method. @serene barn

rocky canyon
#

if the hole is X deep.. u can just check if players Y position is less than that

#

or a death trigger at the bottom..

true owl
#

i guess that's true, i just thought of it myself so i was wondering if that's the standard

rich adder
true owl
#

i think i'll use the trigger

rich adder
#

yeah go for trigger

true owl
#

alr 👍

verbal dome
#

Probably want to add a Y check anyway in case something goes wrong and you fall down where there's no trigger

swift crag
#

It's a decent idea to include a "kill plane"

serene barn
#

playersetting?

rocky canyon
#

^ lol facts

swift crag
#

A last resort that shouldn't ever be needed.

#

But you might as well make your game break more gracefully.

swift crag
#

Bonus points if you prompt the player to submit a bug report (:

rich adder
serene barn
rich adder
#

you can just use that variable there instead from same script

rocky canyon
rocky canyon
rich adder
#

ah yeah its good idea especially for saving movement speeds and such later, meant to say class lol

rocky canyon
#

its just a Layermask

#

as seen in the vid i just sent

serene barn
#

reading fens post

rocky canyon
#

layermask just makes it easier to deal with...
if u didnt have it, it could collide w/ anything with a collider

#

including the player..

serene barn
#
float rayLength = characterController.height / 2 + 0.2f;

dumb questing but what is the importance of this line

rich adder
#

layers is so you're not dealing with tags on everything.

rocky canyon
#

that would mean u'd have to check to make sure what u actually hit was the ground..

#

the layermask just makes it automatic.. (if ground is the only thing in layermask ground is the only thing the raycast would detect)

rocky canyon
#

so it only reaches a little farther out from the collider

serene barn
visual linden
rich adder
#

though personally I'd go for an overlap or spherecast to match the bottom half of the collider

#

if you are standing on an edge it might incorrectly say its Not grounded

rocky canyon
#

^ this works too.. thats fair..

swift crag
#

You want to fire the ray from a little above the player's feet

#

Otherwise, it might start below the floor

serene barn
rich adder
#

its a property of the character controller component

#

but I think you are use Rigidbody

rich adder
#

so you have to tap into the collider

serene barn
hushed root
#

Hi, i was practising with the frog plataformer in unity and made a box collider to check if i am on the ground so it can jump, the problem its that when i collide from above with the collectibles the collider takes its as if it isGrounded and let me jump again, i want it to only have one jump.

rich adder
#

there is no right answer

#

they both have their pros and cons @serene barn

sand sonnet
#

Do you think doing documentation is a really important aspect to the game?

rocky canyon
#

once u figure out (1) ray. u could always add more to improve the accuracy..
but as was said way way earlier..

theres more than 1 way to do ground detection..
SphereCasts, OverlapSphere, A basic trigger, etc etc

rich adder
#

games tripled in price and we dont even get a cd anymore let alone a manual

rocky canyon
#

i still have dozens of PS1 manuals 💪

rich adder
#

layer-based collision matrix and such

#

OR just use a physics query which lets you already filter out layers

sand sonnet
#

so how would you suggest i even start the game, firstly im guessing i need to make the main page right?

hushed root
#

thanks tho how do i exclude a layer from the trigger
i found exclude layer but it does not appear the layer in which the apples are.

serene barn
rich adder
#

also the ground check collider needs its own layer too

#

the collider that does ur ground check and do Exclude layers but tbh I never used that since its new and have used the collision matrix and did it globally

rich adder
sand sonnet
#

right ok so you would suggest to design the main screen first?

swift crag
#

Start with the gameplay.

#

You want to start poking at that core gameplay loop as soon as possible

#

what do you do in the game? start with that

#

notably, you don't fire up a game for the menu (:

#

(you can spend/waste 20 hours on a cool menu system later, like me!)

sand sonnet
#

right ok, so would anyone be willing to help me get started, like im guessing the square should fill up the entire display only a part of it?

rancid tinsel
#

if I want to have a check if an actual job was found, would it make more sense to make this return a bool instead of void?

rocky canyon
rancid tinsel
swift crag
#

also, "No job found" is a pretty misleading error

#

you gave it null!

rancid tinsel
# rich adder why not return the job ?

hmm i actually dont know why lol, i guess it achieves the same thing i just for some reason thought a bool (successful/unsuccessful) was more appropriate in this case

rich adder
#

both are good

swift crag
#

(also, this will lose your paused job if you start three jobs in a row)

true owl
#
using Unity.Cinemachine;
using UnityEngine;

public class PlayerCameraSettings : MonoBehaviour
{
    CinemachinePositionComposer cinemachinePositionComposer;
    [SerializeField] float cameraOffset = 0.13f;
    [SerializeField] GameObject cameraObject;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Awake()
    {

        cinemachinePositionComposer = cameraObject.GetComponent<CinemachinePositionComposer>();

    }
    // Update is called once per frame
    void Update()
    {
        Vector2 screenPosition = cinemachinePositionComposer.Composition.ScreenPosition;
        cinemachinePositionComposer.Composition.ScreenPosition = new Vector2(transform.localScale.x > 0 ? cameraOffset : -cameraOffset, screenPosition.y);
    }
}

#

what's wrong with this

#

it says my line with the Vector2 screenPosition = cinemachinePositionComposer.Composition.ScreenPosition;

#

is null

rancid tinsel
true owl
#

wait

#

one second im still writing sorry

visual linden
rich adder
#

best of both worlds

swift crag
#

i should point out that no job is being created in that method

#

you give it a job and it runs it

rancid tinsel
true owl
#

nvm

polar acorn
true owl
#

i fixed it thx

sand sonnet
#

should i do these with him or just take notes on what hes saying?

visual linden
true owl
#

i put the object in the inspector while the thing was running

swift crag
rich adder
swift crag
#

but yes -- I do enjoy myself a Try* method

#

My current procgen system is littered with stuff like

#
public abstract bool TryGetPosition(out Vector3 result);
#

If it fails, false is returned

rancid tinsel
swift crag
#

I may replace that with a "result type" at some point

#

either "okay, here's the answer" or "error, die"

#

then I could chain them together

#

shit, i'm inventing monads

#

monoids? in the subcategory of endofunctors? in my codebase...?

visual linden
#

Do love a nice results object though

swift crag
#

yeah, I'm looking around for a good way to do that right now

#

C# has...some pattern matching

hushed root
swift crag
#

Inheritance is a tempting way to do this, but it often winds up shooting you in the foot

#

most obviously if you ever wind up wanting an item that does two things

mystic lark
#

Hi im still learning C# and unity and i have this script of a bow im trying to make but i have no idea how do i make the arrow fly the arrow spawns but when i hold the right click and click the left click it doesnt go any suggestions?

visual linden
#

When I need flexibility in code, I usually tend to end up with something like this.

sand sonnet
#

So just wondering, how would I make a loading screen?
Like when you load up a game, how would I design that?

swift crag
sand sonnet
#

No I mean, how would I add it onto the unity project

swift crag
#

I keep running into it when coming up with inventory systems, though

visual linden
#

I've only ever turned to scriptable objects when I've had really boring content tasks, like creating new item or skill variants- there, scriptable objects can be useful as a non-coder alternative that lets you offload the work to designers or interns.
But nowadays I'd expect this stuff to live online somewhere and not in the project.

sand sonnet
#

Oh what how to add photoshop files onto a project?

visual linden
dreamy wren
#

no when i did it if i was moving I would stay moving in that direction

rich adder
#

so you just undid everything and wrote the same code?

#

why would someone waste time helping again

visual linden
dreamy wren
#

Im newer so if you dont want to help im not forcing you

rich adder
slender nymph
#

ew if you're gonna use the input manager, you should at least be using keycodes rather than strings if you're working with keys directly rather than buttons/axes

rich adder
#

would've been easier to just state what was not working with the newer solution then we could've gone from there 🤷‍♂️

visual linden
slender nymph
#

and spoonfeeding is apparently compulsory

rich adder
#

events is not exactly beginner topic

dreamy wren
#

If that makes it easier then yes, how do I switch?

visual linden
rich adder
#

how to overcomplicate a simple boolean check 101

dreamy wren
#

Will it help even if im doing a 2d style?

visual linden
hot laurel
#

store items as ScriptableObjects and implement interfaces for functionalities, so you can have base items and their wariants easy to configure 🙂

sand sonnet
#

wait so how do i make different kind of like pages, im guessing i can link them up from buttons

visual linden
slender nymph
#

technically you wouldn't even need to do that if you reference the input actions directly which can be pretty convenient for some

sand sonnet
#

you should make a document of anything you know haha

dreamy wren
#

Ok i will, thank you all who helped

slender nymph
small shale
#

im a beginner and I made this script to make the player move left and right using a tutorial. But it doesn't seem to work, any solutions?
Image

#

ill try it!

slender nymph
#

a velocity of 1 will move, if it isn't moving at all then something else is wrong

small shale
#

yall are some much more welcoming that the ue5 discord they all bully me lol

slender nymph
#

and a velocity of 100 is way too fast

small shale
#

okay

#

where would i put that in the code?

#

ok

#

yeah i think you found the issue nothing is coming thrpough.

sand sonnet
#

Vengeful you any good with ui

#

oh lol as i just wanna get this one thing done lol and i cant find it on the tutorial or its not really on the chapters

small shale
#

so what should i do from this point (sorry to interuptt danny) because i dont really know C# as i JUST started and I cant seem to fix the problem

#

all im trying to do is make it so you move

#

left and right

#

in a 2d space

#

that it lol

#

wasd

#

the video said it will be automatic in the settings input as wasd if you do the move code or whatever

#

ill look at that

#

hey vengeful! Im not sure if you will see this but I have been troubleshooting for a while and I dont understand how to fix this still I managed to call the input through the info on the website you sent but I dont know how to make it so I can use those inputs in the code later, any help?

lament harness
#

can someone explain to me what GetComponent<> Means i foudn definitions online but idk what it means

small shale
#

youre like "getting" it

slender nymph
lament harness
#

yo i need a dumbed down definition bro

slender nymph
# lament harness yo i need a dumbed down definition bro

you should start by learning the basics of the engine if that is not clear. there are beginner c# courses pinned in this channel and the junior programmer pathway on the unity !learn site will teach you how to use c# with unity

eternal falconBOT
#

:teacher: Unity Learn ↗

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

small shale
#

oops i forgot lmao

#

hold yp

lament harness
small shale
#

i mean its basically the same screenshot i had earlier but ill send anyways

slender nymph
small shale
lament harness
#

ok i get that kinda, but what does accessing it do

small shale
slender nymph
lament harness
lean sandal
#

Hey there everyone I just have a basic question here I want to learn more about.

Say for example I’m moving a player or object.

What’s the difference in using

transform.translate vs. transform.position

slender nymph
lament harness
#

im trying to learn

#

the bare min

#

before starting

#

isnt that how it works?

lean sandal
#

Theef i highly recommend you get on udemy.com and find you some good basic courses to take.

#

So they basically both do the same thing?

small shale
#

and is this meant to print something in the colsole when you hold the w key?

slender nymph
lean sandal
#

Oh okay thank you both so much!

#

So one is more accurate

#

Basically

slender nymph
lean sandal
#

So whats better to use for player movement for example? And why

small shale
#

so uhhh i put that somewhere and it still doesnt work where do you suggest i put it in the code

slender nymph
small shale
#

its in there already Uh

#

i pretty sure lemme check

#

oop 🫢 its not connected to the player how do i do that again

#

wait

#

the entire thing should work now

#

i just fixed it lol

#

i cant believe i forgot that lol

slender nymph
#

using the AddComponent menu. but it sounds like you should go through the beginner pathways on the unity !learn site if that was something you overlooked

eternal falconBOT
#

:teacher: Unity Learn ↗

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

lean sandal
#

Its always nice to find the mistake you made in your code thats part of making you better I think especially when starting out 🙂 gives you a skill or inspecting it and learning the language or how to operate the editor etc

#

I rlly have so much to learn 😭

small shale
#

YAYYY it worked

true owl
#
    Vector2 startPosition;
    [SerializeField] GameObject deathBox;
    Animator animator;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        startPosition = transform.position;
        animator = deathBox.GetComponent<Animator>();
    }

    /* if we've collided with the death box, ie, fallen off the stage
     reset player back to start position */
    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("DeathBox"))
        {

            Debug.Log("respawn");
            animator.SetTrigger("dies");
            StartCoroutine("ResetTriggerCoroutine");
        }
    }

    IEnumerator ResetTriggerCoroutine()
    {
        yield return new WaitForSeconds(1f);
        animator.ResetTrigger("dies");
        transform.position = startPosition;
    }

is there a way to make it so I don't need a coroutine and once that animation is done, it just does the respawn instantly?

slender nymph
#

use an animation event

true owl
#

👍

severe onyx
#

Im using this bit of code to show a little damage number on an enemy that's hit by an attack

            dmg.rectT.anchoredPosition = Camera.main.WorldToScreenPoint(d.transform.position) + new Vector3(Random.Range(25f, -25f), Random.Range(25f, -25f));

but it seems to break when the game is running in a resolution other than 1920x1080. is this an issue with the code or with the UI panel Im anchoring the number to?

#

these are the canvas settings, for reference - although if it's not the code I suppose I shall take this to #📲┃ui-ux

severe onyx
#

interesting

#

how would I translate the enemy's position to the screen point for the second parameter?

rocky canyon
#

and seems to work well w/ scaling

#

theres a WorldToScreen function i think

#

instead of using AnchorPosition you end up only needing to use localPosition

grand snow
#

if the canvas is in overlay mode you can do world to screen and set .position on the rect transform.

rocky canyon
#

ya, i sorta just tinker around w/ screen stuff until it works correctly 😅

severe onyx
grand snow
#

dunno i didnt check it 😆

rocky canyon
grand snow
rocky canyon
#

i also had problems using anchoredPosition w/ scaling

#

so thats why i ended up using the RectTransformUtility funciton

severe onyx
rocky canyon
#

no clue how i got there.. it was a multi-step process for sure lol

grand snow
#

well rect transform inherits position from transform so yes set .position on your rect transform

rocky canyon
#

it really helped me to debug my values too..

severe onyx
#

this seems to have improved things, but Ill have to test again tomorrow with a screen with a real, physically higher resolution

#

but it behaves consistently now no matter what resolution I set the unity game window to at least

#

god I hate UI stuff sometimes

grand snow
#

It will always work because .position is the global position and for overlay canvases that is pixel

swift crag
#

It's pretty straightforward for an overlay canvas.

grand snow
#

other canvas render modes are different so there you have to fudge more but overlay its all good 😄

severe onyx
#

I cant really tell you how Ive arrived at using the anchoredPosition ngl

rocky canyon
#

you may also need to tweak ur offset as well.. depending on how much scaling ur wanting to allow on ur screen

swift crag
#

For other canvas modes, you'd just need to transform back from world space to the appropriate local space

severe onyx
#

Im sure I had some reason at the time

#

maybe I WAS using a different canvas mode at the time

swift crag
severe onyx
#

but it's definitely overlay now

swift crag
#

since that is, indeed, a world-space position

grand snow
#

awesome. ive done ui stuff a lot so i know a lot of the quirks

severe onyx
#

ty for the help, I may or may not show up again tomorrow after testing on my desktop

#

this has been bugging me so long and I kept thinking "I should really post on the discord about this" and just never did lol

rocky canyon
#

lol.. my UI system is held together with hopes and dreams..

severe onyx
#

duct tape and a lot of spit over here

grand snow
rocky canyon
#

as long as i don't touch it anymore it'll continue to work >8)

severe onyx
#

Im just doing one last round of cleanup before building a demo I wanna show my friends

#

which is equally exciting and terrifying lol. but very glad to have this thorn in my side sorted out (hopefully)

swift crag
#

UI is much nicer when it's not developed via trial and error (:

grand snow
#

when trying to make layouts work, often you need to add a layout element to override stuff that comes from image or tmp text

swift crag
#

for auto layout, yeah

#

plus layout groups all the way down

grand snow
#

unity moans like "noo dont use a content size fitter here bad" but it works 😐

swift crag
#

the secret is that you don't have to use content size fitters there

#

just put more layout groups in!

#

let the layout system do its job!

grand snow
#

yea thats true it will size that from the preferred height/width too

swift crag
#

every object needs to understand how much space it needs

#

if it has children of varying sizes, then it should have a layout group so that it can ask its children how much space they want

#

if it doesn't, it should have a layout element that explicitly tells it how much space it needs

#

content size fitters only belong where you don't have a parent that cares about your size

#

e.g. on the content object of a scroll view, or on the very top level of a floating window

severe onyx
swift crag
#

Unity has managed to engineer the UI system so that auto layout is impossible to use by default

#

Layout groups are set to force expand their children and to not control child size

#

Every single preset object (e.g. the Button) implodes when subjected to automatic layout

#

(because they don't have layout groups)

grand snow
#

yea there are probably times i could do it properly.
Tbh id rather swap to the new way and use flex 🙂

swift crag
#

the Button object doesn't understand how much space its child Text object needs

#

therefore it turns into a ridiculous 1x1 pixel

grand snow
#

i think im just used to the bullshit

swift crag
#

it's nice to create a UI and know that it's going to work right

#

instead of randomly hitting it with a hammer and force-updating the layout 30 times per frame

grand snow
#

some game i work on has some animating bars that open with layout groups inside (masked) and that has to be forced to update

fringe plover
#

Why
UnityEngine.UI.LayoutRebuilder.MarkLayoutForRebuild(layout);
doesnt return null object reference exception if layout is null?

severe onyx
swift crag
#

Sort of

#

You get a UI that only sometimes works

#

If the parent of the button cares about the button's size, the objects have to update in exactly the right order

#

You should just put a vertical or horizontal layout group on the button (either works)

#

then set it to control child size and not to force expand the children

#

Content Size Fitter should be used when your parent does not try to control your own size

#

for example, in a scroll view, you have a "Content" object that's moved around

#

the Content object can get really big, but the scroll view doesn't change in size

#

so the Content object needs a ContentSizeFitter on it

fast copper
#

im i able to send large scripts in if so do i just send the file?

swift crag
#

!code

eternal falconBOT
swift crag
#

Use a paste site.

fast copper
#

https://paste.mod.gg/xksayvbtcfyw/0

The issue is ive used NavMeshComponents for my enemy script which is outdated and wont work with current unity, is there a way around this that isnt go back to a old release. I wrote the code from a tutorial i was following ill link it if wanted. (ignore my code notes and now that I see it all there isn't a lot of script)

swift crag
#

Just use the "AI Navigation" package.

#

AFAIK it's just a continuation of that original NavMeshComponents repository

fast copper
slender nymph
#

it's in the package manager

swift crag
#

It is found in the Unity Registry section of the package manager.

#

(it's not even one of those weird invisible packages)

fast copper
sand schooner
#

Hello, so I have a game object which is just a 3d cube. It spins and rotates slowly randomly. I have another game object called power up that I want to spawn on one of the cube faces randomly, and it can spawn anywhere on the cube face. Then every 10 seconds move it to another random face, and random location on that face. Any recommendations on the best way to go about this?

timber tide
#

what do you mean on the face

#

like texture related or another 3D object

sand schooner
#

face as in the cube has 6 sides (faces)

timber tide
#

if it's a 3D object, just define a bunch of empty gameobject as points you can reference

#

or do math

old bolt
#

Hello can someone explain to me why this give a error:

    {
        PlayerControls = new PlayerControls();
        PlayerControls.Enable();

        PlayerControls.PlayerActions.Enable();
        PlayerControls.PlayerActions.SetCallbacks(this);
    }

    private void OnDisable()
    {
        PlayerControls.PlayerActions.Disable();
        PlayerControls.PlayerActions.RemoveCallbacks(this);
    }
Severity    Code    Description    Project    File    Line    Suppression State
Error    CS0120    An object reference is required for the non-static field, method, or property 'PlayerControls.PlayerActions.Enable()'    Assembly-CSharp    F:\dev\3D project\Assets\Scripts\PlayerLocomotionInput.cs    15    Active
Error    CS0120    An object reference is required for the non-static field, method, or property 'PlayerControls.PlayerActions.SetCallbacks(PlayerControls.IPlayerActions)'    Assembly-CSharp    F:\dev\3D project\Assets\Scripts\PlayerLocomotionInput.cs    16    Active
Error    CS0120    An object reference is required for the non-static field, method, or property 'PlayerControls.PlayerActions.Disable()'    Assembly-CSharp    F:\dev\3D project\Assets\Scripts\PlayerLocomotionInput.cs    21    Active
Error    CS0120    An object reference is required for the non-static field, method, or property 'PlayerControls.PlayerActions.RemoveCallbacks(PlayerControls.IPlayerActions)'    Assembly-CSharp    F:\dev\3D project\Assets\Scripts\PlayerLocomotionInput.cs    22    Active```
north kiln
#

!code

eternal falconBOT
sand schooner
north kiln
#

The game objects would be parented

sand schooner
#

yeah the cube is the parent of the power up object

#

So you reccoment having a bunch of game objects all of the cube that are inactive, then randomly pick one to be active?

north kiln
old bolt
#

PlayerControls is C# script made by the input system

north kiln
north kiln
north kiln
#

That's the very verbose and hard to work with version of what I said, yeah lol

old bolt
sand schooner
north kiln
old bolt
north kiln
#

I would start by renaming your PlayerControls property to anything else, so it's differenciated completely from the class Unity generated

sand schooner
#

tbh the lots of game object solution sounds simpler. The code I posted is causing the game object to spawn super far from the cube

north kiln
#

It's certainly simpler if you don't put in the effort to write and understand code yourself

old bolt