#💻┃code-beginner

1 messages · Page 70 of 1

short hazel
#

Google will have an answer, most likely

sour terrace
#

Is there a way to use integers as degrees instead of radians in Mathf.Sin?

spiral narwhal
#

I see, in that case I'll just use an overlay space, that's easier to change imo

#

Thanks for the help

sour terrace
young warren
# sour terrace For example if I have an int Angle = 90 I want to be able to calculate a Mathf....
gaunt ice
#

Mathf.deg2Rad

short hazel
#

Multiply angles with these to convert

young warren
#

and this

sour terrace
#

hmm now it seems to work correctly, except for 180 degrees for some reason

#

the Mathf.Deg2Rad converts it correctly to 3.14159

#

but then it returns some weird value when I get the sine of that

#

-8.742278E-08

#

I have no idea how that even happens

short hazel
#

Very close to zero that number is

#

It's scientific notation

#

-0.0000000874 or something

sour terrace
#

yeah, eight decimal points

#

is it just a floating point error?

short hazel
#

Yeah

sour terrace
#

ah alright I'll just round it to zero then

wintry quarry
verbal dome
short hazel
#

Yeah I started writing this, realized the sentence was going to be backwards, but finished it anyway

topaz mortar
#
Instantiate(blood, this.transform.position + bloodOffset, Quaternion.identity, this.transform);```
I'm instantiating a particle here
I want the particle to follow "this"
but I do not want it to rotate with it
Is there any way to lock the rotation?
young warren
topaz mortar
#

any other/easier way?

young warren
wintry quarry
topaz mortar
#

the object it's attached to is a prefab

#

anyway I figured it out, you can just set the simulation space to world instead of local

verbal dome
#

That doesnt make the particles follow you but it makes the emitter follow you

topaz mortar
#

yeah that's what I meant/wanted

wintry quarry
#

That's a totally different thing than you asked for though

topaz mortar
#

yeah I meant particle system instead of particle, my bad lol

#

the semantics get confusing sometimes

nimble sorrel
#

if the ghost (green) is moving towards the player (black), how would I have it go around the circle collider (which is currently a trigger, I might be able to convert it to a normal collider? though that'll require wrangling other aspects of the ghost's behavior) at a consistent speed. so far I've set up a system that when it enters, I push it directly out of the collider - though this results in heavily varied speeds as it moves around the circle. I'm halfway through setting up some rather convoluted equations using a cord of the circle with length calculated by the ghosts speed and heavy wrangling of the internal angles. but I feel like there's got to be a better way than this

#

typically the ghost's behavior is to move directly in the direction of the player (using movetowards)

solid verge
#

how to build an android game

gaunt ice
#

open build settings switch to android

solid verge
#

cause i get so many errors

#

ok switching

#

what now?

gaunt ice
#

try to build it and wait

topaz mortar
novel shoal
#

@summer stump i did the course

#

i did 23 out of 25

thin blade
#

Hi everyone I have a question. Do you know how I can get the X Y Z rotation of an object because when I use eulerAngles for the rotation 180,0,0 i get in console 0,180,180. Do you have a way to fix it ?

keen dew
#

There's nothing to fix. Those are the same rotation.

nimble sorrel
#

not too familiar with eulerAngles but would transform.rotation not work?

keen dew
#

that's a quaternion

thin blade
#

Yes i don't understand quaternion that why i don't use it

nimble sorrel
#

a lot of time with stuff you don't understand it's way better in the long run to just push through and learn it, rather than going against the flow by avoiding it. Quaternions are definitely an example of this.

thin blade
#

okay i gonna follow your advice

nimble sorrel
#

there are lots of resources online for quaternions, one that immediately comes to mind was a GDC talk from either last year or the year before that

verbal dome
#

You don't really need a deep understanding of quaternions at all

#

Just understand that they are rotations and learn to use the helper methods (AngleAxis, LookRotation, FromToRotation etc)

nimble sorrel
#

turns out the talk I was thinking of just has the slides available for free, rather than the full talk. but they can still be helpful
https://www.gdcvault.com/play/1027047/Math-In-Game-Development-Summit

wintry quarry
#

It's really not needed to understand the underlying math

thin blade
#

thank you very much to allcare

summer stump
weary moss
#

when visualstudio says a line of code is obsolete, does it means it's less efficient?

wintry quarry
weary moss
#

what

wintry quarry
#

Developers usually do this to indicate there's a newer better thing you should be using instead

weary moss
#

like, enough people said its obsolete so the program thinks it is

wintry quarry
#

No

weary moss
#

oh alright

wintry quarry
#

Code is not a democracy lol

weary moss
#

alright thanks

merry spade
#
using Microsoft.Unity.VisualStudio.Editor;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DeadTimerUIScript : MonoBehaviour
{
    [SerializeField] private Image reviveTimer;
    void Start()
    {
        
    }

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

SerializeField is not in the inspector

verbal dome
languid spire
#

Compile error

slender nymph
#

wrong Image type. you should be using UnityEngine.UI.Image

merry spade
#

ok wait

#

yeah now it works

#

nice thank you

novel shoal
#

now i know classes, enums, and that stuff

quick ruin
#

Hi trying to get something to blink black and white.

#

why doesnt this work

summer stump
short hazel
#

Yeah both if statements run here

novel shoal
quick ruin
#

Thanks

novel shoal
summer stump
novel shoal
#

but still i feel like i am missing something

summer stump
novel shoal
#

i'll take it slow though

#

i don't want to rush things and get to a burnout

summer stump
novel shoal
#

i'll try small things and slowly get to bigger ones

novel shoal
supple zealot
#

hey everyone, i am trying to set my coin so that when i collide with it, i increment an integer (score), yet when i collide with it, nothing happens

#

void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Coin")
{
// Coin collected
totalCoinsCollected++;
Debug.Log("Coin collected! Total coins: " + totalCoinsCollected);

        // Destroy the coin
        Destroy(other.gameObject);
    }
}
#

ive set it on my gamemanager, and set the tag of my coin to , well ,coin

short hazel
#

Do you get the debug log?

gaunt ice
#

first dont use == for compare tag, use .ComapreTag()
second log if the method is fired

#

is one of them has rigidbody?

supple zealot
#

i dont see it logged at all, thats the weird part

#

and yes, i do have a rigidbody on player

short hazel
#

Try with the log outside the if statement to see if the method is getting called at all

supple zealot
#

gotcha, will do that rn

#

it is not fired at all , and the body is colliding (dont ask how i messed up the character lol)

short hazel
#

Apply the fixes if needed, and if you still don't get an execution then hit "I am still not getting a message" at the end of the page

supple zealot
#

will do

quick ruin
#

My UnityEngine.UI isnt recognized? Edit: fixed by reloading with unity? idk what happened

slender nymph
#

does the error only appear in visual studio? if yes, regenerate project files and restart it

queen adder
#

I have come to brag using c-sharp 11 on unity 2017 UnityChanwow

slender nymph
#

I mean, you'd only get access to the syntax sugar stuff from newer versions of c#. you're still limited to the features of the .net runtim you are targeting in the unity project

queen adder
#

it does compile

#

it's patched by zombie

slender nymph
#

and are you attempting to use something that isn't just syntax sugar? if not, i never said it wouldn't compile

rich adder
#

all those lines are game objects ? 😬

queen adder
queen adder
#

lemme try switch expression thingy

#

is that one counted too?

novel shoal
#

i cannot see the circle even though i set its color as white

slender nymph
queen adder
#

any example of what's not?

novel shoal
rich adder
novel shoal
rich adder
novel shoal
#

i don't get it

#

it's a 2 dimension project

rich adder
#

unity is a 3D engine

#

there is still Z space

queen adder
#

click the ball, send the screenshot

novel shoal
#

the object has no z value

rich adder
#

what about the camera

#

oh wait this is scene view

#

forget what i said

novel shoal
slender nymph
queen adder
slender nymph
#

myArray[^1] gets the last element of an array

novel shoal
eager elm
queen adder
#

oh does ...somethingHere counts as non-syntactic?

novel shoal
queen adder
#

i remember seeing it a lot before

novel shoal
#

i tried to remove it and it showed a gray object

rich adder
eager elm
novel shoal
rich adder
novel shoal
slender nymph
short hazel
#

Try static abstract members in interfaces, that's not syntax sugar AFAIK

queen adder
slender nymph
short hazel
#

Yeah it does not bring the new types in

queen adder
#

new types like?

short hazel
#

System.Index

formal escarp
#

hey guys i have a question. I have a simple menu with the button "play" on it. when you click it you go to the "level 1" scene. is there any way i can re-use the code to make it so when you click an specific spot of the level 1 you go to "level 2"? i can send my code here.

formal escarp
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Menu : MonoBehaviour
{

    public void Jugar()
    {
        SceneManager.LoadScene("SampleScene");
    }

    public void Salir()
    {
        Application.Quit();   
    }
}
polar acorn
formal escarp
#

I should, make a new script or modify this one?

slender nymph
#

modify that one

formal escarp
#

now i just gotta figure out how to do that, but i think i know how.

queen adder
#

anyway, me is more than happy having pattern matching alone, no more weird pattern like this

#

actually lemme try if i can do a tuple

slender nymph
queen adder
#

tuple should work at least, though idk how to write one

slender nymph
queen adder
#

did i use it wrong then?

short hazel
#

I wonder if records are supported by your thing, they're good for prototyping and get expanded into classes/structs anyway

record Sample();
record struct Point2D(int X, int Y);
rich adder
#

var tuple = (32, 5);

#

I fdup

#

forgot how to do named tuples xD
i just use structs 😦

slender nymph
# queen adder did i use it wrong then?

yeah that syntax that was provided was a ValueTuple not a Tuple (slight difference). that wasn't added to .net until .net 4.7 which i'm not sure if unity 2017 uses 🤷‍♂️

queen adder
#

unity17 is 4.6 .net

novel shoal
#

how to make the ball moge in a random direction (making pong)?

queen adder
#

if you want physics, use addforce

supple zealot
#

Character Controller was in front of my mesh collider, sooooo it never did collide

#

im trully a genius

rich adder
#

or you mean the beginning ball

novel shoal
slender nymph
# queen adder record does work

i'm surprised this works. i was under the impression that records required the init language feature to work. though i guess it does just compile into a class or struct

novel shoal
#

do i have to use a range or something?

rich adder
rich adder
#

same thing

queen adder
novel shoal
#

okk thx

queen adder
#

oh, random direction, isnt it better to use RandomInsideunitcircle for extra added flavor?

novel shoal
#

you are the experts lol

queen adder
#

not even an expert, but it will make your ball like go at an unexpected direction at start

#

Random.insideUnitCircle is a vect2

novel shoal
slender nymph
supple zealot
#

how can i reference one script inside another?

supple zealot
#

ty

queen adder
merry spade
#
    public void TimerStart()
    {
        currTime = 1;
        reviveTimer.fillAmount = currTime;
        while(true)
        {
            print(currTime);
            currTime -= Time.deltaTime * 0.01f;
            reviveTimer.fillAmount = currTime;
            if(currTime <= 0f)
            {
                cancelButton.onClick.Invoke();
                break;
            }
        }
    }
}

why is the timer instant at 0?

slender nymph
slender nymph
#

if this is being called from Update or something then just remove the loop entirely

short hazel
#

You're one of the lucky ones that make a loop that will actually exit all the time

queen adder
slender nymph
#

changing that will also not update unity's .net version

merry spade
slender nymph
#

then read my first message

merry spade
#

what is a yield Xd

#

i will look it up in the internet thank you

queen adder
#

a very short word that is very deep topic in c#

novel shoal
#

why is my WHITE ball gray?

novel shoal
queen adder
#

it looks better tbh UnityChanWIP

rich adder
#

also this isn't a code question

spiral narwhal
#
_childRectTransform.SetParent(transform);
_childRectTransform.position = Vector2.zero;

Is the first line not completed within one frame by any chance? Because it still positions the element at vector zero of the old parent, not the new one

#

This is in `public void OnEndDrag(PointerEventData eventData)´

