#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 526 of 1

solar torrent
#

i sent you something

rocky canyon
steep rose
rocky canyon
#

if it works I wouldn't worry so much about a better way to do it.. as
i would be about understanding exactly what you have so far..
you can refactor more when you learn more

#

i guess this is useful for looping thru vectors? lol cool, TIL

For Vector2:

  • vector[0] โ†’ vector.x
  • vector[1] โ†’ vector.y

For Vector3:

  • vector[0] โ†’ vector.x
  • vector[1] โ†’ vector.y
  • vector[2] โ†’ vector.z
burnt vapor
solar torrent
#

i cant send videos hee

#

herew

silk night
#

upload it

rocky canyon
solar torrent
#

ok gimme a sec

#

<div style="position:relative; width:100%; height:0px; padding-bottom:56.250%"><iframe allow="fullscreen" allowfullscreen height="100%" src="https://streamable.com/e/4lpgqs?" width="100%" style="border:none; width:100%; height:100%; position:absolute; left:0px; top:0px; overflow:hidden;"></iframe></div>

rocky canyon
solar torrent
#

mb

rocky canyon
#

close enough ๐Ÿ‘

#

now can you share the original question? or a link to it

solar torrent
#

๐Ÿซท olk I will

#

do you see like idk whats wrong it works until i does not

rocky canyon
#

its soemthing to do w/ the UnitySelectionManager and the units in that collection

#

can you share the UnitySelectionManager script?

solar torrent
pine jackal
#

wait, 2021 was fine?

rich adder
pine jackal
#

Aha sorry, I think u r taling about seamless audio.

