#💻┃code-beginner

1 messages · Page 89 of 1

rich adder
#

you literally know what assigning is lol

#

where is the miss

muted wadi
#

DiscThrow

polar acorn
muted wadi
#

DiscThrow throwB

#

am i wrong?

summer stump
muted wadi
#

damn

polar acorn
rich adder
# muted wadi damn

references are literally just telling the computer where to look for a particular thing .. if you don't its null..

muted wadi
#

how would I tell it which one it is

polar acorn
teal viper
#

Need to learn about declaration/definition/initialization. Basically, go through C# basics...

summer stump
rich adder
#

without actual some basic c# this will just go in one ear and out the other (figuratively ofc)

muted wadi
#

DiscThrow will only ever exist on one object so

summer stump
#

Yes, but that is the WORST way to do it.
Dragging the object into the inspector would be better if it exists before you click play

polar acorn
rich adder
#

not-informed yet*

strong path
#

so ive replaced "anim.Play" with animator.SetBool()

[SerializeField] public GameObject player;
    [SerializeField] private Animator anim;

    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject == player)
            animator.SetBool("Collision", true);
            Debug.Log("Called");
            
    }```
#

now i get this error

#

(13,13): error CS0103: The name 'animator' does not exist in the current context

strong path
muted wadi
#

is there something im missing?

summer stump
polar acorn
strong path
#

wdym

polar acorn
#

what is animator

muted wadi
#

i already knew that's what serialising does

strong path
rich adder
polar acorn
summer stump
muted wadi
#

honestly im still lost as to what im doing wrong

rich adder
summer stump
rich adder
muted wadi
#

serialising a private variable means i can protect that variable AND have it appear in the inspector, right?

eternal falconBOT
polar acorn
strong path
muted wadi
#

so what am i missing?

polar acorn
summer stump
rich adder
#

thats the true importance of reason

summer stump
strong path
polar acorn
#

where do you make it

#

where do you assign it

muted wadi
summer stump
rich adder
muted wadi
#

sorry could you remind me what serialising means again

rich adder
polar acorn
#

you just said what serializing is

#

Are there two people using your discord account or what

rich adder
#

lol

summer stump
#

I think it was sarcasm?
That confused me too

muted wadi
#

no please im just really stupid

strong path
rich adder
#

its just a fancy word for putting everything in order

polar acorn
#

that you are trying to use

#

where did you make it

rich adder
#

in unity it exposes stuff in the inspector when its done so

polar acorn
#

where did you assign it

#

does it exist

#

did you make it

#

show where it is

summer stump
muted wadi
#

so serialising just makes it appear in the editor?

rich adder
muted wadi
#

thank god i finally got that right

rich adder
#

serializing is done outside of unity as well but nothing you should worry about now

#

it just puts everything in order so the code can be stored

strong path
polar acorn
#

now

#

where did you make that variable

strong path
#

I DONT KNOW

polar acorn
strong path
#

I TOOK THAT LINE FROM MY OTHER CODE USING BOOLS

summer stump
strong path
#

my other code works like this

public CharacterController2D controller;
    public Animator animator;

    public float runSpeed = 40f;

    float horizontalMove = 0f;
    bool jump = false;

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

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

        animator.SetFloat("Speed", Mathf.Abs(horizontalMove));

        if (Input.GetButtonDown("Jump"))
        {
            jump = true;
            animator.SetBool("IsJumping", true);```
strong path
#

shit

summer stump
#

How it says animator

strong path
#

im sorry

polar acorn
#

and you do not in the other one

muted wadi
#

oh i just remembered why i didn't assign newBall a value in the ThrowDisc script through the editor. Its because in the ThrowDisc script, newBall is assigned the value of an instantiated object, so I have to leave it empty through the editor because it gets assigned when the ball is actually instantiated.

#

does that make sense?

#
{
    isReturning = false;
    throwReady = false;
    newBall = Instantiate(discPrefab, discSpawn.position, cam.transform.localRotation);
    ballRB = newBall.GetComponent<Rigidbody>();
    ThrowBall(newBall);
}```
rich adder
#

cause ur error was never newBall

#

newBall has nothing to do with your error

polar acorn
rich adder
#

newBall assignment was just the catalyst to the underlying cause

muted wadi
#

oh goddamit

#

my project crashed

strong path
#

YES

#

YES

#

FINALLY

#

SUCH A PETTY MISTAKE OH MY GOD

#

THANKM YOU

muted wadi
#

guys honestly i really appreciate the help

#

im lost in another country with all this

rich adder
# strong path FINALLY

make sure to configure your IDE now cause it shouldve been highlighted from code editor for you

polar acorn
#

!ide

eternal falconBOT
muted wadi
#

also my project just crashes now whenever i try to make the ball move to the items in the list

rich adder
#

recursive spawn i bet

muted wadi
#

its definitely some kind of infinite error loop or something

muted wadi
polar acorn
muted wadi
#

also another question: do i need to specify an end to a coroutine?

rich adder
#

oh you touched something in a coroutine

muted wadi
#

yeah...

polar acorn
muted wadi
#
{
    if (Input.GetKey(KeyCode.Mouse1))
    {
        FireRay();
    }
    else if (Input.GetKeyUp(KeyCode.Mouse1))
    {
        foreach (GameObject go in hitList)
        {
            go.GetComponent<LockedOnVisual>().VisualMarker(false);
            
        }
        bailiffActive = true;
        StartCoroutine(BailiffMove());
        hitList.Clear();

        Debug.Log(hitList.Count);
    }
}

IEnumerator BailiffMove()
{
    throwB.isReturning = false;
    throwB.throwReady = false;
    throwB.newBall = Instantiate(throwB.discPrefab, throwB.discSpawn.position, throwB.cam.transform.localRotation);

    while (bailiffActive)
    {
        if (Vector3.Distance(throwB.newBall.transform.position, hitList[currentHit].transform.position) < 0.8f)
        {
            if (currentHit < hitList.Count - 1)
            {
                currentHit++;
            }
            else
            {
                throwB.RetrieveDisc();
                break;
            }
            float t = 10 * Time.deltaTime;
            throwB.newBall.transform.position = Vector3.MoveTowards(throwB.newBall.transform.position, hitList[currentHit].transform.position, t);
            yield return null;
        }
    }
}```
summer stump
#

Ah, which you do

muted wadi
#

so it will just end at yield return null?

rich adder
#

goes outside the if statement

#

in the while loop

#

cause your code may not ever hit that if statement thus never end the frame

polar acorn
#

Nothing can change so it can never become true to hit the yield

muted wadi
#

wait which condition

strong path
#

can i start a timeline as soon as the bool turns true

rich adder
polar acorn
solemn bobcat
#

You can also break the coroutine with yield break; line.

rich adder
muted wadi
polar acorn
rich adder
#

isn't this the code from earlier ?

muted wadi
rich adder
#

i give u some of this no? note where this is

muted wadi
summer stump
rich adder
#

you're using VS so we can't even blame poor brackets lmao

rich adder
#

so you're stuck forever there

muted wadi
#

oh is the yield return null meant to be outside the if statement

