#πŸ’»β”ƒcode-beginner

1 messages Β· Page 55 of 1

verbal dome
#

That looks like the Windows 3D viewer?

#

Don't double click the 3d file

silk night
#

Dont try to preview stuff by using the inspector, use the Spacebar to trigger the jump

tawdry rock
#

opps, wrong reply, sry

austere monolith
#

let me show you a video

timber urchin
#

Or wether im grounded

silk night
#

For your jump: because its only true for one frame, depending on your framerate thats ~10ms

#

no way you can see that

austere monolith
silk night
#

Isgrounded because you only update it on OnCollisionStay, while you are in the air you touch no collider

verbal dome
#

Yep and for the grounded check, the logic is wrong

#

Yep

#

Maybe OnCollisionExit instead

silk night
#

set it to false on OnCollisionExit and to true in OnCollisionEnter

#

(with a ground tag check)

timber urchin
#

Ah alrighty

#

Got it thanks

verbal dome
#

Though I find physics queries (OverlapSphere, Raycast etc) more robust than collisions for ground check

#

But you can try that later

silk night
#

If the bones are different the animation does not work

timber urchin
verbal dome
#

The problem I see with collision-based ground check:
Let's say you stand on 2 floor objects at the same time. You move right, and you no longer touch the floor on the left. This causes OnCollisionExit to trigger and your isGrounded becomes false even though you are still touching the floor on the right

timber urchin
#

Ohh yeah that makes sense

languid spire
#

so use an int instead of a bool

timber urchin
#

So im assuming the change in the jump bool in the inspector wont be visible when it happens due to it being so quick?

verbal dome
#

Yes

timber urchin
#

Alrighty thanks that makes sense

verbal dome
#

Inspector updates at like 10fps only

timber urchin
#

Oh damn

verbal dome
#

And less rapid changes

white glade
#

Hello ,
I trying to do a camera wobbling , when the player move and when the player sprint
my problem is when I change the offset of the visual camera it shakes a lot , so is there any way to remove it ?

    public void ChangeCameraWobbling(float zOffset, float amplitudeGain)
    {
        virtualCamera.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>().m_AmplitudeGain = amplitudeGain;
        virtualCamera.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>().m_PivotOffset.z = zOffset;
    }

this is my code and here is a vedio of it

tawdry rock
#

how can i animation cancel? for example if my roll animation is 30 frame but if i jump stop the rolling and start jumping animation? im using currently animator + triggers via c#

silk night
#

transition with a trigger and no exit time

tawdry rock
#

i unticked the exit time, care to explain me this transition thingy?

silk night
#

with exit time you can only exit at a specific frame

#

without you can do it anytime

#

but that only works with a trigger

#

or do you mean what a transition is in general?

tawdry rock
#

i think i got it, thank you.

dapper lava
#

i have a soldier with empty game object at the end of gun but when the soldier(parent) rotate the game object(child) doesnt

crystal magnet
#

Hello there. Can someone help me about this error? This error doesn't affect anything in the game's functionality, but I don't know what it means and I don't really understand what it says. This error only appears at the beginning of the application execution. If I close the unity editor and open it again it disappears, but after a certain amount of programming time it appears again.

silk night
dapper lava
#

it moves together with soldier when i rotate him and move him but doesnt rotate itself

languid spire
dapper lava
proud trellis
#

whenever i try to open unity hub it says there is a critical error quits. would you be able to help me?

#

anyone be able to help me*

crystal magnet
silk night
proud trellis
dapper lava
silk night
#

yes

#

if you set it to object it shows the real rotation

#

"local" sorry

languid spire
proud trellis
#

ok thank you

dapper lava
silk night
#

yes, most likely

dapper lava
#

should i keep it pivot and local

silk night
#

you can stick a 3d object on it

#

to see if it rotates

#

usually you wanna keep it global

dapper lava
#

it rotated when i selected it with "Rotate tool" on scene

proud trellis
#

would it be possible for you to send another link

grim stream
#

For some reason it doesn't fetch the object reference. I cannot find why.
There is one object in the scene with a Level script

grim stream
#

Yes i think so

#

or yes

#

it is

#

Its being referenced by other objects. just this one that doesn't want to

slender nymph
#

then you need tp provide more context. are you certain that line of code is running? are you certain it runs after the Level object has been created/activated/whatever?

#

also if both objects exist in the scene at edit time you're better off just serializing a reference to the object directly instead of using Find

grim stream
#

Oooh okay i found the problem. I put the reference as public. to give access to inheriting classes. How do i give inheriting classes access to the reference without putting it as public. Or should i not do it like that

short hazel
#

protected

slender nymph
#

inheriting classes can access public or protected members

#

but i also don't see how it being public makes it not work

grim stream
#

πŸ€·β€β™‚οΈ

#

When i put it to private it worked sholthink

slender nymph
#

are you sure that is what fixed it, and not perhaps just saving the code and compiling some other change?

silk night
#

My guess would be on a race condition with random outcome πŸ˜„

#

which object loads first

grim stream
buoyant matrix
#

So I'm trying to instantiate a projectile and have it move in the direction I'm facing... I haven't figured out the facing part, but my projectile doesn't move at all. Im doing the following, and my projectile speed logs at 4, and my transform.forward logs as (0.00, 0.00, 1.00), but when I multiply them, my velocity is (0.00, 0.00). What am I doing wrong? float projectileSpeed = projectile.GetComponent<ProjectileBehavior>().projectileSpeed; Debug.Log($"Projectile speed: {projectileSpeed}"); p.velocity = transform.forward * projectileSpeed; Debug.Log($"Forward: {transform.forward}, Velocity: {p.velocity}");

slender nymph
#

you're gonna need to provide more context. is this 2d?

buoyant matrix
#

Sorry, yes. This is 2d. I'm pretty new. What context can I provide to help?

slender nymph
#

well that's why it doesn't work. transform.forward points forward along the z axis which is just used for depth.

grim stream
#

what is p?

buoyant matrix
#

p is a RigidBody2D

slender nymph
#

you probably need to use transform.right or transform.up depending on the rotation of the object when it is not rotated

buoyant matrix
#

Ahhhh. Okay. I tried transform.right, but I think the projectile just stayed there too. But let me try again.

dapper lava
#

i atached camera on top of my player but i dont want it to rotate when i move my mouse around how do i do it

slender nymph
#

don't make the camera a child of the player

#

use cinemachine and just make the camera follow the player but not rotate with it

buoyant matrix
#

Ugh. That was it. Thank you. πŸ˜„ Is there a good way to get the facing of the current sprite? Or do I need to save it as a variable and change it anytime we change direction?

dapper lava
#

cinemachine?

#

wouldn't it just be easier

#

every frame just reset camera rotation to 0 0 0

slender nymph
buoyant matrix
#

I definitely don't, and it just shoots to the right, regardless of facing, so I'll have to keep track of direction and rotate manually. Thank you!

slender nymph
dapper lava
#

how to use it and what is it

#

i will just google

#

transform.rotation = Quaternion.Euler(0f,0f,0f);

#

i started unity yesterday that's good enought

slender nymph
#

i mean okay. but you should still learn how to use cinemachine. it's an incredibly useful tool and you won't end up with stuttery/shitty cameras

buoyant matrix
#

I'll google.

dapper lava
#

i will

buoyant matrix
#

That was easy. πŸ˜„

silk night
# dapper lava i will just google

Boxfriend just suggested cinemachine 2 weeks ago to me, it was like switching from a toyota to a lambo, you will thank him later πŸ˜„ and i was using the old camera system for 3 years before

dapper lava
#

i want my game first to wark later to look
i like programming more

silk night
#

cinemachine works better, it looks the same by default

#

old camera is basically dumb and you have to do everything by hand, cinemachine you tell it what to do and it just does

slender nymph
# dapper lava i want my game first to wark later to look i like programming more