rich adder
#

instead

#

oh wait no

#

anchoredPosition

#

_childRectTransform.anchoredPosition = Vector2.zero;

spiral narwhal
#

Ah yes, cheers

pulsar lodge
#

!code

eternal falconBOT
dry tendon
#

hey, does someone know why fog doesnt correctly works?

#

it just makes an strange halo on the road

pulsar lodge
#

https://gdl.space/tuzifeyove.cpp Can anyone help me figure out why line 26 is not working in my code? Player 1-4 are not being added to my list, should i be using a different Method other than add? or a different parameter other than FindObjectWithGameTag

short hazel
slender nymph
pulsar lodge
#

it isnt adding any, not even the first object

slender nymph
#

then either that code is not running or there are no objects with that tag in the scene at the time the method runs

pulsar lodge
#

i looked it up a recommendation i saw was to use AddRange(GameObject.FindGameObjectWithTag("Hero")); but when i do that, i get this compiler error is VS :
Error CS1503 Argument 1: cannot convert from 'UnityEngine.GameObject' to 'System.Collections.Generic.IEnumerable<UnityEngine.GameObject>' Assembly-CSharp C:\Users\nanak\My project\Assets\Scripts\Battle\BattleManager.cs 26 Active

eager elm
#

AddRange() wants a group of objects, FindGameObject() returns only 1 object. Either use Add() or FindGameObjects(), with an S at the end

#

@pulsar lodge

true pasture
#

would i want to run code capping my velocity in fixedupdate or update? It should be fixedupdate I think, just wanted to double check

rich adder
pulsar lodge
#

Adding these objects to a list to determine attack order (turn based JRPG)

rich adder
#

yeah but you don't need add range but whatevs lol

pulsar lodge
#

and so that i can control their character states (dead, waiting, performing action, etc)

rich adder
#

also GameObject type is as useful as watching grass grow

#

you should use something more specific

#

public List<Players> PlayersInBattle = new ();

#

🤷‍♂️

#

skip uneeded GetComponent()

wise light
#

Hello everyone, I'm super new to coding and Unity. How can I save the y-position of my gameObject in a new float var? I'm supposed to use that later for moving my character forwards/backwards. It's probably very easy to solve but everything online just confuses me, too much info for a noob FroogySad

eager elm
#

float myFloat = gameObject.transform.position.y;

summer stump
eager elm
#

that variable is only usable in the scope, the two brackets {} where it is declared, so you might want to declare it inside your class instead your method:

public class YourScript : MonoBehaviour
{
    float myFloat;

