#💻┃code-beginner

1 messages · Page 534 of 1

rocky canyon
#

just speculating... but Coroutines are called on their MonoBehaviour...
soo if private IEnumerator ReloadCoroutine() is on Gun.cs for example if u destroy the object w/ Gun.cs then the coroutine gets broken

sweet laurel
#

the coroutine is not active when the object is destroyed

rocky canyon
#

thats fine, but something is trying to reference Gun

#

when it no longer exists..

#

just gotta walk thru the code and figure out what

sweet laurel
low rover
#

whats the best way to make destructable/physics affected tiles

#

afaik regular TileMap wont help, since tiles are just purely for rendering purposes

#

unless im wrong

wintry quarry
#

You'd have to get into details about what kind of interactions you want.

low rover
#

my bad

#

let me elaborate

#

@wintry quarry have you played Space Station 13 by any chance?

wintry quarry
#

no

low rover
#

oh, its ok, they just have the mechanic im looking to replicate
Basically a 2D game, Players can interact with tiles and objects on them
Construct/Deconstruct (Changes tile/object texture)
UnWeld - Make tile draggable around the map
Weld - Set tile to the desired grid position

#

Other mechanics work around it, like explosions making tiles unweld and apply force and stuff

wintry quarry
low rover
wintry quarry
#

like explosions making tiles unweld and apply force and stuff
As for localized individually moving tiles, those you would replace with GameObjects at least temporarily.

low rover
#

sooo, remove the tile from grid and spawn the GameObject on that spot?

wintry quarry
#

yes

#

something like that

low rover
#

oh okay, what about tiles that deal damage

#

nvm

#

its google-able question

wintry quarry
# low rover oh okay, what about tiles that deal damage

Can be done several different ways:

  • Have a separate tilemap for that layer with a trigger collider
  • Just check which tile is at a particular place and if it's the damaging one you do damage
  • Use GameObjects for that particular interaction
low rover
wintry quarry
low rover
#

I can just store functions

#

alr, thanks!

upbeat steppe
#

can someone help get out off this and back to the original set up

rocky canyon
#

press Layout > Reset

#

it could be that Scene view is just maximized.. Double Click the tab where it says "Scene"

#

Shift + Space (while hovering a window toggles it from minimized to maximized btw)

upbeat steppe
#

@rocky canyon thanks

rocky canyon
#

ur also i ISO metric view..

#

click the little square (in the middle of the directional gizmo in the top right corner)

#

to toggle from Perspective to Isometric

stuck monolith
#

It keeps saying that the template checker is having an error and it doesn’t let me add items

rocky canyon
#

can you show a screenshot of this error?

mossy iris
#

heyo so ive been messing with the particle system for a bit, and it seems everything other than the actual color & shape of my particles seem to work just fine

#

it seems to just be stuck on this purple square texture

rocky canyon
#

have to pick a material that works w/ the particle system

rocky canyon
stuck monolith
# rocky canyon can you show a screenshot of this error?

if (!playFabSettingsValid)
{
if (EditorUtility.DisplayDialog(
"PlayFab Settings Warning",
"You are currently not logged into PlayFab.\n\n" +
"Please open the PlayFab EdEx window and log in to update your settings.",
"Open PlayFab EdEx",
"Cancel"))
{
OpenPlayFabEdExWindow();
}
}
}

private static void OpenPlayFabEdExWindow()
{
    EditorApplication.ExecuteMenuItem("Window/PlayFab/Editor Extensions");
}

private static void OnPlayModeStateChanged(PlayModeStateChange state)
{
    if (state == PlayModeStateChange.ExitingEditMode)
    {
        CheckSettings();
    }
}

private static void OnBuildPlayer(BuildPlayerOptions options)
{
    if (PlayerSettings.companyName == "Company Name" || PlayerSettings.productName == "Game Name")
    {
        EditorUtility.DisplayDialog(
            "Build Error",
            "Cannot build the project. Your player settings are still set to the default values.\n\n" +
            "Company Name: \"Company Name\"\n" +
            "Product Name: \"Game Name\"\n\n" +
            "Please update these values in the Player Settings.",
            "OK");
        throw new BuildPlayerWindow.BuildMethodException();
    }

    if (string.IsNullOrEmpty(PlayFabSettings.staticSettings.TitleId))
    {
        EditorUtility.DisplayDialog(
            "Build Error",
            "Cannot build the project. You are currently not logged into PlayFab.\n\n" +
            "Please open the PlayFab EdEx window and log in to update your settings.",
            "OK");
        throw new BuildPlayerWindow.BuildMethodException();
    }

    BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(options);
}

}
#endif

rocky canyon
#

!code

eternal falconBOT
stuck monolith
rocky canyon
#

use an appropriate method to share code ☝️
also, i was just referring to a screenshot of the actual error..
(like is it in the console?)
(was it a pop-up?)
etc

#

i've never heard of the error, is why i ask

stuck monolith
#

ok i can take a pic

#

one sec

rocky canyon
#

use Window key + Shift + S

stuck monolith
#

it a vr

rocky canyon
#

can take a smaller, little pic of it instead of a big screenshot

#

ya, but it still should appear in the console in the editor (in the pc)

#

or is the error happening only on the VR headset?

stuck monolith
#

Build completed with a result of 'Failed' in 97 seconds (96610 ms)
TaskCanceledException: A task was canceled.
UnityEditor.BuildPlayerWindow/DefaultBuildMethods:BuildPlayer (UnityEditor.BuildPlayerOptions)
TemplateDefaultChecker:OnBuildPlayer (UnityEditor.BuildPlayerOptions) (at Assets/Editor/TemplateDefaultChecker.cs:89)

#

no in utiyt

rocky canyon
#

oh okay.. so its a Build Error

stuck monolith
#

yes

rocky canyon
#

🫡 gotcha.. thats what i was confused about.. and the direct wording of it

rocky canyon
#

