#💻┃code-beginner

1 messages · Page 290 of 1

blazing flicker
#

@rich adder

rich adder
#

use one of the links, send the complete script

#

lookup Timeline and Signals

blazing flicker
#

I used on of the links

#

do i just paste the link here

rich adder
#

yea

blazing flicker
ruby python
#

'ello again fellas.

Sooo be working at this for a little bit and think I have a solution that SHOULD work.

BUT, I've broken something and I really can't see where.

In the Enemy Script, the enemy is looking for a Path and a Formation, but for some reason, now they aren't getting assigned/found to the necessary variables.

Could someone lend me their eyes please and try to see what I'm missing as I just cannot see it. 😦

Enemy Script
https://hastebin.com/share/jiqofakebo.csharp

Spawn Manager Script
https://hastebin.com/share/oyalelorud.csharp

EnemyCountTracker Script
https://hastebin.com/share/balonipapo.cpp

rich adder
blazing flicker
#

Animation used i only have one direction and i used script to flip direction when moving

hidden sleet
#

if I put a layer on an empty gameobject, will it still get picked up by a sphereOverlap even if it has no collider?

#

aight, i'll just put it on a physical one then

#

cheers

rich adder
rich adder
#

you have to show me where the object goes when you flip, cause nothing in the code wrong

#

show the hirerchy + inspector for player

blazing flicker
#

@rich adder opening unity 1 sec

#

@rich adder

slender nymph
rich adder
#

also please don't use a phone to take screenshots

carmine elbow
#

I'm making a conveyor belt and when the objects move from 1 conveyor to another they get slower or stop moving for a small period (probably move slower)

public class BaseConveyor : Building
{
    [SerializeField] private float speed = 1f;
    [SerializeField] private GameObject conveyorBelt;
    
    private List<Ore> ores = new List<Ore>();
    
    private void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.TryGetComponent(out Ore ore))
        {
            ores.Add(ore);
        }
    }
    
    private void OnCollisionExit(Collision other)
    {
        if (other.gameObject.TryGetComponent(out Ore ore))
        {
            ores.Remove(ore);
        }
    }
    private void FixedUpdate()
    {
        foreach (var ore in ores)
        {
            if (ore != null && ore.Rigidbody != null)
            {
                ore.Rigidbody.velocity = conveyorBelt.transform.forward * speed;
            }
        }
    }
}```

the colliders of both conveyors are overlapping, so that shouldn't really be the problem... Right?
acoustic crow
#

!code

eternal falconBOT
untold raptor
#

are there any scripts that may help me with 3D grid building (Survival based game) ive looked around and keep finding for 2D games

meager steeple
tawny hedge
#

having these issues, i feel its all related to one thing but not sure what, i have a duplicate project with a different name (for building to another platform) and im not getting any errors from that project

#

its odd because this project has worked before and i've built from it

slender nymph
#

Did you recently start using asmdefs?

tawny hedge
#

i've never heard of it or seen the name so i doubt it

#

is there a way of checking if i started using it?

slender nymph
#

Yeah, search for asmdef files in your scripts folder

tawny hedge
#

nope, havent got anything relating to asmdef

meager steeple
# meager steeple i take damage, and the collisions between the layers of the spikes and player ar...

im guessing this would be because i have in my script to ignore layers when taking damage, apart from if the health is 0. but when its taking 2 damage it will ignore layers, but it doesnt reactive the layers afterwards

public class EnemyCollision : MonoBehaviour
{
    public GameObject GameOverUI; // selecting the game over game objects from the hierarchy

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Enemy")) // checks for collision with specific tag
        {
            Debug.Log("collision");
            HealthManager.health = HealthManager.health - 1;
            if (HealthManager.health <= 0 ) // checks if health is 0 or less
            {
                GameOver(); // calls separate function for game over
            }
            else // player is not dead
            {
                StartCoroutine(GetHurt());
            }
        }
        IEnumerator GetHurt()
        {
            Physics2D.IgnoreLayerCollision(8, 9 , true); // ignoring collisions between 2 layers
            yield return new WaitForSeconds(2); // 2 second timer
            Physics2D.IgnoreLayerCollision(8, 9 , false); // stops ignoring collisions between 2 layers
        }
    }

    void GameOver()
    {
        GameOverUI.SetActive(true); // shows game over screen
        Debug.Log("Player Died"); // logs in console
        Time.timeScale = 0; // freezes time
    }
}```
tawny hedge
slender nymph
slender nymph
tawny hedge
#

no, its in the assets/plugins/codeassist/editor and then theres an amsdef and amsdef.meta

slender nymph
#

Then it's not relevant. It would have to be in either Assets or Assets/Scripts

tawny hedge
#

ahh okay

meager steeple
#

im guessing i could run Physics2D.IgnoreLayerCollision(8, 9 , false); with the awake function as a work around, but it doesnt really solve it

tawny hedge
#

ScoreManager.cs

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

public class ScoreManager : MonoBehaviour
{
    public static ScoreManager Instance { get; set; }
    public TextMeshProUGUI boxesText;
    [SerializeField]
    private IntSO Score;

    void Start()
    {
        Score.Value = Score.Value;
        boxesText.text = "Boxes Collected: " + Score.Value;
    }

    private void Awake()
    {
        Instance = this;
    }

    public void IncreaseScore()
    {
        Score.Value++;
        boxesText.text = "Boxes Collected: " + Score.Value;
    }

    public void SetScore()
    {
        Score.Value = Score.Value;
        boxesText.text = "Boxes Collected: " + Score.Value;
    }

    public void ResetScore()
    {
        Score.Value = 0;
        boxesText.text = "Boxes Collected: " + Score.Value;
    }
}```
this is saying the type or namespace name 'TMPro' could not be found
#

just one of the scripts with errors

cosmic dagger
slender nymph
slender nymph
cosmic dagger
tawny hedge
slender nymph
#

have you somehow uninstalled those packages?

slender nymph
#

yes

tawny hedge
#

how i managed that i have no idea

hushed hinge
#

I did click on it, but doesn't get me anywhere, instead it just shows what part was wrong like something in the Collider2D

slender nymph
meager steeple
#

do i need to change something?

slender nymph
#

it's not disabled. but still, your health should not be static

meager steeple
#

can i reference another script by saying using <script name>?

tawny hedge
#

but this is on the original computer i worked on it with

slender nymph
eternal falconBOT
#

:teacher: Unity Learn ↗

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

meager steeple
#

yeah i dont have time for that

slender nymph
#

well i don't have time to help you then 🤷‍♂️

tulip slate
#

I have a simple 3d capsule, with a Character Controller and a Capsule Collider
I have another plane below the character, with a mesh collider.

However, my capsule goes right through the mesh, what am I doing wrong?

slender nymph
#

for starters, the CharacterController is already a capsule collider so you don't really need both (unless you have a specific reason for it). but also how are you moving the CC and is the mesh collider convex or non-convex

untold raptor
#

is there a way of speeding this up? It got much slower after I added the starter assets third person controller. is it due to the game getting bigger in file size?

slender nymph
#

is it actually stuck on Application.EnterPlayMode? because if so, that could indicate an infinite loop in your code. otherwise you really just gotta deal with how long it takes to enter play mode unless you mess with the enter play mode options (do not do so without understanding how they impact your project)

#

also the size of your scene impacts how long it takes to enter play mode as well

cosmic dagger
tulip slate
#

that actually seemed to fix it

untold raptor
slender nymph
#

if it isn't getting stuck, then how long it takes to enter play mode depends on a few things, including the size of your scene, how much work you do in the earliest parts of the first frame (like in Awake), as well as those enter play mode options i mentioned (though, again, do not mess with them without researching how they will impact your project and work flow)

#

oh and read/write speed of your disk also plays a part. i was doing so much waiting when i had my project on an old HDD but after moving it to an NVME SSD it does everything (including entering play mode) much quicker

untold raptor
#

oh right okay that makes sense, I'm working on my HDD atm i'll transfer it to my SSD later

tawny hedge
slender nymph
#

now would be a good time to set up some sort of version control if you don't have it already so you can avoid issues like that moving forward

tawny hedge
#

yeah 😂 thats true

#

i was actually in the process of getting it sorted recently, maybe thats how it managed to mess up, cause i was having an issue importing from cloud to another device

queen adder
#

whatif what if, unity exposes most component classes? Will it like hurt performance?

frosty hound
#

Expose in what sense?

modest sluice
#
            var points = new List<Vector3>();
            AxiomPoints.Add(new Vector3(1, 0, 1));
            AxiomPoints.Add(new Vector3(1, 0, -1));
            AxiomPoints.Add(new Vector3(-1, 0, 1));
            AxiomPoints.Add(new Vector3(-1, 0, -1));
            
            for (var i = 0; i < AxiomPoints.Count; i++){
                points.Add(AxiomPoints[i]); //instead of this line, is there a way to add all of the points in AxiomPoints outside the loop?
                points.Add(new Vector3(AxiomPoints[i].x, AxiomPoints[i].y + stemLength, AxiomPoints[i].z));
            } ```