summer stump
#
while (x)
{
  if (y)
  {
    //yield here if you want. Optional
  }
  //yield here definitely
}

rich adder
muted wadi
#

OH

#

okay yeah i see now

polar acorn
# muted wadi im sorry could you explain

Let me put it this way:
You start the while loop.
You check if the distance is less than 0.8
It is not, so you skip to the end of the loop.
You begin another iteration of the loop.
You check if the distance is less than 0.8
It is not, so you skip to the end of the loop.
You begin another iteration of the loop.
You check if the distance is less than 0.8
It is not, so you skip to the end of the loop.
You begin another iteration of the loop.
You check if the distance is less than 0.8
It is not, so you skip to the end of the loop.
You begin another iteration of the loop.
You check if the distance is less than 0.8
It is not, so you skip to the end of the loop.
You begin another iteration of the loop.
You check if the distance is less than 0.8
It is not, so you skip to the end of the loop.
You begin another iteration of the loop.
You check if the distance is less than 0.8
It is not, so you skip to the end of the loop.
You begin another iteration of the loop.
You check if the distance is less than 0.8
It is not, so you skip to the end of the loop.
You begin another iteration of the loop.
You check if the distance is less than 0.8
It is not, so you skip to the end of the loop.
You begin another iteration of the loop.

open veldt
#

Haiii Quick question I need to see if something I’m thinking of will work;

Can classes derived from an abstract class be assigned to a variable with the type of the abstract class?

open veldt
#

LETS GOO

#

Thanks

rich adder
#

the whole point of inheritance

#

lol

open veldt
#

Just had to make sure idk why I thought I saw something that said it can’t

polar acorn
#

And if you need to get to that derived class from the parent class, you can do a checked cast:

if (theAbstractVariable is DerivedClassName derivedVariable)
open veldt
#

Me when the coding solutions hit me while folding laundry

polar acorn
#

It checks if it's that type, and if it is, assigns it to a variable you can use inside the if statement

open veldt
#

Thanks!!

muted wadi
#

my brain must be full of holes

rich adder
#

me trying to learn something like Haskell

summer stump
rich adder
#

it is just breaks my brain sometimes

muted wadi
#

now im getting this error

#

this must be to do with the hitList

rich adder
#

it tells you the line

#

53

#

lockOn

austere monolith
muted wadi
#

@rich adder that line gets the currentHit index from hitList, which is first set to 0

muted wadi
#

if (Vector3.Distance(throwB.newBall.transform.position, hitList[currentHit].transform.position) < 0.8f)

rich adder
#

clear its more than list contains

austere monolith
rich adder
muted wadi
austere monolith
#

ok

rich adder
#

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

rich adder
muted wadi
#

but why is there an error?

summer stump
rich adder
muted wadi
muted wadi
# rich adder send new script
{
    throwB.isReturning = false;
    throwB.throwReady = false;
    throwB.newBall = Instantiate(throwB.discPrefab, throwB.discSpawn.position, throwB.cam.transform.localRotation);

    while (bailiffActive)
    {
        if (Vector3.Distance(throwB.newBall.transform.position, hitList[currentHit].transform.position) < 0.8f)
        {
            if (currentHit < hitList.Count - 1)
            {
                currentHit++;
            }
            else
            {
                throwB.RetrieveDisc();
                break;
            }
            float t = 10 * Time.deltaTime;
            throwB.newBall.transform.position = Vector3.MoveTowards(throwB.newBall.transform.position, hitList[currentHit].transform.position, t);
        }
        yield return null;
    }
}```
#

i haven't changed anything except for the yield return

rich adder
#

where do you set currentHit

#

for the first time

muted wadi
rich adder
#

also you probably are calling this before you do that

#

so there is nothing in list

summer stump
muted wadi
# summer stump show where you do that
private void Update()
{
    if (Input.GetKey(KeyCode.Mouse1))
    {
        FireRay();
    }
    else if (Input.GetKeyUp(KeyCode.Mouse1))
    {
        foreach (GameObject go in hitList)
        {
            go.GetComponent<LockedOnVisual>().VisualMarker(false);
            
        }
        bailiffActive = true;
        StartCoroutine(BailiffMove());
        hitList.Clear();

        Debug.Log(hitList.Count);
    }
}

void FireRay()
{
    RaycastHit hit;

    if (Physics.Raycast(rayOut.transform.position, rayOut.transform.forward, out hit, maxDist, hitLayer))
    {
        if (!hitList.Contains(hit.transform.gameObject))
        {
            hitList.Add(hit.transform.gameObject);

            hit.transform.gameObject.GetComponent<LockedOnVisual>().VisualMarker(true);
        }

    }
}```
muted wadi
muted wadi
#

okay cool

summer stump
#

it's possible for you to NOT put something in hitList, but still run the coroutine and have it check an empty list

muted wadi
#

goddamit

rich adder
#

fun fact when you do publicand [SerializeField] private a list/array Unity already new()

muted wadi
#

thats what i thought the problem was

rich adder
#

still good habit to write it though

summer stump
#

if you hit mouse1, it fires a ray, if it hits something that is NOT in the list, it will add it, then you check the list with no guarentee that it actually hit something

#

just do an if (hitList.length > 0) before checking it

rich adder
#

.Count

#

cause its a list

muted wadi
#

also i would do that before vector3.distance right?

austere monolith
muted wadi
#

just wanna make sure

austere monolith
#

so i dont know where im using Y

rich adder
summer stump
rich adder
austere monolith
#

im nub

