#💻┃code-beginner

1 messages · Page 584 of 1

wintry quarry
#

So it's:

var halfFOV = viewInDegrees * 0.5f;```
acoustic sequoia
wintry quarry
#

yeah that should work

acoustic sequoia
wintry quarry
#

they fall back to what they learned in 7th grade - which isn't necessarily a bad thing but there are better ways.

acoustic sequoia
#

*solved
why is this function only working sometimes? when it's not workign it's either; 1. not drawing a line, 2. drawing a line when it's behind the transform.

private void IsObjectInViewCone(float radius, float angle) {
            var snakePosition = snakeBrain.position;
            var targetPosition = _targetTransform.position;
            var distance = Vector3.Distance(snakePosition, targetPosition);

            if(distance > radius) return;

            var directionToTarget = (targetPosition - snakePosition).normalized;
            var angleToTarget = Vector3.Angle(transform.up, directionToTarget);
            if(angleToTarget <= angle / 2f) DrawDebug.Line(snakePosition, targetPosition, Color.red);
        }
grizzled spoke
#

Anyone know why when I add 3 players to the input system using .instantiate() it creates a 4th box
How do I fix this

#

Each player object im instantiating has an input system component and a camera child object

slender nymph
#

show code, and be more descriptive about what you mean. what "4th box" are you referring to

cosmic dagger
#

how many boxes do you start off with?

wintry quarry
#

What's a box?

acoustic belfry
#

Hi, im still struggling to make this work, for an strange reason when the player shoots it proyectiles and moves, the shooting speed gets weird, this is of what im talking about (ignore the glitched animation)

#

this is the script

#
{
    Vector3 mouseposition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    mouseposition.z = 0;
    Vector3 shootDirection = (mouseposition - transform.position).normalized;

    GameObject riflebullet = Instantiate(rifle_bullet, transform.position, Quaternion.identity);
    riflebullet.GetComponent<Rigidbody2D>().linearVelocity = new Vector2(shootDirection.x, shootDirection.y) * rifle_bulletspeed;

}```
grizzled spoke
#

i meant these boxes:

wintry quarry
#

that's the Doppler effect in action

grizzled spoke
#

i added the white lines
Each animal is a player object with an input system component
the 1st 2nd and 3rd boxes correspond with a chracter, the 4th does

#

this is how i instantiate the player objects
the boxes are a split screen from the input system

slender nymph
#

the fourth one does not appear to be a separate viewport, but rather is what the main camera is actually seeing, but the other three viewports are overlayed on top of that

wintry quarry
#

yep - disable the main camera you'll see that go dark

grizzled spoke
wintry quarry
#

YOu just have to write the code

#

I take it you're using PlayerInputManager's built-in split screen feature though?

grizzled spoke
wintry quarry
#

if you want what you said you'll have to write it yourself

grizzled spoke
wintry quarry
grizzled spoke
wintry quarry
#

the logic is not that hard

#

you could have a switch statement for the number of players and the code that assigns rects to the cameras.

grizzled spoke
#

is there any benefit, since I already have the split screen code and it's extra work to write it for 3 playes
plus im getting contradicting information, some people say split screen using the built in input manager is better than manual

acoustic belfry
#

cuz the player is supossed to move like crazy and shoot

wintry quarry
wintry quarry
acoustic belfry
wintry quarry
#

If you want them to always appear on screen with the same spacing etc, you would add the player's velocity to the bullets

wintry quarry
# acoustic belfry wat

if the player is moving and the bullets are moving, you will get these spacing artifacts

acoustic belfry
#

oh

wintry quarry
#

it's just the nature of what you're doing

acoustic belfry
#

wait, the character is that fast that outspeeds the mf bullets?

#

dang, then i have to speed up the bullets?

wintry quarry
#

has nothi9ng to do with "outspeeding" them

#

if you run in the same direction you're shooting, they're going to appear compressed

acoustic belfry
#

but i feel like shouldnt be like that

wintry quarry
#

Again it's similar to the doppler effect:

wintry quarry
acoustic belfry
#

but i mean

#

in a gameplay way, do this doesn't feel annoying?

wintry quarry
acoustic belfry
#

i mean cuz thats whats making me feel anxious, if this is normal as physics say, then doesnt matter?

wintry quarry
#

I didn't say it doesn't matter

#

it's just a consequence of how your game works

acoustic belfry
#

then what i should do?

wintry quarry
#

And yes if the bullet was significantly faster than the player, the effect would be less noticable

wintry quarry
#

it's your game

acoustic belfry
#

ok...

#

but i mean, i dont want that effect to happen

#

cuz i feel doesnt look too good?

#

idk

wintry quarry
#

Ok so change it then

#

I already made two suggestions on how to

#

pick one of those

acoustic belfry
#

ok, well, thanks

wintry quarry
acoustic belfry
#

im pretty new at coding...

wintry quarry
acoustic belfry
dire kelp
#

hi i am trying to make a jumpscare if someone presses a button but the animation simply wont show. i used the debugger which showed me that the button got triggerd so it must be an animation error but i cant get behind it any help?

acoustic sequoia
#

how can i do something like this without edge cases or any errors with storing a quick access to a list of colliders: (im going ot remove irrelivant code )

private Collider2D[] _collidersInFOV;