#

axiomPoints is a list of the same type

slender nymph
#

then pass AxiomPoints into the constructor for the points list

modest sluice
#

var points = AxiomPoints; ?

slender nymph
#

no, pass it into the constructor. var points = new List<Vector3>(AxiomPoints);

modest sluice
#

thanks

hushed hinge
#

I am still stuck on what I am doing

hot palm
#

This suddenly popped up after working for 2 days?

#

(Camera does not contain a definition for main)

slender nymph
#

you probably have your own class called Camera causing a conflict

hot palm
#

Oh I fixed it

#

yeah I just created an enum called Camera

#

thx

#

I just realized

queen adder
hot palm
#

Is there any easy way to tell a cinemachine brain (Make this virtual camera go live now)?

frosty hound
frosty hound
hot palm
# frosty hound Change the priority of the virtual camera
public void BlendToCamera(Cameras camera)
{
  
    switch(camera)
    {
        case Cameras.Default:

            _DefaultCVC.GetComponent<CinemachineVirtualCamera>().Priority = 100;

            foreach (GameObject go in _Cameras)
            {
                if (!go.name.Equals("_DefaultCVC"))
                {
                    go.GetComponent<CinemachineVirtualCamera>().Priority = 90;
                }
            }

        break;

        case Cameras.FreeLook:

            _FreeLookCVC.GetComponent<CinemachineVirtualCamera>().Priority = 100;

            foreach (GameObject go in _Cameras)
            {
                if (!go.name.Equals("_FreeLookCVC"))
                {
                    go.GetComponent<CinemachineVirtualCamera>().Priority = 90;
                }
            }

        break;
    }
}
#

That's why I said an easy way xD

frosty hound
#

Cache the active camera, and when you want to switch it, turn the active priority to 0, and the new active camera to 1. Cache the new active camera.

polar acorn
#

Unless there's a higher priority camera enabled, the most recently enabled camera is the one that will be active

#

So if you just never change priority, the way to make a specific virtual camera go live is to just enable it

slender nymph
hot palm
#

True

#

I cached them before in a list tho

queen adder
#

    [ReadOnly] public GameObject latestActive; // Keeps track to the last panel opened, close that when another panels wants to open
    public GameObject LatestActive
    {
        set
        {
            MainGUI.SetActive(!value);
            if(latestActive)
            {
                if(latestActive != value)
                {
                    latestActive.SetActive(false);
                    value.SetActive(true);
                    latestActive = value;
                }
            }
            else
            {
                value.SetActive(true);
                latestActive = value;
            }
        }
    }```this pattern can work, just need some change to use cinemachine instead
hot palm
#

and I use the enum to call the function

#

so it only has errors in class

queen adder
hot palm
#

The whole script

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

public enum Cameras
{
    Default,
    FreeLook
}
public class CinemachineBrainAssistant : MonoBehaviour
{
    /* Singleton */
    public static CinemachineBrainAssistant Instance;


    /* References */
    [SerializeField]
    private GameObject _DefaultCVC;

    [SerializeField]
    private GameObject _FreeLookCVC;

    private List<GameObject> _Cameras;


    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else
        {
            Destroy(gameObject);
        }
    }

    private void Start()
    {
        _Cameras.Add(_DefaultCVC);
        _Cameras.Add(_FreeLookCVC);
    }

    public void BlendToCamera(Cameras camera)
    {
      
        switch(camera)
        {
            case Cameras.Default:

                _DefaultCVC.GetComponent<CinemachineVirtualCamera>().Priority = 100;

                foreach (GameObject go in _Cameras)
                {
                    if (!go.name.Equals("_DefaultCVC"))
                    {
                        go.GetComponent<CinemachineVirtualCamera>().Priority = 90;
                    }
                }

            break;

            case Cameras.FreeLook:

                _FreeLookCVC.GetComponent<CinemachineVirtualCamera>().Priority = 100;

                foreach (GameObject go in _Cameras)
                {
                    if (!go.name.Equals("_FreeLookCVC"))
                    {
                        go.GetComponent<CinemachineVirtualCamera>().Priority = 90;
                    }
                }

            break;
        }
    }
}
#

Is this not foldable? damn

#

So using the name is only a matter of me copy and pasting new ones correctly inside this script

#

But I understand the general concern

slender nymph
#

until you accidentally change the name of one of the objects at runtime and suddenly your code no longer works

#

or you spell it wrong

hot palm
#

uh no

#

because the object is cached in the variable

#

wait

#

nvm

#

ur right

#

I miscoded smth

#

I dont want to check the name of the object

#

but the name of the variable

queen adder
#

huh

hot palm
#

How do I do that? 🤔

slender nymph
#

you don't. you have two variables, just use the one you need to use at the point you want to use it

queen adder
#

you cache the object and use that

slender nymph
#

also consider making your variables CinemachineVirtualCamera instead of GameObject. that would eliminate the need for the GetComponent call

hot palm
#

I did that before

slender nymph
#

so instead of all of this:

foreach (GameObject go in _Cameras)
                {
                    if (!go.name.Equals("_FreeLookCVC"))
                    {
                        go.GetComponent<CinemachineVirtualCamera>().Priority = 90;
                    }
                }

you would just have _FreeLookCVC.Priority = 90;

hot palm
#

Deleted it bcs I couldnt check the name

#

but is smarter yeah

#

But how would I do the condition then?

slender nymph
#

what condition? you have the switch statement already, you know which you need to modify based on the case

hushed hinge
polar acorn
eternal falconBOT
hot palm
#

It would be this, but as you said, using the name is not good in general.

foreach (CinemachineVirtualCamera vc in _Cameras)
{
    if (!vc.name.Equals("_FreeLookCVC"))
    {
        vc.Priority = 90;
    }
}
slender nymph
#

you do not need the loop if you only have the two variables

hot palm
#

Yeah but I will have ~20 cameras

#

When walking to a specific point in the world, I want to blend to cameras

slender nymph
#

then we are back to my suggestion of checking a tag or some property on the vcam (or other component on the objects) instead of relying on the names

hushed hinge
# hushed hinge as if it have something to do at line 18
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class Counter : MonoBehaviour
{
    private TMP_Text _text;
    private int _amountPickedUp = 0;
    private int _allPickups = 0;
    public int levelNumber = 1;

    private void Start()
    {
        _text = GetComponent<TMP_Text>();
        FindAllPickups();
        _text.text = _amountPickedUp.ToString(); //+ "/" + _allPickups.ToString();
    }

    private void FindAllPickups()
    {
        GameObject[] gameObjects = GameObject.FindGameObjectsWithTag("Pickup");
        _allPickups = gameObjects.Length;
    }

    public void PickedUp(int value)
    {
        _amountPickedUp += value;

        if(_amountPickedUp >= 100)
        {
            RemovePickups();
            GameObject.FindGameObjectWithTag("Player Manager").GetComponent<PlayerManager>().AddLife();
        }

        _text.text = _amountPickedUp.ToString();// + "/" + _allPickups.ToString();

        if (_amountPickedUp >= _allPickups)
        {
            PlayerPrefs.SetString("Gems" + levelNumber.ToString(), "Clear");
        }

        //for (int i = 1; i < 8; i++)
        {
            //print("Gems" + i.ToString() + ": " + PlayerPrefs.GetString("Gems" + i.ToString()));
        }
    }

    private void RemovePickups()
    {
        _amountPickedUp -= 100;
    }
}

or if it's something to di wtih "_text.text = _amountPickedUp.ToString();" since it is line 18

hot palm
#

I could actually just pass the vc in the blendcamera function

#

And only care about the 2 player-sided cameras

languid spire
#

also !code

eternal falconBOT
hot palm
slender nymph
polar acorn
#

And it's not in a bin site

languid spire
hot palm
#

ah I see, the syntax will be different then?

#

Lemme test

carmine sierra
#

if (otherCollider.gameObject.tag == "Weapons")

this SHOULD work right?

polar acorn
#

A bin website:

  1. Takes up less space
  2. Can be searched with Ctrl+F
  3. Has line numbers
  4. Can be opened in another tab
hot palm
hushed hinge
slender nymph
polar acorn
hushed hinge
polar acorn
eternal falconBOT
languid spire
#

post the damn code to a paste site

carmine sierra
hushed hinge
# hushed hinge no, I said there's nothing written besides }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PickUp : MonoBehaviour
{
    public int value = 1;

    public GameObject pickedUpObject;

    private void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.CompareTag("Player") || col.gameObject.CompareTag("Player 2"))
        {
            if (GameObject.FindGameObjectWithTag("PickupCounter") != null)
            { 
                GameObject.FindGameObjectWithTag("PickupCounter").GetComponent<Counter>().PickedUp(value);
            }
            GameObject go = Instantiate(pickedUpObject, transform.position, transform.rotation) as GameObject;
            Destroy(go, 0.5f);
            Destroy(gameObject);
        }
    }
}
slender nymph
frosty lantern
#

so I'm using cube coordinates to control the behavior of pieces on a hexagonal board, and I was wondering how that could be turned into a 3D bitboard

eternal falconBOT
hot palm
#

Is this expected when using the website?

public void BlendToCamera(CinemachineVirtualCamera _VirtualCamera)
{
    foreach(CinemachineVirtualCamera vc in _Cameras)
    {
        vc.Priority = 90;
    }

    _VirtualCamera.Priority = 100;

    _Cameras.Add(_VirtualCamera);

}
polar acorn
hot palm
#

Or large code link and short code inline?

#

I feel so stupid jnow

hot palm
#

Nono it's fine I understand now

slender nymph
hot palm
#

Not yet, thought I may only affect camera's that have been interacted with up until now

slender nymph
#

so you don't plan to ever trigger the same camera more than once?

hot palm
#

I only have the 2 player cameras added in start

#

Ah true

#

Man this game jam really wears me out

slender nymph
#

also at this point, you may as well just scrap the whole system. keep track of only the most recently activated cam, and just lower the current camera's priority, raise the new one's priority then set it as current

#

no need for a list or a loop so your method is o(1) instead of o(n)

hot palm
#

Yeah you're right

#

Thanks

hushed hinge
languid spire
polar acorn
hot palm
# slender nymph also at this point, you may as well just scrap the whole system. keep track of o...

Guess it's that simple```cs
private void Start()
{
_CurrentCVC = _DefaultCVC;
}

