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

1 messages ยท Page 33 of 1

snow willow
#

What do you mean?

trim cairn
#

I created the gameObject in the scene in question then saved in the prefabs

snow willow
#

Yes

#

ok

#

Now the state is that you have a prefab

#

and you have an instance of that prefab in the scene

trim cairn
#

Yes

snow willow
#

but the prefab has no knowledge or memory of which scene it was "recorded" from

#

You can parent things to/delete the instance that is in the scene, but not the prefab itself (in the project window)

trim cairn
#

I remove the gameObject from the scene and replace it with the prefab, is that it?

snow willow
#

I don't know what you are trying to do

trim cairn
#

In fact, I created an NPC that is supposed to open a menu with items to buy, but for that I had to create a prefab of the buttons so that the items appear, but I made sure that the original is destroyed and replaced by the prefabs

#

This is my prefab

#

And i don't have my other items

snow willow
#

I just let the GridLayoutGroup or HorizontalLayoutGroup or whatever be empty until items are added

trim cairn
#

I send it to you, thank you for your help

snow willow
#

In your shop manager script - what did you assign to these fields in the inspector?

    public Transform sellButtonsParent;  ```
trim cairn
#

Only SellButtonPrefab it's a prefab

snow willow
#

ok - Sell Buttons Parent is another reference from the scene?

#

Or is that from a prefab as well?

trim cairn
#

OWH ! I got something by modifying SellButtonsParent!

snow willow
#

Oh good

#

I was going to say this setup looks fine assuming the sell button parent is from the scene

trim cairn
snow willow
#

Well it's working you just need to work on the layout part ;D

trim cairn
#

Thank very much !

#

I add you in the credit scene โค๏ธ

snow willow
#

haha cool ๐Ÿ˜›

trim cairn
#

It's not a big game but.. It's a way of thanking kind people like you

pallid lion
#

I am having problems with 2d pixel sprites. Some pixels are bigger than others. There was someone with the same issue and a person preferred to use a pixel perfect camera. I did and nothing changed. What could I have done wrong?

#

PPU 32.
Reference Resolution 320, 180
Pixel snapping enabled.

trim cairn
#

Can you show your problem please?

pallid lion
#

I will post it later here

trim cairn
#

Ok just one seconds

#

Are you using tilemap ?

pallid lion
#

No

#

Is this the problem?

trim cairn
#

No I don't think so, but personally I use a tilemap and it's much easier

pallid lion
#

But would it solve the "diffrent pixel size" problem

trim cairn
#

If you use a 200x200 image and another 16x16, it might look strange but they are the same size

#

Sorry

pallid lion
#

No problem

pallid lion
#

I have a 32x32 sprite

trim cairn
#

Ok ?

pallid lion
#

And some pixels of this sprite are thin while the others are wide

trim cairn
#

Uhmm

#

Are the pixels clean or ugly?

#

Like this ?

pallid lion
#

I found a picture

#

Pls ignore the art. I improved a lot, but if you look closely you can see that some pixels are bigger than other

#

And sorry for the bad quality.

pallid lion
trim cairn
#

Have you set the filter mode to Point(no filter) and Compression to None ?

pallid lion
#

Yes

trim cairn
#

If it's not that then I don't know at all ..

#

Owh..

pallid lion
trim cairn
#

Sorry :/

#

I don't know Unity very well yet.

pallid lion
#

I don't understand what I could hve done wrong.

trim cairn
#

I don't know either, did you try to re-import the image?

pallid lion
#

I made a new project. Drag and Dropped the png. Then filter mode to Point(no filter), ppu 32, compression to none, set to multiple then sliced

#

And then I set up the pixel perfect camera

#

i also turned off anti aliasing

#

Did I do something wrong?

trim cairn
#

I don't know unfortunately I don't do it like this

knotty barn
#

@pallid lion Look into "pixel perfect" in Unity

pallid lion
#

I did

knotty barn
#

Oh I see now. Yea not super familiar with the pixel perfect workflow

pallid lion
#

You can read above for more information

#

I already said that I am using a pixel perfect camera, but some pixels are still bigger than other

frigid crown
#

any reason why this is happening p_p?

crisp pond
#

Hello guys, I made this 2D game and really get stuck in a swapping problem. I want to pile up and down white road s to make a way for a ball to reach the goal. But I am not very experienced so unable to come up with a good logic for this. I have written a code for this in which I am dragging and dropping roads and change their x positions but when I drop road it is not swapped Although I am able to drag so code works but swapping not working. Please, someone, have a look at a code and see where I am going wrong or suggest some better logic for this puzzle swapping. Thank you
Here is the code
https://pastebin.com/timtftik

subtle geyser
#

Anyone know if there's a way to use rule tiles in the tilemap to generate 1x1 and 2x2 tiles together to make something like this?

fallen flicker
#

Can you just manually cut it?

fallen flicker
#

You would have to set it in a script basically with if statements saying if your player is looking direction x, then do animation z

fallen flicker
#

lol sorry not entirely. I've never worked too much with animations myself, I just know that's probably how you do it.

#

Maybe try and use this tutorial and make a couple different idle animations that come active dependent on which way your character is facing

pallid lion
#

the pixels from my sprite don't look perfect even after using pixel perfect camera

#

some are bigger than other

#

here is a picture of the sprite

subtle geyser
sly arrow
#

@still tendon are you looking for help on how to do it? i am confused what your question is

#

Vector2.MoveTowards or Vector2.Lerp is probably what I would use

dim bloom
#

How do you make it so as soon as you hit the ground the player auto jumps?

snow willow
#

Do the jump when you detect collision with the ground, or just on the first frame during which you are grounded

dim bloom
#

but how do I detect it?

snow willow
dim bloom
#

give me a second

snow willow
#

ok so...

#

just say if (IsGrounded()) { Jump(); }

#

?

dim bloom
#

thanks

still tendon
sly arrow
#

does the name of your script in engine and the class line match?

#

like, did you create a new script and then rename it?

still tendon
#

yes

sly arrow
#

Your script name in engine and the script name on this line at the top need to be exactly the same

#

if not, there are problems

dim bloom
#

how do you increase the vertical camera size but not the horizontal?

#

Is it not possible?

snow willow
dim bloom
#

The main camera up and down

#

When I try to adjust it vertically it also does it horzontal

#

I am trying to design a game that goes up instead of right.

#

nvm I figured it out

ebon ivy
#

Hello! so I was wondering if theres a way to make a few tiles in a tilemap go transparent when the player goes behind it, the only way I can think of so far is to make each tree have its own tilemap to tell if the player is colliding with it

distant pecan
#

There is some things you can do, but the easiest way would be to have trees as separate objects

green tapir
#

hey, I'm trying to only detect my floor layer with a raycast for a platformer, but it's still hitting all layers(except ignore raycast, of course).
the code is var layerMasker = 1<<10; hitLeft = Physics2D.Raycast(leftStart, -Vector3.up, GetComponent<CapsuleCollider2D>().bounds.extents.y + 0.1f, layerMasker);
does anyone have any troubleshooting suggestions?

hearty oracle
#

im making a platformer game and its just a square on a single P l a t f o r m,and he dosent respawn,so i need help with the code,i already have the camera following the player and it dosent go up and down so it dosent follow the player while falling to a cold empty v o i d (reply or dm if you can help

drowsy dove
#

hi guys

#

im looking to make a friend with someone with 2d coding experience, we are making a 2d online game where you can play minigames against other people but need people who are interested in working with me on it as a project

tiny seal
#

I am making a 2D crafting and dungeon crawler type of game and my character only moves on the x axis and this happens on an Xbox controller as well

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




public class playercontroller : MonoBehaviour
{
    private Vector2 movementInput;
    public float speed = 5; 
    


    private void Start() {


}



    private void Update() 
{

    transform.Translate(new Vector2(movementInput.x, -0) * speed * Time.deltaTime);
        
    
    

}

    public void OnMove(InputAction.CallbackContext ctx) => movementInput = ctx.ReadValue<Vector2>();

 
    



}


    
still tendon
#

hey, I need to make a hitbox in my game. The problem is that I already have added the Character Controller and cant add the Rigidbody 2D.

tiny seal
#

wait do you get an error?

still tendon
#

yes

rancid gorge
#

You can't make the hit box with a Collider2D?

still tendon
#

for movement is it better to use

#
rb.velocity = speed * distance;
#

or

#
velocity = speed * distance;
#

whats the point of using rb

#

show whole code

#

what you need help with

snow willow
#

Also when would it make sense to multiply speed by distance?

#

You are missing a return type for your method. void

#

Methods need a return type in front of their declaration

#

For OnTriggerEnter it should be void

still tendon
#

hey can anybody help me with a collision pls ? Rigidbody 2D doesnt work

stark trellis
still tendon
#

I made a game with cars and walls ... the problem is that i can drive through the walls at the moment. But i cant use Rigidbody 2D because I already use the Character Controller ๐Ÿ˜… @stark trellis

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

public class PlayerMovement : MonoBehaviour
{
    public Rigidbody2D rb;

    public float direction;
    public float speed = 10f;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), 0);
        Vector2 direction = input.normalized;
        Vector2 velocity = direction * speed;
        Vector2 moveAmount = velocity * Time.deltaTime;
        transform.Translate(moveAmount);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            
        }
    }
}
#

how would i implement jumping

stark trellis
#

My understanding is that Character Controller is only suitable for 3D. There's a 2d controller made by CodeMonkey that is decent, otherwise you'd better make one yourself.

still tendon
#

@still tendon add a collider

#

e.g box collider

#

or polygon collider if you want to be more precise

#

make sure its 2D at the end

still tendon
#

whats the most popular and most used movement for 2d?

hushed merlin
#

Can someone help.

I get this error:

UnityEngine.Object.Instantiate (UnityEngine.Object original) (at <4a33faade1cf4ef1b3e3a2c4a445e544>:0)
GridManager.generateGrid () (at Assets/GridManager.cs:19)
GridManager.Start () (at Assets/GridManager.cs:14)```