    void Start()
    {
        myFloat = transform.position.y;
    }
}```
summer stump
# wise light Hello everyone, I'm super new to coding and Unity. How can I save the y-position...

Note that what Gruhlum said is saving the VALUE, which is exactly what you want.
It won't change even as the transform changes position.
If you saved the transform of something, you are capturing a REFERENCE to the component, and whenever you get the y value of it, it will be the currect y position, and thus not really what you want

As you learn, telling the difference between a value and reference can be important, so I just wanted to put that out there.
Best of luck!

wise light
#

Thank you! When I try the solutions it always says "error CS0236: A field initializer cannot reference the non-static field, method, or property 'Component.transform'"

I think I tried what you shared already but something is lacking here xD

nimble blaze
#

hello guys could someone help me out if i use colliders my character cant go through them but i want it to trigger example a door

#

thing is when i click on the trigger thing it just goes straight down

buoyant knot
#

which defines a float for the class (y), and tries to immediately assign a value to it (transform.position.y) as the class comes into existence

#

but you can’t do that because transform.position.y is not a compile time constant

rich adder
buoyant knot
#

like, you can only do that second part if the machine knows exactly what to assign before any code is run

buoyant knot
nimble blaze
#

well like coins there are supposed to be floating mid air but i want them to trigger them another thing is door im turning off the sprite renderer when its gets trigered

rich adder
buoyant knot
#

the door can be solid

nimble blaze
#

but they are supposed to float in the air when i make it a trigger they fall down

rich adder
#

remove it

nimble blaze
#

the coins?

buoyant knot
#

dynamic rigidbodies have forces applied to them

rich adder
#

sounds like they have rigidbody with gravity on they will fall

rich adder
buoyant knot
#

i would give it a static rigidbody

wise light
buoyant knot
#

rigidbody lets it receive messages about collisions. But static means physics system needs not worry about moving it

#

sure

rich adder
summer stump
buoyant knot
#

if you want coins to detect player, or player detect coins

summer stump
#

As nav said, the rigidbody only needs to be on one object, it will send the message to both colliders in the collision

And yeah, whichever one makes sense will work

rich adder
buoyant knot
#

both are valid

nimble blaze
rich adder
nimble blaze
#

like i have the trigger on

#

that is the result

#

the key went straight down ignoring other collisions lmao

rich adder
buoyant knot
#

at least physics2D basically assumes colliders with no rbs have a static rb

nimble blaze
#

basically its suppose to make it hover on the air

rich adder
buoyant knot
#

you misspelled amplitude

rich adder
#

you're forcing positions

#

= teleport

buoyant knot
#

know that if you want the collider to move, you need to move a rigidbody

nimble blaze
#

but im already using the first establish positions it had before hand

#

ok let me remove the script and let me see

buoyant knot
#

and moving the transform will be kind of shittily trying to move the collider

rich adder
#

dont use physics just to animate a coin /key lmao

#

use something like DoTween

#

and just reise the key and fix the min/max no reason a collider being trigger should prevent what u want

nimble blaze
#

hahah ok

buoyant knot
#

i would probably split it into 2 gameobjects, and move the transform of just one with the sprite.

wise light
buoyant knot
#

if you move the transform while it has a collider, you’ll get janky collision

buoyant knot
#

you want to move just the object with a spriterenderer

#

then you won’t fuck with collision/physics at all

rich adder
#

although only animating the sprite object will cause bad trigger /collision for pickup

summer stump
buoyant knot
#

mario does it like that. the hitbox of a coin is static, while the coin moves

wise light
queen adder
#

are there extra performance cost for using string overloads of GetKeys than the Keycode overloads?

buoyant knot
#

if you do want the hitbox to move as it hovers, you absolutely need a kinematic rigidbody on that collider

nimble apex
summer stump
# wise light I need to do it that way, I learned it in another way in the lecture but I think...

That doesn't really make sense as a reason.
A lecturer said you need to do it with the y position?
Are you sure they weren't talking about the second addforce where you handle jumping?
(Even that doesn't really make sense honestly)

AddForce doesn't need to know the current position explicitly. It already knows the rigidbody position. It just needs the direction and magnitude (a vector)

nimble blaze
#

what is the difference between kinectic and static?

nimble apex
#

it just doesnt make sense

buoyant knot
#

otherwise you’re just teleporting the collider, and it’s coordinates won’t be synced properly

rich adder
rich adder
slender nymph
#

a static rigidbody is effectively the same as no rigidbody

nimble apex
#

unless , the "forward" in ur game is like raiden

rich adder
#

never had a problem hitbox being that inaccurate

nimble apex
#

good old arcade game lol

buoyant knot
rich adder
#

usually the animation/translation is too low to notice an impact

buoyant knot
rich adder
#

I couldnt imagine having a bunch of kinematic coins animated just to get a slight chance of precision

buoyant knot
#

kinematic RBs aren’t really that expensive tbh

rich adder
#

If you're doing a moving platform then yeah it makes sense

#

animating props / coins ?

wise light
# summer stump That doesn't really make sense as a reason. A lecturer said you need to do it wi...

Yeah my object was moving before but not in the way I need to do it now, I guess it doesn't make sense isashookstare maybe I misunderstand, but it says (translated from German)
"Store the Y (forward/backward) component of this vector in a Member variable of type Float so you can access it from elsewhere.
Pass this float value in FixedUpdate() to the AddForce function Rigidbody further to make the car move forward and backward. About the direction to specify the acceleration, multiply the value by the transform.forward of the rigid body. Specify a suitable ForceMode"

nimble apex
#

i animate coins only for giving it much more awesome effects

nimble blaze
#

ah my brain well im using velocty to move around but i heard that you should avoid using them because they consume alot of resources and whenever you can use trasform/translate

nimble apex
#

or just simply moving it around to annoy players lol

rich adder
#

you shouldn't worry about that stuff rn

#

just make it work correct

nimble apex
#

but thats moving, not animating tho

buoyant knot
#

but using an RB to move will keep colliders synced

#

example: if collider ceneter is at y=0; then i set transform.position.y =5f; do you know where the collider’s center is now?

#

it’s not at 5f. it’s still at 0f

nimble blaze
#

oh ok i gotchu

buoyant knot
#

so if any of your other code is reading stuff, it will all be messed up

#

but if you set rigidbody.position.y = 5f, now the collider’s center actually is at 5f

nimble blaze
#

ok i understand so basically even if the gameobject is all the way into the ground the collider is still in the same place so that is why it needs a rigidbody to follow it

rich adder
#

the rigidbody doesn't follow anything

buoyant knot
#

and you shouldn’t set position like that normally. you would want to use rigidbody.MovePosition, but the point still stands

rich adder
#

it controls the transform, if you are using transform directly it defeats the whole purpose of a rigidbody

buoyant knot
#

rigidbody and transform write to each other

#

colliders live in rigidbody space. the collider will only actually move when the rigidbody’s position is moved.

#

and if you set transform, that won’t happen until the next time SyncTransforms is called

#

which it is called automatically at physics similation

rich adder
#

yeah colliders are part of physics

buoyant knot
#

but if you calculate some numbers based on some numbers, thinking everything is synced and gucci, moving the transform while you have a collider can fuck it up

nimble blaze
#

Oh i see my code is super fuck

#

i added the rb now the collider follows the movement

#

but it goes to the ground thing im kind of dumb with programming basically i made my code always deliver between 1 to -1 so the y axis is always going there

nimble apex
#

what?

rich adder
nimble blaze
#

didnt you guys told me to add a kinectic rb to my object?^

rich adder
#

if it was kinematic , it wouldn't fall

#

you added a dynamic rb

nimble apex
#

kinematic doesnt affect by physics

#

which includes gravity

nimble blaze
#

no i mean my code basically forced the y axis

#

in the transform position

nimble apex
#

is there any chances to not force it?

nimble blaze
#

yeah that is why im tryingg to figure out

#

this is the code

rich adder
#

why dont u show us what it looks like in game view

nimble blaze
rich adder
#

you're starting your y at 0.5 world pos

#

and then 0 and so forth

#

sorry 0.83

#

cause thats what you have in inspector

novel shoal
#

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

public class BallBehaviour : MonoBehaviour
{
private Rigidbody2D rb;
float force = 20f;
public Vector2 addition = new Vector2(1, 1);
Vector2 speed;
Vector2 constantspeed= new Vector2(30,30);
void Start()
{
rb = GetComponent<Rigidbody2D>();
Vector2 randomdirection = Random.insideUnitCircle.normalized;
speed = randomdirection * force * Time.deltaTime;
rb.AddForce(speed,ForceMode2D.Impulse);

}
void OnTriggerEnter2D(Collider2D other)
{
    if (other.CompareTag("player"))
        constantspeed += addition;
}
void Update()
{
    rb.AddForce(speed);
}

}

#

why does the ball break through the bars and the barriers?

#

they are all rigidbody, doesn't rigidbody add an hitbox?

slender nymph
#

you shouldn't be adding force inside of Update like that. and you also shouldn't be multiplying your force by deltaTime

#

also !code

eternal falconBOT
nimble apex
#

i mean just a small animation is fine? the key???

novel shoal
nimble apex
slender nymph
#

otherwise your object will just increase speed indefinitely and that speed will be dependent on the framerate

novel shoal
nimble apex
novel shoal
slender nymph
#

lol not the way you are using it

nimble apex
#

wait lemme show u

buoyant knot
nimble apex
#

real quick

novel shoal
novel shoal
slender nymph
#

make sure the rigidbody has no drag and the physics material has no friction. then just assign its velocity

nimble blaze
#

i solved my code

slender nymph
# novel shoal why?

because you only multiply by deltaTime once when you create your variable. so not only are you not accounting for variances in deltaTime each time you apply force, but you are also just continuously adding force every single frame

nimble apex
#

so lets get it clear, i joined half way

#

@nimble blaze

nimble blaze
nimble apex
#

u just want a key to be able to pickup, and it floats up and down

#

thats it?

nimble blaze
#

yes

buoyant knot
#

still not right

nimble apex
#

aight

nimble blaze
#

i did it with code

nimble apex
#

can u try animation?

#

i mean this is the best use case of animation

buoyant knot
#

you want to do Rigidbody2D rb;
rb = GetComponent<Rigidbody2D>();
and then rb.MovePosition

nimble apex
#

ofc rb can do it

buoyant knot
#

instead of transform.position

rich adder
buoyant knot
#

moving transform moves the sprite, while not moving the hitbox properly

#

this is good for if you want the hitbox to be non-moving

#

but not if you want the hitbox to move along with the sprite

#

do you understand?

nimble blaze
#

but it does

rich adder
buoyant knot
#

meaning any code that depends on it later will be using wrong numbers

#

eg it will look perfect now, but potentially break later

novel shoal
slender nymph
#

well now you're just going to make it go in a specific direction no matter what because you've hard coded the velocity. but it's better than it was.
oh and you're still unnecessarily adding force in Start

#

now go add colliders to your objects because no, Rigidbodies are not colliders

novel shoal
slender nymph
#

i recommend watching a tutorial for how to do this. because it looks like it is supposed to be pong and there are dozens, if not hundreds, of tutorials for making pong

rich adder
novel shoal
rich adder
#

yeah pong has many diff movement types, I did something for Breakout classic type Bat/Ball

#

I also used velocity but collision I dont use physics because Physics Materials suck

#

too unreliable

solemn fractal
#
Instantiate(_wallFBO, new Vector3(_player.transform.position.x, _player.transform.position.y, 0), Quaternion.identity);
        _camera.Follow = null;```
