#๐Ÿ–ผ๏ธโ”ƒ2d-tools

1 messages ยท Page 32 of 1

mortal imp
#

okk

#

And how can i make that teleporting object??

void nebula
#

whoops

#

thats a tough one

mortal imp
#

Damn

void nebula
#

I'll DM you

mortal imp
#

Please

mystic wren
#

hey, I am hoping somebody can help me out with something. I am trying to create a rope in my game that swings but one of the nodes in the array im using sometimes is inside the player. is there a way to prevent the player interfering with the node?

#

if needed, I can provide the code used for the rope system

#

i dont think what i wrote explains it properly so heres a video

hidden quarry
#

I've various cameras, those render onto rendertextures, these I display in a Canvas with RawImages using materials generated off the Hidden/BlitCopy shader - My issue is I have one of those raw images on top of another one and cannot get alpha to work no matter what I try.

Relevant parts:

cam.clearFlags = CameraClearFlags.SolidColor;
cam.backgroundColor = new Color(0, 0, 0, 0);

camrenderTexture = new RenderTexture(w, h, 24, RenderTextureFormat.ARGB32);

rawimage.material = new Material(blitCopyShader);
material.SetTexture("_MainTex", cam.renderTexture);

Am I missing something obvious?

crystal geode
#

is there a way for me to tell the game to use "whatever key left is"?
I want to detect when the user presses left, but obviously the key for that might get rebound, so I don't just want to use the 'A' key

snow willow
#

Input.GetButtonDown("Left")

#

and define the left button in the input manager

#

Either that or in the new input system, use an InputAction

crystal geode
#

ah, okay that input.GetButtonDown is what I needed, I'm dumb ๐Ÿ˜†

#

thank you!

crystal geode
snow willow
#

it's an array

#

if you want to add something

#

then you go to the top and increase the size the array by 1

#

Or I think you might be able to right click and say "add element"

#

but I'm pretty sure there's a built in "left" axis

crystal geode
#

ah, I see

#

I change the number of elements

snow willow
#

Or at least there's a built in "Horizontal" axis

#

so you could just use that

crystal geode
#

yeah, I'm not sure how to get "Horizontal.negative"

#

basically

snow willow
#

