#💻┃code-beginner

1 messages · Page 175 of 1

queen adder
#

lemme look at layoutgroups messages

amber spruce
#

yeah its because of the gif

#

it skips every like couple frames

queen adder
#

but it's actually blurry?

amber spruce
#

huh even just recording my screen doesnt show it

queen adder
#

try removing the setfloat ing the fixed update

amber spruce
queen adder
#

i dont even know why you need that there

#

oh the sandivistan effect ig

amber spruce
#

no clue what that is but i guess

queen adder
amber spruce
#

yeah that

queen adder
#

yea, try removing one of the set floats

#

that may be messing up the animation timing

#

remove the one in the input catcher

#

not sure about new input system, but can you try placing that in Update instead?

#

then the velocity will become a class field that is updated by the input system

amber spruce
#

still is a little glitchy but its better

queen adder
#

controlling animation in fixed is glitchy yea

slender nymph
cosmic dagger
queen adder
#

so painful navigating github, cant ctrl+click thingies

slender nymph
#

so download the repo

#

this code is also already on your computer as vertx has pointed out to you multiple times

queen adder
#

ig this what i need, hopefully

scarlet skiff
#

what am i doing wrong here, its always fully filled, as if it ignores fill amount

swift crag
#

is the image actually set to the "Filled" mode?

#

the default mode is Simple

slender nymph
#

and is this code actually running?

wintry quarry
#

Note also that in order to change the image mode to Filled you have to assign a sprite to the Image. It can be a 1x1 white pixel image, but it must have a sprite assigned regardless.

scarlet skiff
#

wait what why does my image component not even have that option

swift crag
#

i was looking into creating a filled, sliced image once

#

the code is scary

#

a mask is a decent approximation, but those edges are hard ):

rocky lava
#

does anybody know how to get rid of this box and get the little line back? it overrides the text instead of adding to it

slender nymph
#

press the insert key

rocky lava
#

oh

#

thank you! ❤️

queen adder
#

works now ig, had to use a coroutine though

scarlet skiff
#

wait so in the tutorial the guy gets the fill to be in the x axis, mine fill in a wierd pattern, bottom left, top left, top right, bottom right

#

how do i make it X fill only

#

nvm found it

cosmic dagger
vast vessel
#

how do i get a scene, from a loadSceneOperation, or its name, so i can use it in setActiveScene?

polar acorn
vast vessel
rare basin
#

try it and see

polar acorn
vast vessel
#

AI_Test is the scene loaded through the coroutine

#

oh wait i think i now what i messed up...

#

gimme a sec

#

i was setting isLoadingLevel to false, my bad. sorry for the ping

spark ravine
#

Is there a way I can create functions, that I can call from every project?(like Vector3) or something?

polar acorn
cosmic dagger
#

It's just like importing Unity packages. When you update your package, you hit the update button in the package manager to grab all the changes . . .

#

It's great for core functionality that you use as a base on any project and extension/utility methods . . .

spark ravine
#

How do I acess them then without having to create a refrence to them everytime?

slender nymph
#

wdym by "create a reference to them everytime"

spark ravine
#

Having to do private Script scriptname and in the code scriptName.Function

cosmic dagger
#

You want to create a static method that can be accessed from the class itself . . .

languid spire
verbal dome
#

If you want helper functions you can make a static class. Then add using static ClassName; and you can call its methods without specifying ClassName each time

cosmic quail
cosmic dagger
#

Either that or extension methods . . .

spark ravine
languid spire
spark ravine
#

so only one static method or one per name? lol

cosmic quail
cosmic dagger
spark ravine
#

ok thanks I will look up extesion metohds, instance methods and structs

cosmic dagger
#

I would read about static methods and extension methods . . .

languid spire
cosmic dagger
#

Smith family reunion, nice!

languid spire
#

hmm, with a name like Josh I doubt we're related, there are lots of different Smiths

cosmic dagger
#

There is an infinite amount. I just like the fact that John, Josh, and Steve were all united, speaking at the same time . . .

unkempt maple
#

this is my script for dashing but when i dash i won't move forward, any ideas?

keen dew
#

Best guess is that movement code overrides the velocity

static cedar
#

I was thinking of friction and drag coming to play.

languid spire
#

AI generated code?

unkempt maple
static cedar
#

I guess, too many comments.

rich adder
#

not only two many but completely obvious and stupid

languid spire
rich adder
#

dashDistance - Distance To Dash

#

no shit

static cedar
cosmic dagger
#

Getting the direction by focusing the distance and time doesn't make sense . . .

west sonnet
#

In 2D, how can I gradually move an object using script? I don't want to use Vector3 because that'll just snap the object to it's new position, I want the object to 'slide' to it's determined position

#

Do I use Lerp?

rich adder
languid spire
#

we are not here to fix crap generated by AI because OP is too lazy to write their own

rich adder
#

its already smoothed

west sonnet
#

Well, I want to make a fist for an enemy that will move back a little, then spring forward. Like a punch

#

So I would use Lerp for that, right?

timber tide
#

maybe a curve

static cedar
#

I thought it was for UI.

rich adder
west sonnet
#

Hmmm I've never used curves before

rich adder
#

otherwise use rigidbody + forces

west sonnet
#

Hmmm okay. I'll see what I can do

#

Thanks

timber tide
#

animator good for like very specific movements like abilities

languid spire
#

@unkempt maple NEVER DM someone without their permission

west sonnet
#

Using a Rigidbody isn't working because when I attach one to the Enemy's fist, it either makes the collision between the first and the player's body act weird, or the fist starts flying off the body towards the player

#

My enemy will have 'Rayman' style hands. No arms, just floating hands that will punch

rich adder
unkempt maple
summer stump
wintry quarry
#

make a thread if you want your own conversation room

cosmic dagger
summer stump
low path
#

why not is because you don't command somebody to talk to you

polar acorn
unkempt maple
summer stump
#

Plus you JUST called them a nerd, why would they even help you anymore?

unkempt maple
polar acorn
rich adder
#

"Im using AI because I just ran out of gas and need to get to my house this one time , if you can just help me out this time"

cosmic dagger
low path
#

or at least just ask nicely

unkempt maple
languid spire
#

Ain't gonna happen, too late, move on

unkempt maple
#

yeah big daddy said move on

west sonnet
#

I want to make the enemies fist move back and forth, to simulate a punch, when the player enters the trigger which is infront of the enemy. Would doing this by code or animation be better?

low path
#

either approach is valid and it depends on how you set up the enemy. is it gonna be just one sprite?

west sonnet
#

Yeah

polar acorn
#

Using code gives you the option to very easily parameterize it to do things like adjusting the wiggle direction and amount.
Using animation gives you the option to actually animate it later with an actual animation.

I'd say go with whichever one you're more likely to want to expand to later.

west sonnet
#

Hmmm, probably code. I'm just struggling to figure out how to do it