rich adder
muted wadi
#
{
    if (hitList.Count == 0)
    {
        if (Vector3.Distance(throwB.newBall.transform.position, hitList[currentHit].transform.position) < 0.8f)
        {
            if (currentHit < hitList.Count - 1)
            {
                currentHit++;
            }
            else
            {
                throwB.RetrieveDisc();
                break;
            }
            float t = 10 * Time.deltaTime;
            throwB.newBall.transform.position = Vector3.MoveTowards(throwB.newBall.transform.position, hitList[currentHit].transform.position, t);
        }
        yield return null;
    }
    yield return null;
}```
#

please tell me i got it right this time

rich adder
#

follow it again, im sure it works there, just skip the Time.deltaTime

muted wadi
#

😭

rich adder
#

you're saying if count == 0 run this

#

nt what i wrotelol

ivory bobcat
muted wadi
#

oh shit

#

i can just do != instead right?

rich adder
#

just use what Aethenosity wrote

summer stump
strong path
#

is there a way for the camera to follow the player without moving its y axis

muted wadi
#

sorry that was just me being tired

austere monolith
muted wadi
#

i promise i at least understand that basic stuff

austere monolith
#

transform.localRotation = Quaternion.Euler(0f, 0f, 0f); instead of having xRotation, 0f, 0f

muted wadi
#

okay so now the ball gets instantiated but it doesn't actually move towards the targets

strong path
#

can two animations play at the same time for the same sprite

#

like this

summer stump
summer stump
strong path
#

oh mb

#

sorry

muted wadi
summer stump
muted wadi
#

oh

#

sorry i know im being a hassle for everyone

gaunt basin
#
void OnCollisionEnter2D(Collision2D collision) { // Collisions
    Debug.Log("Hi");
if (collision.gameObject.CompareTag("bullleft"))
{
    Debug.Log("Hi");
    Destroy(gameObject); 
    Destroy(collision.gameObject); 
}}

Why does this code not work?

#

im trying to make an object collide with an object but imnot getting a debug

muted wadi
#

every time i go to program its like im back to square 0 and know nothing

elder atlas
summer stump
gaunt basin
#

nope

elder atlas
#

does both objects have a collider

gaunt basin
#

Both have a box collider 2d yeah

muted wadi
gaunt basin
#

wait I'll send you the full code

summer stump
muted wadi
gaunt basin
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static UnityEngine.GraphicsBuffer;

public class GhostMovement : MonoBehaviour
{
    public Transform player;
    public Transform leftBullet;
    public float chaseSpeed = 1.3f;
    public float ghostradius = 6.5f;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Vector2.Distance(transform.position, MovementFunc.MovPos) <= ghostradius)
        {
            Vector2 direction = MovementFunc.MovPos - transform.position;
            direction.Normalize();
            Vector2 targetPosition = new Vector2(transform.position.x, transform.position.y) + direction * chaseSpeed * Time.deltaTime;
            transform.position = targetPosition;
        }

        void OnCollisionEnter2D(Collision2D collision) { // Collisions
            Debug.Log("Hi");
        if (collision.gameObject.CompareTag("bullleft"))
        {
            Debug.Log("Hi");
            Destroy(gameObject); 
            Destroy(collision.gameObject); 
        }}

    }
}
muted wadi
#
{
    RaycastHit hit;

    if (Physics.Raycast(rayOut.transform.position, rayOut.transform.forward, out hit, maxDist, hitLayer))
    {
        if (!hitList.Contains(hit.transform.gameObject))
        {
            hitList.Add(hit.transform.gameObject);

            hit.transform.gameObject.GetComponent<LockedOnVisual>().VisualMarker(true);
        }

    }
}``` @summer stump
gaunt basin
#

the collision isnt working at all

elder atlas
#

the OnCollisionEnter2D method should be outside of update

#

they're both monobehaviour broadcasts

gaunt basin
#

ohhhh

#

works thanks

elder atlas
#

np

gaunt basin
#

i wasted 3 hours trying to code an entire physics system >_<

#

its fine though

elder atlas
#

dw you'll spend many hours on dumb issues its just the nature of programming

summer stump
muted wadi
#

wait

#

i might know the issue

#

i have a hitList.Clear right after my BailiffMove coroutine. Could that be called before the coroutine is over or no?

teal viper
#

It could, yes.

muted wadi
#

i'll try and remove that for now

#

holy christ

#

ah of course

#

its in the update function

gaunt basin
#

okay next question, so I have a bullet object, and I've assigned a tag to it and there's code that makes it so that whenever it touches an enemy it sends a line of debug, however its not working

  1. The tag did work on another object (my player character) and the collisions worked perfectly fine
  2. both objects have a box collider 2D

any ideas?

muted wadi
#

i had an issue like this once, send your code if you haven't already

gaunt basin
#
void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.CompareTag("bullleft"))
    {
        Debug.Log("Hi");
        Destroy(gameObject);
        Destroy(collision.gameObject);
    }
}
#

this worked perfectly fine on my player character but didn't work on my bullets

#

code applies to the enemy btw

#

the collisions also work I changed my bullet's sprite to my character sprite and my player is getting pushed back

gaunt basin
#

nope

muted wadi
gaunt basin
#

yeah

#

not sure if the destroying part works but its supposed to debug a line of code thats the part im trying to work out

rotund hull
gaunt basin
#

the collision itself is broken the tag is not

#

ill send a pic of the bullets components and the enemy's 1 sec

rotund hull
#

ok

gaunt basin
#

the bullet's

muted wadi
gaunt basin
#

the enemy's

#

yeah it is

rotund hull
#

just try collision.CompareTag

gaunt basin
#

wym?

#

does this return a collided object?

muted wadi
#

instead of collision.gameobject

rotund hull
gaunt basin
#

the problem isn't with the tag though

#

I added another debug line above the tag comparison and it still doesn't work

#

I added a 2D collider to my player object and gave it the tag and it did work there's just something wrong with my bullet object

rotund hull
#

make sure it is spelled like this OnCollisionEnter2D(Collision2D)

gaunt basin
#

returns an error

muted wadi
#

could it be because its not OnColliderEnter2D

rotund hull
#

it is not

gaunt basin
muted wadi
#

correct me if im wrong but isn't it Collider not Collision

rotund hull
#

i checked on the unity site

#

collision2D needs a name

#

try to give it a name

muted wadi
#

is it collision for 2D and collider for 3D

gaunt basin
#

i named it collision and like i said it didnt work, there's something very strange I wonder if putting it under the player in the hierarchy fixes it though

rotund hull
muted wadi
#

isn't it OnTriggerEnter though?

rotund hull
#

it is but it is like this OnTriggerEnter2D(Collider2D collider)

rotund hull
gaunt basin
#

the code shouldnt be the problem it detects the player when i added a box collider 2d to it

#

i probably made a mistake somewhere down the line

rotund hull
#

can i see the code you have the collsion code in

#

in this

#

!code

eternal falconBOT
gaunt basin
#

OH MY GOD i figured it out

rotund hull
#

what was it

gaunt basin
#

you need to have a rigidbody2d component as well

rotund hull
#

that makes sence

gaunt basin
#

yeah lol

rotund hull
gaunt basin
#

cool thanks

rotund hull
#

no problem

gaunt basin
#

how do you completely block out gravity for the rigid body objects btw?

rotund hull
#

are you making a topdown game

gaunt basin
#

nope a platformer

rotund hull
#

ohhhh

muted wadi
rotund hull
#

sorry

#

no you need it for collsion

#

turn the rigidbody back to dynamiv and set the gravity scale to 0

summer stump
summer stump
rotund hull
#

gravity

muted wadi
#

but that shouldn't be an issue for collisions right?

rotund hull
#

no

#

you just need a rigidbody

#

doesnt matter what you do to it

#

unless its ontriggerenter'

muted wadi
#

strange

rotund hull
#

eyah

#

yeah

muted wadi
#

i guess i haven't used 2D that much

rotund hull
#

i always use 2d

muted wadi
#

fair enough

summer stump
rotund hull
#

oh

boreal tangle
modest barn
muted wadi
summer stump
summer stump
summer stump
#

OHHHH

modest barn
#

Are you meant to be talking to me?

#

Haha

summer stump
#

wrong person

#

lmfao

modest barn
#

You need some sleep

summer stump
boreal tangle
muted wadi
rich adder
summer stump
summer stump
muted wadi
#

god im tired

rich adder
modest barn
rich adder
#

either of these should work

modest barn
#

Ok I'll give them a try.

boreal tangle
rich adder
#

which is base class for the UI stuff

boreal tangle
#

it isnt

boreal tangle
#

oh

summer stump
#

Fix that lol