you do float horiz = Input.GetAxisRaw("Horizontal") if (horiz < 0) { // whatever

crystal geode
#

I guess it would just be checking if input is < 0 wouldn't it

snow willow
#

yeah

crystal geode
#

oh yep

#

you beat me to it ๐Ÿ˜†

#

hmm, but that will trigger on hold as well, I need taps

#

I wonder if there's a way to distinguish between individual presses of a horizontal key

snow willow
#

Yeah you'd make a button

crystal geode
#

yeah, seems like that'll be the easiest way

#

just making a new input scheme

snow willow
#

I personally hate the Input Manager and have switched to the new Input System in all of my projects, but it's a bit of work to get up and running with it, and has more of a learning curve

crystal geode
#

I might try that out once I'm more accustomed to this, but I'm tryna cover all my bases as I learn

#

huh, new question

#

as you can see, I've defined what Right and Left are

#

but I'm still getting a "Input Button Right is not set up" error when it tries to use my script

snow willow
#

hmmm

#

should definitely work...

#

are you using the correct casing?

#

"Right"

#

"right" won't work

#

Also make sure your changes in the Input Manager "took"

#

press enter after typing everything there

crystal geode
#

"right" is what the input manager uses for the right arrow key

#

whereas "Right" is the button name

snow willow
#

no yeah I mean

#

in the "name" field

#

and in your code

#

those need to match

#

"right" is ok for the alt positive button

#

Make sure you don't have like an invisible extra space after "Right" or something

crystal geode
#

yup, it's capitalized in my code as well, no extra spaces in the manager

snow willow
#

๐Ÿค”

#

should work based on that

#

what's your code look like?

crystal geode
#

warning in advance, please excuse my excessive use of &&

#

I'm just testing to see if I can make stuff work in theory right now

snow willow
#

and it fails on that first call?

crystal geode
#

when I save the script and try to compile

snow willow
#

oh really?

crystal geode
#

is there somewhere else in unity where I need to tell it that I've added a button?

snow willow
#

Pretty sure just the input manager

crystal geode
#

hmmm

#

oop

#

I think it might be working

snow willow
#

oh

crystal geode
#

I had to give it a little bit to accept the changes I guess?

snow willow
#

I was about to suggest reopening your project

crystal geode
#

ye

#

thank you for the help, sorry for the confusion

snow willow
#

I guess so - to be honest I've never actually added an axis to the input manager haha

#

np

crystal geode
#

well, I'm trying to do movement without much assistance from physics

#

so I need a weird input setup

#

actually

#

I wonder how GetButtonDown works with Horizontal ๐Ÿค”

#

I'll have to test it

snow willow
#

It probably works only for the positive axis

#

would be my guessw

#

but good question

#

worth testing

crystal geode
#

ooh, okay, here's something

#

is there a way to lock my game at 60?

#

it feels like it's running faster than 60fps which will make input windows a little screwy

snow willow
#

Application.targetFrameRate = 60;

#

or turn on VSync

crystal geode
#

awesome, thanks

still tendon
#

i was told that this chat is better for my question, so how would i generate a dungeon if i want it to be in a tilemap, so the rooms are not objects but just a bunch of tiles

calm zealot
#

get some pictures of the dungeon, you wanna make. make a tilemap, copy ur pictures to the tile pallete

#

and just paint ur dungeon out

still tendon
#

i want to generate a dungeon

#

not pre make it

fleet vessel
still tendon
#

How to make script for find the gameobject from another scene in unity

lofty crypt
#

I have tried but i cant find a way to make more pieces of code work at once. It all just goes in order all the time. Can anyone help?

low shadow
#
public class PlayerController : MonoBehaviour
{
    private new Rigidbody2D rigidbody; //this object's rigidbody

    public float playerAccel; //acceleration speed of the player
    public float playerSpeedCap; //speed cap in u/s
    [Range(0.0f, 5.0f)]
    public float velocityKickback; //how much force to apply when not moving

    // Start is called before the first frame update
    void Start()
    {
        //get this object's rigidbody
        rigidbody = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        //cap the player speed
        if (rigidbody.velocity.sqrMagnitude > playerSpeedCap*playerSpeedCap)
        {
            rigidbody.velocity = rigidbody.velocity.normalized * playerSpeedCap;
        }

        //add a force to move responding to player input
        rigidbody.AddForce(new Vector3(Input.GetKey(KeyCode.D) ? 1 : (Input.GetKey(KeyCode.A) ? -1 : 0), 0, 0)
            .normalized * Time.fixedDeltaTime * playerAccel);

        //is the player moving?
        bool isMoving = Input.GetKey(KeyCode.D) | Input.GetKey(KeyCode.A);

        //apply force in the opposite direction of the player velocity to slow down when not moving
        if (!isMoving)
            rigidbody.AddForce(-rigidbody.velocity * velocityKickback);
    }
}

i've got this and it's giving me jittery movement. any ideas why that may be?

snow willow
#

don't use Time.fixedDeltaTime for AddForce (although that won't cause jitter, it's just not necessary)

#

the speed cap could cause jitter

#

apply your speed cap at the end of FixedUpdate, not the beginning

#

also what's your camera setup?

#

If there's a mismatch in camera vs target motion (update vs fixedupdate) that can cause jitter too

low shadow
#

i'm lerping the camera to the player rb position, so the camera is smooth but the player isn't

still tendon
#

send the camera script

low shadow
#

changing where the speed cap is had no effect it seems

#
    public Rigidbody2D rb; //rigidbody to follow
    public float followSpeed; //speed to follow at. 1 snaps the transform to the rb, 0 doesn't follow at all.

    void Update()
    {
        //lerps between the rigidbody position and the transform position.
        Vector3 moveTo = Vector3.Lerp(transform.position, rb.position, followSpeed);
        //preserve layer
        moveTo.z = -10;
        //set position
        transform.position = moveTo;
    }
#

the camera looks smooth in editor, the player does not

#

the camera also looks smooth in game

still tendon
#

do it inside LateUpdate

drowsy spindle
#

Does anyone know how to do an Enemy Indicator? like an arrow that points to the enemy.

low shadow
rose radish
#

@low shadow because you're following a Rigidbody, you want to update the camera position in FixedUpdate.

#

or you can set the interpolation mode of the object

#

by default Unity runs physics at 50fps

#

which....is always just slightly out of step with 60hz monitors

#

so you can also change your physics frame rate as well

low shadow
#

the whole problem was infact just that i was using Time.fixedDeltaTime, may i ask if i was even using this correctly?

rose radish
#

you probably aren't.

snow willow
#

there's no reason to use it the way you were using it

rose radish
#

fixedDeltaTime is something you generally SET, it doesn't represent frame time.

#

Time.deltaTime is the time between frames

snow willow
#

you may as well have replaced that variable with the literal value .02f

#

think about how odd it would be to put that in your code

low shadow
#

the jittering i was seeing was probably random framedrops then.

low shadow
rose radish
#

yea i know

#

bad name

#

Time.deltaTime is actually smart enough to understand whether its inside Update or FixedUpdate

snow willow
#

It's literally just the constant value you set in Project Settings -> Time -> Fixed Timestep

low shadow
#

well, i got it fixed in the end! thanks for the help humans!

rose radish
#

@snow willow its not a constant โค๏ธ

snow willow
#

it is if you don't change it

#

in your script(s)

rose radish
snow willow
#

I'm using the term relatively to Time.deltaTime

rose radish
#

for a math undertanding of what that skip is

#

if your Update FPS is ~60, and your Physics FPS is 50

#

you will inevitably end up out of phase

#

skip/jitter

low shadow
#

huh, interesting

#

good to know for future!

#

hopefully i won't make the same mistake again!

snow willow
#

Yeah but none of this has to do with the use of the value FixedDeltaTime in your FixedUpdate code

#

in fact I don't reasonably see how using it would cause extra jitter

#

it just scales a number down by 1/50th

low shadow
snow willow
#

doesn't matter

rose radish
#

@snow willow You end up with more Updates than FixedUpdates

low shadow
#

it'll be the representation of framedrops as if i wasn't using deltatime normally

snow willow
rose radish
#

correct

snow willow
#

that's just a problem of having camera updated in Update and object updated in FixedUpdate

rose radish
#

Time.fixedDeltaTime doesn't really care, it'd be a bit inconsistent occasionally, but the hiccup isn't caused by its usage

#

Rigidbody.interpolation is also a good way to resolve it

low shadow
#

it was already set to interpolate is the strange thing, it was much worse without it on

rose radish
#

i should probably make a proper example/tutorial thing for this issue...

#

gonna have to turn my monitor refresh down tho ๐Ÿ˜ฆ

rose radish
#

There... that a decent matrix of stuff

#

@snow willow too actually, just for completeness ๐Ÿ˜›

idle widget
#

can anyone help me out?

#

I want to develop a 2d MOBILE PHONE game which is like
a grapple gun swingiing game so can anybody tell me how to make one?
because I am a beginner in unity

civic knot
# idle widget can anyone help me out?
  1. Make a plan. Decide what features you want in your game. Make a list.
  2. Evaluate features from the list. What can you do and what not.
  3. Research into the topics that you don't know how to do.
  4. Create your game.
  5. Profit..?
#

Now, if you have specific questions, feel free to ask them and someone might help you out.

idle widget
#

thank you very much @civic knot

young knot
#

ฤฑ need help with my parallax effect

#

ฤฑ use this code but it is not repeating and glitcy

dense flame
#

Send codeblocks

#

We will not be downloading things from you

umbral lintel
#

https://picupt.xyz/img/ylgy8p35.png Is there a better way to check the end of the platform? Tilemap colider is everywhere and create 100 colider is very annoying. Or can I check, if I not anymore on the ground?

boreal saddle
#

Hey @idle widget I might be wrong here, however i highly recommend not making a bigger game for your first game ( stick with one to 2 mechanics and a main objective). I would go on youtube search tutorials for diffrent mechanics or even full game tutorials. Go thru the whole thing and see what you understand. Then make the most simple game you can think of and grow from there. What i found with starting out and makeing a bigger game is by the time you get to the end , lets say your making a main menu to finish off. You realize that you could animate your first charecter much better now. This puts you in a never ending cycle on what should of been a simple game. So with that being said just learn the unity interface, basic c# coding, how pyshics work, basic movement, jump and maybe score tracking !

real warren
#

@idle widget whilst I agree with kevin about keeping the scope small there is also a lot of ways and tutorials about making grapple games so there is a big ground when it comes do doing things like that

idle widget
#

thank you @boreal saddle and @real warren for that advice but I am already doing that and besides I cannot find the right tutorials for me even after ending up on channels like dani, code monkey and brackeys(I don't know if I spelled it correct). I have started unity a week ago and I used to make games in python but that games were looking so bad. That is why I am now learning from the official unity website. I hope I will become a good gamedev someday

real warren
#

well not always the big guys can help but little guys also have many tutorials that are awesome

boreal saddle
#

Seriously bro I'll help you with coding your first game animations and all just let me know when you get stuck I found small YouTubers make even better content as well

river wraith
#

Hi!
So I kinda have a small problem... I'm following a tutorial on youtube to get animations, for example jumping, on a 2D character.
He has this line of code:
public void OnLanding(){
animator.SetBool("isJumping", false);
}
and it works for him. But when I put in this code it gives me an error because the modifier "public" is not valid for the item "void"
does anyone know a solution to this?

dull badge
#

@river wraith Make sure that code is inside a class.

river wraith
#

ok i'm just stupid
thank you

cloud schooner
#

hey guys!
I'm relatively new to game dev and I'm a little stuck. I've got a way to have different jump heights, and also buffer a jump, as shown from a tutorial. However, all my buffered jumps have the default height. Can someone help me fix this please?

craggy kite
cloud schooner
#

It's so if the player presses jump slightly before the character is actually able to jump (i.e on the ground again), the game is lenient and still allows your character to jump. Basically a small quality of life thing that stops the game from eating your jump input if you press it a couple frames too early

craggy kite
#

Okay, and whats your problem here? where do you set the height you are expecting?

cloud schooner
#

and this is where the variable jump length is. But whenever I buffer a jump, this section seems to be ignored

craggy kite
#

But you said, all jumps are the same height, but I dont see you altering it anywhere, so it is obvious to me, that its always the default height?

cloud schooner
#

only the ones that are buffered. If i jump when I'm standing still or after I've already touched the ground, the jump heights are different

#

that last picture is where it alters the height

craggy kite
#

But thats intended in your code. If you just set the velocity its relative to the Y, but in your Jump() you are overriding the velocity complete with jumpforce

cloud schooner
#

right

#

I think I understand

#

so how would I fix it

craggy kite
#

you might have to add the jumpForce to the y velocity, if thats what you want

cloud schooner
#

remove the jumpforce bit from the function?

#

I'll have a go

#

thank you

craggy kite
# cloud schooner thank you

But I am not understanding what you expect there. So your character can be "flying" up and you want to add the velocity of your jump force to the current velo?

cloud schooner
#

All it is is that my y velocity is slowed when i release the jump button when im in the air. So the jumpforce i declared is the highest that i can possibly jump. And when i let go it slows that velocity so that the character doesnt jump as high

#

which works completely normally, except for when i use the buffered jump thing

#

i think because i will have already let go of the jump button before the character goes in the air when I use a buffered jump, that statement doesn't get applied, but I don't know how I would begin to fix it

#

Also I tried it and nothing changed :/

craggy kite
#

So your bufferedjump happens when? When your char is at ground?

cloud schooner
#

yeah

craggy kite
#

So velocity will be 0 anyway?

cloud schooner
#

the velocity is just set to jumpforce

craggy kite
#

Yeah but I mean, your character is already on ground, so its velocity is 0. so there is nothing to slow down in Y velocity, right?

cloud schooner
#

ohhh

#

yeah its 0 when theyre on the ground

#

but if its buffered that will only be for 1 frame

craggy kite
#

As far as I understood you, the buffered jump just waits for it to be grounded, if so and buffered, just Jump(). So velocity.y will always be 0 when your buffered jump occurs

cloud schooner
#

yeah

#

thats right

#

so i guess thats why it's not doing the Input.GetButtonUp("Jump") part

#

is there a way I'd be able to fix it?

#

or should I just find a different way to do it from scratch

craggy kite
#

You could just make the buffered jump an object that stores the velocity when pressed the key, then feed the Jump() with your value and add it to the jumpForce or multiply or whatever

cloud schooner
#

so make it so the height of the jump is precalculated before the actual jump?

craggy kite
#

yep, kind of

cloud schooner
#

alright

#

thank you :)

craggy kite
still tendon
#

Hey guys how can i make a controller like this

#

Grid Based Movement

#

something like this game

cold plaza
#

@still tendon Easiest is to always move by one Unity unit

tropic juniper
#

does anyone know if it would be possible to record a series of clicks on the mouse and then take the users input to see how accurate their clicks are to the original series of clicks?

still tendon
#

rigidboydy.AddForce on 3d dont work on 2019 LTS

snow willow
#

do you have a specific scenario that's not working?

cold plaza
still tendon
#

Help

covert cliff
#

Anyone can help me with my "combo" system?

#

When I press "u", the player must execute 3 attacks in sequence. But I'm having some issues to get it working properly

dull plank
#

hey

#

im a new developer and got the clicker template thats free in asset store, i want to make a map where you click a icon then a map open with spots and then you can click some join them and when you click go there then youre here and get more clicks

#

like that

#

how? xD

violet jackal
#

a bit of help please

#

i am trying to make a top down 2d space ship game

#

and i need the camera to look and

#

is that possible?

keen ginkgo
#

someone can help me to resize the screen for different sizes

#

i mean

#

like 3:4 and 9:18

snow willow
#

Game view has a resolution selector

keen ginkgo
#

but it only have only one view

snow willow
#

?

keen ginkgo
#

let me explain better

#

im making a tetris

#

and i need it to run in 2 different resolutions

#

3:4 and 9:18

#

without bug

snow willow
#

Yes

#

Use the resolution selector in the game view to test each of those aspect ratios

#

One at a time

keen ginkgo
#

i can make a different zoom for each?

#

im rewriting this f*** code for the third time

#

the last 2 broke ;-

snow willow
#

I don't know what you mean by zoom

keen ginkgo
#

wait i will send prints to explain

#

like this

#

oh and im having a issue with the line delete

#
    {
        for (int i = maxY--; i>=0; i--)
        {
            Debug.Log("dasbyuidbawuyrbuawyin");
            if (HasLine(i))
            {
                DelLine(i);
                RowDown(i);
            }
        }
    }
    bool HasLine(int i)
    {
        for (int j = 0; j< maxX; j++)
        {
            if (grid[j,i] == null)
            {
                return false;
                Debug.Log("aaaa");
            }

        }
        Debug.Log("aabasuydbvauysedgbuyaa");
        return true;
    }
    void DelLine(int i)
    {
        for (int j = 0; j < maxX; j++)
        {
            Destroy(grid[j, i].gameObject);
            grid[j, i] = null;
            Debug.Log("bbbb");
        }
    }
    void RowDown(int i)
    {
        for (int k = i; k<maxY; k++) 
        {
            for (int j = 0; j< maxX; j++)
            {
                if (grid[j,k] != null)
                {
                    grid[j, k - 1] = grid[j, k];
                    grid[j, k] = null;
                    grid[j, k - 1].transform.position += new Vector3(0, -1, 0);
                    Debug.Log("cccc");
                }
            }
        }
    }```
#

this is the line clear code

low rock
#

what is grid?

keen ginkgo
#

oh wait

#
    private static int minY = 0;
    private static int maxX = 17;
    private static int maxY = 22;
    private Vector3 expos;
    private static Transform[,] grid = new Transform[maxX, maxY];```
#
    {
        foreach (Transform children in transform)
        {

            int arx = Mathf.RoundToInt(children.transform.position.x);
            int ary = Mathf.RoundToInt(children.transform.position.y);


            grid[arx, ary] = children;
        }
    }```
low rock
#

ok whats the error

keen ginkgo
#

sometimes the line dont delete

#

and when it happens one time, for the rest of the test it will not work :/

low rock
#

so are you sure in this scenario when the line doesnt delete, both CheckLine() and HasLine() fires? Only DelLine() doesn't work?

civic knot
#

Is it DelLine? The place where you delete the line?

keen ginkgo
#

yup

civic knot
#

where do you call CheckLine?

keen ginkgo
#
        {
            transform.position += new Vector3(0, -1, 0);
            if (!vMove())
            {
                transform.position += new Vector3(0, 1, 0);
                AddToGrid();
                CheckLine();
                this.enabled = false;
                FindObjectOfType<Spawner>().Spawn();
                
            }
            pTime = Time.time;
            
        }```
#

private int fTime = 1;

ocean olive
#

Hi how would you go to create a collision of cars against trees on a top down 2d game?
at the moement when the car crashes the tree, it wont bounce back

keen ginkgo
#

@low rock

#

@civic knot

#

when this happen

#

it stop working

stable fern
#

how can i save the position of an object to a variable in 2D

keen ginkgo
#

create a vector 2 variable

stable fern
#

i know that but how exactly

keen ginkgo
#

like ```public Vector2 savedPos;

then
```savedPos = transform.position;```
low rock
# keen ginkgo when this happen

okay so did you intend for your maxY to reach an integer of maxY or did you want to to be one less? Like if you define maxY to be 60, did you want 0-60 or 0 to 59?

#

cos maxY goes from maxY to 0 and maxX from 0 to maxX-1

keen ginkgo
#

it worked

#

only one line

#

then stopped again

keen ginkgo
low rock
#

in DelLine

keen ginkgo
#

ok

#

no changes

low rock
#

hmm you didnt do grid.remove anywhere right? no changes to the grid array length?

keen ginkgo
#

only in the first time i changed

low rock
#

perhaps do a try{} before the if statement in HasLine and catch (Exception e) { Debug.Log(j); Debug.Log(i); }

hollow crown
#

you're changing maxY here

#

why?

#

did you mean to write maxY - 1?

#

You can easily make reverse for loops by autocompleting forr

keen ginkgo
#

oh it worked

#

more one question

#

how can i create a button only with code

tropic inlet
#

like this

#

@keen ginkgo

still tendon
#

How to make a simple character selector

novel pewter
#

Anyone got any experience with the Unity Tile Map?

I created these methods to store the location of collectible items from the tile map (Coins, Keys, Power ups, ect), and then when the player collects them and dies I can re-add the collectibles to the tile map without reloading the scene.

The problem is that no matter what I try this will not work: LevelDataArray[CurrentLevelIndex].CollectableItemTiles.SetTile(keyLocation, KeyTile);
However if I swap this line in, it remove the tiles from the tilemap correctly: LevelDataArray[CurrentLevelIndex].CollectableItemTiles.SetTile(keyLocation, null);

So I know the positions are being collected correctly. I've tried re-assigning the tiles, using normal tiles, refreshing the tilemap.

novel pewter
#

Never mind, deleting my animated tiles from the asset folder and remaking them fixed this issue. If anyone has any idea why that worked please let me know, cause you have clearly achieved omniscience and I have some questions about the afterlife...

stable fern
#

anybody help

stable fern
#

xD

#

i fixed it though

novel pewter
#

Can you screen show the animator state machine?

#

at runtime i mean where it's stuck

#

If you're stuck at the down_idle pose it probably means the exit transition parameter to the blend tree hasn't been set up correctly.

#

sorry give me a sec, i've got my own project in the back ground i'm looking now

#

Press play in the unity editor and take another screen shot of the same thing, just to make sure it's your animation that's getting stuck, you should be able to see a blue bar at the bottom of the active state, that shows you how far a long the animation is. Also Press on the arrow that goes towards the blend tree, that way i can see what's supposed to trigger that transition.

#

That condition is what tells the animator to changes states, if your animator is stuck it's normally due to that condition.

#

It's not working cause the value is 0.0

#

you're check if it's greater and less than

#

So you had one condition "greater than 0.1" and another condition that was at "less than 0.1"?

#

so there's a case here where if the value is 0.01 nothing will happen

keen ginkgo
#

anyone here can help me with a ranking code

dusk horizon
#

Hello guys, does anyone know how can I rotate a tile from a tilemap by script?

keen ginkgo
#

the piece isnt falling here

       {
           transform.position += new Vector3(0, -1, 0);
           if (!vMove())
           {
               transform.position += new Vector3(0, 1, 0);
               AddToGrid();
               CheckLine();
               this.enabled = false;
               FindObjectOfType<Spawner>().Spawn();
               
           }
           pTime = Time.time;
           
       }```
#

the time function is not working

#

i mean

#

the fall time

young hinge
#

just wondering, does box colliders not work when theres a character animation

rose radish
#

@young hinge Animators can be set to "Animate Physics" if you need them to perform the animation updates in FixedUpdate

young hinge
#

thanks, but the box collider still isnt working, do you know any other reasons that a boxcollider2d wouldent work?

rose radish
#

lots of reasons! ๐Ÿ™‚

#

describe your situation better

young hinge
#

ok so I have a circlecollider2d on my knob sprite, I have an animation that always plays which just slightly increases and decreases the y size. I also have a movement script and I put the camera in the player so it follows.

#

also I have the fungus asset

dull badge
#

Is the color property on a SpriteRenderer supposed to ignore alpha?
When I set it to Color.clear it turns black instead of going invisible.

snow willow
#

I think... it might depend on the material you're using?

vagrant nexus
#

^

#

If it's an opaque material, the alpha cannot change

plush basalt
#

Does anyone know how to turn my polygon collider 2d into code? I am new to this

warped zealot
#

Good lord, I will pay for a solution to this issue I'm having

#

I am rendering this arrow, and while it looks pretty good, the code is overcomplicated yet still buggy once the path intersects itself.

#

It stores the cell index of every square that's been selected and decides which directional sprite should be rendered

#

tl;dr: I need to find a simpler way to correctly render the correct directional sprite, even when it intersects itself

slim jungle
#

can someone help me with OnTriggerEnter2D? pls

#

it's just not working

silver heron
#

whats your issue? @slim jungle

#

ensure you set the triggerflag on a colider and use that colider as the params for the method

slim jungle
#

thx but i allready solved it

still tendon
#

Hey any good practices for making a top down character?

zinc trout
#

how do i move my character controller into my script

#

ping me to help

silver heron
#

@zinc trout that looks like youve found a public script which references a character controller component

zinc trout
#

it wont let me drag it in

zinc trout
#

i want to drag it in but it wont work

silver heron
#

add component>character controller

#

not sure if character controller is available in 2d but might be

zinc trout
#

im watching a brackey and he did it but it wont let me

silver heron
zinc trout
#

but i have a script that i used

#

and that didnt let me do that either

#

@silver heron

silver heron
#

not sure how to help you it should be where i showed you, also if your tutorial is using a character controller i don't see why they would include a rigidbody

#

it looks more like they've called a character controlling script character controller and that may contain movement and thats whats confusing you by the sounds of it

zinc trout
#

can i show you the video

silver heron
#

welcome to but its 3 am for me so i'm gonna crash soon

zinc trout
#

oh

#

Letโ€™s give our player some moves!

โ— Check out Skillshare: https://skl.sh/brackeys7

โ— Character Controller: https://bit.ly/2MQAkmu
โ— Download the Project: https://bit.ly/2KPx7pX
โ— Get the Assets: https://bit.ly/2KOkwjt

โ™ฅ Support Brackeys on Patreon: http://patreon.com/brackeys/

ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท...

โ–ถ Play video
#

here

silver heron
#

where abouts did he do what you said

#

@zinc trout he drags the script into the box in the video, however can click the little circle on the right of it to select it

#

also he seems to do some funky stuff making a character controller and a seperate movement script

#

but both of those are scripts, character controllers are also a seperate component outside of scripts

#

however thats not what his referencing there

zinc trout
#

thanks it work to move it but my character wont move

#
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public CharacterController2D controller;
    public float runSpeed = 40f;

    float horizontalMove = 0f;

    void Update()
    {
        horizontalMove = Input.GetAxisRaw("Horizontal") *runSpeed;
    }

    void FixedUpdate()
    {
        controller.Move(horizontalMove * Time.fixedDeltaTime, false, false);

    }
}```
#

@silver heron

silver heron
#

im not to sure, thats a pretty funky way of doing it without using a traditional character controller

#

and im off to bed man to late for me to think properly goodluck tho

zinc trout
#

ok!

#

gn

hallow roost
#

Hi i have a error in my code but I can't find what it is ! Because i am following a tutoriel and the code is exactly the same :/ but his script is working

#

this is the code

#

it's for left and right movement for a platformer

zinc trout
#

@hallow roost who aer you using

hallow roost
#

It's ok somebody helped me ^^

zinc trout
#

ok

hallow roost
#

the error was that the B had to be lowercased : public Rigidbody2D rb;

hallow roost
#

Hi who Is specialist with 2D code ?

radiant rampart
#

Was wondering if anyone could help me with this? I'm following a tutorial on how to make turn based combat and i keep getting this error. Does anyone know exactly what's wrong? Thanks!

#

Please ignore how scuffed the game looks

tropic inlet
#

the game looks beautiful

radiant rampart
#

Thanks ๐Ÿ™‚

quartz glade
#

I'm attempting to render just one object to a camera, with the intention of getting a texture of just that object which I can then map on to a texture to apply visual effects to (think the 'death effects' on an enemy in a JRPG game). I'm having issues however with WorldToScreenPoint vertically offsetting my points. I made a post on the Unity Forums at the following link. If anyone here has any experience with that kind of a process I'd really appreciate your help. Thank you!

https://forum.unity.com/threads/camera-worldtoscreenpoint-offsets-vertically-with-orthographic-camera.1048769/

dusty abyss
#

I am making a 2D game which has elevation/verticality. What is the recommended way to handle collisions? 3D Collision or Layers?

#

I'm going the layers route at the moment but I'm not sure if this is what I want. I'm wondering if 3D Collision has more flexibility

#

Does anyone have any experience with this?

zinc trout
#

hey im watching this https://www.youtube.com/watch?v=rycsXRO6rpI and im at the animate part but it wont let me animate it im at 4:54

A brief introduction to 2D Character Movement and Character Animation in Unity. We will use a Sprite Sheet with Animator Controller to animate our 2D Character, and we will use some Scripting to change his position by pressing the Arrow Keys. Topics like Sprite Sheet, State Machine and Animation Transition will be cover along the way.

Are you i...

โ–ถ Play video
#

ping me to help

zinc trout
#

PLEASE HEL

#

HELP

meager mural
#

How can anyone help with that. lol

tropic inlet
#

^

#

no one can help with a problem that doesn't even exist

meager mural
#

this broke help

tropic inlet
#

oh, i didn't see the message above the vid

meager mural
#

Statement still stands

lucid crypt
#

@zinc trout Hey there, could you please tell us more about the specific problem youโ€™re facing, and more about what youโ€™re trying to accomplish? Itll help you receive some better feedback and assistance sooner, since right now we dont really know enough to help

polar pagoda
#

Quick question, does anyone know what type of gameobjects would use win/game over screens? I was thinking it would be UI but I could be wrong.

left nest
#

I am using Unity c#. I want to get a game objects x position value and make a int value = to the x value of the gameobject how would I do this? I haven't tried anything because I don't know what to do

still tendon
#

how to make 3d in 2d pixel

left nest
#

2d

#

this is 2d code

still tendon
#

3d in 2d

#

like some retro games have 3d feel in 2d games

left nest
#

2d in 2d

still tendon
left nest
#

2d style in 2d

#

ohh

#

you are asking a question

#

oops

#

I thought you were answering my question

#

nvm

still tendon
#

LOL sorry

left nest
#

lol

#

lets just repost our questions

still tendon
#

yeah

left nest
#

I am using Unity c#. I want to get a game objects x position value and make a int value = to the x value of the gameobject how would I do this? I haven't tried anything because I don't know what to do

still tendon
snow willow
left nest
#

so

#

for e.g

#

variable = gameObject.transfrom.position.x?

snow willow
#

int x = Mathf.RoundToInt(gameObject.transform.position.x);

left nest
#

ok

#

thx

snow willow
#

If you want it as an int

left nest
#

cool

#

thx

#

byr

noble oak
#

You mean 2.5D?

warm crest
#

Hi! I'm having issues with instantiated objects not triggering events like OnTriggerEnter2D or OnCollisionEnter2D
for example, i instantiate projectiles when the player shoots. I check if they collide with an enemy and that works fine, they get destroyed and deal damage, but if i check if they collide with a solid, they go through it and ignore the check.
They go through walls even though i have a Box Collider 2D on them.
Also, i have a pressure plate the player can step on to activate a door. It works fine when the player steps on it, but when a clone does it, it does not work.
Note that i use tags for OnTriggerEnter2D/OnCollisionEnter2D, and i've set them up properly, so the player and his clone have the same tag so they should work the same with the pressure plate

low rock
warm crest
#

Can i make them kinematic? i don't want gravity to be applied to them

low rock
#

i think you can freeze the y position to stop gravity, yea no you canโ€™t make it kinematic as itโ€™ll stop the callbacks to the functions

warm crest
#

Oh right

#

Thanks, i'll try it out! breebuHype

burnt mural
empty coral
#

does anyone know why OnTrigger2D won't work?

#

WHY???

tropic inlet
#

because u misspelled it

empty coral
#

i have that

tropic inlet
#

proof?

empty coral
#

and i have colliders on both objects as well as rigidbodys, and the object with that code has "is trigger" on

#

WHY won't it work.......

#

@tropic inlet

brittle gyro
#

I want my player to be affected by tilemap colliders, but I also want it to be kinematic so only my movement script can move it. Is this possible?

empty coral
#

WHY???

tropic inlet
#

calm down bro
why are u electronically yelling at me
smh

brittle gyro
#

I didn't know you could check for tags with gameObject.tag. Doesn't it have to be gameObject.CompareTag("tag")?

empty coral
#

!!!!!!!!!!!!!

#

@tropic inlet

tropic inlet
#

Obviously, I don't know how to solve it.

brazen bridge
#

@empty coral Where are those called, because your checking the same parameters most likely OnTriggerExit isnt written to work with your setup

brazen bridge
#

@empty coral Where do you call those functions

empty coral
#

in the gem script, gem has collider is trigger

brazen bridge
#

what checks for collisions

empty coral
#

i don't see why it shouldn't work

brazen bridge
#

is your object isKinematic?

empty coral
#

no, just no gravity

brazen bridge
#

do col.CompareTag("Player")

empty coral
#

it doesn't even print anything

empty coral
brazen bridge
#

col.gameObject*

#

.CompareTag

#

so swap it to col.gameObject.CompareTag

empty coral
#

nope...

#

it doesn't even print a debug message

brazen bridge
#

well because you cant print a comparison like that

#

you should leave the debug as is

#

but only change the conditional statements

empty coral
#

even just a text debug won't show up...

brazen bridge
#

Yes I know that

#

Leave the debug as is

empty coral
#

my player has a collider too, why won't it work?

brazen bridge
#

what are the bodytypes of the player and collision's rigidbodys

#

send a ss of the entire class not just the snippet also

empty coral
#

dynamic

brazen bridge
#

Should you not be handling the triggers on the player?

brazen bridge
empty coral
brazen bridge
#

Do you understand what those modifiers do

tropic inlet
#

Functions are already private by default. You don't need to explicitly specify it.

empty coral
#

but why on earth won't it work!??!?!?!

brazen bridge
#

try handling the collision on the player who has a rigidbody, give the object a collider but not rigidbody

empty coral
brazen bridge
#

the gem i believe

empty coral
#

wait, ok i'll make the player have the trigger and send data to the gem after collision

brazen bridge
#

sure

empty coral
#

umm, still nothing

#

witch rigidbody should i remove?

brazen bridge
#

the one that isnt the player

#

I mostly do 3d so after this im not overly sure

empty coral
#

ok finally it works!

#

thanks a lot

brazen bridge
#

nb

empty coral
brazen bridge
#

Whatever you changed, Ctrl+z

#

Fixed

empty coral
#

i only added a piece of code that adds the score to the player script

#
GameObject.Find("Player").GetComponent<playerController>().points += pointS;```
#