low path
polar acorn
#

The easiest way would be to use a Tweening library like DOTween. It's not terribly hard to code simple movement like this but a tween library is really nifty to have and if you got it you might as well use it for the simple stuff too

west sonnet
#

It makes moving objects easier, right?

#

As in animating, but using code?

polar acorn
#

Yeah, it creates "in betweens", so you give it a start thing, and end thing, and a time to do it in, and it changes that value between those two endpoints over the given time. You can use it for basically any continuous value, not just position.

west sonnet
#

Oookay

#

So I could use it to create smooth movement?

ivory bobcat
#

It would manage the interpolation for you.

polar acorn
west sonnet
#

hmmm ooooookay

#

Since importing DoTween, I have an error message saying 'Failed to find entry-points:'. What does this mean?

ivory bobcat
timid hinge
#

hi, i cant drop a sprite on the animation anyone knows why?

rich adder
timid hinge
#

what is it then?

west sonnet
#

Trying to use DoTween. This is my code at the moment, I want the object to move and then move back to it's starting position but it's just moving, then not returning. Anyone know why?

polar acorn
timid hinge
#

thanks

polar acorn
west sonnet
#

ooh, I thought the SetLoop would bring it back? I'm following a tutorial and it did for that guy

west sonnet
rich adder
#

loop itself doesnt mean it will go to first frame again backwards

#

if there is loopmode to reverse then sure

#

lookup the LoopType

quiet merlin
#

Hi y'all, i got an issue, I need a variable to be from 0 - 1, but it's currently between 0.21 - 0.72, because the object i'm clicking on doesn't take up the whole width of the screen
how do i convert variable to 0 - 1 rather than doing this?

the variable is basically input.mousePosition but converted using ScreenToViewportPoint() so clicks are resolution independant

I can show you my code for more context but I would like to know if it's possible to get an idea of how to fix this issue?

polar acorn
stiff stump
#

how can i find gameobject by name and the gameobject is disabled in hierarchy

dark laurel
#

FindObjectOfType(includeInactive: true)

brave vapor
#

Can someone help me with my code. I tried to run it already a buch of times. I am trying to make a zombie's health go down when it hits an object tagged as "Bullet" but it just doesn't work and I don't really know why

#

Here's the code:

#

using UnityEngine;

public class ZombieController : MonoBehaviour
{
public Transform player;
public float speed = 2f;
public int maxHealth = 20;
public int bulletDamage = 10;

private int currentHealth;

private void Start()
{
    currentHealth = maxHealth;
}

private void Update()
{
    if (player != null)
    {
        Vector3 direction = player.position - transform.position;
        direction.Normalize();

        Quaternion toRotation = Quaternion.LookRotation(direction, Vector3.up);

        transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, Time.deltaTime * speed);

        transform.position += transform.forward * speed * Time.deltaTime;
    }
}

void OnCollisionEnter(Collision collision)
{
    if (collision.gameObject.CompareTag("Bullet"))
    {
        currentHealth -= bulletDamage;
        if (currentHealth <= 0)
        {
            Destroy(gameObject);
        }
    }
}

}

eternal falconBOT
earnest atlas
#

-_-
Sometimes I hate it so bad.

polar acorn
#

It doesn't know anything about code, it just puts words together in ways people do

#

stop asking ChatGPT things

earnest atlas
#

I had issues with thing not working

polar acorn
#

It's not an oracle it's a very complicated markov chain

edgy fox
#

is it possible to set an object as invisble without disabling its meshrenderer or giving it an invisibility mask? I have an object that needs to cast shadows and thus have its renderer on but also has a mask used for LayerMasking, is there another possible solution?

timber tide
#

you can hide a renderer and cast shadows

#

shadows-only option on the renderer itself

edgy fox
#

oh yeah that exists

swift crag
earnest atlas
#

It fails even at that 🙂

swift crag
#

no, it's GREAT at creating spam

earnest atlas
#

I tried to make it create dummy data for me. It takes forever for it. its faster to write it with code

opal ridge
#

Does someone maybe have an article abour Camera.main.screen... I'm wanting to make it so the player looks to the cursor in 2d top-down, but im not sure which to choose

#

Camera.main.ScreenToWorldPoint This for example

rocky canyon
#

heck ya, looks good

earnest atlas
#

I've made small collider on player but its not detecting collisions?

    void OnTriggerStay(Collider other)
    {
        if(!other.CompareTag("Ground")) return;
        GameController.Instance.IsOnGround = true;
    }

    void OnTriggerExit(Collider other)
    {
        if (!other.CompareTag("Ground")) return;
        GameController.Instance.IsOnGround = false;
    }

Solution found on stackoverflow.

#

Ground is tilemap with tag

prisma hound
#
private void OnTriggerEnter2D(Collider2D other)
    {
       if(other.gameObject.tag == "Powerup")
       {
        powerUpEnabled = true;
        PowerUpStart();
        other.gameObject.SetActive(false);
        Invoke(nameof(PowerUpEnd),timeLeft);
       }  
       if(other.gameObject.CompareTag("Portal"))
       {
        isTeleport = true;
        initialPosition = transform.position;
        originalVelocity = rb.velocity;
        rb.velocity = Vector2.zero;
        rb.gravityScale  = 0;
        objMesh.enabled = false;
        Invoke("TeleportFinal",FindObjectOfType<CamFollow>().teleportTime);
        
       }    
    }
   
   void PowerUpStart()
   {
    rb.mass*=3;
    physics2D.bounciness = 0.5f;
    coll.sharedMaterial.bounciness = 0.5f;
    Debug.Log("Power up started");
    
   }

    void PowerUpEnd()
    {
        Debug.Log("Power Up ended");
        rb.mass/=3;
        coll.enabled = true;
        coll.sharedMaterial.bounciness = 0.97f;
        powerUpEnabled = false;
        timeLeft = 3f;
        
    
    }
#

So what this code basically does is that it reduces my ball's bounciness. This worked perfectly fine in 3d(with all the necessary code changes like changing from Collider2D to Collider) but in 2D it doesnt seem to change my ball's bounciness

#

also i tried using both physics2d.bounciness and coll.sharedMaterial.bounciness but both are not working

#

in my 3d version i used coll.Material.bounciness

gleaming wagon
#

any problem with my calculating logic? whenever a non planet collides the score just becomes negative...

earnest atlas
#

Is a planet is always false

gleaming wagon
#

i set it to true

#

in the inspector

#

and the score becomes positive

#

but as soon as a non planet collides it just becomes negative

earnest atlas
#

Make score static I had similar issue

gleaming wagon
#

Example: a planet collides 5 times making the score 5, a non planet collides, suddenly the score is -6

earnest atlas
#

Of score just being forgotten

#

Oh?

gleaming wagon
earnest atlas
#

Maybe make score++ and score--

#

