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

1 messages ยท Page 21 of 1

wanton sparrow
wanton sparrow
#

it returns true. but im still having collisions

crisp rune
#

so I'm trying to check collisions with raycasting, but I can't get the ray to work the way I want it to

#

how would I make the ray extend under the sprite instead?

vocal condor
#

Shouldn't it be Physics2D.Raycast for 2D?

#

Are you intending for 3D physics or 2D physics? @crisp rune

crisp rune
#

there's a physics2d?

#

of course there is, why wouldn't there be

crisp rune
#

that doesn't change how the ray itself acts though

vocal condor
#

Have you already tried the 2D version?

crisp rune
#

this is the debug ray that shows

#

unless there is a Debug.DrawRay2D

#

in which case I will be very annoyed

vocal condor
#

I think the draw is more or less limited to the values you're using as the direction+length

#

Your current length is a variable amount (based on velocity of y), perhaps you'd want something else.

crisp rune
#

I'm using the raycast so I can tell if the player will collide with something, and will put the player directly on the collider instead of letting it intersect

vocal condor
#

Was referring to the DrawRay being incorrect.

crisp rune
#

ah

#

what other variable would I use?

#

I multiply it by Time.fixedDeltaTime to make it be the single frame value

vocal condor
#

Pretty sure you want your ray to be a fixed length unless you're intending for it to grow and shrink as velocity changes.

crisp rune
#

that is exactly what I want

#

it just isn't growing and shrinking in the wrong correction

vocal condor
#

Well, how I usually approach this is drawing a ray to the point of collision (ground or anything else within range)

#

Not sure of the intentions of your raycast and the debug illustration.

crisp rune
#

it lands exactly on the block instead of clipping

vocal condor
#

So you're rolling your own physics?

#

Or is there something wrong with RB2D?

crisp rune
#

I am using some RB2D

#

but I just want more control over it

#

I need RB2D so I can use built in colliders

#

which sucks

#

but idk how to make my own collisions yet

vocal condor
#

Fast objects in RB2D may move through stuff but setting collision detection to continuous usually solves this.

#

Hmm, UnityChanThink

crisp rune
#

lemme make another animation real quick

#

this happens with continuous

#

and I don't like that

crisp rune
#

If anyone replies, I'm going to bed so just ping me and I may answer at like 5pm pst

eternal hamlet
#

hmmm.. thought collision detection and moving the object back on top of the 'floor' was all done in a single frame so you shouldn't be seeing it below the ground

north ridge
dawn plover
#

so my game is done and all, but i want the player to restart in a position. I wrote a code but it doesnt seem to be working
does anyone have an alternative to this code for a 2d game?

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

public class Respawn : MonoBehaviour 
{    
    [SerializeField] private Transform player;
    [SerializeField] private Transform respawnPoint;
    
    void OnTriggerEnter(Collider other)
    {
        player.transform.position = respawnPoint.transform.position;
    }
}
crisp rune
#

I would make respawnPoint a Vector3 and set the transform.position to that

#

also you don't need to put player, you can just put transform.position

fair trellis
#

i gotta 2d scene with 2 players but if i collide with the other player he flies off is there a way to fix this?

crisp rune
#

could you specify a bit more?

tough grotto
#

how to write something on the console

crisp rune
#

how to write something on the console
@tough grotto Debug.Log(variable, string, etc)

grave plume
#

@dawn plover Are you sure OnTriggerEnter is being called? It only works for normal rigidbodies, you need OnTriggerEnter2D instead for 2d rigidbodies.

#

Print something on the console at least to see if it's even being called when you collide with it and that collider is set to trigger

dawn plover
#

@dawn plover Are you sure OnTriggerEnter is being called? It only works for normal rigidbodies, you need OnTriggerEnter2D instead for 2d rigidbodies.
@grave plume ah, thx so much

crisp rune
#

to add on to wesai's comment, when you replace OnTriggerEnter with OnTriggerEnter2D, also replace the (Collider other) with (Collider2D other)

dawn plover
#

im new to c#

#

thanks so much

grave plume
#

that is monobehaviour method, so it has more to do with how the Unity engine works itself than C#

tough grotto
crisp rune
#

what is the error?

grave plume
#

that is because you are using System's namespace

tough grotto
#

the debug thing

#

that is because you are using System's namespace
@grave plume wdym

dawn plover
#

that is monobehaviour method, so it has more to do with how the Unity engine works itself than C#
@grave plume i see

grave plume
#

that grayed out System namespace at the top

tough grotto
#

you talking to me??

grave plume
#

both System and UnityEngine have a Debug

#

yea

crisp rune
#

what is the error specifically?

tough grotto
#

oh

#

both System and UnityEngine have a Debug
@grave plume so whats the fix

crisp rune
#

remove the system namespace

grave plume
#

either erase using System or use UnityEngine.Debug.Log()

crisp rune
#

get rid of using System;

tough grotto
#

i erased it

crisp rune
#

try it now

tough grotto
crisp rune
#

oh, it's from using System.Diagnostics;

tough grotto
#

oh

#

ok thanks

crisp rune
#

do you have an extension that adds it automatically?

grave plume
#

oh yea

crisp rune
#

if so, you may want to configure or remove it

tough grotto
#

oh ok

dawn plover
#

It works!

tough grotto
#

@crisp rune still nothing writes on the console

crisp rune
#

are you calling the function anywhere?

tough grotto
#

no

#

is that a problem

crisp rune
#

yes

#

it won't run the function unless you call it

tough grotto
#

ok can i remove the function?

grave plume
#

you can test it by using the Start() function