that doesn't seem to be the problem tho...

#

oh YEAH

#

NVM

halcyon ice
#

i have question how i can code stuff spawn on top of screen and if it touch for example square it gives score and dissapper ?

empty garden
#

So I have this code that's half way done that will allow me to move from square to square like in a rouge like using cubes. When i launch unity ilk show you what I have but I need help finishing the rest

empty garden
#

as i said its half done and i dont know how to make it complete

#

i think i want move clicks to move the player rn but yeah

empty garden
#

ok was my problem that i wasnt using using Vector2 = UnityEngine.Vector2;

#

either way

#

what code do i need to get it to move from one box to another

ionic halo
#

Do you guys have any good course/tutorial for 2d gaming for someone who is cs major? I dont want to spend time on fundamentals but I know I have to look at them a little at least. So I'm looking for something like unity in 2hrs like Derek Banas videos.

empty garden
#

hmmmm

#

there are a good few

#

depends on what you are looking for

#

most of the time if you are looking for inspiration for something spefic just google exactly that and you can find it

#

not simple

#

like if you know what you are looking to do and just need a shove just google it

#

@ionic halo got you a second to help im using 3d cubes in the 2d engine and i want to move between them with the player cube that i got going on, i have it done a bit but idk how to do the rest

#

idk if you can help though you are the one asking for a tutorial