and this is the line that is the problem:
```GameObject refernceTile = (GameObject)Instantiate(Resources.Load("Grass-sprite"));```

I couldn't find a help channel so I think this is the right channel for it ๐Ÿ˜‰
fluid jewel
#

how i should make a responsive for a 2d game?

stark trellis
#

Optimization question: in my game every Interactable object checks on Update if the Player is in the trigger zone using Physics2D.OverlapCircle, let's say i have 100 Interactable objects in my scene, how expensive is that? Any way i can optimize it/should i?

snow willow
#

that is quite expensive

#

alternatively, just ahve the player do OverlapCircle on itself every frame to find all the interactable objects near the player

#

then you just have one OverLapCircle each frame

#

I'd go with trigger colliders though

stark trellis
#

initially i wanted to use trigger colliders but my Player has no rigidbody and the interactable objects should not collide with anything except the ground so i set them to kinematic... but this way the triggers don't trigger :/

snow willow
#

you can give them rigidbodies

#

kinematic rigidbodies

#

with trigger colliders

stark trellis
#

i did, doesn't trigger

snow willow
#

what does your player have

#

does it have a collider?

stark trellis
#

yep

snow willow
#

and a CharacterController?

#

er - rather the CharacterController is the collider

#

is the player's collider a trigger?

stark trellis
#

no has kinematic RB, Normal collider, custom controller

snow willow
#

oh it has a kinematic RB?

#

I thought you said it has no RB

stark trellis
#

i forgot ๐Ÿ˜›

snow willow
#

"Project Settings > Physics > Contacts Pair Mode" to "Enable All Contacts"

#

you can try that

#

alternatively just do the OverLapCircle on the player itself

stark trellis
#

ah there's a enable kinematic-kinematic pairs... interesting but it's under Physics, not Physics2D should i mess with those even if it's a 2d game?

#

