#💻┃code-beginner

1 messages · Page 176 of 1

earnest atlas
#

If I do that you will need to press jump button again.

#

With that logic it works fine

#

But if its on hold its doing weird things

ivory bobcat
#
     if (_isJumping) // Jump logic
     {
         var hit = Physics2D.Raycast(transform.position, _rayDirection, 2, _groundLayer);
         if (hit.collider != null)
         {
             if (hit.distance < 0.36f)
             {
                 _rb.AddForce(Vector3.up * _upwardForce, ForceMode2D.Impulse);
             }
         }
         _isJumping = false;//Will never jump again until the button is pressed again
     }```
tender breach
#

Just one of them to spawn one.

polar acorn
earnest atlas
#

As I mentioned resetting jump will force another jump click. I want it to jump automatiaclly while jump button is held

#

On normal click its working fine

#

On held its acting possesed

tender breach
polar acorn
#

which one should spawn the new object

ivory bobcat
#

I've got no clue what you mean by automatic jump at this point, so I'll let others help you.

tender breach
polar acorn
tender breach
polar acorn
tender breach
#

dropSet

polar acorn
# tender breach dropSet

Okay, so, whenever this object's dropSet is 2, and it collides with an object that is the floor or another instance of this script

#

That is the condition in which you want to spawn something?

stuck palm
#

why cant i get close to the player in the editor without it clipping?

earnest atlas
polar acorn
# tender breach Yes

So, that'd be what you want. Inside of your trigger function, check those conditions. Start by checking this object's DropSet, then check if the object is floor or puyo, and if both conditions are true, spawn your thing

slender nymph
polar acorn
frosty hound
#

@stuck palm You've been told multiple times in the past about posting non coding questions here. You should know this by now, and the next one will be moderated.

fierce shuttle
#

You could use a singleton, static class or ScriptableObject, if the data needs to exist across scenes, you could mark it with "DontDestroyOnLoad", if your goal is to save to a file at some point, you could then use a serialized class and save an instance of that class with something like JSON, maybe a combo of a serialized class and ScriptableObject might help, depending on how much data and the type of data your trying to persist

stuck palm
frosty hound
#

Key word is multiple times. Just be aware next time please.

stuck palm
#

i shall

queen adder
#

It overcomplicates it and makes it a ton harder to follow

fierce shuttle
short hazel
#

Do note that "saving" data to scriptable objects is not persistent. In builds, restarting the game will discard changes made to scriptable objects.
As such, you most likely need another system, where the data is saved to a file, and loaded when the game starts.

queen adder
queen adder
queen adder
#

that's what i need to learn how to do, scriptable object data to plaintext json

wintry quarry
#

but this is extremely vague. A simple variable "stores" data. You need to specify the lifecycle you want for this data.

#

A local variable "stores" data during function execution
A member variable "stores" data for the lifetime of the object

short hazel
#

No scriptable object, just a regular class. Saving and loading that into a file with JSON is literally 2 lines of code

queen adder
#

What are those magical lines

fierce shuttle
#

Depends on if your using the built-in JsonUtility or something like Newtonsoft JSON (which I suggest due to its flexibility) or another package

queen adder
#

JsonUtility

#

Wait you weren't joking

wintry quarry
#

yes the whole thing though is you need to design that "playerData" object

#

that's where most of the code is

swift crag
#

you create a class that stores a description of your game state

#

you create an instance and then serialize it to JSON to save

#

you deserialize from JSON and use the instance to restore your game state

buoyant knot
#

I’m reinstalling Unity. I need to know which version of unity editor corresponds to June of last year. How do I find that out?

rare basin
#

am I doing something wrong or it doesn't work on new input system?

  private void OnMouseEnter()
  {
      Debug.Log("Mouse over object: " + gameObject.name);
  }

  private void OnMouseExit()
  {
      Debug.Log("Mouse left object: " + gameObject.name);
  }

Doesn't log anything (It's attached to primitive Cube created via hierarchy, it has collider on it obviously)

wintry quarry
#

IPointerEnterHandler/IPointerExitHandler

rare basin
#

that'll also work for 3D objects?

wintry quarry
#

yes as long as:

  • They have colliders
  • You attach a Physics Raycaster component to your camera
  • You have an EventSystem/InputModule in the scene
rare basin
#

cool thanks

static bay
#

That sounds like a “sanity check” type of thing

earnest atlas
#
 private void ScrollBackground()
 {
     var xScrollClouds = Time.time * _speedClouds*_movementVector.x;
     var xScrollMountainsFar = Time.time * _speedMountainsFar * _movementVector.x;
     var xScrollMountainsNear = Time.time * _speedMountainsNear * _movementVector.x;
     var xScrollTrees = Time.time * _speedTrees * _movementVector.x;

     var offsetCloud= new Vector2(xScrollClouds, 0);
     var offsetMountainFar = new Vector2(xScrollMountainsFar, 0);
     var offsetMountainNear = new Vector2(xScrollMountainsNear, 0);
     var offsetTrees = new Vector2(xScrollTrees, 0);

     _rClouds.sharedMaterial.mainTextureOffset = offsetCloud;
     _rMountainsFar.sharedMaterial.mainTextureOffset = offsetMountainFar;
     _rMountainsNear.sharedMaterial.mainTextureOffset = offsetMountainNear;
     _rTrees.sharedMaterial.mainTextureOffset = offsetTrees;
 }

 private void GetRenderer()
 {
     _rClouds = _clouds.GetComponent<SpriteRenderer>();
     _rMountainsFar = _clouds.GetComponent<SpriteRenderer>();
     _rMountainsNear = _clouds.GetComponent<SpriteRenderer>();
     _rTrees = _clouds.GetComponent<SpriteRenderer>();
 }```

Im using tiled images on background I want to make ilusion of them moving. This is not working, dont know what to do?
wintry quarry
earnest atlas
#

Yes

wintry quarry
#

Time for Debug.Log

earnest atlas
#

I can place an interruption and its infact running but Im not sure if its doing anything

wintry quarry
#

log some values. Make sure things are as you expect

#

Or sure if you're using the debugger

#

look at the values there

earnest atlas
ivory bobcat
#

You need to define what's not working and log the necessary related stuff

earnest atlas
#

I mean nothing is moving

wintry quarry
# earnest atlas

99.9% sure mainTextureOffset is not implemented on SpriteRenderer

#

or at least not on the default sprite material

earnest atlas
#

I think so to

rare basin
earnest atlas
#

I have no idea what to search

wintry quarry
#

Use a different material and potentially renderer (MeshRenderer)

#

you need a material that supports texture offset

#

a quad with a basic unlit shader should do

earnest atlas
#

Hmm gonna add change things

buoyant knot
# static bay U good buddy?

it’s a “my computer got fried, and while I wait for the backup files to be accessible, I’m installing the version of unity editor that matches what I was using.”

#

eg “fine”

rare basin
# wintry quarry yes as long as: - They have colliders - You attach a Physics Raycaster component...

so got it working, but, the "click!" debug log isn't displaying after pressing down the left mouse button, but it's printing after releasing it (up! is also printing)

    void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
    {
        Debug.Log("enter!");
    }

    void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
    {
        Debug.Log("exit!");
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        Debug.Log("click!");
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        Debug.Log("up!");
    }
#

is that something I need to adjust in the new input system module?

wintry quarry
#

IPointerDownHandler is for the first part

static bay
rare basin
#

so what's the difference between Click and Up?

wintry quarry
#

Click is the whole process of clicking and releasing

#

PointerDown is just the initial click

#

PointerUp is just the release

rare basin
#

ow so Click is down and up combined

buoyant knot
#

one that handles power