polar acorn
rocky canyon
# solar torrent https://hatebin.com/ogmntahjtw
private void TriggerSelectionIndicator(GameObject unit, bool isVisible)
{
    Debug.Log($"Unit: {unit.name}, Child Count: {unit.transform.childCount}");

    if (unit.transform.childCount > 0)
    {
        GameObject child = unit.transform.GetChild(0).gameObject;
        child.SetActive(isVisible);
    }
    else
    {
        Debug.LogWarning($"Unit {unit.name} has no children.");
    }
}```
#

i think you should probably check if thers a child first before manipulating..

#

from the video tho it appears all ur selectable units have a selection image.. (as a child) soo idk it seems like maybe its adding stuff that isnt?

#

id open the UnitSelectionManager component and keep an eye on that list and make sure its working how u expect

eternal stag
#

how do i enable code recommendations for unity programming?

silk night
#

!ide

eternal falconBOT
eternal stag
#

thanks

pine jackal
# rich adder huh?

Unity web build has issue for looping sound. it make pop or void sound every loop

rocky canyon
#

https://www.youtube.com/watch?v=vAVi04mzeKk&ab_channel=SpawnCampGames

i have a tutorial on a top-down selection system.. maybe it might help to check my code and compare it to the one ur using.. (iirc i don't remember having that issue)..

i think the main difference I see is I don't add or remove units from the list from outside that class.. I tell the UnitSelectionManager which Unit it is.. and then it removes itself from the list..

solar torrent
rocky canyon
#

that way its not trying to remove it more than once.. or trying to access something that isnt there

rocky canyon
rich adder
rocky canyon
#

sometimes pops arent easy to notice.. could be just teh very last sliver of the audio file..

#

if u have some sort of audio editing tool you can shorten it or clip the end/beginning and see if the pop goes away.. or test w/ another clip

burnt vapor
# solar torrent

Ok but I asked for both the exception and the last log message

#

Remember I asked you to log the gameobject and the childcount until the exception is thrown

#

At this point it's just all assumptions until you start debugging

#

And now people like @rocky canyon will suggest the exact same thing because conversations have 40 minute intervals, after which we just start over again

#

So please pay attention and give us results if you want this to be fixed

real forum
rocky canyon
#

well, enjoy the delay.. he'll be back later ๐Ÿ˜„

burnt vapor
rocky canyon
pine jackal
rich adder
#

its probably not the editor then, I use webgl without issue

pine jackal
pine jackal
#

on editor everything is ok

rich adder
#

firefox

pine jackal
#

only webgl build has issue

#

Can you share import setting of audio?

#

And how did u loop? just set loop = true?

rich adder
#

they're the default ones , I havent touched them usually

pine jackal
#

did u test on chrome?

rich adder
rich adder
pine jackal
rich adder
#

did YOU try a different browser
and where did you host it? which settings you exported with ? etc..

pine jackal
#

like this?

pine jackal
rich adder
pine jackal
pine jackal
rich adder
#

thats not what I meant, inside of unity and the export page of webgl

round tulip
#
public void Build()
{
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    Vector3 targetPosition = ray.origin + ray.direction * range;

    Collider buildingCollider = currentBuilding.GetComponent<Collider>();
    if (buildingCollider != null)
    {
        buildingCollider.isTrigger = true;
    }

    Renderer buildingRenderer = currentBuilding.GetComponent<Renderer>();
    Vector3 boxSize = buildingRenderer.bounds.size / 2;
    Vector3 boxCenter = targetPosition;
    Quaternion boxRotation = currentBuilding.transform.rotation;

    Collider[] hitColliders = Physics.OverlapBox(boxCenter, boxSize, boxRotation);
    bool canPlace = true;

    foreach (Collider hit in hitColliders)
    {
        if (hit.gameObject != currentBuilding)
        {
            canPlace = false;
            break;
        }
    }

    currentBuilding.transform.position = targetPosition;

    Renderer renderer = currentBuilding.GetComponent<Renderer>();
    if (canPlace)
    {
        renderer.material.color = Color.green;
    }
    else
    {
        renderer.material.color = Color.red;
    }

    if (isBuilding && canPlace && Input.GetMouseButtonDown(0))
    {
        isBuilding = false;
        currentBuilding = null;

        if (buildingCollider != null)
        {
            buildingCollider.isTrigger = false;
        }
    }
    else if (!canPlace && Input.GetMouseButtonDown(0))
    {
        Debug.Log("Cannot place the building here!");
    }
}

So when the building is a floor it should snap to other floor. but not when the player is looking at a floor. How can I manage to do that?

pine jackal
#

Is there any option for it?

#

And this is my import setting

rich adder
#

did you test blank project? different settings? different browser etc. You have to do more testing to isolate the problem. Also send a link of your webgl maybe its just your end

pine jackal
#

by the way which version of unity are u using?

rich adder
pine jackal
#

same to me

#

I used this before

pine jackal
rich adder
#

I don't have a specific pipeline , I use all 3

#

multiple projects lol

pine jackal
#

oh

#

then i'll try to SRP for isolate testing

#

ah before it

#

i want to share my issue video

#

I just tought it was ok but later found issue

#

here is my video

#

you can check it have something pop sound

#

or something void(empty) sound

#

this was not happen on ur?

rich adder
#

okay but you should not be crossposting

#

and this is like 99% not a code question

onyx tusk
#

can i somehow set only 1 coordinate in vector3 without creating new? if no, just say no

pine jackal
#

web, audio

rich adder
languid spire
pine jackal
#

also firebox has same issue

onyx tusk
#

ok, thx

solar torrent
#

whos back

#

the one and only

#

erm what the sigma

solar torrent
devout flume
# solar torrent Sigmas Back

I suggest you to start a thread about your issue next time, whenever your problem takes time to be solved, or whenever you know you'll need to do other things that will make you unable to check this channel

solar torrent
#

Ok mr how do i aquire a thread

devout flume
#

Issue

#

Here ^

solar torrent
solar torrent
naive pawn
solar torrent
#

bett let me cook

solar torrent
onyx tusk
#

y i don't see cursor in input field?

polar acorn
solar torrent
#

home boy

#

i but the

#

debug in

#

and it still did not say anything

polar acorn
#

Show a screenshot of your full console, including the buttons for hiding message types

sterile radish
#

hi, im making a top down rpg game similar to that of undertale. what is an efficient/effective way to manage/save/set a lot of bools to check if the player did some sort of action and change character dialogue according to the value of those bools? (i.e, a player chose to insult a character, next time they open the game the character is still bitter about them being insulted)

polar acorn
solar torrent
#

there unc

polar acorn
#

Eyyyy 0

#

Like what I said earlier

solar torrent
#

๐Ÿ’โ€โ™‚๏ธ tamam ehehe samanana eh eh

sterile radish
onyx tusk
solar torrent
#

๐Ÿคฉ

polar acorn
onyx tusk
solar torrent
polar acorn
solar torrent
sterile radish
onyx tusk
solar torrent
#

i dont wait if daddy aint comeing home you know

frosty hound
#

@solar torrent Can you settle down. Stop pestering people.

solar torrent
#

huh sorry sir i wont do the pestering

#

just waiting ๐Ÿ’โ€โ™‚๏ธ

hexed terrace
#

you're not waiting, waiting does not include sending lots of messages ๐Ÿ˜„

solar torrent
#

sir yes sir

#

๐Ÿซก

onyx tusk
solar torrent
onyx tusk
solar torrent
#

like my puny knowlodge does not make me edgeable for this

sterile radish
onyx tusk
sterile radish
onyx tusk
solar torrent
compact token
#

hello guys i have a question, how to save that ?

#

i dont know why but i cant use zqsd

solar torrent
#

idk go to adavanced

hexed terrace
compact token
#

ah sorry

#

thank you at least

frosty hound
#

@solar torrent This is your last warning before you're muted, to stop being annoying. Also, if you're going to continually spam this channel with noise, make a thread instead.

solar torrent
#

bro i made a thread

frosty hound
#

Use it, then.

solar torrent
#

no one saying anything on it though

onyx tusk
solar torrent
solar torrent
#

๐Ÿ’โ€โ™‚๏ธ

onyx tusk
solar torrent
#

hell yea

frosty hound
#

!mute 793466504309768195 1d You can come back tomorrow. Be less noisy, actually help people help you with explaining things, and stop expecting people to hold your hand with your issue.

eternal falconBOT
#

dynoSuccess noobie_q was muted.

bright siren
#

Sorry this is bit VS focused, but I can not see how to turn off the 'fade' effect when code is unused because its really annoying actually and I only remember the 3 dots effect. If i am in the middle of writing a class there may be unused functions - I do nto need the text to be faded!

dense root
#

Hi everyone I am trying to set a simple navigation to the sphere as shown in the screenshot, however I am getting a SetDestination" can only be called on an active agent that has been placed on a NavMesh. error despite my best attempts to adjust the sphere. Thoughts?

wintry quarry
dense root
#

I readjusted the nav mesh, but no dice

rich adder
dense root
#

Is that what you are referring to?

rich adder
#

this feller

rich adder
dense root
dry jungle
#

Hi

rich adder
# dense root

navmesh agent component is on this sphere ? whats the scale of the sphere

dense root
#

.5 .5 .5

rich adder
dense root
#

Radius 0.5
Height 1
Step Height 0.4

rich adder
#

nah the one on the sphere

#

show the entire component

rich adder
dense root
#

Are you referring to this Navigation panel?

bright siren
rich adder
dense root
#

Oh I see

rich adder
#

this is what traverses the mesh

dense root
#

Here's the navmesh Agent for the enemy

#

There's no navmesh Agent for the destination, is that the problem?

rich adder
#

and no the destination does not need an agent ofc, its not a moving agent lol

dense root
rich adder
#

put the enemy closer to the ramp

dense root
rich adder
#

you should probably use navmesh surfaces btw, this way of baking is deprecated

dense root
#

Oh I see

rich adder
#

wait you're not even on Unity lts lol

#

2022.1 ?

dense root
#

Yes lol

rich adder
#

oh my

#

no wonder the bake tab didn't say deprecated

dense root
#

Hmm, I'll re-review the video I'm following and see if I missed a step. For future projects I'll use navmesh surfaces

rich adder
#

yeah they're much better because you dont have to painfully go through each gameobject to mark as navigation object and all that

dense root
#

Ahh makes sense, thank you for the guidance

hexed terrace
rich adder
#

is it working now btw @dense root

errant pilot
#

Guys how can i make an image grey then make the grey go away from top to bottom in x seconds?

rich adder
#

or do you mean UI image

#

that would be easier

magic panther
#

I'm trying to get the player to read a float from an xml file. This system works, but only for non-float falues, as of right now. What can I do to get this working, without changing the xml file?

Player class --> https://hastebin.com/share/wafonifule.csharp
Defaults (DefaultJrlGameObject class) --> https://hastebin.com/share/amomadeniz.csharp

MovementVariants.xml

<MovementVariants>
    <HorizontalMoveAccel>0.2</HorizontalMoveAccel>
    <WalkSpeed>5</WalkSpeed>
</MovementVariants>

Error: FormatException: Input string was not in a correct format.

dense root
errant pilot
rich adder
dense root
#

kk

rich adder
# errant pilot yes please

just put another gray image over it then scale it the direction you want, should be easy once you set pivot to top edge

dense root
#

Weird I'm getting the same error

rich adder
#

restart the editor?

dense root
#

I clicked reimport all and it restarted it, I can try again

rich adder
#

another reason you should probably be using lts

dense root
#

Yeah, I think I'll upgrade the project and spend some more time with it after a break. Thank you so much

rich adder
# errant pilot yes please

btw if you have a blank square you can set the image mode to filled and you can just use the slider so you dont have to worry about scaling anything or changing pivots

errant pilot
rich adder
errant pilot
#

Oh that simple? Okok ty

kindred spade
#

hey there! i'm here to ask for help again so i wrote some code to spawn pipes in a flappy bird project for my first project which worked before dinner but then i came back after and now suddenly it won't run anymore and i get a ton of errors. for exmaple the gameobject.findgameobject which worked fine before doesn't work now

#

does anyone have a idea what i did wrong for all this stuff to stop working? i get the same error for the Time.deltatime, instantie, vector3, transform, random and a vew more

rich adder
#

always start at the very top

#

look carefully

kindred spade
#

oh lord

#

i see it now...

#

it was the using+! thank you so much!

#

i've spend the last 20 minutes looking at it and not getting what was wrong while it was the top row all along

rich adder
kindred spade
#

aha

#

i will go continue now thank you again i was so confused

mystic robin
#

Haha I've done that couple times hit a button on side of my mouse when i go back to desk and puts a character into script ><

fading thunder
#

Hi! I'm following tutorials and using many other resources to mane a "first draft" while learning. Trying to make a 2d side scroller character jump, but it doesn't seem to want to do that no matter what I do...

Here's the code that I've got so far:

using UnityEngine;
using UnityEngine.Assertions.Must;

public class playerMovementNew : MonoBehaviour
{
    public float moveSpeed = 10f;
    public float jumpForce = 5f;

    public Rigidbody2D rb;
    public SpriteRenderer SpriteRenderer;
    public Vector2 movement;

    private void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

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

        if (Input.GetButtonDown("Jump"))
        {
            Debug.Log("Jump button pressed.");
            rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
        }
    }
    private void FixedUpdate()
    {
        rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
        // ^Makes player actually move based on input. 
        if (Input.GetAxisRaw("Horizontal") < 0)
        {
            SpriteRenderer.flipX = true;
        }
        else if (Input.GetAxisRaw("Horizontal") > 0) {
            {
                SpriteRenderer.flipX = false;
            }
        }
        //^Makes the sprite flip directionally

    }
}

Any idea what's wrong here? I press space and the debug says I did, but the character doesn't go up.

naive pawn
#

did you set the jump force in the inspector to something else?

fading thunder
rich adder
#

ur overriding position with Rb.MovePosition

#

AddForce works on forces

naive pawn
#

(sidenote, comments that annotate code usually go before the relevant code, so you get an explanation before having to read the code)

fading thunder
naive pawn
#

you could replace MovePosition with setting the x velocity

#
Vector2 vel = rb.velocity;
vel.x = /* intended x velocity (NOT proportional to deltaTime, since velocity is already per unit time) */;
rb.velocity = vel;
#

so the velocity would bemovement.x * moveSpeed

#

(if it's a sidescroller, not sure what you'd need a vertical axis control for)

fading thunder
naive pawn
#

i'd recommend you stick to a single, reputable guide, since different people have different styles and it's likely you'll encounter slightly different ways of doing stuff in different tutorials

#

!learn

eternal falconBOT
#

:teacher: Unity Learn โ†—

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

formal hill
#
using UnityEngine;

public class Movement : MonoBehaviour
{
    public float speed = 5f;
    public Rigidbody2D rb;
    public Camera cam;
    public Animator robotAnimator;

    private Vector2 movement;
    private Vector2 mousePos;
    private bool isMoving;
    private bool isSprinting;

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

        mousePos = cam.ScreenToWorldPoint(Input.mousePosition);

        isMoving = Mathf.Abs(movement.x) > 0 || Mathf.Abs(movement.y) > 0;
        isSprinting = Input.GetKey(KeyCode.LeftShift);

        AnimationStuff();
    }

    void AnimationStuff()
    {
        if (isMoving)
        {
            if (isSprinting)
                robotAnimator.Play("Run");
            else
                robotAnimator.Play("Walk");
        }
        else
        {
            robotAnimator.Play("Idle");
        }
    }

    private void FixedUpdate()
    {
        Vector2 newPosition = rb.position + movement * speed * Time.fixedDeltaTime;
        rb.MovePosition(newPosition);

        Vector2 lookDir = mousePos - rb.position;
        float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
        rb.rotation = angle;
    }
}
``` Does anyone know why the animations aren't playing/Why the "isMoving" bool doesn't detect movement. (Please don't be mean I'm a beginner)
naive pawn
#