ya.. im just lookin into something.. (i thought files in /Editor/ didn't matter as they dont get built into the final build) but it appears that they can matter..

and secondly.. thats not a script You made im guessing...
looks like something Unity would include itself.. soo it makes me question why it isnt working..

im thinking something along the lines of corruption

#

are you signed into Unity Hub?

stuck monolith
#

@rocky canyon dms so i can give you tae link i use forme github

rocky canyon
#

also looks like something that could happen due to a network timeout..

stuck monolith
#

one sce it wrek

stuck monolith
#

@rocky canyon

rocky canyon
#

ahh, ya, third party asset then

stuck monolith
#

waht how do i fix

rocky canyon
#

did you ever change ur Company and Product name?

#
  • "You are currently not logged into PlayFab.\n\n" +
  • if (PlayerSettings.companyName == "Company Name" || PlayerSettings.productName == "Game Name")
#

these are the only two things i see in that code that would cause an error

#

the line number is this

#

so maybe check that function as well

#

all the code seems to imply that it would log errors if any of that fails but idk.. im not the asset's creator

stuck monolith
#

Ye I did

humble forum
#

what is this?

#

new to unity

stuck monolith
night mural
mortal spade
#

does oncollisionenter and ontriggerenter get called from children and parent object or just the parent

humble forum
languid spire
night mural
#

well there are situations where it matters a lot, but for the most part if you just use == you can probably not worry about it

humble forum
#

cuz like != looks cleaner to me and the first option you see nothing

mortal spade
humble forum
night mural
#

just do what makes sense to you

slender nymph
slender nymph
#

huh?

languid spire
humble forum
slender nymph
#

you shouldn't be using is not null with unityengine.objects

languid spire
#

like I give a shit, do what works not what looks nice

humble forum
languid spire
#

rubbish

slender nymph
#

"it works"
yet comparing with the is operator is bound to lead to exceptions being thrown

languid spire
#

and, no, it does not work with Unity objects

humble forum
#

my game works fine 🤷‍♂️

slender nymph
#

until it doesn't 😉

languid spire
#

you do you, just dont come back when it does not work

humble forum
slender nymph
#

holy shit, have you not bothered reading any of what was said?

humble forum
slender nymph
#

go read the information that was presented to you again.

humble forum
slender nymph
#

again, that is what you have to use with unityengine objects

latent glade
#

why am i getting this error

humble forum
#

i don t understand the difference used to using != in ue5

humble forum
languid spire
slender nymph
#

that page explains exactly why you need to use the == operator over the is operator and other null operators

humble forum
languid spire
humble forum
slender nymph
latent glade
humble forum
languid spire
latent glade
#

so what do I do to fix it?

languid spire
#

check what is null and why

slender nymph
#

read the information on that page that was linked to understand why

zenith cypress
# humble forum i don t understand the difference used to using != in ue5

For reference, is null/is not null/?./?? do raw null checks, which bypass overrides that are available for equality. Unity has an overload for equality of UnityEngine.Objects since they live in C++ land, but are exposed to C#. So the C# object can be perfectly fine and not null, while the internal one is invalid (hence the custom equality that checks lifetime), so using it in the api will throw exceptions.

You can easily see this in action with this example:

// assign in inspector
[SerializeField] private GameObject _obj;

private void Start() {
  Debug.Log(_obj); // _obj/true, C# not null
  Debug.Log(_obj != null); // true, C# not null
  Debug.Log(_obj is not null); // true, C# not null

  DestroyImmediate(_obj);

  Debug.Log(_obj); // internal null/false, C# not null
  Debug.Log(_obj != null); // false, C# not null
  Debug.Log(_obj is not null); // true, C# not null
}
languid spire
#

if you let air out of a baloon does it only go from one side?

latent glade
#

when I do Debug.Log(my_input);
or if (my_input is null)
still nothing debugs in the log

hybrid finch
#

Im trying to make it so that if this object is over 5 away from target it walks towards it, any ideas on why it doesnt stop?

slender nymph
eternal falconBOT
hybrid finch
slender nymph
#

have you looked at the documentation for the navmeshagent?

hybrid finch
#

ty

hybrid finch
steep rose
#
if(Targetfurtherawayfromplayer){
   //set destination and allow movement
}
else{
  //do not allow movement
}
latent glade
slender nymph
#

i meant where in the code

latent glade
#

(except it didn't)

#

in the update section

wintry quarry
#

show your code

#

"in the update section" isn't particularly helpful

slender nymph
#

if it is after the line that is throwing the exception, then it is no wonder it isn't logging since that line would not run

latent glade
#

ohhhh

#

ok my_input is the null object

slender nymph
#

yes, i already pointed that out. what is InputSystem.actions and are you sure it has an action map called Player

latent glade
#

they are both under the name Player, the one in the code and the actionmap itself is named Player

slender nymph
#

show it.

latent glade
#

k one sec

slender nymph
#

okay and is this the input action asset you've actually assigned in the input system settings?

latent glade
slender nymph
#

that is not the input system settings, that is the Player Input component

glad quiver
#

My player’s IsGrounded boxcast is ticking true at the apex of his mini jump which seems to be causing the state machine to switch from the jump state to the running state momentarily. I checked the boxcast size and location and distance and it all seems correct, is there anything else it might be that I’m not considering?

wintry quarry
# latent glade Yes

You shouldn't be using PlayerInput at all if you're using InputSystem.actions

wintry quarry
#

Just log the object it's hitting
or otherwise log why the bool is becoming true.

latent glade
wintry quarry
latent glade
#

ok

#

ok the error is gone
(PraetorBlue was right - it was linking only the main action maps and not the new one)

#

and ty BoxFriend for checking everything else

glad quiver
glad quiver
#

I’m definitely missing something obvious but I can’t tell what

wintry quarry
#

Share your code !code

eternal falconBOT
wintry quarry
glad quiver
#

@wintry quarry I have a few debug.logs that print whether the player is grounded and what the collision is and what state they are leaving and entering

#

The log says they are grounded, then running, then jump state, then colliding with the ground, then running again (in mid air), then not grounded, null collision, falling state (finally)

#

This doesn’t happen with stationary jumps it only happens when the jump has a running start.

glad quiver
#

@wintry quarry Holy crumbs, I googled my problem and clicked a link that looked related from a couple years ago and YOU were the person that replied to help them, what a coincidence! Are you a Unity employee or just a really helpful person?

ember tangle
#

I'm noticing that I can get a direction vector3 by subtracting the origin from the destination, but I have to multiple it by -1 in order for it to point in the right direction. Am I doing this right?

slender nymph
#

if you have to multiply it by -1 that means your direction is backwards. remember, direction is (endPosition - startPosition) in that order

ember tangle
#

ooh that makes sense

exotic turtle
#

How do I procedurally generate terrain? I have tried looking it up but all I got was links to github repos that I can't figure out how to use.

teal viper
exotic turtle
#

I figured that would be the case but I have no idea how to do anything in my project without terrain to do it on

timber tide
#

many youtube videos out there you can follow

teal viper
normal turret
#

Hey guys, what's up...? Just a quick question, for the "new" Unity Input System how can I use the equivalent of GetKeyDown if I use the Invoke Unity Events method...?

#

I have to jump but when I press and hold space my character jumps on the ground as long as I hold the jump button

#

Same thing with wall-jump, I just want it so that the player jumps only when you press the button and not hold it

exotic turtle
teal viper
steep rose
exotic turtle
#

where do I find the terrain system? should I just look it up

fierce badger
# exotic turtle Ok then can you explain how meshes work and how I can manipulate them so I can c...

Generate a landscape through code!

Check out Skillshare! http://skl.sh/brackeys11

This video is based on this greatwritten tutorial by Catlike Coding:
https://bit.ly/2Qd1o1d

● Perlin Noise: https://youtu.be/bG0uEXV6aHQ

● More on generating terrain: https://youtu.be/wbpMiKiSKm8

● Singleton: http://wiki.unity3d.com/index.php/Singleton

❤️...

▶ Play video
fierce badger
#

its math and code

steep rose
exotic turtle
#

it says

teal viper
fierce badger
exotic turtle
fierce badger
#

prob geo locked for u or something me no know

exotic turtle
#

Why is the terrain object immune to scaling

void notch
rocky canyon
# exotic turtle Why is the terrain object immune to scaling

b/c all its scaling and stuff is done thru the Terrain component and its settings..

similar to how u can't change the Field of View on a Camera when its being controlled w/ a Cinemachine brain. (it needs to be done thru the Cinemachine Camera's instead)

exotic turtle
#

what is cinemachine

steep rose
#

A camera movement platform

#

unlrelated to terrain

rocky canyon
#

its just a Camera supplement plug-in for unity..

#

was just an example.. not important to know really

formal escarp
rocky canyon
#

but the Terrains scaling, and positioning, and all that stuff is done thru its component

ember tangle
rocky canyon
#

^ yup, that proves my point.. ur actually modifying the Terrain Component

#

not the transform component

exotic turtle
#

there is no scaling option here

rocky canyon
#

its not really a scale.. its *terrain size, terrain height etc

steep rose
rocky canyon
#

and its in the last tab to the right..

#

settings

ember tangle
# ember tangle I have a bit of a janky way I made a terrain have hills using perlin noise. You ...

then I fed it a function like this: terrain.terrainData = MakeTerrain(terrain.terrainData); which looked like ```TerrainData MakeTerrain(TerrainData terrainData)
{
terrainData.heightmapResolution = width + 1;

terrainData.size = new Vector3 (width, depth, height); // set terrain size

terrainData.SetHeights(0, 0, GenerateMesh()); //starting x and y, and a grid of floats

return terrainData;

}```

formal escarp
#

I tried dragging and dropping

ember tangle
#

The generate mesh function adds noise: ```private float[,] GenerateMesh() // generates height based on
{
float[,] mesh = new float[width, height]; // create grid based on wanted size.

for(int x = 0; x < width;  x++)
{
    for (int y = 0; y < height; y++)
    {
        //create perlin noise based on the coordinates, offset randomly.
        mesh[x, y] = Mathf.PerlinNoise( (float)x / width * scale + PerlinOffsetX, (float)y / height * scale + +PerlinOffsetY);
    }
}
return mesh;

}```

rocky canyon
ember tangle
#

youll have to play with it a lot to make it work in your usecase

steep rose
formal escarp
steep rose
#

are you dragging a TMP text into it or just the default

rocky canyon
#

Text Component is different than TMPro..

#

Text is Legacy

formal escarp
#

oooohhh

steep rose
#

you would use TMPtext(I think it was) for your type

formal escarp
#

i thought they would be the same

rocky canyon
#

TMP_Text and you'll need the using TMPro; using statement

formal escarp
#

like, at the end of the day they are both text.

#

I do have "Using TMPro;"

steep rose
#

that does not mean they are the same, its like saying an apple and orange are the same because they are fruits

rocky canyon
#

but u must have the correct type to reference it

rocky canyon
#

c# is pretty serious bout that

#

even an Apple and an apple aren't the same 😄

timid quartz
#

I have a network transform with a network rigidbody for Mirror networking, but it doesn't appear to be affected by gravity. Am I missing something obvious? Gravity is checked in the rigidbody component.

rocky wyvern
#

all 'child' rigidbodies in the network I believe are made kinematic

#

and just move with the authorative rb

timid quartz
#

is there a way to make the authoritative RB have gravity?

#

I am using the authoritative RB from Mirror

timber tide
timid quartz
#

ok, ty!

hollow zenith
pure drift
#

!code

eternal falconBOT
timber tide
#

or grab a better GridLayout off the asset store ;p

hollow zenith
#

Tbh I need a vertical layout, the reason I picked grid layout was for an easy way to resize all objects

#

Except the one I want to override

#

I might do just that.
I had to redo it a bit to make it work with scrollview, which now forces me to do the above

#

Because I want a vertical list with header which is larger.

pure drift
hollow zenith
#

so it won't update UI

pure drift
#

even the debug.log is not updating gets stuck at 1

hollow zenith
#

that means you are not colliding

pure drift
#

it does debug when it hits the player but the actual variable doesnt go up in value

hollow zenith
#

you can manually place a bullet and drag it around in play mode to see if it works

#

oh

#

thats probably because you store a variable on a bullet script

#

but you destroy the bullet

#

so each bullet holds "playerScore"

#

you'd need to update your player object score or something, depends on how u want to handle that

pure drift
#

ohhh ok thank you

hollow zenith
#

You can look into Singleton pattern, its very simple and could work here(you'd create Score script and make it static so you can do Score.Add(1); etc)

pure drift
#

i have a question how does destroying a gameobject affect variables updating that makes no sense to me

slender nymph
#

you increment the variable on the object being destroyed. that variable is an instance variable so each Bulletscript object has its own playerScore with the values being entirely separate from each other. it's typical to store the score on a separate object that isn't being destroyed and just update that when necessary. you could even make it a public property that updates the displayed text when the score is assigned to as well

teal viper
slender nymph
#

i think their confusion stems from their misunderstanding of how instance variables work, as their previous issue was the common "update instance variable's value and immediately destroy object" issue where they expect them to act more like a static variable

teal viper
#

Ah, I see.

pure drift
#

oh ok thank you i see

cosmic dagger
#

25

pure drift
slender nymph
#

don't use string equality to check a tag, make sure to use the CompareTag method instead. it will actually throw relevant errors when a tag doesn't exist instead of failing silently

pure drift
#

thank you

sleek sparrow
#

Where can I ask for help

slender nymph
#

!ask

eternal falconBOT
naive pawn
#

oh that's just there now isn't it

sleek sparrow
#

I have an error with my engine

#

and I need help

naive pawn
#

we can't help when you don't tell us what you need help with...

slender nymph
sleek sparrow
slender nymph
#

not a code question. your camera is likely too close to the object to see it. make sure your camera is at or behind -10 on the Z axis, that is the convention for orthographic camera placement

sleek sparrow
#

It is at -10 and I can move the pipes onto the bird and they will still not render

slender nymph
#

check the Pipe object and make sure it isn't behind the camera

sleek sparrow
#

How to I do that

slender nymph
#

click it and look at its position

sleek sparrow
#

It worked

#

Thanks for the help man

pure drift
#

i used the other keyword but it still doesnt track if i hit the enemy properly could someone check if i messed up something with the tag please

slender nymph
#

what do you mean by "the other keyword"?

pure drift
#

one sec ill show you

slender nymph
#

what component is this code on?

steep rose
#

has VSC been buggy for anyone? I can't even declare a string 🤔

slender nymph
#

also just fyi, other is not a keyword, you've just changed the name of the parameter to other but it was perfectly fine as collision

naive pawn
naive pawn
#

what was it

steep rose
eternal falconBOT
naive pawn
#

oh i thought that was for a different snippet

pure drift
#

oh i should change it back one sec

steep rose
#

yes I know, I already have everything

#

I can triple check though

naive pawn
pure drift
slender nymph
#

so it was not attached to any collider or rigidbody involved in the trigger overlap/collision?

naive pawn
#

why would it collide with anything then

steep rose
#

sorry for the inconvenience

pure drift
slender nymph
#

OnTriggerEnter2D and OnCollisionEnter2D (and the other variants) are called on objects involved in the collision. unrelated objects will not receive those messages

glad quiver
#

Anyone know why this code correctly returns false for isGrounded during freefall but true for GroundCheck()? Debug.Log says GroundCheck returns true every frame no matter what, yet isGrounded returns correctly every frame. If I use "if(!GroundCheck())" elsewhere, nothing happens but "if(!isGrounded)" works fine. The boxcast and collisions are correct and nothing overwrites the values elsewhere. It's probably something obvious and fundamental -_-

cs
public bool GroundCheck()
{
RaycastHit2D hit = Physics2D.BoxCast(capsuleCollider2d.bounds.center, capsuleCollider2d.bounds.size, 0f, Vector2.down, 0.02f, groundLayer);
if(hit.collider !=null)
{isGrounded = true;}
else
{isGrounded = false;}
return hit != null;
slender nymph
#

hit cannot be null because it is a struct. but hit.collider can be, which is what you are checking in that if statement

#

also you can just return hit, it's got an implicit cast to bool that just checks if its collider property is null (which is also what you are doing in the if statement)

glad quiver
slender nymph
#

huh? i was referring to the last line of that method where you attempt to compare something that can never be null to null and how you are doing something entirely different in the if statement that is inside the method

glad quiver
#

Sorry for being confusing, I meant if I return hit in the last line instead of hit != null, can I use !GroundCheck() elsewhere in the code (my FallingState example was just an example)

split dragon
#

Hi. I have this question: I have 10 objects, and half of them are turned off. I want to turn off the disabled objects through the script, but I do not know which ones are on and off. Would it be better to check whether the object is turned off through the for loop and through if, or turn on all objects immediately through the for loop? For example:

slender nymph
#

what do you mean by "turned off"? because if you mean that they are disabled then that if statement will never be true because that is how you check if an object is destroyed or null, not if it is inactive.
but the second option would be just fine if you wanted to just make sure all of the objects in the list are enabled

split dragon
glad quiver
#

Sorry, to be clear I’m asking this stuff because it still doesn’t work, not because I am not trying. IsGrounded() just returns true always. I tried returning hit instead but I must be doing it wrong.

slender nymph
slender nymph
eternal falconBOT
split dragon
slender nymph
#

okay?

glad quiver
slender nymph
#

yes

glad quiver
#

Well then the new code is exactly what is above except with that one change lol

slender nymph
#

great! now show the full code

nimble apex
#

can u visualize enum property on UI button OnclickEvent?

slender nymph
#

no

nimble apex
#

then i guess i gonna do this instead

    public directionOffset direction;
    public void DirectionUp() => direction = directionOffset.Up;
    public void DirectionDown() => direction = directionOffset.Down;```
summer stump
upper prawn
#

Hi, I'm a C++ dev and new to Unity and C# for the most part. I am trying to find a GameObject in a list that is directly in front of my Player GameObject.
What I can't figure out is how to clone the Player's transform. What I'm doing is something like

var targetTile = player.transform;
targetTile.Translate(new Vector3(1.0F, 0.0F, 0.0F));

I know that C# uses reference based semantics so it makes sense that this mucks with my Player object, but I don't know how to make a copy of the transform. From some googling it looks like I should Instantiate another GameObject from it?

summer stump
#

Ah, the edit changes the question a bit

upper prawn
#

Yeah sorry, I hit enter too quickly

summer stump
#

Why are you needing to clone the transform?

upper prawn
#

I don't necessarily want to, I just want to use a transform that is 1.0 units in front of the player to lookup the tile in my list that is closest to that point

summer stump
#

So, a transform is a component, not a position in Unity

#

So targetTile IS player.transform (meaning the component attached to the player)

#

If you want a POSITION that is 1 unit in front, use a Vector3

#

player.transform.forward happens to be shorthand for 1 unit forward (on the Z axis)

upper prawn
#

Yep. And I found out when I tried using Instantiate that it clones the whole game object, e.g. the Player haha
Oooo ok, that makes sense. As someone who works in the robotics space it seems weird that the transform itself isn't a plain-old-data structure like Vector3, but yeah, this makes sense

summer stump
#

Yeah, I can totally understand that confusion.

upper prawn
#

Cool, thanks for the quick help!

wintry quarry
#

(I see you figured that out now)

gaunt sandal
#

anyone available to help me with using LeanTween with Unity 2022.3.47? I can't get it to compile to save my life

#

it's cursed or something

night mural
#

nobody can help you if the only information you provide is 'it's cursed or something'

gaunt sandal
#

I can jump into a call and stream my setup. I'm just not sure what information is needed to help me

#

Anytime I've attempted to use 'LeanTween', i get the 'type/namespace could not be found' error

so far, i've tried:

  • re-importing LeanTween
  • re-downloading LeanTween
  • adding any files related to 'DentedPixel' and 'LeanTween' to the Script Execution Order
  • added/removed 'using DentedPixel;'
teal viper
gaunt sandal
teal viper
#

The other way around might also be an issue. If you use assembly definitions and the asset doesn't, and it's code happens to be outside your assembly, that would make issues like you have now.

teal viper
gaunt sandal
#

those are the only errors

teal viper
#

Also, did you do this?

To use LeanTween move the included Plugins folder into the root of your project (or move LeanTween.cs directly into any pre-existing Assets/Plugins folder).
teal viper
gaunt sandal
teal viper
gaunt sandal
#

thank you dlich

#

let me try that and see if it fixes it

teal viper
#

Did that work? It might just be confusing wording tbh

gaunt sandal
#

I'll try creating a 'Plugins' folder and moving the 'LeanTween.cs' file there

gaunt sandal
teal viper
#

First of all, it's not just lean tween. All of these files are related to the plugin. Taking the script out of the files and moving around is not gonna help.

#

And 2: comment out the erroring code and let it compile once. Then try again.

gaunt sandal
#

so I need to stuff the whole 'LeanTween' folder into the folder?

#

I will try commenting out the code first

teal viper
gaunt sandal
#

I'll move it back then put the 'LeanTween' package into 'Plugins'

#

this is what I interpreted it as

gaunt sandal
teal viper
#

What is dented pixel?

#

A namespace? It doesn't seem like you need to use it. Looking at the code from GitHub, it's commented out.

gaunt sandal
#

I removed said using directive and still this:

#

i'm going to bed. I'll figure this out later

#

Feel free to keep suggesting stuff and I might pop back in if I think of an idea

teal viper
teal viper
gaunt sandal
#

ill link my github rq

teal viper
gaunt sandal
teal viper
#

Or you could just remove it if you don't specifically need it

gloomy cosmos
#

Hello, I get a bunch of warnings and even errors cause I have cyclical serialization. However in my case I pretty much need it. Is there a way to set a limit on how many times it can serialize itself within itself? Cause I doubt I'd ever need more than 3 self containments ever.

any tips are appreciated.

burnt vapor
teal viper
#

Basically flatten your serialized objects.

jovial granite
#

Where do I find input settings in? For exampe, there's Input.GetAxisRaw("Horizontal");, where do I add new axes and button bindings?

gloomy cosmos
willow scroll
#

This is for the old input system

jovial granite
#

I see. Yeah I guess I want to use the new system

#

I searched it on YT and there's a video from 5 years ago for the new system

#

And then the author has

#

But I don't have that in my interface

#

And it's completely different to what he has

clever idol
#

I just opened a new project and without doing anyting i got this error...

teal viper
keen dew
#

Collab hasn't existed for years, you can just uninstall the package. And if you're starting a new project you shouldn't be using such an old editor version anyway that includes Collab

rain ginkgo
#
private void OnTriggerEnter(Collider other)
 {
     if (other.transform == player)  // Ensure it's the player colliding
     {
         // Apply knockback force
         Vector3 knockbackDirection = (transform.position - player.position).normalized;  // Direction away from player
         m_Agent.isStopped = true;
         m_Rigidbody.isKinematic = false;
         m_Rigidbody.linearVelocity = knockbackDirection * knockbackForce;

         // Temporarily disable movement for the knockback duration
         StartCoroutine(ApplyKnockback());
     }
 }

 private IEnumerator ApplyKnockback()
 {
     isKnockedBack = true;
     
     while (m_Rigidbody.linearVelocity.magnitude > 3f) // Continue until velocity is less than 3
     {
         m_Rigidbody.linearVelocity *= 1-knockbackRes;
         m_Agent.velocity = Vector3.zero;
         m_Agent.destination = transform.position;

         yield return null; // Wait for the next frame
     }

     // Re-enable NavMeshAgent to continue movement towards the player
     m_Agent.isStopped = false;
     isKnockedBack = false;
     m_Rigidbody.isKinematic = true;
 }

this is for a navmesh agent, for some reason in the corutine, the y value keeps decreasing, cause the linear velocity to be (0,-3,0) and making its magnitude bigger then 3.
why is the y velocity decreasing while its on the ground?

teal viper
rain ginkgo
teal viper
#

Assuming the result is negative

rain ginkgo
#

I figured it out
thanku lots though

rough bough
#

how can i decrease the time my Capsule needs to reach the highest point of one Jump?

rough bough
#

ah ok thanks

naive pawn
#

(assuming you want to keep the highest point the same)

rough bough
#

yeah

naive pawn
#

from v'^2 = v^2 + 2as
v' = 0 (apex)
s is constant (height)
a=g is negative (gravity)
-1/2 • v^2/g = s
to maintain the same jump height you have to keep the ratio v^2/g constant
@rough bough

thorny basalt
#

To tweak my gravity I use Demos with the formula y = vt - gt^2 given v and g :)

#

It helps visualize the changes.

rough bough
#

but where do i need to add this ? 😅

naive pawn
thorny basalt
#

Yeah. It’s a useful tool for double checking math

naive pawn
#

try plugging these in and playing with s and v

s=1
v=1
g=\frac{v^{2}}{2s}
y=vx-gx^{2}\left\{y\ge0\right\}
```(you can copy these straight into desmos)
rough bough
#

alright thanks for your help 🙂

naive pawn
rough bough
#

ok

marble hemlock
#

Question about raycast. Lets say I was trying to do a system where you could pick up items. I still have an issue with occasional camera snapping but it got noticebly worse when I added more scripts, and one of them was a raycast script, and I'm wondering if (for any of you that may use raycasts) when you have an item you want the player to be able to interact with, do you think it would be better if I had it where the player raycast wouldn't be sent unless I clicked a specific key, and then tried to make the item have some sort of distinction (whether it be a glow or something) for the player, or do you just let it run in void update, and work around it?

wintry quarry
marble hemlock
#

Idk I just assumed it could be a performance thing, since it seemed to get worse when I enabled the rest of the scripts

wintry quarry
#

do you think it would be better if I had it where the player raycast wouldn't be sent unless I clicked a specific key, and then tried to make the item have some sort of distinction (whether it be a glow or something) for the player, or do you just let it run in void update, and work around it?
You would typically be doing it every frame because you want to be able to do things exacrtly like that selection glow

marble hemlock
#

Sometimes the camera would just sort of jump while turning

wintry quarry
wintry quarry
#

nothing to do with raycasts

marble hemlock
wintry quarry
#

The typical reason for something like that is improperly factoring Time.deltaTime into mouse input, which is not correct.

marble hemlock
#

ah

wintry quarry
#

That's what I'm talking about

marble hemlock
wintry quarry
#

If you're multiplying it into your already-framerate-independent mouse input, yes it's bad

#

Very common mistake.

marble hemlock
#

oh

#

which would i use then? time.time?

wintry quarry
#

Nothing

#

you don't need any time-based adjustment for mouse input

#

How would Time.time make sense>

#

Think about what the code is doing.

naive pawn
#

when you're trying to do something per unit time, you design it in per second, but you implement it per frame or per physics tick. deltaTime/fixedDeltaTime lets you do that conversion, from per second to per frame or per tick
when you aren't doing something per unit time, all of that goes out the window, because you don't have to factor time into anything

marble hemlock
#

I'm going to be entirely honest, I still don't properly understand all of the properties of the Time. I mean some of it I understand from the documentation but most of it kind of just goes over me.

wintry quarry
#

Mouse input is already "how much the mouse moved during the last frame

#

So it doesn't need to be adjusted

wintry quarry
marble hemlock
#

I will do my best

wintry quarry
#

Time.deltaTime is simply "the number of seconds that have passed since the previous frame"

marble hemlock
# wintry quarry Nothing

Thank you, it actually worked. Its been bugging me for weeks, so I was just ignoring it and trying to work around it on other things.

#

I gotta understand this time. class a bit better because I constantly see it in tutorials but i never really questioned why it was there.

naive pawn
#

Time is just a central spot for time-related stuff. you need to understand deltaTime specifically, and when to use or not use it

thorny basalt
#

It’s typically better just to update your game on a fixed frame rate

wintry quarry
#

Also reading input in FixedUpdate results in missed input

thorny basalt
languid spire
thorny basalt
thorny basalt
languid spire
#

oh, it will matter a great deal, many events only fire on one specific frame, miss that frame and you are fucked

naive pawn
wintry quarry
languid spire
languid spire
thorny basalt
thorny basalt
balmy jetty
naive pawn
# thorny basalt Wdym?

inputs are frame-bound. if you're checking for pressed/released events in fixedupdate, you might miss the frame where pressed/released was true.

wintry quarry
#

That won't survive someone else playing it on a different machine.

languid spire
naive pawn
wintry quarry
#

Likewise if you're handling mouse input in FixedUpdate you are missing frames which will result in stuttery/jagged motion.

thorny basalt
naive pawn
wintry quarry
balmy jetty
#

How are you doing there

#

For your information I have someone that can make an avatar from the scratch if you don't mind

thorny basalt
naive pawn
wintry quarry
#

so that's not true

naive pawn
thorny basalt
wintry quarry
#

"game logic" is really vague, but yes you need to process things in the correct places, that's the entire point.

naive pawn
#

it's a bit misleading to say "update your game on a fixed frame rate" then imo
since "update your game" is incredibly broad

thorny basalt
balmy jetty
naive pawn
#

but aight, makes a bit more sense now

thorny basalt
#

I just used the fixed time stamp for progressing game time, physics calculations, etc.

wintry quarry
#

Yes, physics calculations are explicitly what FixedUpdate is for.

balmy jetty
balmy jetty
#

Oh sorry

#

U just inform you

#

Oh sorry

keen cargo
#

Hey yall, I'd like some advice for a 2D shooter-

I'm recreating Gun Smoke for a class project. Gun Smoke's shooting system allows the player to shoot left, right or middle

So i've placed some empty gameobjects for where I want the bullets to instantiate from, but i'm stuck on how to approach accessing the "left", "middle" OR "right" gameobjects

lets say the player clicks both left and right mouse, this would have the player shoot from the "forward" points (refer to image)

The only idea that I've gotten is creating a for-loop within the shooting script, and then just accessing the specified indexes in an array of transforms, so for this example it'd be firepoint[2] and firepoint[3]

with some plans to bringing in powerups like a shotgun, which will shoot more bullets from the same points, is this a good idea or is there a way better way to deal with this?

wintry quarry
#

if you want to write a for loop and shoot all of them at once, for example, then put them in an array

#

and there's nothing that says you can't do both

#

e.g.

public Transform leftFirepoint;
public Transform rightFirepoint;

Transform[] allFirepoints;

void Awake {
  allFirepoints = {leftFirepoint, rightFirepoint};
}```
keen cargo
#

and for this purpose it'd be a lot better to have one PlayerShooting script instead of a GunShoot script for each firepoint object?

wintry quarry
#

It's not really a question that can be answered in general

keen cargo
#

ah you're right

wintry quarry
#

Your game may get to the point where such a thing makes sense

#

or it may not

slim lark
#

Hey guys, student currently extremely delirious and losing his mind due to lack of sleep.

I have a presentation in a couple hours and it seems I managed to break my buttons and reverting isn't fixing them. Zero clue how, even tried doing it from scratch in a new project.

It's in VR on an HTC vive. They were working PERFECTLY before I tried to add a new button. I reverted the change but they're STILL BROKEN.

Yes, I did reimport all, I deleted Library, and I started a fresh project and went piece by piece there but maybe the sleep deprivation is getting to me because nope still nothing.

languid spire
#

!code, please use a paste site

eternal falconBOT
slim lark
#

I can't use the basic "button" component, because I need it to be "do function while button held"

#

ah sorry

languid spire
#

Right now explain what is 'broken'

slim lark
# languid spire Right now explain what is 'broken'

So it's supposed to (while held) raise a table, and then at max table height it extends a tray until max tray extension.

There's also a button for the inverse.

And a button that makes it go to the "table all the way up, tray fully retracted" state

#

VRHoldButton.cs is for the first two
VRHomeButton.cs is for the bottom one

languid spire
#

So why is there absolutely no evidence of debugging in your code?

slim lark
#

because I send it directly to an htc focus 3 and don't get logs

languid spire
#

oh yes you do, add debugs and do a developemt build then look at the player log

slim lark
#

I'm also incredibly sleep deprived right now and this is my first project in Unity... or C#... let alone VR

hexed terrace
#

still haven't said what's broken

languid spire
#

then sleep/ Inexperience+Tierd == incompetent

hexed terrace
#

Steve, shut up.. you're not helping at all 😄

slim lark
# hexed terrace still haven't said _what's broken_

oh right, so uhh it used to work but now it doesn't at all. I didn't mess with the buttons I only tried to add a different new button.

The ray interactions still work properly from the controller, as there are other things that are still working in the scene. But even though I didn't change anything about the controllers or how they trigger on the buttons... they stopped working

hexed terrace
#

so, still not telling us what's not working

slim lark
#

I tried going from scratch just setting up the controllers (just the sample xr interaction setup) and then setting up the canvas with those scripts.

hexed terrace
#

"not working" and "its broken" are not discriptions of what is/ isn't happening

slim lark
#

NOTHING is happening. I click at the button and nothing happens. It used to complete the, as I explained earlier, "moving the table" task

hexed terrace
#

so.. you need to troubleshoot it

slim lark
#

it's literally just supposed to be translating a table along the y-axis, and if at max then it translates the tray that is a child of the table instead

hexed terrace
#

Look at the inspector, make sure everything that needs assigning is still assigned.
Add debug logs all over the place to make sure the various things are being called when you expect them to.

runic lance
#

are you able to move it in the editor? do you have GraphicRaycaster components in your canvas?

slim lark
#

yes and yes

#

these are the two children of the canvas, Button_Up and Button_Down

languid spire
#

Man, just debug your damn code

slim lark
#

as I said before I don't know how????????

#

This is literally my first time ever touching unity or vr

languid spire
#

And I told you how

slim lark
#

no you vaguely mentioned a path. Idk what you're talking about or where to see the logs

languid spire
#

you know how to write a Debug.Log statement, right?

hexed terrace
#

Debug.Log("enter some useful text so you know where it's coming from");

slim lark
#

yes but if I'm building directly to a VR headset idk how to check its logs

hexed terrace
#

so don't build directly to the headset, run it in editor..

languid spire
#

!logs, look at the Documentation link

eternal falconBOT
#
📝 Logs

Documentation

Editor logs

Windows: %LOCALAPPDATA%\Unity\Editor\Editor.log
MacOS: ~/Library/Logs/Unity/Editor.log
Linux: ~/.config/unity3d/Editor.log

Unity Hub

Windows: %UserProfile%\AppData\Roaming\UnityHub\logs
Mac: ~/Library/Application support/UnityHub/logs
Linux: ~/.config/UnityHub/logs

languid spire
#

you want player log

timber tide
#

dev build has a console btw so logging works

hexed terrace
#

why did you add box collider and rigidbody?

slim lark
steep rose
#

then sleep

#

why code when sleep deprived, it literally doesn't make sense

slim lark
#

I got it to work with arrow keys in editor and it moves

polar acorn
#

It ain't gonna run away from you overnight

hexed terrace
#

remove those, re-enable the image components - make sure 'raycast target' is enabled

slim lark
#

my presentation is in a few hours and this is important

keen cargo
# keen cargo Hey yall, I'd like some advice for a 2D shooter- I'm recreating Gun Smoke for a...

I got the directional shooting pinned down basically, though now there's the issue of the left + right click not registering consistently

so if i were to spam left + right, i'm expecting the player to shoot from the middle, but they're shooting from left & right simultaneously

now I understand that this is because of how Update is handled, it's checking every frame so the chances of mouse clicks lining up is very small, but even with some timing handlers I'm still getting inconsistent results, even tried adjusting the buffer to higher values

https://hastebin.com/share/bopiyekuvu.csharp

slim lark
hexed terrace
#

You couldn't have had this issue on Friday when the euro lotto was £170+ mil 😄

slim lark
#

I had accidentally disabled the image component while I was copying it around without remembering raycast target was in it

#

I had set the alpha values to 0 so it made no difference to the screen

hexed terrace
slim lark
#

sleep deprivation goes crazy, but thanks to you I might get to get a nap in ❤️ ❤️ ❤️

runic lance
#

it's also a good time for learning git and not waiting until the last minute possible to finish your tasks 🙃

slim lark
hexed terrace
#

never go to GPT

steep rose
slim lark
hexed terrace
#

anyway, stop chatting in here now.. and go finish what you need to / sleep

steep rose
#

it will give you the most common second idiots answer

slim lark
#

also for some reason our project hates git

#

every time we pull we need to fully rebuild library and often everything gets unlinked or loses textures

rich adder
#

are you commiting the .meta files?

hexed terrace
#

it's not your project that hates git.. sounds like you've got it setup incorrectly

echo crater
#

!code

eternal falconBOT
slim lark
#

Yes, but it's easier to say it's the project because there are 3 of us

slim lark
rich adder
#

look for something else

steep rose
#

look for your bed

keen cargo
#

hey yall, having issues with implementing simultaneous button presses

https://hastebin.com/share/yehidohoza.csharp

I want the player to be able to spam-click to shoot in any of the three directions (which is why i'm using getbuttondown instead of getbutton)

However i'm having great issue with triggering the forward shooting, even while raising the buffer timer, it's very inconsistent and activates about 10% of the time

stuck palm
#

if i want to get the children from OnlineButtonToggle, will it also get the children of its children?

#

I just want to get backToMenu and Rematch

keen cargo
#

so back to menu and rematch

#

but not the image from backtomenu

#

you'd need to use recursion to get children of children

long jacinth
#

i have different cities i want it so thats its buildable in each city and if u upgrade one city it doesnt upgrade in others i know what im doing is wrong but is there a way to do something like this

rich adder
stuck palm
long jacinth
#

do u mean like seperate scripts for each type of building

rich adder
#

so each one has their own copy of the values

long jacinth
#

but i want it so that its easy to add buildings and players can mod it

rich adder
#

so write the code clean

long jacinth
rich adder
devout flume
long jacinth
rich adder
devout flume
#

Design things in such a way that it allows extensibility, specifically since others may need to use the features you want to implement, so they need to understand what's going on, how it works, & why it works

rich adder
#

make prefab for each building type

#

spawn whicever you want, now its own object

long jacinth
#

so players will be able to make new prefabs if i make an api or something like varonex said

rich adder
#

yeah sure , you'd probably need to look into asset bundles or something like that to insert the asset. the data is easy cause it can just be Json ,CSV etc. ? whichever

long jacinth
rich adder
keen cargo
#

How do I improve consistency for the ShootForward function? https://hastebin.com/share/yehidohoza.csharp

I've been stuck on this for hours now, in the video you can see I'm trying to get it to trigger with very little success

cosmic quail
keen cargo
#

basically i'm trying to get the player to shoot forward (or from the middle), by clicking left & right mouse

#

but it's only doing the shooting left and right

#

maybe around 10% of the time I get what i need

cosmic quail
#

if they just go straight then they can just raycast for collisions, rigidbody is worse for performance and will not register collisions sometimes when its a fast moving bullet

languid spire
steep rose
keen cargo
#

no, i haven't had anyone respond, it was for the other person in chat at the same time

steep rose
languid spire
#

well your logic in update looks very suspect so I advise start adding debugs there

cosmic quail
keen cargo
#

i'll look into raycasting later, it's just this one issue that's been incredibly frustrating to figure out

steep rose
#

besides as I stated before it depends on what style of bullets you actually want, and moving objects via transforms is horrid so rigidbodies will work fine

cosmic quail
steep rose
#

no

#

unless you are working with a paper thin collider which most of the time you wouldn't be

cosmic quail
steep rose
#

They would most likely clip through walls

#

of which you would need to make your own collision detection, which rigidbodies do and are probably optimized for the physics engine

cosmic quail
steep rose
#

it depends on what type of bullet you want

#

if you want a hitscan bullet sure use raycasts, if you want a projectile use a rigidbody.

cosmic quail
steep rose
#

it probably depends on how fast you want this projectile to be, but this argument is arbitrary anyway as none are greater than the other

#

most of the time, rigidbodies would be fine but it depends on what you actually want as a bullet

keen cargo
#

tried some debugging and it's just made me even more confused

I'm using Mathf.Abs to get a comparable value to the buffer timer

the only time the shootforward goes through is if the mathf.abs results in a 0

rocky canyon
#

i tend to use a combo of both rigidbody and hitscans for my projectiles

#

rigidbody one is more as a graphical thing.. doesn't really hit exactly everytime..

#

with a raycast i can have better detections.. w/ the fancy projectile as fluff

hybrid finch
#

hii how do i make it so that 10 damage will be taken away every 2 seconds in this else statement

polar acorn
#

Unless this is a condition that runs every 2 seconds

hybrid finch
#

how do i make a condition? pls

polar acorn
#

...you already have one

#

that's what you've just shown

hybrid finch
#

ooh how do i run it every a seconds?

wintry quarry
sage mirage
#

Hello, guys! I have a question. How to play infinitely a sound effect or a music?

#

What I mean is that I don't want my sound effect to loop but instead to play this sound effect infinitely

polar acorn
#

So, what you're saying is you don't want it to loop, you want it to loop

sage mirage
#

I mean I want it to loop but infinitely bro

polar acorn
#

Check that

#

done

sage mirage
#

Yes I have it checked

polar acorn
#

So it'll loop.

sage mirage
#

Maybe the issue is with my clip?

polar acorn
#

When it reaches the end, it'll go back to the beginning

sage mirage
#

Because it is 1.20 in duration

#

when it arrives at 1.20 it stops

#

It loop sorry

#

So, I hear the reset sound

#

That's not cool

#

Do I really have to worry about it ?

polar acorn
#

I have no idea what you are even talking about

#

Worry about what?

sage mirage
#

Worry about the fact that it is resetting

#

I hear the sound effect to reset

polar acorn
#

That's what you want isn't it?

sage mirage
#

I don't want it to reset to tell you the truth

#

Just to go and got

#

go

polar acorn
#

Then what do you want

sage mirage
#

If I am disabling the loop checkbox it just stops when the time comes

nocturne kayak
keen cargo
#

Do you mean you want a seamless transition

polar acorn
keen cargo
#

Like that you don't want to notice the music or clip is resetting

nocturne kayak
sage mirage
keen cargo
#

Then the clip should be built in a way that it seamlessly loops

steep rose
viral vine
#

I have a project, based on a grid of cubes, that change state - whether you can walk through them or not, Occasionally I am able to walk through a cube that visually seems as though I should not be able to walk through.

sage mirage
#

I think I have to program it in order to make it work

#

Something with time

keen cargo
#

I assume you want the clip to be like this:

Blahlahlahlahlahlahlah

sage mirage
#

yes

nocturne kayak
#

Anyway- i have a problem of my own, and no, it's not my ammount of sleep per night:
Hopefully this should be quick.
I'm trying to make a raycast return true or false, and am debugging it per frame, but it only ever returns true
Debug.Log(Physics.Raycast(rayOrigin.position, rayOrigin.transform.TransformDirection(Vector3.forward), maxDistance));

keen cargo
#

But it's going blahblahblahblah (noticing the b's)

polar acorn
nocturne kayak
#

Not as in it returns true EVERY frame, it`s just that when i'm not hitting anything, it simply doesn't show anything in the log

polar acorn
eternal falconBOT
viral vine
# viral vine I have a project, based on a grid of cubes, that change state - whether you can ...
nocturne kayak
steep rose
#

literally just do TAF = Physics.Raycast(rayOrigin.position, rayOrigin.transform.TransformDirection(Vector3.forward), maxDistance) as a raycast returns boolean if all you want is a true or false

sage mirage
polar acorn
nocturne kayak
#

there's a warning that i'm not using a certain variable but i'll get to that bit of the code later on

#

Like i said, it never returns false

keen cargo
# sage mirage yes

A semi ghetto way you could do it is making 2 clips, one that starts with the correct Blah, and another that can continue with the rest lah's

So it goes like:

Clip 1 play normally, no loop
Clip 2 starts immediately after, which should loop
So it goes clip 1 > clip 2 > clip 2, etc

polar acorn
polar acorn
nocturne kayak
#

That makes no sense

#

when i point it up at the skybox, shouldn't it return false?

#

Like i said, it's not that it always returns true, it's that when it's supposed to return false, the log doesn't update

inland perch
#

So added lives to my game and every time u die u get 1 life off with a picture of a pingiun getting of the screen. I made a game data but the lives go down it but the pictures always go back to 3 even when i restart

nocturne kayak
#

so it's more like:
Frame 1: true
Frame 2: true
frame 3:
frame 4:
frame 5: true

that is assuming i point at the skybox during frames 3 and 4

polar acorn
polar acorn
nocturne kayak
#

Huh

#

i do

polar acorn
#

Try disabling it and see

nocturne kayak
#

same behavior

polar acorn
#

Can you send a screenshot of your Unity window with the console open after you've been pointing at the sky for a while?

nocturne kayak
#

this is the ray itself (red one)

viral vine
polar acorn
nocturne kayak
#

oh

#

oh shit.

#

yeah

polar acorn
#

Yeah that's what I was expecting

steep rose
#

what are the runtime errors

nocturne kayak
#

i didn't check if it was hiting something before checking if that something had a certain component

polar acorn
lapis veldt
#

Hello. I have a problem that I am confronting for a long time. I know how to make the character move, but I am not able to make a jump function to work properly. Any advice on how to do that?

nocturne kayak
polar acorn
lapis veldt
# rich adder what is "not working properly"

either it doesn't work unless I use a condition that checks the ground (in wich the case, it only does the jump animation) or it jumps to infinity by spamming the jump button

humble forum
#

is this func alr made it for dynamically loading different scnes for the levels

nocturne kayak
#

i just added an hit.collider != null to the if statement on the 55th line

#

and not everything works as intended

#

huh.

eternal falconBOT
rich adder
lapis veldt
#

one sec

short hazel
#
if (Physics.Raycast(...))
{
    // code
}
lapis veldt
#
CharacterController characterController;
Animator anim;
Rigidbody rb;
int isWalkingHash;
int isRunningHash;
int isJumpingHash;


[SerializeField] float speed = 5f;
[SerializeField] float jumpSpeed = 5f;
[SerializeField] float gravity = 10f;
[SerializeField] float speedH;
[SerializeField] float speedV;
string _currentDirection;

private float yaw = 0.0f;
private float pitch = 0.0f;

// Start is called before the first frame update
void Start()
{
    rb = GetComponent<Rigidbody>();
    anim = GetComponent<Animator>();
    characterController = GetComponent<CharacterController>();
    isWalkingHash = Animator.StringToHash("isWalking");
    isRunningHash = Animator.StringToHash("isRunning");
    isJumpingHash = Animator.StringToHash("isJumping");
}

// Update is called once per frame
void Update()
{
    //Vector3 forward = transform.TransformDirection(Vector3.forward);
    //float curSpeed = speed * Input.GetAxis("Vertical");
    //gameObject.GetComponent<CharacterController>().SimpleMove(forward * curSpeed);

    bool isRunning = anim.GetBool(isRunningHash);
    bool isWalking = anim.GetBool(isWalkingHash);
    bool isJumping = anim.GetBool(isJumpingHash);
    bool forwardPress = Input.GetKey("w");
    bool runningPress = Input.GetKey("left shift");
    bool jumpingPress = Input.GetKey("space");

    Vector3 moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
    moveDirection = transform.TransformDirection(moveDirection);
    moveDirection = moveDirection * speed;


    // Handle walking animation
    if (!isWalking && forwardPress)
    {
        anim.SetBool(isWalkingHash, true);
    }
    if (isWalking && !forwardPress)
    {
        anim.SetBool(isWalkingHash, false);
    }

    // Handle running animation
    if (!isRunning && (forwardPress && runningPress))
    {
        anim.SetBool(isRunningHash, true);
    }
    if (isRunning && (!forwardPress || !runningPress))
    {
        anim.SetBool(isRunningHash, false);
    }

    if (jumpingPress && characterController.isGrounded)
    {
        moveDirection.y = jumpSpeed;
        anim.SetBool(isJumpingHash, true);
    }

    // Check if jump animation has ended
    AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0); // Assuming layer 0
    if (stateInfo.IsName("Jump") && stateInfo.normalizedTime >= 1.0f) // Animation has completed
    {
        anim.SetBool(isJumpingHash, false);
    }



    // Apply gravity
    moveDirection.y = moveDirection.y - (gravity * Time.deltaTime);

    // Move the controller
    characterController.Move(moveDirection * Time.deltaTime);
#

it's a mess and I need to clear it a bit more

nocturne kayak
#

I recommend looking into state machines

#

That`s a lot of YanDev code right there

steep rose
#

what's the reason for the RB when you are using a CC 🤔

humble forum
lapis veldt
nocturne kayak
thorny basalt
steep rose
nocturne kayak
#

Supposedly you do want your character to collide with stuff

humble forum
polar acorn
steep rose
nocturne kayak
#

The CC handles that without he need for a RB?

#

i was just guessing

steep rose
#

you literally do not need a rb for animations

nocturne kayak
#

like i said, brain's smooth as a baby's bottom

polar acorn
#

You shouldn't have a Rigidbody and CharacterController on the same object

lapis veldt
#

oh, I see

lapis veldt
swift crag
#

these are unrelated concepts

steep rose
#

animation clips do not require RB or CC

#

I suggest you use the animator as the animation component is legacy

swift crag
#

perhaps you are thinking specifically of root motion?

#

(but I don't see any sign of that in your code)

lapis veldt
humble forum
#

fen can you rate my code? (it is for dynamically loading scenes

lapis veldt
nocturne kayak
#

Are you setting your button texts based on the names of the buton's GameObject name?

keen cargo
#

alright, so i've been doing some debugging for the past hour or so regarding my input detection

I still can't figure out why the ShootForward is being very inconsistent, only ShootLeft and ShootRight are being triggered most of the time

https://hastebin.com/share/obezosahov.csharp

steep rose
swift crag
#

That sounds challenging.

lapis veldt
#

so your suggestion is to change to either rb or cc

#

and not both?

swift crag
#

Perhaps you meant to use GetButton

keen cargo
#

that i understand yeah, though i've tried implementing a buffering system

steep rose
swift crag
#

GetButtonDown only returns true on the frame that you press the button

keen cargo
#

I'd like the player to be able to spam-click said button, which is why it's buttonDown and not just button

humble forum
swift crag
#
      if (fire1Pressed && fire2Pressed && (clickTime < fireBufferTime))
        {
            ShootForward();
            fire1Pressed = fire2Pressed = false;
        }
        else if (fire1Pressed && !fire2Pressed)
        {
            ShootLeft();
            fire1Pressed = false;
        }
        else if (fire2Pressed && !fire1Pressed)
        {
            ShootRight();
            fire2Pressed = false;
        }

This will not give you a "grace period" -- it will immediately fire the left side and reset fire1Pressed

#

So if you right click one frame later, fire1Pressed is already false again

#

Perhaps you meant to do this?

#
      bool bufferOver = (clickTime >= fireBufferTime);
      if (fire1Pressed && fire2Pressed)
        {
            ShootForward();
            fire1Pressed = fire2Pressed = false;
        }
        else if (fire1Pressed && !fire2Pressed && bufferOver)
        {
            ShootLeft();
            fire1Pressed = false;
        }
        else if (fire2Pressed && !fire1Pressed && bufferOver)
        {
            ShootRight();
            fire2Pressed = false;
        }

This would only fire the left or right sides after enough time has elapsed

#

I bet that wouldn't feel very good, though.

keen cargo
#

i'll try this real quick

humble forum
swift crag
#

But if the buffer period is very short (maybe 50ms or 100ms), it will feel..decent enough

keen cargo
#

that's actually exactly what i've been looking for i think

#

because it's working a lot better now

#

ahhh thank you so much

inland perch
#
 public void ResetPlayerState()
    {
        currentLives = maxLives;
        Color Color3 = Pinguin3.color;
        Color.a = 1f; // Set alpha to 1 (not transparent)
        Pinguin3.color = Color3;
        Color Color2 = Pinguin2.color;
        Color2.a = 1f; // Set alpha to 1 (not transparent)
        Pinguin2.color = Color2;

        Color Color1 = Pinguin1.color;
        Color1.a = 1f; // Set alpha to 1 (not transparent)
        Pinguin1.color = Color1;
    }

#

what's wrong with this?

rocky wyvern
#

you've accessed the non static property a of the static class color

swift crag
#

because you typo'd a variable name

rocky wyvern
#

because you put Color.a instead of Color3.a

inland perch
#

oooh

swift crag
#

you're doing the same operation many times

wintry quarry
humble forum
slender nymph
eternal falconBOT
nocturne kayak
keen cargo
inland perch
humble forum
inland perch
humble forum
keen cargo
#

and does it work?

humble forum
keen cargo
#

if it works then it's good

rich adder
#

getting the name from the button isn't very modular

#

you're doing the opposite, instead of buttons from list of levels/names available

#

then linking each created button to that name or index

humble forum
#

but is it bad then 🥲 ?

rich adder
#

yes its bad

keen cargo
#

basically if you want to make more levels then it's not good

rich adder
#

you should have the list of level names in an array of string, then you can loop each one to create button for it / linked to it

#

or use index/integer if just level1,level2,etc

humble forum
#

but why does it matter?

#

because it is scalable right?

keen cargo
#

so if you want to add more levels later then it's easier for you

rich adder
humble forum
rich adder
#

you're grabbing the level name to LoadScene from the button/ui text, that is silly

#

your code should as functional as possible even without a UI.

humble forum
swift crag
#

So here's how I do it in my game!

rich adder
swift crag
#

Each of my levels (I call them "scenes", how confusing!) is defined by a scriptable object

humble forum
swift crag
#

The object stores information like the name and description, plus the actual scene to load and a thumbnail

#

I have a Scene Button component that takes a single scene definition and sets itself up

#

well, actually, I used to -- now I have a more complex scene-selection menu

swift crag
rich adder
#

SOs are goat

swift crag
#

So now I'm not juggling four different things and making sure they're not getting out of sync

humble forum
#

🙆‍♂️

rich adder
swift crag
#

It's impossible for the "Level 3" button to accidentally take me to Level 4

#

I removed the possibility of that happening

#

I already make enough mistakes 😛

cosmic quail
swift crag
#

My game is almost exclusively only playable in English, but I use localized strings everywhere

#

so that once I do some translating, it'll be easy

#

I use almost no plain strings

cosmic quail
swift crag
#

Yeah

humble forum
swift crag
#

I use this everywhere, too

#

Each setting in my game is a scriptable object asset. Saved settings data is a bunch of key-value pairs where the keys are GUIDs

swift crag
cosmic quail
#

gonna be reading that, thank you! 👍

swift crag
#

so when I rename settings, nothing breaks

humble forum
swift crag
#

there is such a thing as too much foresight, haha

humble forum
rich adder
#

or sometimes you end up digging yourself deep then go, phew should've done it this other way.. lol and waste more time fixing mistake than redoing it properly

humble forum
humble forum
rich adder
#

it can be tiny you just have to understand your codebase so you can easily fix it / extend it

humble forum
#

but happy with all the help feels like im learning the engine quite quick 🙂

rich adder
#

you eventually come up with your own system that works for you, there usually never one sepcific way to do something (solve problem)

untold ether
#

A lot of it just goes for life and engineering in general

#

The best part is no part, and don't optimize something that shouldn't exist anyway

swift crag
#

simply do the right thing, and not the wrong thing 😉

#

you develop a sense for this over time

#

sort of

hybrid finch
#

i would like to reduce damage with a delay, does anyone know how to do this?

wintry quarry
eternal falconBOT
wintry quarry
#

Second,

i would like to reduce damage with a delay
What does that actually mean?

hybrid finch
wintry quarry
#

no it's not "instantly"

#

it happens when the code runs

#

which is every frame, since you're in Update

wintry quarry
hybrid finch
#

alr tyy

frosty field
#

does anybody know where i can learn just the basics? idk, i try using documentation, doing my own scripts and trying everything and i couldnt even get player movement to work. Finally i had to google the right script but there is no fun for me doing that, i would really like to get any help.

eternal falconBOT
#

:teacher: Unity Learn ↗

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

fading mountain
#

When I make an enum, should it be outside the monobehaviour class, above the variable declaration in the class, or under the variable declaration in the class? Assuming I only have one class in the script and the enum doesn't need to be accessed anywhere else. This is mostly a question on best practice and not necessarily function. I'm new and just learned about enums but I'm not sure about this

short hazel
#

If it's only accessed inside the class, then it can be declared inside that class

#

Otherwise enums are types like others, the best practices recommend to put them in their own file

fading mountain
#

okay. but the class will be able to access it if it is outside of it in the same file, or in a different file and made public, right?

wintry quarry
wintry quarry
#

as long as the two files are in the same assembly

fading mountain
#

Okay so it needs to be made public in both situations

wintry quarry
#

All the usual rules about access modifiers apply

short hazel
#

Not ncessarily public

wintry quarry
#

if it's public it can be accessed from anywhere
If it's internal it can be accessed from the same assembly

short hazel
#

Inside classes they can be made private

fading mountain
#

got it, thanks guys

swift crag
#

(basically only relevant for code-generation)

queen adder
#

if working on a game like hearthstone, where there are thousands of cards each with a special characteristics and effects. How do you like design the card's code?
I've seen approaches where each card have their own c# class (inheriting from scriptable object BaseCard class), but is that approach good?

latent glade
#

Is there a way to have a key only register once every time you hold it down or tap
for context I'm making the pause menu, and every time you press esc, it registers like 10-20 times and if you hold it for a second like 500 times

slender nymph
#

how are you detecting these key presses

latent glade
#

the new input system, in an action map

slender nymph
#

okay but how

latent glade
#

what do you want me to show you? my code? my action map?

slender nymph
#

mate, this is a code channel. i am asking about your code and how you are detecting the key presses in your code

latent glade
#

didn't see the input channel sorry

slender nymph
#

okay but it's clearly something you are doing wrong in the code. so share the code if you want help

swift crag
#

It will still be useful to see what you're actually doing, yes

slender nymph
#

there are like half a dozen ways to use the input system, you've shared almost no information about how you are using it

swift crag
#

we need to know how you are actually receiving this input

foggy crypt
#

Is it better do everything in 1 singular script, or make multiple and connect them together?

swift crag
#

I've been on a long journey to move from the former to the latter

#

😛