dusty silo
#

Hello. I am trying to create an EdgeCollider2D for in my Edge class's constructor.
Here is the relevant constructor code:

    {
        
        m = Instantiate(Resources.Load("Vessel") as GameObject);
        ec = m.AddComponent<EdgeCollider2D>();
        lr = m.AddComponent<LineRenderer>();
        //Debug.Log(v1.localPos());
        //Debug.Log(v2.localPos());
        ec.points = new Vector2[] { v1.localPos(), v2.localPos()};```
`Vertex.localPos()` just returns the Vector2 that the Vertex was constructed with.
`Vertex.getRealPos` uses `transform.TransformPoint(localPos)`.
Neither `localPos()` nor `getRealPos()` connects the EdgeCollider2D to the vertices without a considerable offset. What can I do to negate the offset?
wintry quarry
ivory bobcat
#

Print some values:

  • actual
  • expected
#

Are there any patterns to these differences?

wintry quarry
#

and where did v1 and v2 come from in the first place? What values did you give them and where did those values come from?

dusty silo
buoyant knot
wintry quarry
#

yes but where did those come from

buoyant knot
#

edgecolliders have vertices, connected by edges

#

why do you have a separate class of edges and vertices

wintry quarry
#

There's nothing wrong with edges/vertices

buoyant knot
#

i’m just confused why there is a second class here

wintry quarry
#

Because lots of algorithms operate on Edges

#

I honestly don't think it's that important in the context of the question

buoyant knot
#

oh, are you trying to start with a representation of vertices and edges, and then create an edgecollider that matches this?

ivory bobcat
#

The class is likely just "boxing"

#

We need to see the behavior pattern of what's working and not working (the actual data)

buoyant knot
#

if you need to create an edge collider based on a predefined path of vertices, you want to use SetShapes, and PhysicsShapeGroup2D or something like that

inland cobalt
#

Hey all, i'm trying to make a simple pong game and im currently working on getting the ball to bounce off correctly, while giving it bounciness achieves this, it does bounce in the directions it should like the original pong as it is really a flat surface, so i'm trying to implement bounciness myself.

I have this code here:

    private void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.CompareTag("Bumper")) // Get other's distance from centre and check Y offset
        {
            float yOffset = transform.position.y - other.transform.position.y; // Set velocity based on this offset

            rb.velocity = new(-rb.velocity.x, yOffset);
        }
    }

On detecting collision with the bumper, it tries to inverse it's x velocity to start travelling the other way and give it y velocity based on it's offset from the centre of the bumper. The issue is, as of the time of collision, velocity is zero, how would i go about getting the velocity before it collided?

wintry quarry
#

Basically @dusty silo is saying "Vertex.localPos() just returns the Vector2 that the Vertex was constructed with." - so I want to make sure what they're passing in here is actually a local position in the coordinate space of whatever m is.

#

which seems unlikely since m was just spawned inside this constructor

buoyant knot
#

the edge shape has a set of vertices, relative to the offset of the collider, which is relative to the transform

wintry quarry
#

OnCollisionEnter indeed happens after the collision is already processed and it already bounced and changed velocity

queen adder
#

HAHAAA

#

Thank you all

buoyant knot
#

if your edgecollider2D is on something with transform at (100,0), it has an offset of (0,10), and you put a vertex at (1,0), then the edge will have a vertex at (101,10) in world space

dusty silo
inland cobalt
#

nevermind, it was the friction i had set, apologies

dusty silo
queen adder
#

is there a builtin way to do a knockback grenade? Like an ImpulseForceAt()?

#

or do we manually have to code it with a overlap, then manually doing the addforces?

rare basin
#

how would built-in feature for such system work

#

when in every game it works differently by design

#

get colliders with overlap, calculate knockback direction, add force in that direction

#

5 minutes of work

#

and extensible/configurable to your needs

trail heart
woeful lagoon
#

When I use this bit of code I end up just turning off my ui but am unable to turn it on again, any help?

if (Input.GetKeyUp(KeyCode.Escape))
{
    Netmanui1.SetActive(!Netmanui1.activeInHierarchy);
}
slender nymph
#

Update does not run on disabled objects

queen adder
#

oh nvm

trail heart
queen adder
#

yea, i quite want to let unity handle the physics math as well

lilac crow
#

Hi.
Good day!
I have a question :
How can i have multiple cutscenes in a scene and how should I summon them?

rich adder
woeful lagoon
#

Yeah, I belive I fixed it

lilac crow
rich adder
queen adder
swift crag
#

Objectives and quests are veeeery broad topics

cosmic dagger
#

Very much so . . .

visual hedge
#

how do I remove elements from this custom list thru gameObject?
Like if that would be the List<GameObject> list, I would simply : list.Remove(gameObject);
but how do I do that with custom list?

lusty socket
#

!code

eternal falconBOT
cosmic dagger
swift crag
visual hedge
lusty socket
#

Hi im trying to make an aim and shoot basketball game but im a big beginner o 3d and been using different tutorials online to make the code, it all works as wanted except when clicking to aim the line renderer used to aim appears way above the starting point given although the x axis is fine. Could anyone fix this? thankyou

swift crag
#

List<T> will have a Remove(T item) method, yeah

#

this will hold true for any type

cosmic dagger
twilit dirge
#

I've gone ahead and looking into taking your advice here, because it seems like the best approach. I have a few questions/issues though: Localization. I probably won't be launching with localization, but I definitely would want to add it in the future. SO's seem problamatic as I'd need to double all these SO's for each lang. But I've seen that it would basically be the same thing for a json, but externally, so I'm not too worried about this, but wanted to know which is the more efficient route.

Also, the memory issue again. I can either load the appropriate scriptable objects according to language all at once on startup and leave it there, or load & unload dynamically as the user requests dialogue. I think the first approach would be better as using Resources.load and unload every single time the user requests dialogue seems taxing, but I wanted to get input from someone who knows more about this first. Maybe there is another way?

#

maybe loading it async or something

vernal minnow
#

Is there an is touching method/function?

#

Like if (object.isTouching.otherObject) {Do this}

#

The closest thing I've found is just a boolean setup

#

I can probably check for a collision but I figure the proper formatting makes more sense

twilit dirge
#

if you're even doing 2D

#

I don't know much about 3D

vernal minnow
#

Would OnCollisionStay2D() work?

#

I'm trying to detect if an object is touching another object so that I can later attach/detach the two objects on a keypress

acoustic sequoia
#

Can someone help me find the answers im looking for by either;

  1. sending me to the correct discord channel.. or
  2. direct me to the correct tutorials/docs/youtube video(s) for syncing my game across gamecenter on iOS for a turn based board game.
vernal minnow
#

void OnCollisionStay2D(Collision2D collision) can i put specific colliders into inputs so that a different action happens depending on the collider that was hit? (like this maybe?)void OnCollisionStay2D(Collision2D BoxCollider2D)

warm condor
#

hey, so in this unity document (https://docs.unity3d.com/ScriptReference/Vector2.ClampMagnitude.html), it explains what the Vector2.ClampMagnitude is and how to use it. The thing is, I understand that one of the parameters is to set the velocity using Vector2 to tell the program what that the maximum velocity. The thing I don't understand is the other parameter, the maxLength, which I don't know what it is. Can someone explain to me what it is?

late burrow
#

how to make most default green progress bar that i can display script progress on

frosty hound
#

What does that even mean?

late burrow
#

for example it appears when compiling

#

how i use that bar myself

frosty hound
#

What's your usecase?

late burrow
#

script that digests through text file for 5 mins to get all vectors

frigid sequoia
#

I am trying to delete a Canvas when its content has finished an animation, but this error shows up

#

What is causing that?

late burrow
#

is that green bar even usable or is reserved for unity stuff

potent garnet
#

having a problem rn, it seems like the OnTrigger function doesn't work

#

Trying to make it so when the enemy shoots a laser, and that laser collides with the player, an event will invoke and set off different methods.

frigid sequoia
#

Make sure you are following that

woeful lagoon
#

Hey guys, Im currently getting an issue with connecting to an Ip, when I get my ip from a textbox in ui and put it into the unity transport system it must have an invalid charcter, is there anyway to trim it?

potent garnet
#

alr thank u

#

i'll see what i can do with that

warm condor
frigid sequoia
#

The magnitude of a vector is like how far does it go

warm condor
#

oh ok, so the vector parameter is like checking if it goes to a certain speed, and if it does, then it will cap it to maxLength

#

did I get that right?

frigid sequoia
#

Vector is not necesarily speed, but yeah, pretty much

#

If you are using it to set the maxSpeed of a 2D object, that would do

north kiln
frigid sequoia
#

And I saved it

north kiln
#

In future, I made a robust physics messages debugging resource that is pinned to this channel

frigid sequoia
#

Cause it seem superusefull XD

warm condor
frigid sequoia
#

Is like starting a statement saying "3"

#

It is a value, not a variable

warm condor
#

I don't get it, how do I use it then?

frigid sequoia
#

What you want to do is something like rb.velocity = ClampMagnitude(rb.velocity, maxVelocity);

#

Or somethin like that

#

Also why are you using an int for direction?

#

That seems not very optimal

warm condor
frigid sequoia
#

Yeah, but shouldn't that be at leats a float?

warm condor
warm condor
frigid sequoia
warm condor
#

so basically there is no diffrence between making it a float or not

warm condor
#

I have tried to use if statements, but I had problems with that, so someone here suggested me to use Vector2.ClampMagnitude

frigid sequoia
#

Why would you want to clamp the speed just in mid air and not on the ground?

warm condor
#

yea I was going to do that after clamping the max speed on ground

#

I do need to know how to apply it before using it on other things

frigid sequoia
#

Just clamp the velocity overall and apply the clamped value directly to the rb velocity instead of adding force

warm condor
steady isle
#

im tryna practice my coding basics with c# and made a rock paper scissors game. It works perfectly fine but I can't seem to get the part of the code which allows the user to play again to work. Please let me know if you can help.

warm condor
#

I have had a similar experience with that before, it is like setting a value to a 3, and on the same function you set it to a 4, so the final value will be a 4

frigid sequoia
frigid sequoia
steady isle
frigid sequoia
#

Load again, when you want to do another game

olive bane
#
//Here's the relevant function on the Tile script:
    void OnMouseDown()
    {
        var x = transform.position.x;
        var y = transform.position.y;
        selectedTile = new Vector2(x, y);
        Debug.Log(selectedTile);
        OnTileClicked.Invoke();
    }

//And here's the GenerateObject script:
using UnityEngine;

public class GenerateObject : MonoBehaviour
{
    public Tile script;

    void Start()
    {
        // Iterate through all tiles in the grid and subscribe to their OnTileClicked event
        Tile[] tiles = GameObject.FindObjectsOfType<Tile>();
        foreach (Tile tile in tiles)
        {
            tile.OnTileClicked.AddListener(HandleTileClicked);
        }
    }

    void HandleTileClicked()
    {
        Debug.Log(script.GetComponent<Tile>().selectedTile);
    }
}
gloomy ice
#

Hello, I want to load characters data from a JSON, and I have some character images separated as moods (angry, sad, happy, etc) how can I load the character expressions based on a MOOD variable and the character data?

wintry quarry
#

e.g.

Dictionary<Mood, Sprite>```
#

you can can just do mySpriteRenderer.sprite = myDictionary[currentMood];

gloomy ice
#

and how do I populate the dictionary?

wintry quarry
#

in Awake

#

iterate over your json data

#
foreach (MoodInfo mi in moodInfos) {
  myDictionary[mi.mood] = mi.sprite;
}```
#

would be ideal

queen adder
#

can we manually play an animation clip via code without sending to animator?

wintry quarry
#

assuming you structure your json well

wintry quarry
queen adder
#

ooh didnt know there's this animation thing, thanks

#

that's more playable

#

isnt there an animation thing that is already deprecated on new unities?

#

forgot what though

#

or that was an audio thing, dunno

rocky canyon
#

whoa, what a component

frigid sequoia
#

I am using a World Space Canvas to show some floating text, I want to save it as a prefab and it has a general script that just makes it look at something, in this case that would be the camera. When assigning the main camera to the object to follow on the inspector it works as expected, but when I save it as a prefab I cannot assing anything that is not directly on the prefab itself as a gameObject to follow. Do I have to make a reference to it directly in the script for it to work as a prefab? Cause that seems really inconvinient for scripts like these

#

If I drag the component from the scene to the editor's reference it says "Type missmatch"; which doesn't show when the prefab is in scene and I assing it there

wintry quarry
#

assets (prefabs are assets) cannot reference objects inside scenes.

#

Simple example:

[SerializeField]
MyCanvasScript myPrefab; // assign in the inspector to the prefab
[SerializeField]
Camera mainCamera; // assign in the inspector to the camera

void SpawnCanvas() {
  MyCanvasScript myInstance = Instantiate(myPrefab);
  myPrefab.cameraRef = mainCamera;
}```
#

This would be the code that spawns the floating text thing

ivory bobcat
olive bane
#

I'm trying to access the selectedTile variable in a different script

ivory bobcat
#

Looks fine. What's it supposed to be rather than (0, 0)?

frigid sequoia
ivory bobcat
#

You don't need to call GetComponent for the referenced Tile btw

olive bane
wintry quarry
#

it's really very simple

frigid sequoia
ivory bobcat
wintry quarry
ivory bobcat
#

Maybe show us the inspector for that component?

frigid sequoia
wintry quarry
#

get used to dealing with references in your code

frigid sequoia
wintry quarry
#

no

frigid sequoia
#

Why would it work differently?

wintry quarry
#

it is not

wintry quarry
#

that object has to exist to be able to reference it

olive bane
wintry quarry
#

When you think about it, what you want doesn't make any sense unfortunately

frigid sequoia
#

Don't get why it would be coded differently

wintry quarry
frigid sequoia
gloomy ice
ivory bobcat
north kiln
gloomy ice
#

I want to load to load it by code

ivory bobcat
#

Try changing the log tocs Debug.Log($"{script.selectedTile}", script);

#

Click the log in the console during runtime and see which object is highlighted yellow.

wintry quarry
olive bane
ivory bobcat
#

You may want to drag your console windows out and have it place next to your assets or something to have it visible during the selection

frigid sequoia
#

How can I do a prefab overload?

north kiln
ivory bobcat
teal viper
olive bane
solid rock
#

Good day everyone, PLEASE HELP! Can anyone point me towards a good direction. I would like to create knitcap for a snowman but I don't know and I didn't find a resource that teaches how to do it. Thank you for any advice.

frigid sequoia
ivory bobcat
teal viper
gloomy ice
frigid sequoia
#

Oh welp, it is what it is

gloomy ice
#

im looking for an option that doesnt work with the inspector

olive bane
queen adder
wintry quarry
#

it doesn't change the basic idea

#

I don't really see what benefit you have from avoiding the inspector though

rocky canyon
#

i guess its still okay to use.. || learn the animator, though||

gloomy ice
#

alright ill try that, thankx

ivory bobcat
# olive bane I have a dictionary variable, but it's in a GridManager script. Could I make tha...

You'd do so when you instantiate or reference them with your manager.
An example for when they're instantiated:cs var tile = Instantiate(tilePrefab); tile.OnTileClicked.AddListener(HandleTileClicked);``````cs void HandleTileClicked(Tile tile) { Debug.Log(tile.selectedTile); }``````cs OnTileClicked.Invoke(this);*Implies you've got an event/action that has one parameter of the type Tile.

lusty socket
#

!code

eternal falconBOT
olive bane
gloomy ice
#

Hello, how can I change a texture from a gameObject?

Texture2D newTexture = Resources.Load<Texture2D>("pixi");
gameObject.GetComponent<SpriteRenderer>().sprite = // what to put here using "newTexture"?
teal viper
wintry quarry
#

Don't make life harder for yourself

gloomy ice
queen adder
woeful hedge
wintry quarry
gloomy ice
#

Ohh thanks

wintry quarry
#

(and make sure you actually imported the image as a sprite)

woeful hedge
#

I just tried to display the destination of NavMeshAgent, but the Ray seems to draw wrong positions. How to solve this?

(In the screenshot, the agent is going to (-3,0,-4) but ray points at opposite way)

here's the code -

    IEnumerator NormalMove(Vector3 vector)
    {
        navMeshAgent.isStopped = false;
        animator.SetTrigger("IdleToWork");
        navMeshAgent.SetDestination(vector);

        Debug.Log(vector);


        while (true)
        {
            yield return new WaitForSeconds(0.1f);

            if (Vector3.Distance(transform.position, vector) < 0.001f)
            {
                Debug.Log("Reached");
                transform.position = vector;
                animator.SetTrigger("IdleToWork");
                break;
            }
            else
            {
                Debug.DrawRay(transform.position, vector, Color.red, 0.1f);
                //Debug.Log(Vector3.Distance(transform.position, vector));
            }
        }

        navMeshAgent.isStopped = true;
        navMeshAgent.velocity = Vector3.zero;

    }
#

oh shit wait it was (-3,0,-4) but anyways it is wrong

gloomy ice
#

it worked, thank you uwu

edgy fox
#

When the green wall is placed, I need it to recognize which of the red lines have walls and which don't. I've been trying to do this for awhile but I'm drawing a blank

#

I already have blank walls on the red lines without non-rendering walls that have hitboxes for raycasts but I have no clue how to actually detect them aside from comparing coordinates which seems unreliable at best

#

and I also want to avoid iterating through a list of every single blank/not blank wall because that will have issues scaling

wintry quarry
edgy fox
wintry quarry
#

In the usual ways

#

An Adjacency list is best.

edgy fox
#

would each wall have its own list stating which walls are adjacent or is there one grand list that has all walls with there adjacencies?

woeful hedge
#

Does a function exist that draws a line between two points?

wintry quarry
#

more like each box in the grid knows which edges it has and the neighboring grid boxes, and each edge knows which grid box it's part of.

woeful hedge
wintry quarry
next portal
#

Good evening all. I've been messing Unity for a few days now. Dabbling in making my own game. It's coming along but one frustration I can't overcome is my objects overlap no matter what I try. I've made a completely new 2D project with 2 simple objects. Both with rigidbody2d and box collider and I control one of them into the other and they overlap. I've watched tutorials and in 5 minutes they make a platform jumper. My "Player" just falls through the floor. What am I missing?

wintry quarry
#

Make sure you're following all the steps of your tutorials

next portal
edgy fox
wintry quarry
#

Don't skip or change anything the first time through

wintry quarry
#

to be honest this is not really a beginner topic so if you're new to programming it's going to be difficult.

edgy fox
#

is an adjacency list completely separate list syntaxwise from a normal list or is it just an application of a list?

next portal
edgy fox
wintry quarry
edgy fox
#

oh ok

wintry quarry
#

in practical terms it could just be a List<GraphNode> where each GraphNode has a List<GraphNode> representing its neighbors

edgy fox
#

and I assume I would have one master list as a static element of some class?

wintry quarry
#

but you have to understand graphs and graph algorithms to do this effectively

wintry quarry
edgy fox
#

alright makes sense, that's probably how I'll wind up doing it

edgy fox
wintry quarry
#

it was an example class name I made up

edgy fox
#

ah that makes sense

snow depot
#

I'm having trouble getting my game to register my left mouse button to fire projectiles and I can't seem to figure out why.

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

public class ProjectileGun : MonoBehaviour
{
    [Header("References")]
    public Camera protagCamera;
    public Transform attackPoint;

    [Header("Projectile Info")]
    public GameObject projectile;
    public float shootForce;

    [Header("Gun Info")]
    public float timeBetweenShooting, spread, reloadTime, timeBetweenShots;
    public int magazineSize, bulletsPerTap;
    public bool allowButtonHold;

    [Header("Keybinds")]
    public KeyCode reloadKey = KeyCode.R;
    public KeyCode fireButton = KeyCode.Mouse0;

    // private variables
    int bulletsLeft, bulletsShot;
    bool shooting, readyToShoot, reloading;

    [HideInInspector] public bool allowInvoke = true;

    private void Awake()
    {
        bulletsLeft = magazineSize;
        readyToShoot = true;
    }

    private void FixedUpdate()
    {
        MyInput();
    }

    private void MyInput()
    {
        if (allowButtonHold) shooting = Input.GetKey(fireButton);
        else shooting = Input.GetKeyDown(fireButton);

        if (Input.GetKeyDown(fireButton)) Debug.Log("Button Pressed");
        

        if (Input.GetKeyDown(reloadKey) && bulletsLeft < magazineSize && !reloading) Reload();

        if (readyToShoot && shooting && !reloading && bulletsLeft <= 0) Reload();

        if (readyToShoot && shooting && !reloading && bulletsLeft > 0)
        {
            Debug.Log("Shoot Function Called");
            bulletsShot = 0;
            Shoot();
        }
    }

    private void Shoot()
    {
        readyToShoot = false;

        //Find the Hit Position using Raycast
        Ray ray = protagCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
        RaycastHit hit;

        Vector3 targetPoint;
        if (Physics.Raycast(ray, out hit))
            targetPoint = hit.point;
        else
            targetPoint = ray.GetPoint(75);

        // Calculate direction from attackPoint to targetPoint
        Vector3 directionWithoutSpread = targetPoint - attackPoint.position;

        // Random spread
        float x = Random.Range(-spread, spread);
        float y = Random.Range(-spread, spread);
        float z = Random.Range(-spread, spread);
        Vector3 directionWithSpread = directionWithoutSpread + new Vector3(x, y, z);

        // Creating projectile
        GameObject currentBullet = Instantiate(projectile, attackPoint.position, Quaternion.identity);
        currentBullet.transform.forward = directionWithSpread.normalized;

        // Adding force to projectile.
        currentBullet.GetComponent<Rigidbody>().AddForce(directionWithSpread.normalized * shootForce, ForceMode.Impulse);
        //currentBullet.GetComponent<Rigidbody>().AddForce(protagCamera.transform.up * upwardForce, ForceMode.Impulse);

        bulletsLeft--;
        bulletsShot++;

        if (allowInvoke)
        {
            Invoke(nameof(ResetShot), timeBetweenShooting);
            allowInvoke = false;
        }

        if (bulletsShot < bulletsPerTap)
            Invoke(nameof(Shoot), timeBetweenShots);
    }

    private void ResetShot()
    {
        readyToShoot = true;
        allowInvoke = true;
    }

    private void Reload()
    {
        reloading = true;
        Invoke(nameof(ReloadFinished), reloadTime);
    }

    private void ReloadFinished()
    {
        bulletsLeft = magazineSize;
        reloading = false;
    }
}
#

When I change the fire button to my F key it works just fine, but for some reson it won't register a click on Mouse0

wintry quarry
#

input should only be handled in Update

#

Also if you move this handling code to Update you will need to make a few other small adjustments

snow depot
#

well I've changed it from FixedUpdate() to Update() and it still doesn't seem to be registering a left click. what else should be changed?

vale karma
#

hi, im trying to implement a MouseLook script for my Main Camera, in order to look around using the mouse in a 3D game. Is there documentation to go over how to do that with the new input system? Every tutorial/documentation doesnt go over the basics or what each block of code means

#

Also each vid goes over the old input method. Brackeys and other popular utubers just gloss over any relevant info

timber tide
ivory bobcat
# olive bane I'm confused as to how HandleTileClicked can have a parameter, since it tells me...

I'm confused as to how HandleTileClicked can have a parameter, since it tells me it's a function when I add a parameter.
Functions can have parameters but I'm guessing you did not declare your event/action to accept functions with a parameter type.
I'm also not entirely sure where all of these scripts are supposed to go, since my event listener is in a different script to my instantiation script.
It's practically your code so you ought to be able to recognize most of it: #💻┃code-beginner message 🤷‍♂️..
Here would be an example using plain c# that adds a listener with a parameter to another class (Echo) and have a manager (Cave) broadcast the messages without knowing the underlying implementation https://dotnetfiddle.net/OYrVn9 (main defined the functions, echo referenced the function and cave manages echos).
In your case, you'd just need to change the declaration of your event/action to accept a parameter so you could pass the Tile data to the function to be printed to the console when the tile is clicked. Printing the position value of the prefab is what I'm assuming you're not wanting from your original code post.

tepid summit
#

I have an idea, but id just like confirmation/ a second opinion on how to do this with OnTriggerEnter instead of CollisionEnter


private void OnCollisionEnter(Collision collision)
    {

        if(collision.gameObject.name == ("Bullet"))
        {
            Debug.Log("Collision Found");
        }
    }
timber tide
tepid summit
#

i know how to do an OnTriggerEnter

#

i want to know how to check the name of the enterer

twilit dirge
timber tide
tepid summit
#

so instead of if(collision.gameObject...)

i just do if (collider.gameObject... )?

timber tide
tepid summit
#

ive always wondered about random picker things

timber tide
tepid summit
#

ill have a look and try something, and come back if theres further errors

timber tide
#

but as you should know, the collider is a component, and if it's a component then it must inherit from mono, meaning it will always have a gameobject property

#

and transform for that matter

tepid summit
#

yes

#

sorry, i forgot how to check object tags?

timber tide
#

Collision object on the otherhand is not a component, but an object generated by colliding, but it has properties referring to the gameobject's properties

tepid summit
#

right

tepid summit
#

oh yeah

timber tide
#

documentations are your friend

tepid summit
#

thats right;

#

they are

#

i use them alot

#

ok

#

one last question (for now)

#

actually ill google it first

fierce shuttle
# vale karma hi, im trying to implement a MouseLook script for my Main Camera, in order to lo...

If your handling input through Update, you should be able to follow any tutorial for mouse look, and replace the old input checks for Mouse.current or setup delta in an input action asset, and reference it, you could also refer to the "how do I?" page which may help: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/HowDoI.html

This approach, would be polling in Update rather than using events of the input system, for a mouselook, it should be a fine approach

tepid summit
#

not my original question, but how do i make children of an object not match the scale of their parent object

timber tide
#

you dont usually as you should consider making those siblings if needed instead

tepid summit
#

a what

#

sorry im pretty new if that wasnt obvious

#

or

timber tide
#

don't make it a direct child, but instead use another gameobject to wrap them

tepid summit
#

not so much new, as unexperienced

tepid summit
rocky canyon
#

crosshair wrapping crosshair graphics

timber tide
#

your implementation: parent -> child
my suggestion:

another gameobject ->
gameobject1 (previous parent)
gameobject2 (previous child)

tepid summit
#

isnt that childing

#

oh

#

so have it 3 layers deep

#

like
Parent>Obj1>Obj2

#

or is it
Parent>Obj1 + Obj2

timber tide
#

right, if you're going to scale and don't want the children to scale, then don't directly add children to those objects

tepid summit
#

yeah

#

thats what i ended up doing

rocky canyon
#

if it makes sense to go

  • parent
    • child
      • child

then sure

tepid summit
#

ok

#

and how would one change this from a cylinder

#

id rather a rectangular prism

rich adder
# tepid summit and how would one change this from a cylinder
Unity Learn

The Shape module defines the surface from which particles are emitted and can drastically change the appearance of your particle effect. All the shapes have properties that define their dimensions, except for Mesh, which will follow the details of the mesh you select. In this tutorial, we’ll explore the options in the Shape module.

tepid summit
#

oh

#

its literally an option right there

#

guess i didnt look hard enough

#

oh

#

you have to click on it after you enable it

stable jackal
#

hello! ive imported Mirror and done all the steps, i can connect locally and such, but the tutorial says i should tick Client Authority, but in the network transform there's no client authority anymore....

how do i put authority on the player prefab?

main problem is one player can manipulate all the characters at once so... what can i do?

Unity 2022.3.2f1

timber tide
#

but usually if it's a specific library, you'd probably get more help in its related communities cause not everyone uses Mirror

tepid summit
#

ive made a script and its not creating errors, but it isnt working

    public GameObject BoxObj;
    public GameObject BoxPref;
    void Update()
    {
       if(BoxObj == null)
       {
        GameObject newBox = Instantiate(BoxPref, this.transform.position + new Vector3(-1, 0, 0), this.transform.rotation);
       } 
    }
#

any ideas?

rare basin
#

"it isn't working"

#

how are we supposed to know what isnt working exactly

#

and what is the desired behaviour

tepid summit
#

it doesnt do anything

#

check if the object is null/destroyed and spawn a new one

rare basin
#

because this code doesn't make sense

#

you are checking if BoxObj is null

#

then you are trying to spawn null object edit: nevermind

#

did you debug log it?

#

to see if it's being called?

#

where are you assigning BoxObj?

tepid summit
#

lemme check

rare basin
#

thats the first thing you should've done before asking

#

debug your code

tepid summit
#

so theres the issue

#

not being called, that is

rare basin
#

yup

tepid summit
#

yes

tepid summit
rare basin
#

if(BoxObj == null) this is not true

#

so it doesn't enter that if, so it doesnt spawn the thing you want to spawn

tepid summit
#

right

#

youve forgotten to apply an object

#

on the thing with the script

rare basin
#

what is FightSystem line 33?

#

then camTransform is null

#

not assigned

lilac crow
tepid summit
#

could use a list

#

wait no

#

i forgot the name

#

its pretty much a list

rare basin
#

depends on the design you want to achieve

#

there is plenty of tutorials on that

#

you can make it based on ScriptableObject, interfaces etc

tepid summit
rare basin
tepid summit
#

signalling it

#

you know?

#

its on the tip of my tongue

#

"calling" is the only verb i can think of right now

lilac crow
tepid summit
#

jesus

lilac crow
#

i know 🥲🥲

tepid summit
#

i was talking about the message above

#

this one

lilac crow
#

and i noticed

tepid summit
#

ok

#

making sure

#

its very missable

lilac crow
#

the funny fact is when i do ctrl+z the error is gone . but i just rewrite the function name nothing more and it make it to what was befor then the error gone like poff

tepid summit
#

i just realised you wrote the mesage

#

ohhhhhhhhhh

#

REFERENCE

#

thats it

tepid summit
tepid summit
rare basin
#

you cannot reference if

tepid summit
#

damn

rare basin
#

do you know what a reference is?

tepid summit
#

sort of

rare basin
#

doesnt look like you do

tepid summit
#

let me get it

#
{
 GetTheCheese();
}
#

that would reference GetTheCheese

#

every.

#

frame.

faint sluice
#

That would call get the cheese

#

Not reference

tepid summit
#

oh well same thing

#

except

faint sluice
#

Not really no

tepid summit
#

it isnt

faint sluice
#

Reference is usually referred to well, referencing the variables itself

lilac crow
tepid summit
#

yayyyy

rare basin
tepid summit
rare basin
#

that will call GetTheCheese() function every frame

tepid summit
#

it calls it

rare basin
#

you are missing bassic C# terms and knowledge

tepid summit
#

i wouldnt say mising

#

i was trying to reply quickly as i dont like keeping people waiting

#

i didnt think about it

#

and just

#

posted the mesage

#

that is also why i make a lot of typo's

eternal needle
#

You are most definitely missing the basics, but as long as you're trying to learn them then it's fine. Hopefully you're not just trying to make the next competitive shooter at the same time

tepid summit
#

i only just learned about (object) == null (only because i didnt require use of that) so i dont know much about (object) == null

tepid summit
#

just personal projects

#

dm me anytime

#

use SetActive instead of disabling all the renderers

#

np my man

faint sluice
#

Could be an issue with duration of animation clip not syncing with the time you're using in script too

#

Also animation could be looping

tepid summit
#

oh i see

#

did you make sure to re-enable them at the start of the anim

faint sluice
#

Showing clip might help recognise the issue

trail heart
#

If your animator is controlling the sprite renderer's active status, it probably cannot be controlled from code
It's possible that blending to an animation that enables the sprite renderer causes it to switch too early, as booleans can't really be blended
Best to use code only for it at first

tepid summit
#

renderers

#

yeah i would just have the death in the anim, then use SetActive in a script

faint sluice
#

I would argue if disabling an object (especially a child object) is part of the animation, it should be done via animation not via script but depends on need i guess

trail heart
faint sluice
#

It's different thing tho if you want to disable object that are not children of animator

tepid summit
#
GameObject.SetActive(true);
#

@peak tide

honest haven
#

i have 2 scenes that i want to toggle between. rather then having 2 scenecan i have one scene with 2 scene?

tepid summit
#

you want a scene,

#

within a scene?

honest haven
#

yh so i have 2 scenes currently one is an arcade the other is a mini game(arcade game) and dont really want to carry all my DDOL to another scene like the player and game manager as they are not needed.

faint sluice
honest haven
#

and i dont to build the mini game as an ui

tepid summit
#

use a canvas and ui for the game

tepid summit
trail heart
#

A minigame can also exist in a prefab if you don't need a whole scene asset for it

honest haven
#

Well i could, will all objects work the same, can i use sprite renderer on a ui or will i have to swap things

trail heart
#

Whether it's UI or not doesn't make a difference in this case

honest haven
#

ok thank you. maybe ill try the UI approach then.

trail heart
#

Canvas is a component like any other, it's not concerned with how it's loaded in or out

#

So look into additive scenes and prefabs and decide which suits you better

honest haven
#

awesome thank you

faint sluice
#

Had an intern make 200 scenes for different levels in the game, i internally cringed so hard

timber tide
#

one scene all I need

faint sluice
#

Prefabs all the way babyy

trail heart
faint sluice
#

Turns out you just disabled a game object in scene that's enabled in every single scene but since you made duplicates of scene there's no way to confirm every single element is exactly same except for the "new level"

trail heart
#

You'll want to reuse prefabs within them anyway

faint sluice
#

Which surprise surprise, intern didn't

#

Every single scene was duplicate, and levels weren't prefab

trail heart
#

The nice thing about scenes is that there's the built in method to load them asynchronously, unlike prefabs, but the drawback is that you can't offset or rotate them if that's required

trail heart
# faint sluice Offset/rotate?

If you need to build say, a labyrinth from modular rooms, it's practical to have room prefabs and instantiate them at every connection point
But as far as I can tell scenes even when loaded additively can only be in the position they were originally created in
Unless you make an extra parent for all the objects in it and move that, but that's worth the trouble only in rare occasions

tepid summit
#
    public GameObject BoxObj;
    public GameObject BoxPref;
    public bool _Summoned = false;
    void FixedUpdate()
    {
        GameObject go = GameObject.Find("Box");
        if (go) {
            Debug.Log(go.name);
        } else {
            _Summoned = true;
        }
        if  (_Summoned)
        {
          GameObject newBox = Instantiate(BoxPref, this.transform.position + new Vector3(-1, 0, 0), this.transform.rotation); 
          _Summoned = false; 
        }
        
    }``` im trying to sset the bool to false so the cubes stop spawning but they wont stop when they start
faint sluice
#

Definitely desync between "respawn"/enable object

faint sluice
#

When are you enabling your character again?

rare basin
#

why are you doing such things in FixedUpdate

tepid summit
#

wait yeah

trail heart
#

If your animation event is used for respawn, try moving it one or two frames earlier

tepid summit
#

let me rearrange some thuings

rare basin
#

and why in Update type-methods at all

#

if you just want to do it once

tepid summit
#

wait

#

i havev an idea

rare basin
#

doing any Find-type methods every frame is terrible

faint sluice
#

The "gameobject.Find" in fixed update is giving me goosebumps

#

What a madlad

trail heart
#

Like we said, stick only to animation or code for the enabling/disabling, not both

rare basin
#

Find() in general is giving me goosebumps

faint sluice
rare basin
#

i was replying to you xd

faint sluice
#

Ahh my bad xd

tepid summit
faint sluice
#

I see in your animation clip at 1:15 (or end) you're doing something to your sprite renderer, what is it? Spill the beans

rare basin
#

why are you doing Thread.Sleep

#

it's not a good idea

#

make it a coroutine

#

IEnumerator

faint sluice
#

Look up "coroutines" in unity, pretty damn handy tools

rare basin
#

also you can extend that code by firing OnDeath event

faint sluice
#

Most used things after if and loops for me

rare basin
#
public UnityEvent OnDeath;

public void Death()
{
  //your code
  OnDeath?.Invoke();
}
#

then you can subscribe to that events via inspector (like in button's OnClick)

faint sluice
#

I would rather have that method be fired inside animation as event UnityChanwow

rare basin
#

still can do both

faint sluice
#

No need to check for delays and all

rare basin
#

if he wants to for some reason

#

but yea it's better to keep things in animation timeline

#

to be more precise

#

for example making footstep sounds, its much better to do it in animation events

#

instead of playing with delays lol

faint sluice
#

Yea

rare basin
#

no, what made you think that

#

public UnityEvent OnDeath;

#

write this in your script

#

then in your Death() method add this

#

OnDeath?.Invoke();

#

you will see that you can assign stuff in the inspector

#

and they will be called when the event has invoked

#

disable objects, enable objects, call methods from other components etc

#

idk if im not going to "deep", this might be kinda confusing to you at this level

faint sluice
#

Events may not be the easiest subject to grasp as beginner blushie

rare basin
#

they are not hard at all, but if you are just beggining then they might be, hard to say 😄

faint sluice
#

Me personally learnt to use them after 1 year of practicing lol, and still haven't found good use for them in the games we make

rare basin
#

at the end preferably

#

there is a common mistake of people firing the event, before actually doing "stuff"

#

like for example you have event OnDamageTaken

#

but you call it before calling the TakeDamage() method from healthsystem

#

and imagine you have healthbar assigned to that event

tepid summit
rare basin
#

and it's not updating properly

tepid summit
#

i wanted it to constantly be watching for the destroy

faint sluice
#

And check if variable is null

tepid summit
rare basin
#

don't

#

he's trying to do weird things

tepid summit
#

never done events before

rare basin
#

with instantiating in Update

tepid summit
#

im more confident with variables

faint sluice
#

Or yeah, use On destroy call back on the game object

rare basin
#

make it proper way

faint sluice
#

@tepid summit what are you trying to do exactly???

tepid summit
#

dw, ive got it

rare basin
#

i dont understand what do you mean

#

you are calling OnDeath event in your Death method

#

now you can subscribe things to that event

#

via inspector/or code

faint sluice
#

Lemme break it down for you

-> you touch spike
-> you call death method

Death{
Runs animation
OnDeath?.invoke()
}

MethodSubscribedtoOnDeath()
{
Wait until sprite is disabled
Respawn after x seconds
}

rare basin
#

you should really watch some basic tutorials

#

on animations and animation events

#

right now it's impoosible for you to understand what are we saiyng

faint sluice
#

Actually yknow what let's scrap the topic and start from scratch,

Where are you enabling the sprite from?

#

Is it only in the script or any other animation is enabling it too?

trail heart
#

Shouldn't do both

faint sluice
#

Ok so at start of death animation sprite is being enabled

Death animation lasts 1:15 and it's not looped

You're starting animation and death function at the same time

Death function re enables sprite after 0.5 second correct?

tepid summit
#

why

trail heart
#

Don't do it that way so then you won't "need to"
Either the animation or the code should be responsible for that, otherwise you'll have an awful time troubleshooting

vast saffron
#

guys should i learn coding while making a game? or without?

#

whats more efficient

#

i wanna learn game development

faint sluice
vast saffron
#

not much

#

beginner

#

just lil basics

#

thats it

slender nymph
vast saffron
#

i know how to use assets and that in unity but i cant really code

faint sluice
#

Well I would recommend beginner level c# courses on YouTube

vast saffron
#

ight

#

is it easy to learn C

#

C# without knowing maybe C

#

or python or any other language

slender nymph
#

you do not need to learn C in order to learn c#. do not go and learn one language for the sole purpose of then switching to another language to learn

outer scarab
#

Learning C# in todays world is easier than learning C.

vast saffron
#

ight yea some people told me to first learn idk python then java then C and C#

#

but i think

outer scarab
#

Nah

vast saffron
#

python and java are pretty boring

timber tide
#

c# better starting point

vast saffron
slender nymph
vast saffron
#

yea idk

#

i tried python shii was boring

faint sluice
#

Stick to one language until you actually understand the concept of programming (efficiently)

vast saffron
#

i was just lost lol

#

ight

#

thanks for the help

outer scarab
#

To be honest, if you learn one, learning the others will be easy.

#

Beginners often struggle with syntax.

timber tide
#

python is a little more intermediate I'd say because syntax is less verbose

vast saffron
#

yea imma try c# then

#

i just really wanna learn C# and C++ in my career

#

thats the 2 that i wanna be good at

twilit dirge
slender nymph
faint sluice
#

I would recommend c# over c++ as c# is easier to understand overall , atleast as first language

honest haven
#

if you learn the basics of vars,for,foreach,whiles and functions. you can pick up any language. the syntax is not the issue. its the thinking process. you can always google syntax.

vast saffron
#

imma stick to it

outer scarab
#

And if you really going to mess with cpp, give rustlang a try!

#

It's very fun

vast saffron
#

alright

#

imma start with C#

outer scarab
#

Good idea

#

🙂

vast saffron
honest haven
#

i think of it like this. say the problem was i had a hundred objects and i need to make sure each of them had a name. then the code break down would be i need an array and a for loop. then google the syntax

slender nymph
honest haven
faint sluice
honest haven
#

this is also good

outer scarab
#

I think giving suggestions is nothing bad, just depends on the type of suggestion.
As an example, someone who never learnt any programming language.. why would you tell him to start with C instead of C#?

#

Those guys will get frustrated fast

#

Like in C# he doesn't have to deal with pointers, he can easily do mistakes and IDE/compiler will tell him

honest haven
outer scarab
#

But "Learn Python first then Java" is a really stupid advice.

faint sluice
outer scarab
#

On the other hand, who knows Java well, almost knows C# well.

twilit dirge
slender nymph
#

use a serialized reference

faint sluice
twilit dirge
# slender nymph use a serialized reference

I try, but how can I do that if i need to refernece the editor class used to create the scriptableobject but i can't because it's in an editor foolder because it needs to be?

slender nymph
#

anything you expect to use at runtime should not be inside an Editor folder

#

on account of anything being inside the Editor folder will be included in the Editor assembly which is not included in a build

twilit dirge
#

It's the script to create the scriptableobject, i just need to reference the this specific scriptableobject itself

blissful vector
slender nymph
#

of course the ScriptableObject's script must not be in an Editor folder otherwise its type will not exist in a build

faint sluice
#

What is it?

outer scarab
twilit dirge
faint sluice
slender nymph
cunning rapids
#

Guys I have a problem with my animation and I was wondering if I can use a script to fix it.

I made a shotgun empty animation where the shell flies off the barrel when you cock it. The problem is, when I transition the animation back to the idle animation, the shell flies back into the barrel. I think what might be a good solution is something to do with scripting the bullet to stay invisible during the transition back, or something like that. I'm relatively new with Unity animations so help please (I can't provide a video in the meantime)

slender nymph
#

this seems like an #🏃┃animation issue
but you also have another keyframe way past that circled bit

twilit dirge
faint sluice
#

1:13 is doing what?

verbal dome
slender nymph
#

i'd bet the issue is exit time on the transitions. of course that still isn't a code issue.

verbal dome
#

@cunning rapids Play it with an animation event

cunning rapids
faint sluice
#

I would put dots at 2:00 same frame with "teleport" player so sprite is enabled as soon as teleport happens

verbal dome
#

Doesnt make sense to recycle one shell casing

cunning rapids
verbal dome
#

From a script

#

A method you call from an animation event @cunning rapids

slender nymph
#

ah yes, "buggy somehow" is super descriptive. this still doesn't seem like a code issue though and this is a code channel.

outer scarab
cunning rapids
#

I don't actually shoot out the shell

hidden bone
#

after a while of falling, the speed resets for some reason. is this a problem with unity or could it be a part of a script

slender nymph
#

probably your code. it seems to happen as you pass platforms

verbal dome
hidden bone
#

ok

faint sluice
cunning rapids
verbal dome
#

Why are you asking if you have a solution

cunning rapids
#

I suggested it making it invisible DURING the transition, not setting the position back in the animation

#

But that was a pretty stupid suggestion, the latter of them is better

verbal dome
#

Oh I thought you were being sarcastic at first lol

cunning rapids
#

Yeah I can see why, sorry bout that 😭

#

The tone sounded sarcastic

trail heart
#

@cunning rapids Animation events can be useful for that
Though they can be finicky with transitions too sometimes
I believe they fire off if the animation has any influence at all as part of the transition at the event's time

cunning rapids
#

That's the main problem with transitions tho, they completely ignore the final state of objects in the animation

verbal dome
#

Yeah, though if your method uses AnimationEvent as a parameter, you can check the event's animationClip's weight

#

To avoid events firing off at say, 0.1 weight

cunning rapids
#

I use an animator and the Play() method

#

Which is probably set for problem is the future since I can't set any conditions in the future

#

I think you need an animation trigger for that

#

Although I could be speaking nonsense since I haven't used the Unity animation system in a while

verbal dome
#

If you hide the shell while it is moving back, you dont even need to call a method, just animate the enabled toggle of the renderer (or gameobject)

cunning rapids
#

Yeah that makes sense

trail heart
cunning rapids
#

Anyways, thanks for your help guys :)

verbal dome
#

Yeah dont think I ever used Play

cunning rapids
verbal dome
#

Man I kinda wanna get Animancer.
Mecanim seems so restricted

trail heart
#

Animator gives you a lot of power to automate things, but that's kinda the only efficient way to use it
And even if you optimize the need of transitions to a minimum, they're still a lot of clicking to make

cunning rapids
trail heart
#

Most people don't care about animator state machines (and don't realise they actually need them)

faint sluice
#

I thought they were some anime website

verbal dome
faint sluice
#

Felt so lost

cunning rapids
cunning rapids
#

How long ago?

verbal dome
#

Idk I think I started with Unity 5 and it was integrated into unity then

#

So yeah a long time ago

cunning rapids
verbal dome
#

Thinking of building a custom layer on top of mecanim to support different crossfades, regional "events" etc.

#

But maybe Animancer can do all that

cunning rapids
#

For more complex animations like walking you can just use procedural, no?

verbal dome
#

I do use procedural stuff for foot placement etc.

#

It's just not as efficient or good looking if you only have procedural animation

cunning rapids
#

How so?

verbal dome
#

Well you have way more artistic control when you hand animate things

earnest atlas
#
       var rClouds = _clouds.GetComponent<SpriteRenderer>();
       _xClouds = rClouds.sprite.rect.width;```

I have images that are tiled, I want to get their size on X axys without taking the tiled repetitions.
cunning rapids
earnest atlas
#

I want to move them X amount of spaces before teleporting them back when they reach the border

earnest atlas
#

Wont this give me entire image size?

cunning rapids
#

Yes

#

Don't you want that?

#

It will ignore the tiling

earnest atlas
#

No, its tiled so moving the entire image will move the tiled no?

cunning rapids
#

It will instead return the actual size of the sprite in thr world space rather than counting tiling

#
_xClouds = rClouds.bounds.size.x;```

Like this
earnest atlas
#

Welp lets see what it gives me

cunning rapids
#

Try it, maybe it's what you're looking for

earnest atlas
#

Great it gives me NoReff because serialize field for some reason broke

#

Yeah evrything has it just does not count it as serialized

cunning rapids
#

Give more details of the code

earnest atlas
#

I have deleted and saved it again and now its working after I added it again

cunning rapids
#

Oh alright

earnest atlas
#

Great now all of them unlinked

cunning rapids
#

Dude

earnest atlas
#

I hate unity

cunning rapids
#

Just... give more details

cunning rapids
earnest atlas
#

YES

#

As I mentioned its broken garbage

#

Im restarting entire thing

cunning rapids
#

2D isn't my field of expertise so idk what's going on here

slender nymph
# earnest atlas I hate unity

this warning is because you are not assigning it anywhere in code. this is normal because visual studio does not know that you've assigned a reference in the inspector for one of your objects

cunning rapids
earnest atlas
#

No it works correctly in other places

#

Its just decided to act special

cunning rapids
timid saffron
#

is _skybox a local variable now? we don't use = in c sharp?

slender nymph
slender nymph
earnest atlas
#

I will need them later to use transform on them

cunning rapids
#

No need for a script unless you want to periodically change it

slender nymph
#

use the type of component you actually need access to in your code

cunning rapids
slender nymph
#

sure if you only need to use the Transform. otherwise use the actual component you care about. every component has a reference to its transform

timid saffron
#

like var asdadas = 3;

rare basin
#

do you know what is a local variable?

timid saffron
#

in gamemaker i used them

rare basin
#

this is definitely not a local variable

#

you can acces _skybox from any function

timid saffron
#

so this is a script then?

rare basin
#

what?

cunning rapids
#

Works the same

rare basin
#
void Update()
{
   int variable;
}
#

this is a local variable

#
int variable;

void Update()
{
   
}
#

this isnt

vast saffron
#

is c# the best for game development?

rare basin
#

there is no answer for such question

#

is lamborghini the best car?

vast saffron
#

why is that

cunning rapids
#

Minecraft was coded in Java

earnest atlas
#

Java script is yhe best

rare basin
#

preferences, project needs

cunning rapids
#

Tf2 in Python and C++

rare basin
#

skill

vast saffron
rare basin
timid saffron
rare basin
#

that is the purpose of doing a LOCAL variable

#

so its only available LOCALY

timid saffron
#

well Im asking because in gamemaker you could use a local variable

#

outside of the code block

#

by using scripts

rare basin
#

try it

#

and see

cunning rapids
rare basin
#

local variables aren't engine specific things

verbal dome
rare basin
vast saffron
rare basin
#

C++ might be more complex to start with, with header files, pointers etc

vast saffron
#

where can i find it

#

on yt?

rare basin
cunning rapids
verbal dome
#

Check the pina on this channel

rare basin
#

simple racing game is easy to make

vast saffron
rare basin
#

realistic car behaviour? nope

vast saffron
#

but it had many bugs

vast saffron
#

simple

rare basin
#

go for it then

cunning rapids
# rare basin depends

Wheel colliders and setting the different physics properties of your car can be gruelling for a beginner

#

Such as myself

rare basin
#

he doesnt need to use such things

verbal dome
rare basin
#

if he wants to make just a simple game

vast saffron
#

it feel across the map

rare basin
#

but for the first projects

#

you might wnat to do something easier

#

like pong game or sth

vast saffron
#

i said

#

i want to make a simple one

#

not a complicated one with realistic driving physique

cunning rapids
rare basin
#

why is that?

vast saffron
rare basin
#

weird statement

#

you can learn how components works, how to make proper connection/references between scrvipts etc by making pong

cunning rapids
#

Learn basic programming structure, terminology, and syntax before worrying about other stuff

rare basin
#

then you can extend it by making powerups, fancy animations etc

#

Unity isn't overkill for anything

vast saffron
#

is c# good for pong?

#

i just wanna focus on one language

rare basin
#

that's not related

vast saffron
#

many people do it with idk python

#

or smnth like that

vast saffron
rare basin
#

you can do pong in c#, c++, java

#

whatever

verbal dome
#

You gotta realize that the language doesnt really matter

rare basin
#

there is no such thing as "whats better language for X game"

vast saffron
#

alright

#

imma learn c# then

rare basin
#

good luck

vast saffron
#

while learning unity

#

thanks

cunning rapids
#

Otherwise Python might be a better fit

cunning rapids
#

Because Python is great for more branches of programming when it comes to terms of security or software engineering

verbal dome
#

We talking games though

rare basin
#

but they meant exactly in the game dev context

verbal dome
#

Performance is probably the biggest difference between languages

#

C++ is fast but I just love working with C#

cunning rapids
#

It's possible to implement Python in games, but usually, C-based languages are used in stuff like gane engines

timid saffron
#

can you tell me whats wrong? when I press play the image I set doesnt apear in game

#

I think I did everything correct

#

I dont see any issues myself

rare basin
#

_skybox is null

#

so it doesnt "enter" the if

verbal dome
#

OnEnable might run before Awake

#

Also the <= should be <

slender nymph
rare basin
#

put ChangeSkybox(0); in Start() for example

verbal dome
#

Does the skybox component exist already or is it added via RequireComponent?

timid saffron
verbal dome
#

I wonder if reqcomp would cause issues

timid saffron
#

thats why

verbal dome
#

Not at Count

rare basin
#

3 elements at list = 3 Count

#

but the last index is 2

rare basin
timid saffron
#

skybox

verbal dome