#

Any ideas why ?

nimble apex
#

@nimble blaze hey can u check this out, maybe this is what u want?

#

i mean as long as it works as u want, any solution should be acceptable

rich adder
#

what is the first screenshot of I dont understand whats happening here

solemn fractal
#

and it doesnt spawn above the player it spawn in a wrong position

nimble apex
#

if this is what u want then u dont even need rb at first place

rich adder
solemn fractal
#

it is, actually it is in the center

#

and it spawn a bit lower and to the right

nimble apex
#

just to double check

#

i mean it wont hurt lol

solemn fractal
nimble apex
#

see?

rich adder
solemn fractal
#

oh, it cant be in center mode? i thought that would need to be in center mode

rich adder
#

so ur not seeing the true pivot

solemn fractal
#

ok got it thank you 😄

nimble apex
solemn fractal
#

how can I move the pivot to the place i want without moving the object?

rich adder
#

is it a 2D sprite ?

#

it usually have it in the spire editor

solemn fractal
#

that is parent of 4 child 2d sprites

rich adder
#

unparent it, move it proper

#

then reparent

solemn fractal
#

ok, thank you

#

worked, thank you!

nimble apex
solemn fractal
# rich adder you have to match the children

now if I stand still it works.. if I am moving with the player it appear a bit off.. is there a way to fix that? or as it is updating the player position there is no way to do it?

nimble apex
#
  1. make sure ur in pivot mode
#
  1. create an ampty object
  2. put all the objects u want under it
lusty cosmos
#

feeling very stupid right now, does anyone know why my camera is turning unevenly?

nimble apex
languid spire
eternal falconBOT
nimble apex
#

get input with time.deltatime

#

is it brackeys?

solemn fractal
# rich adder you have to match the children

also when I make my camera to stop following me its like I lost a lot of movement speed with my player.. wierd.. and if I stand still it works.. if I am moving with the player it appear a bit off.. is there a way to fix that? or as it is updating the player position there is no way to do it?

#

if I stand still it spawns on the correct place

#

if I am moving right it spawns where u see now

rich adder
solemn fractal
#

If I move left itt spawns more to the left.. and also i turn my camera OFF to follow me and my player I dont know lose a lot of movement speed

solemn fractal
#

the idea is... i will be playing. when i reach lvl 30 the final boss appears.. but now the camera needs to stop following me and I will be trapped inside those walls

dry tendon
#

Hello, could someone take fast look at my lighting question said in that channel? I say it here because almost no one watches it... 🤷‍♂️
#archived-lighting message

solemn fractal
# rich adder which one is which

the player movement actually is the same .. it was just an impression.. but the walls appear slightly to the left or right depend which direction I am moving.. is there a way to fix that? I am saying to spawn on my location but it seems the movement of the player is influencing it a bit

summer stump
wise light
summer stump
chilly vigil
#

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <4a4789deb75f446a81a24a1a00bdd3f9>:0)
StormController.Update () (at Assets/StormController.cs:101)
i got this error

slender nymph
#

show the StormController class

rich bluff
summer stump
wise light
chilly vigil
#

yes it asking for not negitve value

rich bluff
#

not only

summer stump
rich bluff
#

Index was out of range. Must be non-negative and less than the size of the collection.

#

Index was out of range.
Index is the position you are trying to access
range is the size in elements of the array/list/collection you are trying to access

#

it has a range, an array with length 5 will have a range 0-4

#

error says you are trying to get something that is beyond the range of valid positions in the collection

chilly vigil
#

"Your ShrinkCircle method seems correct for its purpose, but there is an issue in the way you're accessing CloseTimes in the Update method. The error you are facing (ArgumentOutOfRangeException) indicates that you're trying to access an index in the CloseTimes list that doesn't exist.

Here's the problematic part:

csharp
Copy code
if (((int)timeElasped) > CloseTimes[closeTimesIndex]) {
// ...
if ((int)timeElasped - (int)timeElasped != CountDown) {
CountDown = Mathf.Clamp(CloseTimes[closeTimesIndex] - (int)timeElasped, 1, 1000);
// ...
}
// ...
}
You should perform additional checks before accessing the CloseTimes list to ensure that closeTimesIndex is within a valid range. You can use the Count property of the list to check its length. Modify the code as follows:

csharp
Copy code
if (closeTimesIndex >= 0 && closeTimesIndex < CloseTimes.Count && (int)timeElasped > CloseTimes[closeTimesIndex]) {
// ...
if ((int)timeElasped - (int)timeElasped != CountDown) {
CountDown = Mathf.Clamp(CloseTimes[closeTimesIndex] - (int)timeElasped, 1, 1000);
// ...
}" this chatgpt said

summer stump
languid spire
weary moss
#

what would be more efficient?
Use collision to detect an object's tag or make a variable for that object and then use collision to detect the GameObject?

frosty hound
#

Use whatever is easier to keep organised for you

rich bluff
#

most efficient is direct reference comparison

weary moss
#

so the variable

rich bluff
#

tell me how many you expect

weary moss
#

like one every couple of seconds

rich bluff
#

then it doesnt matter

#

it will matter when you will have 10k collisions per frame, where string/tag/GetComponent will have actual effect

weary moss
#

i mean, it's a phone game, even then it doesn't matter?

rich bluff
#

even then, once every couple seconds

weary moss
#

alright thanks

rich bluff
#

differences there are in microseconds

queen adder
#

can we simulate a button press via code?

keen crescent
#

Hello,
I'm having trouble intuitively understanding how GameObjects work, or just objects in general
If I have a class called Cell, not inheriting from monobehaviour

{
    public GameObject cellObject;
}```
and a class that makes an array of them
```public class NewGrid : MonoBehaviour
{
    Cell[,] cellgridArray = new Cell[10, 10];
}

Why doesn't this actually instantiate gameobjects? I know you can iterate through and instantiate them, but I don't understand why that's necessary
Doesn't making an array of Cell objects necessarily make their gameobjects?

rich bluff
queen adder
#

wrapper?

rich bluff
#

anything inheriting an object, so a class has to be allocated manually through new or Activator.CreateInstance

#

because what happens is you create that object on the heap and a reference to it is returned to you

#

structures are value types and they behave like you expected

#

they are stored by value, embedded into the object they are stored in, so an array of Vector2 will have element size of 2 floats

#

and will be created in place when you allocate the array

rich bluff
#

so that you dont directly use Input.GetKey

#

but instead you do that through a layer

#

bool pressed = myInputLayer.GetKey(..)

#

then the layer can "simulate" key press

sturdy lintel
#

I'm trying to be able to select an AxisFramePrefab in Unity it & move it. An axisFrame prefab is basically 3 small cylinders looking like x,y,z axis. So If I click & drag on Y cylinder, I should be able to move it in Y-axis only & vice versa for other cylinders. But there is no smooth movement. Can anyone tell me what wrong I am doing?

rich bluff
#

instead of initial offset, create initial plane in which you will operate

#

then you can raycast that plane instead, not relying on hitting any collider

sturdy lintel
#

let me try. thanks for suggestion

abstract onyx
#

Are CodeMonkey's code practices good? I'm watching one of his YT tutorials and I wanna make sure I'm learning correctly before I step in too far, the vid is pretty popular and big in views so I assume you guys know a bit about CodeMonkey

dense root
#

So I'm trying to pass an input from InputField into my CheckString function however it is returning null. For some reason my input = s goes null once I hit enter... any thoughts?

Here is the setup:

public void ReadString(string s)
{
    input = s;

    // This checks to see if the string written is the same being read
    CheckString(currentWord, input);
}
#

And CheckString method for reference:

    private void CheckString(string read, string write)
    {
        Debug.Log("read: " + read);
        Debug.Log("write: " + write);


        if (read == write )
        {
            Debug.Log("Read equals write");
        }
    }
#

The first read is okay, it holds the value as expected but once I press enter it changes to null

rich bluff
dense root
#

hmm when i change it to submit I still get the same error

rich bluff
#

seems a way to mitigate it is to bypass the callback and just read the value on input

dense root
rich bluff
#

dont use it

#

how many calls per enter happen?

dense root
#

just one

#

when i press enter it calls the function

#

but the read variable disappears upon submit

#

same with write on the next submit

#

the form seems to "clear" the value

#

everytime i hit enter

rich bluff
#

try disabling navigation on the component, anything changes?

dense root
#

how do i do that?

rich bluff
#

in the inspector navigation dropdown

dense root
#

no dice

rich bluff
#

im not sure whats going on there, you can try googling, or if you know how to use the debugger, you can copy the ugui package into the project which will allow you to navigate the call stack and find where it loses the reference

abstract finch
#

Is there a way to rotate the camera with clamp using Input.GetAxisRaw? I notice alot of guides store the values rather than use it per frame. The reason I ask is because I want to incorporate a recoil variable in adition to applying the input

rich bluff
dense root
#

Yeah I'll do that

solemn fractal
#

Hey guys.. I created an object and when I instantiate it on the players location, if I am standing still the boss spawns at the correct location, but if I am moving to the right it spawns like a bit to the right etc.. also for the left and so on.. any fix?

wintry quarry
#

You also need to explain what you want to actually happen (what is the correct behavior?)

solemn fractal
# wintry quarry Whatever is happening is due to your code. The fix will be to change the code. C...

true, I am using this as the player movement. ```cs
private void PlayerMovement(){

    float horizontalInput = Input.GetAxisRaw("Horizontal");
    float verticalInput = Input.GetAxisRaw("Vertical");

    transform.Translate(Vector3.right * playerSpeed * horizontalInput * Time.deltaTime);
    transform.Translate(Vector3.up * playerSpeed * verticalInput * Time.deltaTime);
    
}``` When I spawn the boss like that:  ```cs
private void InvokeFinalBO(){

    Instantiate(_finalBossOne, new Vector3(_player.transform.position.x, _player.transform.position.y + 21.4f, 0), Quaternion.identity);
    //Instantiate(_wallFBO, new Vector3(_player.transform.position.x, _player.transform.position.y, 0), Quaternion.identity);
    _camera.Follow = null;
    
}``` it should spawn on player position. itworks BUT if I am moving to any place.. it spawns a bit like 1..2..3..4. units to the direction I am going..
wintry quarry
solemn fractal
#

but it doesnt.. and if it does.. it mess up.. because the boss just move left when reach end of the screen he moves to the right.. just that.. but if I am moving with the player as he spawns not where I want he goes beyound the screen 1..2..3...4 units

#

if am standing still it works as intended and he moves to the left or right until the end of the screen and doest go further away.. so might have some frames of something that is messing with it.. dont know how to fix.. maybe say that if the player is going to the left.. spawn him a bit to the right etc

wintry quarry
#

What I do know is that Instantiate spawns objects exactly where you tell it to

hybrid gust
#
float noiseHeight = Mathf.PerlinNoise((float)(x/ height), (float)(z/width));

Assuming this line of code is in for loops that change the x AND they y values. Why am I getting 0.4652731 regardless of the value of x or y?

#

Ive seen people suggesting that using ints instead for floats might be the issue, but it doesn't seem to be making much of a difference whatsoever

wintry quarry
#

I.e. you are plugging in (0, 0), (1, 0), (2, 0) etc

#

you need to sample the noise function between those values

#

You're sampling at the dots and you need to sample between the dots

#

Also x/ height < if x and height are integers, this will do integer division

#

casting to float AFTER that is useless

#

You have: (float)(x/ height)
You need: (float)x/height or x / (float)height

hybrid gust
#

Okay gotcha, I was about to lose my mind lol

muted wadi
#

im confused on why the objects that are hit by the ray and stored in the hitThing RaycastHit variable are only added to the lockedOn list once

 {
     camPos = mainCam.transform.position;

     if (Input.GetKey(KeyCode.Mouse1))
     {
         RayOut();
         lockedOn.Add(hitThing.transform.gameObject);
         hasLockedOn = true;

         Debug.DrawRay(camPos, mainCam.transform.forward * 100, Color.magenta, 3f);
     }
     if (Input.GetKeyUp(KeyCode.Mouse1) && hasLockedOn)
     {
         Destroy(lockedOn[lockedOn.Count - 1]);
         lockedOn.Clear();
         hasLockedOn = false;
     }
 }```
teal viper
muted wadi
#

what else do you need?

teal viper
#

Share the whole code
!code

eternal falconBOT
muted wadi
#

ok

muted wadi
#

the ray is being cast every frame, which means that the data stored in hitThing should also be updated every frame. So in that sense, hitThing should also be added to the list every frame, even if its the same data right?

#

should i maybe use a while loop instead and just break when the player stops pressing the right mouse button?

tacit estuary
muted wadi
muted wadi
wintry quarry
#

Also why do you need a list in the first place?

muted wadi
wintry quarry
#
         Destroy(lockedOn[lockedOn.Count - 1]);
         lockedOn.Clear();```
this doesn't require a list
teal viper
wintry quarry
#

read it

#

notice how you are only calling Destroy one time? Only one thing is going to be destroyed, and that thing is the last element in the list.

muted wadi
#

wait what

#

how come its only the last element?

wintry quarry
#

Because that's the code you wrote

#

Destroy(lockedOn[lockedOn.Count - 1]);

#

"Destroy the thing at the last index in the list"

muted wadi
#

huh

wintry quarry
#

What are you confused about

#

lockedOn[lockedOn.Count - 1] < this gets the last element in the list
Destroy destroys whatever you pass into it

muted wadi
#

doesn't .Count mean all of it?

wintry quarry
#

what?

#

Count is just the number of elements in the list

#

COunt - 1 is the last valid index in the list

muted wadi
#

oh i see

wintry quarry
#

Therefore lockedOn[lockedOn.Count - 1] gets the last item in the list

#

there's no magic that will make Destroy suddenly destroy multiple objects when only being called one time

muted wadi
#

no i know

wintry quarry
#

You should:

  • Use a HashSet instead of a List, since it doesn't allow duplicates
  • use a foreach loop to loop over them all and destroy all of them
muted wadi
#

aw man

#

i was gonna use a hashset at first but i thought it wasn't the right type for this kind of thing

wintry quarry
#

Why?

muted wadi
#

i dont know much about hash sets but i thought it kept less information, or maybe didn't keep an ordered list

wintry quarry
#

It doesn't keep an ordered list

#

but you don't need ordering as far as I can tell

muted wadi
#

i do

wintry quarry
#

Ok then just only add a thing to the list when it's a new thing

tacit estuary
wintry quarry
#

What do you need the order for though?

tacit estuary
#

If you want to play an animation so they destroy in order, you should use a hashset and a list. Use the hashset to verify you are adding a new game object, and use the list to destroy them in order

muted wadi
teal viper
#

Hashset might not work very well with the hit struct.

wintry quarry
#

It won't

#

they should be storing Collider or GameObject

#

they should not be using the RaycastHit struct so widely

muted wadi
wintry quarry
#

so yeah something like:

HashSet<GameObject> uniqueObjects = new();
List<GameObject> objects = new();

void Update() {
  if (Input.GetKey(...) 
  && Physics.Raycast(... out RaycastHit hit, ...) 
  && uniqeObjects.Add(hit.collider.gameObject)) {
      objects.Add(hit.collider.gameObject);
    }
  }
}``` basically
#

and then Clear() them both when you let go of the button

muted wadi
#

hmm alright

teal elk
#
    {
        Move();
    }

    private void Move()
    {
        Vector2 moveInput = input.Move.normalized;
        Vector3 move = transform.right * moveInput.x + transform.forward * moveInput.y;

        transform.position += move * Time.deltaTime;

        animator.SetFloat("horizontal", moveInput.x);
        animator.SetFloat("vertical", moveInput.y);

        Debug.Log("Im Moving");
    }``` im trying to get my charcter to move with the new input  system , but its not moing when pressing the keys, can anyone see what im doing wrong. in the code