#
void Start()
{
    test();
} ```
tough grotto
#

oh

#

i just removed the function

#

should work right?

grave plume
#

anyway, it seems like you need to read some beginner tutorials

tough grotto
#

yea

#

i've watched videos but

#

i dont understand how to do it on unity

grave plume
crisp rune
#

...which videos did you watch?

tough grotto
#

about c#

#

i understand if statements variables

#

and all that

grave plume
#

do you understand how methods are ran and how to call them?

crisp rune
#

unity is different from just C#

#

also this video is ooooolllllddddd

tough grotto
#

yea. there's no tutorials about c# in unity

grave plume
#

there's a bunch if you look

tough grotto
#

where

grave plume
#

unity's official website for example

#

they have a learn section

tough grotto
#

can you send me a link?

grave plume
#

unity learn, there are a few projects which are tutorials

#

you can develop them as you read / watch the videos

tough grotto
#

oh ok thanks ill check it out

grave plume
tough grotto
#

mhm

grave plume
crisp rune
#

most unity tutorials include C# in some form

grave plume
#

you will see that Start() is a MonoBehaviour method, if you click it you will see how it works

tough grotto
#

yea

#

it worked btw thanks guys

grave plume
#

no it's not an error

tough grotto
#

ok thanks, im going to go learn more

#

i appreciate the help

grave plume
#

if you double click it, you will be directed at the line that prints that message

real umbra
#

Does anyone know how to code throwing an item

crisp rune
#

would you care to be a bit more specific @real umbra?

real umbra
#

like grabbing an item and throwing it

#

it's just like picking up an item and instead of dropping it, you throw it

crisp rune
#

that sounds like it would be something you may just want to figure out for yourself since it seems somewhat project specific

hoary frost
#

Hello, I have recently worked on a project but I want to push it to be a little better and one thing that is bugging me is 2D sprite masks..... The issue I have is that sprite masks do not work with sprite skins... does anyone have experience with this? I might cross post this to the shaders channel because I believe that is how I'll solve my problem.

chrome fern
#

Does anyone know how to destroy and respawn a game object over a period of time? I can make the respawn happen in a coroutine but it ignores the yield statement

vocal condor
#

You'll likely want some manager script to destroy the object and instantiate it after a given time of yielding. @chrome fern

#

If the script is on the destroyed object, it will no longer be valid.

#

it meaning, respawn will never occur.

real umbra
#

that sounds like it would be something you may just want to figure out for yourself since it seems somewhat project specific
@crisp rune k

brave creek
#

hello, how would i separate values like bools between 2 of the same object with same script? i'm currently trying landing with two players, but if one lands it also counts for the other, how would i solve this?

crisp rune
#

make the variable static

brave creek
#

that'd be for if it were multiple scripts and it has to send it to a script from a different one, what i mean is have 1 variable, 1 script and 2 objects that are basically the same. how would i have that 1 value change for the 2 objects independent from script, so they they have different landing values from each other

crisp rune
#

make the variable public?

brave creek
#

that still has to do with 2 scripts

crisp rune
#

no?

brave creek
#

public isn't within 1 script, it's in the editor or when you want to reference a value alongside a static

crisp rune
#

I always thought static was the only one that allowed you to use variables in multiple scripts

brave creek
#

you'd need public static for references

crisp rune
#

yeah, you wouldn't use private static

#

maybe you could throw both of your objects under an empty and use that for something

brave creek
#

the script is already under 2 empties

crisp rune
#

ah

#

oh wait I read the question wrong

#

I'm dumb

#

just make 2 bools

#

or make 2 scripts

brave creek
#

making 2 scripts would worsen the performance

crisp rune
brave creek
#

alrighty thanks!

austere iron
#

what's wrong with using a static variable here?

crisp rune
#

It's the opposite of what he needs

orchid matrix
#

gameObject.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePositionX;

eternal hamlet
#

@brave creek not sure if i understand you correctly but each object will have it's own values already that are separate from the others, unless it's a static variable

austere iron
#

Yeah, if you don't want a single share variable, you'd just have a regular class variable since each instance has their own. So in not sure what you're really asking...

boreal quarry
#

Does anyone know a good c# course that goes in depth?

still tendon
#

hello please someone know how can i make get input.mousebuttondown and input.touch not be triggered when u click on UI??

eternal hamlet
#

turn off ray cast target on the UI

#

on the panel/image @still tendon

still tendon
#

if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()

#

i used that

#

and it seems to only work on ui gameobjects idk why but that what i needed

#

dont know if it works on touch inputs yet tho

#

ill check what u toldme if it doesn't @eternal hamlet ty for the info

obtuse torrent
#

For some reason
rb.velocity = transform.forward * speed isn't working
rb is stated in void Start() as getComponent<RigidBody2D> and no matter what the speed is it doesn't work

#

I'm trying to make a projectile that goes to the staff weapon, takes its rotation and goes forwards until it hits an enemy

#

Yet I am unable to make it move forwards

eternal hamlet
#

is there an error?

#

do a debug.log of your speed variable right before that line

obtuse torrent
#

Although a while later, I have found out that the RigidBody2D has its velocity stuck at 0

#

No matter what value I put into the RigidBody2D velocity it stays at 0, 0

heavy token
#

post your code

#

and are you sure speed is not 0?

#

if it's public you need to check the inspector

obtuse torrent
#

i did Debug.Log(speed) and it said 150

#

Which is the value I assigned

#

I couldn't get Hastebin to work

heavy token
#

If isKinematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore.

obtuse torrent
#

It still doesn't work even after removing Kinematic

heavy token
#

you removed the line in Start?

obtuse torrent
#

yes

heavy token
#

well then I dunno. Your increase and decreaseSize functions are also a little strange. You can just call transform.localScale = new Vector2(0, 0);

obtuse torrent
#

oh lol

tall current
#

do you want to make the scale 0, 0? the hell

obtuse torrent
#

No matter what the velocity stays 0 , 0

tall current
#

oh lmao

#

well that's probably because @obtuse torrent , transform.forward is forwards in the Z axis, the one that isn't used it 2D

obtuse torrent
#

oh

tall current
#

try transform.right or left instead

deep rivet
#

can somebody tell me how can i instantiate a object at a raycast hit position

#

nevermind i got it working

violet lark
#

Why this is called two times?

grave plume
#

do you have this script attached twice by mistake?

#

Anyway, you are trying to read input on a physics loop, so that might be your issue, I recommend you try to read it on Update()

#

what you could do is set a bool to true on collision enter and false on exit and on Update if that bool is true and if you press the input, you run that code block

still tendon
#

guys i cant seem to figure out why smoothdamp is not working as i intend it to?

 void moveWorldDown(){
        Vector3 desiredPosition = myTransform.position - offsetY;
        Debug.Log(desiredPosition);
        myTransform.position = Vector3.SmoothDamp(myTransform.position, desiredPosition, ref velocity, dampTime);
    }

when i press 'X' this function is called. i want this function to move some grouping of gameobjects down in world smoothly. instead they move once for very short distance. desiredPosition is calculated correctly

#

dampTime = 0.2 f;
velocity = Vector3.zero;

still tendon
#

Try this:

/// <summary>
/// Moves the world down to the desired position.
/// </summary>
/// <remarks>
/// Called every frame the object wants to move.
/// </remarks>
public void MoveTo(Vector3 desiredPosition, float speed = 14)
{
  transform.position = Vector3.MoveTowards(transform.position, desiredPosition, speed * Time.deltaTime);
}

I use MoveTowards over Lerp/SmoothDamp, easier to work with, the math doesn't prevent it reaching x when the distance is closing so it's a win win.

#

However, it must be called every frame (Late or Update if not physically simulated else FixedUpdate) till your object is at the desired position, which can be done with a simple check to break the move

#

This is assuming you're moving the root down, if you're doing say 100 indevidual objects, you will most likely want to approach this a little different to avoid cucking the main thread

#

If your objects are physically simulated, use Time.fixedDeltaTime

obtuse torrent
#

How could I make it so that when an object is a certain distance away from a given Transform variable, it does something

#

nvm worked it out

dark zenith
#

Guys, i how make the script when ur character lean on object u die?

#

nvm, i saw this trouble is so simple :D

cloud vapor
#

Hi, i am trying to dectect a collision between a BoxCollider2D and a TilemapCollider2D. Why is this code not working? Thanks in advance,

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

public class Pushable : MonoBehaviour
{
    protected Collider2D _collider;
    protected Collider2D _holeCollider;
    // Start is called before the first frame update
    protected virtual void Start()
    {
        Initialization();
    }

    /// <summary>
    /// Grabs components and saves initial position and timer
    /// </summary>
    protected virtual void Initialization()
    {
        _collider = GetComponent<Collider2D>();
        _collider.enabled = true;
        _holeCollider = FindInActiveObjectByLayer(LayerMask.NameToLayer("Hole")).GetComponent<Collider2D>();
        _holeCollider.enabled = true;
    }

    // Update is called once per frame
    protected virtual void FixedUpdate()
    {
        if (_collider.IsTouching(_holeCollider))
        {
            Debug.Log("YEAH");
        }
    }

    private GameObject FindInActiveObjectByLayer(int layer)
    {
        Transform[] objs = Resources.FindObjectsOfTypeAll<Transform>() as Transform[];
        for (int i = 0; i < objs.Length; i++)
        {
            if (objs[i].hideFlags == HideFlags.None)
            {
                if (objs[i].gameObject.layer == layer)
                {
                    return objs[i].gameObject;
                }
            }
        }
        return null;
    }
}

heavy token
#

check if _collider and _holeCollider are not null

obtuse torrent
#

Is there a way to destroy the collision through OnTriggerEnter2D()?

cloud vapor
#

they are not null

uneven wing
#

where would i start for a 2d topdown survival game?

#

like stardew

cold rover
#

I mean, that depends on what your experience level is.

#

If you're basically brand new to Unity, you should probably learn how to use the program and do some basic coding before you jump into making anything specific

light elk
#

anyone else making a 2D platformer game?

distant pecan
#

probably

#

what's your question ?

cloud vapor
#

i have found a solution for my problem for anyone thats need something like that

#

_holeTestMin = Physics2D.OverlapPoint((Vector2)_collider.bounds.min, HoleLayerMask);
_holeTestMax = Physics2D.OverlapPoint((Vector2)_collider.bounds.max, HoleLayerMask);
OverHole = ((_holeTestMin != null) && (_holeTestMax != null));

obtuse torrent
#

How can I make a prefab of an enemy, when created through code aim for a player transform that is outside of the prefab?

#

nvm worked it out

still tendon
#

Hi guys I am new to the chat!
I am working on a 2D project, using 2D lights, but when I build the project in WebGL the screen is all black.
Does WebGL support 2D lights rendering?
thanks!

zenith saddle
#

HI guys, I'm a new here

#

And maybe someone can help me ?
I have a problem with textmeshpro in canvas, it's that it is invisible, I cant see him

#

I don't know if I'm writing in the right place, but I'm begging you for help

heavy token
#

@zenith saddle it has nothing to do with your code. Make sure the canvas is set to Screen Space - Camera and the main Camera is in the camera slot. and make sure the Sorting Layer and Order in Layer is above the background

zenith saddle
#

canvas is set to screen space - camera

#

and i have only one Camera

heavy token
#

Start your game and go into Scene view. Move the text around to see if it's behind something and make sure the text isn't empty

zenith saddle
#

I switch off background and textmeshpro is here

#

It's look that it covers the text.

#

And I see that my player yet gone ๐Ÿ˜’

heavy token
#

Look up sorting layers and sorting order

zenith saddle
#

I have like this

heavy token
#

@zenith saddle Layers and Sorting Layers are two different things. Right now you only have 1 Sorting Layer. the normal Layers don't do anything for the rendering order

zenith saddle
#

Thanks, now it's working ๐Ÿ˜„

#

Yet i have now a problem with pause menu. Game I can stop but I dont see menu pause

keen crystal
#

anyone know how to access the vertices of the tile's custom physics shape via code?

sweet swan
#

if you only need to access them to make them more precise, you can do that from the .meta file

#

but afaik there's no way to change physics shapes at runtime

crisp rune
#

an isometric grid would be just a normal grid rotated 45 degrees and viewed at an angle

sinful pilot
#

How could I stretch my ground element based on screen size?

crisp rune
#

for what kind of game?

crisp rune
#

I think you need to apply the same effect to the square

ebon lagoon
#

Hey all, quick question. I'm trying to figure a way to do a sword slash in a top down 2D. Player is the blue circle, when I attack I do a OverlapCircleAll around him (black circle) to get the enemies inside it, but how could I target ONLY the enemies inside the angle of the sword slash ? (green part) ๐Ÿ˜„

eternal hamlet
#

@small oasis you can use a polygon collider2d to create your collision area, then use OverlapCollider instead of circle

ebon lagoon
#

Was thinking about that too, but if I change weapon I would like to change the angle of the "slash" area

eternal hamlet
#

You can have a separate polygon collider for each weapon

ebon lagoon
#

Could work yes. So if I pick up something that increase the area of effect of my weapon, I would just have to change the scale of the current collider shape assigned to the current weapon

heavy token
#

it's cool though. As long as I get my cut

ebon lagoon
#

Not at all ^^ Just messing around with a TDS and melee combat ๐Ÿ˜†

austere iron
#

@ebon lagoon you can use Vector2.Angle to check if each collider in the array is within a certain angle...

light elk
#

@ebon lagoon check code monkey on youtube

#

best youtuber for unity 2D games

#

he even give u t he project files

#

for every tutorial

#

unlike other youtubers

vagrant jewel
#

Anyone know a good way to move a bullet that is a rigidbody2D gameobject smoothly? When I change the velocity it just teleports across the screen

austere iron
#

are you changing the value drastically?

vagrant jewel
#

The velocity is high, but is only be set once

tribal laurel
#

Does it make sense to draw a sight arc with a linerenderer, and then rotate it to align with the forward vector of a character, rather than trying to figure out where to start drawing the arc relative to the orientation of the forward vector?

#

So if my character's forward vector is Vector2d [1, 0] and his viewing angle is 90.. then you would expect 45 degrees on either side of due East

#

So do I just draw a 90 degree arc from starting angle 0, ending angle 90, then rotate it...

#

Or, do I use an if statement to check where the forward vector is, and in this case return -(viewingAngle/2) as the starting angle to draw from? So it would draw from -45 to 45

sacred elm
#

I'm trying to make a top down shooter but I can't get the rotation right with the new input system. I use the input system to get mouse position and use the following code. Rotation doesn't work correctly if my mouse is in viewport. I have to pull the mouse far away from the sprite for the rotation to be somewhat accurate

#

what is the best way to get mouse position using the new input system>

light elk
#

what is the best way to make a gauge bar

#

for example more attack you do makes ur gauge bar full so u can do a special attack

craggy briar
restive frigate
unique surge
#

@restive frigate If you use movement keys to create the path
you can store a list of directions until the path is finished
go from start of list to end of list, set target to first element

in update gradually move the object towards target
when target reached get next target

when last target reached clear the list

restive frigate
#

@unique surge Thanks for your guidance, I thought about moving to the clicked tile rather than using movement keys, but I think it is the same logic

unique surge
#

you could create a path that only moves on grid

#

if xposition difference is greater than yposition difference, and xposition of target is greater than current xposition, move up

etc

#

target would be the tile you clicked on

#

@restive frigate

restive frigate
#

@unique surge that makes sense, though I wonder how to "bound" (I lack of a better word) my player to the grid system. Most tutorials I watched had the player moving freely around even if there was a tilemap.

unique surge
#

Well how does your player move@restive frigate

#

in my tile based game I have 8 directional movement
and you cannot move again until you reach the tile you wanted to move to
this looks way smoother than you think

#

you press movement key, and then the character just moves to that tile

#

and if you hold down
will keep moving
but will always stop at the center of a tile

restive frigate
#

@unique surge I already implemented this kind of movement, but I would like to "buffer" all tile coordinates from start to end and move the player smoothly on the grid system

#

player should move the clicked tile

unique surge
#

if xposition difference is greater than yposition difference, and xposition of target is greater than current xposition, move up

etc
@unique surge
who said you cant do the same with this?

#

move up a tile

#

then based on next positions in list

#

also move along tiles

#

whats the problem

restive frigate
#

Idk I just started to Unity and I don't much about the coordinate system with isometric maps

unique surge
#

idk about isometric maps

#

if ur game not topdown
and 1,0 is up right instead of right

#

good luck

restive frigate
#

well after hours of search I figured that out already lol @unique surge thanks anyways!

eternal hamlet
#

move the character to the same position on the next tile

#

if character is for example near the bottom left corner, then move character to the next tile but position him in the bottom left corner of it

#

has anyone gotten pixel perfect text easy enough?

light elk
#

@craggy briar that is not the thing

#

i was talking game design actually

obtuse torrent
#

How can I make an object move in a full 360 rotation?

wraith pecan
#

use z coordinate I guess, I have no clue @obtuse torrent

obtuse torrent
#

I'm trying to use LookAt() in 2D doing

private Transform player;

void Start()
{
  player = GameObject.FindGameObjectWithTag("Player");
}

void Update()
{
  transform.LookAt(player.transform);
  transform.rotation = new Quaternion(0.0f, 0.0f, transform.rotation.z, transform.rotation.w);
}```
#