public void BlendToPlayerCamera(PlayerCameras camera)
{
switch(camera)
{
case PlayerCameras.Default:

        BlendToCamera(_DefaultCVC);

    break;

    case PlayerCameras.FreeLook:

        BlendToCamera(_FreeLookCVC);

    break;
}

}

public void BlendToCamera(CinemachineVirtualCamera _VirtualCamera)
{
_CurrentCVC.Priority = 0;

_VirtualCamera.Priority = 1;

}

carmine sierra
#

I am not getting an expected result, but I debugged to see that the conditions are being met (the tag is correct)

hot palm
slender nymph
#

you're forgetting to assign the _VirtualCamera to _CurrentCVC so that next time this is called with a different camera the old one is set to 0 priority

hot palm
#

yup you're my hero

slender nymph
hot palm
#

Also why do I use _? Does it have to be?

young fossil
#

Do any of the Unity samples have a wave system?

carmine sierra
polar acorn
hot palm
slender nymph
hot palm
#

What are Identifiers

untold raptor
#
void AddTriggerCollider(GameObject block, Vector3 direction)
    {
        GameObject colliderObject = new GameObject("TriggerCollider");
        colliderObject.transform.parent = block.transform;
        colliderObject.transform.localPosition = Vector3.zero;

        BoxCollider collider = colliderObject.AddComponent<BoxCollider>();
        collider.isTrigger = true;

        collider.size = new Vector3(1f, 1f, 1f); 
        collider.center = direction * 0.5f; 
    }```

I am officially lost, i've tried to get each collider onto the side of each face but have had no luck. Is anyone able to help me understand what i need to do here
slender nymph
hot palm
#

I see

#

simple enough

young fossil
hot palm
#

Ah so everything I instance I use _?

#

So everything I drag in the inspector?

slender nymph
#

no, again that prefix should be reserved only for non-public fields

hot palm
#

with [SerializeField]

polar acorn
#

C# standards suggest prefixing all private fields with _.

I acknowledge that the council has made a decision but given that it's a stupid-ass decision I have elected to ignore it.

hot palm
#

Sorry for writing in multiple lines, my thinking is thinkies rn

carmine sierra
#

i keep trying to debug with bools but never get anything returned

#

how comes?

hot palm
young fossil
# hot palm Sorry for writing in multiple lines, my thinking is <:thinkies:89671678481887234...

Best way to learn the convention is read through the article yourself here. If you don't understand the terminology, another way is to program next to someone who is also doing it. Other than that, it's overcomplicated for what you're doing, you aren't working in a full team I assume, so it isnt required at all

#

What you do is very normal and a lot of people do that in Unity

hot palm
#

Kk thanks

young fossil
#

You know CodeMonkey? Pretty sure he didn't use _. Maybe he does now

hot palm
#

Anyone knows why my assigned cameras in the inspector are gone after starting playmode?

austere hedge
#

I have a component that I am adding to an object. After adding it, I'm trying to modify the component's values.

LootFall lootFall = coinPrefab.AddComponent<LootFall>();
lootFall.dirtPlatform = dirtPlatformsStatic[pressedKey - 1];

LootFall contains a public GameObject dirtPlatform. When I attempt to supply it with the GameObject, the IDE has no errors, but Unity has this error:

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

How do I modify the value of this component?

slender nymph
hot palm
#

They just disappear

#

Might it be the fact I am setting it to Instance?

polar acorn
#

Do you have more than one CinemachineBrainAssistant in the scene? Because one of em's gonna self-terminate and it might be the one that has the fields set

carmine sierra
#

the script I am trying to access is the same one but i imagined it would clone for each instance, is that correct? The debug isn't occuring and i dont know why

south sky
#

The place to edit the collider wont show, any fix?

hot palm
#

Ah i got it

#

funnyly enough I had to apply the changes to the prefab, I guess unity reload prefabs on play

polar acorn
polar acorn
carmine sierra
polar acorn
carmine sierra
polar acorn
#

You will likely need to reassign it if it was in the inspector

carmine sierra
polar acorn
polar acorn
# carmine sierra sorry why exactly?
  1. GetComponent is slow
  2. Your code is overly complicated because you have to keep getting the component when you want to do anything with it
  3. All components have .gameObject to reference the object it's on
austere hedge
polar acorn
#

There's basically no reason to ever reference an object as GameObject, use the component you actually want, and if you need to access any of the GameObject's methods (usually SetActive or CompareTag, most others aren't used often) then you can just get the gameObject from the component.

#

Going up the chain is fast. All components are on a GameObject, so they all have a readily accessible .gameObject property. But not all objects contain all components, so the process for getting something on the object is slower

carmine sierra
polar acorn
hushed hinge
carmine sierra
polar acorn
polar acorn
#

you change the type of that variable. Presumably it also shouldn't be of type GameObject

#

Use the type you actually want

polar acorn
#

There's almost no reason to ever have variables of type GameObject, be more specific

carmine sierra
#

do I create a new variable or something?

polar acorn
carmine sierra
#

yeah

polar acorn
#

Does every SpawnWood have a WoodCollisionDetection?

carmine sierra
#

no spawnwood is a script

polar acorn
carmine sierra
#

woodcollisiondetection is a script inside of every wood instance

#

which is from a prefab

polar acorn
#

Does every object with a SpawnWood script on it also have a WoodCollisionDetection script on it

carmine sierra
#

every object in spawn wood which is a wood instance yes

polar acorn
#

Then you'd just need to do woodInstances[i].collisionDetection.broken

#

or whatever you decide to name the variable

carmine sierra
#

cause theres only one spawnwood

polar acorn
tulip slate
#

I'm working on some basic movements, and I'm wondering how I should implement these in terms of structure so it'll be good.
For example, I want to be able to dash when pressing WW/AA/SS/DD consecutively.

The way I implemented this is somewhat like this

        foreach (KeyCode keyCode in System.Enum.GetValues(typeof(KeyCode)))
        {
            if (Input.GetKeyDown(keyCode))
            {
                if (IsEligibleForDash(keyCode)) // checks only WASD
                {
                    if (lastTapTimes.ContainsKey(keyCode) && Time.time - lastTapTimes[keyCode] < doubleTapTime)
                    {
                        StartCoroutine(PerformDash(keyCode));
                    }
                    lastTapTimes[keyCode] = Time.time;
                }
            }
        }
    IEnumerator PerformDash(KeyCode keyCode)
    {
        isDashing = true;
        Vector3 dashDirection = GetDashDirection(keyCode); // just transform.forward / backward /  etc
        dashDirection -= transform.up * Mathf.Tan(dashDownwardAngle * Mathf.Deg2Rad);

        float startTime = Time.time;
        while (Time.time - startTime < dashDistance / dashSpeed)
        {
            characterController.Move(dashDirection * Time.deltaTime * dashSpeed);
            yield return null;
        }

        isDashing = false;
    }

Now I'm wondering, should this be in a separate script entirely? What if in the future I add different combos? Like dashing with a slash, it should behave differently I guess.

carmine sierra
hushed hinge
polar acorn
eternal falconBOT
south sky
#

Guys, I wanna add a way for an enemy to push the player away it depending on the position of the player. Anyone got any ideas ??

languid spire
#

fyi a script is also a component

hushed hinge
carmine sierra
#

BREAKING SCRIPT

public class breakingScript : MonoBehaviour
{ 
    [SerializeField] WeaponFire WeaponFire; //Reference to the weapon fire script
    [SerializeField] SpawnWood SpawnWood; //Reference to the wood spawner script
    List<WoodCollisionDetection> woodInstances = new List<WoodCollisionDetection>();

    void Update() {
        if (SpawnWood.placing && !woodInstances.Contains((WoodCollisionDetection)SpawnWood.woodInstance)) {
                woodInstances.Add((WoodCollisionDetection)SpawnWood.woodInstance); //Adds new wood planks to the list
        }
        if (WeaponFire.weaponInstance && SpawnWood.placing) {
            for (int i = 0; i <= woodInstances.Count; i++) { //Checks through all wood instances to see if any should break
                if (woodInstances[i].GetComponent<WoodCollisionDetection>().broken) {
                    Debug.Log("SHOULD BREAK");
                    Destroy(woodInstances[i]); //Destroys the object of the collider that the weapon hits
        }}}
        //KING SECTION WOULD GO HERE
    }
}
#

SPAWN WOOD SCRIPT


eternal falconBOT
carmine sierra
#

or you mean i should link to pastebin

polar acorn
polar acorn
carmine sierra
bitter axle
#

So i have a tag player and a raycast that checks for that tag. However i also want to check if it hits anything else, nothing specific. Is there a way to do that, or do i have to make use of tag or layer?

polar acorn
hushed hinge
carmine sierra
#

i can show a pic labelling 1 to 3

polar acorn
polar acorn
carmine sierra
#

just the new code i made

south sky
#

Guys, I wanna add a way for an enemy to push the player away when the player touches it depending on the position of the player. Anyone got any ideas ??

polar acorn
carmine sierra
ivory bobcat
carmine sierra
polar acorn
polar acorn
#

That's the component you actually want to use

hushed hinge
ivory bobcat
#

General rule of thumb is to never reference as Game Object unless you aren't needing to do anything much with it.

south sky
carmine sierra
polar acorn
#

What did you think this line did

summer stump
# south sky Yh u got an idea how to add that?

I mean, yeah, there are tons of ways to do that. Usually the person asking would provide some details we could use. how you move objects is crucual to this

When you googled knockback, what did you find?

polar acorn
#

If you call Instantiate on a component, it still spawns the whole object, it just returns that type

carmine sierra
carmine sierra
#

ill see if that works

polar acorn
#

why would you make a second variable that holds the exact same data

#

just change the type of the one you already have

hushed hinge
carmine sierra
rapid mountain
polar acorn
#

If you have any objects tagged "PickupCounter" that don't have a Counter component on them, this line can error.

#

If you have some objects with that tag that have that script, this code will sometimes work

hushed hinge
polar acorn
hushed hinge
polar acorn
hushed hinge
polar acorn
#

Decide what you want to happen first, then work on a way to make that happen

hushed hinge
#

you kinda missed my other comment here

summer stump
#

It feels like we are crowdsourcing this game

hushed hinge
polar acorn
hushed hinge
polar acorn
hushed hinge
#

yeah (here's the full screenshot)

polar acorn
#

I'm guessing the object with the PickUp script is spawned in at runtime

#

Otherwise you could just drag it in

hushed hinge
#

drag it in?

stray wraith
#

Unity seems to display my method as missing (even when I reassign it)
Not sure why

polar acorn
# hushed hinge drag it in?

If your PickUp objects exist in the scene, you should just make a public field and drag in this object. Since you haven't done that I assume the PickUps are spawned at runtime?

summer stump
polar acorn
stray wraith
hushed hinge
summer stump
carmine sierra
languid spire
summer stump
slender nymph
polar acorn
# carmine sierra

Okay, so we can get rid of the .GetComponent from that if, it shouldn't break anything. Since the log isn't happening, then broken is not true. Put this log above your if statement:

Debug.Log($"{woodInstances[i].gameObject.name}'s broken value is {woodInstances[i].broken}",woodInstances[i]);
polar acorn
carmine sierra
polar acorn
hushed hinge
polar acorn
#

That's the type of public variable you'd make

#

and drag in your counter object

stray wraith
carmine sierra
polar acorn
#

I thought the variable entry was the problem

#

but there it is

carmine sierra
#

as well as woodinstance

hushed hinge
polar acorn
polar acorn
polar acorn
#

I told you what you'd put for the variable. Counter @hushed hinge

polar acorn
hushed hinge
carmine sierra
summer stump
ivory bobcat
polar acorn
carmine sierra
#

also I access different components of the instance from other scripts, so can that remain the same, or do I say woodInstance.gameObject.GetComponent..... or can it remain as gameObject.componentname..

polar acorn
hushed hinge
polar acorn
#

there you go

#

now you get it

stray wraith
hushed hinge
summer stump
polar acorn
# carmine sierra

Did you make sure to drag in a prefab into WoodPrefab and not an object in the scene?

carmine sierra
#

ys

#

yes

polar acorn
summer stump
polar acorn
# carmine sierra yes

When you hit play, does the object remain assigned? Are you maybe reassigning it in code or destroying it?

ivory bobcat
#

wood (1) usually implies it's a clone and possibly an object in the scene

ivory bobcat
#

But perhaps that could be the name of the prefab - strange name.

polar acorn
#

Name it whatever you want

carmine sierra
polar acorn
#

It's a name

#

it doesn't mean anything

carmine sierra
#

but still need to fix the breakingScript

polar acorn
carmine sierra
#

i ss'd it aboce

carmine sierra
ruby python
carmine sierra
#

@polar acorn no errors, but doesn't work. I feel like the error might be that im accessing it from a prefab, but i have no clue

hushed hinge
polar acorn
carmine sierra
polar acorn
# hushed hinge and then like that?

Yeah, although the name is weird. You now have a reference to the Counter on these objects. You can now call whatever functions or change whatever values you want on that object

carmine sierra
#

that works but not breaking the wood instance

ruby python
# ivory bobcat Are there any errors?

Only when it runs, because the Enemy's can't find the Path and formation objects. It's that what is confusing me cause it was working find before I reworked a bit. And I can't see where it's broken.

ivory bobcat
polar acorn
eternal falconBOT
ivory bobcat
#

I'd rather not play guessing games.

carmine sierra
#
public class breakingScript : MonoBehaviour
{ 
    [SerializeField] WeaponFire WeaponFire; //Reference to the weapon fire script
    [SerializeField] SpawnWood SpawnWood; //Reference to the wood spawner script
    List<WoodCollisionDetection> woodInstances = new List<WoodCollisionDetection>();

    void Update() {
        if (SpawnWood.placing && !woodInstances.Contains(SpawnWood.woodInstance)) {
                woodInstances.Add(SpawnWood.woodInstance); //Adds new wood planks to the list
        }
        if (WeaponFire.weaponInstance && SpawnWood.placing) {
            for (int i = 0; i <= woodInstances.Count; i++) { //Checks through all wood instances to see if any should break
                if (woodInstances[i].broken) {
                    Debug.Log("SHOULD BREAK");
                    Destroy(woodInstances[i]); //Destroys the object of the collider that the weapon hits
        }}}
        //KING SECTION WOULD GO HERE
    }
}
polar acorn
carmine sierra
#
public bool broken;
    public float breakingForce;
    void OnCollisionEnter2D(Collision2D otherCollider) {
        if (otherCollider.gameObject.CompareTag("Weapons")) { //Enters if the wood is hit by a weapon
            Rigidbody2D rb = otherCollider.gameObject.GetComponent<Rigidbody2D>();
            float weaponForce = rb.velocity.magnitude * rb.mass; //Calculates the force
            Debug.Log(weaponForce);
            if (weaponForce >= breakingForce) { //Enters if the weapon overpowers the wood
                broken = true; //Object hit wood at enough of a force to break it 
            } 
            else {
                broken = false; //Object did not hit object at enough of a force to break it
    }}}
}
ivory bobcat
ruby python
rich egret
#

!code

eternal falconBOT
ivory bobcat
rich egret
ivory bobcat
ruby python
rich egret
ivory bobcat
rich egret
hushed hinge
ivory bobcat
summer stump
south sky
#

Anyone got an idea to add knockback to a player?

rich egret
ivory bobcat
#

Place a log to see if jump was detected

#

If detected, check the amount your jumping (value)

rich egret
ivory bobcat
summer stump
#

Where I told you the likely issue

carmine sierra
ivory bobcat
rich egret
rich egret
hushed hinge
summer stump
rich egret
summer stump
ivory bobcat
summer stump
#

So the jump force you are trying to add is possibly minimized into negligence

hushed hinge
eternal falconBOT
summer stump
#

You probably want to normalize all the other input, then combine the inputMove.y (or whatever it was called) with it

ivory bobcat
hushed hinge
polar acorn
polar acorn
carmine sierra
polar acorn
#

You have a public variable now. Use that

hushed hinge
polar acorn
hushed hinge
polar acorn
#

Why are you not using your public field

rich egret
#

@ivory bobcat Ok, according to the logs it detects that I press the button but the character just doesn't jumping

polar acorn
#

You have the reference to the counter

#

use that

ivory bobcat
#

Assuming both are present in the scene outside of runtime and properly assigned from the inspector

polar acorn
polar acorn
# carmine sierra debugs perfectly

Okay, and if we go back to the first log I had you write, do you see anything with the name wood (1)(Clone) being logged with a broken value of true?

rich egret
carmine sierra
#

and i dont remember the first log honestly

summer stump
hushed hinge
ivory bobcat
hushed hinge
rich egret
polar acorn
#

I assumed you'd actually, yknow

#

use the public field

carmine sierra
polar acorn
#

The whole conversation was about what object you wanted to call PickedUp on, so I figured you'd know to call it on the thing I told you you would be calling it on

hushed hinge
polar acorn
summer stump
rich egret
carmine sierra
#

not sure if this is your idea but it didnt log

polar acorn
rich egret
ivory bobcat
polar acorn
polar acorn
ruby python
polar acorn
#

It'll log the broken state of each object in the list

ivory bobcat
carmine sierra
polar acorn
carmine sierra
#

as it is within every wood instance object

polar acorn
carmine sierra
polar acorn
#

Why are you trying to call it on the class

#

use the variable

polar acorn
polar acorn
#

Do you even know basic C# syntax

carmine sierra
polar acorn
#

Wait, did I link the wrong message of mine

#

hang on

#

I might have done a dumb

summer stump
carmine sierra
ivory bobcat
polar acorn
polar acorn
#

Do you know how to call a function on an object

#

You have the counter object

#

call the function on it

#

why is there a find

#

why is it using the Counter class instead of the instance

#

Why are you getting the component from itself

#

why is any of this

carmine sierra
ruby python
hushed hinge
carmine sierra
ivory bobcat
summer stump
#

Thus the arrow....

polar acorn
#

@hushed hinge I will not be typing the code you should be using. I am going to explain this in words and you're supposed to read it and learn things. If you're just going to smash random bits of text together until you get it right and wait for me to validate it I am not going to entertain that. If you have an actual question (not "what do I write") I will answer that, but if you post another random keyboard mash and expect me to tell you if it's right I'm just no longer going to reply to them

summer stump
#

The red line was CROSSING OUT the code. As in, remove it

ivory bobcat
polar acorn
ruby python
austere hedge
#

I have an issue where my transform.position equals the "lootTopHeightFloatingPosition", but the while loop still continues forever.

lootTopHeightfloatingPosition = (-1.28, -9.03, 0.00)
transform.position = (-1.28, -9.03, 0.00)

    public IEnumerator LootAnimationNow()
    {
        while (transform.position != lootTopHeightFloatingPosition)
        {
            Debug.Log(transform.gameObject.name + " position is " + transform.position.ToString());
            Debug.Log(transform.gameObject.name + "targetPosition = " + lootTopHeightFloatingPosition.ToString());
            Debug.Log(transform.gameObject.name + "speed = " + speed.ToString());
            Debug.Log("Still in the while loop.");
            // Move one step toward the target at our given speed.
            transform.position = Vector3.MoveTowards(
                    transform.position,
                    lootTopHeightFloatingPosition,
                    speed * Time.deltaTime
                );
            // Wait one frame then resume the loop.
            yield return null;
        }
}

Even though the two positions end up matching, the while loop keeps going so I end up overshooting my mark.

#

Maybe I should have posted this in code-general.

ivory bobcat
slender nymph
summer stump
#

Do you know what a variable is?

ruby python
#

!code

eternal falconBOT
hushed hinge
ruby python
# ivory bobcat I'm on mobile and have not looked at the other scripts yet but I'm assuming you'...

private IEnumerator SpawnWaves()
{
    while (currentWave < waveList.Count)
    {
        enemyCountTracker.IncrementWaveEnemyCount(currentWave + 1);
        enemySmallID = 0;

        for (int i = 0; i < waveList[currentWave].smallEnemyAmount; i++)
        {
            GameObject newEnemySmall = Instantiate(enemySmall, transform.position, Quaternion.identity);
            Enemy enemySmallBehaviour = newEnemySmall.GetComponent<Enemy>();
            enemySmallBehaviour.SpawnSetup(waveList[currentWave].path, enemySmallID, waveList[currentWave].enemySmallFormation);
            enemySmallID++;
            yield return new WaitForSeconds(enemySpawnInterval);
        }
        yield return new WaitForSeconds(waveSpawnInterval);
        currentWave++;
    }
}


summer stump
polar acorn
eternal falconBOT
#

:teacher: Unity Learn ↗

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

polar acorn
#

Stop guessing

#

Learn how variables work

#

Learn how to call a function on a variable

#

It's quite literally day one programming knowledge

#

this is a fundamental thing from which all other knowledge depends on

summer stump
#

This is the absolute most basic thing about c#
Consider yourself to have 0 knowledge in coding at this point if you can't figure out what you were told to do

ivory bobcat
# hushed hinge

It should have been exactly what I had here #💻┃code-beginner message
where you'd either assign the field through the inspector if the object wasn't instantiated or assign the field after the object was created.

polar acorn
#

if you don't know how to call a function on a variable holding an instance, then you cannot progress further until you do

carmine sierra
# polar acorn If you have, then that's great. I hope you've picked up some debugging steps to ...

so i found an issue in that i had an if statement (before the for loop to check for the broken bool), which required that spawnwood.placing was true, as there was a null reference error previously. However, placing is only true when the user is placing wood, but if you click the shop again (to deselect wood), placing becomes false. The issue i solved from removing that is that the player would never be firing the slingshot and placing at the same time, but now i get this:

austere hedge
slender nymph
#

you know something can affect an object's position without being in a coroutine, right?

polar acorn
carmine sierra
austere hedge
carmine sierra
#

I cant find that key to send code on my keyboard

summer stump
ivory bobcat
polar acorn
#

You'll need to look at where you're adding things to the list and see what's coming in as null

ruby python
south sky
ivory bobcat
# hushed hinge

Looks better but you could probably also do away with the guarding if-statement now. If you still get an null reference exception, that would mean that pickups is null and needs to be assigned from the inspector or by whoever spawned this object.

summer stump
austere hedge
#

@slender nymph I missed a detail. It overshot, but it went back. The logs indicate that the position has been reached, so even if something was affecting its position, it is hitting its mark but it's still not escaping the while loop since you can see the position has been hit 5000 times.

slender nymph
#

you're probably starting the coroutine a bunch of times

ruby python
ivory bobcat
ruby python
ivory bobcat
#

It's likely one of the two

ruby python
ivory bobcat
#

Is the path ever destroyed?

slender nymph
austere hedge
ruby python
slender nymph
ruby python
ivory bobcat
carmine sierra
hushed hinge
slender nymph
# austere hedge

well that is certainly odd. Vector3's equality operator is overloaded to return true when they are approximately equal so it's very strange that the condition is evaluating as false. it's less good, but you could check the distance and Mathf.Approximately with 0

carmine sierra
# polar acorn Yes

I am only appending from the updatewoodinstances() function using the add method

#

Unless that function itself has something wrong with it, i am not sure

#

but i dont see anything wrong with it

polar acorn
#

See if it's ever null when you add it

carmine sierra
#

good idea

austere hedge
carmine sierra
polar acorn
carmine sierra
#

the first time

slender nymph
carmine sierra
polar acorn
#

Which means when you try to use the object in the list, it'll throw a null reference

#

Is your list supposed to contain nulls?

oak island
#

Hi, can someone guide me how can I record microphone audio on android within unity?

carmine sierra
carmine sierra
south sky
polar acorn
# carmine sierra no

So, you should probably add a != null to that check you make before adding it to the list

carmine sierra
#

i see what it is, i add one every time there is a new value of woodinstance, and as the game starts with it being null, it adds that to the list

summer stump
austere hedge
#

@slender nymph If I set it to 8 floating points I can see that it's just a hair off.

slender nymph
#

right but as i've already pointed out the equality operator for Vector3 is overloaded to account for that

south sky
austere hedge
slender nymph
#

that is how you compare it to 0

austere hedge
# slender nymph that is how you compare it to 0

I changed the debug line to use MathF.

Debug.Log($"{name} is moving at {speed} units per second from {transform.position:F8} to {lootTopHeightFloatingPosition:F8} which is {Vector3.Distance(transform.position, lootTopHeightFloatingPosition):F8} units away. Has reached destination? {Mathf.Approximately(Vector3.Distance(transform.position, lootTopHeightFloatingPosition), 0)}");
#

Still says it hasn't reached its destination.

carmine sierra
#

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

what could be a cause of this error?

summer stump
austere hedge
#

@slender nymph I'm still researching, but maybe it's because I am setting the position using "new".

lootFall.lootTopHeightFloatingPosition = new Vector3(CurrentDirtPosition.x, CurrentDirtPosition.y + 2.2f);
lootFall.lootRestingPosition = new Vector3(CurrentDirtPosition.x, numPadKey.CurrentDirtPosition.y + -1.1f); 

https://discussions.unity.com/t/vector3-equals-not-working/101394/2

slender nymph
austere hedge
slender nymph
#

ah so it looks like unity's epsilon value is 0.0001 which is just ever so slightly smaller than your value of 0.0000124

#

that's actually hilarious that you are prevented from using unity's tools that help prevent floating point imprecision issues . . . due to a slightly bigger floating point imprecision issue

austere hedge
fathom frigate
#

One message removed from a suspended account.

hot palm
#

How can I check if a specific action is done? I would have thought similar to this. I want to check if it's the action called "Pause".

if (context.action == CharacterControllerMap.SimpleMovementActions.Pause)
slender nymph
#

what is the context of this code?

hot palm
#
private void Pause(InputAction.CallbackContext context)
{
    if (context.action == Pause) Cursor.lockState = (Cursor.lockState == CursorLockMode.Confined) ? CursorLockMode.Locked : CursorLockMode.Confined;
    else Cursor.lockState = CursorLockMode.Locked;
}
slender nymph
#

so assuming you've subscribed this to the Pause action's performed event and nothing else, then you can safely assume this is reacting to the pause action

#

you do not need to check that it is

hot palm
#

Yeah but I subscribed with ESC and LMB

#

Could do seperate ones or simplify this

#

But do you know how to ask what action the context called?

slender nymph
#

i honestly don't understand what you are trying to do

hot palm
#
characterControllerMap.SimpleMovement.Pause.started += Pause;

characterControllerMap.SimpleMovement.Interact.started += Pause;
#

I want to toggle pause with esc

slender nymph
#

why did you subscribe the Pause method to the Interact event

hot palm
#

If I click I want to unpause

#

Okay I dont do that and only have esc toggle pause, thanks- xd

#

Do drag and drop references not work in a build btw?

#

That'S the reason I did this

#

To check the debug log in my build

slender nymph
#

you should instead make whatever is subscribed to the Interact event check if the game is currently paused and unpause it if it is instead of trying to check what invoked the method

slender nymph
#

what would be the point in the ability to drag a reference into the inspector if it didn't work in a build

hot palm
#

idk what theme for this is but I get nullpointers in my build

#

Which I do not in the editor

#

So I assumed that's the problem somehow

slender nymph
hot palm
#

What is the timing of awake and onenable?

#

I just put the static instances before the ones calling them, so now it should work

slender nymph
#

they are both called immediately upon instantiation, in that order.

fathom frigate
#

One message removed from a suspended account.

hot palm
#

Is IDP.Generic something bcs of the development build?

slender nymph
hot palm
#

I see

rocky canyon
#

@fathom frigate

fathom frigate
crisp moon
#

Ive been really struggling with forcing myself to learn gamedev/unity or even to get an basic idea that isint too complex or strange, i want to make games but how can i with theses conditions? also yes i tend to be hard on myself.

rocky canyon
native flicker
#

Very simple

#

And good for starters in 2d

rapid mountain
hot palm
#

Does UI work while timescale is 0?

rocky canyon
#

if u want to be successful you gotta put the time in

crisp moon
rocky canyon
#

if at first u dont understand just rinse and repeat..

rocky canyon
#

try multiple resources.. find what learning method works for you

#

and start simple like mentioned..

#

Flappy birds is a classic to begin with

crisp moon
rocky canyon
#

absolutely

#

those are the best types to learn w/

hot palm
#

@rich adder too lazy to say yes or no xD Hey I would try it but I'm trying to optimize my time used for the game jam

rocky canyon
#

you'll feel better/ accomplished after u finish something..

#

so u want someone else to optimize their time for your needs instead?

hot palm
#

You don't have to answer

crisp moon
hot palm
#

But clicking a message and reacting takes more time than saying yes or no

rocky canyon
#

lol.. perhaps

hot palm
#

I assume it's a yes

rapid mountain
rich adder
fathom frigate
crisp moon
rocky canyon
#

soo.. say i want to build a circuit board simulator.. every component would take an in and output an out. this would be 0, 1 most likely.. (then the interaction system is seperate) how would be the best way to do this? so they're able to interact with each other?

#

w/o some complicated (if me/else you) conditional

rocky canyon
rapid mountain
rocky canyon
#

then ur ready to use it in ur controller.Move function

#

no need to change that line at all.. ur just modifying the move variable a bit before u use it

crisp moon
#

Thank you, those who responded to me and giving me advice.

rocky canyon
# crisp moon Thank you, those who responded to me and giving me advice.

Welcome to this introduction to game development. We'll be starting from the beginning, so no prior knowledge of programming or the Unity game engine is required.

Unity can be downloaded here: http://unity3d.com/get-unity

Watch episode 01: https://youtu.be/9iCnjdXEfMA

If you'd like to support these videos, you can make a recurring monthly don...

▶ Play video
#

this is a playlist that helped me tremendously when i started

crisp moon
tall delta
# rocky canyon soo.. say i want to build a circuit board simulator.. every component would take...

I know Sebastian Lague has a few videos exploring the subject. the code is also open source
https://www.youtube.com/watch?v=hEDQpqhY2MA

Displaying numbers is trickier than I expected! In this video we explore how to visualize the data inside of our simulated 4-bit registers, with the help of the double dabble algorithm and some seven segment displays.

Series playlist: https://www.youtube.com/playlist?list=PLFt_AvWsXl0dPhqVsKt1Ni_46ARyiCGSq
Simulation tool (work in progress): ht...

▶ Play video
rocky canyon
#

he also starts to make a game w/ the knowledge towards the end of hte playlist

rocky canyon
#

lol

crisp moon
rocky canyon
#

irrelevant.. learning is gonna take time..

#

many other sources are much much longer

crisp moon
#

so ill be sure to look into the playlist.

rocky canyon
#

its pretty straight forward tho

rapid mountain
crisp moon
rocky canyon
#

so.. ur hobbies.. they'll eat up time.. (coding is a hobby) until u learn

native flicker
#

Ye i spent a few hours at night cause i also can't rl do stuff in th day

rapid mountain
rocky canyon
#

so just take some time from other hobbies

#

and count this as a hobby as well

rocky canyon
crisp moon
rocky canyon
native flicker
#

We all got to start somewhere and time is needed, start with half a hour everyday and build that up

rocky canyon
#

i spent more time than that hunting for misspellings when i first started

#

😅

rapid mountain
rocky canyon
crisp moon
untold raptor
#
ghostBlock = Instantiate(buildingPrefabs[BlockID], hitPoint, Quaternion.identity);
// Another line
blockPrefab = buildingPrefabs[BlockID];
Destroy(ghostBlock);
ghostBlock = Instantiate(buildingPrefabs[BlockID], hitPoint, Quaternion.identity);
If you really want to remove an asset use DestroyImmediate (theObject, true);```
I keep getting this error when i change the block ID
rocky canyon
#

