#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 514 of 1

timber comet
#

For the client authorative

#

From GitHub

#

Wait I can find the link for you

rich adder
#

if you're talking about the Client Network Transform that doesn't change how the system fundamentally works, only the movement

devout flume
#

Ah yes, super cool

#

"Expert" level

rich adder
#

oh boy..

timber comet
# rich adder if you're talking about the Client Network Transform that doesn't change how the...
GitHub

A small-scale cooperative game sample built on the new, Unity networking framework to teach developers about creating a similar multiplayer game. - Unity-Technologies/com.unity.multiplayer.samples....

drifting geode
#

Hi I can't seem to figure out why my OnDrag() method is not working

queen adder
#

show code

rich adder
rich adder
drifting geode
drifting geode
#

Its just attached to an image

rich adder
#

do you have an Event System gameobject ?

drifting geode
#

Ohhh I see, sorry i thought that it is always created automatically and forget about it

frank flare
#

tbh that looks pretty hard

summer shard
#

what would be performance better, world space ui rotating towards player's camera or screen space ui setting it's position to object's position

rich adder
#

pool them and you should be okay with either one

#

Overlay iirc is always slightly more performant than world

summer shard
rich adder
#

oh nvm this is just 1 UI i wouldn't worry, i was assuming you meant other types of UI like healthbars / texts around your world

summer shard
#

nah like interaction ui

#

sum like watch dogs have

rich adder
#

just make it how it looks best to you then, don't worry about performance those can be easily localized so its not that much impact

#

for example I only need 1 world canvas (player is holding interactable tablet to inspect items)
switching it to other data read from SO, but its the same canvas

zenith cypress
steep rose
devout flume
#

If they ever ask me to use GPT again (or any other AI), I think I'll explode

night valve
#

Omg what ๐Ÿคฏ

steep rose
#

They recommend AI? ๐Ÿซ 
I believe there is a better tutorial on unity by Imphenzia IIRC

#

EXPAND for Time Stamp Links -- This is the most basic Unity tutorial I will ever make. If you are brand new to Unity, or if you want to make sure youโ€™ve covered the basics, and if you want to learn how to write your first C# script - this is the video for you!

Over the course of 2 hours, I go through the User Interface, Game Objects, Transforms...

โ–ถ Play video
night valve
#

Most fun part is they recommend ai to generate a script that slowly rotates directional light

#

For experts. IG expert would waste more time chatting with ai than writing such script

steep rose
#

instead of talking to an ai just look on google and you will most likely find whatever you need

night valve
#

I believe it's there just as curiosity. On the learn site they should encourage doing everything by yourself

frank flare
#

So I'm trying to make something similar to Human Fall Flat without active ragdolls cus it seems to be too hard. Right now I'm trying to make ragdolled player stand up (rotate) by forces. How can I do that?

My scripts:
PlayerMovement: https://hatebin.com/nbbmviywid
PlayerCam & MoveCamera: https://hatebin.com/kdermrhkac

float maxVelocity = 5f;
Rigidbody localRb;
void Start()
{
localRb = GetComponent<Rigidbody>();
}

void FixedUpdate()
{
    float x;
    float y;
    float z;
    x = localRb.position.x;
    y = localRb.position.y + 1f;
    z = localRb.position.z;
    float localY = -1 * (localRb.position.y - (localRb.position.y + 50f));
    Debug.Log($"Y to aim: {localY}");

    
    Debug.Log(localRb.velocity.y);
    if (localRb.velocity.y < maxVelocity)
    {
        Debug.Log(localRb.velocity.y);
        localRb.AddRelativeForce(0, localY, 0);
    }
}
eternal needle
summer shard
#

how can i check if hitObject contains any script that extends or implements Interactable class

void HandleInteraction() {
    if (!canInteract) { interactable = null; return; }
    RaycastHit hit;
    
    if (!Physics.Raycast(cameraHolder.position, cameraHolder.forward * interactionDistance, out hit, interactionDistance)) { interactable = null; return; }

    GameObject hitObject = hit.collider.gameObject;
    Interactable hitInteractable;

    if (!hitObject.TryGetComponent<Interactable>(out hitInteractable)) { interactable = null; return; }

    interactable = hitInteractable;

    if (Input.GetKeyUp(interactable.getInteractionKey())) {
        interactable.Interact();
    }
}
slender nymph
#

using TryGetComponent like you're doing now

summer shard
#

fr? thanks also should i implements Interactable or extends Interactable

slender nymph
#

neither, it's inherits Interactable

summer shard
#

ohhh thank youu

slender nymph
#

unless you are asking how to do so, in which case look at the current code and see how you are inheriting MonoBehaviour

summer shard
#

okayy, thankss

eternal needle
summer shard
#

yeaa i realized that they're both kind of simmilar

#

also if class Interactable already inherits MonoBehaviour then i should only inherit Interactable in pickable class?

public class Interactable : MonoBehaviour {

}

public class Pickable : Interactable {

}
slender nymph
#

yes. you can only inherit one class. but when you inherit Interactable you are also inheriting MonoBehaviour because Interactable is a MonoBehaviour

summer shard
#

okay thank youu

frank flare
summer shard
#

dumb question, is there a way to hide all the variables from inherited class in the inspector but leave it shown in the inspector for the parent class

slender nymph
#

why would you be inheriting the class if you don't want access to those?

summer shard
eternal needle
slender nymph
summer shard
#

i want to make Pickable class to be able to pick things up but don't want to add Interactable script each time to the object and setting the event to pick up the object so i wanted to inherit the class to call picking up the object whenever the interaction is called

frank flare
slender nymph
eternal needle
frank flare
summer shard
slender nymph
#

you don't override variables.

summer shard
#

i just didn't add it yet

slender nymph
#

right and you can't add that at all because that's not a thing

summer shard
#

wdym??

slender nymph
#

i mean that you do not override variables like i already said. that is not a thing. you just assign a different object to it

summer shard
#

so basically i can't override the variables but i can override the methods?

slender nymph
#

correct. and that is only methods that you explicitly mark as virtual because this isn't java

summer shard
#

oh yea ik that, but what do i do with all these variables that i don't use anymore? they're just shown in the inspector, like i can change them but i'll still return something else

slender nymph
#

why would your class have variables that it does not use

summer shard
clever raven
#

Hello, would anyone be able to help me figure this out. I have nodes that I am using for A* pathfinding, I want the NPC's in my game to increase the cost of nodes so they don't get pathed through but when I do that, it breaks their movement (due to the increased costs) is there a smart way to do this? I currently have all the NPC's on a layer and use layers to calculate node costs.

slender nymph
eternal needle
frank flare
eternal needle
# frank flare ok so I shouldn't try the Human Fall Flat idea

๐Ÿคทโ€โ™‚๏ธ if you want to make a game similar to it that's up to you. Im not trying to stop you, it's also not a bad way of experimenting with rbs and joints. It's just really tough to setup and get working how you want. If every part of the object isnt a rb, they wont react in the same way as human fall flat. I've tried the same before, got the joints setup, hand movements, etc, but it was all just so clunky. The walking was horrible too
Then you realize human fall flat is boring alone and it only works cause of multiplayer

slender nymph
#

!code

eternal falconBOT
slender nymph
#

you're also missing the using directive. right click the error in your IDE and use the quick actions to add the correct using directive

#

if you do not see it in your !IDE then get it configured ๐Ÿ‘‡

eternal falconBOT
slender nymph
#

go through all of the steps to configure it

polar acorn
#

Is your error underlined in red

#

Then you need to configure your IDE

slender nymph
#

screenshot your entire IDE window with the solution explorer visible

#

close visual studio, regenerate the project files, then open it again

#

no, close it. then regenerate the project files. then open it again.

#

there is a button to do exactly that in one of the locations you had to do something in when configuring visual studio

#

did you follow the instructions i just gave you?

#

or even look at the instructions the bot linked?

#

great! then go through that and find that regenerate project files button and click it

polar acorn
#

Do you see a button in this screenshot that says "Regenerate project files"

slender nymph
#

depends on your keyboard layout

polar acorn
#

Capital \

slender nymph
#

there are over a dozen qwerty layouts. it still depends on which one

#

in us and uk qwerty it is shift+\

topaz fractal
#
using System.Collections.Generic;
using UnityEditor.TerrainTools;
using UnityEngine;

[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]

public class WaterManager : MonoBehaviour
{
    private MeshFilter meshFilter;
    
    private void Awake(){
        meshFilter = GetComponent<MeshFilter>();
    }

    private void Update()
    {
        Vector3[] vertices = meshFilter.mesh.vertices;
        for (int i = 0; i < vertices.Length; i++)
        {
            vertices[i].y = WaveManager.instance.GetWaveHeight(transform.position.x + vertices[i].x);
        }

        meshFilter.mesh.vertices = vertices;
        meshFilter.mesh.RecalculateNormals();
    }
}



#

what part of this code makes the waves go up and down slightly?

#

or is there nothing?

steep rose
#

Im guessing the part where it loops through every vertex and gets it Y value and changes it to some arbitrary value

#

so pretty much the code in Update(), what was the premise of this question?

topaz fractal
#

when i set the scale to 1, it fixes the issue

#

heres the other script which the other script uses the "GetWaveHeight" float

#
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.PlayerLoop;

public class WaveManager : MonoBehaviour
{
    public static WaveManager instance;

    public float amplitude = 1f;
    public float length = 2f;
    public float speed = 1f;
    public float offset = 0f; 

    private void Awake()
    {
        if(instance == null){
            instance = this;
        }
        else if (instance != this)
        {
            Debug.Log("Instance already exists, destroying object!");
            Destroy(this);

        }
    }