(doesn't seem to have effect anyway)

snow willow
#

oh no

#

that won't work if these are 2D colliders and rigidbodies

#

two totally different systems

#

sorry I gave you advice for a 3d game >_>

stark trellis
#

lol np, anyway i set up the 2d collision matrix this way thinking it would work... it doesnt...

snow willow
#

does your player need the kinematic rb?

stark trellis
#

nah i think it was an experiment, i actually want to remove it

snow willow
#

idk sometimes this collision stuff is confusing about what workls and what doesn't

#

there's a chart at the bottom of that page^

stark trellis
#

oh my lol, they couldn't have made it more coinvoluted if they tried

snow willow
#

yep lol

stark trellis
#

but actually thanks the idea of using just one OverlapCircle on the player is very good i'll definitely go with that

drowsy dove
#

hi guys im looking to make some friends who are interested in making a 2d game as a team and learn together

#

feel free to dm me if you wanna be involved, a little experience will help but there are resources to learn from

rose radish
#

From the Please Do Not section of this discord's code of conduct

- Post job-posting or make collaboration requests```
still tendon
#

hey can sb help me with my code ? There is an error which I dont know how to solve please pm me I will share my screen than

civic knot
still tendon
#

Haha the problem is that I believe that there is more than one error @civic knot

civic knot
#

Still. Nothing we can't solve here.

still tendon
#

The file name and the class name do match so thats not the problem

civic knot
#

Errors in the console?

still tendon
#

yes error CS 1002

civic knot
#
  1. Go to #๐Ÿ’ปโ”ƒcode-beginner and check the VS config guide in the pinned messages.
  2. You need to solve all the compile errors to put that script on a gameobject.
#
  1. With your ide configured you will not make stupid typos.๐Ÿ˜…
#

But maybe it's not a typo and you actually made a "Vektor2" type ๐Ÿค”

still tendon
#

okay ๐Ÿ˜… well I am doing a 2D game

civic knot
#

If it's meant to be Vector2 then you spell it with c, not k. You got it right in several places.

still tendon
#

Haha thx german writing isnt good for coding

snow willow
#

Vektor2 looks so much cooler than Vector2 though

heavy willow
#

reminds me of that sports cereal

civic knot
#

@still tendon please avoid unsolicited dms, they're against the server rules.

#

having your ide configured to work with unity will help you see and fix the compile errors in the ide.

still tendon
#

ok sry

civic knot
#

And you really should've done it when you just started developing. Didn't you notice you don't have autocomplete? ๐Ÿ˜…

still tendon
#

I am Studying how to make games โ€ฆ I dont know how unity works at all. I try to make a game without having the idea of unity or C#

civic knot
#

Studying unity and c# is part of "studying how to make games". And a very big part of it.

#

Anyways, get your ide configured, fix the errors and you should be able to attach that script.

still tendon
#

mhm

#

@civic knot I think I configured my ide but it dindnt change anything tbh

civic knot
still tendon
#

What does ide actually mean ? And it didnt change anything so I dont see any error highlights

civic knot
#

integrated development environment. VS is an ide.

civic knot
still tendon
#

ok its time to give up haha

civic knot
#

Did you follow the guide?

still tendon
#

yes

civic knot
#

take a screenshot of your preferences - external tools and workloads in VS.

#

You should know where to find these if you really followed the guide.

still tendon
#

Did you mean that ?

hollow crown
civic knot
still tendon
#

Yes I am using VSc

civic knot
#

Then what Vertex said.

still tendon
#

I already did that

#

Ok nvm thx for your help I am giving up

still tendon
#

hello! this channel is for code but for 2D games? If yes, I'd like to share my problem with you if possible ๐Ÿ˜ฆ

still tendon
#

Oh yes sorry ^^

#

To start, I create a 2D game on Unity. AND, for my game, I have to create a spawner that will make me spawn meteorites and coins. But, here is the problem : at first I had something like this:

#

And, I would like my meteorites and coins to spawn more evenly and closer together, but even by changing the "spawnTime" (which changes the time between each spawn) and the "minDistance" (which is the minimum distance between each object) well, there is no change at all. @hollow crown
The code : https://paste.myst.rs/d20od4wr

still tendon
#

@still tendon

#

?

#

I had already tried this but it didn't work.

#

and I don't know how to make it more random without overlapping

#

@hollow crown

#

idk

#

okay

hearty oracle
#

can someone tell me the 2D double jump script,all the jump scripts i have makes me infinitely jump and i need help

#

://

#

reply/dm if you have the script

#

แต–หกแต‰แตƒหขแต‰ :โฝ

old stag
# hearty oracle can someone tell me the 2D double jump script,all the jump scripts i have makes ...

Let's make a Double Jump with the ability to make it a Triple and a nice object to reset the jump count in mid air.
โœ… Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=DEGEEZmfTT0

Simple Jump in Unity 2D
https://www.youtube.com/watch?v=ptvK4Fp5vRY

If you have any questions post them in the comments and I'll do my b...

โ–ถ Play video
hearty oracle
#

i was looking for a script but ok :/

old stag
#

in description is the project, just copy and paste the code

hearty oracle
#

oh

#

Thanks ๐Ÿ™‚

old stag
#

but its better to write it by yourself

hearty oracle
#

well if you have time

old stag
#

yea xd

timid basalt
#

Here is a tutorial that I use: https://m.youtube.com/watch?v=QGDeafTx5ug

In this easy Unity and C# tutorial I wil show you how to make a 2D platformer controller complete with double, triple, quadrupel jumps...

By the end of the video you will have a character ready to take on any platforming challenge he may be faced with !

-------------------------------------------------------------------------------------------...

โ–ถ Play video
humble nebula
#

any of you have already tried to get an enum for scenemanager?

humble nebula
#

or a popup list in inspector

red tundra
#

Hello guys,
I've got an interesting question bouncing around my head since 1 week.
Do yall know what's the visual coding limit ?
I mean, can we do the same thing with Visual coding as C# ?

snow willow
#

It's definitely more limited

red tundra
#

Can you give me more explanations please ?

snow willow
#

it's hard to explain... you have basically absolute freedom to do almost anything when you're writing code

#

in visual scripting you're limited to the various nodes and functions that are already there

#

you can combine them

#

etc..

#

but you can't just write something from scratch in the same way

red tundra
#

Ok, thanks a lot

snow willow
#

Also it's a lot easier to use libraries and frameworks in regular code than in Bolt

red tundra
#

i'm still a newbie, and I've just found it

snow willow
#

you just use them, vs in bolt you have to figure out how to get the API to map into the visual scripting system first

#

Also if you have more questions about visual scripting, check out #763499475641172029 (actuially a link to a separate discord all about the topic)

red tundra
#

Btw visual scripting is pretty easy to use for animations / value check etc

#

Didn't see it thx

still tendon
#

hey I just did a code with a collision, when I hit the Enemys with m y bullets they should disappear which doesnt work ... can sb help me pls ?

#

Thats the code

smoky vector
sick lintel
#

does anyone know how to get the line renderer to repeat segments of an image?

#

i set it to texture mode: repeat per segment

#

but it just stretches

snow willow
#

how many segments does your linerenderer have

#

i think each segment is the space between two points in the line

#

If you only have two points, then the whole line is one huge segment

sick lintel
#

oh

#

now I'm wondering if there's a way to even do what I'm trying to do

snow willow
#

I think I've done exactly what you are trying to do

#

in a n old project

sick lintel
#

make a continuous line of sprite segments and cut it off instead of stretching it?

snow willow
#

uh one sec

#

lemme dig up a video

#

look at just

#

the first like 10 seconds of the video

#

there's a line between my drone

#

and the antenna

#

of blue circles

#

the texture is just a single circle

#

but I have it repeating

#

between like 0:07 and 0:10 of the video you can see it ๐Ÿ™‚

sick lintel
#

yes that's it

#

how did you do it?

snow willow
#

lemme open the project and check my linerenderer settings

sick lintel
#

did you have only 2 points in the line?

snow willow
#

yes

#

but they're being controlled via a script

#
        private void DrawLineToDrone(Transform drone) {
            if (!drone) {
                HideLine();
                return;
            }
            if (!LineRenderer.enabled) LineRenderer.enabled = true;
    
            LineRenderer.positionCount = 2;
            LineRenderer.SetPosition(0, TipRenderer.transform.position);
            LineRenderer.SetPosition(1, drone.position);
        }```
sick lintel
#

when I change it to tile, it does this

snow willow
#

what does your texture look like

sick lintel
#

I want the whole laser to be twisty like in the beginning

snow willow
#

on your material

sick lintel
#

it looks exactly like the first segment of the line here

snow willow
#

also you have only two points on the renderer?

sick lintel
#

yes

snow willow
#

๐Ÿค”

#

that should work

sick lintel
#

it seems to be stretching it after one tile

#

like once I'm more than one tile away, instead of putting another tile it just expands it

snow willow
#

do you have Loop rutned on

#

turned on*

#

on the LineRenderer

#

or Corner Vertices/Endcap vertices?

sick lintel
#

i tried turning loop on and it created this monstrosity

snow willow
#

yeah you don't want loop - although that kinda seems like you have more than 2 points

#

how are you defining the points for the line

#

in a script?

sick lintel
#

corner and endcap vertices are 0

#
        lr.SetPosition(1, ps.transform.position);
snow willow
#

are you doing lr.positionCount = 2 as well?

sick lintel
#

yes

snow willow
#

๐Ÿค”

#

I'm at a bit of a loss then...

#

World Space?

#

it seems like you have things set up the same way I do - it should work

sick lintel
#

on

woeful hazel
#

How do I load a sprite from a texture2D by code? In the editor I split up the texture2D (image) to create individual sprites, and I wanted to access those sprites by code. I've seen that a new sprite could be made with Sprite.Create but is that necessary if it's already been broken up?

ebon marten
#

Does anybody know how to change the color of a 2d point light using a script?
I have a script on my player that used GetComponent<Light> on the light gameobject but it returns null

heavy willow
#

you need a reference to the light gameobject first to then get that component from it, otherwise unity and your code in general would not know which instance of a light to grab

ebon marten
#

I did

#

I used [SerializeField] and dragged it in then used getcomponent on that

heavy willow
#

try making a public Light myLight; field and draggin the light on it, will it let you? if not, then it's not actually a base type of Light

ebon marten
#

Yeah I tried dragging it in as a light and it said type mismatch

#

Everywhere I've seen online says to drag the GameObject in then use getcomponent

#

I think it might be cause its 2d?

heavy willow
#

ah yeah is it the URP 2D system?

ebon marten
#

Yeah

heavy willow
#

try Light2D then

ebon marten
#

It doesnt recognize that as a class

heavy willow
#

probably neeed using UnityEngine.Experimental.Rendering.Universal;

ebon marten
#

Somebody in the lighting channel helped me thanks a lot for the help though

heavy willow
#

ah okay

ebon marten
#

Yeah thats what they said I didnt realize I needed to import that

dusty nebula
#

anyone know how to make this more smooth?

#

the little code

#

the problem for me it's the bullet spawn in wrong position when i move

heavy willow
#

you aren't using physics to move these, so move them in Update, not FixedUpdate

#

FixedUpdate is not bound by the framerate but a fixed physics timestep

#

@dusty nebula

stable folio
#

@dusty nebula The code you posted has nothing to do with spawning the bullets tho

tropic inlet
#

If he's moving the bullets via that code, it sort of is

#

It doesn't "spawn" them, but it handles their movement, I presume

trail cedar
#

I put an empty gameobject with an icon parented to the character sprite. Then make a gameobject public' or serielized private' to drag and drop the empty gameobject into that variable in the inspector. Then instantiate the bullets at that variables transform global position not local position because that would be the set constant offset from the sprite its parented to

#

@dusty nebula i got some ideas

shell dragon
#

CanBindTo is true though

shell dragon
#

It looks like atlas doesn't get loaded in edit mode at all. It works in play mode fine

inland jacinth
brittle lagoon
#

alright

#

boys

#

can u help a guy out

#

i wanna create a pause menu where there is a restart button. But everytime i try and make a canvas it mixes it up already with another cnavas that I have in the gaeme

#

is it possible to have 2 canvasses in the game?

north vault
#

Hi
So i want to make my first 2d game (yeah, i know, kinda weird that i can make 3d but not 2d) and i don't know, which template i must choose

#

2d? Urp?

split portal
#

@north vault 2D. it will download all the 2D stuff automatocally and set it up for 2D. Then upgrade to URP from the package manager.

#

If you want URP

north vault
#

Ok thanks

sage imp
#

does anyone know how I would be able to add controllable vehicle to my topdown 2d game?

summer forge
#

How can i create physicsmaterial2d in runtime?

snow willow
runic dirge
#

hi, amm help me :(

#

how do i solve it?

#

i am using microsoft visual studio

snow willow
#

Check your spelling

hollow crown
runic dirge
#

Where do I configure the visual studio?

runic dirge
#

follow :(

hollow crown
#

you need the same amount of { as you do }
you're opening and closing braces wildly

snow willow
#

Why's your FixedUpdate() inside Update()?

hollow crown
#

both Update and the class needs to be closed

snow willow
#

you didn't copy the code correctly

#

mostly because you are just copying blindly rather than understanding

runic dirge
#

there I copy it back

#

did not give me error, but my character does not move

runic dirge
#

I already solved it, thank you very much anyway

crystal tundra
#

i have the players arm always facing the mouse and i want the player to change the way there facing when the mouse is on the left or right of the screen can some one link me a tutorial because i cant find one

#

sorry if that sounds confusing

final star
#

this ain't working and there are no errors transform.position += transform.forward * moveSpeed * Time.deltaTime;

#

I was hoping the code would make the game-object move in the same direction it is facing but it is just still

vagrant wigeon
#

Hi everyone, i have this code that allows me to Left Click a random position on the screen and the character will head to that point, i wanted to add a directional Dash so that the character is able to reach faster the point. I first thought about using coroutines but i get an error where he says: "Couldn't call "Dash" function

#

here's the code if anyone can help me fix it i'll appreciate a lot

using System.Collections.Generic;
using UnityEngine;

public class MouseDestination : MonoBehaviour
{
    public float speed = 2.0f;
    private Vector3 target;
    private Vector3 mousePos;
    private Vector3 objectPos;
    public GameObject gameObject;

    void Start()
    {
        target = transform.position;
    }

    void Update()
    {

        if (Input.GetMouseButtonDown(1))
        {
            target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            target.z = transform.position.z;

            mousePos = Input.mousePosition;
            mousePos.z = 1.0f;
            objectPos = Camera.main.ScreenToWorldPoint(mousePos);
            Instantiate(gameObject, objectPos, Quaternion.identity);
        }
        transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);

        if (Input.GetKey(KeyCode.W))
        {
            StartCoroutine("Dash");
        } 

IEnumerator Dash(float seconds)
    {
        speed *= 2;
        yield return new WaitForSeconds(seconds);
        speed /= 2;
    }

     
    }

    
}
        

dull badge
#

@final star I think transform.forward is the z axis. try transform.up

final star
#

did that just then, didn't work

#

transform.position += transform.up * moveSpeed * Time.deltaTime; like this? (just making sure)

dull badge
#

yeah. is the script attached to the gameobject?

final star
#

Yep other parts of the script is working like intended

#

Wait, is that attached to WASD? is there any way to move it without pressing keys?

dull badge
#

@vagrant wigeon You may need to pass a parameter value to that coroutine (float seconds)

final star
#

so does transform.up/forward have something to do with keys? I was hoping that it would move on its own, how would that be done?

dull badge
#

It doesnt relate to input

final star
#

hmm... it only works when there is tho

dull badge
#
    private void Update() {
        if (Input.GetKey(KeyCode.W)) {
            square.transform.position += transform.up * 2f * Time.deltaTime;
        }
    }
```I just tried that and it worked
#

if you want to move without input, just put the transform.position line directly in Update()

#

oh, square here is a reference to the gameobject im moving

final star
#

hmm, strange it was in the Update() but I deleted part of the update and it is workin, and with ur transform.position += transform.up * 2f * Time.deltaTime; not sure which one helped tho lol

#

what part of it do I need to change to acount for rotation?

#

the pixel art I drew is on a 90 degree angle

dull badge
#

transform.left or transform.right instead of up

final star
#

ohh yeah makes sense

#

I am slow at this coding stuff I guess lol

#

hmm... 'Transform' does not contain a definition for 'left' and no accessible extension method 'left' accepting a first argument of type 'Transform' could be found (are you missing a using directive or an assembly reference?)

#

offt

#

will I probs should rotate it in photo shop or something lol

dull badge
#

Transform being capitalized there looks like its referring to the Transform class, not the transform on your gameobject

final star
#

tysm for ur help ๐Ÿ™‚

visual spade
#

idk if i should put this here but whenever i try to make a project (2d) and then start it, it comes up with this. so please help

visual spade
#

anyone?

dull badge
#

I'd try reinstalling that version of unity if you haven't already

visual spade
#

no it didnt work

hearty oracle
#

hey can anyone help,i need a jump c# script all the ones i tried kept jumping infinitly which will break my game

#

also a script that removes the sprites off screen to save memory

still tendon
#

@hearty oracle do you have a rigid body on the character i don't know much about coding or game development because i'm new but i am taking classes so if you don't have one put one on the character

dense flame
#

And only if it is on ground you can jump

ebon galleon
#

Hey guys, so trying to have a collision detection to make the enemy's rigidBody kinematic when the player's colliding with them. This is the code I was trying but it didn't even get to the Debug.Log line, so not sure if I'm using the collision detection correctly:

void OnCollisionEnter(Collision collision)
    {
        Collider playerCollider = GetComponent<CharacterController2D>().playerCollider;
        if (collision.collider == playerCollider)
        {
            Debug.Log("Collided with Player!");
            if(GetComponent<Rigidbody2D>().isKinematic)
            {
                GetComponent<Rigidbody2D>().isKinematic = false;
            } else if (!GetComponent<Rigidbody2D>().isKinematic)
            {
                GetComponent<Rigidbody2D>().isKinematic = true;
            }
        }
    }```
vagrant wigeon
#

hi, i'm trying to find an object position in unity 2d and i have to put it in an IF, any suggestionsยง?

tropic inlet
#

transform.position @vagrant wigeon

gleaming horizon
ebon galleon
#

@gleaming horizon Oh thanks! Missed that ๐Ÿ™‚

runic dirge
#

Hello, I need help on how to put two keys for an action, for example space and w to jump, I have configured to jump with space but I want to add the w as I do?

dense flame
#

Use input.GetButton and set the settings to the keys you want

#

Or use
if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.W))