private void IsObjectInViewCone(float radius, float angle) {

            var overlapObjects = _enemyManager.GetAllObjectsInRadius(snakeBrain.position, radius);
            var colliders = new List<Collider2D>();

            foreach(var enemy in overlapObjects) {
                if(angleToTarget <= angle / 2f) colliders.Add(enemy);
            }

            _collidersInFOV = null;
            _collidersInFOV = colliders.ToArray();
        }```
#

in other words... i can't seem to find out the correct way to make an array (with objs in it ) to change entirely into another array (with new objs of same type )

polar acorn
#

If you want your bullets to move at a constant speed, they will be closer together if you move in the direction you fire

wintry quarry
ivory bobcat
#

It wouldn't remove the Doppler effect though. The reason why the bullets appear closer is because you're walking in the same direction as the fired bullets. Spawning the next bullet closer to the previous by running in the same direction. If the bullets are super fast, it'll not be as noticeable.

#

If you want them moving relative to the player or the screen rather than the world, you could perhaps child the bullet to the player so that when moving and firing, the bullet would "look" consistent in speed (they'll always take a certain amount of time to leave the screen because they would be displaced relative to the parent - with the camera following the player)

true owl
#

hello, i've set up two box collider 2d's to keep track of which side my player touches the wall on, is there a way to differentiate them in code? or is there a better way of doing it than what i'm doing?

void thicket
celest ore
#

Folks, I have a tilemap 2D. I want to make Enemy AI. Which approach can i go with?

buoyant finch
tulip nimbus
#

https://youtu.be/O_CyVdB0NgY

Why do my variables behave wierd? In this instance, sometimes when i switch objects in game hierarchy it feels like all my variables operate "faster" or increment differently than they should. This also happens when the tab is maximized. What can i do?

void PlaneMove()
{
        //constant Speed
        transform.position += transform.right * Time.deltaTime * Speed;


   
        if (Input.GetKey(KeyCode.A))
        {
            transform.Rotate(new Vector3(0, 0, 1) * sway);
        }
        if (Input.GetKey(KeyCode.D))
        {
            transform.Rotate(new Vector3(0, 0, -1) * sway);
        }

sway is supposed to control the Plane A/D movement, as shown in the Video, and with my testing, this variable is not changed.

keen dew
#

You have to apply deltaTime to the sway as well

tulip nimbus
#

Thank you!

echo ruin
runic quartz
#

quick question, does a raycast also rotate with the GameObject's rotation? Say a cube rotating every frame, a raycast set on one of the faces. Does the raycast also rotate with the cube's tranform rotation?

#

also does the raycast also rotate if the cube were to rotate via the animator?

slender nymph
#

raycast does not "rotate", it casts a ray in a specified direction. so you need to be using the object's rotation to determine the direction you cast the ray

runic quartz
#

in a way, the raycast is stuck onto the side of the cube. Whatever transformations are applied to that cube's side will also affect the raycast. Did i get that right?

slender nymph
#

no because a raycast is not an object in the scene and has nothing to do with the object you call the method from. it is entirely dependent on the data you pass to the method

runic quartz
#

so if i were to match the raycast's rotation with the cube's side, i'd have to pass direction to the raycast?

slender nymph
#

yes, you always have to specify a direction for the raycast

runic quartz
#

""" bool raycastUp = Physics.Raycast(transform.position, moveDir, 20f);
"""

#

somewhat like this, got it

slender nymph
#

how do you get the value of moveDir

runic quartz
#

from the direction the player is currently bound to move

slender nymph
#

how

runic quartz
#

the emphasis

slender nymph
#

okay i'm not going to play this game where i have to keep asking for more and more information. i am not familiar with the rest of your code, i do not know where these values you use come from, so naturally i don't know where targetAngle comes from and have no way of determining whether this will be relative to world space or the object's rotation

#

if the information i've provided thus far is not sufficient for you to understand how the raycast works then maybe someone else will come along and help you

runic quartz
#

yeah I understood the task

#

thanks for your time

quick pollen
#
    int x;
    private void Awake() {
        Pools = new IObjectPool<GameObject>[projectiles.Count];
        for(int i = 0; i < projectiles.Count; i++){
            x = i;
            Pools[x] = new ObjectPool<GameObject>(() => CreatePooledItem(x),
            OnTakeFromPool, OnReturnedToPool,
            OnDestroyPoolObject, true, 20, 50);
        }
        Instance = this;
    }
    GameObject CreatePooledItem(int i)
    {
        GameObject newPooledObject = Instantiate(projectiles[i]);
        newPooledObject.GetComponent<BasicBullet>().pool = Pools[i];
        return newPooledObject;
    }```
#

so for some reason, x is always equal to projectiles.Count - 1, no matter what I do

#

I try to get items from pool number 0, and it always takes one from pool number 1, no matter what

#

I tried having a list of object pools so I don't have to create a new one for each different type of projectile

eternal dragon
#

I want to implement a game where I will have many characters. None of them share common characteristics, but many of them could share common abilities. For example, many could move with a basic movement, some could jump, some could control gravity, some could fly, and so on. To achieve this, I thought of creating components, like the PlayerMovement class, the PlayerJump class, the PlayerGravity class, where I will define parameters and methods. Then, for each type of cube (or player), I will use GetComponent and use the methods from these classes. For example, in the Player1 class, I will get the jump movement component, while in Player2, I will get the component and then use the methods from these classes
Each player will have different animations, but I could implement them in each script, for example in PlayerMovement, like this. I couldn’t create a separate animation script unless it's a different one for each player, or I could implement it directly in their respective controller.
Could someone give me some advjse??

quick pollen
#

what.

#

if they share abilities they share characteristics

#

also, just use an animator

eternal dragon
#

i wanted just to say that i cant use inheritance but composition

#

but its good to create some classes with only methods that i can acces from a controller ??

quick pollen
#

why not just have each of the components have a reference to an animator, and animate your characters like that?

#

you dont need inheritance for that

#

just manually set the reference to the animator

eternal needle
eternal dragon
quick pollen
#

I know lambda expressions pass by reference basically

#

but ive been told back then to do this, where I declare x globally, and didnt check if it works for a non-1 array

verbal dome
#

The whole idea is to declare a local variable

#

Not global/class scoped lol

buoyant finch
buoyant finch
verbal dome
#

Find out why

#

You need to learn to debug your code

buoyant finch
#

I have I fixed everything else

#

All code runs well now like everything I desired I can even change directions I do still suspect that the animation frames are the problem and I should try modifying then perhaps

verbal dome
#

You could just Debug.Log something every time you change the current frame

#

This way you can check what is setting the walk animation at the start

visual linden
#

I'm curious if GetAxisRaw really returns 0 and not just some very small number.
Instead of checking if it's greater than 0, perhaps try checking if it's greater than 0.05f, or try GetAxis instead of GetAxisRaw.

astral falcon
#

I highly suggest going over to the new input system anyways.

buoyant finch
verbal dome
#

I don't see any debug.logs, did you use the IDE debugger?

verbal dome
buoyant finch
verbal dome
buoyant finch
#

sure

verbal dome
#

Okay well that doesn't tell me much, i'll just assume you assigned them correctly

#

So what debugging steps did you take?

#

Because I don't see any trace of debugging in your code

buoyant finch
#

I checked all the frames that were toggled

astral falcon
#

I guess, the frames you have are just being mirrored because of frame 6, 11 and 3 are in there two times?

buoyant finch
buoyant finch
buoyant finch
astral falcon
#

yes, I did not read the whole conversation, sorry if you have to say it again

buoyant finch
buoyant finch
#

so you can see that the left animation doesn't work like the other directions

verbal dome
#

What's with all those anyKeyDown and anyKey checks

#

The logic is really hard to follow

buoyant finch
verbal dome
#

Also just replace all Input.GetKey(Keycode.z) with isRunning

verbal dome
#

(Like now)