    private void Update()
    {
        offset += Time.deltaTime * speed;
    }

    public float GetWaveHeight(float _x)
    {
        return amplitude * Mathf.Sin(_x / length + offset);
    }
}
#

what in this code would i have to multiply by 10

#

in the original code it was intended to just be 1x1

#

i have changed the size to 10x10

steep rose
#

have you tried using offset?

#

wait before we go on, what was the issue?

clever raven
#

Anyone have any tips how to recalculate pathfinding for dynamically changing node costs for example if the player moves in the way of the path calculated via A* how to tell the AI to calculate a new path

steep rose
#

you would just call your pathfinding function again and to the position you want on the grid/navmesh

#

A* should calculate new paths depending on if the node moves or not anyway

#

oh sorry I didn't read your message fully, A* should just calculate the path automatically if any of the node costs changes, I don't know if the built in navmesh system in unity does though, it probably does but I have not tested it

polar acorn
#

Well, start with reading the errors. What's the first error say?

midnight wave
#

it says im missing a directive or assembly reference, but i feel confused because i was following along with my professor in class 4916catcry

polar acorn
midnight wave
#

this is what it says about them

polar acorn
#

So, what is a throwScore?

#

You cannot apply indexing with [] to an expression of type IEnumerable.

midnight wave
#

ohh okay i see

polar acorn
#

Reading the error explains the error

midnight wave
#

im sorry i wish i had better answers for you guys. im not sure yet the types all i know is hes trying to teach us how to keep track of the points from throwing a bowling ball at pins

keen owl
#

So that would be an int iโ€™m assuming?

polar acorn
#

what kind of thing

midnight wave
#

youre probably right

#

im so sorry im not trying to be stupid i just genuinely have no idea im so sorry

north kiln
#

You can't just have no idea what it is, you're the one writing the code

polar acorn
midnight wave
#

the context of the situation is i watching a recorded class and this is what he was teaching me and i wasnt sure about what it is at all so im just writing what he was giving me, im not sure about everything yet. but while his was working in the recording mine wasnt

north kiln
#

then compare your code against theirs and see what's different, and understand that difference

#

digi reading their pencil to record a mark in the tally

polar acorn
#

So, tell me, what is throwScore

#

What does it do

#

why is it there

polar acorn
keen owl
rich adder
pearl lintel
#

Hi guys, long story short I am trying to practice car controllers and mechanics and for some reason, Unity is recognizing forward Input as -1 and backwards input as 1. This is essentially messing up my game because when trying to add audio when reversing / accelerating it is flipping the sounds because it thinks I am reversing when driving forwards. This is not about what keys are being used its about how it effects the scripts and how the game recognizes inputs. I have tried fixing this for a couple hours and even used chat-gpt but nothing can flip these values. Hopefully you guys can help. Btw, sorry if this is a stupid question, I am new to development. Thanks!

#

To be more clear, I want it so when I drive forward. I want the gas input to = 1 and when reversing I want the gas input to = -1

rocky canyon
#

Input.GetAxisRaw("Vertical");

#

hows ur audio code look?

#

even used chat-gpt but nothing can flip these values
this is not saying much ๐Ÿคฃ ... chat-gpt is regurgitated junk most often

pearl lintel
#

Thanks for the reply. Quick question, could it be the asset I am using that causes the problem?

#

Its as if the game thinks the back of the car is the front and vice versa

#

when I try -Input.GetAxis("Vertical"); it just flips the forward and backwards keys. I need it to actually flip the number

clever raven
#

or smarter logic when it comes to setting up nodes / costs

#

Or maybe I just don't make the NPC's increase path cost and instead add some sort of steering or replusion or something to get them to not run into each other

#

If anyone has any advice on how to make A* pathfinding that also avoids collusions with changing node costs would love to hear it

#

The collider on my NPC's is a polygon 2d one so it makes 8/9 of the nodes that the npc takes up as npc 50 cost nodes and the one in the top left corner a 2 cost node so they always go to the top left as well :/

rocky canyon
pearl lintel
#

