#πŸ–ΌοΈβ”ƒ2d-tools

1 messages Β· Page 44 of 1

lament spire
#

Never used it

#

is it in code or in the inspector that you link it to the player

dense smelt
#

nvm, I'm done, I got all of it working ima take a break from unity for today

#

I might have a problem tomorrow tho

#

we'll see

#

oh you know what, I will

#

I want a way to win

#

welp

#

bye

violet timber
#

that fixed it

upbeat sinew
#

Ooh also if anyone can suggest a tutorial which displays how to split one tile into multiple, that would be really helpful πŸ‘

austere sandal
#

Hey how to change light2d pipeline volumeopacity

lament spire
#

and then go in the editor and it should be pretty intuitive

lost temple
#

hey i was reading over the docs.unity to find a way to make a object in a 2D game only travel in 45,135,225,315 angle diagonals. The closest i got was rigidbody.constraints, if anyone has any suggestions I would greatly appreciate it. πŸ™ˆ

snow willow
ruby karma
#

You gotta code that on your own

vocal condor
snow willow
#

Oh i was reading that as 45 billion etc

vocal condor
lost temple
#

okay sorry. i'm making a object in a game that i want to restrict it to only move in these 4 directions.

vocal condor
#

Are you using a grid based system? Or free movement?

lost temple
#

free movement

snow willow
#

So only move it that way. You have full control over the motion of any objects as long as you don't use Rigidbodies

vocal condor
lost temple
#

how would i go about doing that? the initial input sets at those angles but as soon as it collides with anything it gets knocked off the path and travels in any direction πŸ™ˆ

#

i tried to play around with rigidbody restrict but I was getting no where with it

vocal condor
#

Else I'm guessing you're looking for some built-in way to simply constrain movement; which isn't available. Rotations can be constrained easily because they are states of your Transform (Object). Movement is more of an event process and would not be defined after the movement had been done (you wouldn't know where you've moved without evaluating movement).

#

Sounds like you are wanting to tamper with Unitys physics and likely will need to roll your own collision/deflection system.

#

Make the object colliders type trigger and process the collision events yourself?

lost temple
#

agh thought as much. I just felt like i was missing a simple built in command because it seems so basic moving in the 8 directions. I will try coding my own collisions to affect the transform.
sorta if it is traveling left to right* collides with a top of a block it will transform towards (y1 , x1)

#

cheers for your time though lads

fast siren
#
{
     void OnTriggerEnter2D(Collider2D other){
         if(other.CompareTag("Player")){
             Destroy(gameObject);
         }
     }
    }``` Is my code right? Whenever I collide with the coin, it never destroys the object. pls ping if you have an answer
snow willow
#

Do both objects have Colliders?
Is one or both of the Colliders a trigger?
Does at least one of the objects have a Rigidbody2D?

fast siren
#

yes, wym, and yes

snow willow
#

Is the player ragged properly?

snow willow
fast siren
#

no but i set it on rn

#

it works

#

tytyttytytytyty

snow willow
#

OnTriggerEnter2D is for trigger collisions which is when one of the objects is a trigger

fast siren
#

okay that makes sense

#

i didnt know that ty

snow willow
#

Otherwise you use OnCollisionEnter2D

fast siren
#

if i use oncollision do am i able to use it if 2 of the colliders have ridgid body

snow willow
#

Yes

fast siren
#

nice ty

snow willow
#

But neither one can be a trigger

cold niche
#

Im using the same code like @fast siren but with my code it wont work, i got all like in the tutorial.
what can i do now haha

fast siren
#

show code

cold niche
#

ehm how do i post it like yours xd

fast siren
#

triple ` on both sides

cold niche
#
        [SerializeField] p  rivate string sceneName;
        void onTriggerEnter2D(Collider2D other)

        {
            if (other.gameObject.tag == "player")
            {
                Debug.Log("Menu");
                SceneManager.LoadScene("Menu");
                //SceneManager.LoadScene(sceneName);//
            }
        }```
#

this is my code for quitting it would be better if this work

#
    {
        if (collision.tag == "Collectable")
        {
            Destroy(collision.gameObject);
            gem += 1;
        }
    }
#

and this is the one for coins but yea nothing works

fast siren
#

okay hm lets see

snow willow
snow willow
fast siren
#
if (other.CompareTag("Player")){
{do whatever}
}
}
fast siren
#

try that

cold niche
# fast siren try that

walk through like it's nothing,I have an error but I don't think it has anything to do with it, it's about Edge.WakeUp ()

#

do I need a certain layer or is it simply default

#

Update in playmode it worked someway, it stopped and threw me out of the game and not into the scene "menu", when I tried build and run nothing happened again

long hare
#

if i have multiple objects with a single script attached , i have it such that when that object interacts with another object it stops movement and attacks that object. How do i differentiate between the current object that is colliding with the enemy object from other objects that are not colliding with anything?

harsh imp
#

does unity has a built in sprite deformer to bend a bow?

still tendon
#

hey does anyone have videos on how to place assets in a grid form i'm new to unity so i'm not used to this stuff 😐

#

@ me when u have answers pls

upbeat sinew
#

Thank you @lament spire yes I created a new project and figured that part out last night

upbeat sinew
#

I would like to learn more about tiles, tilemaps, and tile related products πŸ˜‚ Does anyone know any resources that helped them with this?

upbeat sinew
#
    private void SelectTile(Vector3Int tilemapPos)
    {
        print("selecting tile at " + tilemapPos);
        this.tileMap.SetTile(tilemapPos, this.selectionTile);

        Tile tile = tileMap.GetTile<Tile>(tilemapPos);
        print("tile: " + tile);

        tile.sprite = this.selectionSprite;
          tileMap.RefreshTile(tilemapPos);
    }

Hello again πŸ˜… I am trying to highlight a tile on the map, and I've googled around this seems to be a common problem, maybe someone here has insight? Neither changing the tile, the sprite, or both the tilebase and the sprite make any difference, and refreshing the tile does not show a change either.

balmy umbra
#

How can I do this: ```CSharp

TileBase tile = new TileBase();

balmy umbra
upbeat sinew
#

What are you aiming to do Max?

#

@balmy umbra

balmy umbra
#

I allready solved it but still thanks for trying to helpπŸ‘

upbeat sinew
#

No worries πŸ™‚

upbeat sinew
#

I figure it out πŸ™‚ Thanks for letting me unload my thoughts πŸ˜„

glass linden
lost temple
#

hey so i'm was writing a code to spawn a door in the middle of the room when the boss dies but it keeps telling me it's a null reference when i try to use the function. I have made a game object and put a prefab in the slot in the inspector. Would anyone have any idea why it's not working? πŸ™ˆ
` public void MakeDoorVisable()
{
//spawns exit door under the position of the main camera
GameObject tmpObj = Instantiate(myDoor);

    tmpObj.transform.position = Camera.main.transform.position;
}`
#

myDoor is a public gameobject at the top of the code block btw.

turbid heart
lost temple
#

i have a call function in another script to test it

#

the underlined line is where the the runtime error points to

turbid heart
#

is your "test" assigned?

lost temple
#

it's at the top above update

turbid heart
#

assigned. not declared

#

you'll need to drag your nextLevel object from the scene into the "test" variable field of UtilityBehaviors's inspector

lost temple
#

oh okay πŸ™ˆ

#

thank you so much i'll test it

#

i dragged it into the inspector and it's still saying null

#

i'll try moving the whole function to another script to see if that changes it

turbid heart
#

could you post your UtilityBehaviors and nextLevel scripts in a paste site here? and the error you're getting

lost temple
#

yeh sure after i test this give me a bit

turbid heart
#

Are you sure you have β€œmyDoor” assigned? @lost temple

#

Actually can you show where you assigned β€œtest”? If thats not it, I’m stumped

lost temple
#

I just moved on to disabling the rigidbody and to change the sprite on the function now. it seems to be working lol

turbid heart
#

Alright

lost temple
#

it was assigned btw

#

idk why it wasn't working

turbid heart
#

I dont think that’s where you’re supposed to assign it. You need to drag it into the UtilityBehaviors script that is attached to an object in your scene

lost temple
#

hmm

#

give me 2 to try it

turbid heart
#

Which leads me to the question of did you attach those scripts to objects in the scene?

lost temple
#

yeh i have a object with next level in the scene just attached unitybehaviour to the player

#

still null refference

#

i'm just gonna disable the collider and change the sprite on function. idk why its not working

turbid heart
#

Ok

still tendon
#