It shouldnt multiply

gleaming wagon
#

weird tho

gleaming wagon
#

I thought private is shared

vapid mesa
#

hi, when i start my project my camera rotation is good but when i start it the rotation change

earnest atlas
#

Private is private

vapid mesa
#

pls

opal ridge
#

I'm trying to get the plane to look at the mouse cursor, in 2D top-down. It looks like it's moving, but just on the Y axis it seems like?


Vector2 mouseWorld = Camera.main.WorldToScreenPoint(mousePos);
transform.forward = mouseWorld - mousePos;``` 

After some digging I found that WorldToScreenPoint can only be used in Vector3, is that correct? If so, what do I use to get the Camera.main. to what ?
prisma hound
#

You can ignore physics2d

ivory bobcat
prisma hound
#

Yes i did

ivory bobcat
#

Not knowing what physics2d.bounciness is, I'm simply going to assume that it's something incorrect.

prisma hound
#

Bro ignore that

#

If i delete that statement nothings gonna change

#

Im talking about coll.sharedmaterial one

#

In my 3d version of this game the code works

#

But in 2d it doesnt

#

When i look at the physics material attached to my ball in the 2d version the bounciness gets changed to 0.5 but it doesnt bounce less

#

It bounces to the same height

ivory bobcat
#

I've got no clue if you know what you're actually doing but 2d uses the 2d physics material and 3d uses the 3d physics material.
Using a single type for both is likely your issue.

prisma hound
#

I told you

#

That i use 3d in 3d

#

And 2d in 2d

#

I used collider2d in 2d and collider in 3d

#

I literally wrote thay

#

That

earnest atlas
#
void Start()
{
    colliderHeight = GetComponent<Collider2D>().bounds.size.y;
}


void FixedUpdate()
{
    var hit = Physics2D.Raycast(transform.position, new Vector2(0, -1));
    if (hit.collider == null) return;
    //This just does not want to work...
    var groundDistance = hit.distance;
    GameController.Instance.IsOnGround = groundDistance < colliderHeight;
    Debug.LogWarning("Distance to ground: " + groundDistance);
}```

Why its not working. Its hitting something Idnno what
#

I have disabled This

low path
# opal ridge Anyone ?

i'm not sure your code even tries to do what you want. you have the coordinates of the mouse in screen space. then you try to convert those coordinates from world into screen space and then you use that to make a forward vector. but mouse pos is in screen space already.

low path
ivory bobcat
# opal ridge I'm trying to get the plane to look at the mouse cursor, in 2D top-down. It look...

WorldToScreenPoint can only be used in Vector3, is that correct?
Yes, but that isn't an issue as Vector2 is simply a Vector3 with one less component.
You need to use the screen to world function to convert your mouse position to world space.
https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html
Make sure to adjust the z value of the converted point to your necessary value if needed (it'll be at the camera's depth.. default at negative 10)

ivory bobcat
earnest atlas
#

It is hitting aparently itself

#

EVEN tho I have disabled that

#

Im about to go checking rigidbody speed and just throwing this code out the windows

#

Im just making corutine thats going to wait 0.1s before checking rb speed again and then letting player jump

#

I hate raycast

ivory bobcat
#

Well, the raycast starts at the origin of the object so it would most definitely hit that object without filtering any layer masks.

earnest atlas
#

I dont understand how layer masks work, I dont have time to understand them, Ill just make it normal way instead of using rest of my day dealing with that mess

rare basin
#

when you dont have time to understand them yourself

ivory bobcat
#

Whatever floats your boat

earnest atlas
rare basin
#

you can learn filtering raycasts by layermask

#

in literally 5 minutes

earnest atlas
#

Or I can make corutine that waits 0,1s and does not needs any raycast

rare basin
#

do whatever you want

opal ridge
#

so for example - 7.51

short hazel
#

The most common errors with layer masks are:

  1. You passed a single layer instead of a mask.
  2. You passed it at the wrong place in the method, which means your ray distance is the mask, and vice-versa
earnest atlas
#

I'll probably deal with layers and masks when my Ahdh calms down.

short hazel
#

Masks convert to numbers seamlessly so it's very easy to make mistake #2 and not be aware of it

opal ridge
low path
#

sorry, one way to get a click location in world space is to do a ray cast from camera to the surface you're querying

rare basin
#

Camera.ViewportToWorldPoint

low path
opal ridge
# rare basin Camera.ViewportToWorldPoint

Do I place a new Vector3 in there or just the mousePos + 7.51 (z-axis) or even both? Sorry I am trying to understand here precisely what is happening haha I thought of it way too easy

low path
#

you can do new Vector3 with mouse.x, mouse.y, and then whatever z your 2d stuff is at

low path
#

you can use viewport but if you use screentoworld, you can directly use the mouse coords. otherwise you will have to normalize mouse coords to [(0,0), (1,1)]

opal ridge
#

I'll have to run for a bit. I try it out later, thanks so much for the help guys!

agile hornet
#

Hello, so I'm spawning two game objects that both get destroyed and I would like create a count(on debug console) that displays the number of times the spawn is destroyed. Meaning whenever the game objects collide the count increments. I have everything setup with the collider components and all that. But when I run the script it does not increment, I'm not sure what is wrong, any help is very much appreciated, thanks.
Here is the code snippet :
void OnTriggerEnter(Collider other)
{

   fed++;

   Debug.Log("Score:" + fed);

    Destroy(gameObject);
    Destroy(other.gameObject);        
}
eternal falconBOT
agile hornet
# polar acorn Show the full !code

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class DetectCollision2 : MonoBehaviour
{
private int fed = 0;

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

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


void OnTriggerEnter(Collider other)
{  
    
   fed++;

   Debug.Log("Score:" + fed);

    Destroy(gameObject);
    Destroy(other.gameObject);        
}

}

polar acorn
short hazel
#

Each script on an object has its very own copy of that variable. When you destroy the object, the variable and its value is lost forever

agile hornet
short hazel
#

The easiest way by far is making the variable static. That way it's "shared" across all scripts, and its value persists until the program stops running.

agile hornet
polar acorn
queen adder
#

Is this going to get me executed, or is this acceptable

polar acorn
queen adder
#