void CheckInput() { gasInput = Input.GetAxis("Vertical"); steeringInput = Input.GetAxis("Horizontal"); slipAngle = Vector3.Angle(transform.forward, playerRB.velocity - transform.forward); float movingDirection = Vector3.Dot(transform.forward, playerRB.velocity); if (movingDirection < -0.5f && gasInput > 0) { brakeInput = Mathf.Abs(gasInput); } else if (movingDirection > 0.5f && gasInput < 0) { brakeInput = Mathf.Abs(gasInput); } else { brakeInput = 0; }

#

This is my movement script

rocky canyon
#

and the audio is where? what variable do u want to output for each case?

pearl lintel
#

Its a bit hard to describe because im just learning game dev

#

But essentially, because the game engine thinks acceleration is actually reversing. The audio script thinks when I am physically driving forwards with the car model, it is actually reversing. And when I reverse, the game engine thinks I am driving forwards thus playing the acceleration audio.

#

And the issue is, I have no idea why vertical "Up" input is being registered as -1 input when typically it should be 1 input

umbral prairie
#

in tilemap how do i make for example a water tile make it so the player cannot walk through it like a wall barricade

#

do i use tilemap collider 2D?

pearl lintel
#

Could it be the model I am using perhaps?

#

Maybe the front of the car is actually the back?

#

I just downloaded the asset to practice with

#

Its really strange lol

#

I'm just gonna try reverse engineer the code to the best of my ability, thank you so much for the help though ๐Ÿ˜„

rich adder
#

also not a code question

arctic ibex
#

this is less of a how to code question and more of a "what the better way to do this" I have a scene with a list of levels, and i have two ways of assigning the level to each. I can 1. Manually assign it, currently theres only 7 so it will be easy, but i want like, 40+ in the future so it will be annoying to reassign things.
2. Give all of the texts with the levels the same tag, and use FindObjectsWithTag to get an array of all of them and make each one pick its order in the array. Each text object already has its own script on it to calculate what i need to say

eternal needle
# arctic ibex this is less of a how to code question and more of a "what the better way to do ...

2nd option doesnt even really sound like it'll work nicely, im not sure the order of that function is even known. you'll still be going through the trouble of creating text objects for each level. at that point you might as well just assign the scene at the same time
imo a better way, have an array of the scene names. then create the text at runtime for each string in the array, and assign whatever is needed at the same time
assigning the scene names can also be done very easily with SceneAsset and taking the name in OnValidate

umbral prairie
arctic ibex
eternal needle
#

what i described is honestly pretty easy, the hardest part is setting up the UI so that the generated text objects are where u want it to be

arctic ibex
#

hey quick questoin, when you instantiate a prefab can you choose the parent?

lapis yew
#

Instantiate(Object original, Transform parent);

arctic ibex
#

oh cool

woeful schooner
#

so, i wanna think im just making some sort of silly mistake here that i can fix, but it really looks like unity is just objectively wrong with its math here?

woeful schooner
#

what exactly is the issue though
should it not be logging a float, since im explicitly casting it as one?

astral falcon
#

the float still is just set with the calculation done with two integers. as jammingend said, cast one to float

lapis yew
#

*** = (float)currentammo / max ammo

woeful schooner
#

ah yep that fixed it
thank you so much <3

lapis yew
#

๐Ÿ˜‚

woeful schooner
#

lmao awesome

astral falcon
#

But it should be an integer, anyways, right? ๐Ÿ˜„

#

or are you able to shoot partial bullets ๐Ÿ˜„

#

Just jkin, I guess its for some visual ammo representation or similar?

woeful schooner
#

oh nono im using this to scale a little indicator meter for ammo on the gun
its just a simple project for uni so im modelling everything in engine with prefabs, so i have it like this

lapis yew
astral falcon
queen wren
#

I have an image and I am breaking it into smaller cells.
Cach cell is stored in a Dictionary <Vector2Int>, <Texture2D>, then I iterate through the dictionary to recreate the grid.

Each cell has a prefab with a button, and the cell has a TerrainType class that has a variable to store the image.
So while iterating through the dictionary I pass the texture to the button but when I go to check the variable in the Cell.terrainType.splatMap class the texture doesn't match!

Debug says:
Generated and stored textures for cell 0,0. Splat texture name: splat_0_0

then:
Creating cell 0,0 with splat texture: splat_0_0 (and it's true because the texture in button is correct!
but the Cell.TerrainType.splatmap has 47.21 (which is the last cell)

Why?
Can somebody tell me what is going on?? ๐Ÿคฏ

#

The code is fine... I guess, because the in the cell I take the TerrainType.splatMap and I assign it to the background of the cell and the texture is correct:

{
    public TerrainType terrainType;
    public Vector2Int pixelReference;
    [SerializeField] private Image buttonImage;
    [SerializeField] private RawImage backgroundImage;

    public void SetTerrainType(TerrainType terrain)
    {
        terrainType = terrain;

        if (terrainType.splatTexture != null)
        {
           
            backgroundImage.texture = terrainType.splatTexture;

        }
    }
}```
#

I guess that could be a Unity's memory issue.

astral falcon
#

What is TerrainType?

queen wren
# astral falcon What is TerrainType?

A subClass

 public class TerrainType
 {
     public BiomeType biomeType;
     public Color color = Color.black;
     public float height = 0;
     [Space]
     public Sprite sprite;
     public TerrainLayer layer;
     public Texture2D splatTexture;
     public Texture2D heightTexture;
 }```
astral falcon
#

And how do you generate your buttons? That code is probably the one failing, because you seem to overwrite something in the loop

#

especially your terrainType = terrain is generating a reference to terrain instead of a copy, so you might change the terrain object later on and your terrainType gets updated with each iteration in your loop

queen wren
# astral falcon And how do you generate your buttons? That code is probably the one failing, bec...
{
    RectTransform gridRectTransform = grid.GetComponent<RectTransform>();
    float cellWidth = cellPrefab.GetComponent<RectTransform>().sizeDelta.x;
    float cellHeight = cellPrefab.GetComponent<RectTransform>().sizeDelta.y;
    int numCellsX = Mathf.CeilToInt(gridRectTransform.rect.width / cellWidth);
    int numCellsY = Mathf.CeilToInt(gridRectTransform.rect.height / cellHeight);

    for (int y = 0; y < numCellsY; y++)
    {
        for (int x = 0; x < numCellsX; x++)
        {
            Vector2Int cellCoord = new Vector2Int(x, y);
            Vector2 cellPosition = new Vector2(cellWidth * x, -cellHeight * y);

            
            if (!splatTextures.ContainsKey(cellCoord) || !heightTextures.ContainsKey(cellCoord))
            {
                Debug.LogError($"Missing textures for cell {x},{y}");
                continue;
            }

            // Dictionary Recover
            Texture2D splatTexture = splatTextures[cellCoord];
            Texture2D heightTexture = heightTextures[cellCoord];

            Debug.Log($"Creating cell {x},{y} with splat texture: {splatTexture.name}");

            GameObject newCell = Instantiate(cellPrefab, grid.transform);
            newCell.name = $"cell_{x}_{y}";

            TerrainType terrainType = mapGenerator.GetTerrainTypeFromTexture(splatTexture);

            terrainType.splatTexture = splatTexture;
            terrainType.heightTexture = heightTexture;

            Cell cellComponent = newCell.GetComponent<Cell>();
            cellComponent.pixelReference = cellCoord;
            cellComponent.SetTerrainType(terrainType);

            RectTransform cellRect = newCell.GetComponent<RectTransform>();
            cellRect.anchorMax = new Vector2(0, 1);
            cellRect.anchorMin = new Vector2(0, 1);
            cellRect.pivot = new Vector2(0, 1);
            cellRect.anchoredPosition = cellPosition;
        }
    }
}```
astral falcon
#

Did you debug log your terraintype when assigning in your cell to see, what numbers you get there?

#

And also logging this mapGenerator.GetTerrainTypeFromTexture(splatTexture) might be important, as maybe this one gets you the wrong type or something. You really gotta log more into your separated classes to actually get the correct updates that are being set

queen wren
#

Ok, I'll do a couple of tests.

queen wren
#

See.. the code is correct (tha's the debug):
WorldGrid: Creating cell 0,0 with splat texture: splat_0_0
WorldGrid: Assigning Splat Texture to TerrainType splat_0_0
Cell: cell_0_0, TerrainType assigned with splat texture splat_0_0

but the terrainType in the cell_0_0 still have the splat_41_21 which is the last cell. and not only the cell 0_0 but all the cell from 0_0 to 0_41 and forward until the texture didn't change the color because it's an island.

summer shard
#

should this interface be named IInteract or IInteractable

public interface IInteract {
    public void Interact();
    public void SetCanInteract(bool canInteract);
    public bool GetCanInteract();
    public KeyCode GetInteractionKey();
}
swift elbow
#
        {
            instance = this;
        }```
why doesnt this produce an error?
summer shard
swift elbow
summer shard
#

oh didn't realize

summer shard
#

if the assignment is considered true, then it'll set the instance to this

swift elbow
summer shard
summer shard
# swift elbow how am i assigning it if its in an if statement?

A single equals operator is an assignment operation, and will evaluate to whatever value was finally assigned to the variable. If the value assigned was not an integer 0, then the result will be "true" for any conditional statement, so the result is not "always true." The compiler should give you a warning if I recall correctly

swift elbow
queen wren
#

Inside a loop this could be enough to be sure that the variables get reinitialized?

Texture2D splatTexture = new Texture2D((int)cellSize, (int)cellSize);
splatTexture = splatTextures[cellCoord];
Texture2D heightTexture = new Texture2D((int)cellSize, (int)cellSize); 
heightTexture = heightTextures[cellCoord];```
eternal needle
proper yacht
#

What's better to use or what you prefer and why
Example:
Here we define all through Header and drag and drop our class' RigidBodyComponent through Inspector

[Header("Refs")]
public Rigidbody rb;

void FixedUpdate()
{
  some code with rb
}

or this all within code


private RigidBody rb;

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

void FixedUpdate()
{
  some code with rb
}
#

And who knows should I start with learning netcode first or that's too complicated for beginners?

eternal needle
swift elbow
queen wren
#

@astral falcon I've fixed the issue! ๐Ÿ™‚
but I'm not sure how ๐Ÿ˜‚

Texture2D heightTexture = heightTextures[cellCoord];

GameObject newCell = Instantiate(cellPrefab, grid.transform);
newCell.name = $"cell_{x}_{y}";

Cell cellComponent = newCell.GetComponent<Cell>();
cellComponent.pixelReference = cellCoord;
TerrainType terrainType = cellComponent.terrainType;
TerrainType mapTerrain = mapGenerator.GetTerrainTypeFromTexture(splatTexture);
terrainType.layer = mapTerrain.layer;
terrainType.height = heightTexture.height;
terrainType.splatTexture = splatTexture;
terrainType.heightTexture = heightTexture;```

in short looks like that the method mapGenerator.GetTerrainTypeFromTexture(splatTexture);
which returns an object of type TerrainType whic was the class that I show early was doing some mess with memories. so I've made a new instance of TerrainType `TerrainType mapTerrain = mapGenerator.GetTerrainTypeFromTexture(splatTexture);
`
on every loop cycle, and then took the terrainType from the cell and assigned each value one by one. Quite a mess, but now it's working fine.
#

What we learned:

  • Direct references can avoid conflicts: Especially when working with Unity objects like textures or ScriptableObjects, it is important to understand how references are handled in memory.

  • Debugging with Unity requires patience and continuous testing: Sometimes Unity issues involve internal resource management and reference assignment, so step-by-step debugging is often the best way to solve them.

๐Ÿ˜…

wooden sandal
#

Still cant get my list to be correctly sorted... i never worked with sorting, so i dont know what to do...

I grab sprites from a folder with Ressources.LoadAll. They are all named "Level 1" up to 11. But they are somehow saved in this binary format, like shown in the pic.

i tried "previewSpriteList.Sort((a, b) => a.name.CompareTo(b.name));" on the sprite liste and more nothing does a thing

keen dew
#

That's how alphabetical sorting works. If the names are always "Level X" then you can do previewSpriteList.Sort((a, b) => int.Parse(a.name.Substring(6)) - int.Parse(b.name.Substring(6)));

wooden sandal
frank zodiac
#

Whats the convetion order of variables in a c# class? (e.g static variables always on top)

teal viper
burnt vapor
#

Your sorting is correct, this is how sorting works

#

I already told you to just make a loop from 1 to 11, and to then load the images based on the index that it's on

#

Also, please share your !code already so that I can just write it for you

eternal falconBOT
burnt vapor
#

I also told you the substring approach days ago, so idk why you didn't just look for given answers then

#

Note that it's very hacky as I explained then

keen cargo
#

hey yall, quick question -

so i'm trying to do this super simple thing where player presses a button, and a particle effect that i've attached to the player plays

however there's this weird issue where the particle effect just stops existing when i run the game, i get an error that there's no particle effect attached, even though in the screenshot i have it attached

eager spindle
#

There is no particle system attached to the player

#

Did you instantiate the gameobject with the particle system?

#

What does your code look like?

keen cargo
#

they're set up like this

slender nymph
north kiln
#

Also, as it's serialized just don't try to assign it in code

keen cargo
#

ahh i see

#

yeah the getcomponent was unnecessary

#

thanks yall

quiet gazelle
#

if I have a UnityAction test, can I clear all event handlers of that action in such a way that will allow me to add new listeners?

slender nymph
#

UnityAction is just a delegate, just assign it to null to clear its listeners. if you mean a UnityEvent, then it's basically the same thing but you just invoke its constructor

#

or UnityEvent has the RemoveAllListeners method which removes all non-persistent listeners (persistent listeners are the ones added via the inspector)

sweet brook
#
public class orange_text : MonoBehaviour
{
    public GameObject orangetext;
    public TextMeshProUGUI textMeshPro;

    public void Start()
    {
        orangetext.SetActive(false);
    }
    public void OnMouseDown()
    {
        orangetext.SetActive(true);
    }
}

Heyy how do I make orangetext inactive again when clicking once more?

slender nymph
#

use !orangetext.activeSelf rather than the true literal

languid spire
#
orangetext.SetActive(!orangetext.activeSelf);
sweet brook
slender nymph
#

note how i didn't type "isActiveSelf"

languid spire
#

my bad

sweet brook
#

ohhh ok thanks!!!

steep rose
#

yes you are

#

posting in unrelated channels is crossposting

#

what?

#

you are talking about cinemachine

#

not URP

eternal needle
#

You've been told to stop cross posting multiple times now. Dont be surprised when people dont wanna help if you wanna ignore rules

languid spire
#

posting in 3 code channels is what then?

steep rose
#

that does not make any difference

#

wait you got help from spazi

rotund garnet
#

Are there any good methods of sorting a 1 Dimensional list of objects, each having "x" and "z", (x increasing left to right) & (z increasing from bottom to top) ??

example of what the array could look like: [{-1, 0}, {0, 1}, {1, -1}, {0, 0}, {-1, -1}, {1, 1}, {0, -1}, {1, 0}, {-1, 1} ]

and the sorted array would look like this:

[{-1, 1}, {0, 1 }, {1, 1}, {-1, 0}, {0, 0}, {1, 0}, {-1,-1}, {0,-1 },{1, -1}]

so when placed into a tile pattern it would resemble the numbers in a regular coordinate system.

:
[{-1, 1}, {0, 1}, {1, 1},
{-1, 0}, {0, 0}, {1, 0},
{-1,-1}, {0,-1}, {1,-1}]

There must be some fancy math to sort this... or mabye not... idk plz help :))

hope its understandable :)

languid spire
#

by the looks of that it's just a simple case of adding 1 to each number

rotund garnet
#

forgot to mention, that the numbers can be higher or lower, but always within 3 of eachother

#

what i have displayed here is just the very center point

languid spire
#

so you want to find the lowest number and make it zero. then use the same difference on all the numbers

#

so -3 becomes 0 and all other numbers are adjusted by 3

rotund garnet
#

yes exactly

languid spire
#

then it's a very simple algorithm

rotund garnet
#

2 for-loops? each sorting their own rows and columns??

languid spire
#

no, one for loop to find the difference number required, one for loop to put the entries into the array

rocky axle
#

when I start editing code in Microsoft Visual Studio it is erasing all letters after my edited portion. Anyone know how to fix this?

#

Like in a singular line of code it is starting to overwrite it if that makes sense

rotund garnet
#

press the insert button :)

#

it should change the marker to a line instead of block

short hazel
#

Insert key on your keyboard

rocky axle
#

amazing easy solution THANK YOUUUUUU

dire shadow
#

Hey mates, wondering what's your approach to version control, I'd like to work from multiple computers, I'm not sure if github for instance is suitable for projects including multiple asset packs. It would work for the scripts but I guess the other files are too big, but also need to be synced across machines

steep rose
#

you can use github version control and pay for it or use git LFS which is recommended for large files

#

you can also host git yourself if needed, but you need that machine to be on to use it

rotund garnet
#

then on other pc i just press fetch origin, and get the changes down locally

#

i am working alone on it, so i dont need to think too much about merge conflicts or anything

dire shadow
rocky canyon
#

its just for LFS

#

github is free for the most part

steep rose
#

unless you want more than 100mb of commit which I believe you have to pay for

#

but if you are solely storing scripts, you will be fine doing it for free

dire shadow
#

Oh, maybe then I need to split my first commit in several ones?

rich adder
#

LFS has free tier but limited

rocky canyon
#

100 mb / file i think it is

steep rose
#

any git hoster will make you pay for the 100mb limit anyway and for git LFS as well since its integrated for git

#

but yes splitting commits is a good option

languid spire
#

why would you be syncing asset packs across multiple machines anyway when each machine can just download them

marble ocean
#

Hi there

dire shadow
marble ocean
#

i actually have a serious confusion goin on rn

#

im using charcontroller to move

languid spire
#

so you save the changes not the whole packs

dire shadow
#

I'll try to push as it is rn maybe it just works ๐Ÿซข

marble ocean
#

then**

steep rose
#

use full sentences

marble ocean
#

im using transform.rotate to turn it using mouse

dire shadow
#

I guess Library, debug, logs and idea folders can be excluded, right?

marble ocean
#

but its not moving according to where its looking

short hazel
# marble ocean then**

Please write your question in one message so it does not get broken up. You can hit Shift + Enter to add a new line without sending the message

languid spire
steep rose
eternal falconBOT
steep rose
#

you are most likely using Vector3.forward instead of transform.forward

#

one is global one is local

marble ocean
#

oh?

steep rose
#

did I guess correctly

marble ocean
#

wait i will send codd

#

im new to unity

#
using JetBrains.Annotations;
using Unity.VisualScripting;
using UnityEngine;

public class Player : MonoBehaviour
{
    [SerializeField] float moveSpeed = 7f;
    [SerializeField] private Vector2 mouseturn;
    [SerializeField] private float mousesens = 3f;
    [SerializeField] private Animator anim;

    [SerializeField] private Transform NeckBone;

    CharacterController charcont;
    private float downpull = -0.05f; 

    private void Awake()
    {
        charcont = GetComponent<CharacterController>();
    }

    private void Update()
    {
        Vector2 inputvector = new Vector2(0,0);
       

        if (Input.GetKey(KeyCode.W))
        {
            inputvector.y = +1;
        }
        if (Input.GetKey(KeyCode.S))
        {
            inputvector.y = -1;
        }
        if (Input.GetKey(KeyCode.D))
        {
            inputvector.x = +1;
        }
        if (Input.GetKey(KeyCode.A))
        {
            inputvector.x = -1;
        }

        inputvector = inputvector.normalized;

        mouseturn = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

        transform.Rotate(Vector3.up * mouseturn.x); 
        //NeckBone.transform

        if (charcont.isGrounded)
        {
            downpull = -0.05f;
        }

        if (!charcont.isGrounded)
        {
            downpull += -9.81f * Time.deltaTime;
        }

        if (inputvector.y != 0)
        {
            anim.SetBool("isWalking", true);
        } else
        {
            anim.SetBool("isWalking", false);
        }


        Vector3 movedir = new Vector3(inputvector.x, downpull, inputvector.y);

        charcont.Move(movedir * Time.deltaTime * moveSpeed);
    }
}
rich adder
#

start by posting the code maybe ?

steep rose
polar acorn
#

You're going to need to provide more context than that. What are you trying to do and what is it doing instead

steep rose
#

also IIRC you can do Movedirection = transform.forward * y + transform.right * x;

marble ocean
steep rose
#

you are using global vectors to move yes

marble ocean
#

ohh thought so

#

how do i fix it

polar acorn
#

!code

eternal falconBOT
rich adder
#

that if statement is scary..

polar acorn
steep rose
rich adder
rich adder
#

is this a UI Button ?
do you have an event system in the scene

#

omg please use Links

#

as described in the bot message for posting code

steep rose
marble ocean
rich adder
steep rose
#

yup, thanks

rich adder
#

forward * z + right * x

steep rose
rich adder
#

you have to save before you send the link ๐Ÿ˜›

polar acorn
#

You didn't actually put any code in the link

rich adder
polar acorn
#

Okay, what calls RemoveResources

rich adder
#

verify that RemoveResources gets called by putting Debug.Log

#

the logic is fine. If the button isn't clicking or calling that function, you likely do not have Event System

marble ocean
#

finally it moves where its looking

steep rose
#

Glad it worked ๐Ÿ˜

marble ocean
#

thanks very much

polar acorn
#

when what is clicked

rich adder
#

did you see the event on it ? OnClick

polar acorn
#

Okay, so this is calling the function OnShopClick with the string parameter "village"

#

you "think"? Why not check

#

You can see what that function does when you pass it the value "village"

#

How about you tell me what this function does when you pass "village"

#

You already are

#

that's not the question here

#

the function is called with the string value "village"

#

So, what does this function do, when passed the value "village"

#

Okay, so, what actually takes the resources

#

and what calls RemoveResources

rich adder
#

this is already an overcomplicated system you put yourself in lol

#

yeah but now you need to connect the two

#

this doesn't care if you have resources or not it will just spawn whatever (in this case "village")

#

onshop click needs to run some validation logic that you do in the button

#

ButtonClick -> DoIhaveEnoughResources For this -> Subtract amount / Instantiate
i guess not making non-interactable can work to skip some if statements but you still need to Remove the proper resource according to the resource you bought

polar acorn
#

Well, first think about it in terms of words. What do you want to happen when the button is pressed?

rocky canyon
#

more beginners need to do this ^ tbh

#

super helpful at first

rich adder
#

use pen and paper it helps a lot tbh

polar acorn
#

Okay, so the button just removes resources?

#

Click button lose resources?

#

So, it sounds like you want it to do more than just subtract resources

#

Explain the entire purpose of the button

#

What happens when you click on it. The entire process

#

Okay, so, the button is only enabled if you have enough resources, so that's not related to clicking.

When you click on it, you want to remove some amount of resources, then instantiate a prefab.

#

So, put the "Spawn a prefab" thing in this function, and have your button call this function

#

This script already has you setting all the resource costs for a specific thing, just give it a field to drag in the prefab

#

This entire script is redundant. Just have the script that defines the resource costs also spawn the objects

polar acorn
#

Then there's probably something you didn't share

#

So then you were calling RemoveResources somewhere and never showed it

cosmic quail
#

did you try googling "restart the scene in unity" because when i do it there are a lot of results

steep rose
cosmic quail
#

its ok it didnt offend me ๐Ÿ˜„ but if your question is this simple then you can just google it

nocturne kayak
#

Yo

#

Can anyone think of a way to have collisions without rigidbodies?

#

I'm setting a mesh's position manually through code

#

That is

#

manually setting transform position

#

I just want it to not be movable in that direction if it detects a collision

#

i was thinking about doing raycasting

#

but can anyone think of a better alternative?

slender nymph
#

can you speak in complete sentences instead of spamming 8 messages that could have easily been one

eternal needle
#

Youd realistically use a capsule cast instead of raycast

wintry quarry
nocturne kayak
wintry quarry
nocturne kayak
#

I'm not sure charactercontroller would be the way to go if i have multiple of those in a single scene

wintry quarry
wintry quarry
nocturne kayak
#

I'm not sure, i just assumed it would be easy enough to achieve without character controller

rocky canyon
wintry quarry
#

why wouldn't you just use the hammer?

rocky canyon
#

but moving thru code.. a CC should be fine

wintry quarry
#

Sure it's easy - just use CapsuleCast

#

I don't see a reason to though

#

or use KCC

rocky canyon
#

KCC is great.. even if u dont end up using it..

#

lots to learn from just browsing thru the code

nocturne kayak
#

Well

#

I was hoping i wouldn't need to scrap what i've written so far, but might as well learn something that could be more useful

rocky canyon
#

dont scrap it..

#

keep it around.. u can always go back to it.. or use pieces of it.. or go back and look at it after u've learned other ways..

#

might still be benificial to u

molten pulsar
#

the problem is that when i use this code:

#

if (LeftHandGrip != null)
{

 animator.SetIKPositionWeight(AvatarIKGoal.LeftHand ,1);
 float smoothTime = 5.0f; // Ajusta la velocidad de suavizado
 handLeft.position = LeftHandGrip.position;
 handLeft.rotation = LeftHandGrip.rotation;

}

if (RightHandGrip != null)
{
float smoothTime = 5.0f;
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1);
handRight.position = RightHandGrip.position;

 handRight.rotation = RightHandGrip.rotation;

}

#

its suposed that Right hand grip or left hand grip is a object inside the weapon that parent to the player when he get it

#

for example

#

void get weapon(newWeapon){RightHandgrip = newWeapon.right hand grip]//this is an example i now that the code dosent have sense

#

the right hand grip is the target of a Two ik bone constraint

#

if somebody can help me,let me know it because i dont get any solution in other place

astral falcon
#

First !code

eternal falconBOT
solar orchid
#

Does anybody know how I can stop this callback thing? Iโ€™m trying to add water in my player but every time I do that it says call back. What do I do? Pls help me

solar orchid
polar acorn
#

Okay, but then you aren't going to hear when I say that you didn't even include what "Call back" you are talking about ยฏ_(ใƒ„)_/ยฏ

solar orchid
polar acorn
solar orchid
#

9000 !

polar acorn
# solar orchid 9000 !

You know, if you had sent a screenshot of your editor window instead of a poorly aimed grainy photo, someone might have actually seen your error message

molten pulsar
#

i get what you was triying to say

#

XD

solar orchid
solar orchid
polar acorn
solar orchid
polar acorn
solar orchid
# polar acorn

I never said that that I didnโ€™t want you answering my question. I just wanted to block you cause youโ€™re annoying. Like thereโ€™s a difference.

polar acorn
#

Oh well. Blocked now, guess you'll have to figure it out on your own ๐Ÿ‘

molten pulsar
#

please?

solar orchid
polar acorn
eternal falconBOT
polar acorn
#

So show the full code using the instructions provided

#

!code

eternal falconBOT
molten pulsar
#

Bro didnt know how to use code

polar acorn
#

Did you try reading the bot

molten pulsar
#

sorry im noob at english

molten pulsar
#

i try my best

polar acorn
#

Yes, like that. So, it seems like either LeftHandGrip or RightHandGrip is rotating. You're setting handLeft and handRight's rotation directly to that object's. What objects are those

molten pulsar
#

this is a example of what object are those

#

It is added depending on which weapon you choose.

#

this a example inside a musket

polar acorn
#

So, does RightHandGrip, Cube.001, or M16 rotate?

molten pulsar
#

yes

#

only in reload animation

polar acorn
#

So, the hand is going to copy the current world rotation of that object, every frame

molten pulsar
#

and that cube is the magazine

polar acorn
#

So if the HandGrip object, or any of its parents are rotated, it's going to change the rotation of the hand

#

And, actually, since it's IK, changing the position of the hand might also be changing the rotation of the arm. I can't quite tell through the gizmos if the hand itself is rotating in your clip

#

is it facing the right direction and just moving? Or is it actually rotating along with the arm?

molten pulsar
polar acorn
#

So, it's probably the position that's the problem and not the rotation

molten pulsar
#

the arm didnt seem to respect that and only keeps moving ignoring the position and rotation of the weapon grip

night lance
#

hi! i was wondering if there's a way to add scripts/components to tiles in unity's tilemap system for the use case of (for ex) placing enemies down as tiles, creating triggers (in tile format) etc ~ I'd love to be able to slap a camera trigger down similarly to the way it works in lonn for celeste

molten pulsar
#

position of the weapon grip isnt the problem

noble lark
# night lance hi! i was wondering if there's a way to add scripts/components to tiles in unity...

I dont know anything about tilemap as i havent worked with it but from some quick searching it seems like tiles are a intermediary asset? From my understanding it means that its closer to a texture or other types of assets that mostly act as art or properties for gameobjects to use (somebody correct me on this as im new to unity too). If you want to make your own script for a tile, you would have to override functionality from the TileBase class (from what ive understood). Maybe this helps: https://docs.unity3d.com/6000.0/Documentation/Manual/tilemaps/tiles-for-tilemaps/scriptable-tiles/create-scriptable-tile.html.

#

^ hopefully somebody with real experience on tilemap can help out with this. This is just what i found from some digging.

crisp token
#

Compute shader (FFTSpectrumViewer): Can't find kernel (0) variant with keywords: CHANNEL_BLUE CHANNEL_GREEN CHANNEL_RED. Does anyone know why I'm getting this error in the snipped code (FTTSpectrumViewer) provided in the hastebin. The error comes from the dispatch line on the computer shader
https://hastebin.com/share/esiwejezur.cpp

arctic ibex
#

So, I recently coded an error popup, and for some reason it's giving me a null reference exception when it's built, but not in the editor.
Image 1 is in the build, Image 2 is in the editor, three is the console during the editor, 4 is the Script for the error popup.

teal viper
arctic ibex
teal viper
#

Also, you can connect the editor to the build to see errors in the console.

arctic ibex
#

whats it called in the script?

teal viper
arctic ibex
#

thankyou

teal viper
arctic ibex
arctic ibex
dim yew
#

for some reason this BoundsInt.Contains function returns false every time. any idea why? i couldn't find pretty much anything on BoundsInt documentation wise

#

i hope this is the right channel for this also

eternal needle
dim yew
#

would starting at -2 and going down 2 not encompass -3?

eternal needle
#

Actually im not sure if you can have negative size like that

eternal needle
arctic ibex
rich adder
arctic ibex
#

oh thats right i made a dev build

#

lemme get a screenshot

eternal needle
#

Only Text can be null there anyways

#

percent*, which is of type Text

arctic ibex
rich adder
#

you probably want TMP_Text rather than Text

arctic ibex
#

but i still dont understand how it's null, it assigns itself at the start and theres no objects with percentage reader that dont have text

arctic ibex
#

i know i should change it, but like half my text objects are tmp and half arent

eternal needle
#

Did you debug when this method runs? Add a debug in start and your method

arctic ibex
eternal needle
rich adder
#

null checks usually *

eternal needle
rich adder
#

I guess at least, just like assign it in the inspector that get rid of the order issue

eternal needle
#

honestly the whole thing would be solved too if you just plug in the reference in inspector, rather than doing get component

rocky canyon
#

TIL about "lazy instantiation"?

private Text _percent;
private Text percent => _percent ??= GetComponent<Text>();```
eternal needle
rocky canyon
#

ahhh..

#

well good to know lol

cosmic dagger
rocky canyon
#

still interesting.. i tend to stumble on all kinds of wacky syntax here lately

cosmic dagger
#

though, you can still lazy instantiate . . .

rocky canyon
#

just found out about using ! after a variable to suppress null errors

#

does that one work?

cosmic dagger
#

that i don't do myself, so i'm unsure . . .

eternal needle
#

even if you dont use ??, and you're checking for null, for component references this is weird to use. i cant imagine many cases where you wouldnt be able to just assign it in inspector or do get component in awake or start

rocky canyon
rich adder
cosmic dagger
cosmic dagger
#

actually, i lied. i use it in Reset because that gets called in the editor. it'll ensure smth is set . . .

eternal needle
dim yew
#

good heavens i cannot type

brisk sequoia
#

IM having some issue with this error The type or namespace name 'GridTileBase' could not be found (are you missing a using directive or an assembly reference?)
am i missing something?

rich adder
brisk sequoia
rich adder
eternal falconBOT
rich adder
brisk sequoia
ruby python
#

Mornin' all,

I'm refactoring my code at the minute (consolidating a bunch of stuff). It's all working as expected except for one teeeeeeny little aspect.

https://hastebin.com/share/ugefecixaz.java

The Indicator that appears around the ship should appear around the targetted object (In this case Asteroids), and I'm not sure where the error is in the code (It's the exact same code that I was using elsewhere and it worked perfectly, and just can't see where I'm going wrong).

https://streamable.com/guv07w

Can anyone see the issue please?

Watch "2024-10-26 07-36-04" on Streamable.

โ–ถ Play video
timber tide
ruby python
timber tide
#

also, you should consider using TryGetComponent even if you're using layer filtering

ruby python
timber tide
#

Well, you're looking for the gameobject from the hit to apply the target reticle over, so if that's what you're getting there it should be the target of that

ruby python
#

This is what's confusing me. I'm grabbing the 'target object' and the 'interactable' script fine (the cursor sprite changes as it should, the cursor sprite is assigned on the interactable script), so I'm not understanding why the rectTransform of the indicator isn't changing its position based on the currently 'rolledover' asteroid.

timber tide
#

So WorldToScreenPoint is returning the same value for any interactable I'm guessing?

ruby python
#

Like I said, it was working fine before I moved this functionality from the playerController to my MouseController script. I've obviously changed something that's broken it, but I can't see in the code where. lol.

ruby python
#

The Interaction script works perfectly btw. It's the rectTransform positioning that isn't working. It just stays with the ship. ๐Ÿ˜•

timber tide
#

Right, so are the values from worldtoscreen changing depending on where the cursor is right

#

in that case it points to those rectransform.positon then

ruby python
#

Oh for gods sake. lol.

Sorry, I just figured it out and I am a collosal Penis. I'd assigned the wrong thing in the Inspector (The parent container and not the actual image object.

#

Parent doesn't have a rectTransform.

timber tide
#

ah ok I was going to suggest making a primary rect transform with local over world coordinates

#

I dont remember worldtoscreen being a vector3 either but it does use the z for the depth

ruby python
#

Yeah I did look at the docs and it's Vector3, confused me if honest. But I guess it makes kind of sense if it's looking for a vector3 to convert?

#

Thanks for taking a look anyhow, sorry it was me being an idiot. lol.

timber tide
#

if you have problems with that later, may be worth zeroing out the z

#

if you're not doing transparency on the UI by the transparency queue

ruby python
timber tide
#

usually you can sort by z-depth with transparents, but canvas and 2D modules have ways to force what is rendered over each other

ruby python
#

Aaah, yeah I get ya. Yeah tbh, I'm kinda doing all that manually with the hierarchy placement etc.

timber tide
#

so technically it first sorts by queue, then if everything is at the same queue then it sorts by depth

north kiln
#

Use CompareTag instead of equality

severe onyx
#

I got this little piece of code which replicates the forward and backward movement of w and s on mouse scroll up and down - works wonderfully for its purpose, but recently it was pointed out to me that some users expected scrolling in the camera to behave differently; namely for it to instead zoom in on the area of the screen the mouse cursor was in specifically

#

think the way google maps works yknow?

#

and Im kinda having a hard time coming up with what the would even look like mathematically

#

any pointers would be much appreciated

keen dew
#

The basic idea is that you save the world position where the mouse cursor points, zoom, check what position is now under the cursor, and calculate the difference between the old position and the new position. Then you move the camera by that amount to the opposite direction which puts the old location back to under the cursor.

severe onyx
#

Would I check the world position of the cursor against a plane through origin in case I have no natural ground or walls to hit? I'd have to ray cast, right?

keen dew
#

Yes, you need a plane

queen adder
#

how do i use new vector3 without getting that ambigous error thingy

#

im very new to unity i need some help

short hazel
ruby python
queen adder
#

hold on im having a very difficult time screenshotting on imac

ruby python
#

Don't screenshot !code

eternal falconBOT
short hazel
#

It usually happens when you try to add a Vector2 and a Vector3, and C# can't guess which + to use, because both V2 and V3 have an addition operator

#

But I want to confirm this is the actual issue

queen adder
short hazel
#

!screenshots

eternal falconBOT
#

mad No

Be mindful, if someone requests your code as text, don't send a screenshot!

queen adder
#

sorry if its a bit bad

slender nymph
#

oops wrong reply sorry

slender nymph
ruby python
#

You're only creating the Vector3 with only 2 parameters, you need to use all 3 (x, y and z)

If you're using 2D, use Vector2 instead.

short hazel
#

Nope

queen adder
short hazel
#

You have two using directives, both have a Vector3 in them

#

The System.Numerics one isn't compatible with Unity, remove it

ruby python
#

Oops. I didn't even look at those. My bad.

queen adder
ruby python
#

!code

eternal falconBOT
stray iron
#

Guys i wanted to make sudoku is there a way to make it without using DFS or backtracking? Is it even possible?

opal marsh
#

is changing gameobjects from another scene can affect your code in other scene i have this game where answering the question right the game continues and when collided again it stops but then after customizing some design in another scene when the player answers the question right the game continues but when colliding it still continuing

vale geyser
#

I am currently trying to fix my blackjack game, I have completed the code but it does not work for some reason. I do not know if it's something wrong in my GameManager https://hastebin.skyra.pw/yicoyeqinu.pgsql but every time I hit "deal" it works fine. But when I click "hit" it does not determine the winner or loser ( for the dealer or player), cards keeps appearing every time I click "hit" until the game crash

languid spire
# vale geyser

it's pretty obvious handvalue is not being incremented

frozen phoenix
#

I have trouble working with the new input system
I would like to make crosshair appear smoothly when the right mouse button is clicked/"GetKeyDown"
and smoothly disappear when it's released/"GetKeyUp"
smoothness is easy so don't mind static value, but I'm struggling for few hours on how to get keydown/up functionality from the new input system

languid spire
#

started for keydown, cancelled for keyup

slender nymph
#

and make sure that your input action is enabled

desert plinth
#

Hello,
I have this script right here, where a particle system should face the opposite direction of a Rigidbody (car) entering a water object.
Could anybody explain why the particle system instantiated in the script (see below) does not face that direction?


public class WaterEffects : MonoBehaviour
{
    [SerializeField] GameObject splashVFX;

    [SerializeField] string carTag = "Car";

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag(carTag))
        {
            Quaternion rotation = Quaternion.Euler(-other.transform.forward);
            Instantiate(splashVFX, other.transform.position, rotation);
        }
    }
}
slender nymph
#