just beware that having your camera as a child of your player is even worse than just writing your own camera script for it. it's rotation and scale will also be affected by the player. and if you are moving your player with physics you'll end up with a very stuttery looking camera (though it will just appear as if your player's movement is what is stuttering)

dapper lava
#

now itry to make a background
and i have rock texture and it worked in 3d
but i dont know how to put it on 2d sprite

ruby python
#

Would anyone know of any guides/tutorials on how to do vertex displacement through code (not shader), ideally for a sphere please? I've had a look around but everything I've found is shader based, which won't work for what I have in mind. πŸ˜•

silk night
#

he has a series where he makes a planet

ruby python
#

Yeah, I'm looking at his planet generation stuff atm, but tbh I'm a bit lost translating what he's doing with noise toi using an image instead.

silk night
#

click on it and you can set the type at the top

dapper lava
#

ok and how do i make the pattern repeat or do i have to put 100 10x10 sprites to make abckground

silk night
#

well you can just put a plane in your game and apply the texture to it

#

instead of a sprite

buoyant matrix
#

I just switched from doing individual keypresses for movement (WASD) to using Input.GetAxis() to get whether someone is pressing a key... I've noticed that it went from being very precise movement to there being a 'cooldown' where the axis is still going from 1 to 0. Is there a way to avoid that and instantly have it hit 0 when I stop pressing a button?

summer stump
buoyant matrix
#

Perfect! Thank you!

dapper lava
silk night
#

certainly possible

#

but not a thing we could just explain here

#

thats a multi step process

dapper lava
#

can you change camera of a player with script mid run

slender nymph
#

that's even easier with cinemachine

dapper lava
#

oh yes

#

the camera is lagging i am learing it

#

tutorial said i should have cinemachine up here

#

i dont have it

silk night
#

Go to windows -> package manager

dapper lava
#

i see

silk night
#

and there in unity registry search for cinemachine

slender nymph
#

even if you have the package it's not up there anymore. you can create cinemachine objects from the regular Create menu.

silk night
#

oh right πŸ˜„

dapper lava
#

got it

#

can i pin cinemachine to the top

silk night
#

no need for that

#

just rightclick in the hierarchy and it offers you to create everything you need there

dapper lava
#

can i reduce the delay with movement

silk night
#

what delay do you mean exactly?

slender nymph
#

probably means the damping for the camera

dapper lava
#

when i move the camera move with delay

#

and where can i change the camera view size

slender nymph
#

yeah reduce the damping on the vcam

dapper lava
#

how do you reduce it

slender nymph
#

change it from it's current value to a lower value

silk night
dapper lava
#

and camera distance

#

so i can see more

slender nymph
#

you should go through the documentation pinned in #πŸŽ₯┃cinemachine to learn how it works instead of asking for every little thing

buoyant matrix
#

What should you expect in a script, when you call transform.parent? I assumed (incorrectly) it would be the parent of the current script?

slender nymph
#

it would return the parent transform for this component's transform. if the object has no parent it will be null

buoyant matrix
#

Is there a good way to get the "main" object this script is attached to? Ideally, I'm trying to get a variable from another script attached to the same object.

slender nymph
#

what do you mean the "main" object?

buoyant matrix
#

So I have a Player Gameobject, and attached is two scripts. I'm trying to get a variable from the other script attached to the Player object.

slender nymph
#

if it's the same object it's just transform or gameObject. or you can just call GetComponent to get another component on the same object

buoyant matrix
#

oh. I was making this way too hard.

#

(As usual πŸ˜„ )

slender nymph
#

you would probably benefit from going through some beginner courses to learn how to use the engine. i recommend 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!

buoyant matrix
#

Thanks. I'll take a look as soon as I figure out how rotation works. πŸ™‚

acoustic arch
#

should i weapons base stats be held on the scriptable object for it?

#

or how else should it be done instead

proud trellis
#

still having issues anyone got any suggestions?

slender nymph
#

this is a code channel

summer stump
summer stump
summer stump
#

What? I'm just pointing out that you have been told multiple times that this is the wrong place to post that.
You're welcome

buoyant matrix
#

So I can see the facing, and I can see the euler angles, which go like 0.00, 0/90/180/270, 0 but my projectile always only shoots right. If I'm facing up or down, it doesn't shoot at all. What am I doing wrong here? Rigidbody2D rigidbody = projectile.GetComponent<Rigidbody2D>(); Rigidbody2D p = Instantiate(rigidbody, transform.position, transform.rotation); p.transform.eulerAngles = transformProjectile(); // This returns the vector3 Debug.Log($"Euler angles {p.transform.eulerAngles}"); float projectileSpeed = projectile.GetComponent<ProjectileBehavior>().projectileSpeed; Debug.Log($"Rotation {transform.rotation}"); p.velocity = transform.right * projectileSpeed; Debug.Log($"Forward: {transform.right}, Velocity: {p.velocity}");

slender nymph
#

are you actually rotating the object this component is attached to? or are you only rotating the sprite?

buoyant matrix
#

Hrm. good question. I think I'm rotating just the rigid body.

slender nymph
#

that would rotate its transform (on the next physics step). if this component is attached to that same object or a child object then it would rotate with it

buoyant matrix
#

Hrm. No, p is the instantiated projectile... Rigidbody2D p = Instantiate(rigidbody, transform.position, transform.rotation);

#

So that should rotate the whole thing, shouldn't it?

slender nymph
#

well the projectile would be rotated to the same rotation that this object is rotated to, yes.

buoyant matrix
#

I updated my code above... If the euler angles when I'm facing right are 0, 0, 0 and when facing up, 0, 270, 0 and facing down, 0, 90, 0 and when facing left, 0, 180, 0 shouldn't that rotate the projectile that's instantiated?

slender nymph
#

why are you changing its rotation immediately after instantiating it with a specific rotation? just give it the correct rotation when you instantiate it

buoyant matrix
#

Oh. That would make more sense.

slender nymph
#

it will also not make a difference as to whether it is rotated or not and has no effect on the velocity since you are using this object's rotation for the velocity, not the spawned projectile's rotation

buoyant matrix
#

oh. because I didn't know how to go from a vector3 to a qquaternion. πŸ™‚

buoyant matrix
#

Because when I change to this: Rigidbody2D p = Instantiate(rigidbody, transform.position, transformProjectile()); it says to use a quaternion, and it can't change from a vector3 to a quaternion

slender nymph
#

but what does transformProjectile do

dapper lava
#

how do i add velocity in direction object is facing

buoyant matrix
#

It looks at the player's facing, and returns a vector3 based on that facing.

#

And that vector 3 is 0, 0/90/180/270, 0, which is obviously wrong. πŸ˜„

slender nymph
#

instead of showing all these disjointed snippets can you share the whole fucking class so that i don't have to play 20 questions to learn wtf your code is supposed to be doing?

dawn sparrow
#

is it possible to write you own mesh class and custom mesh shader/renderer ?

eternal needle
slender nymph
#

only in 3d πŸ˜‰

buoyant matrix
#

Sure. sorry. I was trying not to flood the channel.

dapper lava
slender nymph
eternal falconBOT
slender nymph
buoyant matrix
slender nymph
#

return new Vector3(0, -90, transform.eulerAngles.y);
why are you putting this object's Y rotation as the z rotation?

eternal needle
modest dust
#

Basically check what is the type of the variable you're trying to modify (and if you even can modify it)

buoyant matrix
#

@slender nymph Because I'm an idiot. :/

dawn sparrow
#

i'm trying to render a voxel world using cubic chunking (32x32x32), so what that means is i can do away with the float-level precision for each vertex of an individual mesh, i only need 6 bits per axis to describe the position of any vertex in a chunk mesh relative to its chunk

#

issue is, unity meshes uses floats to describe their chunk positions, and shaders follow that by taking in floats from the datastream

#

i dont need float, i need a single byte per axis, or just 18 bits to describe a vertex position, + 1 float4 for the chunk position relative to the world origin

buoyant matrix
#

okay. changing it to return new Vector3( -90, transform.eulerAngles.y, 0); didn't make a difference. I'll go watch some unity videos first.

#

@slender nymph thanks for your patience.

dawn sparrow
#

I've thought of two solutions for this:

  1. write my own mesh class
  2. leave vertices and triangles empty for a default unity mesh, and instead utilize a TEXCOORD to stream in my custom data
#

I'm tempted to go with option 2 cuz it sounds much much easier but i don't know how much memory waste that'll entail

#

so i'm not too sure what to do, i have no experience with meshes or shaders so i might have things completely backward

acoustic arch
summer stump
#

You could even make the upgrades ScriptableObjects though

proud trellis
acoustic arch
#

it feels a little clunky

#

and bad to look at

summer stump
dawn sparrow
modest dust
summer stump
acoustic arch
#

but i am having an odd error and im not sure what it is

#

on line 15 it says object is not instanced if an item slot is active

summer stump
acoustic arch
#

my 2nd time ever using properties so i mightve made a mistake

proud trellis
dawn sparrow
#

sure, but you were a bitch about it

summer stump
dawn sparrow
#

and still, not the correct place, continue asking in the correct channels or searching it online

summer stump
proud trellis
#

theres not much more info i couldve provided

summer stump
acoustic arch
proud trellis
acoustic arch
summer stump
acoustic arch
#

ask where to gettem if you dont know

acoustic arch
#

in unity

#

not the compiler

#

but im not sure how it would be getting that

#

its only when a slot is active and it has an item in it

spark trail
#

Hi guys, I have a Player object and a gameobject that will be "collected" if a certain part of the player object touches the gameobject. I've added Colliders to both and marked the pickupObject as 'trigger'. On the player object, I have two colliders, one to act as the physical "body" of the character and one to act as the point that will be used to "collect" the pickupObject if it comes into contact. However, no matter what I do, I cannot seem to get this to work. It either triggers on the body and not the top, or none of them at all.

summer stump
acoustic arch
modest dust
summer stump
summer stump
acoustic arch
spark trail
#

Yeah

acoustic arch
summer stump
spark trail
summer stump
acoustic arch
summer stump
acoustic arch
#

hold on

#

i know what to test

spark trail
summer stump
# acoustic arch when played
if (QSlotReplica._itemInSlot != null)
{
    _itemInSlot = QSlotReplica._itemInSlot;
}

This should probably be == null not != null

summer stump
acoustic arch
acoustic arch
#

it should just be replicated from the inventories quick slots

spark trail
#

Ahhh perhaps the polygon debug message is actually the pickupObject's polygon collider?

summer stump
eternal falconBOT
spark trail
# summer stump If you used other, that would be it. But if you don't use other, it wouldn't be....

Sorry I'm not sure what you mean. There's also no code besides the code I posted earlier, it's just inspector components. The pickupObject has a 'polygon 2d' collider which is marked as a 'trigger', the playerObject has two colliders, one is polygon and one is box collider. Both are not marked as a trigger but one is acting as the "body" of the player, the other collider which is a box, is above the body collider so that if the pickup object touches the "top" of the player ( I guess like a headshot in a FPS game?) it will then trigger and "collect".

however in my testing, I cannot seem to achieve this. The pickupObject is triggering both the player colliders and I can't find a way to separate them

summer stump
#

other is the parameter passed by OnTriggerEnter btw

summer stump
# spark trail

Also, it would have helped to see this uncropped, as I asked. You cropped it to only show the inspector

spark trail
#

okay I edited my post as it was slightly wrong, that's the current situation ^
and I can repost code no problem

#

oh sorry I thought the other bits were not importnat

#

a moment πŸ™‚

#
    void OnCollisionEnter2D(Collision2D col)
    {
        Debug.Log("OnCollisionEnter2D" + col.GetType().ToString());
    }

    void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log("Type: " + collision.GetType().ToString());

    }