buoyant finch
buoyant finch
verbal dome
#
        else if (isRunning)
        {
            // Show idle sprite when Z is held and no movement
            spriteRenderer.sprite = GetIdleSprite();
        }
        else if (Input.GetKey(KeyCode.Z) && !Input.anyKeyDown && !Input.anyKey)
        {
            spriteRenderer.sprite = GetIdleSprite();
        }```
How can the second ``else if`` be true here? Z key can't be pressed since isRunning is false
buoyant finch
#

yeah that's why it didn't work but this works

else if (Input.GetKeyUp(KeyCode.Z) || Input.GetButtonUp("Run"))
{
    // Transition from running to walking: force first walk frame
    currentFrames = GetFramesByDirection(false); // Get walk frames
    currentFrame = 0; // Set to first walk frame
    spriteRenderer.sprite = currentFrames[currentFrame];
    frameTimer = 0f;  // Reset animation timing
    keyPressTimer = 0f; // Reset key press timer
    return;
}
verbal dome
#

I think you should use some kind of state machine. This is a mess

buoyant finch
#

I just want to fix this last thing now

buoyant finch
verbal dome
#

You were told many times to debug the input and other variables. Make sure they are what you expect them to be when certain keys are pressed

buoyant finch
verbal dome
#

Show the results and don't delete the debug.logs from your code when you show it

buoyant finch
astral falcon
#

First go away of chaining if statements like you do. Get your input, set the booleans correctly with that input and then assign your frames correctly.

fiery plume
#

im trying to make a walljumping script and it works. but if im holding the same direction of movement against the wall that im jump off. then it cancels the wall jump after 1 frame.

frigid sequoia
#

Am I dumb or this should be returning an error cause they are not the same thing???

buoyant finch
visual linden
frigid sequoia
#

Oh, no, never mind, I am fucking dumb indeed

cosmic dagger
#

Oh, chat just updated (for me) . . .

visual linden
cosmic dagger
buoyant finch
buoyant finch
compact stag
#

guys, need help with something

i got a couple of objects that i apply a variable called pointValue and i have the OnMouseDown function to destroy the game object i click in and add a point using a function from a singleton, however, i can't seem to understand how i'd make it so that the bad objects you can't click in doesn't subtract from your points? i've tried checking to see which was the tag of the object that activated the OnTriggerEnter function and it still made my player lose a point

#

not sure if i explained it correctly but i'll answer any questions

frigid sequoia
#

I am just feel I am superentangling a thing that should be supereasy

#

Just cause I am connecting so many scripts and I am not even sure why I am doing that

#

So my mind went totally Ploof

astral falcon
#

If you are not sure why you are doing something with your code, you def. gotta take a step back and write down your entire flow of data and method calls

frigid sequoia
#

Well, I know I have to split them cause else is gonna be a nightmare later, but not sure what I am gonna be adding later

lilac hemlock
#

Can someone help me please? My unit has a rigid body and a collider. My terrain has a terrain collider. Howeever, my unit goes through the terrain.

wintry quarry
frigid sequoia
#

Like rn, main issue is I have an EnemyAggro that should be telling who should this be focusing as a target, then I have the GeneralistAbilityManager, that tells with what should be using on that target (this should be a superclass and be different for each one later on, but rn, they only do the basicAttack). But the thing is, I need the NavMeshTargetSetter to have a target for the NavMeshAgent to tell it where should it be standing, which is not the same as where should it be focusing UNLESS they have no actual explicitly assigned Waypoint, then it's pretty much the same and it would try to stay at the point that need less movement and it's within range of whatever ability it's using....

#

This amount of abstracts references is kinda melting my mind....

buoyant finch
wintry quarry
#

that mens you're controlling the movement entirely through script
and that colliders are not going to stop it.

fiery plume
#

im trying to make a walljumping script and it works. but if im holding the same direction of movement against the wall that im jump off. then it cancels the wall jump after 1 frame. can someone help me fix this.

wintry quarry
#

If you want collision you'd need to be using a dynamic Rigidbody

#

(non kinematic)

#

,with a kinematic body you'll need to handle collision yourself with BoxCasts

lilac hemlock
#

okay, thanks, will research it

cosmic dagger
buoyant finch
verbal dome
ocean loom
#

Hey, just wondering, how could i add an audio proximity feature to my 2D game. So for example, when im near a game object, then a sound starts to play louder, and whenever i move away, its gets quieter and then silent

fiery plume
ocean loom
wintry quarry
#

while you are in the zone you would check the distance to the thing each frame

#

although now that we're discussing it

#

you don't need any of this really

#

as what you are describing is the built-in behavior of the AudioSource component

#

See how you can configure the volume falloff and everything

#

one thing you might still want a trigger for is if you want to specifically start the sound when the player gets to a certain distance.

charred spoke
#

Thats a spicy volume curve

#

What’s the use case I wonder ?

wintry quarry
#

Simulating a some kind of hyperbolic geometrically shaped room that has perfect resonance zones where the sound waves get reinforced perfectly?

#

idk lol

#

or sound in non-euclidean space?

charred spoke
#

Oh I thought it was from something you are making

wintry quarry
#

no it's the example screenshot from Unity docs lol

charred spoke
#

Kekl

wintry quarry
#

The use case is really "look you can do all kinds of crazy things with the AnimationCurve!"

charred spoke
#

Hey boss does this curve look ok to you

#

Lgtm ship it lad

ocean loom
fiery plume
#

im trying to make a walljumping script and it works. but if im holding the same direction of movement against the wall that im jump off. then it cancels the wall jump after 1 frame

ive tried debug.log on all the numbers in the calculation of the jump both when the jump fails and when it succeeds and the numbers are the same
i have it set currently in my fixed update that the player should only be allowed to move when im not walljumping through a boolean that activates as soon as i press jump while on a wall.

I am confused as to what is causing this.

fiery plume
#

152-196 should be the important part

astral falcon
#

Where does it cancel it?

fiery plume
#

if im pressing wall jump while holding in the same direction as the wall it doesnt cancel it entirely but instead of sending me away from the wall like its supposed to it just sends me straight up.

verbal dome
bitter apex
#

I'm trying to use OverlapSphere to detect if there is a GameObject where my cursor is hovering. all of the GameObjects in question have colliders, but it is not detecting any colliders

astral falcon
#

I do not see any debug.logs on the important parts. So you should check your if statements and be sure, your directino is correct and not in the wrong one so forces try to push you in that direction (against the wall) resulting in up pushes

verbal dome
#

directino
I read this in an italian accent

eternal falconBOT
bitter apex
#
        Vector3 cursorPosition = Input.mousePosition;
        LayerMask mask = LayerMask.GetMask("Default");
        Collider[] intersecting = Physics.OverlapSphere(cursorPosition, 0.01f, mask);
        Debug.Log(intersecting.Length);
        if (intersecting.Length != 0)
        {
            foreach (Collider thingToDestroy in intersecting)
            {
                float dist = Vector3.Distance(cursorPosition, thingToDestroy.transform.position);
                if (dist < 0.5f)
                {
                    Debug.Log("There is an object within 0.5 here");
                    Destroy(thingToDestroy);
                }
            }
        }```
It's only reaching the first Debug.Log() where intersecting.Length == 0.
fiery plume
astral falcon
fiery plume
bitter apex
#

the GameObjects are all in the same layer and stuff as well

astral falcon
bitter apex
#

that's my point, i'm logging the length and i'm getting 0, it doesn't seem to be colliding with anything

fiery plume
#

what i think is happening is that when i jump it decides to jump for 1 fram and then the input of movement happens after that somehow before its been told its not allowed to move and therefore cancels the horizontal movement aspect of the jump but not the vertical aspect. But i dont know why

bitter apex
#

or if it is, it's not in the array

#

which doesn't make sense

astral falcon
bitter apex
#

yes

astral falcon
bitter apex
#

the loop isn't running because it's not detecting any colliders, and i have no idea why

fiery plume
astral falcon
# bitter apex yes

do you check with some debug.draw spehres or lines that your position and radius are correct to hit somethign at all?

bitter apex
#

my game is 2d, could this be a problem?

I haven't tried that, I'll do that now, but i'm just checking if my cursor is hovering over a GameObject in a 2d plane

bitter apex
#

oh my

astral falcon
daring oasis
#

Hey i have a question what is damping and what are its uses? i keep seeing linear damping angular damping and i dont know what those are

fiery plume
ivory bobcat
daring oasis
bitter apex
astral falcon
#

and Collider2D does not inherit from Collider, so your check has to be right to return the correct array type

daring oasis
astral falcon
verbal dome
#

Using linearDamping is convenient in most situtations though

verbal dome
fiery plume
umbral siren
#

hey i have a quick question. how do you rotate an object around a point in the scene view?

verbal dome
#

When that timer is active, stop modifying movement velocity, or use AddForce if you want to mix the two

fiery plume
verbal dome
umbral siren
verbal dome
verbal dome
verbal dome
#

It's hard to follow the logic here

fiery plume
#

(if its set to 5 its a double jump if its 4 its wall jump etc)

verbal dome
#

if (IsWalledL() && !IsGrounded() && horizontal != 0f) this could be still true shortly after walljumping, right?

tribal wave
#