ebon galleon
#

Got another question sorry, so the collisions work and everything, and it randomly works. It'll be a Kinematic bodyType (to stop it moving the player and vice versa), then it'll go back to a Dynamic bodyType. The Debug Log keeps going off so I know it's still colliding, I'm just not sure why it's not staying Kinematic. I tried the previous code and this code and it yielded the same results.
This is my code now:

using UnityEngine;

public class RigidbodyExternalForceController : MonoBehaviour
{
    public Collider2D playerCollider;

    void Start()
    {
        playerCollider = GetComponent<CharacterController2D>().playerCollider;
    }

    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.collider == playerCollider)
        {
            Debug.Log("Collided with Player!");
            GetComponent<Rigidbody2D>().isKinematic = false;
        }
    }
    void OnCollisionExit2D(Collision2D collision)
    {
        if (collision.collider != playerCollider)
        {
            GetComponent<Rigidbody2D>().isKinematic = true;
        }
    }
}```
runic dirge
#

Thankssss

#

:D

snow willow
crystal tundra
#

i have the players arm always facing the mouse and i want the player to change the way there facing when the mouse is on the left or right of the screen can some one link me a tutorial because i cant find one
sorry if that sounds confusing

snow willow
snow willow
crystal tundra
#

i don't know how to code i just copyed the arm code off of a tutorial

ebon galleon
snow willow
ebon galleon
snow willow
#

Isn't that what the code does?

#

It sets kinematic false

#

which means the enemy becomes dynamic

#

right?

ebon galleon
#

The weird thing is setting it to false sets it to Kinematic, setting it to true sets it to Dynamic. Trips me out

snow willow
#

๐Ÿค”

#

Are you sure you're looking at the right property

#

instead of stting isKinematic, maybe set the bodyType?

ebon galleon
#

I tried GetComponent<Rigidbody2D>().bodyType = Kinematic; but the Kinematic was erroring out (same with Dynamic and Static. Not sure what to use in place of it

snow willow
#

RigidbodyType2D.Kinematic

#

RigidbodyType2D.Dynamic

#

RigidbodyType2D.Static

ebon galleon
#

Ohh ok, I'll have a suss. Thanks ๐Ÿ™‚

#

@snow willow It worked! Thanks heaps! Bit of a problem with reverting back to Dynamic upon OnCollisionExit2D. It'll just stay at Static (Static worked for me so decided to go with that):

void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.collider == playerCollider)
        {
            Debug.Log("Collided with Player!");
            GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Static;
        }
    }

    void OnCollisionExit2D(Collision2D collision)
    {
        if (collision.collider == playerCollider)
        {
            //Debug.Log("Collided with Player!");
            GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Static;
        }
        else
        {
            GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
        }
    }```
still tendon
#

Hi, I did save on my game, I created a script, I added the SaveAll function: public void SaveAll (), and then I make an empty object and put the scrip on it and add it to the button, but when I put it in on click, it's not SaveAll function, does anyone know how to solve this?

snow willow
#

Maybe share some screenshots of your code and what you tried to hook things up in the editor?

still tendon
#

ok

#

wat my all script broken

still tendon
#

its now ok

#

I created a MainVariables script that was supposed to save the state "save game" but broke all the scripts.

#

what happeing?

#

when I reloaded unity it broke my scripts but when I took it off the scripts were no longer broken

crystal tundra
#

I have been having trouble getting the player to look at the mouse i got the players arm to do a full 360 i only need the player to look left if the mouse is on the left side of the player sprite and to look right if its on the right side of the player sprite

hollow crown
pine pilot
#

how can i add a script to a individual tile rather than entire tilemap

pine pilot
#

do i just make another tilemap for just a type of tile and add script directly to that?

still tendon
#

if i remember correctly you got to go your preference and set your external editor to match what you're using @still tendon

terse thorn
#

this is my problem, i need the character to jump, by a force aplicated to the orange redtangle (player), but i was checking and it does'nt work.

i think the problem is in how the canJump bool is formulated but idk, i tried my best but nothing, if you want, i can post a screenshots of the code used