ionic halo
#

lol probably im not bro :( but thanks for suggestion

empty garden
#

is there something i can help you with maybe

#

finding a tutorial

#

or you got it

#

so i found this code in a wiki style of stuff online i put it in a paste bin here

#

now i what i want to know is

#

will this work if i use it in the game as is, also how would i change it to work with the square tiles i have

#

or does it not work if i have 3d cubes in a 2d plane

#

idk if this is what i need though

#

wait it doesnt work as is i need to figure out howto use it

#

it says the reference to player is missing idk where to put it

#

ok i got it to work i think this is fine for now

#

just gotta adjust some cords

empty garden
#

ok i got it working

#

also

#

how do i generate a grid with cubes

#

2d

snow willow
#

usually with two nested for loops

#

one loop for x coordinates, and one loop for y coordinates inside that

#

Then just place a cube at each x/y position

thin wraith
#

Hello there, I am currently working on a 2d pixel perfect game that uses TextMeshPro's inLineSprite feature, but I am struggling to get the sprites pixel perfect as well as maintain a correct line height

#

Test Text <sprite="Beverages" index=1> More test Text

#

By adding a <size> override I am able to maintain the pixel perfectness however the size adjust messes the line height

Test Text <size=32><sprite="Beverages" index=1></size> More test Text

still tendon
#

hey how to get my mouse pos?

snow willow
#

Input.mousePosition

still tendon
#

Camera.ScreenToWorldPoint?

snow willow
#

Camera?

#

Input.mousePosition gives you the mouse position on the screen

#

In screen pixel coordinates

#

If you want to know where that's "pointing to" in the game world

#

You can use a raycast

still tendon
snow willow
#

To convert it yo a world space position

still tendon
#

i want to find angle to rotate my weapon

snow willow
#

But that gives you a point very near the camera, not a point near the action of your game

#

Your weapon is on the xy plane?

still tendon
snow willow
#

var xyPlane = new Plane(Vector3.back, 0);

still tendon
#

thanks

snow willow
#

Ray ray = myCamera.ScreenPointToRay(Inpit.mousePosition);

#

xyPlane.Raycast(ray, out float enter);

#

Vector3 worldPosition = ray.GetPoint(enter);

#

Sorry typing on my phone

still tendon
snow willow
#

So that worldPosition

#

Is the position on the xy plane your mouse is pointing

still tendon
#
Vector3 mousePosition = Input.mousePosition;
Vector3 aimDirection = (mousePosition - transform.position).normalized;
float angle = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg;
weaponArm.eulerAngles = new Vector3(0, 0, angle);
snow willow
#

So now you can have your weapon point at that position

still tendon
#

i am doing this

snow willow
#

That doesn't work because you're comparing your weapon's workd space position to the gun's screen space position

#

Replace mouse position from your code with the Vector3 produced by my code

#

And it should work

still tendon
snow willow
#

You can most likely use Camera.main

#

If not you need a reference to your camera

still tendon
#

cannot convert from 'UnityEngine.Camera' to 'UnityEngine.Camera.MonoOrStereoscopicEye' [Assembly-CSharp?

#
 Vector3 mousePosition = Camera.ScreenToWorldPoint(Input.mousePosition, Camera.main);
opal socket
#

Camera.main.Screen...

still tendon
#

oh sorry

#

:p

#

Mate why my code messed up when my player move?

opal socket
#

Too vague

still tendon
#
        Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3 aimDirection = (mousePosition - transform.position).normalized;
        float angle = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg;
        weaponArm.eulerAngles = new Vector3(0, 0, angle);
#

i am trying this

opal socket
#

And whatโ€™s wrong?

still tendon
#

evert thing got inverse when my player move?

opal socket
#

Too vague

still tendon
snow willow
#

Did you just ignore everything I said above?

still tendon
#

i dont wanna use Ray

snow willow
#

Why

still tendon
snow willow
#

Lol

still tendon
#

XD

snow willow
#

Ok I'm going to sleep now bye

still tendon
#

aah i see

#

why everything got flipped

#

i am using Flip()

#

on my player

#

Hey if anyone facing same problem this is what i did

        Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        mousePosition.z = 0f;
        Vector3 aimDirection = (mousePosition - transform.position).normalized;
        float angle = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg;
        if(isFacingRight == true) {
            weaponArm.eulerAngles = new Vector3(0, 0, angle);
        } else if(isFacingRight == false) {
            weaponArm.eulerAngles = new Vector3(0, 0, 180 + angle);
        }
#

:D

dull plank
#

i have a clicker and i want to make like 50 things that can happen ( get attacked, find some things) and that every 30 clicks

#

how can i do that?

#

i dont have any idea and dont find tutorials

#

its just a button to click and after 20 clicks one of the things happen

tropic inlet
#

increase an int

#
theInt += 1;
if(theInt >= 30)
{
  //do stuff here
  theInt = 0;
}
stable fern
#

how can i make an object rotate its Y based on the curcor

#

but only if the rotation is 180 or 0

tropic inlet
#

?

stable fern
#

how can i save the position of the cursor in a variable

snow willow
#

Vector3 mousePosition = Input.mousePosition;

gaunt hawk
#

If there is someone experienced with tilemaps, what would be the best way to place 4 million tiles? SetTile loop takes me about 2 minutes, and im not sure abt settilesblock

fallen narwhal
#

I have an animation and I check for collision, but when I go through the collision it triggers twice

#

could this be related to the animation (in frames) the object has?

grand cove
#

What method are you using for detection? @fallen narwhal

snow willow
worn nymph
#

How do I get a camera to follow a 2d spaceship's rotate?.

  1. When I attach the main camera on the player ship, it rotates and moves with the player, but it is forced into the center of the screen.

  2. I tried to create a very simple player scrip, but it only translates the x/y movements and does not rotate.

Is there a way to follow the relative rotation of the focused entity and put it into the camera?

distant sun
#

but I do not know where they could arise . the function code is below, all the checks I did have already been done

old field
#

hey therem i need some help with my 2d sword, when i turn around the sword just disapperes m how can i fix this ?
edit : my sword is in a difrante sprite from my character.

old field
#

nvm i fixed it, the sword was -90z in the position

fallen narwhal
quartz glade
hallow roost
#

Hi does anybody know how to make a empty object rotate directions with my player?

#

My player can already rotate so I put the empty as his chield because it's a firepoint. but when the player rotate the firepoint don't rotate at all

modest marsh
#

try this:

var width = Mathf.RoundToInt(screenBottomRight.x - screenBottomLeft.x);
var height = Mathf.RoundToInt(screenTopRight.y - screenBottomRight.y);
var srcx = screenBottomLeft.x;
var srcy = Screen.height - screenTopRight.y;

Texture2D finalTexture = new Texture2D(width, height, TextureFormat.RGBA32, false);
finalTexture.ReadPixels(new Rect(srcx, srcy, width, height), 0, 0, false);
quartz glade
hollow agate
#

When I try to make the ball bounce

#

it get stuck in the top

#
if (other.gameObject.name == "Plafond") {
            transform.Translate(Vector3.down * Time.deltaTime * speed);
        }
#

I tried to do this

stone siren
#

@hollow agate put Debug.Log("We hit the top box")'; inside of your if statement to make sure it's actually getting called?

#

See if you're getting to that point to begin with

hollow agate
#

It does get called

#

I tested with a print

#

It prints when the ball hits the top

#

@stone siren

stone siren
#

OH

#

wait a second here.

#

You're running a transform.translate but not on the game object itself

hollow agate
#

How could I do it

#

(New to unity)

stone siren
#

put other.transform

hollow agate
#

I want the ball to move, not the wall?

stone siren
#

What you're doing ios doing transform.translate etc on no object at all, you need to add the object you just checked for (plafond) and run the method on it

hollow agate
#

other refers to my wall

#

I am in my ball script

stone siren
#

Is Plafond your ball?

hollow agate
#

Plafond means ceiling in French

#

My bad

stone siren
#

what is the object your ball is named? (The variable you've used)

hollow agate
#

Circle

stone siren
#

so call transform.translate on circle there

#

(circle.transform.translate etc etc etc )

hollow agate
#

it doesnt see Circle tho for some reason

stone siren
#

You may need to show more of your code ๐Ÿ˜›

hollow agate
#
public class MouvementBall : MonoBehaviour
{
    
     
    // Start is called before the first frame update

    public int speed = 1;
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        transform.position = transform.position + (new Vector3(0, 1, 0) * (Time.deltaTime * speed));
    }

    private void OnCollisionEnter2D(Collision2D other)
    {
        //print(other.gameObject.name);

        if (other.gameObject.name == "MurDroit") {
            UnityEditor.EditorApplication.isPlaying = false;
            print("Player one win");
        }
        if (other.gameObject.name == "MurGauche") {
            UnityEditor.EditorApplication.isPlaying = false;
            print("Player two win");
        }
        if (other.gameObject.name == "Plafond") {
            transform.Translate(Vector3.down * Time.deltaTime * speed);
        }
        if (other.gameObject.name == "Plancher") {
            transform.Translate(Vector3.up * Time.deltaTime * speed);
        }

    }
#

my whole script

stone siren
#

Is this attached to your ball or the walls?

hollow agate
#

Ball

stone siren
#

Ok try doing this.transform

hollow agate
#

does the same shit

#

if you want I can screen share

#

maybe I am doing something wrong in unity xD

stone siren
#

I'm a beginner myself with C# but what it looks like you're doing is seeing if the walls are colliding with the ball, rather than the ball colliding with the walls? if that makes sense

hollow agate
#

so

#

should I go on the wall script then?

stone siren
#

Well, let me think about what you've got here for a moment lol ๐Ÿ˜›

hollow agate
#

ayt

supple cloak
#

hello i wanna shoot but i dont know how to do could you help me please?

#

if you wanna help you can write from direct message ๐Ÿ™‚

lucid crypt
#

Can you clarify what you mean, and tell us a bit more about what you're looking for? "Shoot" is a bit vague

subtle geyser
#

When using the 2D Tilemap, can you have specific tile types spawn various objects at runtime?

robust ivy
#

if not using that you gonna have to memorize the array somewhere and mark each tile you want with script using the int coordinate

distant rover
#

Any of you ever use AABB collisions? Isn't physics a bit overkill for a lot of games?

peak stirrup
distant rover
peak stirrup
#

not yet, will do

#

It didn't work

#

@distant rover

distant rover
#

maybe it's not hitting anything?

coarse acorn
#

I'm still unclear on the diffrences, but would Debug.LogFormat be more appropriate?

peak stirrup
#

I am clicking on stuff

#

do they have to be on the same layer?

distant rover
#

not sure sorry ๐Ÿ™

hidden plinth
#

@peak stirrup maybe object is too far from screen projection. try to increase 100.0f to a bigger value ?

#

Also make sure script is attached to a gameobject in the hierarchy (even an empty one)

#

And that your main camera really has that tag

peak stirrup
#

I increased the thing to 2000, still doesn't work, It is attached to the main camera

hidden plinth
#

alright, please Debug.log just before the hit.transform != null line

peak stirrup
#

still nothing

hidden plinth
#

๐Ÿค”

#

oh god

#

you're in 2d xd

#

Physics2D.Raycast()

#

Physicsis assumed 3D

peak stirrup
#

ok thanks

hidden plinth
#

You'll get another error, but you should be able to find that one ๐Ÿ˜‰

peak stirrup
#

yep

hidden plinth
#

you don't guess ?

peak stirrup
#

do I change it to vector2

#

nvm error

hidden plinth
#

RaycastHit2D

peak stirrup
#

I did that

#

but ray is giving me an error

#

It says cannot convert type Ray to Vector2

hidden plinth
#

yeah use the ray x and y to build a new vector2

#

strange, in 3d you don't need to, you can use Rays ๐Ÿ˜›

#

anyway, should be good then

peak stirrup
#

Should I just find the position of the mouse and use that?

#

with Input.GetAxisRaw("Horizontal");

hidden plinth
#

yeah that's the Ray

#

no, you already did it

#

Physics2D.Raycast(origin, Vector2.zero);

#

with origin Vector2 origin = new Vector2(ray.x, ray.y);

#

Sorry I gave it backwards haha

peak stirrup
#

oooh

#

that makes more sense

hidden plinth
#

๐Ÿ‘

peak stirrup
#

thank you

hidden plinth
#

You're welcome, happy coding !

#

Glad that it ticked, that's the most important

peak stirrup
#

the variable hit has an error and I don't know how to fix that, I'm pretty sure it's because it's never assigned any value.

hidden plinth
#

yeah assign to hit the result of the Raycast I didn't write all the code, you have to glue it where it makes sense

peak stirrup
#

ok

#

I did that and there are no errors but it still doesn't work

#

Do i have to set hit equal to the position of the object being hit?

dense flame
#

hit is a null variable there, it will not be equal to the raycast you make

#
RaycastHit2D hit = Physics2D.Raycast......
if (hit)
{
      //do something with hit
}
peak stirrup
#

ok

dense flame
#

Your discord state says youโ€™ve been playing aseprite for 5 hours

peak stirrup
#

it's open in the background

#

It still doesn't work

#

Does it need to hit a colider or just the object?

hidden plinth
#

Raycast will need a collider to hit yeha

#

then hit.collider

peak stirrup
#

still doesn't work

hidden plinth
#

you messed origin value

#

Input.mousePopsition is in screen space

#

you need to cast a ray from camera with it

#

you had id okay earlier

#

it*

#

This is taking too much time :p copy paste code here if that still doesn't work, we will fix it for you this time

peak stirrup
#

I got it to work

hidden plinth
#

awesome ๐Ÿ‘

peak stirrup
#

Thanks so much for the help!

hidden plinth
#

You're welcome, have fun

golden fox
#

Does anyone know how I can set the name of an individual tile in a tilemap through script? Tile.name = "something" doesn't work because it sets the name of the tile itself. I want to change the name of an individual.

dense flame
#

I think you canโ€™t, maybe make a class inheriting from tile with a string

#

Like cs public class MyTile : Tile { public string otherName; }

golden fox
#

might work actually

#

Thanks!

dense flame
#

Anyway why do you want to change the name?

golden fox
#

Because the system I have for placing and removing blocks revolves around differentiating between individual tiles

#

wait no

#

@dense flame how would I make that class apply to all tiles? I'm usually don't work with custom classes

#

its giving me a nullRef when i try to set the otherName of a random tile

dense flame
#

Search for scriptable tiles

golden fox
#

scriptable tiles apply to every tile of a certain type

#

i want to store data in an individual one

#

@dense flame I want a non global parallel to scriptable tiles, does that exist?

dense flame
#

Sorry I am not an expert on those things

golden fox
#

๐Ÿ‘

hidden plinth
#

@golden fox

public enum TileType {
    ROCK,
    GRASS,
    AIR,
    WATER
}
golden fox
#

Oh, thanks, but no, i figured out a better way for my apecific uae case

#

Use*

trim cairn
#

Good evening everyone !

I have a little problem with my project, can I ask for help here?

obtuse torrent
#

Would you recommend rb.velocity = [value] or rb.addForce() ?

snow willow
obtuse torrent
#

Ok

narrow gulch
#

hey, can someone help me?

#

sorry

#

so, i cant put 2d collision on objects, put tile collision on an object and 2d collision on the character, but it's not working

#

a script and animation

#

the object is stopped

#

ok thanks

trim cairn
#

I have a problem with my character's life, when I run the game or want to inflict damage on myself, or get attacked, I get this error in the console

snow willow
#

You neglected to assign a value to something

#

on line 35 of that file - you are trying to access that value which was never assigned

trim cairn
#

Okay, but how do you find out what this thing is? It can be an object like a script, right?

snow willow
#

yes...

#

first place to start would be to look at line 35 of your code

#

deduce what could possibly be null on that line

#

it has to be something you are dereferencing - e.g. something you are reading/writing a value from or calling a method on.

#

so something on the left side of the dot on a something.something statement

trim cairn
#

Here is line 35 of my code

snow willow
#

Ok so it's healthBar

#

healthBar is null

#

where in your code do you assign a value to healthBar?

trim cairn
#

In this script ?

snow willow
#

yes

#

where is healthBar declared?

trim cairn
#

I think I know where it comes from, tell me if that's it

snow willow
#

Yep

#

so

#

see how it says "None"

#

that means it's null

#

you need to drag your health bar into that slot

#

so find your health bar in the hierarchy window

#

and drag that object into this Health Bar slot from that screenshot

trim cairn
#

If I drag a prefabs from my health bar, does that make a difference?

snow willow
#

Yes it makes a difference

#

So the health bar is something that doesn't exist in the scene yet?

#

It's a prefab that gets instantiated?

#

(or part of one)

#

And what about "Death Zone"? Is that part of a prefab, or is it in the scene at the start?

trim cairn
#

In reality it is that of the scene that I rendered in prefab

#

DeathZone is a prefab for another level

#

If I modify a prefab, will it be modified in all my scenes?

snow willow
#

Yes

#

that is the purpose of a prefab

trim cairn
#

Alright, great thanks a lot for your help!

snow willow
#

np

trim cairn
#

Hmm .. I have another prefab to which I would like to add a reference but when I want to select the object, I see nothing .. (the object is also a prefab)

still tendon
#

Having a bit of a weird issue here with my project.

When trying to make a level finish system using a trigger block at the end of the level and using the Scene Manager to do it, it won't work as intended. It just stays at the initial level with no player character in sight. Additionally, in the Hierarchy I can see Level 1 flickering between loaded and not loaded twice over.

My code is basically checking for the 2D trigger collision then checking to see which trigger was hit (because i have enemies and coins to check as well). However, for the end trigger I am using a tag to check seeing as I have multiple end blocks. I am not sure why it is doing this behavior. If I need to post my code, I will do so if asked.

Thanks for any help you can provide ๐Ÿ™‚

#

I will also post a video of the issue on Unity if needed/requested

trim cairn
#

This problem has happened to me before, and I had unwittingly put two "Next level", check if you did not do that

still tendon
#

I am sure that I have not put two of the same level in the code or build settings. There are two distinct levels in the build settings at the moment.

#

I have also checked multiple times that the player does not spawn in a trigger block.

trim cairn
#

Can you upload a video of what's going on please?

#

Sorry

still tendon
#

I don't speak french if you couldn't already tell... but yes I will post a video.

#

No worries haha, I'm guessing you're google translating most of your messgaes?

trim cairn
#

Yes Kikoosauvage

still tendon
#

you might notice that it looks like the world's hardest game, this is intentional. lol

#

I can supply the code in the PlayerController script if needed.

trim cairn
#

Yes it looks very complicated haha! You probably forgot to put your scenes in the build settings

still tendon
#

No I have my scenes in building settings

#

@trim cairn Base level is just a test level that I have made to make sure that this concept works.

#

This is why I feel as though this is some sort of bug with the unity version I am using (i did not update from 1.4.f1 yet)

trim cairn
#

BaseLevel it's first level ?

still tendon
trim cairn
#

Ok, i can see your code and your trigger block inspector ?

still tendon
#

Yes, let me get the screenshot & pastebin link

trim cairn
#

Ok

still tendon
#

ignore the pastebin name lol

trim cairn
#

Why do you have tow Box collider ?

#

And you don't have script for the trigger block ?

still tendon
#

A) To differentiate the edge of the box with the inside of the box
B) I handle everything from the PlayerController mentioned before, which is stored on the Player.

#

I did the box colliders that way to make edge collision more precise

#

And for the player to actually be able to move because if the whole thing was a box collider the player would get stuck

trim cairn
#

Okay, I personally use a script for this, so I'm not sure exactly what this might come from .. sorry :/

still tendon
#

I thought the way that I did it would work perfectly but I'm not entirely sure where it failed

trim cairn
#

Do you have a box collider on your player?

still tendon
#

Yes.

trim cairn
#

It may be because of this, if your code is on your player and it has a box collider

#
private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.name == enemyCol.name)
        {
            transform.position = spawnPoint.position;
        }
        if(collision.name == coinCol.name)
        {
            coinCount++;
            coin.SetActive(false);
        }
        if(collision.CompareTag("Finish"))
        {
            levelNumber++;
            SceneManager.LoadScene(levelNumber);
        }
    }