what does csharp do { insert block of code }

#

mean?

#

like what "do"

tribal wave
#

ty

verbal dome
#

It's like a while loop that executes at least once before it checks the condition

lilac hemlock
#

Can someone give an advice please. I am making an arcade racing multiplayer game (similar to Star Wars Episode I: Racer). Is it better to use unity physics system (non kinematic rigid body) with collision or code collision myself?

fiery plume
bitter apex
verbal dome
fiery plume
verbal dome
fiery plume
static stag
#

hey, does someone got a tip for me what term i should search to load tiles at runtime / game start ? My goal is to allow inserting new tiles and then use them in game. Maybe load a tsx file and then the png

naive pawn
#

why tsx?

static stag
#

just as example, i think its generated by Tiled

#

ofc after asking here

night mural
static stag
#

yea basically that 😄

night mural
#

basically you'd pick a place that you try to load user-tiles from and check there for any overrides

static stag
#

Resources.Load<TileBase>("Assets/Tiles/Sprites/" + tileSpriteName) i think thats the line i was looking for

#

so check for json files, parse them and then load the tiles based on json

night mural
#

I don't think these would be Resources since they're being included by your users, not as part of your build, right?

static stag
#

mhm true

daring oasis
#

what is a more begginer friendly way for an enemy to move twards the player without using pathfinding i tried watching a tutorial but all of that is way out of my league atm

night mural
daring oasis
#

yeah thats what i have now but that is the problem

#

it gets stuck

night mural
#

then you probably want some kind of pathfinding catshrug

#

anything else will end up pretty silly

#

you could try functioning how the robo-vacs without mapping do and bounce cleverly but unless your game is about fighting robo-vacs it's going to be weird

daring oasis
#

my game is just a square with a weapon that has to beat zombies and when the zombies spawn they have to fallow him

night mural
#

pathfinding with the nav mesh is about as simple as it gets so it's worth figuring that out

daring oasis
#

thanks i will try to undestand that

static stag
umbral siren
#

how do i make when the enemy dies, it will just drop and disappear while blinking in 3d

timber tide
#

We talking sprites?

#

ah I guess 3D is a give away, not that 2.5d sprites arent a thing

umbral siren
static stag
timber tide
ivory bobcat
#

Resource would imply it's in the resource folder, which users would not have access to? (a part of the build etc)
Perhaps you're wanting streamable assets or something.

static stag
#

found this

#

gonna try this

umbral siren
timber tide
umbral siren
timber tide
#

oh, if the animation is reseting then make sure your blend tree isn't exiting that animation when it completes

#

Both ways are fine, but the physics idea is more for like a ragdoll effect if you wanted that, otherwise if you can pinpoint where the problem may be in the animation. I can probably help otherwise #🏃┃animation is probably the place to post screen shots of the blend tree if that's the problem

brittle isle
#

Trying to wrap my head around Animal Buddies from DKC, to barely any success

#

I'm trying to implement rideable things in my platformer, akin to Yoshi and the Animal buddies from DKC.

#

The first idea was hopping on it and letting the player's script determine the basics of how it moves on land. but since so much of my movement script would be deactivated, i'm struggling to come up with a plan b

static stag
#

@night mural

public TileBase LoadTile(string path)
        {
            var fileData = File.ReadAllBytes(_basePath+"/Game/Data/Tiles/" + path);
            var tex = new Texture2D(2, 2);
            tex.LoadImage(fileData);
            var sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
            Tile tempTile = ScriptableObject.CreateInstance(typeof(Tile)) as Tile;
            tempTile.sprite = sprite;
            return tempTile;
        }

is working so far 😄 need some optimization but good to go for the moment

bright zodiac
#

us Path.Combine instead

quick pollen
#
        float pingpongValue = Mathf.PingPong(Time.time * rotationSpeed, anglesToCheck) - (anglesToCheck / 2);   
        cannon.transform.rotation = Quaternion.LookRotation(transform.forward * visionLength + (Vector3.forward * pingpongValue));```
#

so I have this code for making the enemy basically look left and right constantly

#

rotationSpeed, anglesToCheck and visionLength are set through the inspector, for the upcoming example
rotationSpeed is 30
anglesToCheck is 30
visionLength is 3

#

is there a better way to do this?

frosty hound
#

Do what, implementing it? If it works, then it works.

#

If you mean designing enemies, you can use SOs and define the properties on it, and use that instead.

quick pollen
#

which isn't intended

#

I just want it to rotate back and forth rotationSpeed degrees in an anglesToCheck cone

swift crag
#

transform.forward * visionLength also doesn't make sense

#

You should compute a rotation and then apply that to your original forward direction

#

e.g.

Quaternion.AngleAxis(pingpongValue, transform.up) * transform.forward;
quick pollen
swift crag
#

this rotates your original forward vector around your up vector

quick pollen
#

so if anglesToCheck is 30, pingpongValue is a number between [-15, 15]

swift crag
#

yes, I understand that -- the resulting math still makes no sense

#

you are adding together two vectors and then using the resulting direction to compute a rotation

quick pollen
#

don't you need a Quaternion for AngleAxis?

swift crag
#

no, it computes a Quaternion from an angle and an axis

#

hence the name

#

I presume that the turret rotates around the tank's up vector

quick pollen
#

well uhh

swift crag
#

alternatively, you can combine that angleaxis rotation with another rotation

quick pollen
#

oh, wait

swift crag
#
cannon.transform.forward = Quaternion.AngleAxis(pingpongValue, transform.up) * transform.forward;
cannon.transform.rotation = Quaternion.AngleAxis(pingpongValue, transform.up) * transform.rotation;
#

Both of these would work.

quick pollen
#

i completely forgot about the fact that transform.forward can be set .-.

quick pollen
swift crag
#

Personally, I would go with the second one. That will make sure the turret is rolled correctly

quick pollen
#

I feel silly that I've been using quaternions and such for so long and I still struggle with simple up and down movements :/

swift crag
#

there's less information in a direction than there is in a whole rotation

quick pollen
true owl
#

so i've followed this logic where I've created 2 triggers for each side of the character to determine what wall they're touching

using UnityEngine;

public class WallJump : MonoBehaviour
{

    Rigidbody2D parentRb;
    bool isTouchingWall = false;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        parentRb = transform.parent.GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        /* while touching wall, if holding a direction opposite to the current object
            then start wall slide logic
            */



    }

    void OnCollisionEnter2D(Collision other)
    {
        isTouchingWall = true;
    }

    void OnCollisionExit2D(Collision other)
    {
        isTouchingWall = false;
    }
}

#

now i'm confused if I'm gonna apply this script to both of the child objects how would i know which one i'm currently on

#

or would i need to make 2 separate scripts?

quick pollen
true owl
#

i meant like

quick pollen
#

is that the question?

true owl
#

i have 2 triggers on each side

#

i'm not sure if i use that script how would i know which trigger i'm using

#

my structure is a parent object with 2 separate game objects as children and each has a trigger

#

one for left and one for right

quick pollen
#

to be fair

#

you could use some super mario bros logic

true owl
#

wym

quick pollen
#

would there be any way for the character to be touching a wall on the left, if the character is moving toward the right?

true owl
#

i guess

#

that's true

verbal dome
quick pollen
#

if the velocity is facing the left, you are touching a wall on your left

true owl
#

well no

quick pollen
#

if the velocity is facing the right, you are touching a wall on the right

true owl
#

i want the logic to be the wall slide

#

oh wait

#

i see what ur saying

quick pollen
#

this works with the wall slide

#

basically

#

if you are going left

#

you are touching a wall's right side

true owl
#

that makes sense

quick pollen
#

and vice versa

verbal dome
#

I dont think velocity is reliable since you might have already collided with the wall and bounced back

#

Or stopped

verbal dome
quick pollen
true owl
verbal dome
#

Another common way is to do physics queries like OverlapBox/OverlapCircle

true owl
#

how would i differentiate which trigger is the one that actually is it

quick pollen
quick pollen
true owl
rocky canyon
#

overlapbox's and spheres are solid for the purpose

#

Circles rather

quick pollen
#

also yeah, circles are generally nicer

rocky canyon
#

can u use layermasks w/ those? im pretty sure u can..

quick pollen
#

you can, yeah

rocky canyon
#

id just mask out my player and have 1 on each side

quick pollen
#

so you can make a layermask which only collides with walls

#

so you cant walljump/wallslide off of, say, enemies

true owl
#

i've set up my layers properly with a wall layer

#

so that won't be happening

quick pollen
#

basically

      Wallslide Right
  else if (OverlapCircleOnLeft == wall)
      Wallslide left```