#

One sec, lemme do that agian so its easier to read/se

summer stump
#

Ah yeah, OnTrigger2d's parameter is defaulted to collision. Sorry, that's what I meant by "other" earlier

summer stump
spark trail
#

OHHHHHHHHHHH you want the 'scene' ?

summer stump
#

every single thing on the editor

spark trail
#

Haha so sorry I misunderstood

#

Okay is that it? πŸ™‚

#

You can see the little green hollow box at the top, that is the point in which pickupObjects should actually trigger and "collect", but not the polygon (body) of the playerObject

summer stump
# spark trail

Yes, ok that is perfect.
Now that I can see what's going on, I can difinitively say you want the top part to be a child object

spark trail
#

I see

#

How might I do that? do I make another emptyGameObject and then attach the collider there?

summer stump
spark trail
#

Yeah, okay I get it now

summer stump
#

what is SkyCheck btw? That seems like a good thing to use for this purpose

spark trail
#

This makes so much sense now.... I can see why it was not working before.

#

Yes you're right SkyCheck would be ideal for this

dapper lava
#

how bad are particles for fps

dawn sparrow
#

can i create a custom mesh class whose vertices have custom data? I know about TEXCOORD data but I'm trying to reduce the number of bits per vertex from 4 bytes per axis to 6 bits per axis, and I'm not sure how else to do this

dawn sparrow
#

not a major impact

spark trail
dapper lava
#

so i have 2d game and bullets are very small and i want them to glow

dapper lava
spark trail
dapper lava
#

you can just put mesh colider without rigid body so it won't be able to be pushed back

#

i think there is mass option in rigidbody

spark trail
#

Oh I see

#

Thanks

summer stump
dapper lava
#

or you can give them huge mass and they will react very little

spark trail
#

Thanks guys , much appreciated πŸ™‚

summer stump
dapper lava
#

i started yesterday

deft quarry
#

I'm working on a 3d game and trying to get the hang of unity. When I move and look around my game objects in the scene, it looks like stop motion instead of the fluid movement and im not sure whether this is a camera, or movement issue, or if its something else.

#

Might be a little hard to see in that video

dapper lava
#

if i make a prefab and then change script will script of prefab also change?

short hazel
#

Change script in what way? The code itself, or you modify some values in the Inspector?

timber tide
#

If it's on the scene and you add a script it wont unless you click in the inspector to apply changes to the actual prefab asset instance

#

otherwise open up the prefab editor window and apply the script

short hazel
#

The things you touched compared to a prefab will be in bold, with a blue bar on the left of the Inspector

dapper lava
#

the script used for the prefab

short hazel
#

That does not answer the question

dawn sparrow
#

I'm trying to store vertex positions for my mesh in an optomized manner, so does anyone know of a way i can my per vertex position data in a TEXCOORD while leaving vertices[], triangles[], and all the other datastreams empty?

short hazel
#

Code changes are applied everywhere

dapper lava
#

for example i change varaible speed

#

so does prefab get coby of the script or will the prefab change how it works when i change the script

short hazel
#

In the code or on the Inspector??? We'll get to it one day I hope

dapper lava
#

in project files

short hazel
#

That's not a valid answer lmfao

dapper lava
#

i go to bed

#

gotta go

short hazel
#
  1. Code
  2. Inspector
    Choose 1 or 2
dapper lava
#

i think code

short hazel
#

You think?

queen adder
#