transform.forward is not expressed in euler angles. it is a direction and is normalized

short hazel
#

Use .LookRotation(-other.transform.forward) to construct a quaternion from a direction

night raptor
#

Btw, you can set Transform.forward directly too

#

So whatEverTrans.forward = -other.transform.forward should work too

wild widget
#

!ide

eternal falconBOT
vale geyser
#

would you need the other scrips to help me further?

languid spire
vale geyser
#

the notes are not in English, sorry for that๐Ÿ˜…

languid spire
#

you obviously know how to use Debug.Log so why not debug this?

int cardValue = deckscript.DealCard(hand[cardIndex].GetComponent<CardScript>());
languid spire
frozen phoenix
# languid spire started for keydown, cancelled for keyup

I've tried but only performed seems to trigger anything
when in OnEnable method I write aim.context.performed it runs ToggleAim exactly once upon keydown and exactly once upon keyup
once I swap performed for either started or canceled I do not run ToggleAim method

I think I have been rash to jump straight into input system without any preparation
But on the other side I've been reading the documentation for it and yet I don't understand it well
Do you guys have any youtube video explaining such actions in the new input system? I'll really appreciate it!

short hazel
#

You need to use performed and canceled if I remember correctly

slender nymph
#

correct, which is also what steve suggested to them