thats usually the issue 😄

untold raptor
#

thats exactly whats confusing me lmao

rocky canyon
#

ohh u are.. b/c u reset it

rapid mountain
#

you basically instantiated and destroyed the prefab at the very next line

rocky canyon
#

lol.. nah his code has similar wording

#

i think we were missreading it

#

he destroys ghostBlock not blockPrefab

untold raptor
#

i have no idea what to do lol

ivory bobcat
#

I think the excerpt is missing some data

rocky canyon
#

possibly.. can u show more of the code? or is that all thats relevant?

rich adder
rapid mountain
untold raptor
ivory bobcat
#

Maybe we're looking at the wrong spot

rocky canyon
#

code-dump incoming

untold raptor
#

i think thats all that is relevant

rocky canyon
#

error doesnt give any line-num does it

untold raptor
#

Interactor:PlaceBlock () (at Assets/Scipts/Interactor.cs:268)
Interactor:Update () (at Assets/Scipts/Interactor.cs:75)

fathom frigate
untold raptor
#

which is, one second

ivory bobcat
#

I think unless you know the exact line number you're going to need to show everything

untold raptor
#

268:

Destroy(ghostBlock);```
#

and 75 is just the placeblock function

rich adder
#

this aint even the whole code..

ivory bobcat
#

Did you make ghost block reference your prefab?

rich adder
#

where are the definitions

ivory bobcat
#

Because if you did, you'll get that error you've shown earlier

untold raptor
rich adder
eternal falconBOT
rich adder
#

this one sucks an ass

#

70% realestate for other people's script

#

shitty design

untold raptor
#

i wont bother reuploading that'll just be spamming but for next time i'll use a different provider

rich adder
#

yeah its hard to read on mobile 😢

cosmic dagger
#

a link with pure code is a godsend. no noise, no nothing; just code . . .

untold raptor
#

i do try and give just relevant code most of the time but it never helps in the long run lmao

rocky canyon
# fathom frigate One message removed from a suspended account.

its pretty straight forward.. here is your code :

Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
controller.Move(move * Time.deltaTime * speed); // Move the object using the transformed move vector```
and here is the instructions i gave you : 
```cs
Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

move.Normalize(); // normalize the move vector
move = transform.TransformDirection(move); // transform the move vector to match the direction of the object

controller.Move(move * Time.deltaTime * speed);
ivory bobcat
untold raptor
#

unless im not understanding right

ivory bobcat
#

Did you reference it from the inspector?

untold raptor
#

ohhhh

#

lemme check

#

yeah

#

i did

ivory bobcat
#

You've likely referenced a prefab from the inspector

untold raptor
#

these are just prefabs tho, I have other variables that instantiate

rich adder
fathom frigate
#

One message removed from a suspended account.

rich adder
#

who says webapps need js frameworks 💩

untold raptor
#

sorted it

#

thanks guys

lunar fern
#

yo does anyone know why my code only calculates the speed only like once per 5 frames? here is the code and a vid of the output(I'm trying to debug why my code isn't restricting the speed of the player) its a bunch but ill highlight the important bit: https://gdl.space/udutafupek.cs

#

btw i have bad wifi rn so i might take a while to respond sometimes

wintry quarry
#

if you want to be synced with the physics engine, that's what FixedUpdate is for

#

(you should also not be using AddForce in Update)

lunar fern
#

why shuldnt i?

wintry quarry
#

because it will lead to inconsistent behavior depending on your framerate

rich adder
wintry quarry
#

The physics simulation needs to happen at a fixed timestep or you will not get consistent behavior, and no this can't be fixed with Time.deltaTime

lunar fern
#

alright i will change it to fixedupate. thanks for the help

rich adder
#

OnCollisionEnter for grounding is not very reliable

hot palm
#

Anybody an idea why I get a nullreference exception in my build at if(gameManager.GameIsPaused)?

private void Start()
{
    if (gameManager == null) gameManager = GameManager.Instance;
}

private void Update()
{
    if (gameManager.GameIsPaused)
    {
        UpdateCursorLockState(CursorLockState.Confined);
    }
    else
    {
        UpdateCursorLockState(CursorLockState.Locked);
    }
}
lunar fern
rich adder
#

nothing else can be null on that line

rich adder
fathom frigate
hot palm
fathom frigate
#

One message removed from a suspended account.

rich adder
hot palm
#

But why is it null in the line below then

lunar fern
rich adder
#

if you said you assigned it and its not being unassigned at runtime, then you have a copy of the script with one unassigned

hot palm
#

okay let me remove the if null and run again

rich adder
hot palm
#

I wonder why it's only debugging that in the dev build and not in the editor

rich adder
hot palm
#

I got it right here

#

Ah wait

#

wrong class

#

lemme retry

rich adder
#

if you need to start changing orders of executions , your whole design is probably not good

hot palm
#

Well thing is I didn't have a problem in the editor

#

just the built gives me some

rich adder
#

also are you exporting the correct scene

hot palm
#

Yep

#

This the correct folder right?

rich adder
#

should be

hot palm
#

NullReferenceException: Object reference not set to an instance of an object
at CursorHandler.Update () [0x00001] in C:\REDACTED\UnityC\AFishFestGameURP\Assets\1_Scripts\Player\CursorHandler.cs:34

rich adder
#

ok and
CursorHandler.cs:34 is what

hallow acorn
#

public class PlayerMovement : MonoBehaviour
{
    private PlayerControls playerControls;
    [SerializeField] Rigidbody2D rb;

    [SerializeField] private float Speed = 10;
    [SerializeField] private float JumpHeight = 50;

    private bool IsGrounded = false;

    private void OnTriggerEnter2D(Collider2D collision) {
        IsGrounded = true;
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        IsGrounded = false;
    }
    private void Awake()
    {
        playerControls = new PlayerControls();
    }

    private void OnEnable() {
        playerControls.Enable();
    }
    private void OnDisable() {
        playerControls.Disable();
    }

    void Start()
    {
        Application.targetFrameRate = 60;
    }

    void Update()
    {
        Vector2 Move = playerControls.Move.Move.ReadValue<Vector2>();
        rb.velocity = new Vector2( Move.x * Speed, transform.position.y);

        if (playerControls.Move.Jump.IsPressed() && IsGrounded)
        {
            rb.AddForce(new Vector2(Move.x, JumpHeight));
        }
    }
}

hi this is my basic player movement srcipt, do i reset the y axis somewhere? bc my player isnt jumping as high as he should with jumpforce 4500, except in some weird cases he gets shot out of the known universe

rich adder
# hot palm

aside from start, where do you assign gameManager

hot palm
#

Only drag and drop

rich adder
#

also polling every update for GameIsPaused is overkill

hot palm
#

Yeah that's moment where I do IEnumerator and check every second or smth

#

But my friend is waiting for the build for 6 hours now 💀

rich adder
#

GameManager invokes a static event

#

public static Action<bool> OnGamePaused;

hot palm
#

since when doesn't GameManager have the special icon btw?

rich adder
#

it does

hot palm
#

Not for me somehow

rich adder
#

what about inspector?

hot palm
rich adder
rich adder
# hot palm

yeah thats weird.. hmm not sure are you on 2023?

hot palm
#

No 2022.3.20f1

#

bit old

rich adder
#

you mean 2022?

hot palm
#

yeah

rich adder
#

thats LTS

#

its not old

hot palm
#

oh thought I'd seen someone use .30f1

rich adder
#

idk i think version control might be messing with the icon

hallow acorn
short hazel
rich adder
short hazel
#

The higher you'll be, the faster you'll be going upwards

rich adder
#

also fix that

hallow acorn
rich adder
#

basically

opaque hinge
#

Not to interrupt what you guys are doing, but I was wondering if anyone could help me with some issues I'm running into with a basic game I'm working on

wintry quarry
#

If you ask about the issues, people might help you.

hot palm
#

I also get an error on the second line, even tho it works in the editor at runtime

if (renderManager == null) renderManager = RenderManager.Instance;

if (this.MaxPlayerDistance != renderManager.MaxPlayerDistance) this.MaxPlayerDistance = renderManager.MaxPlayerDistance;
rich adder
hot palm
#

Both errors still there

rich adder
#

you put null check ?

#

in if statement of Update

rich adder
# hot palm This is start

private void Update()
{
if(gameManager == null) return;
if (gameManager.GameIsPaused)
{
UpdateCursorLockState(CursorLockState.Confined);
}

opaque hinge
#

okay, I created a 7x7 hexagon grid and have an enemy in the middle of it. I'm trying to figure out how to write a code that has the enemy move one tile per turn towards the nearest edge piece.

hot palm
#

nvm the first one is update

rich adder
#

if no errors , you know that it was running without being assigned

opaque hinge
#

Yeah I watched a video on A* and got confused. I don't understand how each tile can be considered a unique node

rich adder
hot palm
#

Daijkstra :D

#

!code

eternal falconBOT
ancient trench
#

hey guys, how can i move center of my Physics2D.overlapbox?

opaque hinge
#

So I set the node to the starting tiles position, then put it in a list, then set nodes for all adjacent tiles and add them and so on?

willow scroll
ancient trench
#

ty

fathom frigate
#

One message removed from a suspended account.

fathom frigate
willow scroll
rocky canyon
fathom frigate
#

One message removed from a suspended account.

#

One message removed from a suspended account.

rocky canyon
#

are you following a particular tutorial?

willow scroll
eternal falconBOT
fathom frigate
#

One message removed from a suspended account.

#

One message removed from a suspended account.

willow scroll
#

well, on the site.

eternal falconBOT
fathom frigate
#

One message removed from a suspended account.

rocky canyon
#

my CC works the exact same way.. groundVector is just new Vector2(horizontalAxis, 0, verticalAxis);

#
                        if(useTransformDirection)
                        {
                            // run it through the TransformDirection to make movement relative to players direction
                            groundVector = transform.TransformDirection(groundVector);
                        }
                        else
                        {
                            groundVector = groundVector;
                        }```