wintry quarry
#

The code you shared doesn't explain how you're handling input at all

signal mango
# queen adder this does not work ig

For System.Index and System.Range, all you need to do is polyfill them. You can do that manually or you can use a package like IndexRange for it.

  • Download package (button on the right)
  • Open the .nupkg in an archival program (it's just a ZIP file)
  • Go into lib/netstandard2.0/ (or netstandard2.1 for Unity 2021.3+) and copy IndexRange.dll into your project
teal elk
# wintry quarry Where is `input.Move.normalized` coming from?
    void Awake()
    {
        playerActions = new GameInputActions();
        playerActions.Enable();
    }
    private void OnDisable()
    {
       playerActions?.Disable();
    }
    public Vector2 Move => playerActions.PlayerActionMap.Movement.ReadValue<Vector2>();``` here is what is handling my input.
wintry quarry
teal elk
wintry quarry
#

how is the property assigned?

#

(btw PlayerInput is not a good name for that script, since there's a PlayerInput component in the input system package already, which is confusing)

teal elk
wintry quarry
teal elk
wintry quarry
wintry quarry
#

That all looks good 🤔

#

Can you show the inspector of your player object?

teal elk
wintry quarry
#

Hmm is there a reason you have those prefab overrides?

teal elk
#

its a prefab

wintry quarry
#

This isn't a prefab

#

This is an instance of a prefab

#

And those components are only on this instance, not on the prefab itself. Hence the overrides (in blue, with plus signs)

hollow axle
#

Say I have an object that has bool isLookingForAFight = true. I want the object to move toward and collide with another object with the same var value. How do I do that? FindGameObjectsWithTag is similar to what I'm looking for, but instead of looking for a certain tag I want the object to look for a certain variable

wintry quarry
#

Then simply check what's in that list as needed

hollow axle
#

It's a bit too advanced for me, lol, but I'm gonna try it nonetheless. Thanks

chilly vigil
#

!code

eternal falconBOT
chilly vigil
heady vortex
#

i think unity hates me

chilly vigil
#

why

heady vortex
#

every time i try to type any of my code it never works even if i copy someone elses

true pasture
#

Well let us see the code

heady vortex
#

ight hol up

chilly vigil
#

help me i still got errors after have chat gpt help me with me code

summer stump
amber spruce
#

so these are my 2 scripts how do i add a double jump to them

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

    public CharacterController2D controller;

    public float runSpeed = 40f;

    float horizontalMove = 0f;
    bool jump = false;
    bool crouch = false;

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

        horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

        if (Input.GetButtonDown("Jump"))
        {
            jump = true;
        }

        if (Input.GetButtonDown("Crouch"))
        {
            crouch = true;
        }
        else if (Input.GetButtonUp("Crouch"))
        {
            crouch = false;
        }

    }

    void FixedUpdate()
    {
        // Move our character
        controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
        jump = false;
    }
}

the second one has to be a file

eternal falconBOT
amber spruce
#

thats the second one

teal elk
chilly vigil
wintry quarry
rocky gale
#

hi im making a tower defense game and whenever i place a character i get the error: UnityException: Transform child out of bounds
MouseHoverScript.Update () (at Assets/Scripts/MouseHoverSelect.cs:97) and when i place a bunch of characters after a few seconds i get the error: NullReferenceException: Object reference not set to an instance of an object
MouseHoverScript.Update () (at Assets/Scripts/MouseHoverSelect.cs:93)

heres the code:
https://hastebin.com/share/ofireqineq.csharp

summer stump
rocky gale
#

mb

#

changed it

rich adder
rocky gale
#

ye but it has children thats why im confused

runic lotus
#

hello! when I use input field, the text (the value that is written in the field) is by default a TMP UGUI right? I need to target that in UVS, but due to a problem, I cant be using Get Text of TMP UGUI, I need to specifically target only a 'TMP text' to get its value, can I turn the value of that input field to TMP text instead of UGUI without messing up anything ?

rich adder
#

i trust the computer

rocky gale
#

idk it has children

runic lotus
summer stump
wintry quarry
rich adder
runic lotus
#

the 'text' is TMP UGUI'

chilly vigil
#

and there shrinking storm using an force flied from 2018 in spainish

wintry quarry
#

just read it through the TMP_InputField

runic lotus
#

also cant be using it either, sadly

#

its complicated and stupid i know

wintry quarry
#

SOunds like a fake problem / XY problem

runic lotus
#

just thank microsoft for their beautiful creations

wintry quarry
#

anyway your variable is of type TextMeshPro

#

TMP_Text is the parent class of both TextMeshPro and TextMeshProUGUI

#

just use TMP_Text

wintry quarry
#

what does Microsoft have to do with the type of your variable in your script

runic lotus
#

thats the part where i said, 'due to a problem', Im using something called 'Microsoft mesh', and its basically not allowing 90% of normal methods that are in UVS

rocky gale
wintry quarry
#

I would guess you are doing something incorrectly

runic lotus
#

well, it is in my case, not much that I can do to that

wintry quarry
#

I'm hitting the doubt button on that

summer stump
wintry quarry
#

I think you just picked the wrong type in this dropdown

runic lotus
wintry quarry
#

Maybe just write a regular C# script

summer stump
runic lotus
#

cant be compiled by microsoft mesh

#

trust me ive tried

wintry quarry
#

ok well idk then, stop using that shitty product

runic lotus
wintry quarry
#

maybe try legacy input field?

runic lotus
wintry quarry
#

Then what you want to do is not possible

runic lotus
teal viper
runic lotus
#

sigh

wintry quarry
#

But why not TMP_InputField?

#

that doesn't work either?

runic lotus
#

idea is, click on a cube (note), and have the text from the input field be in the text that s on top of the cube, simple enough.. yeeeaaahhh..

#

if anyone could suggest another way of doing it, to have a similar system to 'sticky notes', id be grateful

wintry quarry
#

Looks like Mesh has its own UI stuff like this dialog?

#

Maybe you should try to use those?

runic lotus
#

thats the thing, there is only that, 'show Dialog'

wintry quarry
#

Looks like there's some other concept called "Cloud Scripting"?

#

Seems to mention TMP components as being supported

#

idk if that helps

amber spruce
#

anyone know how i can add a doulbe jump to my script

summer stump
amber spruce
#

how do i call a variable from one script to another

wintry quarry
#
  1. Get a reference
  2. do whatever you want with it
amber spruce
#

how do i reference it

summer stump
#

If you can, you want a serialized reference

amber spruce
#

anyone know why i cant start my thing

summer stump
#

If you can't, it means you're probably instantiating the object? You have to pass the reference returned by the Instantiate call somehow

amber spruce
#

i hit play and nothing happens

summer stump
amber spruce
#

like nothing happens

summer stump
# amber spruce

You are clicking start so fast nothing COULD happen.
Click it ONCE

amber spruce
#

clicking it once doesnt do anything

summer stump
#

Do you have a rigidbody with gravity enabled?

amber spruce
#

yeah

summer stump
#

Show a video where you only click it once, and show more of the inspector if possible

amber spruce
queen adder
#

that's a lot of errors

summer stump
#

You have 65 compile errors
Can't play with compile errors

amber spruce
#

i didnt see that they where unchecked lol never noticed thenm

#

fixed it

#

now i have the problem of it never resetting the jumpcounter

summer stump
#

Every fixed update you seem to set m_Grounded to false and use wasGrounded.

Ah, I see where you set it true

spare mountain
amber spruce
#

it works thanks

summer stump
eternal falconBOT
amber spruce
#

also anyone know why i get this

queen adder
#

does anyone here know how to snap assets on the axis and transform them at a certain increment on the 2D URP

amber spruce
#

there is no settings though

#

now what do i do

queen adder
#

click the Axes and let your ancestors guide you 😄

amber spruce
#

can i add a imput there

queen adder
amber spruce
#

where do i say what key it uses

#

and what would i say for control

#

would i say ctrl or control or Ctrl or Control

#

it just keeps removing it

wintry quarry
amber spruce
#

thanks

nimble sorrel
#

Is there a (simple) way to rotate a vector by an amount in radians

#

quaternion.eulerAngle() uses degrees but most of the trig functions return radians, I can convert easily enough but I'm curious

gaunt ice
#

Mathf.deg2rad and mathf.rad2deg

wintry quarry
#

The simple way is to convert

vocal widget
#

i have doubt about the node system that
i am working on tiger and goat game and the game consist a kill condition for tiger to kill goat
but the condition is tiger should actually kill the goat if the goat is there infront of tiger and skip that node and transform its position to the next node
can some one help me with this

#

i am not able to get the logic

eternal needle
vocal widget
gaunt ice
#

Adjacency list
So you have defined next node already

vocal widget
#

yeah

#

so every node has its specific list of elements on which tiger can move

#

and the kill condition list which is neighbouringnextnode list is having thenodes on which tiger if the tiger will come then it will have this nodes to move

lethal depot
#

how to use animator if your main model(mesh) is child object of an empty game object?? can we still animate the character ?
the player mesh is child object of playerholder empty game object and i want to animate the player for idle and running animation , how do i do it?

gaunt ice
#

What are the purposes of having neighbouring nodes? (Not next node)

#

I think you mean: for each node: it checks its neighbours next nodes to see if there is tiger on the next node, and further check will the tiger comes(?) to itself (the node that are checking), then assign its position to tiger s position

eternal needle
# vocal widget

you should have the list ordered in a certain way, or define each node like
public Node left, right, forward, back. If its random (just based on how you decide to drag the transforms in) then your only check for direction relies on the position which might be annoying.
Im not sure what neighbouring next node is for though in your component

lethal depot
#

oh sorry about that.

gaunt ice
#

I prefer the tigers done the checking, for each neighbouring node (not the next node) of the node that the tiger on, check if is there any goat in the neighbouring nodes, and the next problem is to define direction, considering what bawsi said
One node may have multiples “next nodes” that tiger can jump into

patent compass
patent compass
gaunt ice
#

The tf should be assigned in a Ordered Way, not related to how you stored the tf (using array or list or multiple variables)

#

What is the “Occupied by goat” field….

vocal widget
eternal needle
#

you should store the reference to Node instead of transform

gaunt ice
#

Are the positions of tigers/ goats are limited( they can only stay on the nodes)? Though this is unimportant, consider assigning corresponding node by the animals’ position to animals

vocal widget
gaunt ice
#

The node can reference to tigers/goats and vice verse

vocal widget
eternal needle
vocal widget
#

i am not getting that how will i check if the node is occupied

gaunt ice
#

Read what i have typed…

vocal widget
#

and one more thing is every node tiger and goat has different script on it for movement and there respective work then how should i write a kill condition for tiger

teal viper
#

Instead of storing neighboring nodes as transforms, store them as Nodes, so that you can access it's members.

#

Then you can check if a neighboring node has a sheep or a tiger and what other nodes it's connected to.

tawdry mirage
#

temporary variables used inside cycle, should i declare them before cycle or inside of it, if i don't need them outside of cycle?

#

i mean it will reallocate memory every time or something

languid spire
tawdry mirage
#

reference types

languid spire
#

Reference types are better declared outside of the method if that method is called many times

teal viper
#

It's fine unless they are instantiated/created inside the loop

gaunt ice
#

I will declare them inside the scope, since they are not needed outside the scope and the registers/stack/cache should be released

woven crater
#

whats the different between SmoothDamp and lerp?

silver dock
#

my game has 100+ UI buttons, i want to make it so that an audio source plays when any of them is clicked, excluding 2-3 buttons. Is there any way i can do this via code without having to assign each button manually, but instead i only assign the exceptions

gaunt ice
#

loop through all buttons

#

then alllistener

silver dock
eternal needle
# silver dock like this?

I wouldnt use FindObjectsOfType incase you want to add new buttons in the future that dont play a sound. Everytime you'll have to remember to adjust this list, and having to remember previous scripts is truly a headache. I think it's worth it just mass selecting all the relevant gameobjects and dragging them into some inspector slot for which play a sound

silver dock
eternal needle
silver dock
eternal needle
#

Not on pc but I think you can filter out all the irrelevant objects with searching
t:Button

#

I forgot if that displays parent objects

rotund belfry
#

what's wrong?

public class SceneLoader : MonoBehaviour
{
    public GameObject loaderUi;
gaunt ice
#

Are the script using UnityEngine;

languid spire
silver dock
modest dust
#

Why not just make a custom script and attach it to the buttons to let them add themselves to the list on Start()

#

Or Awake() or whatever

eternal needle
#

🤷‍♂️what you had above could work if you're really confident you'll remember to add to the excluded list everytime you need to. It's a lot easier to debug that you need to add a button to the list instead of "why is my button making noise when it has no scripts on it" 3 months down the line

modest dust
#

either via event or singleton

silver dock
eternal needle
silver dock
woven crater
#

how to get 2D object direction?

#

got vector for movement but idk how to convert it into angle

hidden path
#

how do i make a 3d bird player controller

modest dust
woven crater
#

thank you.

#

when to use lerp and when to use smoothdamp?

modest dust
woven crater
#

UnityChanCelebrate ty

runic lotus
#

for anyone whos experienced in UVS (bolt) here, what are the "methods" to create a cube + have it in a set Position + change its color ?

solemn fractal
#

Hey guys.. I am trying to do something that might be simple but it seems that my mind cant figure this out with coroutines or invokingRepeating. Basically I have a boss that should shoot for 10 sec 1 type of bullet and after 10sec it stops and start shooting another bullet for 3 sec, and that repeats for ever.. tried with booleans, ifs, coroutines or invokes but 1 - or I crash the program with loops and whiles or it just doesnt work. any tips?

modest dust
#

Show current code

nimble apex
gaunt ice
#

crash is not freeze...
10 sec shooting->10 sec cool down->3 seconds shooting->cool down
^ |
|-----------------------------<------------------------------------|
now you have a loop that can run on coroutine

solemn fractal
#

oh, ok will try, thank you guys

nimble apex
#

buuuuut switching should be fine, if not shooting bullets

solemn fractal
#

yeah, its simple task but for me as noob is taking more than it should.. still getting around coroutines etc..

nimble apex
#

for actions that is extremely frequent , like 400RPM+ , do a simple timer

for action that is few second once or even 1-2 seconds once, feel free to use coroutines

woven crater
#

so because i put movementDirection.x and movementDirection.y into the directionangle and movementDirection is controller by vertical and horizontal input
which set the direction angle vector to 0,0 when im not moving so when im using directionangle to rotate the character it keep rotate back to (0,0) rotation.
how to fix?

#

maybe not using the movementDirection.x and y but idk what value to put inthere to get the current direction

modest dust
#

simply don't rotate when both horizontal and vetical are 0

woven crater
#

ah..... lol thank

solemn fractal
#

hey guys when I mouse hover a method that yes is not complete, it says +3 overloads for example.. how can I see the other overloads?

#

Some videos I see people clicking on an arrow, but mine doesnt have it so normally i crtl click on the method and go to the method class to check it but is there another way ?

solemn fractal
# nimble apex keep in mind that coroutine waits will be affected by frame time, it will have a...

done it like that and worked ```cs
private IEnumerator Shoot(){

     while (true)
    {
        StartCoroutine(ShootNormal(10));
        yield return new WaitForSeconds(10f);
        StopCoroutine("ShootNormal");

        StartCoroutine(ShootFast(3));
        yield return new WaitForSeconds(3f);
        StopCoroutine("ShootFast");
    } 
}

private IEnumerator ShootNormal(float duration)
{
    float startTime = Time.time;

    while (Time.time - startTime < duration)
    {
        Attack();
        yield return new WaitForSeconds(0.5f);
    }
}

    private IEnumerator ShootFast(float duration)
{
    float startTime = Time.time;

    while (Time.time - startTime < duration)
    {
        AttackFast();
        yield return new WaitForSeconds(0.03f);
    }
} ```
teal viper
solemn fractal
teal viper
nimble apex
#

what will u guys do to group up a set of poker? or make it into a collection

like dividing diamond heart spade and A-K

patent compass
#

Hello, how can i create a turn system in my game. is it necessary to use enums?

nimble apex
#
dictionary<int,int>```
where 0,1,2,3 is code for diamond, heart, spade....

or 
```cs
dictionary<enum,int>```
where enum can be diamond heart spade
#

i think enum int should be better

#

ty lol

solemn fractal
teal viper
solemn fractal
hexed terrace
# solemn fractal Visual Studio Code

You can scroll the overloads while you're typing .. I dunno if you can do it once you stop and leave it with an error, like in this screenshot

solemn fractal
#

Hmm cant anyways. but all good thank you !!

quaint thicket
#

I have a AnimationController and FBX animations, can I use C# to add these animations to the AnimationController?

steel forge
#

Death movement overwritten

eager elm
full imp
#

My goal is to try to move the bottom part whilst moving and the top whilst looking at the mouse

rich adder
#

because its covering the whole screen size

#

also not a code question

woven crater
#

ahh...

full imp
rich adder
# full imp

which one is myRigidbody also show you setup like hierarchy and pivots

languid spire
# full imp

you are using Quaternion values as if they were Euler

queen adder
#

Anyone knew how to make it so the camera can't moving around despite I put 'Time.timeScale = 1;' on the InventoryManager script?

rich adder
#

also that ^

full imp
rich adder
queen adder
eternal falconBOT
queen adder
rich adder
queen adder
rich adder
full imp
languid spire
queen adder
#

can i get some help with something please?

fickle plume
rich adder
#

if its only the cinemachine component doing it , then you disable that

steel herald
#

may i ask how to make animations :s

#

am lost

#

!code

eternal falconBOT
rich adder
#

you twice used command and dont read the bot message 😂

steel herald
#

my bad

#

i just joind :s

rich adder
#

is alright, reading in hard xD

gaunt ice
#

where is the button? i believe the two green tracks definitely not the button
btw is the button located as 0,0,0 in parent's space? it should be child of the track

umbral bough
#

I kind of tested this theory out but not in a way that you recommended, I noticed that the sprite sometimes disappears very early on, sometimes even as early as the first launch so that's not it.
Any other ideas?

#

It seems that I am actually able to constantly recreate it :/

#

I just add this force to the object at the very start:

private IEnumerator Start()
{
    yield return new WaitForSeconds(2);
    _rb.AddForce(Vector2.right * 100, ForceMode2D.Impulse);
}

teal viper
umbral bough
#

I am able to reproduce it consistently now, how am I supposed to debug it tho?

umbral bough
#

nah man I am confused rn

teal viper
umbral bough
#

I moved the scene camera so that the object can be seen and it's not disappearing

teal viper
#

Maybe it's just being disabled?

umbral bough
#

moved the camera away and it's disappearing again

steel herald
#

:(