and for some reason when I'm on the left of the object, it turns away from the Player object

#

because I'm using it to orientate projectiles being shot from an enemy

vagrant jewel
#

Is there a way better than moving a 2d sprite with rigidbody2d.velocity? Whenever I do so it just teleports across the screen instead of moving

heavy token
#

Then you are doing something wrong. What the better way depends on your goal. Moving with a rigidbody is usually done because you want physics/collisions to happen

vagrant jewel
#

I am trying to detect collision, but it is just teleporting through so I guess I will try moving the transform's position

tropic inlet
#

Are you moving, like, super fast? Could that be why?

orchid leaf
#

I have tried the Unity Doc example of "Texture Scaling" , changing Texture tiling by code, but cant get it to work, i have version 2019, is there any simple method to use, for changing the Texture tiling?

I want to have pickable materials for 3d character, and add it to different gameobjects, planes, with different sizes

split bolt
#

hey guys

#

i need some help

#

currently when my character collides with a wall, he just sticks to this wall

#

he does not fall

#

he used to be able to infinitly jump if he was on a wall

#

but i figured that out

#

I need to know if I can make it so that he slowly slides down this wall

#

@heavy token

#

can you help

#

I think you helped me before so

heavy token
#

post your code

split bolt
#

ok

#

uhh

#

is there

#

a better way to post code

#

cause it wont let me

#

too much

heavy token
split bolt
heavy token
#

mhh I don't see why he sticks to a wall

split bolt
#

yeah

#

i have no clue

#

my only thought

heavy token
#

What collider has the wall?

split bolt
#

is that I would have to make a line of code to make the "ground" layer affect vertical movement when hit

#

oh

#

tilemap 2d, rigidbody 2d, and composite collider 2d

heavy token
#

Do you want physics to happen between the wall and the player? i.e. the player can push the wall over?

split bolt
#

that may be helpful later

#

but for now no

#

I just want him to slide down the wall

heavy token
#

You could remove the rigidbody and make the colliders isTrigger = true. Then in your player script you add ```cs

private bool isOnWall;

private void OnTriggerEnter2D(Collider2D collider)
{
//Check if the collider is actually a wall
isOnWall = true;
rb.velocity.x = 0;
//Maybe set velocity.y to zero
}

private void OnTriggerExit2D(Collider2D collider
{
isOnWall = false;
}

void FixedUpdate()
{
Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y);
if (isOnWall)
{
movement.y -= 0.2f; //However fast you want to slide down
}
rb.velocity = movement;
}```

split bolt
#

where do I add this

#

just under everything?

heavy token
#

in your PlayerMovement script

split bolt
#

yes

#

but where there

heavy token
#

yes make sure you remove the old FixedUpdate

#

doesn't matter where

split bolt
#

im kinda a noob

#

i dont know where the "old fixed update" is

#

wait

#

i think I found it

#

but

#

if I remove that, wont it mess up my movement?

heavy token
#

well I put the old stuff in the new stuff

split bolt
#

oh wait

#

lol

#

nm

heavy token
#

you don't have to remove it. Just add the new stuff

#

I added rb.velocity.x = 0;
to OnTriggerEnter()

split bolt
#

ok

#

wait

#

ima try now

heavy token
#

make sure you have the Colliders on the wall set to IsTrigger = true

split bolt
#

uhh

#

i fall through the floor lol

heavy token
#

the the floor a wall as well?

split bolt
#

uhh

#

its a tilemap

#

so everything is on there

heavy token
#

that's not good

split bolt
#

this is a problem isnt it

#

crap

heavy token
#

you need to give the wall and and ground separate colliders. So one can be set to IsTrigger and the other can be a normal collider

split bolt
#

but you see, I dont think this is possible

#

look at my game

#

lol

opal socket
#

Instead of OnTrigger you can use OnCollision

heavy token
#

You need to find out why your player is getting stuck to walls

#

You can also change OnTrigger() to
private void OnCollisionEnter2D(Collision collision)
{}
and
private void OnCollisionExit2D(Collision collision)