Can someone Help me with my problem because I cant understand anything

#

I can send the script if someone needs it

abstract olive
#

Use a bin site to share code. Also, specify your issue.

wicked wasp
#

hy

#

someone now how to make a destructible block in unity 2d

#

with a life

#

i want to make destructible terrain like minecraft2d

#

and how to make a block hill which can get climb

#

by car

ruby karma
#

google marching cubes

tidal oracle
#

hey, sorry but is there any chance I could get some help with some wall jumping im trying to implement?

carmine stag
#

can someone help me with animating my player? I set it all up, but it does not properly transition from one state to another even though it's all set up properly. Basically the state does not change from idle to run, run to jump, etc.

grand cove
#

So when you move your character, the bool variables or whatever you use change state correctly?

carmine stag
#

I am not sure. I seems to be all correct, but I am not sure

#

I am just a beginner. haven't really done too much in unity.

grand cove
#

and how old is the video you are following <.<;

carmine stag
#

2018

#

is that bad?

grand cove
#

Well, if it's brackeys tutorials, then they are pretty outdated.

carmine stag
#

yeah it is

grand cove
#

there are several ways to make 2D character controllers.

carmine stag
#

ok

grand cove
#

so it's a bit hard to just take one video and go with it.

carmine stag
#

ok

grand cove
carmine stag
#

i will get back to you if I fail again

tidal oracle
#

Im having an issue that when my character wall jumps they move constantly along the x-axis until the hit a wall, anyone ever heard of this issue?

still tendon
#

Hey does anyone have any insight on how to place my sprite in tiles I’m really new to unity and I need help or a video that can help

still tendon
#

nvm i figured it out

dense smelt
#

I really don't want to rewatch this tutorial, but I guess I have to now

#

wrong channel...

carmine stag
#

hey @grand cove. I looked over the video you sent and messed around with it a little, but it still does not work. Can you take a look at all my work to see if you will find any mistakes?

still tendon
empty sail
#

Does anyone have the time to explain what am I doing wrong ?

abstract olive
#

Well, one thing you're doing wrong is expecting someone to invest time without knowing what the issue is.

#

Secondly, don't cross-post.

lament elbow
#

I need a bit of help. I don't know why it says this. I'm making a grappling hook, but the Console is saying, "Cannot create the 2D joint on 'Player' because it connects to itself. It shouldn't be connecting to the player, it should be connecting to the "ground" layer or "foreground" layer. Can someone please help me? If you need any more information let me know. πŸ˜…

I'll send my code if you need it. I'm not familiar with this error but I don't think its in the code. (Yes yes... I'm following a tutorial.)

snow willow
#

So when you pass in your LayerMask - I believe it's being interpreted as an integer and used as the maximum distance parameter instead of the layer mask parameter

#

If you mouse over the raycast call it should show you what each parameter is

crystal geode
#

what could be causing two boxcollider2Ds, both with rigidbodies, to not push against each other? When I run my program I'm able to make them just completely overlap, they don't seem to detect each other at all

lament elbow
#

I turned off one of my colliders and it's better but I need both of them in order for my game to work πŸ₯Ί Also when I fire it throught my foot collider it doesn't work.

#

I basically want it to ignore player colliders.

snow willow
#

The problem I think is that you're not passing the parameters correctly to the raycast

lament elbow
#

Thanks. Sorry I was just telling Nivrap that. I'm trying to figure out what you meant. πŸ˜…

#

Thank you Nivrap though!

lament elbow
#

I'm very basic level at coding.

snow willow
lament elbow
#

Ohhhh

snow willow
#

your mask should be going into the layermask parameter and not something like max distance

snow willow
crystal geode
#

rigidbody2Ds

snow willow
crystal geode
#

no

snow willow
#

@lament elbow @crystal geode is asking a completely unrelated question lol

crystal geode
#

one of them is X and Y locked, the other is a child object of my camera, and it moves along with it

snow willow
#

you guys have such similar names πŸ˜“

lament elbow
#

LOL

#

Yeah

snow willow
#

The X/Y locked one can't move at all, and kinematic rigidbodies don't react to forces or collisions at all anyway. So naturally you cannot get any reaction out of them

crystal geode
#

ah, that might explain it then

#

let me try something...

#

hmm

#

so when I lock the X and Y of the one attached to the camera and make it dynamic, the camera can still move it

snow willow
#

X/Y lock stuff is related to the object moving from forces

crystal geode
#

awesome

snow willow
#

it doesn't stop scripts etc. from moving it

crystal geode
#

cool, that works for me

#

but they still can't touch for some reason

snow willow
#

You still have one that's kinematic and one that's X/Y locked right?

crystal geode
#

no, both are dynamic and X/Y locked now

snow willow
#

ok so if they're both x/y locked then they will not move from forces

#

that's what it does

crystal geode
#

right, I don't want them to move

#

I want one to basically act as a barrier

#

and stop the one that's moving with the camera

snow willow
#

that means that one of them would be moving the other

crystal geode
#

ah

#

I see

#

hmm

#

so I need to have some way to have my camera box not X/Y locked

#

but still not fall due to gravity

#

and not be kinematic

snow willow
#

the barrier one should be kinematic. The one that's a child of your camera, you should make not a child of your camera, You should instead use MovePosition in a script to move it to a transform position that is a child of your camera

#

also re: gravity just disable gravity on it

crystal geode
#

ahh, okay

#

also yeah oops

lament elbow
#

I don't know if this helps with my question.

#

Lemme know if I'm interrupting plz

#

Looked like he had the answer 😬

snow willow
# lament elbow

See how in this screenshot the third parameter is distance

#

and that's where your mask is going

#

that's not good

lament elbow
#

OH this is all making a lot more sense now.

snow willow
#