using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour
{
  public float velocity = 5; //determines the player velocity
  public float jumpForce; //determines the force aplicated when "Z" is pressed

  bool canJump; //the declaration of the bool canJump


    void Update()
    {
        if(Input.GetKey("left"))
        {

          gameObject.transform.Translate(-velocity * Time.deltaTime, 0, 0); //if the left key is pressed the player will move left
        }

        if(Input.GetKey("right"))
        {

          gameObject.transform.Translate(velocity * Time.deltaTime, 0, 0); //if the right key is pressed the player will move right
        }

        if(Input.GetKeyDown("up") && canJump == true) //if you press UP and canJump is true the jump function is called and canJump is returned to false
        {
          canJump = false;

          Jump();
        }
    }

    void Jump(){

      gameObject.transform.Translate(0, jumpForce * Time.deltaTime, 0); // the only purpose of this function is
    }                                                                    //to make the character jump


    public void Collision2D(Collider2D collision)
    {
      if (collision.transform.tag == "jumpable") {    // if you are over a collider tagged "jumpable" canJump will be true

      canJump = true;
    }

    }
}```
vocal condor
runic dirge
#

Hi, I have a bug, when I start the game everything is excellent, but when I jump and fall to the ground the character keeps the animation falling, what do I do?

vocal condor
runic dirge
#

Ahh sry

vocal condor
runic dirge
#

I put the photos in that section?

vocal condor
#

Microscopic, I cannot see and copying/pasting code support is extremely tedious with images; nevermind having to constantly alternate between images.

runic dirge
#

I understand, sorry

#

I pass the code here?

vocal condor
#

Look at the link, they provide the possibilities.

terse thorn
# vocal condor Define "it does'nt work". Your code should only displace the character by a minu...

hey, i updated a bit the code and now it looks like this:
the problem is that when i press "up" it does not anything

using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour
{
  public float velocity = 5; //determines the player velocity
  public float jumpForce; //determines the force aplicated when "Z" is pressed

  bool canJump = true;
  bool jumpPermission = false;
  
  public Rigidbody2D rb;


    void Update()
    {
        if(Input.GetKey("left"))
        {

          gameObject.transform.Translate(-velocity * Time.deltaTime, 0, 0);
        }

        if(Input.GetKey("right"))
        {

          gameObject.transform.Translate(velocity * Time.deltaTime, 0, 0); 

        if(Input.GetKeyDown("up") && canJump == true)
        {
          jumpPermission = true;
        }
    }

    void FixedUpdate()
    {
      if(jumpPermission == true);{

        Jump();

        canJump = false;
      }
    }

    void Jump(){

      rb.AddForce(transform.up * jumpForce); 
    }                                           


    public void Collision2D(Collider2D collision)
    {
      if (collision.transform.tag == "jumpable") {   

      canJump = true;
    }

    }
}```
vocal condor
#

Either insert code here with back ticks or one of the available web services.

vocal condor
terse thorn
#

let me see

vocal condor
#

Also, are you getting any errors; assuming you're referencing the rb in the inspector.

terse thorn
#

ok

runic dirge
#

I already copy and paste in the section that you gave me

terse thorn
#

i added a Debug.Log("works") and when i open the game, all is ok, then i press up and the console sends a "works" Debug Log almost every frame and my character just go to the space (just floats up slowly)

vocal condor
runic dirge
vocal condor
#

Ah, nevermind - in update.

#

Actually, no. It isn't ever reset.

terse thorn
orchid pasture
#

?

vocal condor
#

Basically, what you have is a always true condition: ```cs
void FixedUpdate()
{
if(jumpPermission == true);//Always true, but why is there a semicolon here?!
{

        Jump();

        canJump = false;
    }
}
terse thorn
#

i deleted it

#

(the semicolon)

#

early

#

when i said fixed bad-spell

vocal condor
vocal condor
#

Else you'll go flying into orbit as time -> infinity

orchid pasture
#

@runic dirge try to make a grounded bool and and if this bool is true turn the animator "Jump" bool to false cz it stay true after you jumped

terse thorn
vocal condor
terse thorn
#

yes

#

will try that

orchid pasture
#

@runic dirge

#

wait

#

imdumb

vocal condor
runic dirge
#

xd

orchid pasture
#

@runic dirge try this

terse thorn
#

man, idk why it does'nt work.

{
  public float velocity = 5; //determines the player velocity
  public float jumpForce; //determines the force aplicated when "Z" is pressed

  bool canJump = true;
  bool jumpPermission = false;

  public Rigidbody2D rb;


    void Update()
    {
        if(Input.GetKey("left"))
        {

          gameObject.transform.Translate(-velocity * Time.deltaTime, 0, 0);
        }

        if(Input.GetKey("right"))
        {

          gameObject.transform.Translate(velocity * Time.deltaTime, 0, 0);
        }


        if(Input.GetKeyDown("up") && canJump == true)
        {
          jumpPermission = true;
        }
    }

    void FixedUpdate()
    {
      if(jumpPermission == true){

        Jump();

        canJump = false;
      }

      if (canJump == false){

        jumpPermission = false;
      }
    }

    void Jump(){

      rb.AddForce(transform.up * jumpForce);
    }


    public void Collision2D(Collider2D collision)
    {
      if (collision.transform.tag == "jumpable") {

      canJump = true;
    }

    }
}```
hollow crown
terse thorn
#

i added a Debug.Log("work") in Jump() and it does just work one time and not more

vocal condor
#

Maybe your jump force is zero?

terse thorn
terse thorn
#

the jump is fine but only happens one time

vocal condor
#

That's how RB is used.

#

You do not need to interpolate it per frame like direct translation with transform.

hollow crown
terse thorn
#

so, how i made it that you can jump the amount of times you want, not only once in the entire game

vocal condor
#

Does it jump?

#

Once at all?

terse thorn
#

yes, jumps properly but only once

vocal condor
#

The next concern would be your isGrounded state aka canJump

#

Which you're supposedly resetting in Collision2D.

#

Which would only be applicable if your object was colliding with another whose tag is jumpable

#

I'm assuming the floor is tagged with the jumpable string.

terse thorn
#

yes, it is

#

(tagged as jumpable)

vocal condor
#

I'm saying that you'll only be able to jump once if canJump never gets set to true again.

terse thorn
#

it is set to true on collision

#

with the ground

vocal condor
#

But you said you could only ever jump once?

#

And the two conditions to limiting your jumping is either pressing up or canJump. canJump is likely the culprit.

terse thorn
vocal condor
#

Unless you're simply asking "how do you implement a double/nth jump".

vocal condor
#

Is it ever occurring?

#

If not, you will never be able to jump again.

terse thorn
#

let me use a debug.log

vocal condor
#

And it will not occur if there isn't a collision . Second thought Collision2D isn't a callback function.

terse thorn
#

:O

vocal condor
#

(First should work but if for some reason.. first should work)

terse thorn
#

the debug.log is not printing

   {
     if (collision.transform.tag == "jumpable") {

     canJump = true;

     Debug.Log("collision");
   }

   }
}```
vocal condor
#

What if you put the log outside of the if statement?

terse thorn
#

when i set it to OnCollisionEnter2D unity launch an error that says it needs to be "Collision2D"

vocal condor
#

And make it print out the tag of the collider instead

terse thorn
vocal condor
#

And it should be private.

terse thorn
vocal condor
#

It says you're declaring it incorrectly.

#

The link above illustrates that it wants: MonoBehaviour.OnCollisionEnter2D(Collision2D)

#

Look at their example in the link above.

#

Quick copy/paste without reading a bit can produce quick results but also easily send hurdles of error your way.

terse thorn
#

it works perfectly

#

thank you so much

vocal condor
#

The Collision2D has the collider property if you ever need it||; not likely in your case but if you ever get weird parent-child collider complaints, this is likely the issue. Only the object with the RB is recognized unless you explicitly select the collider's game object - they differ||.

#

Gratz UnityChanCheer

terse thorn
#

you were so patient, even you expained me how collision works!

#

thanks and have a great "rest of the day"

hallow onyx
#

guys i have a ques

#

i animated a ball

#

when it is moving

#

and i want to rotate that animation

#

depends on the postion iam going to

#

so anyone has an idea?

remote moth
#

I don't understand PerlionNoise

vagrant wigeon
#

Hi everyone i need someone for like 5 minutes because i'd like to ask for advices to simplify a code. If anyone's available pls dm me :)

tame lark
#

I need an idea (hint). I have a button, and I think i want to use the UI, which is for start and stop music, and of course it has 2 states, started and stopped. I have 2 images for those 2 states. Which type of UI component do you think I should use?

still tendon
#

when u add a component like physical 2dd then u add a polygon 2d thing do u have to save?

#

pls help

#

its my first projet an im already stuck

dense flame
#

Save the project? Yes

still tendon
#
int childamount = level1buildingparent.transform.childCount;
        GameObject building = level1buildingparent.transform.GetChild(Random.Range(0, childamount)).gameObject;
        GameObject bullet = Instantiate(buildingbullet) as GameObject;
        bullet.transform.position = new Vector2(building.transform.position.x, building.transform.position.y);
        bullet.transform.parent = bulletspawnarea.transform;
        bullet.transform.localScale = new Vector2(0.2577487f, 0.1823389f);
``` does anyone know how to modify this code to shot the created bullet up
worldly patrol
#