#

although they are only subscribing to started here

languid spire
#

performed is GetKey though, multiple calls

short hazel
#

Started is for some cases where the action is long, like a button with the Hold modifier: pressing the button invokes started, when held for the required amount of time invokes performed, when released invokes canceled

#

If you have no modifiers, it should be performed (key down) and canceled (key up)

frozen phoenix
#

I've tried to use both in the onenable and created separate methods to be run by started and canceled
but I have not received any log in console when I've done it this way:

short hazel
#

Also log stuff inside OnEnable directly. The script needs to be on an active and enabled object for this to run

languid spire
#

is the action even enabled?

frozen phoenix
#

well the performed runs twice, once on keydown once on keyup
canceled and started are ignored
is this even the correct way/place to call them?

frozen phoenix
# languid spire is the action even enabled?

Frankly speaking I don't have knowledge to be certain about it, sorry
But I believe I have the action enabled through action map
At least the documentation says it should be alright this way

short hazel
#

Are you using a mouse or a gamepad to test this out? The action supports both

frozen phoenix
#

of course

#

mouse and gamepad is always connected

#

and im trying both

short hazel
#

Mild inclusive or moment

slender nymph
# frozen phoenix Frankly speaking I don't have knowledge to be certain about it, sorry But I beli...

https://docs.unity3d.com/Packages/com.unity.inputsystem@1.11/api/UnityEngine.InputSystem.InputActionType.html#UnityEngine_InputSystem_InputActionType_PassThrough