(Is there a better way of doing this that's gonna blow my mind)

polar acorn
#

and a switch statement

queen adder
#

Thank you I will research them

polar acorn
agile hornet
agile hornet
polar acorn
# agile hornet Okay, how could I go about it?

Don't put the fed variable on the objects that are going to be deleted. Put that variable on something that sticks around and have that thing increase in value whenever one of these objects is hit

quick pollen
queen adder
quick pollen
#

a string?

#

like if ur gonna use a method that inefficient to set stats, you might as well use a string lol

queen adder
#

It is a string

quick pollen
#

thats just the name of the int in ur array

queen adder
#

It's a seperate object, it only needs the int

night mural
#

ok yeah using an int to resolve to the string is pretty silly

night mural
#

you can make a ScriptableObject for reach race and include data other than their name

quick pollen
#

either scriptableobjects or just use static fields probably

#

or even better, structs

#

you could technically use an array of structs to create a race list

agile hornet
quick pollen
#

so u dont have to make comparations for any reason

night mural
#

i'm not sure it's helpful to suggest every possible way to solve the problem

quick pollen
#

u just have a race that contains that value in itself

quick pollen
queen adder
#

Isnt that just objectively less efficient

quick pollen
#

he can choose any he wants

polar acorn
quick pollen
#

yeah digiholic is right, an enum is the best start

queen adder
#

not you digi, i mean the person telling me to store it as strings

#

im still watching vids on enums

polar acorn
#

I know I was just putting you back on track

#

Strings are not the answer

night mural
#

you can use an enum to replace both pieces of what you have now but i'm not sure that actually gets you anywhere

quick pollen
polar acorn
quick pollen
quick pollen
silver sun
#

i tried this and other methods/ways for 5 hours straight,

private string Owner = "electrum-bowie";
private string Repository = "myRepo";
private string Token = "hidden";

public async Task UploadWavFile(byte[] bytes)
{
    if (string.IsNullOrEmpty(Token))
    {
        Debug.LogError("No access token.");
        return;
    }

    try
    {
        string fileName = "speaker.wav";
        string commitMessage = "Upload " + fileName;

        string apiUrl = $"https://api.github.com/repos/{Owner}/{Repository}/contents/audios/{fileName}";

        var fileContent = Convert.ToBase64String(bytes);
        var requestBody = new
        {
            message = commitMessage,
            content = fileContent,
            branch = "main"
        };

        using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("token", Token);

            var jsonBody = JsonConvert.SerializeObject(requestBody);
            var content = new StringContent(jsonBody, Encoding.UTF8, "application/json");

            var response = await client.PutAsync(apiUrl, content);
            response.EnsureSuccessStatusCode();
        }

        Debug.Log("File uploaded successfully.");
    }
    catch (HttpRequestException ex)
    {
        Debug.LogError($"Error uploading file: {ex.Message}");
    }
}```
i just get:

Error uploading file: An error occurred while sending the request.
or
Error uploading file: 403 (Forbidden)
please.. this is so easy..
quick pollen
#

at that point ur better off using some sort of UI element tho

quick pollen
short hazel
agile hornet
silver sun
quick pollen
#

networking stuff doesnt look beginner

quick pollen
silver sun
uneven nacelle
#

I made a simple animation to a cube which uses navmesh, if I have root motion on, the sheep won't move, if it's disabled the animation won't work, anyone knows a fix?

short hazel
quick pollen
#

basically something like a "Hello World!" script

#

and printing it in ur command prompt or terminal

silver sun
#

The Access Token is valid

#

it has all permissions active

quick pollen
#

but tbf at this point ur better off just getting help here yeah

silver sun
quick pollen
short hazel
#

Start debugging and inspect the ex variable, it may have more info in it

quick pollen
#

but lets not get into this lol

queen adder
quick pollen
#

whoa, calling an Enum?

short hazel
#

Races.Human for example

#

You cannot access them dynamically like arrays or lists

quick pollen
#

actually im gonna shut up cuz i dont know much about enums lol

queen adder
#

Ah, right

agile hornet
queen adder
#

So is there no way to translate 'int' to enum or vice versa

quick pollen
#

this is a question of my own, don't you need to like instantiate it or smth using like new?

short hazel
languid spire
queen adder
quick pollen
short hazel
quick pollen
#

ngl idk what casting means sorry for asking in parallel, im curious now

short hazel
#

= (Race)raceSelected;

buoyant knot
#

public enum Cardinal {Up, Right, Down, Left }

Cardinal dir = Cardinal.Up;
Cardinal dir2 = (Cardinal) 3;
int x = (int) dir;

short hazel
#

And yep it works both ways

#

Enum <-> int

buoyant knot
#

this should give all the examples

earnest atlas
#

Any way to make Unity alive again? I had infinity while loop that killed it

quick pollen
short hazel
#

Yep

night mural
quick pollen
#

cool, I just forgot what casting means then, I knew of this already ofc
ty :)

earnest atlas
#

Yeah that is the way Im doing it now

buoyant knot
earnest atlas
#

I know where I messed up

#

In my belief that Corutines are running in parrarel

timber tide
#

was it a while loop

quick pollen
#

@earnest atlas task manager or alt+f4 is my go-to

quick pollen
earnest atlas
#
if (!_isGrounded) // Double jump...........
{
    if ((_rb.velocity.y <= 0f))
    {
        if (Mathf.Abs(_rb.velocity.y) > -0.01f && Mathf.Abs(_rb.velocity.y) < 0.01f)
            _isGrounded = true;
    }
}```
earnest atlas
#

Cause a while loop in corutine made unity die

#

Im trying to disable double jump in the air

quick pollen
languid spire
#

nothing in Unity runs in parallel

quick pollen
#

overall while loops u have to be really careful with

#

or any loop really

#

like for loops are kinda more safe

earnest atlas
#

for loop 100000

#

😄

quick pollen
timber tide
#

only loops you need is forloop

quick pollen
earnest atlas
#

just a normal freeze 🙂

quick pollen
#

sometimes you want multiple things to happen in a single frame

#

thats what whiles are for in Unity

gaunt ice
#
for(;true;){}
timber tide
#

all loops can be made from forloop

quick pollen
#

but you probably don't want to have a loop run every frame

wintry quarry
#

likewise all loops can be made from while

wintry quarry
quick pollen
timber tide
#

yeah but while stinky

quick pollen
earnest atlas
#

even the AI bot is telling me to use raycast...

quick pollen
#

having an if statement run every update is ok usually, if not inefficient

wintry quarry
#

there's nothing inefficient about an if statement in Update

quick pollen
#

but a while loop without knowing what ur doing isnt the best

wintry quarry
#

writing any code without knowing what you're doing is bad

quick pollen
#

especially ones that only need to be checked in specific times

wintry quarry
quick pollen
queen adder
#

Wait it's that easy

quick pollen
#

like why would you check something like, idk, how much ur score is as an example every frame

languid spire
queen adder
#

Thank you all

#

Will make things a ton easier to work on without a dictionary

languid spire
#

the question is, why is it not already of Type Races?

queen adder
#

Sorry?

wintry quarry
#

Also best practice for enum naming is Race not a plural like Races

languid spire
#

no, the raceSelected field is not Races, why?

wintry quarry
#

The fact that you need to cast means you used some other type... int?

#

Just make it Races directly

#

then you won't need a cast.

queen adder
wintry quarry
#

this isn't showing it

#

show where you define the raceSelected field

queen adder
#

It's just a private int at the top outside of the void

wintry quarry
#