how do you handle sub states?

drowsy dove
#

hi has anyone here worked with multiplayer

silver heron
#

@drowsy dove if you want to implement multiplayer have a look at mirror its probably the easiest and most secure networking available atm

#

UNET is severley depreciated

silver heron
trim cairn
#

Hey! I would like to know how I can call this function in another script please? Enemy.instance.TakeDamage (); made a mistake.. I know it's because of (int damage) but I can't figure out how to fix this ..

undone coral
#

@trim cairn You're supposed to input a int value to the function, so Enemy.instance.TakeDamage (10); should work, for example.
The "Enemy.instance" is a little worrying though. :p

still tendon
#

How do I make it go up tho

dense flame
#

You can
Instantiate(buildingBullet, building.transform.position, Quaternion.lookAt(Vector3.up), bulletSpawnArea.transform);
maybe

#

Change values on the Quaternion.lookAt to make it work

trim cairn
#

I would like my enemy to display the damage it takes in a float text, everything works fine, but the float text is not the enemy and it activates every time I use my Mouse. help me please?

My float text script : https://hatebin.com/rpksktoetf

dense flame
#

When do you want it to happen?

trim cairn
dense flame
#

And how do you know you hit it? On the code you pasted it was always the mouse is clicked

#

Maybe the enemy can show the text every time it is being hit

trim cairn
#

Yes it would be perfect if it worked like that

dense flame
#

Put it on TakeDamage()

#

Or is there a reason you canโ€™t ?

cyan pike
#

hi

#

i need help with a script

woeful edge
#

What is it?

cyan pike
#

i added fruits to my game

#

but when i eat the fruits my character doesnt jump and i have to go to another platform to be able to jump again

#

this happens sometimes

trim cairn
#

@dense flame It works ! But now I have the problem where my text is not at all at the level of my enemy.

dense flame
#

wdym level of your enemy?

undone coral
#

@cyan pike we have no idea what you mean by fruits or what the intent is. Please post the actual code and what's supposed to happen in that code. :p

cyan pike
#

ok

#

how do i post the text like a code?

trim cairn
#

wdym ?

#

Like this @cyan pike ?

eee
cyan pike
#

wait

#

how did you do that

trim cairn
dense flame
#

Instantiate (myObject, transform.position, Quaternion.identity);

cyan pike
#

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            GetComponent<SpriteRenderer>().enabled = false;
            gameObject.transform.GetChild(0).gameObject.SetActive(true);
            Destroy(gameObject,0.5f);

        }



    }

}   
#

like this?

trim cairn
#

I put this in TakeDamage ? @dense flame

dense flame
#

You are doing this
Instantiate(damageTextPrefab, enemyInstance.transform)
Change it to this
Instantiate(damageTextPrefab, transform.position, Quaternion.identity, transform)

trim cairn
dense flame
#

Change sorting layer or something

trim cairn
dense flame
#

No problem

cobalt jacinth
#

does anyone know how to make a grappling hook?

marble badger
#

anyone here familiar with sebastian lague's 2d player controller video

quaint copper
#

For issues where you can't tell the difference, I use a site called diffchecker. Especially helpful for following tutorials and comparing blocks of code for the same methods between me and my friends when one works and the other doesn't. Saves time and effort instead of making a git commit or some other difference version control

marble badger
#

i will check it out

trim lion
#

Hey all Iโ€™m wondering if you guys can help me with some maths code I have to do for college

#

I need to output the layout number and permutations for that lauding to the screen in scientific notation

snow willow
#

What does that have to do with Unity exactly?

trim lion
#

And itโ€™s code