#

this isnt how OverlapCircle works ofc

#

it just returns to you an array of colliders

#

you can look through that array and see if there are any walls in there

true owl
#

i'm confused so overlap circle is added to every single wall in the game and it checks if the player is currently colliding with it?

quick pollen
#

basically

#

you draw a circle around the player

#

or, in this case, on the left and on the right of the player

#

and if the circle overlaps with a wall, then use wallsliding logic

#

there are other ways of doing this wallsliding too, now that I think about it

#

but I won't confuse you any more

true owl
#

I'm sorry if I'm not understanding but isn't this basically the same as the triggers? I set up one on each side and if it overlaps I do the wallslide logic

quick pollen
#

OverlapCircle returns an array of Colliders that are inside of it's radius

true owl
#

oh interesting

verbal dome
quick pollen
#

you just need to check if any of the colliders is a wall

verbal dome
#

Similiar to raycast if you are familiar with that

quick pollen
true owl
#

oh wow

quick pollen
#

basically imagine it for like guns

true owl
#

ah so you shoot the bullet and see if it hit anything

rocky canyon
#

hit-scan vs rigidbody projectiles

quick pollen
rocky canyon
#

well it draws a ray a direction * distance... and returns true or false.. if true u can dig deeper and get the RaycastHit variable back from it

#

w/ all the info on the hit, position, what it was etc

true owl
#

intereting

#

well I think i'll look into it deeper when I need to

rocky canyon
#

just remember theres 2 variants..

quick pollen
#

personally I use raycasts in my game

rocky canyon
#

theres Raycast.. and Raycast2D

true owl
#

for now I might just stick with the triggers i have cause I think the OverlapCircle might be overkill

quick pollen
#

those green lines

true owl
#

interesting

quick pollen
#

I basically check if the rays ever touch the player

#

in which case I make the enemy attack

true owl
#

smart

quick pollen
#

actually, @rocky canyon, is overlapsphere or a raycastcommand more efficient?

naive pawn
#

why not just reference the player and check the distance?

#
  • a raycast to check line of sight
quick pollen
quick pollen
#

I dunno, I've seen this method used way more

#

plus it was a nice way for me to learn about jobs and raycastcommands

rocky canyon
#

but i think u could also make overlaps pretty close.. using the Non-Alloc version

quick pollen
rocky canyon
#

and having a pre-existing array or something to hold the contacts

#

or w/e

quick pollen
#

you use raycastcommands for cones of vision

#

but for me it doesnt make much sense to use raycastcommands because I check in a circle

rocky canyon
#

ya totally.. use w/e u feel comfortable with

quick pollen
#

I guess theres the option for me to use cones of vision at any point tho

frigid sequoia
#

This should be executing or am I doing something wrong?

quick pollen
#

I like the way I made my enemy AI code because everything is customizable

naive pawn
quick pollen
#

searching, chasing, dodging, firing

#

@true owl the topic got a bit off track, I hope u understand what u need to do

#

if u need further specifications, just ask :)

true owl
#

yeah i got it, i'm using the circle overlaps

#

much appreciated

frigid sequoia
#

Oh, okay, I know what I am doing wrong

quick pollen
#

good call on this actually Chris, ty!

frigid sequoia
#

How do I... get a list of all child gameObjects that contain a specific script?

polar acorn
#

Note that this also includes the object itself, if that object has the script on it

rocky canyon
#

i like the way it makes those cool grid/wavy scanlines

frigid sequoia
rocky canyon
#

(s) makes me believe its a collection of some sort yes

naive pawn
quick pollen
frigid sequoia
#

Mmmmm.... I was setting everything with Lists....