#

and set IsTrigger to false on all colliders

split bolt
#

ok i try

#

now

heavy token
#

and then you can check whether you are touching the ground or the wall with isGrounded()

split bolt
#

wait

#

im so bad at this

#

I have no Idea how to impliment the isGrounded part

#

wait

#

i might have learned

#

i just put isGrounded = false; under the isOnWall right?

heavy token
#

inside the OnCollision functions you have to check if you are touching the Ground. If not, set isOnWall to true.

split bolt
#

uhh

#

problem

#

;i tried

#

but

#

the problem is

#

that it gives me the error that i can't do this because isGrounded is a method group

heavy token
#

isGrounded()

opal socket
#

An advice: instead of panicking after 5 minutes of trying to do something, maybe try to research & google first, write some code, check why it's not working, reiterate, rinse and repeat.

tough grotto
heavy token
#

which part doesn't work?

#

do you get the "ob"? If not move it outside the if statement. Then you know if there is a problem with the tag or the function itself

tough grotto
#

oh ok ill try it now

#

the function

#

it doesn't print either way

heavy token
#

Does your coin have a Collider that has isTrigger = true? Has your player a collider and a RigidBody? @tough grotto

tough grotto
#

yea

#

wait is trigger

distant pecan
#

are you sure you "Coins" tag isn't lowercase "coins" ?

#

it is case-sensitive

plucky galleon
#

he someone tell me if im on the right track to move a 2d enemy to the player

#
using UnityEngine;
using System.Collections;
using System.Security.Cryptography;
using System.Collections.Specialized;

public class AIController : MonoBehaviour
{
    public int moveSpeed;
    public int maxDistance;
    public Transform target;
    public bool trigger;
    private Transform myTransform;

    void Awake()
    {

        myTransform = transform;
    
    }

        void Start()
    {
        moveSpeed = 1;
    }

    void OnTriggerEnter2D(Collider2D  other)
    {
        if (other.tag == "Player")
        {
            target = other.transform;

            maxDistance = 0;
            trigger = true;
        }
    }

    void Update()
    {

        if (trigger == true)
        {
            Debug.DrawLine(target.position, myTransform.position, Color.yellow);

            if (Vector3.Distance(target.position, myTransform.position) > maxDistance)
            {
                myTransform.position = Vector3.MoveTowards(myTransform.position, moveSpeed)
            }
        }
    }
}
#

the bottom half im refering to...under void Update

#

i think im missing something in the MoveTowards () but i dont know what...

civic knot
#

@plucky galleon Check the docs for MoveTowards. Specifically what arguments it takes and how it even works.

plucky galleon
#

theres a document for this stuff......

#

like what each one requires to be functional.

#

for FUCKS SAKES xD

#

ima stop bothering yall now

civic knot
#

Hahah. Yeah. Always check the docs first.

plucky galleon
#

i didnt know docs existed...would make this so much easier...most of my struggle is not knowing what to actualy type in to C#....cuz i know how code works...its just with a blank slate....i wouldnt know what to start typing

civic knot
plucky galleon
#

yes i did find it thank you im just now trying to figure out which 3 piece to plug into it...cuz i know moveSpeed needs to go in
myTransform.position needs to go in... i just cant figure out the 3rd

#

or should i use myTransform.transform......

#

ugh i know this is such a simple task... xD my brain hurts figuring this out for first time

civic knot
#

"speed", if you may call it so, is the third parameter.

plucky galleon
#

yeah i have that as the 3rd item, i know its (start position, new position, speed

civic knot
#

the first 2 are 2 points in space between which the new point should be.

plucky galleon
#

oh wait hold on i actualy read the console error

#

one sec

#

says } expected

#

am i missed a } somewhere

civic knot
#

seems so

#

or have one extra {

plucky galleon
#

wait is it cuz i have an if statement inside of another if statment

#

but no else...?

civic knot
#

I don't see a problem in the code you posted previously

plucky galleon
#

omfg i see the problem

#

it said fucking ; not }

#

theres no ; at the end there

civic knot
#

Yeah. Didn't you see that highlighted in your ide?

plucky galleon
#

yes i did im just so fried i didnt read my damn console....nore pay attention to the symble

#

well it works

#

it actualy works however ....the enemy snaps to the players position now xD

civic knot
#

the speed is probably too big

#

multiply it by delta time

plucky galleon
#

and Time.deltaTime fixes it!!!!1 YESS

wispy hazel
#

Hey before coding a game, what are some things I need to look out for in terms of performance optimization?

tall current
#

@wispy hazel Don't worry too much about performance in the beginning. You'll figure out things as you go along, but some optimizations can be a bit complicated and scare you away if you start with them too soon

#

Object pooling for example, it's very useful, but not easy to understand in the beginning

#

You don't really need it unless the game spawns hundreds of projectiles at once.

wispy hazel
#

Ok then, thanks๐Ÿ˜„

exotic steeple
#

how do i make my player infront of a game object in 2d? im a noob. and how do I make it so my player won't go through objects

tropic inlet
#

For the last one, rigidbody2d and some 2d collider

eternal hamlet
#

@exotic steeple sprite ordering is done by the sorting order value on the sprite renderer, set the players sorting order higher than everything else

exotic steeple
#

Thx I got it

tawdry veldt
#

hey is there anyone who could teach me how ro program a 2d game?

elfin sandal
#

plenty of good tutorials out there

tawdry veldt
#

thanks dude\

light elk
#

hey anyone knows a tutorial to make jumps for top down games

#

example game

#

you know those sidescroller ortho or top down stuff

grand cove
#

@light elk how I would do it is to always keep track of the ground position under the target to know of an attack should hit me, and just increase the y axis to display the jump. I would personally shrink the character a tiny bit too make it obvious he's moving away from the camera. It's all math really for the jump to look good though, since you need to take into account that the landing could potentially be a y axis higher or lower...

But tbh, I would just make these games in 3D with Paper Mario/Octopath style animations to make it look 2D since I'm lazy.

light elk
#

problem is we got no 3D skillz

#

๐Ÿ˜“

vocal condor
#

Could just have a parenting object maintain transform relative to world and the object itself (with renderer) maintain jump positioning.

light elk
#

find this

#

oh well m just making random prototypes

#

learning different things

alpine steeple
#

How would I turn a pdf into a list of Images inside a script?

craggy briar
#

Slowly and painfully

civic moss
#

๐Ÿ˜‘

light elk
#

@grand cove how would you make this kind of controller moduler though

grand cove
#

Character controllers are usually very specific to each ype of game you make, something that could be modular is the key binds that could be events, but in my experience I would always make a character controller tied to the game or game genre.

#

Don't really know what else you could mean with modular @light elk

light elk
#

i think people make the controller like octopath style

graceful cargo
#

hey guys so i tried to make my character move in my 2D world and I copied a bit of code from a video that taught me how and so this is the code that I ended up with
public class PlayerMovement : MonoBehaviour
{
public float movementSpeed = 5f;

public Rigidbody2D rb;

Vector2 movement;
void Update()
{
   movement.x = Input.GetAxisRaw("Horizontal");
   movement.y = Input.GetAxisRaw("Vertical");
}

void FixedUpdate() 
{
    rb.MovePosition(rb.position + movement * movementSpeed * Time.fixedDeltaTime);
}

}
My character does not move when I Input w a s or d tho

#

If anyone knows any fixed pls lmk

civic knot
#

@graceful cargo check the input settings for the input axis that you try to query.

tropic inlet
#
  1. Make sure the script is actually attached to your object.
  2. Check your coordinates in the inspector as you input WASD in order to see if there really is no movement.
  3. Try increasing movementSpeedโ€”maybe it's too low.
rugged hedge
#

i have an idle animation and a script that changes the position of a limb solver so that the arm rotates to the mouse position. But it does not work if the animator is active. if i disable the animator therefore there is no idle animation playing then it works

velvet folio
#

Assets\photonbuttons.cs(25,31): error CS1002: ; expected

sweet swan
velvet folio
velvet folio
#

pls help me

lean estuary
velvet folio
#

oky thnks

zealous hearth
#

can someone help me?
i'm still a beginner at coding. i want, that my character looks at the cursor. i've been looking for tutorials, but none of them worked (top down shooter btw)

neon barn
#

can someone help me?
i'm still a beginner at coding. i want, that my character looks at the cursor. i've been looking for tutorials, but none of them worked (top down shooter btw)
@zealous hearth Check this tutorial out, it should work for what you want https://www.youtube.com/watch?v=LNLVOjbrQj4&ab_channel=Brackeys

Let's have a look at the easiest and best way to make top down shooting in Unity!

Check out Jason's courses! https://game.courses/mastery-course-brackeys-bonus/?ref=21

Unite Copenhagen: https://unity.com/event/unite/2019/copenhagen

Armored Soldiers: https://bit.ly/2Zqqn9P
W...

โ–ถ Play video
strange quartz
#