try debugging some values. is movement being set? is isMoving being set?

formal hill
naive pawn
#

being assigned to correctly

formal hill
#

And how exactly would I check that with the debug.log?

naive pawn
#

you log the value out

#

and you see if the result is what you expect

#

just, Debug.Log(movement);, same for other variables

languid spire
#

And the reason your animations aren't playing is because you are starting them every frame

languid spire
#

stop doing it

formal hill
formal hill
languid spire
#

it's not about not making them start, you are already doing that, it's about not doing it too often so apply some logic

formal hill
languid spire
#

maybe restrict calling AnimationStuff unless certain conditions are met?

formal hill
placid oxide
#

made a script that has 4 drop zones and 1 general card to drop onto. Worked perfectly fine until I wanted to make the card bigger once dropped (changing the size to droppedSize). Problem is line 50 makes the card go back to the place where the card is picked from (startPosition). Chat gpt didn't really help

using UnityEngine;
using System.Collections;

public class DragDrop : MonoBehaviour
{
    private bool isDragging = false;
    private GameObject currentDropZone;
    private Vector2 startPosition;
    public Vector2 droppedSize = new Vector2(335, 522);

    void Update()
    {
        if (isDragging)
        {
          transform.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
        }
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {

        if (collision.gameObject.CompareTag("DropZone"))
        {
            currentDropZone = collision.gameObject;          
        }
    }

    private void OnCollisionExit2D(Collision2D collision)
    {
        if (collision.gameObject == currentDropZone)
        {
            currentDropZone = null;
        }
    }

    public void StartDragging()
    {
        startPosition = transform.position;
        isDragging = true;
    }

    public void EndDragging()
    {
        isDragging = false;

        if (currentDropZone != null)
        {
            transform.position = currentDropZone.transform.position;  
            RectTransform rectTransform = GetComponent<RectTransform>(); 
            rectTransform.sizeDelta = droppedSize;                //problem is here  
        }
        else
        {  
            transform.position = startPosition;         
        }
    }

}
rocky canyon
placid oxide
#

but it's the endragging event, should't it run only when I drop the card?

placid oxide
#

but it's the thing I want, to resize the card once dropped

rocky canyon
#

does that line cause any errors in the console or is this just a
"working, but not desired outcome" type of problem?

placid oxide
#

not even working, it doesn't even resize the card, it just make it go back to the default position

rocky canyon
#

that might be the root cause of ur issue

#
if (currentDropZone != null)
{   //grab components
    RectTransform rectTransform = GetComponent<RectTransform>();
    RectTransform dropZoneRect = currentDropZone.GetComponent<RectTransform>();

    // set position to match dropzone position
    rectTransform.anchoredPosition = dropZoneRect.anchoredPosition;

    //optional assignments
    rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
    rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
    rectTransform.pivot = new Vector2(0.5f, 0.5f);

    // set size
    rectTransform.sizeDelta = droppedSize;
}```
#

screen space coordinate system vs world space coordinate system

#

that said and all.. But chosing to use UI for a 2D type of game probably isn't your best choice.. (not sure how much you've already built)
but Unity UI usually isn't the most performant.. and is meant to be used more so to display stuff(info) to you..

as for interacting w/ the objects I'd probably chose to use 2D Sprites.. those will exist in world-space and will be much easier to drag, drop, and interact with..

#

even if they're "text heavy" you could pair 2d sprites w/ textmeshpro world text objects

#

either way.. the .rectTransform.anchoredPosition is the bit that will fix what you already have..

#

if u go w/ 2d sprites instead you can resort back to the basic transform.position = thatPosition; type positioning

placid oxide
#

it doesnt )))

#

now it doesnt stick at all

rocky canyon
# placid oxide it doesnt )))

it does work.. maybe not w/ your setup for some reason

    public void TopLeft()
    {
        thisRect.anchoredPosition = topLeft.anchoredPosition;
    }``` etc, same for each of the test methods i call in the clip
for yours, not sure, I'd probably suggest:
make sure your components are assigned.. (like the recttransform you grab w/ your getcomponent methods)
can debug them afterwards to see that they're assigned ` Debug.Log(rectTransform.name);`
make sure you're setting its `anchoredPosition` debug it afterwards see if it has a value that makes sense `Debug.Log(rectTransform.anchoredPosition);`

put some debugs in  ur if statements make sure they're being called like you expect
`Debug.Log("If statement is true, doing this"):`, same w/ else, or false, or w/e
nothing more comes to mind besides something i'm just not seeing.. or some error you haven't revealed yet
#

the logs and stuff should tell you whether its an issue w/ ur logic flow
or its a problem w/ assigning the wrong values or variables

placid oxide
#

With the line removed works just fine, now i get that adaptive performance thing after I used ur code and removed it

#

the one with the rigidbody is the card

rich adder
placid oxide
#

I used a tutorial for the base of the game

rich adder
#

I mean that doesn't mean its correct

placid oxide
#

I know but i dont want to take the just redo the game in another style way yet since not much is left to do

rich adder
#

another style?

placid oxide
#

Not using only canvas

rich adder
#

if you plan on using colliders/physics then you'd switch it to using sprites,
if you use canvas then you have to use the event system instead with all the functions that come with

#

the canvas and the physics objects are not even in the same space

obtuse quarry
#

I need help with my pathfinding algorithm, I'll record a little clip to show whats wrong but essentially i can only pathfind around certain like... obstacles

#

its a little hard to explain but i was working on it for multiple hours yesterday and im launching the project rn

placid oxide
#

well, nvm, chat gpt made it work somehow, thanks for help @rich adder @rocky canyon

acoustic belfry
#

Hi, i been thinking, how i can make the sprite of the character of a 2D game flip depending on where the mouse is?

obtuse quarry
#

my pathfinder gets stuck here

#

tho it can pathfind around other structures of blocked cells

acoustic belfry
obtuse quarry
#

there are some cases where it cant pathfind around certain cells

#

it perfectly pathfinds around this structure of blocked cells

#

its an image so you cant actually see it get to the destination, but it does

#

and it gets to the destination no matter where it starts with this structure and many others

#

there are just edge cases where it cannot

#

i know the code is definitely terrible, this is just a prototype keep that in mind

rocky canyon
stable quail
rocky canyon
#

theres usually two options..
"scale the object negatively (this works out well most times b/c the axis will flip w/ it"
or you can flip the sprite FlipX (this means you need two states of movement.. when lookin left, if lookin right

acoustic belfry
rocky canyon
acoustic belfry
#

I use it for flip it

#

Bad idea?

rocky canyon
#

nah, its a completely acceptable option..

obtuse quarry
#

are you trying to detect which side of the player the mouse is or something?

acoustic belfry
#

Yep

rocky canyon
#

but note that the axis will not flip around.. (ur transform.right) (y axis in 2d) will always point right..

#

if u scale the object negatively.. then the axis will flip so looking right will have the axis pointing right.
and looking left will have it left

obtuse quarry
#

if its just for the appearance flipping the sprite should be fine

rocky canyon
acoustic belfry
#

How?

obtuse quarry
#

i must suck at programming

acoustic belfry
#

Me too

#

;-;

rocky canyon
#

positive value would be on the right side.. and negative value would mean its on the left

obtuse quarry
#

i know what it does ive jst never used it in this application

polar acorn
# acoustic belfry How?

Dot Product can be thought of as a "Sameness" value of two direction vectors. If it's 1, then both vectors are pointing in the same direction. -1 is opposite, 0 is perpendicular.

acoustic belfry
#

Ok. But i mean, now i can detect the left and side of the mouse...but how i can detect the mouse itself?

obtuse quarry
#

like its position?

acoustic belfry
#

Yep

rocky canyon
obtuse quarry
#

Camera.ScreenToWorldPoint(Input.mousePosition) i think

#

or something like that

#

to get its world pos

polar acorn
acoustic belfry
#

So how the script would look like?

obtuse quarry
#

itd be like this i think

Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mousePos.z = 0;

to get the world position of the mouse

polar acorn
#

Although if it's 2D, ScreenToWorldPoint should be fine

#

You only really need to worry about the ray for a perspective camera

#

If you just need left/right and don't care about any other directions, you can just check if that result is less than or greater than the player's X position

obtuse quarry
#

yeh

#

@acoustic belfry ^^^ if you havent seen it already

sand otter
#

(URP) I'm trying to add a flashing to my game, but it doesn't go nearly far enough to see what's in front of you. Turning up the intensity of the flashlight makes it still not go far enough, and flash the player when looking at something too close. I can't seem to find a way to make the flashlight see further and also be darker up close. Is there a fix to this? (first image intensity 3, second image intensity 30)

obtuse quarry
#

algud

#

a build of my pathfinder if anyone wanted to test it, it works sometimes around obstacles

#

The red cell is the pathfinder, the green cell is the destination

Press Tab to show the neighbours around the pathfinder in blue
Press Space to pause and unpause
Left Click to make any cell an obstacle
Right Click to make any obstacle a regular cell

teal viper
steep rose
sand otter
teal viper
# sand otter im using a spot light

Technically, this is how a spot light would work in real life. Since PBR rendering tries to mimic real life behaviour, this is how it looks by default. How exactly do you want it to look?

sand otter
# teal viper Technically, this is how a spot light would work in real life. Since PBR renderi...

I'm trying to go for a flashlight that is far reaching, but not super bright up close. I want to be able to see where I am going in my map, but currently the light is too bright for that. My game is a speed parkour game and running into walls is pretty annoying. I originally had the whole map have a light cast on it so you could see, but it looked terrible. I'm making a flashlight mostly for ambience. End goal is just to tone down the light up close.

teal viper
sand otter
obtuse quarry
#

do i need to put -1 after .Count in a list?

#

like
if (list.Count - 1 < value)

#

or does this work fine
if (list.Count < value)

arctic ibex
#

is there a version of Mathf.Clamp for Vecotr 2?

#

I know theres ClampMagnitude but that only does a maximum, not a mimimum

#

cause i have a vector that i dont want to go below zero, do i have to just Mathf.Clamp X an Y seperatly?

obtuse quarry
#

i think you have to do it seperately

arctic ibex
#

damn

#

well thanks anyway :)

nocturne parcel
obtuse quarry
#

for enemy ai, would a breadcrumb solution suffice? like the player drops a "breadcrumb" every certain interval and if the enemy has los of a breadcrumb it moves towards that breadcrumb

steep rose
#

sure if you want it to follow the last players position, I would just use the conventional A* for AI enemies though

obtuse quarry
#

i thought a breadcrumb solution would be good because

i dont want the enemy to always know where the player is after seeing it, with breadcrumbs if the enemy loses los of the player it can just move to whatever breadcrumb is in los and if it can see the player when it gets to that breadcrumb then great else it can be idle

#

ive tried A*

#

its nice but not what i need

slender nymph
#

a* and this breadcrumb idea are not mutually exclusive. I do this in one of my projects and use navmesh (which uses a*) to move the enemy

obtuse quarry
#

does navmesh work in 2d?

steep rose
#

no

#

A* can be used in 2D though as it is only an algorithm

obtuse quarry
#

oh

slender nymph
obtuse quarry
#

ill check these options out

#

ill go through them and see which one is good for me

#

A* probably will be better, in the past it just didnt really work out

steep rose
#

A* is probably the best pathfinding algorithm unless you need hundreds of objects pathfinding to a certain position, if that's the case use flow fields

sonic pond
#

(i didnt finish the tutorial yet but it works in the video so i just wanna fix it)

eternal needle
eternal falconBOT
sonic pond
#

and it actually works

#

(yes the script was saved when i was getting errors)

#

(and i didnt change the scripts)

errant pilot
#

guys is it possible to check if an animator has a specific boolean?

cerulean imp
#

Could I get some help regarding raycasts in 2D please?

I am having trouble getting the raycast to detect my player and return a RaycastHit2D. I have given the required parameters as seen below.

RaycastHit2D los = Physics2D.Raycast(m_mob.transform.position, (collider.transform.position - m_mob.transform.position).normalized, m_visionRadius, m_targetLayers);
Debug.DrawRay(m_mob.transform.position, (collider.transform.position - m_mob.transform.position).normalized, Color.red, 0.1f);

I also drew rays to make sure it is actually looking at all colliders within the specified radius that belong to the Player layer as seen here

Collider2D[] targetColliders = Physics2D.OverlapCircleAll(m_mob.transform.position, m_visionRadius, m_targetLayers);

So far the colliders and debug rays are correct, they point at every collider belonging to the Player layer, however, the raycast isnt working as expected.

I have provided it the correct vector values since the debug ray works fine and takes in the same values, however it doesn't seem to return anything from the method, its always null.

It uses the same values as my OverlapCircleAll arguments but it doesn't return anything despite being in direct line of sight.