boreal tangle
#

ok

summer stump
#

I think I will leave haha. Like three mistakes in a row. Sorry for the confusion

modest barn
#

@rich adder

[SerializeField] TMP_InputField secondaryInputField;

private void Start()
{
    secondaryInputField.enabled = false;
}
NullReferenceException: Object reference not set to an instance of an object
#

But I thought that the InputField would be an instance because it's been created in the scene

slender nymph
#

that means you didn't drag the input field into the slot in the inspector

rich adder
modest barn
#

Oh... it was definitely there before as my code uses it, and then I renamed the GameObject. I thought that Serializing fields protected issues with renaming? Oh well, I dragged it back in

boreal tangle
#

can you tell me

rich adder
#

look for a moment what this is doing when you jump ```cs
rb.velocity = new Vector2(horiMovement * movementSpeed, rb.velocity.y);
if (toJump)
{
rb.velocity = new Vector2(rb.velocity.x, 5);

 toJump = false;

}```

queen adder
#

can someone explain me what Mathf.Atan2 is

rich adder
#

code runs top to bottom btw

boreal tangle
#

ik

rich adder
queen adder
verbal dome
boreal tangle
#

I dont see it. toJump should be false and the keys should act as normal

rich adder
#

= radius

rich adder
#

very smart people thought its better to get angles this way

queen adder
verbal dome
# queen adder yes

You can just do Vector3 direction = lookPosition - transform.position
Where lookPosition could be camera.ScreenToWorldPoint(Input.mousePosition), for example.

queen adder
verbal dome
#

Then do transform.right = direction
Or transform.up/.forward depending on your game

boreal tangle
rich adder
boreal tangle
#

what do you mean by one frame bool

rich adder
boreal tangle
#

When I press the UpArrow the player jumps. I used the input manger horizontal axis for horizontal movement and when I press the keys for left and right the player does not go left or right.

ivory bobcat
#

You're overriding velocity. So if you aren't pressing forward anymore, it'll completely stop relative to the x component.

#

If you're pressing right and left but it isn't moving, likely your keyboard might be limited.

boreal tangle
#

even if I contiue to press left or right the palyer doesnt move after jumping

ivory bobcat
#

Are you pressing more than one key?

boreal tangle
#

no

ivory bobcat
boreal tangle
#

ok il check

modest barn
#
The referenced script (Unknown) on this Behaviour is missing!

Is there a way to find out where this is happening?

gaunt ice
#

script was renamed/the script was edited in play mode

modest barn
#

Oh I was in play mode 😂

#

Oops

wanton hearth
#

I think I'm going insane? Why is this giving errors?

slender nymph
#

put it inside of a method

wanton hearth
#

who would've thunk it...

gaunt ice
#

btw are you having two monobehaviour on one script?

wicked cairn
# wanton hearth who would've thunk it...

in addition to his answer. if you dont want it in a function and need it to be that number by default you would have made the original longer like public int testInt = 1;

wanton hearth
wicked cairn
#

with just public TheOtherScript something; then in a function youd do something.testFunction();

wanton hearth
#

Yeah, I know about it, thanks.

floral bloom
#

hey i got a if statement that loops anyone able to assist me?

floral bloom
#

i have it so when i press tab and bool is false it opens then bool turns to true
and another else if statement for when its true
but pressing tab loops both and i get 50 logs for each if statement

gaunt ice
#

are you using getKey not getkeydown or up?

floral bloom
#

lol

#

yes

floral bloom
#

ffs

#

you were right

#

is there any good books for learning unity code, im getting nothing from watch videos

rich adder
#

ups

floral bloom
rich adder
#

thats good

#

keep doing it

summer stump
#

There are also resources pinned on this channel.
Catlike coding is good

floral bloom
#

ill give them a look tysm

formal escarp
#

hey guys sorry dumb question but im not trolling.

#

Destroy(gameObject); will destroy the gameObject alright. Destroy(transform.parent.gameObject); will destroy the parent, but what if you have an empty object por example, a child, and a child of that child like. you can also destroy the "grandparent" (name is dumb but not sure what it would be called)

cosmic dagger
#

honestly, i read rb whitaker's beginner and intermediate c# tutorials. i was good after that . . .

timber tide
#

pretty much grandparents, ect

cosmic dagger
formal escarp
# timber tide pretty much grandparents, ect

They are a totally different thing right? and that would mean you need to make another call to destroy it (although, i do not want to destroy it but im just curious as im experimenting with destroying children and parent)

summer stump
#

Oh, did you mean the other direction?

formal escarp
#

but i was wondering how it would go if i wanted to destroy the "FolderItem" out of curiosity.

summer stump
#

It would destroy everything

formal escarp
#

and what is the name of that in the case.

timber tide
#

chopping the root will usually just kill it all

formal escarp
timber tide
#

oh yeah you can use tree terminology too if you want ;)

summer stump
#

Grandparent is usually what it's called. Or root if there are no parents beyond it

timber tide
#

root, leaf, branch

formal escarp
#

i mean.

formal escarp
#

i did not wanted to kill the "main thing" just the smaller ones.

summer stump
summer stump
formal escarp
summer stump
formal escarp
#

The "Item" has a rigidbody and gravity, if i put on "IsTrigger" too it breaks and goes underground. So i had to add a child to the "Item" and give THEM the "IsTrigger"

summer stump
#

Do you want to preserve Trigger? You'd have to reparent it

summer stump
formal escarp
cosmic dagger
summer stump
formal escarp
formal escarp
summer stump
#

You wouldn't be able to differentiate them though. That is why people often stick them on children with their own scripts.
(Like one for sight, one for hearing, etc)

formal escarp
#

thats cool

#

thanks for the info man.

proper flume
#

!code

eternal falconBOT
proper flume
#

Does anybody see anything in my code that might make me fall through my floor? I keep collision with it like 90% of the time, but certain triggers like jumping too high, or colliding with the sides of objects makes my player fall right through. https://gdl.space/opuxeceril.cpp

proper flume
#

For the floor or my character? I tried adding a rigidbody to the plane, but it says that the plane mesh isn't compatible since Unity 5.

summer stump
proper flume
summer stump
#

And interpolate to interpolate (instead of none)

proper flume
#

That worked! Thanks. I'm still going through the Learn.Unity.com stuff and this is supposed to be my "project." When they explained how to set up a side-scroller none of that was mentioned though. 😅

summer stump
#

Also put Move() in FixedUpdate()

summer stump
#

it is more of an issue if moving kinda faster. As you saw it wasn't ALWAYS an issue

proper flume
#

Ah, that's a good knowledge. I appreciate it.

craggy bane
#

Hello I'm trying to make a quest goal script

#

This is my script

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class QuestGoal : MonoBehaviour
{
  public GoalType goalType;
  public int requiredAmount;
  public int currentamount;

  public bool IsReached()
  {
    return (currentamount >= requiredAmount);
  }
  public void GatheredTrash()
  {
    if (goalType == GoalType.Gathering)
    currentamount++;
  }
}

public enum GoalType
{
    Gathering,

    
}

#

i want it to show up like this