If I have 150 images, and I make a Sprite Atlas, how do I use the Atlas to make the animation or GameObject? I'm not sure how to use the Atlas or the best way to use it.

UPDATE: I drag 150 images into unity assets they become textures, then I turn each one into a 2d 1 image / square sprite, once they are all sprites, i add them to the atlas. Then ... not sure the best way to animate them.

austere iron
#

Open your atlas (in the project folder) to see all of the individual sprites. Select the group of sprites that make an animation and drag them together into scene. That will automatically create an animation...

chrome lintel
#

Iโ€™ve been thinking heavily about inverse kinematic rigs for 2d animating. One clear as day flaw is how it makes your characters feel like paper because you can really only use one set of sprites at a time. Therefore you canโ€™t do any animations that have a horizontal pivoting such as a turning your back to the screen.

Iโ€™ve been trying to use my own brain instead of just taking other ideas and the solution Iโ€™ve come to is having multiple IK rigs inside of a game object at once.

So for example say you want an animation where a character with a sword facing the camera will turn his back to the camera and swing the sword from his hip in an upward arc ending with his chest facing to the camera (think the image below but as a 2D IK rig instead of 3D model)

My solution would have you start the animation with an IK rig using an image where the character faces away from the camera, then using the state machine in unity disable the rig facing away and enable the rig facing the camera. From there Iโ€™d finish the animation on the new rig and again the state machine would be set up to switch to given rigs for the idle animation

Would this be a viable option for what Iโ€™m trying to do or am I working way too hard and thereโ€™s another solution Iโ€™ve totally missed

(Also no Iโ€™m not making a smash clone, Marths jab is the only thing I could think of to convey my idea)

https://media.discordapp.net/attachments/438387862963093504/771670038682796032/image0.gif

grand cove
tribal laurel
#

how do I rotate a List<Vector2> around an axis in 2d, where each vector2 represents positions/points of a shape?

#

I'm trying to draw something with linerenderer, then rotate it in the direction the player is facing

keen skiff
#

Could someone DM me a player movement script that doesn't have your sprite fall down immediately? (Or some alternative to this, I just want my player to have some sort of balance)

#

oh yeah just 2d platformer

elfin sandal
#

Whats the best way off implementing blood effects in 2d?

#

Particle system?

#

Or instantiting new gameobjs with sprite renderer component?

chilly siren
#

how would one stop their character from moving to the left in 2D

grand cove
#

@tribal laurel You take each object in the list and reverse the positions depending on the shape, you probably need a list of configs for each shape which node you need to move though. Now that I think about it, you could literally rotate the entire parent or you literally re-render it in the other rotation.
@keen skiff just lock the rotation of the character with a rigid body on it and put a collider under it.
@elfin sandal Depends how fancy you want it, particles are just enough for simple 2D, might have to put in some extra work if you wish for them to paint the ground
@chilly siren Depends what is pushing the character left TBH, but setting velocity to 0 or stopping it in it's tracks with transform.position = 0 works too.

tribal laurel
#

I've re-arranged my hierarchy to make this plausible. The player creates a child object that has the linerenderer component.

#

I can now rotate the linerenderer on the Z axis, but only if I uncheck "use world space"

#

the side effect tho, is that now the linerenderer is being drawn far away from my player object

#

I have already confirmed that the instantiated linerenderer carrying child object (SightArc) is being given the player's transform position as its origin

still tendon
#

Here's my jumping code:


ublic class JumpScript : MonoBehaviour
{
    // Start is called before the first frame update

    public bool IsGrounded = false;

    private Rigidbody2D rb2d;
    private BoxCollider2D b2d;

    void Start()
    {
        rb2d = GetComponent<Rigidbody2D>();
        b2d = GetComponent<BoxCollider2D>();
        
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Space) && IsGrounded)
        {
            float jumpVelocity = 10f;
            rb2d.velocity = Vector2.up * jumpVelocity;

        }
        
    }



    void OnCollisionEnter2D(Collision2D Collision2D)
    {
        if(Collision2D.gameObject.name == "Collision")
        {
            IsGrounded = true;
        }

    }

    void OnCollisionExit2D(Collision2D Collision2D)
    {
        if (Collision2D.gameObject.name == "Collision")
        {
            IsGrounded = false;
        }

    }




}

#

It works great, however while I am moving over tiles (with a composite collider or not) it wont let me jump whilst moving?

tribal laurel
#

if I set LineRenderer to draw in local space, how can I make sure it begins drawing from the position of its parent object? When I set world space = false, the shape is drawn far away from its parent object.

meager mural
#

@still tendon you have a space in the file name. you cant have spaces in file names

#

and file name and class name need to be exactly the same

tacit dock
#

how do we display text in unity so that it has a fixed position...like it stays in one location and not move with the player screen..?
can smone help plzz

still tendon
#

What would be the best way to make a one sided collision platform for a multiplayer game. Where they could also press the down arrow when they are on top of the platform to fall through the platform. I looked at a few tutorials but none of them would work for multiplayer

#

@meager mural you seem like someone that would know

clear tusk
#

@tacit dock the canvas should be set to the world space not screen space

#

@still tendon if you are working with 2D then you just need to use the Platform Effector 2d component

still tendon
#

But if I set the collider mask to rotate whenever I press a key so that I could go downward through the wall, then couldn't other players on the server fall through it as well. Since it is a multiplayer game @clear tusk

clear tusk
#

yes they will fall to is like when you open a door in CODW and other players will find the door open not close

still tendon
#

Exactly, but that is not what I am wanting.

#

Because it will be more like an evasive manuever than it will be opening a door.

clear tusk
#

then you should choose an other mechanic to make your player go down fo example if the player is on top and he hold the down arrow for 1ms then you make hime fall

still tendon
#

This is what I have currently, where they hold it for half of a second. Will this make the other players fall through?

clear tusk
#

no each play has its own script so they other won't fall of when you do

still tendon
#

Okay, thanks for the help

clear tusk
#

np

meager mural
#

@still tendon 2D? Look at effector colliders

#

There's many of them. Don't know what does what

#

Just search for "effector" component and you'll see them all

still tendon
#

Mind scrolling up @meager mural and see if what we came up with would work

#

I had the effector part right, I just did not know if the other players in the game would fall through

rugged hedge
#

am stupid

clear tusk
#

@rugged hedge what do you mean exactly assigned in the inspector, also you are already checking if the gameobject is not null

rugged hedge
#

yeah i already removed that

meager mural
#

No idea, never done multiplayer or effector colliders, sorry

rugged hedge
#

like the checking if the first one is null

lean estuary
#

@rugged hedge Don't cross-post. Question has nothing to do with 2d as well

rugged hedge
#

i mean im doing a 2d game

#

but i understand

tacit dock
#

thnx @clear tusk !!

graceful arch
#

Does anyone know if its possible to get the height and width in units of the 2d pixel perfect camera? I thought the easiest way to get this was by finding the current scaled resolution and divide it by the ppu but the normal camera only has the current resolution, the ppc only the ref resolution.

heavy token
#

camera.PixelWidth maybe

graceful arch
#

@heavy token I hoped that aswell, but its just the screen pixel width

tall current
#

@graceful arch can't you just get the world coords for the highest point on your camera?

#

then take the difference of the middle and the highest one, then multiply it by two

#

works in my head I s'pose

graceful arch
#

@tall current that works, ty

brave creek
#

heyo, I've been trying to do this for a while but to no avail: I want to have it so that the players can grab a gun, which I succeeded to do, but when i have multiple players with the same object (grab with same script) and one picks a gun up, it counts as the same for the other, how could I fix this?

spring ledge
#

@brave creek static for fields means that the field will be the same value on all objects of that class

brave creek
#

ah thanks, but how would i reference it too other scripts then though?

spring ledge
#

What do you mean? If you have it public, other scripts can access it on an object of type Grab. If you need to get that you can use someGameObject.GetComponent<Grab>(); to fetch it. Though ideally you'd only fetch the component do that on something like Start() or Awake() and stick the result in a variable to use later. That way it isn't run every single frame

brave creek
#

i generally use getcomponent, but then it would say it's not a static value?

#

oh wait, is that only if you don't have the "someGameObject" before it?

spring ledge
#

How are you using getcomponent

#

You'd do something like

// use yourVarName.Pistol```
Not
```Grab.Pistol``` then
brave creek
#

i'd normally use it like

"GR = someGameObject.GetComponent<Grab>();"

spring ledge
#

Should work I suppose? If you the nuse GR.Pistol

brave creek
#

ahh, thanks!

ebon flame
eternal hamlet
#

@ebon flame you would need to store val in a public variable

ebon flame
#

so i have to create a static variable and then put it in there?

eternal hamlet
#

public int inputVal;

public void HandleInputData(int val) {
    inputVal = val;
    if (val == 0) {

    }
}
ebon flame
#

ooh thanks

eternal hamlet
#

no not a static variable

ebon flame
#

does it also work with those?

#

cause i need it on a other script

eternal hamlet
#

it would...but it would be bad programming practice