try:
(Physics2D.Raycast(transform.position, targetPos - transform.position, float.PositiveInfinity, mask);

lament elbow
#

You're a legend

#

Thanks m8

empty sail
#

Can anyone please tell me what is wrong with this

hollow crown
#

Without the context as to what is wrong, it is very hard to tell

#

but I imagine you're running up against OnCollisionEnter2D not working

#

and that's because you are moving via Transform

#

and not by physics, like Rigidbody2D functions

still tendon
#

Well if I look better you shoul check if the object that has been hit actually has an enemy component

balmy umbra
#

Hi how can I get the lastMove direction of my player?
I allready tried a own method but both keys would have to go up at the same time for it to work the way i want.
Any ideas?

mental idol
#

ping me if you have something to say about my situation

balmy umbra
mental idol
#

yeah

balmy umbra
#

could you show me the animation in the animation tab?

mental idol
balmy umbra
#

or is the wiggle not the animation?

mental idol
#

its the animation

#

The problem is

#

The dagger is supposed to aim at the mouse

#

when the animation isnt playing

balmy umbra
#

and that part isnt workin?

mental idol
#

but the dagger only follows the mouse when I delete the weak animation

#

its somehow stopping the dagger from following the mouse

#

even though it isnt playing

balmy umbra
#

try rotating the weaponRot with the mouse and weapon place with the animation

mental idol
#

are animations that arent even playing supposed to affect objects

balmy umbra
#

sorry im stupud

#

try making that animation in the script using courotines if nothing else works

#

@mental idol

mental idol
#

sure, thanks

mental idol
forest quail
#

is transform.localRotation not a thing?
i can't get it to work (trying to flip my character)

vivid wagon
#

I'm trying to change the material of an entity using the new Entity Component System
In the entity debugger it looks like it is working and changing the materials, but it does not update in the game view

#

They are all blue/yellow, but in the entity debugger, some of them are linked to a red/black material

#

Why does this happen?

mild panther
#

How do I have a button say in one position in my 2d world instead of staying on the main camera?

snow willow
mild panther
#

How do I get a worls space cavas

#

Canvas*

snow willow
#

Just set the render mode of your canvas to World Space

mild panther
#

Oh ok and that will lwt me place it anywhere in my 2d world

snow willow
#

yes

foggy orchid
#

does anybody know how to do custom physics for 2d space like for example that my player is staying on the ground or wall or cealing or is just attracted to the nearest point that belongs to an object with a specific tag.. I searched on the internet but somehow im too dumb to understand it

snow willow
#

Just do this in FixedUpdate:

rb.AddForce(myCustomGravityVector, ForceMode.Acceleration);
foggy orchid
#

is the customgravity vector really just a x and y?

snow willow
#

it's a Vector2

#

so yes

#

obviously you'll need to calculate the direction and magnitude of gravity

foggy orchid
#

well yes thats kinda my problem

#

oh wait

snow willow
#

if it's for a planet you can use the standard gravity formula

foggy orchid
#

no no planet

queen coral
#

you can add the gravity force if the player is inside of a trigger or a length between check

foggy orchid
#

is it also possible to use raycast? as if my raycast hits the ground the gravity should be set to the ground angle?

queen coral
#

ye raycasts work

foggy orchid
#

okay thanks

snow willow
#

raycast would be kind weird imo

#

to do the raycast you need to know the direction to the thing

#

and if you know the direction to the thing, that's already the gravity direction, no?

queen coral
#

the direction to the planet is players position - planets position

snow willow
#

Maybe I don't understand exactly what you're going for

snow willow
#

well the other way around technically but still

foggy orchid
queen coral
#

you can do rigidobdy2d.addforce(planetdirection)

foggy orchid
#

btw when I use custom physics isnt then my complete movement script for the bin?

snow willow
#

you will need a custom movement script probably yes

foggy orchid
#

okay

foggy orchid
queen coral
#

try out every singe one and see what u like best you can olso not use it its not not needed for the force adding to work

foggy orchid
#

oh and btw whats about the Physics2D.gravity ?

#

isnt this something I could just use?

queen coral
#

rigidbody2d does have build in gravity

snow willow
snow willow
foggy orchid
#

but there istn a ForceMode.Acceleration

snow willow
#

Fixed

foggy orchid
#

oh okay thanks

queen coral
#

GL making you game

foggy orchid
#

thanks ! but one quick question xD do I need now to set the scale to 0 for the gravity right?

snow willow
queen coral
#

ye

snow willow
#

since you'll be doing your own gravity

foggy orchid
#

okay

#

appreciate your time guys

#

omg something is working xd but cant tell what

#

nvm

lost temple
#

I downloaded a sprite pack with multiple parts(arms, head, body) per sprite. Do i assemble all the sprites parts as a game object to make one big sprite or what do i do with the pieces?

#

nvm

#

i found you can just make a new sprite

#

sorry for the silly question

real pilot
#

Does someone know the name of an algorithm that combines two polygon paths (that form something like a torus) into a single polygon?

#

two paths (torus)

#

single path (polygon)

#

I need this for decomposing a tilemap's composite collider into multiple polygon colliders, to then generate shadow casters from their paths

modest marsh
#

if your paths never cross, you could cheat and do this with PolygonCollider2D quite easily (set two paths, then use P2D's CreateMesh)

willow current
#

How do I add like a timer to my dash system?

currently this is my dash code

// Dash Function
IEnumerator Dash(float direction)
    {
        isDashing = true;
        rb.velocity = new Vector2(rb.velocity.x, 0f);
        rb.AddForce(new Vector2(dashDistance * direction, 0f), ForceMode2D.Impulse);
        float gravity = rb.gravityScale;
        rb.gravityScale = 0;
        yield return new WaitForSeconds(0.4f);
        isDashing = false;
        rb.gravityScale = gravity;
    }

// Code in Update(), to check inputs and some other stuff
 if (Input.GetKeyDown(KeyCode.A))
        {
            if (doubleTapTime > Time.time && lastKeyCode == KeyCode.A)
            {
                StartCoroutine(Dash(-1f));
            } else
            {
                doubleTapTime = Time.time + 0.3f;
            }

            lastKeyCode = KeyCode.A;
        }

        // Dashing Right
        if (Input.GetKeyDown(KeyCode.D))
        {
            if (doubleTapTime > Time.time && lastKeyCode == KeyCode.D)
            {
                StartCoroutine(Dash(1f));
            }
            else
            {
                doubleTapTime = Time.time + 0.3f;
            }

            lastKeyCode = KeyCode.D;
        }
jolly hawk
#

You mean cooldown timer or cooldown to display on canvas?

dusty jolt
#

anyone know a good way to make a welding system so you can connect 2 objects together ingame?

lament elbow
#

I'm trying to make my Cinemachine follow my player after it re-loads and doesn't destroy. In my script it says it's finding my player but it still won't follow it.

Lemme know if you wanna see my code that I have because maybe IT can be changed, but does anyone know what I can do just to set the "follow player" ... to player, by code. While still having my player prefab enter the scene by not getting destroyed.

lament elbow
#

Hey is there anyone online that knows much about Cinemachine code that would be willing to give me a hand???

snow willow
#

You honestly shouldn't need much code for that at all

#

Just make the vCam a part of your prefab

#

have it preconfigured to look at and follow what you want

#

and set the priority high enough that it will take over as the camera when it comes into the scene

lament elbow
#

I've got something similar to that. I'mma send my code image

#

I don't know what's wrong with it πŸ˜…

#

Seems like it shouuulld work

snow willow
#

You shouldn't need that script at all is what I'm trying to say

lament elbow
#

😐

#

Woah

#

OHHHH

#

You mean put it into my player prefab?

snow willow
#

Yes put a virtual camera in your player prefab

#

already configured to point at the player and follow it

lament elbow
#

🀯

#

You mad genius

#

I'll try that. Thanks so much πŸ˜„

#

Nah it's not working

#

The follow of player doesn't exist after I enter a new scene

#

Because I have it set to don't destroy / destroy other object on load so that I can be in a proper place.

#

Yeah it says missing transform

#

Does anyone know if it's possible to make Cinemachine follow the player Tag or anything?

willow current
#

I have a wall sliding (and jumping) system but for some reason my player only slides down slowly for less than a second then just falls normally. If anyone can help me fix this it'd be awesome

https://paste.myst.rs/rv2ozciq

foggy orchid
#

so hey guys! im Still working on my custom Physics2D and this is my code. but theres an issue that I dont quite get.. its working as fine with the angle and stuff but my player is falling down like 2mph how can I like do him weight more.. when I add mass to him it doesnt change anything

cloud kindle
#

Hi, I'm currently working on a 2D project for school and am facing kind of a problem
I am changing the rigidbody position and transform.localscale at the same time in a Coroutine with a While(), It's working, it is, but the thing is it takes about 1 seconds for the scale to get to its desired value while it takes 3 seconds for the rigidbody to get to its desired poisition... They have the same speed * Time.deltaTime, but definitely the distance between localScale vector2s is shorter than the distance between both vector2 position (startPos and endPos)

any idea how I could get the speed in sync ?
tyvm!

cloud kindle
#

I,ve solved it using Vector2.Lerp

runic pawn
#

how do i give priority to hitboxes if they overlap?

#

im making a chess engine, and when u click on a piece it will instantiate a bunch of tiles which show the possible moves

#

however, occasionally it seems to clash with the 2d collider of the pieces themselves

#

it looks like this

#

it seems to prioritise the bishop's hitbox

runic pawn
#

welp, fixed it by messing around with some z-values

snow willow
#

Seems strange to me to be using colliders for a Chess engine at all

ripe edge
#

hi guys is there any way to implement depth perseption in top down 2d games in unity??

#

all the tutorials i found are for platforms games

snow willow
#

or just use other visual cues like... darkness/brightness

#

shadows

ripe edge
#

my project is a 2d pixel art top down game

#

i start thinking maybe i could use layers

#

i tryed to make 2 platforms with 2 layers (1: death layer/2: platform layer) and and i made them one over the other but it didnt work

fickle prairie
ripe edge
#

yeah zelda is a good example! well i can make it like falling holes and and when player collide he dies but the problem here what if there is a big hole or empty area between the player and his goal and he need to pull a lever or push a switch so he can activate a bridge to cross(instantiate the plaform game object) here where the problem cause the deadly area that the player cant cross without dying and now a platform has been added on top of the deadly area how to tell the game that the player need to cross the bridge without colliding with the deadly area

daring moon
#

Some ideas for how to make a chunk for a 2d survival game ? With what should i start?

upbeat sinew
#

Hey 2d devs πŸ‘‹

Was hoping for a bit of help here, I am trying to move my camera only something seems to be blocking it. Now I think, it's probably not being blocked, the update function must only run once when I use a condition, because my camera will only move if I stick it outside of any conditions even newly created ones

#

I am using this bit of code to move my camera to a desired target,

   cam.transform.position = Vector3.SmoothDamp(
      cam.transform.position, camTarget, ref camSmoothDampV, 0.5f);
#

The only way it moves the camera is if it is open in the update section, not under any ifs or other conditions. I am assuming it is because this only runs once, is there an alternative function I could use like perhaps, MoveTo?

queen coral
#

the reson its not moving is cuz every frame it moves it closer but if it doesnt get used again itll not move it it must be run every frame

#

moveto olso does the same

#

i dont think there is a way to move it slowly if only run in 1 frame

#

if u dont want to move it with scripts try using cinemachine its a unity add on that has alot of options to make camera movement

#

i found a way you could do it in 1 frame

#

you can use DOTween

#

its an animation creating with only moving parts

#

its animating without animation

upbeat sinew
#

hmm tweening yeah that's kind of what I was looking for

#

thank you @queen coral

#

I'm used to unreal alot of this is native there, still crappier though πŸ˜„

#

what about a while loop perhaps, while camera position != to target position then lerp?

upbeat sinew
#

πŸ˜… that stuck me an an infinite loop...

#

do I really have to use external software for this? Just want to move a camera lol

formal scarab
#

Look into Cinemachine maybe

upbeat sinew
#

gotta animate or something huh, okay i will check that out at least. DOTween really looked decent too just seems alot

formal scarab
#

Cinemachine is pretty awesome, I trashed all my code driven cameras once I got the hang of it

#

One of the best things they've added to Unity over time

upbeat sinew
#

Alright that sounds promising. Thanks, both of you πŸ‘

formal scarab
sly tartan
#

can someone explain me how random movement is done with a sprite? like walking around in random directions

rotund burrow
sly tartan
#

i got it turning now

#

how can i make it move forward always

rotund burrow
#

wdym

sly tartan
#

like

#

lol

#

that always and when it turns (which it does) it goes forward still

#

its an ant it it now turns every x seconds in a random way

rotund burrow
#

u mean u wanna make it continue in that direction?

sly tartan
#

but it doesnt move

#

no i want it always to go forward in his perspective

#

so when it turns it goes to another way

rotund burrow
sly tartan
#

i made this

#

so i know the position

rotund burrow
#

wait

sly tartan
#

alright

rotund burrow
# sly tartan alright

create some if statements where depending on the rotation of the sprite it will add a force in a certain direction

#

i dont know why that took me that long to come up with

sly tartan
#

idk how to do that

#

ive never done 2D

rotund burrow
#

i think u gotta do something like

if (transform.rotation.z = 90)
{
  rb.velocity.y = moveSpeed;
}
#

im not too sure myself

sly tartan
#

but ill put it in update tho

odd siren
#

hello guys

rotund burrow
#

hello

sly tartan
#

hi

odd siren
#

can somebody help me with my script

#

i tryed to make an scene switcher

sly tartan
#

can u send it

odd siren
#

the script?

#

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

public class ChangeScene : MonoBehaviour
{
public void MovetoScene(int 1)
{
SceneManager.Loadscene(1);
}
}

#

this

sly tartan
#

what

rotund burrow
#

thats just unnecessary

sly tartan
#

yep

rotund burrow
#

u can just use scenemanager.loadscene directly

sly tartan
#

yea and then like ("Nameofscene")

odd siren
#

what

#

can you correct me and then plsssss it belongs to me

rotund burrow
#

Scenemanager.loadscene("scenename")

#

i think thats what it was

sly tartan
#

help

#

lol

sly tartan
odd siren
#

can you send me the correct code pllls ._.

sly tartan
#

well what d you want to happen

rotund burrow
#

the scene name cannot be an int

#

it should be

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

public class ChangeScene : MonoBehaviour
{
    public void MovetoScene(string nameOfScene)
    {
        SceneManager.Loadscene(nameOfScene);
    }
}
sly tartan
#
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class ChangeScene : MonoBehaviour
{
    public void MovetoScene()              //call this if you want to chnage the scene (call it with MovetoScene())
    {
        SceneManager.Loadscene("**nameofscene**");
    }
}```
rotund burrow
#

if u use that code

sly tartan
#

i think i did in my prjects

rotund burrow
#

it works but it could be done better

sly tartan
#

but im not sure

odd siren
#

ok

sly tartan
#

yea well

rotund burrow
#

in the moveToScene function

sly tartan
#

thats all my code

rotund burrow
#

u wanna add a parameter

sly tartan
#

"it works so it works"

rotund burrow
#

true

sly tartan
#

cant i use this

odd siren
#

i have a queastion

sly tartan
#

idk how tho

rotund burrow
sly tartan
#

move the and the way its facing to

rotund burrow
#

i dont think that has anything to do with its position

sly tartan
#

ant*

#

oof

odd siren
#

where 1 is written do I have to add the name of my scene?

rotund burrow
#

yes

sly tartan
#

yah

rotund burrow
#

the name of the scene u wanna change to

#

but u do that when u call the function

odd siren
#

ok nice

rotund burrow
#

for example if the name of ur scene is Scene1

odd siren
#

yes

rotund burrow
#

it would be MoveToScene("Scene1");

odd siren
#

does i have to ride it in "" these

rotund burrow
#

yes

odd siren
#

oh ok

rotund burrow
#

scene names are always strings

#

i think

odd siren
#

you mean like this?

rotund burrow
#

No

#

thats u defining the function

odd siren
#

ok

rotund burrow
#

over there u can just name it 1

rotund burrow
#

for example

#
if (somethingHappened = true)
{
  MovetoScene("Free Coins")
}
rotund burrow
# odd siren you mean like this?

but as i said earlier u should just erase that whole function u wrote and just do

if (somethingHappened = true)
{
  SceneManager.Loadscene("Free Coins")
}
odd siren
#

ok

sly tartan
#

this is on the Z axis

#

how do i change it from different axis

#

it needs to be y

rotund burrow
# sly tartan

shouldnt it be RigidBody2d.velocity = tramsform.forward * moveSpeed * Time.deltaTime

sly tartan
#

well this works

#

its just on z and not y

rotund burrow
sly tartan
#

position

rotund burrow
#

can u show me what happens by screensharing it

sly tartan
#

in call?

rotund burrow
#

alright

sly tartan
#

ill mute myself

rotund burrow
#

same

sly tartan
#

ill call u ok?

rotund burrow
#

i dont have a mic anyways lol

sly tartan
#

lol

rotund burrow
faint sparrow
# sly tartan

transform.forward are equal to vector3(0, 0, 1) and that why its on Z, so if you need on Y you do transform.up i believe....and that equal to vector3(0, 1, 0)

sly tartan
#

how do i make it so that if it collides with "ant" it overlaps and not actually collides?

snow willow
sly tartan
#

oh how

snow willow
#

it's a checkbox on the collider

sly tartan
#

i know

#

but then what

snow willow
#

idk you tell me

#

what are you trying to do

snow willow
#

you just asked me how to make it able to overlap

sly tartan
#

yes

snow willow
#

trigger colliders don't physically collide

sly tartan
#

cuz now they hit eachother

snow willow
#

so it will overlap

sly tartan
#

so this will do?

snow willow
#

yes

#

or just removing the collider entirely

sly tartan
#

omg bruh

#

thanks so much lol

#

and no i need the collider for walls etc

#

thanks!!

#

wait

#

no

#

wait lemme test

#

now the walls dont work

#

lol

snow willow
#

If you're trying to make it so certain objects collide with certain other objects and ignore others you should use layer based collisions

sly tartan
#

whaaa

#

wait i have an idea

#

how do i set the collider trigger true in script

snow willow
#

nah that's not going to do what you want

#

you want to use layer based collisions

sly tartan
#

hmm

snow willow
#

by the time you get OnCollisionEnter, it is too late, the collision already happened

sly tartan
#

yea i found out

#

uhm

#

now i find it confusing

#

what do i check if i want the ants to not collied but them with wall i do

#

collide

snow willow
#

You need 3 layers right?

#
  • Ant
  • Wall
  • Player
#

or youi can use Default for the player, or whatever

sly tartan
#

well i dont have a player

snow willow
#

ok so what needs to collide with what

sly tartan
#

its just AI

snow willow
#

and what needs to not collide with what?

sly tartan
#

the ants collide with everything execpt eachoter

snow willow
#

ok so just uncheck the Ant/Ant box

sly tartan
#

kk thankssss

#

and then

#

do i

snow willow
#

And make sure your ants are on the Ant layer

sly tartan
#

make thier boxes is trigger?

snow willow
#

no

sly tartan
#

unchecked right

snow willow
#

leave the colliders as not triggers

sly tartan
#

alrighty

#

imma test

#

Yep!!

#

thanks a lot

snow willow
#

np

sly tartan
#

now my ants walk

#

and dont escape through walls

#

yaayy lmao

#

time to program the brain

mellow bane
#

Hello! For some reason my button doesn't work. It doesn't highlight or click to a darker colour but i put interactable on and OnClick set? Please help

snow willow
mellow bane
#

no i dont think

snow willow
#

You need one

#

GameObject -> UI -> Event System

mellow bane
#

ok tahnk you

#

i added it but it still doesnt work 😦 is it because it is in a prefab? do i need event system outside prefab?

snow willow
#

put it in the scene

mellow bane
#

what about the button does that have to be in scene or prefab?

lament elbow
#

Hey guys, how would you put in a code, if the player is touching a specific layer or tag then .......
I have a public static Player instance; in the player.

Like how would I make something like this work
if(Player.IstouchingLayer(Layermask.GetMask("Blank"))
{ Then do this.....}

snow willow
#

Use OnTriggerEnter to detect when they start touching

#

OnTriggerExit to detect them stopping touching.

wraith hawk
#

Hello guys, I have a question. So basically I am trying to create a game like Bubble Witch saga,where you have the tower and then you use the already instantiated object

#

I have Blocks instead of bubbles, and my blocks cannot go outside of the grid I have set. The thing is, I do not know how to first instantiate the object, and then shoot it accordingly. I have the Blocks be able to rotate as the user pleases

#

I have already made a working cursor and tower but My problem is shooting those Objects after, the game is in 2D. I tried with a way I found on youtube but it gets the RigidBody, whereas i do not have one on my objects

left lotus
#

GameObject.Instantiate() from a bullet prefab that has a forward velocity script on it?

#

What's the problem with using a rigidbody

#

If that really doesn't work, you could adapt the same script, except in your FixedUpdate you will have to move the object manually in code

#

You can have a script, such as, ShootsForward, which makes the object travel forward in FixedUpdate

#

Have it on your bullet prefab by default

wraith hawk
#

Everything kinda breaks when i use the rigidbody because I guess I always check when the objects go out of grid and relocate them, like in tetris, but when i applied the rigidbody it just fell down to the void

left lotus
#

Ah, I think I see. Yeah RigidBody links an object to Unity's physics simulation. So if you begin messing with the position yourself, the physics simulation gets a bit out of sync

#

But you don't necessarily need your blocks up top to be rigidbody's with gravity and such. Only your bullet

#

If you set the "isKinematic" checkbox on a rigidbody, it won't move because of physics/gravity/etc. Only when you do it thru c#

#

But it will still be a RigidBody for the use of collision triggers and such

wraith hawk
#

Yeah i get what you mean but my blocks are actually the "bullets" in that case like the bubble witch saga game which has bubbles.

#

Ohh okay i see

left lotus
#

Your bullet then could either be a regular rigidbody (probably with gravity turned off), or also an isKinematic rigidyBody where you are manually controlling the bullet movement

#

Ah interesting, can you elaborate on the blocks are bullets things

#

Sorry haven't played bubble witch saga, but from the look I believe I've played similar ones

wraith hawk
#

The bullets I have already have collision on them between the blocks, its like a tetris game the blocks are the actual bullets, and i want to shoot the blocks. Also i truly appreciate your help lol I am probably making fully beginner questions but ive been searching for some time to find an answer and i didnt manage to

#
    {

        foreach (Transform children in transform)
        {
            int roundedX = Mathf.RoundToInt(children.transform.position.x);
            int roundedY = Mathf.RoundToInt(children.transform.position.y);


            grid[roundedX, roundedY] = children;


        }

    }``` this is how i Add a block to the grid i have
#

and this is how i check if the blocks are outside the grid, ```bool ValidMove()
{

    foreach (Transform children in transform)
    {
        int roundedX = Mathf.RoundToInt(children.transform.position.x);
        int roundedY = Mathf.RoundToInt(children.transform.position.y);

        if (roundedX < 0 || roundedX >= width || roundedY < 0 || roundedY >= height)
        {
            return false;
        }

        if (grid[roundedX, roundedY] != null)
        {
            return false;
        }

    }
    return true;
}

}```

#

if they are not, I just use this transform.position -= new Vector3(0, -1, 0);

left lotus
#

Sorry gotta be offline for 20-30, will probably be in the channel later. But just to give you something to work with,

wraith hawk
#

yeah bro i totally get it You helped me enough i will try the rigidbody + isKinematic and will go from there

left lotus
#

You probably want to stay with what you've done but also use RigidBody's with isKinematic checked so it's true, and then you can use OnCollisionEnter, and compare against a tag, or name, or similar, to see what you're colliding against

#

There are of course many other ways to do it, but this way uses what Unity has built in

wraith hawk
#

I see, Yeah probably some already defined things will be easier for me cause i dont know a lot of stuff on this topic haha, thank you so much for your help bro I will try those

still tendon
#

hi! im trying to resize a ui slider at runtime but i get that the recttransform whit is not varible

#

how can i doit?

#

nvm

#

if anybosy wonder

lament elbow
#

Is anyone online able to give me a quick hand?

hollow crown
#

Just ask your question

lament elbow
#

I'm not sure why this is looping.

#

I'll explain

#

Basically this code is used on multiple objects. Doors have an object on on them that has the tag Door and the player has the tag player. Other objects in the scene have no tag. The ones with no tag transfer you just by touching. Which works. But the doors I want the player to have to press either the uparrow or w in order to change scenes.

#

But the doors right now for..... some reason... when you just touch them are transfering you and are looping between scenes over and over.

#

I might change it so that the door object itself has the tag door and change it to gameObject.tag in the script. Just to make things easier.

#

If more information is needed I can send it.

hollow crown
#

it's only going to change to the Next Scene you have declared in the inspector

lament elbow
#

Yeah like this

#

I really like this code because I can keep reusing it for each scene I want to transfer to.

#

But it broke somehow and won't allow me to make it so if I stand on a door tag I have to press the up arrow.

#

I had it working at one point but then I wasn't able to make it so if it's not a door tag I don't have to.

#

So at the moment. When I climb my ladder to "go upstairs" for example, I don't have to press the up arrow. Which is good. But my door I want to have to press the up arrow. But right now it's just warping me when I touch it.

hollow crown
#

currently you would have to hold up while you enter the trigger

lament elbow
#

That's what I'd expect but it's not for some reason.

hollow crown
#

you would need to use TriggerStay to make it work when you are inside the trigger

lament elbow
#

😲 What's that?

lament elbow
#

Cuz I wanna use this script for multiple things. Both for needing to press uparrow and not needing to.

hollow crown
#

Also, unsure whether you could use OnKeyDown, and might have to switch it to OnKey, as this is a physics event and is probably not called in Update specifically

lament elbow
#

That makes it work but then I cant do the "else ... (if the tag doesnt have door) then you can just walk through it and change the scene."

hollow crown
#

you would probably need to have both OnTriggerEnter and OnTriggerStay and handle each of those cases in them separately

lament elbow
#

OwO

#

I'll try that thanks

#

This also doesn't work. Might not have been what you were talking about too.

hollow crown
#

That's back to front, and you will also have to handle the "not door" part of the automatic transition

twin nebula
#

Does anyone know how to set raycast to where you touched on screen(IOS) in 2d

lament elbow
#

@hollow crown Thanks for your help. For some reason when this is my code, it doesn't let me use the up arrow or W to enter the scene. But everything else works now.

#

Oh also am I supposed to @ you?

hollow crown
#

It's because you need to flip the logic, so the one that detects input is in Stay, and the other one is in Enter

lament elbow
#

OH

#

OHHH ok

hollow crown
#

It's all good because it's not just a random @ πŸ˜›

lament elbow
#

Thanks

#

OHHH THANK YOU SOOO MUCH

#

It works perfectly now

hollow crown
#

Great! We don't allow gifs though πŸ˜‰

lament elbow
#

Oh sorry bout that. I should go read the rules. 6487_Big_Brain_Laugh

honest charm
#

Hi everyone πŸ‘‹ , I would need your help if you have experience in gameplay programming for a design issue :

The situation : I’m currently working with Unity, on a 2D platformer. I use the Unity’s built-in physics (Rigidbody2D and colliders) and I need to design a scalable system for the player’s movements. Indeed, I want to easily add some mechanics or some series of movements (like long jump in Mario by crouching and jump at the same time).

How you can help me : If you have some references of similar systems or any idea of where to start I would love hear your tips.

Thanks !

mortal ginkgo
#

okay i just have a question... does anyone know how they made the rotating in the original tetris on nes and stuff since im making a simple clone and thats the part im stuck on, and no i dont want to just rotate the piece. i use 64x64 boxes to make up the pieces

tidal oracle
#

Anyone here have much experience with A* Pathfinding? im looking for a way for my enemies to ignore the player if they are outside the enemies pathfinding grid

gleaming horizon
#

Do you have a Rigidbody2d and Collider attached to your bot?

#

Well, the first things to check would be that you're moving the bot through the velocity of the rigidbody or with the MovePosition function. If you are, I'd make sure they level geometry and bot are on layers which can collide with each other in the Physics settings of your project

#

oh, and make sure that you are using BoxCollider2D's

dreamy fractal
#

so, i know this is going to sound stupid, but does physics.checksphere work in 2d?

snow willow
#

There's a separate Physics2D class that has 2D stuff

dreamy fractal
#

ok, thanks

dreamy fractal
#

one last question, sorry, do character controllers work in 2d? or are they also 3d only?

snow willow
#

3D only

dreamy fractal
#

ok thanks

tidal oracle
mellow pine
#

hey uh this is my code

#

whenever i right click I slow time and rotate the player towards the cursor,

#

then im supposed to fling them towards it

#

but it only shoots the player either upwards or downwards, with the speed dictated by the orientation of the x arrow

#

with it shooting me faster the more vertical the x arrow is

#

and frankly im fuckin stumped

snow willow
#

maybe x position is locked for example

mellow pine
#

i do not

#

its a default rigidbody apart from the drag values

#

gimme ten im getting a coffee

mellow pine
#

man i can just not figure this out

#

after commenting this out the boost just isnt working at all

#

ah fuck man i give up for tonight

light crag
#

Hello,
I need to create a freezed lake, here's the upper layer of ice on the lake.
My ship must broke the ice layer, so I created multiple gameobject of ice layer which have a hinge join.
My question: How can I have the texture for each object to have a continuous look like the sprite above?

sleek carbon
#

Is anyone here experienced with Playfab? (@me with response)

proper gate
#

Some1 help a noob :3 i have a script for 2D game that spawns random blocks and they fall down and u need to dodge it. And the problem is i want to create a startscreen UI where i need to press space and then the blocks coming down i think i cant do that with an if statement? maybe some1 pm me who is good xD or to deactivate all the blockspawn.cs and the playermovement.cs till i press space and than it starts. i already have a Game Over screen with the seconds i achieved on it and when i press space it loads the scene(0) from new etc. now i just wanna make the startscreen right at the beginning when you start the .exe "Welcome to...game" your highscore is....press space to play

mellow pine
#

okay all my problems stem from these lines of code

#

i could add force instead but then movement feels like ice skating

#

how do I make movement feel less shit if i use force

forest portal
#

so I am working on the movement on my game and I have a crouch disable collider but the problem is when is collide with something the collider gets disabled and it doesn’t even say crouching is true in my Console (I have a debug.log statement), the player kinda slows down a bit and the collider gets disabled just like it’s crouching but it says crouching is disabled

mellow pine
#

isnt that just brackeys 2d tutorial

#

looks like it

forest portal
#

yeah lol

#

but I

mellow pine
#

have you finished watching it?

forest portal
#

but I’m trying to do my own system

#

yes

#

I did everything like him but I changed some values

#

and added sprinting

#

idk why the collider is getting disabled

mellow pine
#

send the code then ill see if i can figure it out

forest portal
#

I’ll send it in dms

mellow pine
#

dont

forest portal
#

oh ok

remote moth
#

How can i set the rotation from a child object in script

#

if i set the parent rotation to 0,0,45 then is the child rotation automaticly 0,0,-45

signal zinc
#

@remote moth can you explain a bit more

#

what you want to do

remote moth
#

yes, i want fields rotate so:

#

(one square is on e object)

#

so i have first tried to ratote them at z -45

#

with paren work it but when i in code rotate the parent to 45, then it set all childs the z rotation to -45

#

and i can't edit the child rotation in the code

snow willow
unique storm
#

So, how do I remove sprite renderer from a certain object, but I would want to find that object by it's name.....

#

and later I want to add sprite renderer to the same object

#

I tried this: ```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class rendering0 : MonoBehaviour
{
public GameObject bg;
public GameObject fg;
public GameObject bg1;
public GameObject fg1;
public GameObject bg2;
public GameObject fg2;
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Collision(Collider hit)
{
if (hit.transform.gameObject.name == "ColliderCubeThingy")
{
bg.GetComponent<SpriteRenderer>().enabled = true;
fg.GetComponent<SpriteRenderer>().enabled = true;
bg1.GetComponent<SpriteRenderer>().enabled = true;
fg1.GetComponent<SpriteRenderer>().enabled = true;
bg2.GetComponent<SpriteRenderer>().enabled = false;
fg2.GetComponent<SpriteRenderer>().enabled = false;

    }
    else if (hit.transform.gameObject.name == "ColliderCubeThingy1")
        {
        bg.GetComponent<SpriteRenderer>().enabled = true;
        fg.GetComponent<SpriteRenderer>().enabled = true;
        bg1.GetComponent<SpriteRenderer>().enabled = true;
        fg1.GetComponent<SpriteRenderer>().enabled = true;
        bg2.GetComponent<SpriteRenderer>().enabled = true;
        fg2.GetComponent<SpriteRenderer>().enabled = true;
    }
    else if (hit.transform.gameObject.name == "ColliderCubeThingy2")
        {
        bg.GetComponent<SpriteRenderer>().enabled = false;
        fg.GetComponent<SpriteRenderer>().enabled = false;
        bg1.GetComponent<SpriteRenderer>().enabled = true;
        fg1.GetComponent<SpriteRenderer>().enabled = true;
        bg2.GetComponent<SpriteRenderer>().enabled = true;
        fg2.GetComponent<SpriteRenderer>().enabled = true;
    }
    }
}
#

nvm, this won't work for other ways

#

I want to render out parts of my map that won't be seen from the current position of my character..... How do I do this?????

#

(if you can help me, please ping me, so I can see it.....)

still tendon
#

I want to make the surrounding grid blocks bounce up like the one i click on, but delayed so it forms a wave-ish shape. how would i go about doing this?

carmine stag
#

Question! Here's my code. I need the frog that it's controlling to jump there and back, but it only jumps once and stops. Help! It's for a 48 game jam with 17 hours left so i need help asap please.

native token
#

anyone have a idea how to make a simple plants vs zombies style building system? ive tried multiple tutorials but they dont do the trick

#

like drag and drop a item onto a grid

fair vessel
#

like what are you struggling with? which part? spawning objects? aligning them?

native token
#

right now i can click, spawn in a dummy prefab and then when i let go of the mouse destroy it but thats as far as ive got

#

so not very far

fair vessel
#

kinda sounds like that's the bulk of it? what else do you want it to do?

#

make a build selection bar to choose which unit you wanna spawn?

native token
#

well the things on the to do list are to make some sort of grid wether its in a script or just some gameobjects doesnt matter

#

then i would need to have the dummy prefabs im instantiating interact to build on the grid when i let go of the mouse

fair vessel
#

er.... well you can use the grid game object and use this code:

Vector3Int _gridPosition = _map.WorldToCell(_mousePosition);```
#

errr wait that might be the opposite, one sec

native token
#

so that code would detect when my mouse is over the grid game object?

fair vessel
#

ah yeah this should convert grid coordinates to world position:
_UnderMap.GetCellCenterWorld(**grid coords here**)

native token
#

and all of that would go in the update method of the grid gameobject?

fair vessel
#

well what you can do is click an area with the first code, and that would return the closest grid coords - then the second code would convert the grid coords back to world coords, which is where you would place the sprite or prefab or w/e

#

update and then check for the left mouse click input

native token
#

ok ill give it a shot

#

should i use empty objects with box colliders?

fair vessel
#

i dunno, what do you plan on doing with this?

#

up to you

native token
#

ok

native token
#

ok so ive made quite a bit of progress but ive hit a wall

#

right now when i click on my gui i can drag a dummy around and when i let go of the button it deletes itself

#

there are grid objects that light up when im dragging said object around

#

i have a event on them that on mouse up will instantiate a prefab

#

but for some reason onmouseup doesnt work with dragging

#

i modified my code to not delete the dragging prefab and when i let go of the mouse i have to click again to instantiate the object

#

theres alot of code but i will post it

turbid heart
native token
#

oh i cant delete the messages and resend it then

#

can*

#

there

#

thats what it does

fair vessel
#

can you instad of destroying the draggable instance, just drop it at the appropriate position?

native token
#

What do you mean?

fair vessel
#

instead of destroying the instance attached to your mouse, instead just drop it? would that work in your case?

#

it gets destroyed because you are telling the code to destroy it

#

twice if i counted correctly

native token
#

So deleta that and then see what happens?

fair vessel
#

well you could have to fix the position of the instanced object at some point, but yes, in general

native token
#

I think I’ve tried that

#

when the code doesn’t deleted on mouse up

#

The object just sits there

fair vessel
#

is that not what you want?

native token
#

Then if I click a grid space after I already let go then it places

#

No that isn’t what I want because the object on the cursor is just a dummy

fair vessel
#

you have a grid, use that code magic i sent earlier to get the center position of the individual grid cell and place the instanced object on that spot using the .GetCellCenterWorld() function. then in another array record spots already used

#

then if a spot is already used dont allow them to place a unit there

#

that's how i imagine i would do it

#

because that is how i do it XD

native token
#

So then when I get the center I can instantiate the object then delete the dummy that follows the cursor?

fair vessel
#

why have a dummy follow the cursor? why not just have the object? you can do it your way, i believe that would work

#

maybe you use a dummy for performance or for a certain look

#

that'd make sense

native token
#

Ok thanks for the help

fair vessel
#

look into the following commands:
_tempMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
_gridPosition = YOURGRIDHERE.WorldToCell(_tempMousePosition);
_SelectedGridsCenter = YOURGRIDHERE.GetCellCenterWorld(_gridPosition);
this is the magic you need for organizing/instancing objects to a grid

#

there might be a better way if someone more advanced than me wants to chime in, this seems somehow a bit inefficient, but it does work! πŸ˜…

foggy orchid
#

do you guys encourage to use Physics2D.gravity to change the gravity or should I use something else

snow willow
#

That's the only way to change the built-in gravity

foggy orchid
#

does anybody know how to do custom gravity for a 2d game with the corresponding walk movement und jump stuff.. im really trying hard but im cant get it to work... It would be amazing If I could show the code to someone its a bit big for in this chat here.. so pls anybody hit me up

cinder perch
#

spot the 2 bugs and win a prize

#

this sometimes happens as well

#

except there he can move and not fall through and cant jump

#

tilemap thing

native token
#

when i instantiate a object, that object has a script and i want to refrence a script on the object that instantiated it, how would i do that

snow willow
#

in my opinion it's better to just have whatever be a reference to your script type in the first place and then clone will already be of your script type

native token
#

that is the opposite of what i want i think

#

i want the clone object to refrence the script that created it

snow willow
#

Then you add one line:

#
var clone = Instantiate(whatever);
MyScript m = clone.GetComponent<MyScript>();
m.referenceToCreator = this;
native token
#

how did i not think of that

#

ty

foggy orchid
#

does the rb.addforce just add force to the current one or does it overwrite it? (maybe its obvious but want to be sure)

snow willow
#

If you want to overwrite it you would first do:

rb.velocity = Vector3.zero``` and then add your force
#

or just set the velocity directly to what you want instead of using AddForce

#

the end result of AddForce is always just to change rb.velocity

foggy orchid
#

k thanks!

red glacier
#

I'm going to be adding the input system to my local multiplayer game soon, and I'm wondering how I would make it so whenever a new player joins it sorts their collision layer?
Since I don't want the player bullets to collide with their shooter and accidentally kill them, I have 4 collision layers for each 4 players. And if the player was a prefab and is spawned using the input system or whatever, I presume it would stick to the same "player1" layer and the players couldnt kill eachother. is there any better way to do this?

#

or should i put this in the input system channel actually, i cant really tell.

snow willow
red glacier
#

thanks for the quick reply! I'll try that out as soon as I can, and if it dont worky ill come back.

unique storm
# still tendon you didn't call "Collision" anywhere. you probably wanted to use this https://do...

I changed it to : ```cs
void OnCollisionEnter(Collision hit)
{
if (hit.transform.gameObject.name == "ColliderCubeThingy")
{
bg.GetComponent<SpriteRenderer>().enabled = true;
fg.GetComponent<SpriteRenderer>().enabled = true;
bg1.GetComponent<SpriteRenderer>().enabled = true;
fg1.GetComponent<SpriteRenderer>().enabled = true;
bg2.GetComponent<SpriteRenderer>().enabled = false;
fg2.GetComponent<SpriteRenderer>().enabled = false;

        }
        else if (hit.transform.gameObject.name == "ColliderCubeThingy1")
        {
            bg.GetComponent<SpriteRenderer>().enabled = true;
            fg.GetComponent<SpriteRenderer>().enabled = true;
            bg1.GetComponent<SpriteRenderer>().enabled = true;
            fg1.GetComponent<SpriteRenderer>().enabled = true;
            bg2.GetComponent<SpriteRenderer>().enabled = true;
            fg2.GetComponent<SpriteRenderer>().enabled = true;
        }
        else if (hit.transform.gameObject.name == "ColliderCubeThingy2")
        {
            bg.GetComponent<SpriteRenderer>().enabled = false;
            fg.GetComponent<SpriteRenderer>().enabled = false;
            bg1.GetComponent<SpriteRenderer>().enabled = true;
            fg1.GetComponent<SpriteRenderer>().enabled = true;
            bg2.GetComponent<SpriteRenderer>().enabled = true;
            fg2.GetComponent<SpriteRenderer>().enabled = true;
        }
    
}``` But it still isn't working.....
limpid valley
#

does anyone have any idea why contactfilter2d isn't working properly here? i feel like i've tried everything

        {
            layerMask = LayerMask.GetMask("Player")
        };

        print(contactFilter.layerMask.value);
        RaycastHit2D[] rh2dRes = new RaycastHit2D[1];
        Physics2D.Raycast(rigidbody2D.position, Vector2.down, contactFilter, rh2dRes, 5f);
        Debug.DrawRay(rigidbody2D.position, (rigidbody2D.position + (Vector2.down * 5f)) - rigidbody2D.position, Color.white, Mathf.Infinity);

        if (rh2dRes[0])
        {
            print(rh2dRes[0].transform);
            print(LayerMask.LayerToName(rh2dRes[0].transform.gameObject.layer));
            return true;
        }
        return false;```
still tendon
limpid valley
still tendon
limpid valley
#

put the snippet inbetween ``` and ```

still tendon
topaz peak
native token
#

in my game my bullet gets instantiated and then it goes foward, when it hits my enemy nothing happens

#
    {
        if(collision.gameObject.layer == 6)
        Destroy(this.gameObject);
    }```
fair vessel
#

i havent done a lot with collision but from how it seems, it looks like you check if the object it collides with is on layer 6 and if so destroy the bullet? i feel like this is a pretty obvious question, but what layer is the enemy on?

#

i think checking a tag might make more sense? tag all the enemies as enemies then look for a tag? if you'd be willing to show the game objects for a bullet and enemy (and all related properties) that might help. if you havent figured out your issue yet, that is.

native token
#

yea i shouldve used tags from the start

#

tried to do some stuff with the collision matrix but it wasent ment to be

fair vessel
#

@topaz peak what does your code look like?

native token
#

although it still doesnt work

#

i think ive done something wrong the colliders because i removed all the code from oncollision enter and just put a print(collision) and still nothing

fair vessel
#

if you'd be willing to show the game objects for a bullet and enemy (and all related properties) that might help. if you havent figured out your issue yet, that is.

native token
#

like a screenshot of the inspector

#

ok

fair vessel
#

yes

#

of a bullet and enemy

native token
#

thats the bullet

#

the things you cant see are the transform and sprite renderer

#

thats the enemy

fair vessel
#

that's alright not super worried about the renderer or transform

native token
#

im not sure if that will work for me

#

ill keep looking

fair vessel
#

yeah sorry im not more help haven't used colliders that much besides detecting a mouse

#

still pretty new too

native token
#

thanks for trying to help tho

#

it seems the problem was it being kinematic

#

i put it to dynamic and then put all the values to 0 and then it worked

fair vessel
#

both of the bodies?

faint sparrow
still tendon
#

I have this code that sets the camera to lerp between the mouse and player but for some reason as the character moves away from the mouse the camera becomes heavily off centered

#

How could I fix this

#

Even if i place the mouse on the player after movement the camera is still heavily off centered

#

If this is just a con im gonna have to deal with what are some ways i might be able to replicate the effect of the camera staying smoothly between the mouse and camera

#

Does anyone know why when I change the level using index, it just always takes me to the 0 index level?

turbid heart
still tendon
#

I know this is bad but

#

that's the only way something works

#

one of them is on a trigger and another is for the ui stuff(canvas)

turbid heart
still tendon
#

yeah so am I

turbid heart
#

so you're saying you put load the scene with the index of 2, but your scene with index 0 gets loaded instead?

still tendon
#

yeah

#

every time

#

I've tried everything

#

this might have to do something with the code loading it twice, WHICH I KNOW IS Bad, but i just need to get it working

turbid heart
#

can i see your build settings

still tendon
turbid heart
#

so you're trying to load Prototype2, but Menu gets loaded?

still tendon
#

yeah

turbid heart
#

oh, so those are 2 different places you tried to load scene index 2. That was mighty confusing -_- those arent related?

#

honestly, no idea what's wrong at this point. are you sure you're calling that function that loads scene 2? Debug.Log to be sure

#

did you assign the correct function to the animation event? which is how i'm assuming you're calling OnFadeComplete()

still tendon
#

I'll check everything, I probably have an idea why this is happening, thanks for the help

honest summit
#

your levelToLoad is on different class, they are not connected

still tendon
#

Is there any way to somehow make one script call a function from another script?

still tendon
#

yeah but these tutorials don't help

turbid heart
#

do they not?

still tendon
#

they'

#

they're confusing af

turbid heart
#

that's not the tutorial's fault

still tendon
#

ill try tho

jolly hawk
#

You can call other method like this: declare a object PlayerHealth playerhealth;

#

Then on Start() method: playerhealth.Getcomponent<PlayerHealth>();

#

And to use this method, you can just write PlayerHealth.(insert function name)

whole musk
#

is there a way i can generate a 2d grid visually without spawning a bunch of sprites?

jolly hawk
#

And make sure method you want to call is public, Sorry for miss information serializefield does not work on calling methods, only to show private method on inspector

white cedar
#

can someone help me out? I need to this, but i don't know how i should aboard this

white cedar
#

its a work that I have to do to my university

turbid heart
#

yeah we can't help you with your homework. attempt it first. if you run into problems, you can ask like any other coding issue

#

but we will not do your homework for you

weary hull
#

does anyone know how to make a 2d jetpack go up? but not like a jump.

still tendon
weary hull
#

yeah blike getting progressivly stronger

still tendon
#

like rb.AddForce(transform.up * someSpeed)

weary hull
#

so it still isnt going up at all. I would show you my code but i cant type that much text here

snow willow
#

You would call that every FixedUpdate while your jetpack is active

weary hull
#

is there anywhere i can share large chunks of code here? because i read what you're saying i just don't know if i'm implementing it right.

still tendon
snow willow
#

Or https://paste.myst.rs if that one doesn't work for you

weary hull
#

fire3

still tendon
#

also try increasing runSpeed

#

or multiply it with it's own variable

weary hull
#

OK!! We Got It!! Yo! Tango Down!!

#

4hours of late night google has come to an end

wicked wasp
#

hey

#

how can i shoot a bullet ?

abstract olive
#

Has no tutorial online for one of the most common features of a game worked for you?

wicked wasp
#

i tried to search tutorial online but they doesn't work

cedar stag
#

Hi, I want to make a 2d game. But i have aquestion. I have crosshair which is on the moouse position, but I want to draw a maximum range of the crosshair around the player. So when the mouse is outside of the range, the crosshair's position stops and rotates around the player on a circle

The blue gizmo is the max range, and the green gizmo is the "crosshair" which follows the mouse

knotty barn
#

Follow one to start with so we have a base to work from

wicked wasp
#

ok

snow willow
wicked wasp
#

the bullet does not move

snow willow
#

Set the crosshair position to the result of that^

wicked wasp
#

@abstract olive in unity 2d

#

i want to make that

abstract olive
#

Don't be so ridiculous

wicked wasp
#

ok

abstract olive
#

Just add "in 2d" to the Google search.

wicked wasp
#

I've already tried those tutorials

#

all

cedar stag
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCombat : MonoBehaviour
{
    //Attack variables
    public Transform attackPoint;
    public float attackRange = 1f;
    public LayerMask enemyLayers;
    public int attackDamage = 40;
    public float attackRate = 2f;
    float nextAttacktime = 0f;

    //build and break variables
    public Transform buildPoint;
    public float buildRange;

    // Update is called once per frame
    void Update()
    {
        if (Time.time >= nextAttacktime)
        {
            if (Input.GetMouseButtonDown(0))
            {
                Attack();
                nextAttacktime = Time.time + 1f / attackRate;
            }
        }
        attackPoint.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    }
    void Attack()
    {

        Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);

        foreach (Collider2D enemy in hitEnemies)
        {
            Debug.Log("We hit " + enemy.name);
            enemy.GetComponent<ObjectHealth>().TakeDamage(attackDamage);
        }
    }
    void OnDrawGizmosSelected()
    {
        if (attackPoint == null)
            return;
        Gizmos.color = Color.green;
        Gizmos.DrawWireSphere(attackPoint.position, attackRange);
        Gizmos.color = Color.blue;
        Gizmos.DrawWireSphere(buildPoint.position, buildRange);
    }
}

snow willow
abstract olive
#

They work. You haven't followed them properly. You're not making such a unique game that this problem is only specific to you.

cedar stag
#

this is my code now

snow willow
#

@cedar stag

attackPoint.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);

replace with:

Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
attackPoint.position = Vector2.MoveTowards(transform.position, mousePosition, attackRange);
cedar stag
#

Thank you very much! I'm pretty new to UnityCS and it's pretty confusing sometimes.

Just had to change
attackPoint.position = Vector2.MoveTowards(transform.position, mousePosition, attackRange);
to
attackPoint.position = Vector2.MoveTowards(transform.position, mousePosition, buildRange);

unique storm
#

How do I check collision between two layer masks?????

snow willow
snow willow
unique storm
#

Never mind, I did it differently

snow willow
#

If so you should be able to do this:

int result = mask1 & mask2;
bool theyOverlap = result != 0;
#

alright

unique storm
#

thanks anyway

#

Also, one more question, I want my projectiles to get deleted/destroyed when they hit my enemy..... They are all clones, how would I do that?????

#

I know how to check for hit

snow willow
#

They need to have rigidbody2Ds and colldier2Ds

#

and then you can check in OnCollisionEnter2D or OnTriggerEnter2D for the collision

unique storm
#

Thank you a lot.....

cedar stag
idle kite
#

Hey guys πŸ™‚ very new to Unity:
I have a bunch of ScriptableObjects (.asset files?) and I want to initialize and display them all when the game begins. What's the proper flow here? can (and should) I 'convert' them into GameObjects?

snow willow
#

ScriptableObjects just hold data so is there some text or images or models you want to show in the game?

idle kite
#

Yes πŸ™‚ they're actually a bunch of card datas and they all have a Sprite which I want to display

#

(in a gird view, but I guess it doesn't matter)

snow willow
#

You can do this all in script - or create a prefab that has the spriteRenderer and just assign the sprite in the script.

#

To do it all in script would be something like:

// create a GameObject
GameObject myNewGo = new GameObject();
SpriteRenderer sr = myNewGo.AddComponent<SpriteRenderer>();
sr.sprite = myScriptableObject.sprite;
#

If tis is a card game it may make more sense to make this thing intoa prefab and Instantiate it - then have a script on the prefab that has a function like SetMeUpBasedOn(MyScriptableObject so), and you call that to have the object set itself up based on the SO

#

this is a lot of pieces though - you'll need to take it slow as a newbie

#

try to get a single object created and displaying your sprite, then think about expanding that to do all the cards you want to show

idle kite
#

Ohh ok I will try it out! thank you πŸ™

snow willow
#

myReferenceToTheOtherScript.enabled = false;

weary hull
#

Ok! Now I'm attempting a "dash" ability im trying to guess how to make it require 2 inputs "fire1" and a "horizontalMove" Input. I watched https://youtu.be/G3cGpnuzVHU to get an idea but he is using a detection instead of a second input.

Consider donating to help me keep this channel and website alive : https://paypal.me/supportTheGameGuy πŸ’–

Support me on Patreon : https://www.patreon.com/the_game_guy

In this video im gonna show you how to make the player character dash in mid-air like the famous Hollow Knight game, You could make changes to the dash settings by playing around ...

β–Ά Play video
foggy orchid
#

My player is kinda lagging or jittering while playing... can the cause only be the way i add force to my player or can It have other issues?

#

or can it like come from something else

#

oh it can also be the cam right?