  • I have read the docs many times over and I don't know what I'm doing wrong.
  • Also, how do I specify a layer with colliders the block line of sight in addition to the layer I wish to detect the collider using the raycast from?
gloomy cloak
#

Hi I just started using unity and for some reason I am having trouble making my character jump
But when I put the jumping script on a cube it jumps so I'm a bit confused why it doesn't work on my model..

keen dew
cerulean imp
ivory bobcat
cerulean imp
ivory bobcat
#

Show the data. You may be looking at the wrong thing.

sonic pond
#

how do i fix this error?

languid spire
#

Spot the difference

sonic pond
#

i dont understand

languid spire
#

which variable do you want to pass to the method?

sonic pond
#

nevermind i fixed the error

languid spire
#

yes, sentence is not the same as Sentence. Case matters in C#

obtuse quarry
languid spire
obtuse quarry
#

oh dam

#

i thought it was like... a global thing

#

where case always matters

languid spire
#

there are probably many, many languages you have never even heard of

obtuse quarry
#

definitely

obtuse quarry
#

Whats the difference between Vector3.Distance and calculating manhatten distance?

whole sequoia
#

can someone help me out with this movement script i made i would like the movement to be a bit smoother

ivory bobcat
#

I'm assuming you'd want velocity to gradually increase towards the target instead of becoming the value immediately

whole sequoia
#

i would like to jump while i m running

obtuse quarry
#

the way your coding your movement doesnt allow for that

whole sequoia
#

oh

ivory bobcat
obtuse quarry
#

youd have to refactor that bit of movement code

whole sequoia
#

ok

obtuse quarry
#

i think you need like a movedirection vector3 or something, im not good at 3d but i just know that movement code doesnt allow for jumping and running simultaneously

cinder void
#

Hi, i'm new to unity and i saw a tutorial on how to do better jumping and i want to integrate it to my project, any ideas on how to implement it for the "newer Input System" (the one that gives you OnJump(), OnRun(), etc) ? Thanks in advance

obtuse quarry
#

possibly? again im not a 3d coder so im not sure what the right way would be

whole sequoia
#

ok thnk u tho

somber beacon
#

do anyone know where can I look for documentation on how to do a 2D grid pathfinding system in a 3D world, in which entities don't get inside other entities?

timber tide
#

rigidbody, you could also just use a character controller and emit a light force around each unit so they don't occupy each other

runic lance
ivory bobcat
# whole sequoia can someone help me out with this movement script i made i would like the moveme...
Vector3 velocity = rb.linearVelocity;
if (...)
    velocity += forward; 
if (...)
    velocity += backwards;
if (...)
    velocity += right; 
if (...)
    velocity += left; 
velocity.x = Mathf.Clamp(velocity.x, min, max);
rb.linearVelocity = velocity;
if (canJump)
    rb.AddForce(jump, ForceMode.Impulse);```Where you'd substitute the variables above with their respected values. Consider multiplying directionally increments by delta time (jump should not be multiplied by time).
whole sequoia
#

ok thank you

somber beacon
steep rose
runic lance
steep rose
ivory bobcat
steep rose
#

yeah it does look a little more confusing to beginners but it is always good to teach them new things

#

also you could substitute the old input system for the new one, I just do not know how to use the new one ๐Ÿ˜…

obtuse quarry
#

in pathfinding should i use manhattan distance or regular Vector3.Distance?

steep rose
#

Manhattan (as it works for grids) if you are using A*

obtuse quarry
#

i searched it up and apparently manhattan distance isnt good for diagonal movement

#

and stuff

steep rose
#

huh?

#

why would it be bad for diagonal movement

#

it just makes the distance between the current node and the top/down , right/left/down/up movments a distance of 2

obtuse quarry
#

oh

#

okay ill try it

steep rose
#

now if you want the distance to be 1.4 for diagonal movement just use the โˆš2

#

which is somewhere around 1.4

obtuse quarry
#

would that benefit?

steep rose
#

I've never tried it

#

but I'm guessing it will be roughly the same, you can google the differences if you would like

obtuse quarry
#

i cant get past this

#

and obstacles placed like it

#

but most other setups work fine

steep rose
#

are all of the Fcosts correct? are you checking all of the neighbors around the current node?

obtuse quarry
#

yea, im moving to the neighbor whos fcost is the least

#

fcost = gcost + hcost

steep rose
#

are you ignoring the current node?

obtuse quarry
#

yeah, you cant see it because its an image but the pathfinder just continuously moves between 2 nodes

steep rose
#

so it does pathfind?

obtuse quarry
#

to something

#

just not to the right place

#

and it works fine with no obstacles and when obstacles are placed in certain ways

#

i can see which cells have the lowest fcost, the cell i have selected apparently has the least fcost

#

and now this cell i have selected has the lowest fcost

#

and the pathfinder continuously moves between these cells

steep rose
#

are you checking end to start or start to end

obtuse quarry
#

what?

steep rose
#

the current node on start of the project should be the starting node I believe

obtuse quarry
#

yep

steep rose
#

then you pathfind to the end node, then retrace steps (to get the path)

obtuse quarry
#

oh im not doing it that way

#

even ill admit i have no idea what im doing imo

#

what ive done has gotten me this far

somber beacon
obtuse quarry
#

basically i just move to whichever neighboring cell has the least fcost

somber beacon
#

and on every step you will change the grid position you are in as an obstacle, and when that agent gets out of it, you make it available again

steep rose
#

I'm guessing you are which is good

obtuse quarry
#

yeah, the list of neighboring cells i get doesnt include obstacle cells

steep rose
#

Sebastian league has some good stuff on A* pathfinding, some good information that you can use

obtuse quarry
#

it only includes valid cells

obtuse quarry
#

i watched his introduction video

#

in theory i think the way im doing it should be working

#

idk why it isnt

obtuse quarry
#

god its 2am and ive been working on this for 2 days

#

๐Ÿ˜ญ

#

this isnt worth it im going to sleep

#

fr im bad at coding ๐Ÿ˜ญ

steep rose
#

coding requires good rest, I would suggest looking at the algorithm in depth to see what you need and what you do not need, you can also look at articles and examples on it as well (which I would recommend)

graceful fractal
#

I'm swapping back from Rider to Visual Studio code since I might not get another Rider License for next year.

With that being said, I need to reinstall Visual Studio's extensions, and as such, which extensions in Visual Studio code is recommended for a game developer?

keen dew
graceful fractal
keen dew
#

Follow the instructions on that link

jaunty bay
#

does anyone know what stuff do i need to do to make a boomerang?

#

i can picture what i want, but i dont know how to name stuff so idk how to look for it in the internet

timber tide
#

If we're talking like 2D zelda boomerang you're just moving a transform and giving it some collider

cosmic dagger
#

creating a mechanic or system is all about logic (coding in general). once you know/understand the logic, you substitute the logic with its programming counterpart . . .

timber tide
#

If you want curving, you can create a path using AnimationCurve but I'm pretty sure Zelda was just a straight forward throw and return

#

3D versions had more realism to them

naive pawn
#

if it's like a terraria boomerang make sure it's going towards the player instead of the starting position after the apex

#

you could also use acceleration instead of a distance check

queen adder
#

Does anyone know how to get a random entery form a dictionary? To be more specific this my Code ```cs
public Dictionary<Vector2,TileScript> SpawnTilesDic;

public void AddEntery() {
SpawnTilesDic[new Vector2(x, y)] = currentTile;

}

public void ReadEntery/SpawnBox() {

    TileScript spawnTile = SpawnTilesDic.Random(); //Does not work 

}
naive pawn
#

have you tried googling for it at all?

queen adder
#

yeah a read that, but don't understand it

languid spire
#

what is there not to understand?
get a random number between 0 and the number of entries in the dictionary
get the value at that element number

queen adder
#

I'm sorry, i found it really difficult to warp my head around it. Even this simple task took me now nearly 30 mins. But i have, so thanks

hazy crypt
#

hello unity heads, im having some trouble with a coroutine

#

I am making an arcade racer. At the start of the race, I use an Ienumerator to countdown to the race start, this works fine. I want the player to be able to quickly restart the race, so I would like to run the coroutine again, however the countdown somehow end up as a negative number?

hexed terrace
#

because you haven't reset the number at the start of the countdown

hazy crypt
#

I have done this

hexed terrace
#

not properly, otherwise it wouldn't go negative

hazy crypt
#
    {
        //reset collectibles
        currentCollectibles = 0;
        UpdateCollectibleCount();
        hasAllCollectibles = false;

        // set vars so that the player can reset with R key after finishing
        raceStart = false;
        raceEnd = false;

        // turn off end screen
        EndRaceBackground.SetActive(false);
        LeaderboardBackground.SetActive(false);
        NavigationBackground.SetActive(false);

        //reset race timer and countdown to start 
        timerTime = 0;
        countinTimer = 3;

        StartCoroutine(CountdownToStart());
    }
#

This is the reset race method

#

the countdown definitely does go back up to 3, but it counts down twice as fast

hexed terrace
#

ok.. show the rest..

frail hawk
#

how about stoping the first coroutine

hazy crypt
#

If I keep resetting it, it always back to 3 straight away and then instantly jumps to a negative number

#
    IEnumerator CountdownToStart()
    {
        while (countinTimer > 0)
        {
            countinTimerStarted = true;
            yield return new WaitForSeconds(1f);

            countinTimer--;
        }
        countinTimerStarted = false;
    }
hazy crypt
frail hawk
#

well if you restart you would have to stop the current coroutine

hazy crypt
#

I see

#

It doesnt stop running on its own>

#

How would I do that

hexed terrace
#

you shouldn't need a stopcoroutine, you should be exiting it properly when the countdown finishes

languid spire
#

should you not be setting countinTimerStarted = true; somewhere?

hazy crypt
#

That was my assumption but im learly wrong somewhere

hazy crypt
#

its there

languid spire
#

no it's not

naive pawn
hazy crypt
#

line 6

hexed terrace
#

that bool doesn't look like it does anything anyway - probably used elsewhere

naive pawn
#

(it should probably be before the loop?)

hazy crypt
languid spire
#

if you are expecting your coroutine to do something, should it not call something after the while loop has finished

hazy crypt
#

Im only using it to display the countdown on screen

naive pawn
#

and not to control the actual start?

hazy crypt
#

I display "countInTime" at the race start

hazy crypt
naive pawn
#

so how are you controlling the actual start

hazy crypt
#

Im not sure what you mean

#

oh right

#
        if (countinTimer > 0)
        {
            raceStart = false;
            countdownText.gameObject.SetActive(true);
            countdownText.text = countinTimer.ToString();
            countdownBackground.SetActive(true);
        }
        else
        {
            raceStart = true;
            countdownText.gameObject.SetActive(false);
            countdownBackground.SetActive(false);
        }
naive pawn
#

how are you controlling them not to start before the countdown is over

hazy crypt
#

This is in the update method

hazy crypt
naive pawn
hazy crypt
#

Yeah its inefficient

#

But its not the cause of my current problem

#

I can make it pretty later

naive pawn
#

(it's probably not related to the current issue, but that may cause issues with having like, a proper, understandable logic flow in the future)

hazy crypt
#

Yeah thank you, ill take that on board

languid spire
#

this
yield return new WaitForSeconds(1f);
should probably be WaitForSecondsRealtime

naive pawn
#

WaitForSeconds is scaled according to Time.timeScale

languid spire
#

because WaitForSeconds is frame rate dependent

hazy crypt
#

I have changed it and the problem still occurs

naive pawn
#

have you tried debugging the coroutine? seems like it should exit on its own just fine

hazy crypt
#

Im not sure how I would go about this

rich adder
#

debug.log

naive pawn
#

just, Debug.Log in the loop, Debug.Log after the loop

hazy crypt
#

Okay, sounds good

#

I have been printing the countInTimer to the console

#

looks like this on the right

naive pawn
#

in what, Update?

#

is countinTimer being set anywhere else?

rich adder
#

check also how many coroutines you running

#

if(countinTimerStarted) return; StartCoroutine(CountdownToStart());

hazy crypt
#

So it looks like when i start the coroutine on reset, it never stops

#

the first instane does

#

instance

naive pawn
#

how are you calling Restart?

hazy crypt
#

pressing the "r" key on my keyboard, and also from the end screen and options menu

#

i have an event manager handling it

naive pawn
#

in code

hazy crypt
#

yes

naive pawn
#

show in code

#

i asked "how" not "when" ๐Ÿซ 

hazy crypt
#

oh i see lol

devout flume
naive pawn
#

more like
"how are you checking your engine oil"
"only when the engine light is on"

hazy crypt
#
// quick reset scene with R key
        if (Input.GetAxis("Reset") > 0)
        {
            EventManager.RestartCurrentScene();
        }
#

In the gamemmode controller

naive pawn
#

in Update?

hazy crypt
#

yeah

naive pawn
#

yeah you're starting a coroutine every frame that R is held down

hazy crypt
#

shit

naive pawn
#

so the coroutines are being stopped

#

there's just more than 1

hazy crypt
#

that figures

rich adder
#

called it ๐Ÿ˜…

hazy crypt
#

thanks guys

naive pawn
#

and the decrement happens before the check, so they're all decrementing

hazy crypt
#

Ill go fix this

#

If it breaks again, which it will, ill be bak

naive pawn
#

use it as a button/key instead of an axis and check for the frame it's pressed

rich adder
#

also you have a bool. use it. Never hurts to assure yourself

#

if(countinTimerStarted) return; StartCoroutine(CountdownToStart());

naive pawn
#

also edge case to test while you're at it: what happens if you press R while the countdown is active?

hazy crypt
rough spade
#

Hello, I am pretty new to Unity, I have a slider and this function:

    {
        bloom.intensity.value = brightness;
    }```

But for some reason, in "On Value Changed" there's that 0 and the value of "brightness" doesn't change at all. I maybe don't understand how sliders work as I am new, so I would be very grateful if someone could explain to me!
rough spade
#

Oh perfect, that was it haha thanks!

minor dagger
#

can someone help me get this pause menu working i want when player presses escape this to pop up and the player should not be able to move nor anything else the game should pause and the buttons should work ๐Ÿ™

naive pawn
#

or have you not implemented it at all? in that case, have you tried googling how to make one?

minor dagger
#

i used multiple scripts when i press escape it shows it but the game is not paused i can still move and cant press the buttons

naive pawn
#

have you written anything to make it actually paused?

minor dagger
#

i cant code i just use any script i can find

slender nymph
#

then start with the beginner c# courses pinned in this channel

uncut lantern
#

Hi am am a beginner with coding and I am having a problem with my code if someone can dm me and help ty๐Ÿ™

naive pawn
#

!ask

eternal falconBOT
#

:thinking: Asking Questions

:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #๐Ÿ”Žโ”ƒfind-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696

naive pawn
#

see that last point

#

noone can help you if you don't say what to help with

uncut lantern
# naive pawn we don't do dm support here

I see ok so I have a 2d game where when you hit the zombie he dies but the problem I am having is or the game object dies so I made him go invisible but I can figure out how to make it go back to visible

naive pawn
#

why do you need to make it visible again

uncut lantern
uncut lantern
naive pawn
#

none of what you're saying makes sense

#

please provide more context

#

are you trying to achieve object pooling or something

uncut lantern
#

The game I'm working on is zombie survival the problem I have is that I have a zombie spawner when I kill the zombie the game object that is the zombie destroyed it self so to fix that I made it go invisible but when new zombies appears it is invisible

#

Can I send videos?

naive pawn
#

when I kill the zombie the game object that is the zombie destroyed
yeah that should happen if you aren't pooling them. why is that an issue?

polar acorn
# uncut lantern The game I'm working on is zombie survival the problem I have is that I have a z...

It looks like you've independently come up with the concept of object pooling. You've got the basic concept right, but might be a bit confused on the implementation. Here's a tutorial on the concept:

https://learn.unity.com/tutorial/introduction-to-object-pooling

Unity Learn

Free tutorials, courses, and guided pathways for mastering real-time 3D development skills to make video games, VR, AR, and more.

naive pawn
#

you don't

#

because it's not an issue

#

are you getting an error or something

#

are you instantiating separate gameobjects with a prefab?

uncut lantern
potent garnet
#

what would be the best way to check if a wave has no more enemies, then spawn the next available wave?

rich adder
#

the "best" imo is using events for this

sharp abyss
faint agate
#

my problem is player vertical camera jitter lag when falling. I fixed it by turning interpolate to none on my rigidbody but then it made my game feel horrible and the bullets are super laggy now. Is there anything else I can do to fix the jitter lag when falling without turning off interpolate ?
I can send my player movement or camera script

sharp abyss
#

did you use a cinemachine

#

you can get it from package manager

faint agate
sharp abyss
#

cinemachine is a gameobject

#

you can make it follow a gameobject you assign in the inspector

faint agate
sharp abyss
#

I dont know why but I thought about 2d

#

what does your camera script do?

faint agate
#

https://pastecode.io/s/3ha6snzi

so here is my camera script.
first, I'm setting the direction in which the player is start facing, then I check if game is playing, if so then I can control the player looking around. Next is setting the sensitivity and camera rotation logic along with if im on a wallrun which is probably where my issue is somewhere

#
  • on the y axis, if I move too fast sliding to rocket jumping. Its like the camera starts kicking back trying to get itself back in place
sharp abyss
#

is camera child of your character

faint agate
faint agate
sharp abyss
#

do you set cameras position in MoveCamera script?

#

maybeusing fixedupdate can solve or making camera child of the player and not setting it by script

faint agate
#

Heres the moveCamera script. In this script I tried making it fixed update, but then the camera become super unsmooth

#

i think i found the problemmm

sharp abyss
#

what is it

hazy crypt
#

guys why does my new input manager package thing not look like the tutorials? I cant assign any global actions or anything

faint agate
# sharp abyss what is it

On my main camera, theres a script to handle player clipping. When I turned it off the bug went away but now I can look through wall if im next to one and look all the way down. fixed one issue to have another lol

naive pawn
faint agate
fading thunder
#

Okay this is puzzling for me. I'm working on my first 2d sidescroller as a learning project, and I am just this simple script for the camera to follow the player:

    public GameObject playerDefault;

    // Update is called once per frame
    void LateUpdate()
    {
        transform.position = playerDefault.transform.position;
    }
}```

But when I actually playtest, the camera does position itself at the player, but it doesn't show anything except the empty background...
#

any idea what could cause that?

hazy crypt
fading thunder
#

Oh, so even though it's 2D, I need to offset ?

faint agate
#

just in case
https://pastecode.io/s/wtjmpi48
heres the script that messed up my camera. When this script was active, the camera starts kicking back trying to get itself back in place if moving too fast. I turned it off and everything is fine now

hazy crypt
#

youre not just looking at the thing, youre inside of it

#

you need to zoom out away from it

naive pawn
fading thunder
#

Ahhhh yeah that makes sense now. Ty.

naive pawn
#

the z index in 2d is depth

#

you may notice the camera is at z=-10 by default

hazy crypt
#

@naive pawn hey mate did you happen to catch my question?

naive pawn
#

please don't ping random people to look at your question, if you haven't got an answer just bump it

hazy crypt
#

sure no worries

sharp abyss
naive pawn
#

(you don't need to do that.)

hazy crypt
#

guys why does my new input manager package thing not look like the tutorials? I cant assign any global actions or anything

naive pawn
#

tutorials might be outdated, try !learn maybe?

eternal falconBOT
#

:teacher: Unity Learn โ†—

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

rich adder
#

show screenshots of both

#

its likely the composite part thats different

hazy crypt
#

Yeah so this is the older system I think

#

Unity keeps telling me to use the new one but its messed uppp

rich adder
#

not much we can go on from here you have to show the exact error and issue comparison

hazy crypt
#

the one on the right is what it should be, the one on the left is what I have

naive pawn
rich adder
# hazy crypt

whats that for anyway? i never had to do any of that and use Input system daily

hazy crypt
#

I dont know what any of it is

#

I want to learn it but I cant find any resources at this pass

#

Ive been using the old system for ages but i figured its time to upgrade

#

I follwed the unity doc information on the setup but their pages look suuuper different to mine

#

Yeah thats the page im on

rich adder
#

yeah I never did it that way idk lol just create a new input system action map on the PlayerInput component

sharp abyss
open veldt
#

Hi so I followed a tutorial for making outline shaders, and after Iโ€™m done it just looks super janky and has these black pixels everywhere, does anyone happen to have experience with sprite outline shaders that I can maybe look at? I imagine itโ€™s pretty simple lol

#

Using shader graphs

open veldt
#

Cool didnโ€™t see that one ๐Ÿ˜ญ

thin hollow
#

can someone help me with git hub? Basically I made changes to my project which I didnt push to the github yet. I dont like the changes on my local disk and want to revert to what I had on github yesterday. im not sure how to do this

past spindle
#

I'm following instructions for the last project in the Junior Programmer course and it says to "Select Canvas in Inspector. In the window for Player Name Input assign the Text component of the InputField" but when I try to drag it over, it doesn't let me put it in the box. Does anybody have a clue as to why?

runic lance
past spindle
runic lance
past spindle
#

!code

eternal falconBOT
naive pawn
#

you don't have to share the entire thing, just the line where you're declaring playerNameInput

past spindle
#

[SerializeField] Text PlayerNameInput;

#

So just switch that to [SerializeField] TextMeshProUGUI PlayerNameInput; ?

runic lance
#

yeah, that looks correct

#

Text is the old unity text component, you should avoid it

past spindle
#

What about the later reference to PlayerNameInput.text; ? Do I need to adjust for this change or can that stay the same?

naive pawn
#

does it error?

#

if not, no

past spindle
#

lol fair enough

naive pawn
#

that's just how you'd do it in general lol
if it does error, you'd have to check docs for what the right property is
you should check regardless to make sure it's not subtly different, but i mean, this is pretty straightforward lol

past spindle
#

That does seem to fix the problem. I would like to check the property though, as you said. I would just google TextMeshProUGUI, yeah?

naive pawn
#

yeah

past spindle
#

cool thank you

naive pawn
#

some extra keywords like "unity" or "tmp" would help ensure you get the right docs

#

and you could also just go to tmp docs and search the class there

timber tide
#

tmp docs are pretty bad

surreal prairie
#

I am experiencing a weird issue when editing code in this snippet
int xCoord = Random.Range((int)currentRoomPosition.position.x-3, (int)currentRoomPosition.position.x+4); int yCoord = Random.Range((int)currentRoomPosition.position.y-2, (int)currentRoomPosition.position.y+2); float snappedX = xCoord * 0.64f + 0.32f; float snappedY = yCoord * 0.64f + 0.32f; Transform spawnPoint = new GameObject().transform; spawnPoint.position = new Vector3(snappedX, snappedY, 0.0f); //spawnPoint.position = new Vector3(xCoord, yCoord, 0);
editor (2022.3.20f1) stops responding and keeps on using more memory when attempting to launch the game, but if the commented line runs it works fine
any solutions?

timber tide
#

!code

eternal falconBOT
timber tide
#

new GameObject().transform
Probably related to the mem problem

ebon marlin
#

How to stop two dynamic rigidbody2d gameobjects from pushing eachother/affecting each others veolicities on collision while still wanting to detect collision by code and without freezing position

timber tide
ebon marlin
#

both use rigidbody to move

timber tide
#

I was thinking triggers for detecting, but the case of having two rigidbodies, and only one rebounding off the other I think requires changing the matrix

verbal dome
#

If you need to detect collisions between those two but not have them physically collide

ebon marlin
#

Triggers seem to be the way, thanks

#

just what i needed ^^

light merlin
#

for camera control on the mouse, the path used to be called Delta [Mouse]
does anyone know the new path for the input system?

naive pawn
light merlin
abstract copper
slender nymph
#

have you confirmed that you are not over writing the velocity anywhere like i suggested

abstract copper
#

Yeah

slender nymph
#

show how you move the object

abstract copper
#

The enemy?

#

or the player

slender nymph
#

no, the player which is the one being knocked back

abstract copper
#
moveInput = Input.GetAxis("Horizontal");
rb.linearVelocity = new Vector2(moveInput * moveSpeed, rb.linearVelocity.y);

if (moveInput != 0)
    transform.localScale = new Vector3(Mathf.Sign(moveInput), 1, 1);
slender nymph
#

rb.linearVelocity = new Vector2(moveInput * moveSpeed, rb.linearVelocity.y);

#

what a surprise, you over write the velocity

abstract copper
#

is it not only when moving the key

slender nymph
#

unless there's some logic preventing this code from running when no key is pressed or for the duration of the knockback, then no

#

of course if you do have logic that prevents this from running when you do not press one of the Horizontal axis's keys, then you never stop either

#

don't mix assigning directly to velocity with AddForce unless you know what you are doing. use one or the other. otherwise you need to prevent input from the player (and this code you've just shown from running) for the duration of your knockback so you don't just immediately assign the velocity again

abstract copper
#

thanks i fixed it

crisp lodge
#

like this

slender nymph
#

use mp4 not mkv to embed the video in discord

#

also make sure to show relevant !code

eternal falconBOT
valid ridge
fading mountain
#

Hey guys, I was thinking maybe I should just [SerializeField] all component references or object references because it's faster than doing

void Awake()
{
  rb = GetComponent<Rigidbody2D>()
}

or

void Awake()
{
  boss = FindObjectOfType<BossMovement>().transform;
}

Would that be good practice?

slender nymph
#

a serialized field is definitely faster than using any of the Find methods

fading mountain
slender nymph
#

it is perfectly fine to do so and is preferable over using any of the Find methods because those are all incredibly slow

fading mountain
#

Okay, thanks for clearing that up

slow tusk
#

Hello

devout flume
queen adder
#

How to rotate an object toward another 2D

timber tide
#

atan2

bronze carbon
#

how should i be connecting my player to the ui? ive tried using events to notify the ui when values change, and it mostly works, but im left with placeholder values until the values change for the first time because i cant guarantee that the ui is ready to listen when the player object starts itself
my only other idea is to give the ui a reference to the player and read the values every frame but that seems wasteful

timber tide
#

Events are usually the idea, but just communicating to the UI every time your health decreases or something similar is pretty standard

queen adder
timber tide
spare mountain
eternal needle
naive pawn
rocky canyon
timber tide
#

There's many ways you can rotate in 2D in unity, even using quaternions

steep rose
#

quaternions are evil

timber tide
#

People give Unity a lot of crap for not having traditional 2D, but having the ability to use those methods makes up for it

steep rose
#

but necessary

rocky canyon
#
// Set rotation using Euler angles
transform.rotation = Quaternion.Euler(0, 0, angle);

// Smoothly rotate to target
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 10f);

// Rotate around target's position
transform.RotateAround(target.transform.position, Vector3.up, rotationSpeed * Time.deltaTime);

// Align object's up direction with a vector
transform.up = direction.normalized;

// Rotate to face the target
transform.LookAt(Target);

// Rotate around Y axis
transform.Rotate(0f, rotationSpeed * Time.deltaTime, 0f);
#

soo many ways to rotate stuff
i still dont know which one my favorite..
I tend to use rotation = Quaternion.AngleAxis the most i guess

bronze carbon
obtuse quarry
#

I usually use the atan2 for rotating towards another object

#

Quaternions just donโ€™t work for 2d ig

rocky canyon
#

atan 2 is normally the next step after getting a direction

obtuse quarry
#

Yeh

rocky canyon
#

lot of those methods require a bit of math before hand

#

then u got magic ones like LookAt()

#

which im pretty sure also uses Atan2

#
Vector3 direction = target.position - transform.position;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0, 0, angle);```
#

my golden rotation code

naive pawn
rocky canyon
#

one liners eh

naive pawn
#

i was already on that one line and didn't feel like making more stuff lol

rocky canyon
#

that makes me wonder if theres any optimizations to be had to write a little extension method to pass in two directions and just get the angle needed w/ the atan2 and the conversion

eternal needle
obtuse quarry
#

Itโ€™s about the same through other game engines that donโ€™t already have a function for it

rocky canyon
bronze carbon
rocky canyon
#
   public override void _Process(float delta)
    {
        Vector2 direction = target.Position - Position;
        float angle = direction.Angle();
        Rotation = angle;
    }``` seems Gadot *does* have that extension method ๐Ÿ˜‰