ebon flame
#

how can i access it better from another script?

eternal hamlet
#

post all of your code

ebon flame
#

th whole script?

eternal hamlet
#

what is the script called that you want to find?

#

what is the script name where HandleInputData is in

ebon flame
#

the variable is from topicChanger and i need it in produceScript

#

oh topicChanger

eternal hamlet
#

ok so at the top of produceScript, put "public topicChanger topicChanger;"

ebon flame
#

ok

spring ledge
#

Sort of depends on your exact usecase if you can use static or not, but yeah, probably better to use non-static

eternal hamlet
#

then you can go to the inspector and assign that variable, find the object with topicChanger on it and click and drag it

#

actually your variable name can't be topicChanger since that's the name of your script...your script name should really be TopicChanger

#

script/class names should be capital first letter

ebon flame
#

yes its in produce so no problem

#

ok

eternal hamlet
#

in your topicChanger script, just under "public class topicChanger" put "public int inputVal"

ebon flame
#

ok

eternal hamlet
#

what did you name your topic changer variable?

#

"public topicChanger topicChanger;"
this line, what did you put?

ebon flame
#

topicChanger

eternal hamlet
#

whats the name of your script?

ebon flame
#

produceScript

eternal hamlet
#

i mean the topic changer script

ebon flame
#

topicChanger

eternal hamlet
#

that should produce an error

#

i think? maybe not

ebon flame
#

no

eternal hamlet
#

ok anyway, now you can access inputVal by going to produce and typing topicChanger.inputVal

ebon flame
#

i put public topicChanger topicChanger into produceScript

eternal hamlet
#

though seems like it would be an ambiguous call...

#

are you using visual studio?

ebon flame
#

yes

eternal hamlet
#

can you highlight your class name in topic changer script and push ctrl+r twice

#

and rename it to TopicChanger

#

make sure you do ctrl+r twice to rename, that way it will also rename everywhere else (including your file name)

river root
#

Yo, I'm pretty new to unity and I am trying to make a tree stump prefab with a tree trunk as a child, and when the stumps health is 0 the tree trunk activates and falls, but I can't seem to make it work, I keep getting (Object reference not set to to an instance of an Object), and I am on day 2 of trying to make this work. It's giving me a headache and I am desperate. is anybody able to lend me a helping hand?

ebon flame
#

does it work on visual studio code?

eternal hamlet
#

i would imagine so

#

try F2 for VS code

ebon flame
#

nope

#

doesn't work

eternal hamlet
#

Renaming is a common operation related to refactoring source code and VS Code has a separate Rename Symbol command (F2). Some languages support rename symbol across files. Press F2 and then type the new desired name and press Enter. All usages of the symbol will be renamed, across files.

#

hmm it says F2 should work

#

try ctrl+f2

ebon flame
#

I'll just do it manually

eternal hamlet
#

you'll also have to rename the file

ebon flame
#

ok i did

eternal hamlet
#

now your variable can be "public TopicChanger topicChanger;"

ebon flame
#

ok

eternal hamlet
#

and you should now be able to put
Debug.Log("inputVal: " + topicChanger.inputVal);

ebon flame
#

yeee, thank you :)

eternal hamlet
#

no worries

ebon flame
#

thanks

spring ledge
#

@river root I mean, without seeing your code, probably noone can

river root
#

Sorry I don't know the etiquette here yet

spring ledge
#

Generally you'd just paste it into hatebin or some site like that xD But that may work

#

Any more info on the error?

river root
#

This is what I get

ebon flame
#

try to double click it

eternal hamlet
#

remove .TreeTrunkScript at the end on line 20

river root
#

Okay

spring ledge
#

You're having sort of odd logic there in setting your TreeTrunkScript variable

eternal hamlet
#

oh wait sorry, misread your code

spring ledge
#

Why are you getting a component of type TreeStumpScript inside the TreeStumpScript

#

Just get a component of type TreeTrunkScript

river root
#

I had a friend help me with it earlier and it sort of spaghettified

eternal hamlet
#

it's your lin 20

#

line 20*

#

hold on

river root
#

I appreciate this

eternal hamlet
#

TreeTrunkScript = TreeTrunk.GetComponent<TreeTrunkScript>();

spring ledge
#