noncoalesomething does work in non-unity objects right?```cs
Shop toedit = AllShop.FirstOrDefault(shop => shop.shopID == ID) ?? AddNewShop();

short hazel
#

Ah, non-Unity objects it does

dapper lava
#

tis either code project.cs or what inspector for sure not inspector so it has to be code

short hazel
#

The Inspector is the thing on the right that shows the Transform, where you can add scripts and change their values

dawn sparrow
#

then figure out how to write a shader for that custom mesh class

timber tide
#

right, you'd use the vertex buffer functions it has then

dapper lava
#

i mean the project.cs script

timber tide
#

that stuff

dawn sparrow
#

but it sounds a lot easier, if it's possible, to kind of use the existing mesh class as a husk that doesnt store any information in its traditional fields, and i route all my custom packed data thru TEXCOORD

dapper lava
#

probably not inspector

short hazel
dapper lava
#

i have never opened code from inspector

#

ok

#

thanks

dawn sparrow
#

is this exactly the function

timber tide
dawn sparrow
#

i was praying to the lord

#

exists?

#

ok, im not at all familiar with the lingo, like i'm not sure what exactly thatmeans but I'm pretty sure this is literally exactly the thing i was looking for

#

thank you so much man

#

so is this the "husk" thing i was talking about where it basically pretends there x number of vertices ?

timber tide
#

yeah, the difference between these methods and what the mesh class original has is you can pass all variables at once, instead of position then triangles, ect

#

I mean, this is like peak optimization if it matters I guess

dawn sparrow
#

thing is im creating a voxel world

#

so having so much precision is worthless for that

#

i saw a video where someone packed 96 bytes of per-vertex data into just 4, and it makes a lot of sense

#

but they did that in opengl, was trying ot figure out how to translate that into unity

timber tide
#

Right, you can probably just compute it all directly instead of using unity's API (or rather access the graphics API without going through too much of unity's API calls)

dawn sparrow
#

can you set a custom data type with this i wonder?

#

i guess it doesnt matter, since i need 4 bytes only

#

and that neatly packs into a float

timber tide
#

it's limited to these

dawn sparrow
#

i can probably work with that

timber tide
#

Oh, I thought it had indices/triangles too. Huh

#

I forget this stuff a bit

frank light
#

here is my full code: https://pastebin.com/1P7gPrTM ,

Hi I am trying to use the new input system for my jump code but it keeps giving me this error: NullReferenceException: Object reference not set to an instance of an object. I am doing it just like the example in the docs, so I am confused. does anyone know my problem?

timber tide
#

what line

frank light
final trellis
#

quick question about Mathf.Approximately(), is a variance of Mathf.Epsilon really "big" enough to account for floating point shenanigans?

timber tide
#
        if (playerInput.actions["Jump"].IsPressed() && _groundedPlayer)```
Quite a few things here, so I suggest you to debug log each of these such they are not null and then maybe you can find yourself the answer.
silk night
timber tide
short hazel
final trellis
#

istg ive seen floating point funny moments higher than epsilon

short hazel
#

Definitely, the bigger the value, the higher the error

frank light
final trellis
#

or am i misinterpreting the methods functionality

short hazel
#

Yes, it does

timber tide
#

So what you'd want to do is check each individual operation you're doing, starting from the first.

final trellis
frank light
final trellis
#

also wait the regular == automatically approximates when it comes to Vectors?

timber tide
#

Oh, does it? I still don't trust it enough ;)

final trellis
#

me neither, esp as a while loop condition

#

yeah what the hell unity

#

these 2 things sound like they should be swapped

#

programmers cannot name things ig

#

well just in case ima make an 'emergency exit' in the loop lol

hushed spire
#

I have a parent script that a few different children scripts extend. Is there a way to find all of the different scripts that extend this parent inside of the scene? like looping throughGameObject.FindGameObjectsWithTag("ParentTag")and than using GetComponent<ChildScript>() for all of them, except the child script's name will all be different, their only similarity being they all extend the Parent script.

summer stump
hushed spire
#

For a game over sequence basically

#

What do you mean by "there is reflection"?

summer stump
#

You should google reflection, but it's costly and not great to use

hushed spire
polar acorn
#

So, you want to find all objects that are child classes of some specific type?

hushed spire
#

Yes

hushed spire
#

Oh wow

#

This is going straight into my dumb moments to remember later

summer stump
polar acorn
#

If you also need to filter by tag, better to search by type first, then iterate through and check the tag

#

Just make sure to use CompareTag not == to check the tag

silent haven
#

https://pastebin.com/twB49GcZ
I made a code that moves a slime to a certain position and then slowly moves them to another, choosing one of three colors. my problem is that while the slime is in fact moving, it doesn't seem to be affected by the moveSpeed variable, even if i change it it's still the same speed

summer stump
silent haven
summer stump
silent haven
fickle stump
#

hey, does this forum only focus on unity 2D/3D or also VR?

slender nymph
fickle stump
#

yeah was wondering wether that is for code questions aswell or just general VR question stuff

#

thank you happy_laugh y

high pawn
#

Hey, i can ask a question here ?

fickle stump
high pawn
#

Here is my game when i start it instant with the level, and after when i use my menu to start the level, why my luminosity is so different ? idk how to fix that

rich adder
#

Even if not baked you should hit the bake button in lighting tab

high pawn
#

i just found :), ty

trail gull
#
    private void OnTriggerEnter(Collider other)
    {
        if (other.TryGetComponent<Goal>(out Goal goal))
        {
            SetReward(+1f);
            EndEpisode();
        }

        if (other.TryGetComponent<Wall>(out Wall wall))
        {
            SetReward(-1f);
            EndEpisode();
        }
    }
#

could someone tell me why im getting this error?

#

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

#

im getting the same error with 'Goal'

#

Wall and Goal are 2 3d objects I have with scripts 'Wall' and 'Goal' which are empty attached to them

teal viper
#

Share the Wall script.

trail gull
#

Its empty

teal viper
#

Doesn't matter.

trail gull
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WallCollision : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
#

oh

#

i see

teal viper
#

It's not a Wall

trail gull
#

yeah I just figured

#

thank you!

trail gull
#

like why do I use 'Wall' and then 'out Wall wall'