still tendon
#

the thing is enemy and coin collision was working fine

#

but i had to do the tag for the finish because there were multiple end blocks that the player could hit

trim cairn
#

Mmh, okay sorry but I won't tell you where it came from (I'm still learning)

still tendon
#

:/

#

Hey did you look at the 2d collision matrix in Physics2D settings? Just one of the things I always check

#

Tags and layers are useful for that stuff

#

Hmm ill check to make sure to see if i spot something out of the ordinary but i never tampered with it in the first place

#

@still tendon am i missing something here because this looks normal to me

bitter monolith
#

Anyone know good tutorials for making monsters and a health bar?

tropic inlet
#

i saw one i liked for health bars

#

i don't even remember what it was called. . .

#

Anyway, searching "Unity healthbar tutorial" would probably yield satisfactory results

pine hawk
#

How to control the sound? For example, I have entered from the open environment to the closed environment, so the sound of rain should be less and return to the original state when I return to that environment. :)
What codes are used for it ? (2D)

pine hawk
obtuse torrent
#

Can somebody link something on how to make procedurally generated terrain?

obtuse torrent
#

yes

distant rover
#
obtuse torrent
#

nvm I found something

hallow onyx
#

Hello guys i have a small problem

#

can anyone help me?

#

i have 2 objects. i Instantiate obj1 from obj2. how can i know, who made obj1?