#

yoink

naive pawn
#

atan2 is such a godsend, ive used it for 2 robotics competitions lol

rocky canyon
naive pawn
rocky canyon
obtuse quarry
rocky canyon
#

dot product is great for things in front of you

#

things behind you

naive pawn
#

yeah i see what you mean

rocky canyon
#

ohhh.. nah for robotics im still writing Blink Hello World code for my ESP32

#

you got me beat

eternal needle
naive pawn
#

i don't think that application is applicable for games since most are in cartesian systems already, so joystick input can be used as-is instead of direction really mattering ๐Ÿค”

rocky canyon
#

Awake <- Me
Start -> Them

#

for rare occasions I set manually execution orders for a gamemanager or such to fully initalize first

naive pawn
obtuse quarry
#

You need to do that?

naive pawn
#

for some systems, yeah

steep rose
#

was trying to make a robotic arm and I have all of the components for it

#

just have not 3D printed the "skeleton" yet

rocky canyon
#

its ~~fun ~~ cheaper (lol) to do real-world projects like that In Unity first

steep rose
#

if you have a 3D printer you can easily cut costs, the electronics are an exception of course

obtuse quarry
#

does anyone have ideas for a project?

rich adder
#

usually that follows with a project

obtuse quarry
#

any suggestions?

#