teal viper
summer stump
#
Wall wall;
if (other.TryGetComponent(out wall)

Would work too. Declaring it separately doesn't make sense if it's local. It's more for when it's a class variable so you can use it in other methods or classes

static cedar
#

Might be confusing for first timers how it works especially when C# lets and prefers you to automatically cut down what can already be said implicitly.

trail gull
#

Ah okay I think I understand

static cedar
# trail gull do you mind explaining what the things you input into `if (other.TryGetComponent...

The thing between the <> is the generic type argument, it's basically how the entire method operates as whole based on the type since it can dictate what type arguments or what it returns, depends on how they make the method work.

The out keyword is just another way to return a value from a method, since the method already returns a bool (true or false).

The Wall after out is the type of the argument. Noticeably, the type changes based on what's inside the <> or the generic type parameter.
Like he said earlier, you can cut down the thing inside the <> because C# already knows what the generic type is based on what you put in the arguments alone.

If you hover on the method the tool-tip should show TryGetComponent<TComponent>(out TComponent wall) where TComponent : Component or somewhere around that at least.

timber urchin
#

I've been trying for a while to do it on my own without help or searching and nothing seems to work, would anyone be able to point me in the right direction of making the player movement follow where the camera is facing i've got another script handling the camera

#

And this is the camera script

timber urchin
#

Ohh wait I'm guessing my mistake is not rotating the character on the horizontal axis with the camera πŸ˜‚

mental wren
#

Hi, need help with using unity for simulations

#

Basically the plan is to have NPC(s) that navigate the world based on slider settings (how much of the traversal journey will involve running, jumping, etc.)

The end goal is to use some type of ingame camera to record the pathing or resulting world interactions that said NPCs have.

What unity libraries or workflows that can be used for this?

brazen narwhal
#

why wont even the debug show up?

gaunt ice
#

the update is early return

#

that means you cant grab weapon once the current weapon is null

brazen narwhal
#

thx

buoyant matrix
#

Why if I do something like this so I g et an error? I'm checking for existence, and it's possibly undefined, but possibly defined? int x = 1; string myWord; if (x == 1) { myWord = "Hello, world!"; } if (myWord) { Debug.Log($"My word was {myWord}"); } It tells me Use of unassigned local variable 'myWord'

brazen narwhal
#

set it to "string.Empty" when you initialize it

buoyant matrix
#

Then myWord should be undefined and it won't go into that if block?

summer stump
buoyant matrix
#

@brazen narwhal This was actually something I found out when I was trying to debug a problem with another class. The real class is SpiritBehavior, which I can't set to string.empty πŸ™‚

brazen narwhal
#

oh ok

buoyant matrix
#

@summer stump Is there a different way to check for definedness?

#

myWord would be null, if x wasn't 1. Right?

#

So it wouldn't go into the second if?

polar acorn
buoyant matrix
#

Or do I not understand C# at all (which is quite possible, I'm very new to it)

#

@polar acorn Can I just set it to null??

brazen narwhal
#

the error is just that the variable is undefined, so you have to somehow define it as something

polar acorn
buoyant matrix
#

Gotcha. Thank you. That makes sense.

#

So I have to manually set it to null.

brazen narwhal
#

yes

polar acorn
#

There's a difference between an empty box and the abstract notion of a sudden lack of boxes

buoyant matrix
#

That makes sense.

brazen narwhal
buoyant matrix
#

I'm coming from a different language, where there is a difference between undefined and null, but var something; is null. Although, now that I think about it, I'm not 100% sure I'm correct.

feral ice
#

Player.transform.localRotation = Quaternion.Euler(0, turn.x, 0);
how can I make it so that it only rotates the x
(basically get rid of the 0s)

buoyant matrix
#

@brazen narwhal @polar acorn That is a very good explanation, and i really appreciate it.

polar acorn
brazen narwhal
#

yea it really depends on the language

buoyant matrix
#

Ahh. That makes a lot of sense, thank you.

#

I'm coming from node, where everything uses memory (not really, but it was funny in my head...)

brazen narwhal
#

some coding languages set variables to null when initialized

polar acorn
#

Ones more user friendly ones more memory friendly

brazen narwhal
#

yea

buoyant matrix
#

It makes sense. and If I wasn't writing code at 1am, I'd like to think that would have been obvious to me. πŸ˜„

brazen narwhal
#

usually higher level languages do that

buoyant matrix
#

I also didn't realize it's 1am. Thank you again, both of you. I'm off to bed.

brazen narwhal
#

gn

supple wasp
#

How can I make a button create multiple scenes as new projects?

swift stag
#

I'm having trouble loading back the HDRP pipeline

queen adder
#

Can I make an OnPointerEnter work in this tilemap(white thingies)?

#

omg silly forgot to send the screenshot,
PS. the error is irrelevant btw

static cedar
#

Considering nil is another term for null.

#

For Javascript, I think they use undefined by default.

static cedar
rancid pollen
#

how do i take a look at available overloads for any function/method on the user interface ?
i am using Visual Studio 2022, default keyboard shortcut settings.

static cedar
#

TBH, just type out the method, type a , inside the method parameters and u should see an arrow that you can scroll up and down to on the tool-tip.

#

That's how I've been doing it.

teal viper
reef patio
#

Hello, does anyone have a level changing script I could look at?

#

I tried a few and they all fail to work, but visually code goes through

rancid pollen
reef patio
#

i'll try it and ill brb

#

how would I replace it to those 2 levels from 1 to 2?

rancid pollen
reef patio
#

one moment ill update it

rancid pollen
#

since you created the strings, GAMEPLAY_SCENE and MAINMENU_SCENE, use those inside the SceneManager.LoadScene();

reef patio
#

is that okay?

rancid pollen
#

and after that you have to use "loadMainMenu()" or "restartGameplay()" on a button click or other trigger

reef patio
#

how do I manage to do that?

rancid pollen
#

how do you intend to change the levels in your game ?

reef patio
#

I have an object I can create

rancid pollen
#

is it by click of a button or character dying, etc ?

reef patio
#

walking on to a platform

rancid pollen
#

then you need to insert the loadMainMenu or the other function into the OnCollisionEnter2D or OnTriggerEnter2D depending your game

reef patio
#

its 3d

#

do I need 2 scripts?

rancid pollen
#

no, just insert the restartGameplay() into your Collision function

#

so that when collision takes place, the level 2 scene is loaded

reef patio
#

one moment

#

how do I insert that to a collision function 3d?

#

im lightly confused

rancid pollen
#

you usually have a OnCollisionEnter in your player script, or in the platform script on which the player will walk at some point

reef patio
#

i dont see it

rancid pollen
#

then you need to create it

reef patio
#

ok can you help me with creation?

rancid pollen
#

no, unfortunately. Don't have much time.

reef patio
#

oh

#

can i add you to friends and we can chat later about it?

rancid pollen
#

sure

reef patio
#

ok ttyl

#

thanks

languid spire
# reef patio ok ttyl

May I suggest that you follow some tutorials from !learn because you seem to be lacking a lot of very basic knowledge

eternal falconBOT
#

:teacher: Unity Learn β†—

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

dapper lava
#

how do i check for collision when the object isn't projectile for example i want to make laser but make it stop when it hits wall and dont come out from the other side

#

because it is not flying i cant check frame by frame for collision but i have to check have there been any object on the path of the laser and if there were few i need to find that was first and change position of laser end to this of an object

#

i could make small invisible object fly at very high speed and when it hits something it will ge me anwser i just thought of it but then there will be little ddelay

#

and if wall is thin is it possible the object will miss the wall between frames if it moves too fast?

fierce shuttle
# dapper lava how do i check for collision when the object isn't projectile for example i want...

Sounds like you may be looking for a Raycast: https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
Which will fire a invisible line in a direction and store everything that was hitt along the way into a RaycastHit array, theres also a "NonAlloc" version of most casts which let you control what gets returned, and all casts work best using layers to filter unwanted objects along the path - there is also a "LineCast" if you know the end point of your laser, which will stop at the first thing hit, however all of them rely on the thing your hitting to have a collider to be detected - there is also Physics2D that offer similar functionality if your game is not using 3D objects/collision

dapper lava
#

thanks

#

one mroe question

hazy folio
#

ive also got a question

#

how do i make a tight 2d player control with colliders because wall clipping is an issue and using tilemaps makes corner blocks hard to use

#

ive got a ground check hitbox below to check for ground but it clips into the wall and gives an unintentional wall jump

dapper lava
#

i am usint transform.psotion to move my character 2d. but i use rigidbody to detect collision so it pushes me back when i try to go thourgt wall. so i could use velocity to make dash for my character i could use velocity but because gravity is set to 0 the velocity never stops and i move in that direction all time is there a way to slowly negate all velocity like here

#

so when someone pushes me or i dash the velocity fade away for example in 1 second

solemn fractal
#

hey guys, does unity have a built-in method or feature to show in the screen a timer? Like appear in the screen a timer 10 minutes and it decreases every second until 0? or it needs to be done 100% via code?

cloud flume
#

hi everyone, trying to create a 3d movement system from scratch but im stuck, i got the player rotation with the camera but it still moves in the same direction, im trying to get the player to move in the direction of the camera, any help please?

modest dust
#

You could take a reference to the camera transform and use it's forward and right vector

cloud flume
modest dust
#

Multiply these by the input and add them together

#

Oh

cloud flume
modest dust
#

No idea, I rarely ever play around with physics

#

Play around with the mass and jump force

dapper lava
#

can i change the refresh rate of Update() function?

modest dust
#

Update is called every frame

languid spire
modest dust
#

You could play around with either Coroutine or InvokeRepeating

dapper lava
#

and can i ```cs
timer = 0;
in update->
timer + Time.deltaTime;
if(timer > 0.05){
timer = 0

// here you do what you want the function to do

}

will taht work?
modest dust
#

More or less, yeah

dapper lava
#

unless someone have 5fps

languid spire
heady nimbus
#

I feel like I'm having a really stupid brain fart right now...

I cannot get my floating head boss to register collisions with the walls.. boss has a poly2d trigger collider, floors and walls all have box colliders.

Neither ontrigger or oncollision will register vs the walls, but trigger will register vs the player. I didn't think trigger required a rigidbody to interact

languid spire
#

all collision/triggers require a Rigidbody

dapper lava
hallow badger
#

is there good course? where i can learn the basic of unity?

dapper lava
#

thanks

eternal falconBOT
#

:teacher: Unity Learn β†—

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

eternal falconBOT
#

:teacher: Unity Learn β†—

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

hallow badger
#

WoW that is a lot

quaint thicket
#

I have a bunch of GameObjects stores in a Dictionary variable. Instead of searching through the Dictionary, I was wondering if there is something I can add to the GameObjects, like a reference number, so I can match it to the correct dictionary entry?

gaunt ice
#

dictionary is unordered and you retrieve the gameobject by key

quaint thicket
#

I'm not sure if I understand but I have a idea for that.

languid spire
quaint thicket
#

I can use that also.

#

Thanks

tulip folio
#

I have an issue in my game when my score is 20, i need 120 points for 3 stars but its saying i have 3 stars πŸ”₯

short hazel
#

Show your code, perhaps your conditions are backwards

tulip folio
short hazel
#

Yeah they're backwards

#

The first one says "if 120 is greater or equals than your score"

#

It's most likely always the case

gaunt ice
#

you dont need to check the socre in update loop, you just need to check if when you updating the score btw

short hazel
#

Swap the two operands of >=

tulip folio
#

ohhhhh

gaunt ice
#

or turn >= to <=

#

oh wait

short hazel
#

I find it more legible for the thing that changes to be first in the condition. Like if (null == something) is really ugly to me

gaunt ice
#

the order is different...

neon fractal
tulip folio
#

I don't know what i'm doing ive just barely scraped this all together 🫑

short hazel
#

For such a "high-score system" you need to check the conditions in descending order, ie

  • If the score is greater than 120
  • Else, if the score is greater than 90
  • Else, if the score is greater than 60
  • etc.
tulip folio
#

should i do like if (ThreeStarScore <= ScoreCount && ScoreCount > TwoStarScore)

gaunt ice
#

no

short hazel
#

No, take advantage of how else if works

tulip folio
#

how would i write it then

tulip folio
#

gotchu

#

lemme give it a whirl

#

alright that all works now

#

idk how im so dumb for getting the symbols wrong + having different ones ordered oppositely 😭

ruby python
#

Af'noon all, I'm working on a circular gravity system and trying to add some 'falloff' but I'm struggling a bit with the Maths.

I have a gravity amount, a falloff inner radius and a falloff outer radius. (inner radius gravity should be at 100%, outer radius it should be 0%). My brain is completely failing me and can't seem to wrap my head around it. lol.

gaunt ice
#

gravity is proportional to M/R^2, not so understand

short hazel
#

Doable with a remap operation (InverseLerp + Lerp) probably. The InverseLerp operates on the physical distance you are between the two radii, and the Lerp takes that percentage to calculate the falloff

ruby python
#

It's not 'real' gravity, it's simulated/faked. It doesn't need to be physically accurate.,

#

I just need a %age multiplier between the two radii.

gaunt ice
#

do distance checking and apply your custom function(distance) returns force
(1-(distance-min)/(max-min))*force
force is vector btw

short hazel
#

Pretty much what a remap does internally yes

ruby python
#

Okay thanks fellas.

floral barn
#

does this mean that i cant use this for Unity?

static cedar
#

Yep.

#

Gotta make the

namespace Input
{
}

sad. UnityChanLOL

solemn fractal
#

Hey guys, I have a prob here. I have this OnTriggerEnter2D on my player script. And I am getting an error saying Object reference not set to an instance of an object. But I think I have it, tried with dif ways even tho nothing works.

#

Is that not referencing the enemy? or should I do other way? tried algo with findobject of type instead of assiging it on the inspector.. also didnt work

gaunt ice
#

you should use "other" in the parameter

solemn fractal
#

oh

gaunt ice
#

it is reference something in the file but not the scene

languid spire
#

iirc you are assigning the data variable once a prefab has been instantiated so refering to data on the prefab will, of course, return null

solemn fractal
short hazel
#

Collider does not have an _enemyPrefab member, so no

gaunt ice
#

other does not contain the definition of _enemyPrefab

#

you need getcomponent

languid spire
#

you have not even bothered to find out what is actually null, just made an assumption

wintry quarry
#

Also =- is not a thing

gaunt ice
#

technically valid

solemn fractal
#

hmm ok

short hazel
#

Doesn't really matter, since getting a value on a prefab instead of on what you hit, is invalid

solemn fractal
#

when I instantiate my enemy an Enemey ScriptableObject controls how much damage he deals

gaunt ice
#

just assign negative of attack to hp

#

but doesnt make sense

short hazel
brazen canyon
#

Excuse me guys.
I'm having problem with subscribing my Jump function with my Jump Action

#

I already created the Jumper Action but the code keeps telling me that I haven't created it

solemn fractal
short hazel
#

You can use GetComponent on any variable of type GameObject, or Component (which Collider2D inherits from), so you can use that on other to find a script on what you just hit

solemn fractal
solemn fractal
short hazel
#

Yep, though it's not a prefab you're getting, it's the script on the prefab instance (the copy of the prefab in the scene)

solemn fractal
#

So there is no =- ? so I should do what? like that? cs playerCurrentHeath = playerCurrentHeath - _enemyPrefab.data.attackDamage;

short hazel
#

-=, not =-

solemn fractal
#

if I use -= i get error

short hazel
#

a -= b is the shorthand for a = a - b

solemn fractal
#

Oh my mistake I am getting no error, thank you

gaunt ice
#

there is not =- operator but =- (or =+, =*) can be valid or exists in source code

#

eg int x=-1

floral barn
#
 private void FixedUpdate()
    {
        rigidBody2D.velocity = inputVector * speed;
    }
    private void GetInputVector(Vector2 inputVector)
    {
        this.inputVector = inputVector;
        this.inputVector.Normalize();
    }

Since i receive the movement input from an event how do i reset the input vector so it doesnt moves forever? should i make an event for when i stop pressing movement input?

grim stream
#

I copied my project onto an USB drive and moved to another pc. On th other pc the Console is floded with Errors like this:

#

Why or how?

languid spire
short hazel
#

Or to use source control like Git

grim stream
#

Manage to fix it

grim stream
dapper lava
#

is FixedUpdate usually direct update from Update

gaunt ice
#

i remember fixed update is called before update

wintry quarry
dapper lava
#

i mean that at least at my level using Update may change character speed or fire rate but changing it to FixedUpdate doesnt have any downsides

#

maybe it has downsides but not ones that may happen in my program

wintry quarry
#

Update doesn't "change character speed or fire rate". It's just a function that runs every frame. You might have written bad code inside it that does those things but that's not Update's fault.

ruby python
#

!code

eternal falconBOT
ruby python
#

Seriously don't know what's going on with my brain today, can't seem to think my way out of this.

float targetDistance = Vector3.Distance(body.position, transform.position);
targetDistance = targetDistance - innerGravityRadius;
Debug.Log(targetDistance);

//gravityMultiplier = .........

I need to get the 'gravityMultiplier' based on the targetDistance. With my current 'base' values, gravityInnerRadius is 0 and my gravityOuterRadius is at 450.

The multiplier at 0 should be 1, and 450 should be 0.

Seriously struggling to figure out the maths. 😦

wintry quarry
ruby python
short hazel
#

Distance between the outer radius and the player position

ruby python
#

Ah sorry, brain cabbaged. Thank you.

short hazel
#

It's because the "lower bound" of the Inverse Lerp here is the outer radius (so the outer radius gives out a percentage of 0)

surreal wagon
#

does anyone know how to create a new inctance of a prefab in unity

short hazel
#

An alternative would be to Inverse Lerp starting with the inner radius, and do one minus that to reverse the 0-1 multiplier

#

1 - InverseLerp(inner, outer, distanceFromInner)

surreal wagon
#

thanks

ruby python
acoustic arch
#

whenever your on a line just hover your mouse to the left of the lines number and that little popup will show itself

#

then you can click on it and itll have some suggestions like that show up

#

idk if thats exaclty what you were asking but

modest dust
#

Try Alt+Enter

#

weird

#

should work

heady nimbus
#

I want to create a couple lists of "waypoints" to define some movement patterns, but then I want to be able to select one of these "paths" at random.

My default thought was a List of Lists of gameobjects. Is there a "standard" way of handling something like this?

gaunt ice
#

an array of points first
then an array of the path, where the path contains the indices of point in the first array
it can reduce the memory usage

heady nimbus
#

So same concept, just with arrays then?

gaunt ice
#

list is nothing more than array, you can use list

#

or construct a graph

#

this should be much better since you can run graph algorithm on it

heady nimbus
#

I'm not familiar with graphs, I'll have to look that one up, but it sounds appropriate here

ruby python
modest dust
#

Had only the second option available before, didn't have my VS configured

#

Well then, you have your answer.

#

Also, he's probably using Resharper

gaunt ice
#
struct Vertex{
  public Vector3 worldPosition;
  public List<int> nextPositions;//contains the indices in graph
}
Vertex[] graph;
```here you have a graph
ruby python
short hazel
#

What kind of inverse lerp do you have here?

ruby python
#

!code

eternal falconBOT
ruby python
#

I may have broken it.....lol.

gravityMultiplier = Mathf.InverseLerp(outerGravityRadius, targetDistance, actualDistance);
short hazel
#

Yeah, it's InverseLerp(outer, inner, distanceFromOuter)

ruby python
#

okay, 1 sec

#

Player distance from outer yes?

short hazel
#

Correct

ruby python
#

hmm, okay, well my playerdistance from outer (actualDistance) is correct and reporting correctly, but the multiplier stays at 0

short hazel
#

Ah wait the radius distances are in world space right? In that case you should be able to just put the player position there

ruby python
#

okay, 1 sec will give it a go before I have a tantrum. lol.

#

ah no, can't put the player position cause vector3

wintry quarry
ruby python
#

Okay, I'm assuming the inner gravity radius (surface of the planet)

wintry quarry
#

i'm not 100% sure inverselerp actually works backwards like that so you might have to do

float gravityMultiplier = 1 - Mathf.InverseLerp(gravityInnerRadius, gravityOuterRadius, actualDistance);```
ruby python
#

Oh my god I am such a moron

#

I was setting my outergravitydistance variable to be how far above the innergravitydistance it was (ie 450), so the calculation didn't work because they needed the world distance.

#

Sorry guys, but seriously thanks for the help.

verbal dome
#

Far clip plane in the scene camera settings

#

You can select an object and hit F to focus on it in the scene view, this will auto adjust the clipΓ₯ing planes

solid verge
#

I am trying to make two buttons and if you hold the button on the right the play will move until you stop holding. I tried Input.GetMouseButtonDown(0) and it won't work.

#

i connected the void MoveToRight function to the button

verbal dome
#

Yeah that resets the clipping planes too.

rich adder
#

flip it

short hazel
#

Looks like the script that makes the stuff "look at" the player is backwards

#

You need to multiply a vector by -1 somewhere

ruby python
#

Last thing with this now I promise. lol.

But I'm struggling to apply the gravity multiplier to the gravity value. (max gravity = -10)

  gravityMultiplier = 1-Mathf.InverseLerp(innerGravityRadius, outerGravityRadius, targetDistance);
  Debug.Log("Gravity Multiplier" + gravityMultiplier);
  //gravity = ..........;

No matter what I try it either goes nuts, or returns a value 1/10th that of the multiplier πŸ˜•

short hazel
#

Value check: all 3 values you pass to InverseLerp are relative to the center of the body (planet)

ruby python
#

Yes they are.

#

That was the problem with the other thing. notlikethis

short hazel
#

Does the log show correct values?

solid verge
#

Yo how do i make so if you only click on the button a function works?

ruby python
#

Yes, it shows the correct multiplier based on the players distance to the surface of the planet.

rich adder
#

or use Ipointerclickhandler

solid verge
#

But i want to make it so if i hold the button the function works

ruby python
rich adder
#

use GetKey

short hazel
solid verge
#

No

solid verge
rich adder
ruby python
ruby python
#

At 1, the 'actual' gravity should be -10.

short hazel
#

So you can execute the second part of the remap, which is passing the ratio you get from InverseLerp to a Lerp with the min and max gravity

#

grav = Lerp(minGrav, maxGrav, multiplierFromInverseLerp)

solid verge
#

i want to react only when i hold it on the button

#

but when i assign a public void to on click

#

it doesn't work when i hold it

#

only when i click it

short hazel
rich adder
solid verge
#

how to use event trigers

ruby python
#

Okay progress, it works and matches the distance, but it's 'inverted'

short hazel
ruby python
#

OH! I just put the 1- back in and it works perfectly.

short hazel
#

Ah yeah I thought you were in the reversed configuration still, where the lerp was from the max radius to the min

ruby python
#

Aaah okay. Seriously though, both you and @wintry quarry thank you so much for the help.

bronze yacht
#

Hi Guys im doing a tutorial from YT and there was a point where i needed to programm Picking up items with raycast i did exactly the same thing but it doesnt work

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

public class SelectionManager : MonoBehaviour
{

    public static SelectionManager Instance {  get; set; }

    public bool onTarget;

    public GameObject Interaction_info_UI;
    Text interaction_text;

    private void Start()
    {
        interaction_text = Interaction_info_UI.GetComponent<Text>();

    }

    private void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }
        else
        {
            Instance = this;
        }
    }


    void Update()
    {
        Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit hit;
        if (Physics.Raycast(ray, out hit, 10))
        {
            var selectionTransform = hit.transform;

            if (selectionTransform.GetComponent<InteractableObject>() && selectionTransform.GetComponent<InteractableObject>().playerInRange)
            {
                onTarget = true;

                interaction_text.text = selectionTransform.GetComponent<InteractableObject>().GetItemName();
                Interaction_info_UI.SetActive(true);
            }
            else //if there is a hit, but without an Interacable Script
            {
                onTarget = false; 
                Interaction_info_UI.SetActive(false);
            }
            
        }
        else //if there is no hit at all
        {
            onTarget = false;
            Interaction_info_UI.SetActive(false);
        }
    }
}  ``` 

Could somebody help me? Im so desperate to fix this problem so if anyone could help me i would pay 10$ to fix it
short hazel
#

a.b will fail if a is null, for example

buoyant knot
#

Is there a clean way to "bake" a property?

short hazel
#

to what?

buoyant knot
#

I have something like this

#

but I have a class that holds a collider, and the type of that collider stays fixed.

#

oh wait, should I just use a virtual extension method, and add it to each instead of downcasting?

#

or is that a bad idea?

#

the main issue is PolygonCollider2D just can't do it

short hazel
#

Static stuff can't be virtual, but you can add overloads of that method

buoyant knot
#

wdym

#

I want to basically tie get/set to a generic "radius"

short hazel
#

Multiple GetColliderSkin methods, with different parameter types

eager elm
buoyant knot
#

but then how does Collider2D call it cleanly?

eager elm
buoyant knot
#

I feel like my Collider2D would be taking in an arg, and then using a switch case block to downcast... again

short hazel
#

Stick to the extension method with the switch

buoyant knot
#

I have a class which has a reference to Collider2D, which I believe is abstract

#

well, I am wondering if there is a clean way to just directly tie it, because the class that holds a collider2D is going to keep that type of collider

#

but it would also be better if I could just have a virtual extension method

short hazel
#

Is that class a MonoBehaviour? If not, you can make it generic with a type constraint

buoyant knot
#

I'm pretty sure Collider2D derrives from Monobehaviour

short hazel
#

From Component sure, but that's not the question

bronze yacht
# eager elm

Yes that was it but i still cant pick up items for some reason

buoyant knot
#

oh yes, the holding class derrives from MonoBehavuiour

short hazel
buoyant knot
#

this just sounds like a really simple challenge, but idk if I can avoid going through a switch-case every time I call

eager elm
summer stump
short hazel
#

I'd stick with the switch

buoyant knot
#

ugh, if only I could edit Unity classes -.-

#

ty

buoyant knot
#

another question: can I make an extension property?

short hazel
eager elm
short hazel
#

SelectionManager.cs

buoyant knot
eager elm
buoyant knot
#

mostly assign

summer stump
short hazel
summer stump
bronze yacht
#

and its still in that code

short hazel
#

Ah ok, they didn't explicitly say that was the issue lol

bronze yacht
#

picking up the items and the name getting displayed still doesnt work

eager elm
#

as the other comment said, use Debug.Log("some text"); to figure out what code isn't getting called

bronze yacht
#

yeah doing that rn

#

So i did debuging like this Here 3 and Here 4 where called but 1 and 2 wasn't

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

public class SelectionManager : MonoBehaviour
{

    public static SelectionManager Instance {  get; set; }

    public bool onTarget;

    public GameObject Interaction_info_UI;
    Text interaction_text;

    private void Start()
    {
        interaction_text = Interaction_info_UI.GetComponent<Text>();
        Debug.Log("Here 1");
    }

    private void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }
        else
        {
            Instance = this;
        }
    }


    void Update()
    {
        Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit hit;
        if (Physics.Raycast(ray, out hit, 10))
        {
            var selectionTransform = hit.transform;

            if (selectionTransform.GetComponent<InteractableObject>() && selectionTransform.GetComponent<InteractableObject>().playerInRange)
            {
                onTarget = true;

                interaction_text.text = selectionTransform.GetComponent<InteractableObject>().GetItemName();
                Interaction_info_UI.SetActive(true);
                Debug.Log("Here 2");
            }
            else //if there is a hit, but without an Interacable Script
            {
                onTarget = false; 
                Interaction_info_UI.SetActive(false);
                Debug.Log("Here 3");
            }
            
        }
        else //if there is no hit at all
        {
            onTarget = false;
            Interaction_info_UI.SetActive(false);
            Debug.Log("Here 4");
        }
    }
}```
buoyant knot
#

@short hazel In a similar vein, is there a smarter way than this:

summer stump
bronze yacht
#

what do i place

#

in the code

summer stump
bronze yacht
#

and there i place debug.log something

#

and check if it is called

short hazel
buoyant knot
#

if only the language had the tools to work around it

short hazel
#

Yep, inheritance! But it's not even used here lol

#

That's what you get for trying to support multiple languages at once, and not even modify the stuff when all the alternative languages are dropped

brazen canyon
#

Guys I need a little help
How to regenerate the json-like file for this Input system

short hazel
#

You have auto-save enabled, so modifications are applied instantly. What's the real question here?

brazen canyon
#

So when I subscribe a function to this action

#

This error shows up

short hazel
#

Are you looking at the right file? Its name does not match the Input Actions Asset

brazen canyon
summer stump
short hazel
#

You can't rename it yourself!

brazen canyon
short hazel
#

Well you can, but only in the "Generate C# class" options

brazen canyon
#

Then I changed to see if it works with different names

short hazel
#

It won't. It will generate a new one named PlayerMovement on each save of the Input Actions Asset

#

Unless you modify it directly from the generation settings

summer stump
brazen canyon
nimble sorrel
#

Sorry to interrupt, but I'm having a bit of trouble with hitbox colliders and onTriggerEnter. I've added a box collider to my player gameObject, checked the "isTrigger" box, and did the same for my enemy. theoretically, the OnTriggerEnter method on my playerController script should activate when the two box colliders overlap (right?). However, as far as I can tell, the method seems to be getting called when the enemy's hitbox overlaps at all with the player's gameObject, rather than the collider. Is there something I'm missing here?

#

oh I think I've found the issue - or started to at least

#

it seems rather than activating on the gameobject, it's activating on the second hitbox I added to a child of the player (I used a child object to handle interactions)

brazen canyon
short hazel
#

It already generated a new one. If you need to change its name, then do so from the Inspector

nimble sorrel
#

First solution that comes to mind is to reorganize my prefab hierarchy so that the two objects containing their colliders are even with each other? Since I believe Unity uses colliders from children objects as well. But rather than reorganizing my hierarchy is there not a way to just...consider the colliders separately?

short hazel
#

Select the asset => where you ticked "Generate C# class", you'll have a field where you can type a class name

knotty gust
eager elm
short hazel
knotty gust
#

i see

eager elm
#

and while you are at it, use XML or JSON to save files

knotty gust
#

using statement?

short hazel
#
using (FileStream fs = ...)
{
    // Use the stream as 'fs' variable
}
// stream automatically disposed, even if an exception occurs
knotty gust
#

okay okay

knotty gust
short hazel
#

Whatever type of stream you use really, as long as it implements IDisposable, it should be done in a using statement to avoid memory leaks or unclosed handles

bronze yacht
knotty gust
#

or is it something i would have to implement myself

short hazel
#

The class implements IDisposable yes

nimble sorrel
#

is there any way to tell a script to ignore the collider on a GameObjects that's a child to the GameObjects storing the script (and the collider that I do want to use)? or do I just have to restructure my hierarchy so that the two GameObjects are even

short hazel
#

You'll get a compiler error anyway if you try to put something that does not implement IDisposable into a using statement

real void
#

hey how could I make a list in C# like this im new to scripting and this would help a lot!

knotty gust
#

okay thank you

rich adder
rich adder
summer stump
# knotty gust how are they better?

More flexible. More control over where they go. You can have more than one file. Just as easy. Just better in every way

You can also use BinaryWriter. Any custom file will do ya

knotty gust
#

okay ill look into it, thanks

eager elm
knotty gust
#

so its better for writing to the file?

short hazel
#

I use zip files to store stuff. Especially useful if you have multiple payloads to save, System.IO.ZipArchive allows edit of a single entry without unpacking the archive and re-packing it again

#

Keeps everything tidy in a single file for the user, if they ever need to move it around

knotty gust
#

that would be useful later on

#

thank you

short hazel
#

Basically a small file system in a single file. Lots of programs do that, Office files are ZIP files containing some XML

#

You can change the extension of an xlsx file to zip, and explore how it's made inside

nimble sorrel
summer stump
nimble sorrel
#

physics messages - specifically onTriggerEnter

summer stump
#

If you want the other way. Then not really. A rigidbody will treat all child colliders as one compound collider

nimble sorrel
#

the issue I'm having is that I'm trying to have the player respond to the enemy when the enemy collides with a small hitbox on the player (functionality that I execute in OnTriggerEnter), but the functionality is getting activated on a larger trigger that I have as a component on a child to the player GameObject

nimble sorrel
#

will the child object (soon to be a sibling) need it's own rigidbody?

summer stump
nimble sorrel
#

it doesn't use any physics or anything - just checks whether the player is in range of interactable objects

summer stump
#

You can also check out spatial queries though. Like OverlapSphere or raycasts or CheckBox (there are a bunch)

nimble sorrel
#

unfortunately the enemies do not have a rigidbody (they're ghosts so I'm using that as an excuse to not have them manage physics or pathfinding), so I suppose that means I need to add a rigidbody

#

I may check out those other options, but I'd rather avoid reworking the whole system if I can avoid it

#

thank you

silver dock
#

Im trying to save character information to playerprefs (which it does according to Debug.Log), then load it (which it again does), and then update the ui with loaded data (which it does) but apparently every stat is just "0" instead of the value that was saved from the last session. anyone willing to look at my script and tell me where i went wrong?

jaunty wing
#
var NormalizedDirection = Direction.normalized;
        
// Set the velocity
playercharacter.velocity = NormalizedDirection * speed;

Am I able to multiply

var NormalizedDirection = Direction.normalized;

by something so that the velocity is realitive instead of being world space?

nimble sorrel
verbal dome
#

Thats one way

jaunty wing
#

Thanks

silver dock
summer stump
eternal falconBOT
nimble sorrel
#

omg I sure did respond to the wrong person mb

brazen canyon
#

Excuse me I need a little help
The Generate C# File button is gone.

eager elm
eager elm
# silver dock lol

It's hard to tell but maybe the problem is that you update the UI twice, once in the Load method and then in UpdateUI().

summer stump
short hazel
verbal dome
brazen canyon
gray flower
#

for some reason when i imported a unity project it didnt automatically generate a csproj for me. and so when i open a script it always leads to the start screen of vs studio. anyway to generate one? (im in version 2022.1.4f1 btw)

nimble sorrel
summer stump
nimble sorrel
#

huh ok nice, ty

#

wish me luck I've already spent a lot longer on this than I expected lol

#

"oh I just need to go in and adjust the size of the player's hitbox that'll be the easiest thing on this todo list" (<- naive and foolish)

silk night
#

and !ide

eternal falconBOT
silver dock
gray flower
#

already done that

silver dock
silk night
eager elm
gray flower
silver dock
summer stump
silk night
gray flower
#

i have visual studio?

silk night
#

nvm