Essentially you're getting probably the script you're already in, and trying to set the variable (which is null because you haven't set it) to itself

#

๐Ÿ˜„

river root
#

So erase line 20 and slap that in instead?

eternal hamlet
#

yup

river root
spring ledge
#

You may need GetComponentInChildren though

river root
#

I think you're right, let's give it a play

eternal hamlet
#

you could just click and drag the script into the variable in the inspector

river root
#

It seems to remove its self

spring ledge
#

Is that with GetComponent or GetComponentInChlidren

river root
#

Children

spring ledge
#

And the trunk (with TreeTrunkScript in it) is a child of stump (with TreeStumpScript in it)?

river root
#

Yup, let me take a pic

spring ledge
#

Oh never mind

#

Use GetComponent

#

since you're already accessing the trumk directly

#

Thought you're going through the stump :p

river root
#

Access the Trump

spring ledge
#

haha

#

This Stump/Trunk switcharoo is making my brain weird

river root
#

Yeah trust me I know the feeling

#

Same error

#

And when I run the Tree Trunk and Tree Trunk Script are both blank again.

#

If I unpack the prefab or unpack them and take the TreeTrunk out of TreeStump it still gives the same error.

#

It's like, completely blind to the TreeTrunk for some reason.

spring ledge
#

Sounds like TReeTrunk isn't set there from your last error btw

#

Maybe something to do with it being a prefab?

eternal hamlet
#

remove the GetComponent and just assign it in the inspector

river root
#

I place all my chips on it being that, 1 sec.

spring ledge
#

Try GetComponentInChildren instead of TreeTrunk.GetComponent

eternal hamlet
#

click and drag your tree trunk object into the tree trunk script

river root
#

Okay, ComponentInChildren does let me launch it no problem, and it grabs the script, but then immediately after that the Tree Trunk field in the inspector goes back to being empty

spring ledge
#

define "after that"

#

The game is still running?

river root
#

Yes

#

Let me check something

#

I really appreciate the help here, honestly truely.

I'm trying to make the tree do all the things it can do to make it easier for me to visualize

#

Alrighty, it is doing some things properly, others not, but at least it is finding the TreeTrunk, so I think I have it from here!

tall current
#

I hate it from here hahah

river root
#

๐Ÿ˜ฌ Freudian slip

#

Now I need to make the trunk tell the Stump when it hits the ground, here we go

eternal hamlet
#

you could just rotate it and once it hits 90 or 95 degrees then it "hit" the ground?

#

same as what i did here awhile ago

still tendon
#

if (2D.Good == true){
TortureObama();
}

tropic inlet
#

I used to work for Obama and I find this offensive

still tendon
#

Ah sorry senpai

#

Why public gameobject tho

#

why not private

#

Destroy(Death);

#

boom you died

#

wow i accidentally wrote the d cap so you did not die

#

i suck at coding

eternal hamlet
#

you should probably take your stoned talk somewhere else

still tendon
#

ye

eternal hamlet
#

ahh mother insults, thanks for that

still tendon
#

NO

#

thank obama ๐Ÿ˜Ž

river root
#

Was that @ me Limited Past?

still tendon
#

@river root

eternal hamlet
#

nope...it was at the 12 year old stoner @still tendon

river root
#

(I mean the video)

Oh my god is that the real Obama420? In the flesh?!

still tendon
#

Yes

#

Its me

hollow crown
#

@still tendon Please do not post off topic nonsense thanks

eternal hamlet
#

@river root oh sorry yeah the video was for you ๐Ÿ˜›

hollow crown
#

!mute 762878490999521331 1d Do not post off topic.

barren orbitBOT
#

dynoSuccess Obama420#1586 was muted

river root
#

Okay, yeah the reason I want the tree to fall this way is because it is more organic I think.

#

I'm very much a stickler for things like this

eternal hamlet
#

is your game side scroller or top down?

river root
#

SideScroller

eternal hamlet
#

ahh ok yeah that makes more sense then

#

rigidbody and ground collider would be the way to go

river root
#

Yuppers, already set up and (Almost) working, that's actually what I am trying to fix rn.

#

Thank you for the suggestion though, that video does look nice and crisp.

golden tendon
#

any good guides for a complete noob?

solemn latch
#

Depends on what you want to do, @golden tendon . Some topics have much better guides than others.

golden tendon
#

pixel art

magic haven
#

this channel is about 2D coding concepts

thick geyser
#

So this may seem obvious, but how do I determine where a ray cast goes.

I thought that the direction would be a quaternion being called direction, but it is a vector2.

I want to set the direction to be the direction the player is facing.
I have animator variables that I was going to use, but I could not figure out how to get it to work

#

I know that vector2.up works as (0,1), so why canโ€™t I have new Vector2(anim.GetFloat(โ€œhorizontalMoveLastโ€), anim.GetFloat(โ€œverticalMoveLastโ€)

#

As my direction vectors?

#

They are either -1, 0, or 1 based on the last input for context

spring ledge
#

I mean, what makes you think you can't?

eternal hamlet
#

@thick geyser you can certainly do that

spring ledge
#

just change their position?

tropic inlet
#

Use CharacterController?

#

idk

spring ledge
#

I mean, just moving is transform.position, yes. Not sure fi they were asking about collisions too

#

How would we know if you don't show the whole script (like put it on hatebin.com or so). You probably mispelled shootpont there though.

tropic inlet
#

you should always hover your mouse over the red line and say what the message is

#

it usually tells you what is causing the issue

#

there u go

spring ledge
#

Instantiate wants either a Transform or position+rotation

#

either you hand it the whole transform, or you hand it both a position and a rotation

#

Not just a position

#

I mean, no clue what rotation you want, could use shootpont.rotation :p

#

But then you may as weell just pass it the whole transform

#

I mean, that sounds like a direction or so, not a rotation

#

show a screenshot of your shootpont object stuff and describe what you're trying to do?

spring ledge
#

Have you tried hovering the red underlined part to see what it tells you

leaden hill
#

So, I can get raycasts and stuff working just fine in 3D but i'm working on a 2D project now

#

At first my ray was colliding with my player, so I ticked a box in Physics2D settings that stopped that.

#

And now the ray just doesn't cast at all seemingly. I try to draw it and I see nothing even with gizmos enabled, the color set to red, and the duration cranked up

#
            RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.forward);
            if (hit)
            {
                Debug.Log("Hit!");
                Vitals targetVitals = hit.transform.GetComponent<Vitals>();
                Debug.Log(targetVitals);
                if (targetVitals)
                {
                    Debug.Log("Damage!");
                    targetVitals.SufferDamage(gunDamage);
                }
            }
#

Anything obviously wrong?

#

I'm not even getting a hit and the object i'm trying to raycast to has a circle collider during the game with gizmos enabled

spring ledge
#

Try a Debug.Log before the if (hit) check to see if the thing even executes

#

Also what box did you tick in Physics2D settings

#

Thats a rather broad question :p

#

probably?

leaden hill
#

It's the one that stops raycasts from colliding with colliders they originate in

#

Let me load up Unity

#

"Queries start in colliders"

spring ledge
#

I see

#

@leaden hill Well try the Debug.Log output I suppose, and Debug drawray or so

leaden hill
#

Yeah, it's firing

#

Draw ray gets me nothing for some reason

#

Even if I turn on color and duration

#

Duration set to 5.0f

spring ledge
#

@leaden hill Try transform.right

leaden hill
#

@still tendon Basically you need to have a script handling the score and it needs to be accessed by a UI script to render the value on screen.

#

It's a pretty broad question

#

I haven't worked with UI much because I've never finished a game ๐Ÿ˜‚

#

It works just like anything else in Unity though

spring ledge
#

@still tendon Try Brackey's how to make a game series

#

Let's create a score counter for our game!

โ— Download the Project Files: http://devassets.com/assets/how-to-make-a-video-game/

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

ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท

...

โ–ถ Play video
leaden hill
#

There's probably a text box you can change the value of.

spring ledge
#

@leaden hill Anyway, .forward should poin talong the z-axis, which for 2d is into the screen

leaden hill
#

@spring ledge Yeah, that's probably what's up

#

I figured it was something like that

#

That was it

#

Thank you very much.

#

I have to get used to Unity assuming 3D in most situations

spring ledge
#

I need to mess more around wiht U nity 2D too

leaden hill
#

I just got kind of confused because I used transform.forward in a 2D context before and it did exactly what I wanted so I figured it worked for 2D

#

I mean, it does

#

It just works differently than I thought.

covert meteor
#

Hi, hoping someone can help with something. I've got a 2D sprite that can rotate around a central point, and move towards or away from that point within some boundaries. In isolation, both functions work fine - I can rotate around the centre, and move forwards and backwards. However, when the user tries to rotate AND move forwards/backwards on the same FixedUpdate, the rotation can sometimes "desync" it seems. I can't get my head around how this can happen - unless there's some behaviour of either .normalized or .RotateAround() that I'm not understanding.

leaden hill
#

Probably because you're trying to use a float or int or whatever as a string

covert meteor
#

change to score.ToString()

#

scoretext.text = score.ToString()

leaden hill
#

It helps to mouse over the errors and read them.

#

Because it'll usually give you an idea of what's wrong

#

At least vaguely

covert meteor
#

The compiler will give you an error that tries to explain what went wrong. It doesn't know what you were trying to do (beyond a guess), but it will point in the right direction. In this case, your error would have been something like "can't assign int to string" or words to that effect

#

When you say 'drag and drop your text', what is your text exactly? What kind of object?

#

I'm not sure. Definitely the UI text game object you're dragging in right?
You don't have any other namespace classes called Text?

wintry saffron
#

@still tendon scoretext.text = score.tostring();

tidal marlin
#

U sure that the object ur draggin has a "text" component attached to it

lilac briar
#

Hi ! I'm following inScope studios' tutorial on making connected tiles but when I create a Tile subclass and drag and drop an instance of it on a tile palette, Unity crashes. Did anyone have this problem ?

rigid crypt
#

Hey guys i have an issue. So i am trying to create a gun follow mouse mechanic in my 2D game and i am trying to clamp the rotation of the gun on either side of the player. So when the player is facing right (As can be seen in the video) the gun rotates normally, but when i turn left the gun just stops rotating. I have attached my script and a video for anyone to understand better.

https://paste.myst.rs/zlu

spring ledge
#

@rigid crypt Have you tried putting in a Debug.Log to check what Mathf.Atan2 actually returns.?

rigid crypt
#

Oh yea, wait lemme see

undone coral
#

Considering it completely stops functioning I'd guess the issue is in the if condition, issues in the math would most likely cause weird rotations and flipping, not freezing.

rigid crypt
#

So i did du bug it and Mathf.Atan2 does not return anything in the else if function

#

@spring ledge

#

@undone coral

spring ledge
#

What do you mean, does not return anything

rigid crypt
#

I did Debug.Log("Rotating"); at the end of the else if function and it did not say anything in the console

spring ledge
#

Sounds more like your else if isn't running

rigid crypt
#

Ye

spring ledge
#

You sure myPlayer.transform.localRotation.y is 180? And not global rotation?

rigid crypt
#

Yes i am

spring ledge
#

What does Debug.Log say it is

rigid crypt
#

because the moment i turn left then the gun stops rotating completely even if i turn back right @spring ledge

spring ledge
#

Might be not 0 but not 180 then

#

Ah

#

You're comparing degrees

rigid crypt
#

Yes

spring ledge
#

Or no

#

You're comparing quaternions xD

rigid crypt
#

degrees

spring ledge
#

try myPlayer.transform.localRotation.eulerAngles.y

#

Makes me wonder if theres a good way to check that without converting it to eulerAngles though

rigid crypt
#

Im trying it

#

Nope still dose not work, should i change it for condition, if an else if or only one?

spring ledge
#

Put a Debug.Log that outputs myPlayer.transform.localRotatio.eulerangles

rigid crypt
#

Im pretty begginer, how would i do that

#

Debug.Log("myPlayer.transform.localRotatio.eulerangles");

#

?

spring ledge
#

without the quotes

#

And proper writing/capitalisation

rigid crypt
#

ok

#

Lemme try

#

where would i put this tho

#

under the else if function

undone coral
#

I can't currently test this, but could you try just replacing the if statement with:

    Vector3 difference = Camera.main.ScreenToWorldPoint (Input.mousePosition) - transform.position;
    difference.Normalize ();

    float yRot = transform.localRotation.eulerAngles.y;
    float rotationZ = Mathf.Atan2 (difference.y, difference.x) * Mathf.Rad2Deg;
    rotationZ = Mathf.Clamp (rotationZ, -45 - (yRot * 0.5f), (45 + yRot));

    transform.rotation = Quaternion.Euler (yRot, yRot, rotationZ);
}```
And see what happens, it should just skip out the entire if, and adjust itself on your rotation.
spring ledge
#

Anywhere in your update as long as it isn't in the ifs

rigid crypt
#

let me try and get back to you

undone coral
#

Whups my bad, I might've messed up in the Clamp() there. I think it should be rotationZ = Mathf.Clamp (rotationZ, -45 - (yRot * 0.5f), (45 + yRot));
It's currently adding/subtracting 180 instead of 90.

rigid crypt
#

Ok so first @spring ledge i tried the debug and it returned the angles appropriately, i could send a video if you like

#

@undone coral yea, ill make your change, also i am getting an error at difference for some reason, Vector3 difference, but ill figuer it out

spring ledge
#

I mean, what does it say the angles is when you're turned left and waht does it say it is when you're right

rigid crypt
#

Give me a second im gonna send screen recording to both of you guys, so you can better understand whats happening @undone coral @spring ledge

#

@undone coral

#

There now i hope you guys can see whats happeing

spring ledge
#

Weird, not sure why the elseif wouldn't run then. If you still even have that now

rigid crypt
#

Yea, ive been trying at this for so long, but it just dosent seem to work

spring ledge
#

whats your code now

rigid crypt
#

@spring ledge

spring ledge
#

Wasn't it == 180 before

rigid crypt
#

No, but i dont think that will change anything ill try it tho

spring ledge
#

I mean

#

why wouldn't it

#

Your debug log says that y is 180, not -180

rigid crypt
#

Wait a second, im an idiot

#

Omg

#

but there is still some problems let me show you

#

@spring ledge

undone coral
#

@rigid crypt So, it took me way longer to do than I'd like to admit, but this works for me.

    Vector2 difference = new Vector2 (Input.mousePosition.x, Input.mousePosition.y) - (Vector2)Camera.main.WorldToScreenPoint (player.transform.position);
    difference.x *= player.transform.right.x;
    difference.Normalize ();

    float rotationZ = Mathf.Atan2 (difference.y, difference.x) * Mathf.Rad2Deg;
    rotationZ = Mathf.Clamp (rotationZ, -45, 45);

    float yRot = player.transform.localRotation.eulerAngles.y;
    gun.transform.localRotation = Quaternion.Euler (yRot, yRot, Mathf.Sign (yRot) * rotationZ);
}```Please let me know how this goes. Made two GameObject references (gun and player) and used those so you know what was refering to what, because I don't know how you have yours setup. Also I redid (copied from the interwebs) the difference calculation, because yours wasn't working for me for some reason.
rigid crypt
#