wintry quarry
craggy bane
cerulean crypt
#

In a 2d game, what's the best object to detect collision but not to bump into other objects? I'm kinda new to collision stuff

craggy bane
#

I added the goal but I want it so that each time I click plastic the current amount goes up but it isn't

summer stump
cerulean crypt
#

Yh, Imma use the isTrigger var, thanks!

summer stump
craggy bane
#

i have an event system

#

but I don't think i subcribed to the callback

#

can you teach me how?

summer stump
craggy bane
summer stump
craggy bane
#

Mhm

summer stump
#

Which object has the script with this code?

craggy bane
#

Player

#

W guess

summer stump
#

Ok, so click the plus right there

#

And drag the player object into the new box

craggy bane
#

is this what I'm supposed to do?

summer stump
#

Yep!

craggy bane
#

Thanks

summer stump
#

If picktrashup is what you want of course haha

craggy bane
#

wait

#

Nevermind

#

I want the current amount to go up by 1

#

I need to add this after the onclick function right?

#

OH nevermind it works now

true heart
#

i have a list of strings and i was wondering if i wanted to find out what string was placed 1st or 2nd item of the list how woudl i do that

summer stump
true heart
#

oh i see

summer stump
#

not sure I fully understood though. Is that what you wanted?

true heart
#

well im trying to have a for loop that checks all items and then summons a prefab for each so i could use mylist[i] to find what each thing has

#

i think that woudl work maybe

summer stump
cerulean crypt
rocky gale
#

https://hastebin.com/share/unuxesajen.csharp hi im making a tower defense game and this script is in the tower. i need help because whenever i place a tower (or multiple it doesnt matter) after a while the tower will just stop doing damage to the enemy. it still has the enemies that it is attacking in the list of enemies in range, but it doesnt attack it. there are no errors so i dont know whats wrong

nimble scaffold
#

Hey can anyone help me with the problem that to switch a camera with right click ... The code worked but in game view it's saying no camera found but all things are attached to the script

#
using UnityEngine;

public class CameraSwitch : MonoBehaviour
{
    public Camera mainCamera;
    public Camera secondaryCamera;

    void Start()
    {
        // Ensure only the main camera is active initially
        mainCamera.enabled = true;
        secondaryCamera.enabled = false;
    }

    void Update()
    {
        // Check for right mouse button press
        if (Input.GetMouseButtonDown(1)) // 1 represents the right mouse button
        {
            // Switch between cameras
            mainCamera.enabled = !mainCamera.enabled;
            secondaryCamera.enabled = !secondaryCamera.enabled;
        }
    }
}

code not working its saying that display 1 no camera found

slender nymph
#

you should consider using cinemachine

nimble scaffold
#

Now I have given the comments also

#

So that's u all can understand

#

And pls help me

nimble scaffold
true heart
slender nymph
nimble scaffold
#

Is there anything wrong with the code?

slender nymph
#

i have 1 single camera in my scene, but i can switch the view by simply enabling/disabling different virtual cameras and cinemachine does the hard part of transitioning between them for me

slender nymph
summer stump
slender nymph
#

by using cinemachine and enabling/disabling different vcams

nimble scaffold
#

Can you please provide me the code

summer stump
true heart
#

ya im trying to find what item has the same tag as an item name on the list then instantiate it. so if how i wrote it dont work how would i go about that

summer stump
true heart
#

oh should so i shouldnt use a list of strings

nimble scaffold
#

So is it good for switching between my nirmala fps cam and sniper gun cam? And do I also need to change the normal fps cam to cinemachime

true heart
#

ican just make a list of gameobjects straight away i see

summer stump
#

Do you have multiple objects with each tag?

true heart
#

no not really i wanted to connect all of them to a gameobject

#

na

#

all have there own tags

summer stump
#

Then yeah, I guess not.
But I recommend avoiding using Find at all honestly

true heart
#

oh really is it laggy or something

summer stump
summer stump
summer stump
true heart
rocky gale
#

https://hastebin.com/share/unuxesajen.csharp hi im making a tower defense game and this script is in the tower. i need help because whenever i place a tower (or multiple it doesnt matter) after a while the tower will just stop doing damage to the enemy. it still has the enemies that it is attacking in the list of enemies in range, but it doesnt attack it. there are no errors so i dont know whats wrong

summer stump
true heart
cerulean crypt
cerulean crypt
summer stump
#

Also, your !IDE is not configured

eternal falconBOT
cerulean crypt
summer stump
cerulean crypt
#

What fixed it was using OnTriggerEnter2D. I'm assuming it assumes 3D?

summer stump
#

not just an assumption

cerulean crypt
#

Sorry yh that's what I meant

#

Anyway thx for the help

summer stump
#

It is a little confusing that there are the two alternatives but only one is named. It's the same with multiple things like colliders and rigidbodies and whatnot

nimble scaffold
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraScript : MonoBehaviour
{

    public GameObject Camera1;
    public GameObject Camera2;
    public GameObject Camera3;


    void Update()
    {
        if (Input.GetKeyDown("1"))
        {
            CameraOne ();
        }

        if (Input.GetKeyDown("2"))
        {
            CameraTwo ();
        }

        if (Input.GetKeyDown("3"))
        {
            CameraThree ();
        }
    }

    void CameraOne()
    {
        Camera1.SetActive(true);
        Camera2.SetActive(false);
        Camera3.SetActive(false);
    }

    void CameraTwo()
    {
        Camera3.SetActive(false);
        Camera2.SetActive(true);
        Camera1.SetActive(false);  
    }

    void CameraThree()
    {
        Camera3.SetActive(true);
        Camera2.SetActive(false);  
        Camera1.SetActive(false);
    }
}

Will this code work?

summer stump
#

Also, seems like you do an early return in update if EnemyStats is null. That may be the issue. Naaah, the physics message would still get new ones. So that isnt it

rocky gale
nimble scaffold
#
using UnityEngine;

public class CameraScript : MonoBehaviour
{
    public GameObject Camera1;
    public GameObject Camera2;

    void Start()
    {
        
        Camera1.SetActive(true);
        Camera2.SetActive(false);
    }

    void Update()
    {
        if (Input.GetMouseButtonDown(1)) 
        {
            SwitchCameras();
        }
    }

    void SwitchCameras()
    {
        if (Camera1.activeSelf)
        {
            Camera1.SetActive(false);
            Camera2.SetActive(true);
        }
        else
        {
            Camera2.SetActive(false);
            Camera1.SetActive(true);
        }
    }
}

Guys pls say will this code work or not

summer stump
#
  1. EnemyStats should have its own TakeDamage(float damage) method and update its own health probably. Separation of concerns can be very helpful.

  2. I would throw a debug in there to check the isDead value of the enemy to see if that's part of the issue

summer stump
nimble scaffold
#

I'm in my mobile rn

rocky gale
summer stump
nimble scaffold
#

Okay

#

Sir

summer stump
rocky gale
craggy bane
#

hi how do I make a text popup after completing a quest?

summer stump
summer stump
craggy bane
summer stump
craggy bane
#

Yeah

rocky gale
summer stump
# craggy bane Yeah