#

in the clip the first part is using TransformDirection() and the 2nd part is when I disable it.. (then my turning doesn't matter)

#

it just moves relative to the world (w/o my facing direction mattering)

#

you said you tried it but didn't work.. thats interesting.. is ur Movement code running on the same object as the CC it should be

willow scroll
rocky canyon
#

he says this didn't help

#

thats the two lines i asked him to add

fathom frigate
#

One message removed from a suspended account.

willow scroll
fathom frigate
#

One message removed from a suspended account.

short hazel
#

Actually normalizing here is not good because it'll take a very noticeable amount of time for the player to stop moving, since GetAxis is smoothed you'll have a few frames between the moment you release the keys and the vector falls back to exactly (0, 0, 0)

fathom frigate
#

One message removed from a suspended account.

rocky canyon
fathom frigate
#

One message removed from a suspended account.

willow scroll
hexed terrace
#

Just move your camera look component to the parent

willow scroll
#

The TransformDirection works perfectly, so the issue is in the Camera, isn't it?

hexed terrace
#

the camera child doesn't (and shouldn't) need to be rotating separately from the parent

rocky canyon
#

perhaps the camera isn't rotating ur CC

#

if ur CC doesn't actually rotate then the TransformDirection isn't actually gonna work for ur usecase
not by applying it to the cc's transform atleast

fathom frigate
#

One message removed from a suspended account.

rocky canyon
#

your camera should be parented under the CC but u camera script need to rotate the camera up and down..

#

but rotate teh CC left and right

fathom frigate
#

One message removed from a suspended account.

hexed terrace
#

The camera GameOject should remain as a child of the player.
The camera rotation Component should be on the parent, and not the camera.