The second key difference is that only Performed is used and will get triggered on every value change regardless of what the value is. This is different from Value where the action will trigger Started when moving away from its default value and will trigger Canceled when going back to the default value.

short hazel
#

"A or B?" - "Yes"

frozen phoenix
#

yeah, it took me a second to understand it the way you intended
at first I interpreted it as "are you even using any of these?" :x

frozen phoenix
slender nymph
#

idk what you are referring to when you say "that works" as i did not give a suggestion, i was simply showing why you were not getting started or canceled invoked

short hazel
#

I wonder why it's in passtrhough by default though, seems like it comes from the standard assets one

#

Especially when you can configure the press point (ie. how far you need to press the trigger down on gamepads) to trigger the action

frozen phoenix
wintry quarry
#

Pass through only does performed

#

Sorry lag

frozen phoenix
#

Yeah it seems so
boxfriend pointed me in the right direction
even if he didnt intend to do so he helped me to fill out my knowledge to resolve this small issue :)

lunar coral
#

They changed the Input manager ?

slender nymph
young lava
#

Does anyone happen to know why this error keeps showing up? I recently updated my game to a newer version of unity so that is most likely the issue, but I'm not really sure where to even start for this error besides the error taking me to the GridEditorUtility script. Additionally the error pops up when I make changes to random scripts. For example, I change my enter room controller script and after saving this error pops up. I can still play my game and it doesn't seem to be affecting anything in my game, but I'd like to get rid of it xD

ivory bobcat
#

Either that or the near clipping plane or some other inspector value for the camera may be inappropriate.

young lava
#

gotcha tyvm ^^

proven matrix
#

I dont understand this error, the script is attached to the gameobject. Am i suppose to assign "gamneoBEJCT" TO anything.

I am trying to make it so when my player hits the ground with the tag "ground" then the boolean "is grounded" is true

languid spire
#

you are using the variable type not the variable name

proven matrix
languid spire
#

exactly what I said

proven matrix
#

So am I suppose to be using the name of the gameObject

languid spire
#

no, you use the name you associated with the type Collision2D

polar acorn
proven matrix
#

Ohhhhhh

#

Makes sense now lol

languid spire
#

maybe brush up on some C# basics

proven matrix
#

Lol I think I have been coding for too long and need a break