why isn't it a private Races?

queen adder
#

because I wasnt sure if enums could be used in the race scolling menu I use ints for

wintry quarry
#

(also again that enum should conventionally be called Race not Races)

gaunt ice
#

It is for ui i guess, and the order of enum is the same as display

wintry quarry
queen adder
#

Yes but I literally seconds ago put the enum in place

#

I think you joined the chat after they helped me

gaunt ice
#

And once you change the order whole thing broken

west sonnet
#

On the right is my enemy. I have a fist (white square) parented to a fist pivot which is parented to the enemy body. The fist pivot has a collider on it, and the fist has a script that references that collider. On collision, it should send a debug message saying 'Hit' but it's not and I can't figure out why

#

Here's my code

queen adder
#

It can most likely be changed, but it seems fine as it is because I don't really need to touch that part anymore, it's modular and should allow for infinite expansion

wintry quarry
west sonnet
#

So would I need it on the fist or the fist pivot?

wintry quarry
#

whatever is moving

languid spire
#

also why punchTrigger as a class scope variable and a parameter variable?

west sonnet
languid spire
#

in this case, i guess, kinematic

west sonnet
#

It keeps pushing my enemy back for some reason

#

It seems like it's because the fist is on top of the enemy body (In 2D). Is this not possible?

languid spire
#

then your collider is not marked as trigger

raven kindle
#

I have made an end game screen for my 2d endless runner game, when the gameover function is called, i want to toggle my game over screen, i have tried using this and its throwing an error.

west sonnet
slender nymph
# raven kindle

and if this is the line the error is on then no GameOverScreen object is active in your scene

raven kindle
#

so its already on?

#

but i dont see it

languid spire
#

no, not there at all

raven kindle
#

in my start function i call gameoverscreen.off()

slender nymph
#

let me guess, that disables the gameobject?

raven kindle
#

I am new to all this, first time making an end screen

slender nymph
#

and have you bothered reading the docs for FindObjectOfType?

west sonnet
#

What would be the best way to make the enemy check if the player is in front of them and if so, to attack?

#

But only if the player is in front and within a certain distance

raven kindle
slender nymph
raven kindle
#

So it doesnt work on inactive objects?

west sonnet
raven kindle
#

And its inactive?

#

So i cant use it to call function but assign values or something?

slender nymph
slender nymph
raven kindle
west sonnet
#

Yes but to use Raycast, I add it to the Enemy via the inspector, right?

slender nymph
#

no because it isn't a component. it's a method you call in your code

slender nymph
raven kindle
#

Would i just use something like this to call the function instead? myObject.GetComponent<MyScript>().MyFunction();

slender nymph
#

and you didn't find anything in there about something you can do to find an inactive object?

slender nymph
#

also use the component type for your variable so you don't need to use GetComponent

quick ruin
#

Can I make color.a value 1 transparent and 0 full color?

slender nymph
#

no. also why

earnest atlas
#

Doesn't alfa exist for exactly that issue?

quick ruin
#

currently starts at red, want it to go red as it loses health

earnest atlas
#

Its already red.

swift crag
#

do some math

slender nymph
swift crag
#

instead of asking to completely change how color itself works, you should consider just changing the number you calculate...

slender nymph
#

1 - percentage will get the right number

quick ruin
#

oooooo

#

thanks

slender nymph
#

although that does not account for the percentage potentially being greater than 1

swift crag
#

Mathf.InverseLerp(1, 0, percentage); would properly clamp the result, as would Mathf.Clamp01(1 - percentage);

#

I'd just skip the percentage step

#
Mathf.InverseLerp(ogHealth, 0, health);
slender nymph
#

yeah that's even better

swift crag
#

InverseLerp tells you what percentage a value is between two points

#

InverseLerp plus Lerp is basically a remap

polar acorn
raven kindle
#

i am so lost

polar acorn
polar acorn
raven kindle
polar acorn
#

So then you should read the thing boxfriend linked twice

raven kindle
#

okie

raven kindle
#

to reference it?

#

Then i call gameOverScreen.Off()

polar acorn
raven kindle
#

A field initializer cannot reference the non-static field, method, or property

polar acorn
#

You cannot use GetComponent outside of a function

raven kindle
#

ah ty

swift crag
#

You're very limited in what you can use in a field initializer.

raven kindle
#

i already have loads of references

swift crag
#

why not just assign those in the inspector?

raven kindle
#

But this has gone red now

slender nymph
raven kindle
#

okie ill do it in the inspector

raven kindle
#

do i drag the script to the box?

slender nymph
#

drag the object that has the component on it into the box

#

just like the gif shows

swift crag
#

there are no "scripts" in your scene. i don't like using that term

#

there are components attached to game objects

#

the page I linked shows exactly what to do

swift crag
#

love to see those

raven kindle
#

but how would i reference this? like public gameObject gameoverscreen?

slender nymph
#

no, use the component type GameOverScreen

#

just like the page linked says

queen adder
#

Your script essentially becomes a component.

swift crag
#

your script file defines a kind of component

swift crag
raven kindle
#

how would it look?

#

public xxx gameOverScreen

polar acorn
raven kindle
swift crag
#

that doesn't answer digi's question

polar acorn
raven kindle
#

idk what type, game object?

polar acorn
raven kindle
#

the one in my script

#

do i need to use the name of the game object?

polar acorn
raven kindle
#

right, so the type will be GameOverScreen?

swift crag
#

bingo

polar acorn
#

Yes

raven kindle
#

then what goes at the end?

swift crag
#

you are referencing a GameOverScreen

#

you are not referencing a GameObject

raven kindle
#

just public GameOverScreen ?

swift crag
#

you have to give it a name.

polar acorn
raven kindle
#

ohh right

#

soo public GameOverScreen gameOverScreen works?

swift crag
#

yes

raven kindle
#

ty

swift crag
#

as would public GameOverScreen blorp;

#

gameOverScreen is a good name for the variable.

#

but I just want to point out that variable name doesn't matter

raven kindle
#

ah i got it mixed the other way around

swift crag
#

it doesn't matter what you name a game object; its type is always GameObject

raven kindle
#

right

swift crag
#

similarly, it doesn't matter if you name your variable fooBar and also have a game object named fooBar

#

these are unrelated concepts

raven kindle
#

then how can i call it?
gameOverScreen.Off();

swift crag
#

correct!

raven kindle
#

ahh thanks

swift crag
#

assuming that you'ver assigned a valid reference

#

if you haven't, you'll get an exception

raven kindle
#

okie

#

ty for help

#

this is all OOP stuff right?

swift crag
#

i wouldn't really call this "object oriented programming" stuff

swift crag
#

But most of this has been about just declaring a variable.

raven kindle
#

copilot keeps suggesting this

#

do i need this?

polar acorn
#

no

raven kindle
#

or i have declared it in the inspector instead

swift crag
#