Omg thanks a lot @undone coral I actually am going to sleep now, but will try it first thing when i get up

undone coral
#

@still tendon Have the game over screen on a seperate Canvas / GameObject. Make sure that GameObject is not active at first, and set it active once the player touches the enemy.

    public static UIManager instance;
    [SerializeField] private GameObject gameOverCanvas;

    private void Awake () {
        instance = this;
    }

    public void ShowGameOver () {
        gameOverCanvas.SetActive (true);
    }
}```
```public class Enemy : MonoBehaviour {
    private void OnTriggerEnter (Collider other) {
        UIManager.instance.ShowGameOver ();
    }
}```
Work something like that into your own code and it should be fine. ๐Ÿ™‚
wanton sphinx
#

Hey guys I'm following a tutorial which uses raycasting instead of rigid bodies, how would I check to see when in the code I could double jump?

undone coral
#

I'd guess the tutorial already has something like this, but: If space is hit - check if you're not grounded (the downward rays don't hit anything) - jump again (add upwards velocity).
Add a boolean 'canDoubleJump', that turns false when you double jump, and true again when you hit the ground. To prevent endless jumping. :p

wanton sphinx
#

Ah thank you! I will try that

fair mist
#

How would I resize a gameobject without resizing the parents? I'm trying to use obj.transform.localscale = new Vector2 to make the red circle bigger but it also resizes the squares around it

abstract mural
#

make sure the script is on the object you want to change or if its on the parent for all of them then reference the gameobject then use localscale

#

it sounds like youre accidentally accessing the parents transform @fair mist

fair mist
#

@abstract mural Thank you!

abstract mural
#

no problem ๐Ÿ™‚

leaden hill
#

So, I have functioning colliders with a door object I'm creating, and my player also collides with enemies, but when I try to make a tilemap collider nothing lights up green with gizmos enabled unless I enable grid colliders for the sprites, which isn't ideal as they do not take up an entire cell.

#

The walls are slightly transparent, I tried taking away the transparency but it just makes them look terrible. Is Unity not able to auto generate a collision mesh for the 2D tiles because of the transparency messing with it?

#

Tried going in and manually generating each collider in the sprite editor and again, nothing lights up. Like it won't even recognize the sprites. I flipped the alpha button in the top right corner of the sprite editor and I can see everything in black and white, though. It generates colliders based on the alpha channel, right?

tidal shell
#

would anyone maybe happen to know how to make a trampoline work with unity bolt?

leaden hill
#

Not with Unity Bolt, no. It'd probably be trivial to do with script, though.

#

Also I'm stupid and realized I was using my tileset wrong anyways.

#

There were these gray areas and I'm sitting here like "Shouldn't those be transparent?" Nah, you're supposed to have an entire grid space dedicated to each wall.

#

Grid based collision will work fine.

tidal shell
#

ive tried it with script but i just could not get it to work, and since bolt is free now i thought id try that

#

also glad you figured it out!

leaden hill
#

Basically for script I'm thinking you have your normal Vector2 for movement

#

Then a separate Vector2 for velocity

#

This vector 2 is constantly modified by gravity

#

Collide with a trampoline

tidal shell
#

id previously used this script

#

paired w a tutorial

#

id tried to make it work several times but couldnt

leaden hill
#

I'd look up a tutorial for jumping in 2D

#

Except have it triggered by hitting a trampoline instead of hitting a keyboard button or gamepad button or whatever

#

I mean, you can have both

#

Just modify the trampoline code to be a more extreme jump

tidal shell
#

might try it later since my project has to be turned in today, was hoping to give it one more try with bolt since id spent days trying w normal scripting

#

but itd either give me errors or just not work

leaden hill
#

That's often how scripting goes until you get the hang of things

tidal shell
#

haha yeah i figured that out the hard way:'))

modest cradle
#

hello guys

#

i have a problem im using unity personal and my code has no problems in vs code but in unity i get alot of error even tho im making my first game using tutorial

#

can anyone help me

hasty sleet
#

Hey all! Working on an rpg with multiple enemies. I'm trying to figure out how to allow only one enemy to attack the player at a time.

violet sail
#

in my case , i will add all the enemies into a List , and have a bool to control all of them

hasty sleet
#

So how would I allow only one to move towards and attack the player

#

?

still tendon
#

Hey all! Working on an rpg with multiple enemies. I'm trying to figure out how to allow only one enemy to attack the player at a time.
@hasty sleet while (enemies.length() >= 0) { enemies[0].attackPlayer(); }

#

It's a hacky way to get you started. I'm not sure how you are going to make decisions such as "which enemey" does the attacking. you could check to see closest or the one with the least health.

#

I would consider looping through and measuring distance to player and firing the attack method on closest(smallest) distance.

hasty sleet
#

k, I think I managed a working solution but thanks!

grand cove
#

@modest cradle One thing you need to keep in consideration when you are switching to visual studio from VS Code is that VS code is literally just a text editor, it lacks a lot of features that VS has to offer, and some of these features are probably linking your scripts to unity, so make sure that VS is assigned as the editor for unity and so on for debugging. It really depends what the error is.

leaden hill
#

I tried to get VSCode working with Unity

#

You need to download some plugins to get intellisense and whatnot

#

And half the time it didn't even work, but I'm smooth brain

grand cove
#

I like VS code, but I'm used to VS, so I just work in that massive monolith instead.

#

I think you also need to make sure that the VS installation contains the unity bits and bobs

pastel chasm
rich drum
#

@pastel chasm Make sure that your project does not have any error in the debug logs.

humble tusk
#

Can anyone help

#

the bullet falls before i shoot

still tendon
abstract mural
#

@still tendon you have a rigidbody

#

lock the z rotation i believe in the rigidbody settings

fluid scarab
#

Yes Z.

still tendon
#

ahh, I knew that. I shouldve thought of that. Thank you

still tendon
still tendon
#

Or any ideas

rigid crypt
#

Just click on Project setting and see what happens @still tendon

still tendon
#

I figured it out, forgot I said anything in here about it. Thank you, I appreciate the help @rigid crypt

rigid crypt
#

np ๐Ÿ™‚

thick geyser
#

Iโ€™m having trouble with raycasts, for some reason the direction is always up, I have the vector set as my animator floats for the last direction faced.
But it will only work from below the object Iโ€™m trying to interact with, and will work from there no matter which way you are facing

#

here's my code(its uncommented im sorry lol)

#

most of this is temporary btw, the input will change, and I will expand on it. I just dont understand why the raycast wont go where I want it to

ruby karma
#

log those animator floats

thick geyser
#

log?

#

oh like debug.log?

plush coyote
#

don't really understand why you are raycasting twice

thick geyser
#

one to check if it hits, and one to set it as the interactable variable

plush coyote
#

just do if interactible.collider != null

#

I know why you are raycasting twice, I just meant that there is a better option

thick geyser
#

oh ok

#

huh thanks for that actually, I tried doing something similar but I did it wrong

#

its working correctly for the values

still tendon
#

dude are u professional?

thick geyser
#

no?

still tendon
#

im new to unity and programming

#

can u help?

thick geyser
#

what do you need help with exactly?

still tendon
#

idk

plush coyote
#

just say your question in the chat, thats what it is here for

#

if you dont know what you need help with, nobody can help you

still tendon
#

i'll tell you later i will add you friend

#

not rn

#

i need help later

plush coyote
#

then ask your question in the unity chat later...

thick geyser
#

well just ask in here later, Im not really that qualified lol