i might try remaking other simple games

rich adder
#

Unity has some many systems

agile oracle
#

if you were to make a game that involved combat with weapons, would you include a script on the weapon itself that dealt with the functionality of doing damage? idk if that makes much sense, but what iโ€™m trying to do is come up with a good way to structure my game so that i donโ€™t regret it down the line

naive pawn
#

sure, that'd work

eager spindle
#

it's what I do as well

#

makes it easier to implement carrying the stats after dropping the weapon

eager spindle
#

make it multiplayer if you want a challenge

wintry quarry
waxen adder
#

So I made a GameManager script, and its icon turned into a little gear instead of the traditional c# paper that I'm familiar with. What's that all about?

naive pawn
#

in the assets menu or in file explorer?

obtuse quarry
#

ive always wondered that

slender nymph
wintry quarry
#

just based on the name

obtuse quarry
#

i thought it was a unity easter egg or something

wintry quarry
#

it sort of is

naive pawn
waxen adder
#

Ah ok, good to know I'm not overriding something special or something

wintry quarry
slender nymph
naive pawn
#

wtf lmao

agile oracle
# wintry quarry > combat with weapons This is really just too vague. The answer is, it depends.

so in my game, i plan on implementing multiple melee weapons (and maybe ones that shoot projectiles). the player and enemies can both perform combat actions like swinging the weapon. right now, i handle combat with a script on the player/enemy game objects. the player executes the attack by pressing the left mouse button, and the enemy does if the player is in the โ€œattack spaceโ€ (some area that triggers the enemy to chase the player).