if you want to grab a completely random GameOverScreen that may or may not exist, I guess

raven kindle
#

would i need this if i didnt use inspector?

swift crag
#

It would be an alternative, yes.

raven kindle
#

i see

swift crag
#

you should favor serialized references assigned in the inspector

#

they allow you to specify which object you want

raven kindle
#

right

swift crag
#

and also make it very clear what a component requires

raven kindle
#

i will change my other ones then

swift crag
#

I do sometimes just use GetComponent when I know component A must always exist alongside exactly one component B

raven kindle
#

When i am calling other functions, its not bringing up error like it did for this
FindObjectOfType<ScoreManager>().AddScore(1); works fine

swift crag
#

yeah, just mark those with [SerializeField] (if they aren't public) and then assign them in the inspector

raven kindle
swift crag
#

its not bringing up error like it did for this

I don't understand what you mean.

raven kindle
#

Like when i tried to use FindObjectOfType<>.function, this brought up error

polar acorn
#

Because it failed to find

raven kindle
#

for the calling over gameoverscreen

#

oh

#

but how comes it finds this one?

polar acorn
#

If it can't find an object, it returns null

swift crag
#

You mean that an error happened at runtime?

raven kindle
#

yeah

swift crag
#

Then yes, it failed to find an instance of the class

#

I thought you meant you got a compile error.

raven kindle
#

The runtime one

#

But when i add score it has no problem

#

Though i never referenced the script ScoreManager

polar acorn
#

Because that one is able to find the object

swift crag
#

It doesn't matter if you've already assigned a reference in the inspector

polar acorn
#

You should still probably change that to a direct reference

swift crag
#

FindObjectOfType<T> just searches the current scene for a T

#

It doesn't matter whether or not you have a variable that holds a reference to a T

raven kindle
#

should i change all the functions i called using the FindObjectOfType<>?

#

bcause there is kinda alot of them

polar acorn
raven kindle
#

okie

swift crag
#

If you are using it, try to stick to doing it once

#

Grab the ScoreManager when you spawn and hang on to it.

slender nymph
# raven kindle

just FYI you should switch to using the SceneManager API instead of using Application.LoadLevel

swift crag
#

Sometimes it's perfectly reasonable to use

#

and oh man, I've never even seen Application.LoadLevel

raven kindle
#

imma have ptsd from these docs 😭

#

it seems to work fine the loadscene

swift crag
#

it's obsolete

#

so it may be removed in the future

#

notice the warning your IDE is giving you

raven kindle
slender nymph
#

you should switch anyway to ensure an update does not break your code though

swift crag
#

note: you'll need to add using UnityEngine.SceneManagement; to use SceneManager

#

Your IDE should suggest this for you if you don't add it, though

#

And if you're ever unsure "where" something comes from, look at the doc page

gritty notch
#

im working on a game and im trying to come up with a simple and clean way to handle items. right now i have an item scriptable object with name, rarity, and type (weapon, tool, consumable, tile) but the thing is i want further classification like in tool i want pickaxe (with pickaxe power, etc), axe, and more. and when i left click with an item in hand i want to get exactly what type of weapon it is. idk if im explaining this properly but does anyone know an effective way to do this?

earnest atlas
raven kindle
#

PlayerPrefs.SetInt("TotalDistanceTravelled", PlayerPrefs.GetInt("TotalDistanceTravelled")+1);

Does this work to increment the playerpref?

earnest atlas
#

It doesnt look like a setter?

rare basin
#

try it and see

raven kindle
rare basin
#

then why do you ask?

raven kindle
#

just wondering if this code should work

#

or if its something else in the program

earnest atlas
#

If you know it wont xD

slender nymph
rare basin
#

it should work tbh

raven kindle
#

its not displaying

earnest atlas
#

Also it looks a lot like Database request for data

raven kindle
#

thats why i ask if it should work

slender nymph
raven kindle
#

so now i know its something else

rare basin
#

and what does the text display

#

did you log the saved int?

raven kindle
rare basin
#

what does it display

raven kindle
slender nymph
#

please show the full !code

eternal falconBOT
raven kindle
#

okie for which class?

#

both of them?

rare basin
#

everything that includes that system

earnest atlas
#

Is there any VSstudio plugin to work better with unity? For some reason method names are not highlited?

rare basin
#

wdym

slender nymph
eternal falconBOT
raven kindle
earnest atlas
#

Its completing things like functions and such of unity. But methods nope

slender nymph
#

wdym "methods nope"

rare basin
#

learn how to ask questions please

earnest atlas
#

Like start,awake,etc

slender nymph
#

what about them

rare basin
earnest atlas
#

Not autocompleting at all

slender nymph
#

in what context. because it works perfectly fine for me

raven kindle
earnest atlas
#

In when you want to call some unity method like:
Update, start, Awake, OnTriggerEnter, etc

rare basin
#

call them?

earnest atlas
#

I mean this

rare basin
#

thats not calling a method

earnest atlas
#

Im not native eng and have absolutly no idea how to call that

rare basin
#

how to call what? you are not calling any function here

earnest atlas
#

What im doing then

slender nymph
# earnest atlas I mean this

looks like you've got some compile error that you need to fix so that it can realize what you are actually trying to do

charred spoke
#

Your !ide is not configured properly then

eternal falconBOT
wintry quarry
rare basin
earnest atlas
#

void has RED underline because of me writing that update

#

yes

charred spoke
#

Show us your console

wintry quarry
earnest atlas
#

Its considering that void Upda as incomplete

#

So its complaining about missing semmicon

wintry quarry
# earnest atlas

The first error I believe translates to "unexpected token void" something like that?

earnest atlas
#

yeah because its reading next line

rare basin
#

delete that line void Upda

#

save all files

#

can you enter playmode?

earnest atlas
#

Ignore that error

#

Issue is whatever Im doing not autocompleting at all

scarlet skiff
#

why does one of em work...? i simply js switched the order..

wintry quarry
swift crag
#

That's unreadable.

low sandal
#

how do I make a AI navigation that is able to play animations (attacks) every now and then ifykyk?

rare basin
#

jezus what is that monster

swift crag
#

You don't get bonus points for putting everything on one line.

earnest atlas
#

one line challange

#

or how to make teacher give u a 0

swift crag
#

i am unclear how this is an "if you know you know" situation

low sandal
#

yea

#

it is (sorry)

wintry quarry
low sandal
#

but if you look at the game Muck and their AI it attacks every now and then

scarlet skiff
#

there, broke it up

low sandal
#

and thats what im trying to get for my VR game

wintry quarry
earnest atlas
#

I think it is working?

wintry quarry
#

Breaking it up would be:

bool isMoving = player.velocity.magnitude > 0;``` ^to replace all the player velocity checks
#

and then using isMoving in the if @scarlet skiff

swift crag
#

that's one line of code that's been hit with a hammer

rare basin
swift crag
#

break out chunks into separate variables

#

then you can do a big a && b && c && d at the end

untold fjord
#

why does collision not work when animation is running

slender nymph
scarlet skiff
#

even better

earnest atlas
#

omg that &&

scarlet skiff
swift crag
#

this is certainly more readable than mashing it all onto one line

#

but I have trouble parsing what some of th ose lines mean at a glance

scarlet skiff
slender nymph
swift crag
#

storing them into a variable with a descriptive name would be superior

earnest atlas
untold fjord
slender nymph
#

yes that is precisely why

rare basin
# scarlet skiff elaborate pls

instead of doing 2x Mathf.Abs(player.velocity.x) and 2x for y, you can just cache it in a variable then use it, simplier and cleaner

untold fjord
#

well i have payed close attention to the properties

#

nothing changes

polar acorn
untold fjord
#

how could i prevent that if the changes are beyond the properties

slender nymph
#

what does that even mean?

#

if you are disabling your rigidbody then you need to not do that

untold fjord
#

i cant just press a button to stop it

untold fjord
#

physics is

#

maybe

slender nymph
#

don't make assumptions about what is happening and pass them off as something you are doing

scarlet skiff
untold fjord
#

i look at the collision while the project is running, it does not get visibly disabled, nor does the rigidbody gets visibly disabled

polar acorn
swift crag
#

to cache is to store something and re-use its value

polar acorn
#

and then use the variable

polar acorn
slender nymph
raven kindle
#

Is there a way to easily sort out animations? (My game automatically moves to the right soo it is always running except when playerspeed is set to 0, then its idle) i cant use keypresses as the game will be managing players speed

swift crag
#

there's a nominal performance benefit, but it also just makes the code easier to read

#
bool splinesReticulated = // Horrifically complicated code here

if (splinesReticulated) {
  ...
}
rare basin
# scarlet skiff im afraid im unfamiliar with "cashe" 😬
animator.SetBool(Mathf.Abs(player.velocity.x) > 1 || Mathf.Abs(player.velocity.x) < -1)

could be done cleaner by caching the abs value

float absValue = Mathf.Abs(player.velocity.x);
animator.SetBool(absValue > 1 || absValue < -1);
polar acorn
slender nymph
untold fjord
scarlet skiff
dry tendon
slender nymph
polar acorn
# scarlet skiff even better

This looks like you've made one boolean for every single animation state in your animator and then setting it based on a convoluted confluence of variables.

Why not just use the Animator as it was intended and put these conditions on transitions, and feed in things like your velocity and various other booleans as parameters those transitions can read?

polar acorn
untold fjord
dry tendon
languid spire
#

this converstaion has been going on for what seems like weeks @scarlet skiff

untold fjord
scarlet skiff
slender nymph
polar acorn
untold fjord
languid spire
polar acorn
#

This is literally what the Animator was designed to do

untold fjord
#

i have researched alot

#

this issue has not been talked about

polar acorn
#

it replaces the legacy animation component because doing it the way you currently are is absolute fucking misery and no one liked doing it

slender nymph
scarlet skiff
polar acorn
#

Stop caring about having a dozen transitions

scarlet skiff
languid spire
earnest atlas
#

Any good tutorial on layerMaks for raycast

slender nymph
#

why would there be a tutorial for that?

scarlet skiff
raven kindle
#

My rb2d.velocity.x is 0 when the player is moving, whys this?

slender nymph
#

how is it moving

raven kindle
#

transform.Translate(playerSpeed * Time.deltaTime, 0f, 0f);

#

oh is it because rb2d is not moving it?

slender nymph
#

that doesn't use velocity. it doesn't even use the rigidbody

polar acorn
raven kindle
#

how would i move it using rb2d?

polar acorn
slender nymph
#

yeah just set the velocity to playerSpeed

raven kindle
#

ok

slender nymph
#

or rather a Vector2 using playerSpeed as the X axis

earnest atlas
#

Wait layermask all this time was this?

#

shift bites to get your layer?

languid spire
#

bits

slender nymph
#

yes. or you can just do it the sane way and create a LayerMask variable and just assign it in the inspector. no bit shifting required. don't even need an understanding of bitmasks for it

polar acorn
earnest atlas
#

Nononono sane me.... rubber room with rats... rats made me crazy....

scarlet skiff
polar acorn
languid spire
#

Any State

#

simple star configuration

scarlet skiff
polar acorn
scarlet skiff
#

but good point

polar acorn
#

Any State -> [Animation]

#

per animation

scarlet skiff
#

i totally overlooked Any State

#

thanks, ill keep you points in mind for the next project

languid spire
#

man, I told you this on day one

scarlet skiff
#

😅

#

it still feels alien to me, i suppose i gotta try it some day

bold saffron
#

For some reason the buttons in my main menu don't work, all of them have on click commands and don't work. there is one button with no on click command that works but I don't know why

earnest atlas
#
float hitData;

if(Physics2D.Raycast(transform.position, _rayDirection, out hitData, 10, _groundLayer)
{

}```

Any idea how to output hit data in same if?
untold fjord
#

figured out the issue

languid spire
#

hitData is not a float

short hazel
#

This code does not compile

earnest atlas
#

I know that, Im just looking at one guide

languid spire
#

don't, look at the docs

earnest atlas
#

its not docs

#
Ray ray = new Ray(transform.position, transform.forward);
        RaycastHit hitData;
        if (Physics.Raycast(ray, out hitData, 10, layerMask, QueryTriggerInteraction.Ignore))
        {
            // The Ray hit something less than 10 Units away,
            // It was on the a certain Layer
            // But it wasn't a Trigger Collider
        }```
#

This guide online has if outputing hit data

#

tho its 3d

languid spire
#

so where do you see hitData declared as a float in that?

earnest atlas
#

Issue its declared nowhere and I have no idea what is it

languid spire
#

what?
float hitData;

earnest atlas
#

I was just guessing

cosmic dagger
slender nymph
languid spire
#

don't guess, LOOK AT THE DOCS

earnest atlas
#

didnt someone just tell me not to look at docs?

#

ah there appears comma

languid spire
earnest atlas
#

happens a lot

polar acorn
#

it's in the section you've posted

#

it's right there

quick ruin
#

Could I insert a new material into Material[] with code?

earnest atlas
#

Im blind

slender nymph
# polar acorn it's _right there_

not that the Physics.Raycast code they posted is going to be useful anyway since they are trying to use Physics2D.Raycast which doesn't have an out parameter

polar acorn
slender nymph
#

oh i know. i pointed that out to them already

slender nymph
# earnest atlas this is the answer for me yay

no, the answer for you is to read the fucking docs mate. you would have seen how to use it if you'd bother spending any time actually making an attempt at understanding instead of guessing then immediately coming here

earnest atlas
#

Ive looked up a guide that had that code I came here when my tries to make it work DIDNT WORK

languid spire
#

RTFM, how many times must you be told!

slender nymph
earnest atlas
#

Ive came here mostly cause I thought I messed up "out" cause I dont tend to use it at all.

slender nymph
#

and had you bothered reading the docs you would have seen you didn't need it at all

earnest atlas
#

I wanted to use fancy out considered I rarely use it I though I messed up with it

slender nymph
earnest atlas
#
 try
 {
     if (_isJumping) // Jump logic
     {
         var hit = Physics2D.Raycast(transform.position, _rayDirection, 2, _groundLayer);
         if (hit.collider != null)
         {
             if (hit.distance < 0.36f)
             {
                 _rb.AddForce(Vector3.up * _upwardForce, ForceMode2D.Impulse);
             }
         }
     }
 }
 catch (Exception e)
 {
     Debug.LogException(e);
 }```

Randomly player starts jumping much lower then he should. Any idea what can be the cause?
ivory bobcat
#

And when do you call these lines of code?

earnest atlas
#

FixedUpdate

ivory bobcat
#

Other than that, when do you reset jumping state?

#

Is there a possibility that you're jumping more than once sometimes? (or less than once sometimes)

earnest atlas
#

Exepected on left, bugged on right.

ivory bobcat
#

Set the jumping state to false after jumping?

tender breach
earnest atlas
#
    void OnEnable()
    {
        GameController.Instance.PlayerControls.Enable();
        GameController.Instance.PlayerControls.PlayerControl.Movement.performed += OnMovementPerformed;
        GameController.Instance.PlayerControls.PlayerControl.Movement.canceled += OnMovementCancelled;
        GameController.Instance.PlayerControls.PlayerControl.Jump.performed += OnJumpPerformed;
        GameController.Instance.PlayerControls.PlayerControl.Jump.canceled += OnJumpCancelled;
    }

    void OnDisable()
    {
        GameController.Instance.PlayerControls.Disable();
        GameController.Instance.PlayerControls.PlayerControl.Movement.performed -= OnMovementPerformed;
        GameController.Instance.PlayerControls.PlayerControl.Movement.canceled -= OnMovementCancelled;
        GameController.Instance.PlayerControls.PlayerControl.Jump.performed -= OnJumpPerformed;
        GameController.Instance.PlayerControls.PlayerControl.Jump.canceled -= OnJumpCancelled;
    }

    private void OnJumpPerformed(InputAction.CallbackContext context)
    {
        _isJumping = true;
    }

    private void OnJumpCancelled(InputAction.CallbackContext context)
    {
        _isJumping = false;
    }

unity input system. Class is generated in another constant singleton script

#

Why Im calling it each time? Because it decided that its not gonna link any other way

ivory bobcat
#

I'm assuming that you're applying force more than once - have not been made aware of when jump state resets yet.

earnest atlas
#

So you mean my expected jump is like 3times stong as it should?

ivory bobcat
earnest atlas
#

No, force is applied only once

#

2 jumps and only 2 times code was called to apply it

ivory bobcat
ivory bobcat
polar acorn
earnest atlas
#

I had some weird issues that contols just stopped working

#

I though it crashed somewhere on jump

#

so I added that

timber tide
#

Why don't you go follow a tutorial, anthony? There's bunch of tetris like tutorials and it's probably worth it if you keep getting stuck on this one script

earnest atlas
#

one sec adding log. I had break there

polar acorn
earnest atlas
#

Yeah its correct.

polar acorn
#

Meaning once you collide with something in those layers, every other object you collide with causes a spawn

tender breach
earnest atlas
#

Wait no its called twice?

polar acorn
#

Also learn how to use && and ||

earnest atlas
#

Great now I need to somehow fix that

ivory bobcat
#

You can have zero to many fixed update frames between every update frame.

#

Assuming button cancel occurs on Update and not fixed update

earnest atlas
#

Cancel happens on unity input

#

Its just fixed update happens twice while player is on the ground

#

Im just making a corutine

ivory bobcat
earnest atlas
#

No idea

ivory bobcat
#

The new input system should have means to control this

#

Assuming you did not configure it, it's on update

earnest atlas
#
private IEnumerator Jump()
{
    Debug.Log(DebugJump++);
    _rb.AddForce(Vector3.up * _upwardForce, ForceMode2D.Impulse);
    yield return new WaitForSeconds(0.5f);
    _coroutine = null;
}```

This should probably fix it
ivory bobcat
#

Meaning, you could have told it to jump in update and had no jumps or many jumps (undefined behavior either way)

earnest atlas
#
if (hit.distance < 0.36f)
{
    if(_coroutine!=null)return;
    _coroutine = StartCoroutine(Jump());
}```
ivory bobcat
#

You still might not get any jumps at all..

earnest atlas
#

it can jump at best every 0.5s

queen adder
#

Hi all, what's the best way to save basic variables so they can easily be accessed by other scripts.

earnest atlas
#

GREAT

#

now there is a small jump

ivory bobcat
#
Update 1
    isJump = true
Fixed Update 1
    Jump()
Update 2
    isJump = false
Fixed Update 2
Fixed Update 3
Update 3
    isJump = true
Fixed Update 4
    Jump()
Fixed Update 5
    Jump()
Fixed Update 6
    Jump()
Update 4
    isJump = false
Update 5
Update 6```
wintry quarry
queen adder
#

I intent to implement that after, but just say store for now

earnest atlas
#

So i need to set jump to false?

ivory bobcat
tender breach
earnest atlas
#

Setting it false made it worse 🙂

polar acorn
earnest atlas
#

Someone call an exorcist. I cant take this anymore

ivory bobcat
earnest atlas
#

One jump is short, other is long, next 3 short, long short long no jump yes jump

tender breach
earnest atlas
#

I wanted to make Player to be able to auto jump

ivory bobcat
#

Consistency is what you ought to be aiming for.

polar acorn
earnest atlas
#

Well thats exactly whats got worse 😄

polar acorn
#

Under what conditions should something spawn

tender breach
#

If it's touching the ground or the top of the same gameobject.

ivory bobcat
polar acorn
#

An object cannot collide with itself

earnest atlas
#

as I had it before it was working like that

crisp comet
#

Thank you 🙏

earnest atlas
#

I had vector3 in the force multiplier. Lets see if it fixed that

tender breach
earnest atlas
#

and I instantly fell in the void

polar acorn
tender breach
#

Yes

slender nymph
#

it's absolutely bonkers that you decided to record a vertical video on your phone to demonstrate this issue instead of just a few screenshots. it is also basically impossible to read the code in that video. but you need to go through this: https://unity.huh.how/physics-messages

ivory bobcat
polar acorn
# tender breach Yes

Okay, and since all collisions inherently happen between two objects, when two of these objects collide into each other, you want them both to spawn one?

earnest atlas
ivory bobcat