vale geyser
languid spire
vale geyser
languid spire
#

share the code for DealCard

queen adder
#

how do i make a bunch of gameobjects with a tag do something at the same time

queen adder
#

both ways please

languid spire
#

good way is using events, simple way is FindObjectsWithtag and for loop

queen adder
#

oooooooo

queen adder
languid spire
#

this is called Debbuging btw, a very good skill to learn

polar acorn
queen adder
vale geyser
languid spire
polar acorn
queen adder
polar acorn
#

In order to select a set of objects you first need to decide which objects you want to select

languid spire
vale geyser
vale geyser
languid spire
vale geyser
languid spire
#

tbh, you should understand your own game a great deal better than you appear to

vale geyser
languid spire
vale geyser
#

yea if i did not do it wrong

scenic saffron
#

what's my mistake?

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

public class move_one : MonoBehaviour
{
    public Image one;
    public GameObject Canvas;
    float i = 255;
    float t = 0;
    private void Update()
    {
        t += Time.deltaTime;
        transform.position = new Vector3(transform.position.x, transform.position.y + Time.deltaTime * 50, transform.position.z);
        if (t > 1f)
        {
            one.color = new Color(255f, 255f, 255f, i -= 100 * Time.deltaTime);
            Debug.Log("a_changes");
            Debug.Log(one.color.a);
        }
        if(one.color.a <= 0)
        {
            Destroy(Canvas);
        }
    }
}
languid spire
scenic saffron
#

the color changing part

languid spire
#

Color should be Color32

rich adder
vale geyser
vale geyser
#

unless its their name

vale geyser
languid spire
#

So the CardScript you just showed is in a prefab

vale geyser
languid spire
#

that is not what I asked.
I am somewhat confused how you ever expected every card to have the correct value

vale geyser
#

yeah๐Ÿ˜…

languid spire
#

you appear to have a fatal design flaw in your game

vale geyser
languid spire
#

that is irrelevant to this problem

plucky bear
#

So I'm working on a school project and I want to ask if anyone here is good at using unity and C#. The project has to do with simulating a 3d rocket from data from a model rocket. Im just asking if anyone can help me as I just installed the unity editor today so DM me if possible.

scenic saffron
#

how do i convert an int to a byte

scenic saffron
#

thx

vale geyser
languid spire
scenic saffron
#

why dose this make ยดone` blink sometimes

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

public class move_one : MonoBehaviour
{
    public Image one;
    public GameObject Canvas;
    byte i = 255;
    float t = 0;
    float t2;
    private void Update()
    {
        t += Time.deltaTime;
        transform.position = new Vector3(transform.position.x, transform.position.y + Time.deltaTime * 50, transform.position.z);
        if (t > 1f)
        {
            t2 += 2 * Time.deltaTime;
            i -=  Convert.ToByte(t2);

            one.color = new Color32(255, 255, 255, i);
            /*Debug.Log("a_changes");
            Debug.Log(one.color.a);
            Debug.Log(Convert.ToByte(Mathf.RoundToInt(t2)));
            Debug.Log(t2);
            Debug.Log(i);*/
        }
        if(one.color.a <= 0)
        {
            Destroy(Canvas);
        }
    }
}
vale geyser
wintry quarry
languid spire
scenic saffron
languid spire
wintry quarry
#

what are you trying to do?

scenic saffron
#

make the image fade out

#

and move up at the same time

vale geyser
languid spire
languid spire
vale geyser
scenic saffron
languid spire
vale geyser
languid spire
#

so show the console, that's why the debug.log is there

languid spire
languid spire
#

right now compare that to mine

vale geyser
#

ah, did not see that

vale geyser
languid spire
#

And you still have not learned to look at the Debug info in the console to see why?

languid spire
#

so you tell me, which card was dealt

vale geyser
#

and that's the blue card

languid spire
#

ok, so maybe that is why you had currentIndex=1 in shuffle because zero was not a valid card

vale geyser
#

yes

languid spire
#

and I was supposed to know that how?

vale geyser
languid spire
#

So Value is still not right and I noticed you made the same mistake in GetCardValues as you did in Shuffle

cardValues[1] = num++;
languid spire
#

also your for is from 0 and it should be from 1 if the first card is not used

vale geyser
languid spire
#

so show me the logs, do I have to ask every time

vale geyser
languid spire
#

so dont you see that Value is still 0 for every card?

vale geyser
#

yes, but i could not find in inspector where to change the value of each card

languid spire
#

ffs do you not understand your own code. It is being done in GetCardValues

vale geyser
#

oh let me take a look on that

vale geyser
languid spire
vale geyser
young lava
#

So after updating to Unity6 when I create new monobehavior scripts for a duration my console gets spammed with warning messages. After a little loading however, the warning messages stop. I was wondering what is causing this issue?

scenic saffron
#

why cant i spam click my button anymore

north oar
#

``using System.Collections;
using UnityEngine;

public class SpawnCards : MonoBehaviour
{
[SerializeField] RectTransform[] cards;
Animator[] cardAnimators;

void Start()
{
    cardAnimators = new Animator[cards.Length];
    StartCoroutine(CardSpawn());
}

IEnumerator CardSpawn()
{
    yield return new WaitForSeconds(0.5f);

    for (int i = 0; i < cards.Length; i++)
    {
        cardAnimators[i] = cards[i].GetComponent<Animator>();
        cardAnimators[i].SetTrigger("Spawn");

        yield return new WaitForSeconds(0.1f);
    }
}

}
``
this spawn code i have aint workin how i want it to idk why, i want the cards to spawn one after the other but they all spawn together in one. i use an animation handler so they all have the same animation

dusky gust
#

int currenCard;
IEnumerator CardSpawn()
{
yield return new WaitForSeconds(0.1f);
cardAnimators[currentCard] = cards[currentCard].GetComponent<Animator>();
cardAnimators[currentCard].SetTrigger("Spawn");
curentCard++;
StartCoroutine(CardSpawn());
}

#

try this @north oar

solemn bobcat
scenic saffron
#

its working i just cant spam it

lethal pivot
#

hey yall so i was making a game and at one point unity froze and i dont want to close it cus i did not save the project and i dont want to lose everything cus im making it for 4 hours

north oar
dusky gust
#

wait

north oar
#

wait u forgot loop

lethal pivot
#

so can someone please?

solemn bobcat
dusky gust
scenic saffron
north oar
livid grail
#

Hello! how can I find compare a index within a string? for example if I have a string " Hello world" I want to get the 4th letter within that string, with is " o " and "h" being zero

keen dew
#

string[4]

livid grail
#

@keen dew Ive tried that but its telling me that I cant convert a " char " to a "string"

#
string temp = password[2];
#

password being a string aswell

keen dew
#

password[2].ToString()

livid grail
#

oh... I thought that wasnt needed when password already was a string

#

thanks!

keen dew
#

Yeah but password[2] is a char like it says

livid grail
#

... that makes sense to me now

keen dew
#

You'll get an answer easier if you ask directly about the actual problem

livid grail
#

damn sometimes I feel extra stupid, thanks for sorting it out for me

north kiln
#

You would be better off comparing with a char 'o' not a string "o"

solemn bobcat
#

You can treat strings like an array of chars.

scenic saffron
#

why the fuck does the image start blinking and my button stops working when the last line is not a note

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

public class move_one : MonoBehaviour
{
    public Image one;
    public GameObject Canvas;
    byte i = 255;
    float t = 0;
    float t2;
    public Camera cam;
    private void Update()
    {
        t += Time.deltaTime;
        transform.position = new Vector3(transform.position.x, transform.position.y + Time.deltaTime * 50, transform.position.z);
        if (t > 1f)
        {
            t2 += 2 * Time.deltaTime;
            i -=  Convert.ToByte(t2);

            one.color = new Color32(255, 255, 255, i);
            /*Debug.Log("a_changes");
            Debug.Log(one.color.a);
            Debug.Log(Convert.ToByte(Mathf.RoundToInt(t2)));
            Debug.Log(t2);
            Debug.Log(i);*/
        }
        if(one.color.a <= 0)
        {
            Destroy(Canvas);
        }
    }

    private void Start()
    {
        cam = Camera.main;
        //transform.position = Input.mousePosition;
    }
}
north kiln
scenic saffron
#

its is tho

#

in my case

#

and wdym i ignore the z axis?

north kiln
#

Screenshot your camera's transform

scenic saffron
#

ohhhhhh

#

is this better?

#

it fixes the blinking but my button still is weird

waxen adder
#

Let's say we have vector A: (0, 0, 0) and vector B: (0, 0, 1).

Would this mean that the distance between A and B is one "unity's unit" in the z direction?

Trying to clarify/understand what unity's units are

polar acorn
#

Yes

#

Well, assuming both vectors are meant to represent positions in unity's coordinate space

#

Vectors are just unitless collections of numbers

waxen adder
faint yew
#

is there a way to change the position of the trail renderer since its not aligned with the character

polar acorn
faint yew
#

U are too good for this world

scenic saffron
#

is there something wrong with this code?

slender nymph
#

why don't you describe what you are expecting to happen that isn't happening, or what is happening instead rather than assuming anyone here can read your mind and know what you wanted to actually happen

scenic saffron
#

thats a good point

#

what i wanted was for the color of one to fade out and then delete it, but for some reason it starts blinking for a bid and then gets deleted

#

it seams like the more instances of one i have the worse it gets

slender nymph
#

so you've got multiple instances of whatever this object is all modifying the single instance of your Image component

#

unless you've explained that really poorly and/or left out some context

scenic saffron
#

First of all hears my code

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

public class move_one : MonoBehaviour
{
    public Image one;
    public GameObject Canvas;
    byte i = 255;
    float t = 0;
    float t2;
    public Camera cam;
    private void Update()
    {
        t += Time.deltaTime;
        transform.position = new Vector3(transform.position.x, transform.position.y + Time.deltaTime * 50, transform.position.z);
        if (t > 1f)
        {
            t2 += 2 * Time.deltaTime;
            i -=  System.Convert.ToByte(t2);

            one.color = new Color32(255, 255, 255, i);
            /*Debug.Log("a_changes");
            Debug.Log(one.color.a);
            Debug.Log(Convert.ToByte(Mathf.RoundToInt(t2)));
            Debug.Log(t2);
            Debug.Log(i);*/
        }
        if(one.color.a <= 0)
        {
            Destroy(Canvas);
        }
    }

    private void Start()
    {
        cam = Camera.main;
        //transform.position = cam.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0,0,10);
        //transform.position = Input.mousePosition + new Vector3(0,0,10);
        transform.position += new Vector3(Random.Range(-90f, 90f), Random.Range(-90f, 90f), 0) + new Vector3(0,-110,0);
    }
}
#

and what i was expecting to happen is that the a of one.color would slowly get lower after t was more then 1, until it fades out completely and it gets deleted along with the canvas the Image is in but for some reason it doesn't fade out but instead starts blinking and the more i I spawn of it the more it happens but it allso happens when there is only one

#

the blinking is not on/off/on/off but more like a wave

slender nymph
#

you should look into using Color.Lerp instead of manually subtracting like that. Print your values and you might see what is going wrong. for example, place this log after the i -= line: Debug.Log($"T2: {t2}, T2 as byte: {System.Convert.ToByte(t2)} i: {i}", this);

formal escarp
#

How do i share my code if its too long again? Sorry.

slender nymph
#

!code

eternal falconBOT
steep rose
#

or read this bot

formal escarp
#

Im going to paste what i wrote on the general chat here for context if thats okay. I have a character which automatically moves to the right, and if it collides with a wall it changes direction to the left. When they jump they can slide on the walls to make like a, slide + jump and reach to other places. I have a problem tho which is, if the player is sliding and they dont jump, once they hit the ground they wont change directions, they can still jump but you will get stuck to that wall. forever. The player has a Physics 2D material with no friction and no bounciness.
Am i missing something? The walls and the floor have a box collider 2D, and the player does as well.

scenic saffron
steep rose
formal escarp
#

Thanks. Ill try that.

steep rose
upper forge
#

How do I stop the transform of a gameobject from changing when it becomes a child of another gameobject?

strong wren
#
 if (WeaponUsed == true)
 {
     if (VariablesSaved == false)
     {
         _attackDelay = AttackDelay;
         _whenColliderOn = WhenColliderOn;
         VariablesSaved = true;
     }
     AttackDelay -= Time.deltaTime;
     WhenColliderOn -= Time.deltaTime;
     WeaponCollider.SetActive(ColliderActive);
 }
 if (AttackDelay <= 0)
 {
     WeaponUsed = false;
     VariablesSaved = false;
     AttackDelay = _attackDelay;
 }
 if (WhenColliderOn <= 0 && ColliderActive == false)
 {
     ColliderActive = true;
     WhenColliderOn = _whenColliderOn;
     Debug.Log("Turn On Attack Collider");
 }
 if (ColliderActive == true)
 {
     HowLongColliderActive -= Time.deltaTime;
 }
 if (HowLongColliderActive <= 0 && ColliderActive == true)
 {
     ColliderActive = false;
     HowLongColliderActive = 0.2f;
     Debug.Log("Turn Off Attack Collider");
 }``` why does the debug.log code run twice?