when the player or enemy swings their sword, and the swordโ€™s collider detects a collision, it raises an event that the targetโ€™s health component listens for, and then promptly decreases the health.

this is fine for now, but thereโ€™s an issue with this. since the enemy follows the player, thereโ€™s a chance it will hit the playerโ€™s sword even when the player is not swinging, which causes the enemy to lose health, and the enemy should only be damaged by the sword if the player is swinging.

iโ€™m sorry if this is too long winded btw

wintry quarry
#

It's better to use direct physics queries

agile oracle
#

as in raycasting or spherecasting?

bronze carbon
# bronze carbon how should i be connecting my player to the ui? ive tried using events to notify...

hmm im still struggling pretty hard with this
i have:

  1. a LevelManager script that spawns my Player inside of its Start() method
  2. a Player script that fires a HealthChanged event when it gets hurt
  3. a PlayerUI script that adds a callback to the HealthChanged event in its Start() method
    i want the player ui to update with the players health as soon as the player spawns, but the player could spawn before the ui does and i cant find a way to handle that
naive pawn
night mural
#

if you need something in a specific order, make a higher level thing which enforces that order

agile oracle
#

well "real time" in the sense of getting instant feedback when you attempt to attack

night mural
#

whatever solution you use, you probably want to define when the weapon is 'active' and only register hits while that is the ase