#

i mean is there anyway how to detect the make of an object?

distant rover
#

GameObject maker

#

when you instantiate:
newThing.maker = this

#

after you made it

hallow onyx
#

thanks i solved it ^^

distant rover
#

woo

hallow onyx
#

^^

hallow onyx
#

what is wrong in this:

#
        if(GameObject.FindGameObjectsWithTag(TagCard) == null)
        {
            print("there is no Card on Top of me ");
            isFull = false;
        }
distant rover
#

what's the error/issue?

hallow onyx
#

wait

#

Tagcard is by def is Null

distant rover
#

whats Tag?

hallow onyx
#

the Tag of an Object

#

u k

distant rover
#

double click on error and show code please

#

maybe not use it if it's null

hallow onyx
#

it shows me this if(GameObject.FindGameObjectsWithTag(TagCard) == null)

#

this line

#

it is

#

i tried to print it

#

and it shows Null

#

XD

distant rover
#

what's TagCard?

hallow onyx
#

lemme show u on private

trim cairn
#

Hey, I have a mistake in one of my scripts, could you help me? I have NPCs that I can chat with, but when I run the game I get this error and I can't figure out where it is coming from.

Script DialogueManager : https://hatebin.com/jukalzglpj

distant rover
trim cairn
#

I check this

#

No, sentences = new Queue<string>(); is called in Awake

#

And DisplayNextSentence() is called when player clicked on next in canvas

trim cairn
#

Do you have any idea what this can be?

distant pecan
#

sentences is null

#

probably wasn't initializated yet

#

change

if(sentences.Count == 0)

to

if(sentences == null || sentences.Count == 0)
runic burrow
# bitter monolith Anyone know good tutorials for making monsters and a health bar?

here is a brackeys tutorial for health bar in case your question wasn't answered https://www.youtube.com/watch?v=BLfNP4Sc_iA

Let's create a simple health bar using the Unity UI-system!

Get up to 91% OFF yearly Hostinger Plans: https://hostinger.com/brackeys/
Code: "BRACKEYS"

โ— Brackeys Game Jam: https://itch.io/jam/brackeys-3

โ— Project Files: https://github.com/Brackeys/Health-Bar

ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท...

โ–ถ Play video
trim cairn
snow willow
#

and/or call Destroy() on a prefab

#

prefabs are not in the scene, so you can't parent things to them

trim cairn
#

Hm, Yes it is, but the prefab was recorded in this scene that's why it surprises me ..

snow willow
#

recorded in this scene?