tiny seal
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class fire : MonoBehaviour
{


    public Transform FirePoint;
    public GameObject ArrowPrefab;

    public float ArrowForce = 20f;

    // Update is called once per frame
    void Update()
    {
      if(Input.GetButtonDown("Fire1"))
    {
      Shoot();
    }  
    }


    void Shoot()
    {
     GameObject arrow = Instantiate(ArrowPrefab, FirePoint.position, FirePoint.rotation);
     Rigidbody2D rb = arrow.GetComponent<Rigidbody2D>();    
     rb.AddForce(FirePoint.up * ArrowForce, ForceMode2D.Impulse);

    }



}
``` Um i need help my arrow spins around the player and then after 5 seconds it shoots of into a random direction and i need it to where it fires straight (i have been working on this for 5 hours already)
snow willow
#

what does straight mean

narrow meteor
manic zinc
#

Programmers I need help, big help! So listen, atm im creating a 2D mmorpg, on unity. I currently use photon for rooms to join ext, im looking for a reliable option to create one big server that everyone autojoins (mmo will be multiplayer). But, photon only does rooms. ;-;

Does someone have a viable option to make one big server that people autojoin? I use html, css, javascript, c++, c#, java, and python.

Pm please, if someone has an option in will change the course of the mmo

young pebble
trim lion
#

Or find a website that will help me make code for what I need it to do .

hollow crown
#

is this Unity-related?

trim lion
hollow crown
#

Does Console.WriteLine even output anything in Unity at all

ruby karma
#

it looks more like homework

hollow crown
#

looks entirely unrelated to Unity to me

#

and certainly looks completely unrelated to 2D coding concepts in Unity

trim lion
#

Iโ€™ve tried googling the answers but keep running into nothing

hollow crown
#

lol no it isn't, can you screenshot your Unity project?

trim lion
#

So thought I would ask in a dedicated unity group where people would know how I can get the answers

#

I can try and send a copy of the unity girl

#

File

#

Iโ€™m not on my pc any more so couldnโ€™t take photos

#

I only have the screenshots I took earlier of inside visual studio

#

Have I done something wrong by asking for help ? The reason Iโ€™m asking is cause Iโ€™ve been stuck on this for hours and have been trying to get answers for hours with no luck . Itโ€™s a bit maddening

hollow crown
#

This is a console application almost 100%,
You are not asking for help, you are asking for someone to just do your entire homework for you

#

if you want that sort of help, hire a tutor

#

and don't ask here, in a channel that's entirely unrelated to whatever it is you're trying to accomplish

trim lion
#

No Iโ€™m asking for help of like websites and such where I may be able to get the code

#

Or how I would go around getting the code

#

And itโ€™s done through visual stupid

#

Studio

#

Instead of it being for a video game tho itโ€™s for maths itโ€™s to run mathematical equations in unity

#

What channel is appropriate to get help with this code ?

hollow crown
trim lion
#

Is there something off about the code that means I wonโ€™t be able to get help with it ?

arctic stag
#

it looks as if you just want help with homework. that is what your teachers are for

ruby karma
#

lack of details, lack of relation to unity, lack of context etc etc

ruby karma
trim lion
#

Help

#

Because I donโ€™t even know what to google to start looking for what code I need

arctic stag
#

sounds like you need a better time management then

hollow crown
#

there is no code, the descriptions of what you're trying to achieve either can be easily googled, or are incomprehensible. Additionally each of the problems seem entirely unrelated and without context

#

also nothing here is to do with 2D coding in Unity as far as I can see?

#

there's no tilemaps, sprites, etc

#

just permutations, factorials, and an abstract idea of a level

trim lion
ruby karma
#

I was stumped at : Generate a level.
Bro what you mean generate a level

trim lion
#

Through a maths script

hollow crown
#

I have no idea what that even means

ruby karma
trim lion
#

Thank you

ruby karma
#

that is if this is actually the factorial that you want

hollow crown
hollow crown
trim lion
hollow crown
#

No. Please move

pallid kayak
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 5f;
    public Rigidbody2D rb;
    public Camera cam;

    Vector2 mousePos;
    Vector2 lookDir;
    private Vector2 position;

    void Start()
    {
        position = gameObject.transform.position;
    }

    // Update is called once per frame
    void Update()
    {
        mousePos = cam.ScreenToWorldPoint(Input.mousePosition);

    }

    void FixedUpdate() 
    {
        if (Input.GetMouseButton(0))
        {
            lookDir = mousePos - rb.position;
            float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
            rb.rotation = angle;

            transform.position = Vector2.MoveTowards(transform.position, mousePos, moveSpeed * Time.deltaTime);
        }
    }
}
#

why is my spaceship falling when i have my mousebutton pressed? i only want gravity to pull it down when i'm not flying up

dense flame
#

You should move with rb.velocity

#

Or AddForce

#

If you move with Rigidbody.velocity the gravity wonโ€™t affect it

still tendon
#

Yeah he didn't show what gravity is applied to his entire project. Might be a good idea to set it to 0 if he's not expecting to use it at all.

remote moth
dense flame
#

A trigger collider?

remote moth
vocal condor
#

circle cast

delicate loom
#

I've given my tilemap a collider, but now it spins around an arbitrary point instead of the center

#

How do I change its center?

#

Using a tilemap and composite collider with rigidbody2d

delicate loom
#

When I add torque instead of setting rotation it just spins in a huge circle

#

What on earth

still tendon
#

I need help if is possible ๐Ÿ™‚

dull badge
#

Just ask your question

still tendon
#

I created a 2D game and implemented a meteorite and coin spawner. My objects move from right to left. So far, I get a spawner like this :

#

The problem, as you can see on the red line, is that my meteorites are too similar, I would like to have a more random spawner like this :

#

And I don't know what to change in my code to make something random without it being too much of a mess, you understand? ๐Ÿ˜ฆ

delicate loom
#

Youll need to use another means of generation

#

Gaussian distribution or some noise as an input

still tendon
#

i.e ?

#

I have my script if you want to take a look at it.

delicate loom
#

You have a few options

#

The simples is checking out where the last meteor spawned, and not allowing your game to spawn one on that height again

#

Sure, paste a snippet and ill have a look

still tendon
#

I can also send you my spawner's inspector.

delicate loom
#

Nah its fine

#

So I see what you are doing

#

Any reason to handle it like this?

#

I would change it for the following if you want the right behaviours (pseudocode incoming)

#

``

still tendon
#

do I put my code in a code block?

delicate loom
#

Nah pastemyst is better for large chunks

still tendon
#

okay okay

#

and I don't know what to change in my code

delicate loom
#

Did you get this code somewhere or write it yourself?

still tendon
#

Overall, I wrote it, but I had the help of several people.

delicate loom
#

Right

#

The easiest way is, right before you spawn an asteroid

#

do a check with rectangle overlaps, and see if there arent already 3 asteroids nearby on that height

#

If there are already, simple try another spawn location

#

Also keep in mind that the results you are getting right now ARE random

#

If you want evenly distributed asteroids with equals space before them, simply try a random position, see if it is far away enough from the nearest asteroid, if not try another random positions etc until success, then spawn

still tendon
#

oh I see... but I wouldn't know how to rewrite all that in my code ๐Ÿ˜ฎ I only wanted to try to modify it or add a few lines :/ @delicate loom

alpine frigate
#

Hey guys I am making a 2D top down game where I control a ball and I have to avoid getting hit by obstacles that are thrown from random directions. My goal here is to instantiate "Obstacle" prefabs at a point and then launch them towards the player. But to actually get the spawn point of my obstacles, I want to get a random angle around my player and then extrapolate the lenght of this direction and then spawn the obstacle to then give it a force towards the player. I'm not completely new to Unity but I am still not really good when talking about vectors... Could anyone explain me how this would be possible?

#

I am spawning my obstacles in a "ObstacleSpawnerScript"

limber thistle
#

So you want to spawn obstacle anywhere in a circle around the player?

#

You can do this to get a random position:
Vector2 randomDirection = new Vector2(Mathf.Cos(randomAngle), Mathf.Sin(randomAngle)); Vector2 obstaclePosition = playerPosition + randomDirection * distance;

alpine frigate
#

๐Ÿ‘๏ธ ๐Ÿ‘๏ธ

#

I'l go try that real quick

limber thistle
#

and then for the movement
Vector2 obstacleToPlayerDirection = -randomDirection;

alpine frigate
#

thanks mate I'l check that out and let you know if it works as I intended. I will also give a look at Mathf.cos() in the API

neon current
#

Hey there ๐Ÿ™‚ I'd like to have have a rectangular shape in a 2D game which I rescale during the game. It shall show a symbol on it, though, which should remain it's original size and shape.
Is there a better way than my workaround to have an empty game object which inherits the rectangle and the symbol object?
Is there a more elegant way? Can I achieve this without the emtpy parent? ๐Ÿ™‚

limber thistle
#

@neon current It's certainly the most elegant in the sense that it's the simplest!

#

Meaning you can get fancy with shaders, etc...
But here you have two object with different behaviours so it makes sense to separate them

#

If you really want to avoid having an empty parent, you can keep just the two object and move them independently ot the same position

neon current
#

Codewise it would be easier to somehow have the symbol as a child of the rectangle somehow.
Yet, the code works, but restructuring it, makes it pretty difficult as I need to change the symbol, when the colour of the rectangle changes. Makes it a bit more complicated at the moment. Kinda struggling right now.

limber thistle
#

It shouldn't be more difficult one way or another, send code over if you need a quick help

neon current
#

oh no, it disappeared.

#

It may be helpful to know, why I can't access the child of my empty object.

The hierarchy structure is:
wall_segment

  • wall
  • symbol
#

I instantiate the wall segment. And then I want to save its first child (wall) in an GameObject Array but it throws an error. Would show the code, but it did disappear in this chat.

limber thistle
#

You can try with pastebin

barren lark
#

Does anyone know how to make a rigid two-player-only system with the New Input Manager? I don't want to use Player Input Manager, I just want to have the first controller control the already-existing 1st player (left side of the screen) while the next active controller controls the already-existing second player (right side of the screen.)

neon current
#

Assets\Scripts\GameController.cs(172,25): error CS0029: Cannot implicitly convert type 'UnityEngine.Transform' to 'UnityEngine.GameObject'

limber thistle
#

Ah! It's because transform.GetChild() returns the transform of the child object. So you want to do
wallInstances[i] = transform.GetChild(0).gameObject;

neon current
#

aaaah, so easy ๐Ÿ˜„ haha, thank you so much! I will try further with my workaround then ๐Ÿ™‚

barren lark
#

Yeah! I should have said something, you can be scaling the box but keep the position on both the box and symbol that way.

#

Anyway, I hope someone can figure out my quandary. I'm using the New Input System.

limber thistle
#

Sorry @barren lark I have no idea ๐Ÿ˜„

barren lark
#

Fuccckk hahaha

neon current
#

@barren lark sorry, I can't help you either. But would be interested in how that would work for my question. ^^'

barren lark
#

Well, my issue is this. Using the new Input system, most everyone seems to be inclined to having local multiplayer defined like this:

#

https://puu.sh/Hgcnf/9cefd8776d.png When a new controller is recognized, a new player "Prefab" is created and connected to that input. So, in a game like Gang beasts, a first or second Humanoid is spawned. But this system is so rigid that it's a little silly.

#

All I want is to have already-existing Player objects that get "possessed" when a new controller is detected.

#

Also, if anyone knows how to separate keyboard and joystick input across multiple players, make my work a little easier, haha. I'd appreciate that too.

neon current
#

@barren lark unfortunately I have no clue. :/ But could you explain to me, how I could add an image to my scaled object without it being distorted?

low gull
#

How do I figure out if something is above/below/left/right of a position?

#

I don't need the exact angle

#

Just something like Vector2.Up

neon current
#

@limber thistle I now made a bit of "dirty" workaround. The thing with the empty parent did not work well in terms of positioning, etc. I know have the symbol image as child object of the wall and before rescaling it, I unparent the wall and reparent it after rescaling again.

snow willow
#

extrapolate that with y or x for all 4 directions

barren lark
#

Yeah if youre still interested gimme like 30 mins

limber thistle
#

@neon current If it works, great ๐Ÿ™‚

#

(but it should works with the empty parent also :p)

neon current
#

@limber thistle it surely would. I just have a specific calculation rescaling and repositioning the rectangle. I would have to recalculate this to the parent, etc., which makes it a lot more complex. ^^

barren lark
#

Yeah, so.

#

Child objects' position are always relative to the parent object IIRC.

#

So, if I'm envisioning this problem right... You have a wall object you want to scale, with an emblem that keeps the same relative position.

heavy willow
#

can add a rotate constraint as well. Or use the parent constraint and disable scaling

remote moth
#

How can i create a Gui?

uncut glen
#

Hey there, anyone knows how to make a platform in 2D that you can stand on it and go through it from down?

#

@remote moth Right click on hierarchy => UI => Button(For Example)

remote moth
#

Why show the texture other in unity?

tropic charm
#

I'm not sure I understand your question but I'm guessing you want to change your sprite's Filter Mode setting to "Point."

remote moth
#

and i still have the problem

tropic charm
#

There must be some other setting causing that then. You might post a screenshot of the sprite's Inspector settings.

remote moth
undone coral
#

@remote moth The Unity version look as though they are .jpg files, where as the first are .png.

undone coral
#

The images you made in Paint, save them again but as a png file instead? :p
Don't just change the file-extension from the ones you already have in Unity by the way, that won't change anything.

remote moth
#

i never use jpg

#

i always use png, and i have this problem in unity by all textures files

undone coral
#

Dunno either then; settings seem fine.

crystal geode
#

maybe a dumb question, but how do I refer to a different gameobject within a script? I have two characters, and I need them to be able to interact (like check each others' position), but I'm not sure how to refer to the other one within the first one's script

#

would I do like

#

public gameobject otherplayer;

#

and then just set it in the editor?

undone coral
#

That's one possibility, yeah. For just having a reference between objects in your scene it's the most straightforward solution.

crystal geode
#

awesome

#

and if I do that, then I should be able to refer to the other player's colliders as well, which was the thing I was worried would be a headache

undone coral
#

Something like a otherPlayer = GameObject.Find("Other Player"); would work as well (not adviced). Have some form of manager keep tracks of objects, and reference them through that.
It depends on the situation, really.

#

And you can reference the collider through the gameObject with something like otherPlayer.GetComponent<Collider2D>();.

crystal geode
#

that makes sense, thank you!

#

do you think it would be best to keep it as a public var that I set manually, or should I just do like...

#

private GameObject otherPlayer = Player2;

#

because it's not like the 'other player' is ever going to change for each player

knotty barn
#

Inspector hooking is usually nice when possible, but things that are spawned at runtime generally can't be referenced like that

crystal geode
#

ahh, okay, that makes sense

undone coral
#

Exactly; if you can guarantee that both objects are in your scene at startup, and stay that way it's likely the best way. If you need it to change dynamically at any point you'll need something more.

tropic charm
#

@remote moth You shouldn't delete your posts once someone has replied to them. That is very poor etiquette.

still tendon
#

I'll never make it ๐Ÿ˜ฆ

fleet skiff
#

Do you guys know any good basic 2d movement tutorial?

elder oriole
#

Brackeys

still tendon
#

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
still tendon
limber lichen
#

Hi new here, I have a unity 2d question. Iโ€™m making a npc ai. The npc moves about and when the player comes in range the npc stops. But it stops on the direction itโ€™s travelling in. So if the npc was going to the right and the player approached him from the top, the npc stops and goes to idle. How can I make the npc face the player. I tried using lookat but that doesnโ€™t work. Any help we be great. Thanks

wraith linden
#

Can someone help me figure out how to get a 2d camera bounding box?

snow willow
#

first - what's a 2d camera?

wraith linden
#

well regular camera

#

and I want it so that the camera will not show areas outside of where I have content

#

so a box that the camera view will not go past

snow willow
#

you mean like... a fog of war?

wraith linden
#

kinda i guess

#

like this

#

but i can't get this to work

#

and it's for a platformer

snow willow
#

Yeah this seems like a link to exactly a tutorial for what you need

wraith linden
#

(my games a platformer)

snow willow
#

which part isn't working?

wraith linden
#

In the CameraBounds.cs script you will see 2 field Bounds X and Bounds Y you can change the value and you will see the rectangle in the scene view changing. Set it to your need and itโ€™s done.```
#