rocky canyon
#
using UnityEngine;
public class GetComponentsInChildrenExample : MonoBehaviour
{
    public Component[] hingeJoints;
    void Start()
    {
        hingeJoints = GetComponentsInChildren<HingeJoint>();
        foreach (HingeJoint joint in hingeJoints)
            joint.useSpring = false;
    }
}```
quick pollen
#

its funny because I could have like 50 tanks using 100 raycasts every frame and I still wouldn't have much performance issues

naive pawn
rocky canyon
#

every (x) amount of seconds it fires off a ray

quick pollen
#

and if I do, I can just reduce the amount of checks per second

quick pollen
#

tho thats still scary cuz of lag spikes

rocky canyon
#

its a "Thinking Rate" for my enemies

#

a bit of delay makes it feel organic..

quick pollen
#

so I also have a function to smear the calculations out over x seconds

#

so I dont have 30 checks happening in one frame, rather over x amount of frames

quick pollen
naive pawn
#

not really, there's built-in functions for it

naive pawn
#

fuckin flashbang, dude

rocky canyon
timber tide
#

who needs overlap sphere when you got overlap lattice

quick pollen
#

overlap world

rocky canyon
#

now draw a wiresphere everywhere two rays intersect 😉

quick pollen
rocky canyon
#

u'd need some custom maths

quick pollen
#

also, this is just my debug rays being fucked

#

I'm trying to fix the angle, but i cant

frigid sequoia
rocky canyon
rocky canyon
#

but that i dont know tbh

naive pawn
#

not sure if that still holds over multiple gameobjects though

rocky canyon
#

ya ^ thas what i was thinkin

#

do a few tests and let us know

quick pollen
#

it starts checking from transform.forward, but I want it to check from transform.forward - (scanAngle/2)

#

basically rotate the cone (scanAngle/2) degrees

#

im just way too cooked mentally to do quaternion maths rn

frigid sequoia
#

Like the ListOfEntities is supposed to store the reference to each entity present, so basically has a list for Enemies, Players and Waypoints, and I want the script for it to take each of the parent GameObjects and take the script of each of the entities inside them, since, basically all of them have the script I am looking for

left sail
#

hello, I would like to understand why I have a capsule even though I never asked for it

rocky canyon
#

do u have a CharacterController?

naive pawn
rocky canyon
# quick pollen

the ship gif i sent i have my raycasts start by using spacing between the rays and the number of rays i want.. and then it auto-centers..

left sail
rocky canyon
#

not sure the code i use to do that.. but when i find it ill ping u

#

yes. u

left sail
quick pollen
rocky canyon
#

yea... thats why

naive pawn
rocky canyon
#

a CharacterController has a capsule collider built in..

naive pawn
polar acorn
rocky canyon
#

yea there ya go ^

left sail
#

ah ok so how do I remove the capsule?

rocky canyon
#

remove the Character Controller?

quick pollen
rocky canyon
#

u can't have a character controller w/o a capsule collider.. like digiholic said..

#

its one of the same

#

if u dont wanna see the gizmo. just collapse the Component

naive pawn
rich ice
polar acorn
quick pollen
polar acorn
#

Chances are you need that though

left sail
#

well basically I want it to be the same size as the human

quick pollen
rocky canyon
#

ezpz lol

polar acorn
rocky canyon
#

or position the graphics (ur model) to be centered to the capsule (as it is)..

#

b/c it'll start properly centered

left sail
#

I see what I can do

rocky canyon
#

2 unity units = 6 foot 5 inches

rocky canyon
#

nah, my rooms already warm enough 😛

rocky canyon
#

awesome.. mines a singleton "TickManager" i call events from.. then first the ray off b/c its listening

quick pollen
rocky canyon
#

same concept

left sail
#

thank you (I'm a beginner, that's why I'm struggling)

rocky canyon
rocky canyon
quick pollen
#

probably more efficient than my method

verbal dome
#

You realize most of these rays are useless, if this is for vision

#

Normally you'd do an angle check to see if the target is in the view cone, and if it is, cast a ray to check for obstructions

quick pollen
timber tide
#

pretty tho

quick pollen
#

I mainly did this to learn about raycasts

#

also, I see a lot of people do it this way, even though your method makes way more sense

timber tide
#

I usually do like sphere then calculate angle then raycast for obstruction

quick pollen
#

so no need for spheres

timber tide
#

yeah true

knotty quail
#

I have a character, what is better to use, aggregation or composition?
Why is everything so easy and difficult at the same time?

burnt vapor
#

In the end it's a combination of all of them

icy sluice
#

is Time.deltaTime supposed to increese?

polar acorn
icy sluice
#

tnx, so im the one wrong and not unity to blame

timber tide
echo kite
#

whats difference between private void update and void update

timber tide
#

nothing just you dont need to type it (but I do anyway)

burnt vapor
#

So nothing

naive pawn
burnt vapor
#

access modifier, yes

#

accessor is something else, oops

polar acorn
#

You shouldn't

swift crag
#

yeah, you can't find the "other" collider in a trigger message

#

You'll want to put them on separate game objects

polar acorn
#

Multiple colliders of the same type on the same object should basically be considered the same. If they do anything different, they need to be on different objects

slender nymph
#

seems like a usecase for physics queries rather than individual colliders

#

why

polar acorn
#

How it works:
The Rigidbody involved in the collision will detect when it collides with a collider. It will then call OnTrigger on every component on itself, then every component on the object with the collider it hit.

So, you'd need a script on each thing with the collider on it that handles its own case

#

Yes. Assuming the rigidbody is the one moving into these, rather than these being children of the rigidbody that moves

slender nymph
#

i'm pretty sure trigger messages are sent to the object with the trigger collider on it if they are a child of a rigidbody

swift crag
rocky canyon
#

u can't really do that.. and single out individual colliders

slender nymph
#

but this still 100% seems like a usecase for physics queries rather than relying on trigger messages. of course they won't say why they want to use physics messages

swift crag
#

It's one or the other

slender nymph
polar acorn
#

If you just need to detect when you stop colliding with something you can just run the physics query in update and see when it returns a different result

rocky canyon
#

i always build a simple test script when dealing with these type issues..
by testing out the messages w/ multiple objects and different hierachy setups it can really solidify understanding how they interact

slender nymph
#

for what purpose

polar acorn
#

Maybe? Unsure what you specifically need

rocky canyon
#

ya, lets hear the use-case for this

slender nymph
#

please explain what you are actually trying to accomplish

#

and i don't mean some vague abstract description of what you think you want, explain what you are actually trying to do with this
https://xyproblem.info

rocky canyon
#

I want to: ___ for the reason of: ___ would be most helpful

#

oh lord..

polar acorn
#

If you literally just want to know what objects are within range once per frame, OverlapSphere

swift crag
#

It sounds like they're detecting when an interactable object gets in range.

rocky canyon
swift crag
#

It does sound reasonable to just use trigger messages to notice when they enter and exit your interaction range

#

these are implementation details; you need to explain the actual gameplay you are creating

#

note that if you only react to the OnTriggerEnter/OnTriggerExit messages, you'll need to keep a list of interactable objects that are currently in range

#

six of one, half a dozen of the other (:

polar acorn
#

Okay, so if you want to know if the player is within range of the interactable, why not put the larger trigger collider on the interactable, and have them check if they're within range of the player?

#

You can still use a normal collider to detect when you collide with the object directly

rocky canyon
#

i think i remember now.. were u asking about the WorldSpace UI the other day for pickups?

polar acorn
#

Decentralized is kind of the goal though

swift crag
#

uh oh

polar acorn
#

Each thing should take care of its own functionality

#

Then you can do that, probably with OverlapSphere

swift crag
#

oh, okay, not the worst: but I would rather use a Dictionary<Interactable, InteractionPrompt>. you'd have an Interactable component that represents a thing you can interact with, and you'd have an InteractionPrompt component that handles showing the name, image, etc. for an Interactable

frigid sequoia
#

Ok, I am freaking becoming crazy, this says that those Lists are never read. They are supposed to get a copy of the data of another script (ListOfEntities) and this one does show to gather the List data properly, but then, when passing it, it's empty? What am I doing wrong? I don't get it

polar acorn
#

Then you can do that, by putting scripts on the interactable objects

eternal falconBOT
polar acorn
#

There are no "checks" happening

#

That's not how colliders work

frigid sequoia
swift crag
#

please share a paste of the entire script, rather than a screenshot of most of it

swift crag
polar acorn
# frigid sequoia

Pretty sure the = new List< stuff is gonna get run on Start since it's in the constructors, even though those are serialized fields? Try removing them

swift crag
#

I see no reason to do this!

#

Make small components. Put them where they're needed.

polar acorn
polar acorn
#

The more scripts you have, the better

rocky canyon
#

SingleResponsibilityOLID

frigid sequoia
polar acorn
frigid sequoia
#

Cause the List I get from that ListOfEntities is actually accurate

polar acorn
#

Put logs in your Get___ functions where you clear the lists, see if they find anything

frigid sequoia
#

It's just not passing it correctly and I don't know why

swift crag
#

Is the problem that these lists are empty after starting the game, when you expected them to be non-empty?

frigid sequoia
swift crag
#

Do you have more than one "List Of Entities" component?

frigid sequoia
#

Nope

polar acorn
#

Oh wait, these are different components, just with variables of the same name?

frigid sequoia
#

The whole reason to have that is so I don't have to create a whole List anew for each entity, so it only happens one isntead

swift crag
polar acorn
#

If the purpose of these variables on NavMeshTargetSetter is to always reflect the values in ListOfEntities, why not just cut out the middleman and use the lists from ListOfEntities?

swift crag
#

As I said: Make small components and put them where they're needed.

You'll create an InteractableDetector component on "Collider Interact". Its sole job will be to tell a component on the Player when things go in and out of range

noble forum
#

Hi, my card game object is being destoyed on play, but i have no idea why. How can i see what destroys it?

swift crag
#

then look at the stack trace for that log entry

#

That will give you a hint, at least

frigid sequoia
#

It's weird

#

Cause the Waypoints do pass correctly

swift crag
#

The latter is a way to achieve the former.

polar acorn
frigid sequoia
#

They just have a variable for that

#

So I can tell if they are passed correctly

swift crag
#

did you verify that any of your code is actually running

swift crag
polar acorn
noble forum
# swift crag You can log something in `OnDestroy`
    System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace();
    string scriptName = "Unknown Script";

    if (stackTrace.FrameCount > 1) {
        var frame = stackTrace.GetFrame(1);    var method = frame.GetMethod();
        scriptName = $"{method.DeclaringType?.Name}.{method.Name}";
    }

    Debug.Log($"{gameObject.name} was destroyed by {scriptName}!");
}```
i tried something like that, it was destroyed by uknown script
#