agile oracle
#

ase?

night mural
#

case

agile oracle
#

ah lol

#

yeah i'll keep that in mind

#

thanks for your responses

hushed rain
#

can anyone help me with this, i as following brackeys tutorial on how to make a game in unity using c# and im literally at the end of the game, ive done the credits, menu, all of it but im getting tihs error " error CS2006: Command-line syntax error: Missing '<text>' for '-define:' option " can anyone give me some troubleshooting because i dont feel like it would be good to post 6 scripts of code right here unless that could help you understand how to solve my problem

teal viper
#

And then also explain when it appears.

hushed rain
#

what do you mean by explain when it appears?

#

like when the error appeared while i was doing the game? if so it was after i finished putting all my scenes into the scene list and after completing the menu scene

teal viper
hushed rain
#

it just doesnt let me clear it

#

after pressing clear its like i didnt press it at all

#

according to chat gpt, (which im not sure if it as reliable so i came here) my scripts arent the problem

teal viper
#

Yes, it's unlikely that your scripts are the problem.

#

Did you try restarting the editor/PC?

#

And when did that error start appearing?

#

Was it there from the very start perhaps?

hushed rain
#

im not exactly sure when the error started appearing cuz i did multiple changes before saving

#

im no trying to restart my editor

#

ok this is gonna sound really dumb but how do i get out of this page

charred spoke
#

Top right Layout->Default

hushed rain
#

thanks

#

i fixed it

#

all i had to do was restart the editor

#

thx dilch

queen adder
#

how do i make a sript

#

that changes the value of a public float

onyx tusk
#

is there any way 2 get coordinates of the most right pixel in 3d game?

#

i mean, i need some 3d object to be at the edge of the screen regardless screen parameter's of player

obtuse quarry
#

i have successfully recreated about 80% of the chrome dino game

teal viper
teal viper
queen adder
#

ty

teal viper
buoyant finch
#

hello pls can someone guide me on how to make seperate animations for every move for a pokemon game pls I have the scriptable object as well as the animation clip but don't know how to implement it

teal viper
teal viper
# onyx tusk something like this

Then as I said, use ui. Either use a raw image with a rendertexture and render the object to it, or place it in the canvas hierarchy directly and scale accordingly. The former is the recommended way. There might be issues with the latter approach.

buoyant finch
teal viper
queen adder
#

how do i find a component but i dont know where it is

#

is there a way to find it? i forgot what object i put it in

#

nvm i foind it, its find references

placid oxide
languid spire
placid oxide
#

Im so dumb ty

onyx tusk
#

if in ur variant it'll be overlay anything not in canvas, this variant isn't right in my situation

steep oyster
#

does anyone know why the functions code are grayed out?

#

i want to fix it

languid spire
#

where do you see greyed out functions there

steep oyster
#

they maybe not gray, but they are more transparent

#

the start and update

#

theyre darker colored or something

languid spire
#

I believe this is a known bug in VS 2022

steep oyster
#

i think it's cause it has 0 references

#

but i dont want it to be dark because of that

steep oyster
#

ty

rich adder
buoyant finch
#

hello pls can someone guide me on how to make seperate animations for every move for a pokemon game pls I have the scriptable object as well as the animation clip but don't know how to implement it

rich adder