So, you can go that way, with ui elements there but disabled, then enable them at the right time. Or you can go another route where you Instantiate a ui element at the right time.
It depends. I usually do a combination.
For example, I have a panel that would pop up, and I would write custom text in it, and maybe create some icons

craggy bane
#

because everytime you complete the popup comes up

summer stump
summer stump
rocky gale
rocky gale
#

i think im gonna try doing what you said of handling the damage in the actual enemy maybe that will fix it

summer stump
rocky gale
#

alr ill try thx for the help\

rocky gale
summer stump
#

Ohhhhh. I bet I know the issue

#

You called break early on some condition (can't remember)

#

It must have broken there, and then never got to the part where you set the bool false again, and this could not start another attack

rocky gale
#

ohhhhh

#

that makes sense

#

yea i honestly have no idea why i had that in there

craggy bane
#

error CS0103: The name 'Completed' does not exist in the current context

#

how do I fix this

#

boolean?

summer stump
#

So you have to make it

#

Did you make a variable called Completed you are expecting to use? It may be local or something, or you forgot to make it

craggy bane
#

I want it to popup after finishing the quest

summer stump
craggy bane
summer stump
#

The like a TMP_Text or a GameObject or a Canvas or something

#

Depends on what you want

craggy bane
#

so I added this

#

public void CompleteQuest()
{

Completed.SetActive(true); 

}

#

in the complete quest script

#

how do I make it popup after the quest tho it has an animation

violet verge
#

I cannot get my bullets to damage my enemies. Unity 2D project.

public class Projectile : MonoBehaviour
{
    public int Damage;
    public float Speed;
    public Rigidbody2D rb;
    public SpriteRenderer spriteRenderer;



    public void SetProperties(int damage, float speed, Vector3 direction, Sprite skin)
    {
        this.Damage = damage;
        this.Speed = speed;
        spriteRenderer.sprite = skin;

        rb.velocity = direction * speed;
    }

    public void SetLayer(int layer)
    {
        gameObject.layer = layer;
    }

    private void OnTriggerEnter2D(Collider2D hitInfo)
    {


        if (hitInfo.gameObject.CompareTag("Enemy"))
        {

            IDamage damageable = hitInfo.GetComponent<IDamage>();
            if (damageable != null)
            {
                damageable.takeDamage(Damage);
            }

            Destroy(gameObject);
        }


    }```
slender nymph
#

also consider using TryGetComponent instead of GetComponent immediately followed by a null check, TryGetComponent does both all in one line and also has the added benefit of not allocating garbage when a component isn't found in the editor

violet verge
#

yea

#

yes when they hit the enemy they dissapear.

slender nymph
#

if there isn't any other code that destroys them, then the issue is that the objects they are hitting have the right tag but do not have an IDamage component

violet verge
#
public class EnemyAI : MonoBehaviour
{

    [Header("--------EnemyStats-------")]
    public float Speed;
    public int Health;

    [Header("-------Components-------")]
    public AudioSource EmoteSource, WeaponSource;

    private Transform playerTransform;

    // Start is called before the first frame update
    void Start()
    {
        GameObject player = GameObject.FindGameObjectWithTag("Player");
        if(player != null)
        {
            playerTransform = player.transform;
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (playerTransform != null)
        {
            MoveTowardsPlayer();
        }
    }

    void MoveTowardsPlayer()
    {
        // Move towards the player's position
        transform.position = Vector2.MoveTowards(transform.position, playerTransform.position, Speed * Time.deltaTime);
    }

    public void TakeDamage(int damageAmount)
    {
        Health -= damageAmount;
        if (Health <= 0)
        {
            Destroy(gameObject);
        }
    }
}```
slender nymph
#

this does not implement IDamage

violet verge
#

ahh

ivory bobcat
#
Debug.Log($"{name} hit {hitInfo.name}", hitInfo);```
violet verge
#

Thank's guys.

topaz gorge
#

oh AI class

#

i would still disable

#

if your gonna be respawning them

vernal bronze
#

Hey guys newbie here with 0 scripting experience so I copied one online to make my lights flicker. Only have a single error and was wondering how I could fix it. here is the script and the error:

topaz gorge
#

its not in a class

slender nymph
eternal falconBOT
topaz gorge
vernal bronze
topaz gorge
#

also post code in !code

eternal falconBOT
summer stump
topaz gorge
summer stump
queen adder
#

notepad code 👑

topaz gorge
queen adder
#

Should loosely explain what a class is for you

queen adder
#

Microsoft Word maybe

topaz gorge
#

took 3 hours to get hello world to work

queen adder
#

no shot

topaz gorge
#

and dont forgot the all good google docs

#

the custom highlighting and stuff is endless

vernal bronze
slender nymph
eternal falconBOT
#

:teacher: Unity Learn ↗

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

topaz gorge
#

pretty much that

queen adder
#

i thought my paint shtick was pretty neat

topaz gorge
#

its a container really

#

needed to define between different scripts and such

queen adder
#

You may get an error if the name doesn't match the file right

topaz gorge
#

indeed file name must match class name

#

you can have multiple classes in a script but no need to dive into that right now

queen adder
#

networkbehaviours 🥲

slender nymph
topaz gorge
queen adder
#

I didn't know that

topaz gorge
#

neither i

#

oh endless hes saying some unity versions dont give the error

summer stump
#

2022 and newer do not require them to match

topaz gorge
#

REALLY??

slender nymph
#

still can only have a single MonoBehaviour in a file that will actually be able to be added via the add component menu. that requirement also only ever affected adding a component in the editor

queen adder
#

idk i think im still on like 1924 Unity

#

steam powered ide

topaz gorge
#

damn near dood

slender nymph
#

fix your compile errors

#

we've been over this already

#

again, get your IDE configured. nobody here wants to be RoachyVr's Personal Spell Checker™️

#

well good luck. i won't be helping you any further since you don't want to get visual studio configured. and considering #854851968446365696 specifically says "[Don't] Give answers to users without an IDE configured*.⠀🠖 Get them to configure it first." you probably won't be getting help from any other regulars until you do so 🤷‍♂️

#

you've been given the guide and were instructed on what to try after completing the guide. if you're still having trouble with some part of that then you need to fucking say what it is.
i don't enjoy fishing, so i'm not going to go fishing to find out what you're having trouble with

#

so you don't know which part of the configuration guide you are stuck on? then how the fuck is anyone else supposed to know?

quartz anvil
#

Anyway to Generate 3D Perlin Noise without going to github? I'm kinda supprised Mathf doesn't have a method for 3D perlin noise.

slender nymph
#

afaik there is not a built in way. there seem to be plenty of guides for implementing it yourself though

somber herald
#

I need help, it never calls Sprint()

#

it prints nothing in console

#

and trust me I am in play mode

slender nymph
#

are you sure you have an active instance of that component in the scene?

somber herald
#

yeah ive been editing it and getting output

#

but this one line wont output for some reason

slender nymph
#

there are only a couple reasons that Sprint would never be called, either you haven't saved your code, the component or its gameobject is not active, or you are receiving an error. your console does not appear to have any errors though so it's gonna be one of the first two

somber herald
#

so I put a print statement above the function

#

and it did work

#

i deleted the print statement and now it works

#

but it still won't execute the code inside the function even though I am pressing left shift

somber herald
slender nymph
#

you're calling it every frame. so for one frame it uses the sprintMultiplier and the next frame it will not

somber herald
#

ooooh

slender nymph
#

GetKeyDown is only true the first frame you press a key

somber herald
#

I see ty!

queen adder
#

!code

eternal falconBOT
queen adder
#
    void OnCollisionEnter(Collision2D collision)
    {
        //Check if player
        if (collision.gameObject.CompareTag("Player"))
        {
            //delete myself
            Debug.Log("Player Detected");
            Destroy(gameObject);
        }
    }
#

this code looks right, but for some reason this is never called. I feel that im missing something obvious in my game but I don't know what. Both the player and the enemy have a box collider 2D

slender nymph
ivory bobcat
#

You're probably wanting the 2d variant

normal arrow
#

Hi ! I'm looking for a way to call a function when the user press and hold 2 input for 2s.
I've found the "hold" system in the input action manager but i can't find a way to tell unity "Do this function when both of theses input action are triggered"

thank's !

queen adder
slender nymph
#

no, see the link i posted

queen adder
#

ooooooohhhhhhhh i see what you mean

#

it worked immdiately smh

#

thank you!!!

somber herald
#

If I put a line of code with some calculations in Update, it should reach FixedUpdate fine right?

#

if I put like

  totalMaxVel = playerMaxVelocity + sprintVal;
#

in update, fixedUpdate will receive that value by the time it gets to it right?

slender nymph
#

as long as totalMaxVel is a class-level variable or property then it will be accessible in FixedUpdate. just keep in mind that on frames where FixedUpdate runs it happens before Update so you'd get last frame's result of that math, but for most things (like this) that shouldn't be a problem

somber herald
#

would it be better practice to just calculate this in fixedupdate too or should I just keep it in update?

slender nymph
#

if the only place you need the value is FixedUpdate then it can just be a local variable in FixedUpdate instead of a field

somber herald
#

I think I found a better way to do this whole thing anyways but will keep in mind while I keep writing ty

#

i'm getting this error

verbal dome
somber herald
verbal dome
somber herald
#

I'm super confused cus I don't see sprintVal at all

verbal dome
somber herald
#

i think HotReload might be messing up my Unity or something's wrong with my editor orrr im missing something and im stupid

#

i thought MissingException was super vague and a common exception so i assumed it'd yield nothing

slender nymph
#

yeah that's 100% caused by hot reload not actually reloading the code

verbal dome
#

Ah. I have heard that HotReload can cause problems

somber herald
#

ironically i don't know how to disable it or fix it

slender nymph
#

exit play mode, make a change and save your code so unity recompiles it, then you should be able to use it just fine.
if for some reason that does not work, restart the editor

somber herald
#

I just restarted the editor but same issue

#

ill do it again though since i dont see the hot reload ui

#

oh yeah hot reload has a recompile button in case of stuff like this

#

ya works now ty!

somber herald
#

is using physics.raycast downward every frame bad for performance

#

should I find a better way

#

i'm trying to smartanimate a foot to know when its touching the ground

slender nymph
#

no, but you should use the profiler if you have performance concerns so you can address what is actually impacting performance

somber herald
#

oh how do I get that?

slender nymph
queen adder
#

How do I solve this Gradle Build Failed to make an android build? My project version is 2021.1.19f1

slender nymph
neon ivy
#
public abstract class ScriptableSingleton<T> : ScriptableObject where T : ScriptableObject
{
    public static T Instance { get; protected set; }

    public abstract void SetInstance();
}

I would like SetInstance() to not be abstract but I can't find a way to do the usual Instance = this in the abstract class that gets inherited. (for a wild guess I tried Instance = T but that doesn't work) is there a way to do it or do I have to have SetInstance() be abstract and have the scriptable object inheriting this override it?

slender nymph
#

Instance = (T)this;

neon ivy
#

ah thanks

bold nova
#

Can someone explain the logic behind creating a staic instance? We create a static copy of the same class inside the class? Why cant we just make the class static?

slender nymph
neon ivy
slender nymph
#

ah right, you want to constrain to ScriptableSingleton<T> not just ScriptableObject

neon ivy
#

oooh the where : ScriptableObject is wrong

#

thanks :D

#

I can't believe this actually works xD

slender nymph
#

i feel like a singleton SO is a bit cursed though. wouldn't a serialized reference to an SO asset not be a better option?

neon ivy
#

it would probably be better, I'm just learning stuff

slender nymph
#

also unless you are creating the instance at runtime, isn't there the possibility that the SO asset won't even be included in a build if you aren't referencing it by anything else that is included in it?

eternal needle
neon ivy
# slender nymph also unless you are creating the instance at runtime, isn't there the possibilit...

I'm calling SetInstance from a script so something has a reference to it. it's mostly for me to create libraries of classes in scriptable objects, like a list of CharacterData in which I can look up an npc's ID and get their information. I'm sure there's a better way to do it but I enjoy having a scriptable object for this and didn't want to create a reference to the scriptable object whenever I want to get some data from it

delicate notch
#

Hi guys why does it say this ?

#

when I open it shows it

#

oh wait i think i found somethin

#

This is the issue I got an error
FindObjectOfType<GameSession>().ResetGame();

#

on this

nimble scaffold
#

Guys I planned to launch sniper scope function in later update in my game

queen adder
#

shader scopes are cool too

#

you can distort the lens

proper flume
#

I'm trying to get started on the jump part of my PlayerController script but my Public isGrounded value isn't showing true when my player is on the ground. ( already tagged as ground.) Did I mess up on my script? It's my first time using ||. https://gdl.space/icuxafusaw.cs

fossil drum
keen dew
#

OnCollisionEnter is a 3D method but this seems to be 2D. You need to use OnCollisionEnter2D instead

real dome
#

yo yo guys sorry if this is like NOVICE and im butting in but euler and quaternion angles scare me... im trying to flip an object by making the y scale -1 when the object (which always rotates to follow the players cursor) surpasses the y axis into the 2nd and 3rd quadrants of the unit circle.
y scale is -1 between 90 and 270, and y scale is 1 all else
https://gdl.space/jogayiviku.cpp
the program however only registers between 0-90 as 1 and all else is -1, its probably a really simple fix but i cant figure it out for the life of me guys 😭

verbal dome
#

You could put zRotation into a -180...180 range with this: cs zRotation = Mathf.DeltaAngle(0, zRotation);

real dome
#

would i put that just below

#

float zRotation = rb.transform.localRotation.eulerAngles.z;

verbal dome
#

Yep

real dome
#

it WORKS

#

great HEAVENS thank you so very much i felt so stumped man

verbal dome
real dome
#

i DEFINETELY should have done that

#

im not quite sure why i didnt as ive done that before like wth

#

i think i was over relying on the values the unity editor gave me

#

trying to make connections between the values during runtime and out

#

either way though im a silly clown 🤡

real dome
verbal dome
fickle plume
#

@real dome no off-topic media, please

verbal dome
#

But yeah sounds like you got it right

real dome
#

OK i think ive got it

#

again thanks so much for helping me out and having the patience to explain it does make sense now

verbal dome
#

The thing is that multiple different euler angles can be used to represent the same rotation

#

No problem

real dome
#

as in like uhhh

#

30, 390, 750, etc?

ivory bobcat
#

It might be -180 to 180

#

I don't recall the exact numbers

verbal dome
#

@real dome That yeah, but there are worse examples where you switch up every axis and the rotation is the same

real dome
#

i think ill stick to single axis rotation for now

#

i reckon thats a problem for future me to tackle

verbal dome
#

Yeah you are in 2D so you don't need to worry about this that much

#

Okay I got one example, (90, 0, 0) is the same as (90, 90, 90) 😵‍💫

real dome
#

Why did I ever leave unity2D...

#

Wait uhhhhhh

#

Consider that I'm in a 3d environment

#

If I decided to add or subtract 180 to the x rotation for a smoother transition instead of y scale -1

#

Would there be collateral y rotation movement?

verbal dome
#

Don't think so, you can always try it out

#

The best way is to keep your angles in variables, instead of just storing in/reading from euler angles

proper flume
#

Unity is gaslighting me. Is there anything wrong with my script? My player won't jump, but the bool for isGrounded still gets tripped to false, and I see my debug message. https://gdl.space/wupirazocu.cs

verbal dome
#

You can solve it by keeping the current Y velocity:cs playerRb.velocity = new Vector2(horizontalInput * speed, playerRb.velocity.y)

proper flume
#

UGH. That makes so much more sense, considering I would have needed to change direction midair too. You're a lifesaver. I am STRUGGLING over here lol.

verbal dome
#

Also make sure that this doesn't get called multiple times:cs Physics.gravity *= gravityModifier;
For example, if you load a new scene with a new player object

#

Gravity would keep being multiplied everytime

#

Oh, also use Physics2D.gravity or it won't effect your 2D objects

proper flume
#

Well, I'm not too worried about that. This is a one scene demo, and it's just supposed to be for the learn.unity lab. Also, using that new line of code says rb does not exist in this context (CS0103) I tried changing the rb to my playerRb.velocity instead and that said that it can't use my horizontalInput as a modifier with Vector2 because it's a float var.

verbal dome
#

Not sure about the second error/issue tho...

#

Oh.

languid spire
#

playerRb.velocity.y

verbal dome
#

Yep, I edited

proper flume
verbal dome
#

This might not fix the issue, but call HorizontalMovement() from FixedUpdate instead of Update

#

FixedUpdate is where you should do physics related stuff

proper flume
#

Huh. Well that didn't fix it, and now my cube is floating above the ground, rather than dropping to it.

verbal dome
#

Send updated code

tribal minnow
#

hey guys i need help with making a character sit on a chair, i already have the sitting animation i just need help making the character sit exactly on the chair.

verbal dome
#

You can modify animated transforms in LateUpdate

proper flume
verbal dome
tribal minnow
verbal dome
#

Revert back and do that

verbal dome
#

Using transform.position and transform.rotation on either the root bone or the root transform

proper flume
# verbal dome Revert back and do that

OHHHHHHHHHHHHHHHHHHH. So, I wasn't able to call playerRb.velocity for my jump, because I forgot to make the horizontalInput a NEW vector. Gotcha, gotcha.

tribal minnow
verbal dome
verbal dome
#

That should be all

proper flume
proper flume
#

WHEW. Problem solved lol. My lil buddy is jumping now. I appreciate your help.

reef pasture
#

hao can i Debug.log in unity dots?

#

in dots code, it seems "'Debug' does not contain a definition for 'Log'"

eager elm
shell herald
#

i want the marked Instanciate code to only activate on a 70% probability, how do i do that?

eager elm
verbal dome
#

Alternatively, Random.value

slender nymph
#

in this case you can just use Random.value instead of Random.Range

shell herald
#

thx

bleak vale
#

Why do I get transform child out of bonds error

#

Even when I want to execute this function when the transform child isnt null

verbal dome
#

Better to use serialized references instead of relying on stuff like hierarchy or naming

bleak vale
#

@verbal dome can u give me a normal answear instead of just sending me a link?

#

Like what should I change?

#

Its like u would ask your partner how do you look and he/she would send you a link to a fashion tutorial :/

verbal dome
#

Use fields with [SerializeReference] and assign them by dragging them in the inspector

bleak vale
shell herald
#

i wanna see in realtime how a float value changes, can i simply do "Debug.log(floatparameter)" and display that in the console? or would that not work

bleak vale
#

that I send you

#

If u want to actually help ppl than try to help them instead of sending a link :/

verbal dome
#

Why are you acting so entitled?

bleak vale
#

Because I cant seralize reference

verbal dome
#

How does the script tell me that?

#

Anyway, maybe someone else will help you. I don't deal with entitled kids

bleak vale
verbal dome
#

Welcome to programming. Get used to reading.

bleak vale
bleak vale
#

col.transform.childCount > 0

#

That was the answear mate

languid spire
bleak vale
#

The lots of stuff is if (weaponHolder.GetChild(0).gameObject != null)
{
GameObject weapon = weaponHolder.GetChild(0).gameObject;
Destroy(weapon);
}

verbal dome
bleak vale
#

If its lots of stuff that u dont know nothing about that good luck for you

bleak vale
#

"Dad, why grass is green?"

  • "Here child, you have a thick book about genetics"
languid spire
# bleak vale If its lots of stuff that u dont know nothing about that good luck for you

No, the lots of stuff is

 Transform player = client.PlayerObject.transform;
 Transform holder = player.GetChild(1).GetChild(1);
 Transform weaponHolder = holder.GetChild(0);
 Transform structureHolder = holder.GetChild(1);
 Transform spellHolder = holder.GetChild(2);
 Transform potionHolder = holder.GetChild(3);

and as we know nothing about your hierarchy we and you cannot know what those result in

bleak vale
#

"Dad, but I asked just simple question"
"Stop whining kid"

bleak vale
#

And exacly this if (weaponHolder.GetChild(0).gameObject != null)

#

See?

#

Simple line of code

#

Why I have if isnt null but I still get error when gameobject is null

#

That was my question

#

And if u want really to argue about that

#

One of ppl answeared me

#

With simple answear

#

That u big brains couldnt do

verbal dome
#

Your issue is fixed(?), you can stop now

shell herald
#

im encountering something i dont understand, its an enemy patrol script and its supposed to move the enemy between two points, but right now, when my enemy arrives at a point, it stops forever and i dont quite understand why

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

verbal dome
#

Changing >= to > and <= to < might do the trick

polar acorn
# bleak vale Simple line of code

Do you know what that line of code means or did you just discover the magic incantation to make errors go away?

What have you learned that might prevent you from having to ask another question in the future?

bleak vale
shell herald
verbal dome
#

Oh wait. cs if(enemy.position.x >= rightEdge.position.x)
I think this should be <=

#

You have >= in both