Any other way?

swift crag
# frigid sequoia

I may know what's going on here.

You're sharing a reference to the same list that ListOfEntities is holding

#

But Unity's serializer doesn't really care about that.

#

I actually don't know how it handles that situation...

polar acorn
swift crag
#

It's meant to find the type name of the method

#

but yes, just look at the stack trace :p

#

Note that there won't be much of interest if it's a delayed Destroy call

frigid sequoia
tribal wave
#

im very new, is there a way to tell if a gameobject has moved up by like 5? Like if it goes up by 5 then itll do something

frigid sequoia
polar acorn
#

Have a single source of truth. Use that.

#

Don't copy a bunch of data around and just hope you kept track properly

swift crag
#

oh, yes, I see your ordering problem

#

this creates a new list

#

NavMeshTargetSetter is holding a reference to the original list

#

which was cleared and then thrown out

swift crag
#

Anyone that grabs possibleEnemyTargets before ListOfEntities.Start() executes will wind up with references to the original list object

frigid sequoia
#

Should not cause an issue later

swift crag
#

well, yes, but it's too late

#

the issue has already been caused!

frigid sequoia
#

So are u saying this is sending the List AFTER the clear, but before refreshing it??????

swift crag
#

No.

#
List<int> foo = new();
List<int> bar = foo;
foo = new();
foo.Add(1);
#

bar contains a reference to an empty list.

polar acorn
#

You know what could solve this?

Just not having two lists

swift crag
#

NavMeshTargetSetter is having its Start method called before ListOfEntities.

#

Therefore, it is getting a reference to the list that ListOfEntities starts out with.

#

ListOfEntities throws this list out and creates a new one.

polar acorn
#

You have a reference to the listOfEntities. Just do listOfEntities.possibleEnemyTargets

frigid sequoia
swift crag
#

you just clear it and then add things to it again

frigid sequoia
#

So why would that be different than replacing it for a new one?

swift crag
#

because it's the same list

swift crag
#

as compared to this example

#
List<int> foo = new();
List<int> bar = foo;
foo.Clear();
foo.Add(1);
polar acorn
swift crag
#

where both foo and bar contain a reference to a list with a single number in it

noble forum
quick pollen
#

lmao

frigid sequoia
#

Am I doing that?

#

I may

polar acorn
#

yes

swift crag
#

You're doing both.

polar acorn
#

Which is why you shouldn't have a second variable that is meant to hold the same data

swift crag
#

In some places, you are creating an entirely new list. In other places, you are inserting items into the original list.

#

If you want to add a bunch of things to an existing list, use AddRange

#

But yes: I see no reason to add this layer of indirection

noble forum
#
  at Draw.OnDestroy () [0x0003f] in E:\Tarot Chess — kopia\Assets\Scripts\Cards\Draw.cs:38 ```
verbal dome
#

That's line 38

#

Or wait what's the issue

noble forum
#

It is so confusing... I mean i just play a card and it seems to be deleted when it was supposed to change parent

quick pollen
#

how do you change parent?

noble forum
#
   {
       if (playedCard != null)
       {
           // Transport the card to the graveyard
           MoveCardToGraveyard(playedCard);
       }
       else
       {
           Debug.LogWarning("Played card is null.");
       }
   }

   private void MoveCardToGraveyard(Transform card)
   {
       if (graveyard.Contains(card))
       {
           Debug.LogWarning($"Card {card.name} is in graveyard.");
           return;
       }

       card.SetParent(graveyardObject.transform, false);
       card.gameObject.SetActive(false);
       graveyard.Add(card);

       Debug.Log($"Card {card.name} moved to graveyard.");
   }```
quick pollen
#

are you sure that the issue is that it gets destroyed, not that it gets deactivated?

#

thats my best bet

#

also, not entirely sure, but you might want to move the object to the graveyard before disabling it

#

waitt

noble forum
quick pollen
#

card.SetParent(graveyardObject.transform, false);

frigid sequoia
#

But ya

quick pollen
rocky canyon
#

https://paste.myst.rs/uta0c8xz
something simple like this might get the job done..
u'd need a bit extra logic ofc.. (for example having two interactables close enough that the script would trigger twice)
but the basics are there..

To interact w/ a script you only need a reference to said script.. and public variables and/or public methods

quick pollen
noble forum
quick pollen
#

where your objects are

rocky canyon
#

im not involved in w/e u guys conversation is.. i was talkin to Vengeful

#

the objects im interacting w/ are these if u were askin about me lol

quick pollen
rocky canyon
#

OHH okay i see

quick pollen
#

u just happened to post a vid with the hierarchy xd

#

my bad for the confusion

rocky canyon
#

here ya go lol

quick pollen
#

yeaa ty xD

noble forum
#

Here you go, but thanks to this i looked at it again and it seems there is something that may be the culprit, but im not sure.

#
using UnityEngine;

namespace demo {
    public class CardDestroyer : MonoBehaviour {
        public CardContainer container;
        public void OnCardDestroyed(CardPlayed evt) {
            container.DestroyCard(evt.card);
        }
    }
}
quick pollen
#

"my cards are being destroyed without me wanting them to"
hierarchy shows Card Destroyer

quick pollen
rocky canyon
#

time to debug 🙂

quick pollen
#

try to log it every time it gets called

rocky canyon
#

or referencing in general.. may want to check it out as well

noble forum
#

Ok, it all is mega weird. I disabled the shit out of this, and now ill implement correct changes in other scripts. Thanks

daring oasis
#
[SerializeField] Camera mainCamera;

When i try to attach my camera it says type missmatch

#

Why is this happening?

grand snow
#

e.g. a monobehaviour called Camera

slender nymph
daring oasis
#

in the Hierarchy?

slender nymph
#

in your ide
where ide means "Integrated Development Environment" and refers to your code editor

daring oasis
#

oh wait

#

sorry

#

in the code when i hover over camera its of class Camera

grand snow
#

you want to see

#

When it says Type missmatch in the inspector its cus you changed the type of the field and the old value is still in there but invalid.

slender nymph
#

it will also say Type Mismatch if you try to drag something that doesn't have the correct component or if you try to drag a scene object into a prefab

grand snow
#

doesn't it just not do anything?

daring oasis
slender nymph
#

there were two things i said that it could be, if you have determined it is not one of those then it must be the other

daring oasis
#

well i sent an image with my camera object wich has a Camera Component

slender nymph
#

and did you do what rob5300 suggested and confirm that you are using UnityEngine.Camera and not perhaps some other Camera class, like one you may have created?

daring oasis
slender nymph
#

and have you created your own class called Camera?

daring oasis
#

pffffff right.... the script is called Camera so its the class

slender nymph
#

yeah so that would be the problem. don't name your components the same as other components and there won't be any issues like this