no rectangle appears

snow willow
#

Do you have Gizmos enabled in scene view?

wraith linden
#

umm

#

idk

snow willow
#

It's a toggle

#

at the top of the scene view window

wraith linden
#

this?

snow willow
#

yes but you don't need to go into the dropdown

#

just click it to turn it off and on

wraith linden
#

okay

#

do i want it on or off? and how do i know when it is on or off?

snow willow
#

on

#

see how certain things are not drawn with it off?

wraith linden
#

okay i'm pretty sure it's on cause i can see the stuff for the camera

snow willow
#

uh ok can you share the inspector for the camera bounds object?

wraith linden
#

like the code for it?

snow willow
#

no

#

the inspector

#

it's a window in the editor

wraith linden
#

oh

snow willow
#

where you can see all the public variables on your scripts etc

wraith linden
#

this?

snow willow
#

that's the script itself

#

did you attach the script to any GameObject in the scene?

wraith linden
#

this?

#

oh wait

snow willow
#

yeah

wraith linden
snow willow
#

do you see the rectangle when you click on that object?

#

the one with the bounds on it

wraith linden
#

no i don't

#

this looks important

#

oof

#

heres a better view

snow willow
#

ah yeah you have some issuies that you might need to solve before this works..

#

uhhh

#

you also have 999+ red errors ๐Ÿ˜ฎ

#

you'll need to fix all that before anything works

wraith linden
#
CamFollow.Update () (at Assets/CamFollow.cs:12)
nova vector
#

when starting out, like a brand new scene, I add a Sprite GO, assign an image to the sprite, and click Play, I get a blue screen, why?

wraith linden
#

this

nova vector
#

in the scene preview I see my image in the center

snow willow
#

look at the game view

#

and reposition your camera/sprite as necessary to get it into view

snow willow
#

one of your scripts is not named properly for example

#

make sure all your scripts have the same name as the class inside

wraith linden
#
using UnityEngine;

public class CameraBounds2D : MonoBehaviour
{
    public Vector2 scaleBound = new Vector2(1, 1);
    public Vector2 offset;

    [HideInInspector] public Vector2 maxXlimit;
    [HideInInspector] public Vector2 maxYlimit;

    Camera _camera;

    public void Initialize(Camera temp_camera)
    {
        _camera = temp_camera;
        CalculateBounds();
    }

    public void CalculateBounds()
    {
        float cameraHalfWidth = _camera.aspect * _camera.orthographicSize;
        maxXlimit = new Vector2((transform.position.x + offset.x - (scaleBound.x / 2)) + cameraHalfWidth, (transform.position.x + offset.x + (scaleBound.x / 2)) - cameraHalfWidth);
        maxYlimit = new Vector2((transform.position.y + offset.y - (scaleBound.y / 2)) + _camera.orthographicSize, (transform.position.y + offset.y + (scaleBound.y / 2)) - _camera.orthographicSize);
    }
}```
#

wrong one wait

#

i think this is what the error was pointing to

#
void Awake()
    {
        bounds.Initialize(GetComponent<Camera>());
        maxXPositions = bounds.maxXlimit;
        maxYPositions = bounds.maxYlimit;
    }```
nova vector
#

@snow willow no matter which way I move it, the sprite doesnt show up in the camera preview

#

this is a 2D project if that matters

nova vector
#

the default, -10 for both

snow willow
#

well there;'s your problem

#

move your sprite to 0

#

the camera is put back at -10 so that it can actually see the objects that are at 0

nova vector
#

OK, so even in 2D I have to take Z axis into account?

snow willow
#

yes

#

there is no such thing as a 2D Unity game

#

it's an illusion

#

๐Ÿ˜„

nova vector
#

and all newly-added objects are added at -10, basically invisible by default?

wraith linden
#

it tells me that ```Assets\CameraBounds2D.cs(23,90): error CS0103: The name '_camera' does not exist in the current context

snow willow
#

well newly added objects are just added wherever the current object you have selected is... or something like that

wraith linden
#

but that's what the script i downloaded came as??

nova vector
#

nope, even after setting PlayerSprite to Z=0, and creating a new object, it starts at -10. Anyway no big deal, now I know, thanks

snow willow
snow willow
nova vector
#

lol

snow willow
#

I wish it would just create them at 0,0,0 all the time - I think there might actually be an option for that

snow willow
# wraith linden wdym?

I mean that on line 23 I don't even see a reference to the _camera variable in the code you shared

wraith linden
#
public class CameraBounds2D : MonoBehaviour
{
    public Vector2 scaleBound = new Vector2(1, 1);
    public Vector2 offset;

    [HideInInspector] public Vector2 maxXlimit;
    [HideInInspector] public Vector2 maxYlimit;

    Camera _camera;

    public void Initialize(Camera temp_camera)
    {
        _camera = temp_camera;
        CalculateBounds();
    }

    public void CalculateBounds()
    {
        float cameraHalfWidth = _camera.aspect * _camera.orthographicSize;
        maxXlimit = new Vector2((transform.position.x + offset.x - (scaleBound.x / 2)) + cameraHalfWidth, (transform.position.x + offset.x + (scaleBound.x / 2)) - cameraHalfWidth);
        maxYlimit = new Vector2((transform.position.y + offset.y - (scaleBound.y / 2)) + _camera.orthographicSize, (transform.position.y + offset.y + (scaleBound.y / 2)) - _camera.orthographicSize);
    }
}```
#

this code, it's the last statement

#

well since this doesn't work do you have a better idea?

snow willow
#

I don't relaly see why that code shouldn't work

#

did you copy the Editor folder out of the zip file from that page as well?

#

Or just the CameraBounds2D.cs?

wraith linden
#

...just the CameraBounds2D

#

i don't really know what I'm doing too much

#

should i just copy the whole folder over?

snow willow
#

If you didn't copy the editor folder too, that's why you 're not seeing the box in your scene view

wraith linden
#

oh okay

snow willow
#

there's an editor script in there that is the thing that draws that box