#

it turns the attack collider on then it turns it off then on and off again

wintry quarry
strong wren
#

turning my fps down to 1 causes it to run 3 times -_-

#

i just changed the time.deltatime to time.fixeddeltatime

polar acorn
upper forge
polar acorn
#

So, since you're not keeping the player's position, it's probably moving somewhere else when you make it a child of this

upper forge
wintry quarry
#

You should probably follow the rule of thumb of not scaling any object that has children

#

Then you won't run into this issue

upper forge
#

So i just changed the sprite object instead of the gameobject as a whole and it fixed the issue

wraith condor
#

Is there a way to blit part of a texture onto a part of another texture?

#

There seems to be no BlitRect method in Graphics and there doesn't seem to be a Bitmap or Image api

#

I am trying to draw all my textures onto an atlas

nocturne kayak
#

Is anyone here familiar on how to set up kinematic collisions

queen adder
#

is there a function to do something when an game object is out of the camera

timber tide
#

yes

charred spoke
#

This is for frustum culling however. If you want to take occlusion culling into consideration you need to use the culling group API

queen adder
#

is there a way to use the if function without using the {} and it wraps the entire script in the void

eternal needle
queen adder
#

is there a function to disable components

queen adder
queen adder
#

ah nvm i figured it out

#

help why wont my canvas move ive been trying to add text but it always appears at the top right'

#

can anyone help tell me why my text is so low quality

queen adder
#

ok i solved all of those

#

but why isnt my button working

#

if i click on it it doesnt do anything

round mirage
#

i dont understand what can i do to fix this ??

burnt vapor
#

In this case, likely editor specific code

#

A stackoverflow is often caused by bad recursion

queen adder
#

someone help me on my button ui it wont work

burnt vapor
#

So idk, perhaps find related code if this keeps happening

burnt vapor
eternal falconBOT
burnt vapor
#

What stops working? The jumping?

#

I suggest you debug playerCollider.IsTouchingLayers(groundLayer) first. This likely always returns false

#

I haven't used IsTouchingLayers myself, but does the ground actually have the correct layer assigned?

#

Also, I assume the player has to be partially inside the ground for this to work

#

I would guess that the collider is never in the ground since you'll have two colliders preventing that

#

What you can do is create a new collider that does go beneath the player, and check that instead

queen adder
burnt vapor
proven matrix
#

i have NO clue how to implement a jumping mechanic with the animations, in my 2D platformer. Does anyone mind getting in call and helping me out?

celest flax
#

If I write something like this, does the second line run before or after awake/start for the newly instantiated object?

newObj.variable = variable;```
wintry quarry
#

As will OnEnable

#

Start will run after all of this

#

possibly next frame

languid spire
#

something which, tbh, you could easily have verified for yourself

visual junco
#

is it a better idea to
1: Start with a hard programming language then learn the easier ones after
2: Start with an easy one then progressively move onto harder ones

languid spire
#

All programming languages are the same

teal viper
#

I can't imagine a goal that would require you to learn many different languages in succession

visual junco
#

nobody would believe my final goal

#

but i think i'd need more than 1 programming language

languid spire
#

try us

visual junco
#

tech company, aerospace company and possibly others

#

but i wanna learn unity bc i'm also passionate for the videogame industry

teal viper
#

That's sounds like many different goals.
Maybe start learning languages these companies actually expect you to know then.
As for unity you only need C#.

languid spire
visual junco
#

i dont wanna work for companies, i only would want to start them

#

idk why but i dont like working for others

languid spire
#

what you want to be an Elon clone?

visual junco
languid spire
#

then, as Praetor said, C is definitely the place to start followed by C#, C++ and Rust

visual junco
#

Ok thanks for the advice

teal viper
#

Because I've never heared of a one-man aerospace company.

wintry quarry
#

!learn

eternal falconBOT
#

:teacher: Unity Learn โ†—

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

rich adder
#

"putting a semi colon at the end"
You're already ahead than most ๐Ÿ˜‰

frozen burrow
#

Regarding the new input system, has the proprieties of PlayerInput been removed? I'm trying to access the property .action and .SwitchCurrentActionMap() but I can't find them. Every tutorial I see about switching action maps relies on them but I can't seen to get it to show up. What am I doing wrong?

rich adder
#

did you reference the correct PlayerInput class

languid spire
frozen burrow
rich adder
#

completely different thing

#

the generated c# class is just an easy access to the Actions of that PlayerInput

severe onyx
# severe onyx I got this little piece of code which replicates the forward and backward moveme...

I have been working on implementing a solution for this targeted zoom in; here's what I have now:

                {
                    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    float distance1;
                    Vector3 point1 = new Vector3();
                    Vector3 point2 = new Vector3();
                    if (plane.Raycast(ray, out distance1))
                    {
                        point1 = ray.GetPoint(distance1);
                    }
                    transform.Translate(Input.mouseScrollDelta.y * 0.2f * Vector3.forward);
                    Ray ray2 = Camera.main.ScreenPointToRay(Input.mousePosition);
                    float distance2;
                    if (plane.Raycast(ray2, out distance2))
                    {
                        point2 = ray.GetPoint(distance2);
                    }
                    Vector3 difference = point1 - point2;
                    transform.Translate(difference);
                }```
it definitely does *something* to nudge the camera into the area of the screen the mouse pointer is in but in practice the offset is not consistent with where the mouse is positioned relative to the objects in the scene. worried Im missing something obvious or that casting against a plane is just not a viable solution for my case
frozen burrow
severe onyx
#

the theory as I understood it was, get a point in the scene from mouse position, do a normal forward zoom in, compare the mouse position in scene after the zoom to where it was before and offset the post zoom camera position by that difference

rich adder
frozen burrow
#

sorry I still don't follow, aren't they the same? Because I only have 1 PlayerInput in the whole project

rich adder
#

PlayerInput handles all the stuff like switching Action maps etc

#

the generated c# class just gets the actions

frozen burrow
#

but how do I reference it instead of the generated C# class?

rich adder
#

[SerializeField] private PlayerInput playerInput

frozen burrow
#

But that's what I am doing ๐Ÿ˜ญ

rich adder