daring oasis
#

Thanks the problem is now solved

grand snow
#

thats why i suggested checking in ur ide to see. You can also declare the type with the namespace in it to make extra sure:

[SerializeField]
UnityEngine.Camera cam;
true owl
#

Not sure why but when my character jumps they don't have a parabola, they lose a lot of their speed after the peak of their jump

#

even after I comment out AirModifier and JumpModifier

daring oasis
rocky canyon
#
void Run()
{
    if (isDashing || !isGrounded) return;``` wonder what happens if u were to return out of the run method if ur not dashin or airbourne
true owl
#

wait what

#

you mean the applyMomentum?

#

wait

#

that is ancient code

#

sorry

#

idk why it got my old code

#

this is the new thing sorry

quick pollen
#

it just wont execute anything

daring oasis
#

if i want to make some sort of 2D camera movement like to to slowly move twards the cursor do i need to assign to my camera a rigidbody to use forces? or is there another way

rocky canyon
#

ya, when jumping or dashin it wont.. but i think his problem is b/c the Run() method is using input to manually override linearVelocity during his jumps

#

then causing it to not have a perfect parabola

true owl
#

@rocky canyon

#

that is old code i pasted the wrong thing

rocky canyon
#

oh alrighty

true owl
#

ya sorry

rocky canyon
#

u got plenty of variables to work with..

#

i think u could remedy it by fine-tuning the values

#

especially since it appears u have gravity modifier before and after the peak of the jump

#

i remember making mine.. and i had to iterate many many times to get everything working correctly together..

#

by changing the drag, friction (air resistence in my case), and my control multipliers i was able to get a decent feeling controller
(carries momentum and all that jazz)

#

but its basically running in different states..
is it grounded -> use all these values
is it airborne -> use all these values instead

true owl
rocky canyon
#

you have heck of alot of code there..
without having it 1:1 on my machine i can't assume how everything works with everything else..
if it was anything like mine.. theres alot of little things working together.. and against each other at various times..
ur the only one thats gonna have a good feel for what alls going on lol

true owl
#

yeah that's true

#

i guess i'll need to take a bit more time to look at it

rocky canyon
#

best of luck mate.. i'll come back around to it and check if i can't see something but right now nothing stands out at me

true owl
#

gotcha much appreciated

rocky canyon
#

heres a snippet of mine.. and u can see theres tons of comments telling me.. (remove this force if this..) (make sure to add this force if this) etc etc

rocky canyon
#

i've also used gizmo's and stuff to draw out the trajectory to test

true owl
#

interesting

#

i appreciate all the helkp

#

i've been coding for a bit now so I'll take a break and get back to it later maybe

rocky canyon
#

just noticed mine still isn't perfect lol

daring oasis
#

If im comparing 2 vector2 vectors being a velocityVector and Vector2.zero does it compare the values , the magnitude or the vector instance?

swift crag
#

Vector2 is a value type, so it would be very hard to do a reference comparison 😉

rocky canyon
#

and just to help speed-run the issue...
i'd try testing w/o movement at all.. should be able to Jump in place and then maybe take a recording.. or even write some code to log numbers and values.. to make sure the RISE of the player is = to the FALL of the player

daring oasis
#

Oh ok thanks i will just compare their magnitudes so im sure i get what i want

swift crag
#

Compare the magnitude of their difference against a small value.

#

(that's what the == function is, but you might as well pick a specific threshold)

grand snow
heady crown
#

New to unity 😄 whatsup everyone 😄

grand snow
#

ofc if you want a "bigger" threshold then you should do it yourself

swift crag
#

notably, operator == for Vector2 uses a much larger threshold!

delicate drum
#

Hi, is there any repository GitHub, YT Video, or something else to understand, how is it possible to code an inventory system in Unity with Drag&Drop?

#

If there are different ways of that, I'd like to read all of them. 😄

pulsar forum
crisp moon
#

What are some good short and brief youtube tutorials for unity that are great for a beginner to watch?

frosty hound
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

rich ice
crisp moon
rich ice
delicate drum
kind spoke
#

hello everyone. Is this the right channel to ask for coding help?

rich ice
eternal falconBOT
acoustic belfry
#

hey, whats the difference between update and fixedupdate?

rocky canyon
rocky canyon
acoustic belfry
#

oh

#

i mean cuz im having some issues in the animations and i thought was due using fixedupdate

#

what would happen if i replace fixedupdate with update?

slender nymph
#

it depends entirely on what you are doing in FixedUpdate and what your actual issue is

rocky canyon
#

it'd run every frame.. as opposed to each physics tick..

acoustic belfry
#

oh, interesting

#

well, the issue i have is the animation is glitched

#

like is overlapping

acoustic belfry
#

and i think i did something wrong in the script

#

cuz i did the same in the other npcs

#

and they work right

#

this is an example of the code

#
{
    rb2D.linearVelocity = new Vector2(runSpeed, rb2D.linearVelocity.y);
    animator.Play("Base Layer.valeria_walk");
}
else if (Input.GetKey("a") || Input.GetKey("left"))
{
    rb2D.linearVelocity = new Vector2(-runSpeed, rb2D.linearVelocity.y);
    animator.Play("Base Layer.valeria_walk");
}
else
{
    rb2D.linearVelocity = new Vector2(0, rb2D.linearVelocity.y);
    animator.Play("Base Layer.valeria_idle");
}```
#

i dont know what im doing wrong

slender nymph
kind spoke
#

!ask

acoustic belfry
eternal falconBOT
acoustic belfry
#

ignore the message

slender nymph
rich ice
eternal falconBOT
kind spoke
acoustic belfry
#

btw is there an "example" for a 2d player? i mean cuz i feel like my player script could be more simplier

rocky canyon
rich ice
eternal falconBOT
#

:teacher: Unity Learn ↗

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

slender nymph
acoustic belfry
#

the issue here is, i did the same with my Npcs

#

they worked as a charm

#

what went wrong?

rocky canyon
#

but it could also be transition problems

acoustic belfry
rocky canyon
#

where ur starting the animation over and over and over w/o it ever finishing

acoustic belfry
#

wich shouldn't be

#

cuz the idle animation has a single frame

rocky canyon
#

is it set to looping?

acoustic belfry
#

huh?

#

i think, no

#

cuz i havent add that

#

i just made up the animations

rocky canyon
#

LoopTime

acoustic belfry
#

ah yes

#

they are looped

rocky canyon
#

if its a single keyframe.. im pretty sure it should be set to looping

#

ah ok.. just checkin

acoustic belfry
#

but its still animated even when idle

#

wich is...odd, obviously

#

you're kidding me. I dont know why, and i dont know how, but...its fixed

#

ah no

#

nvm i know why, and its not pretty

#

i have a script that detects if the player is in ground, if is, it will display an idle animation, if is not, it will display a falling animation...I need that script

#

this is the script, what i did wrong?

        {
            animator.Play("Base Layer.valeria_idle");
        }

        if (CheckGround.IsGrounded == true)
        {
            animator.Play("Base Layer.valeria_jump");
        }```
slender nymph
#

you should learn how to use the animator so you can properly transition between your animations based on different conditions instead of hardcoding which animation to play

kind spoke
#

hello. I too am having a problem with the unity....
I made a script to detect when i click an object based on raycasting (this works no issues)
problem lies that i assigned a variable in the inspector and unity is telling me that the field is null 😦

slender nymph
#

there's probably another instance of that object in the scene at runtime where the variable is not assigned