#💻┃code-beginner

1 messages · Page 341 of 1

ivory bobcat
#

Maybe describe what you're trying to do?

clear river
#

I have created a ScriptableObject named SOWorld, and I built a ScriptableObject array named SOWorldDataSet[]. The World scriptable object has a Sprite named encounterBackground.

I have a Canvas with a GameObject called Battle BG which includes an Image and a Canvas Renderer.

BattleHandler.cs should take the encounterBackground sprite from this scriptableobject Worlds, and apply it to the gameobject Battle BG.

Somehow I'm doing this very wrong. What's the best way to make this connection?

honest haven
#

i didnt really want the battle starter script being a instance if thats what you mean as static because each enemy would have on on the scene

fossil tree
ivory bobcat
swift crag
#

You would stash the list in a static field, then read that list in the battle scene

fossil tree
swift crag
#
public static class BattleData {
  public static List<Enemy> enemies;
}

a minimal example

swift crag
ivory bobcat
swift crag
#

ignore the code and the details

#

what is the game going to do?

honest haven
fossil tree
clear river
#

sits and waits for his turn - everyone is puzzling on other requests

swift crag
#

Have a look at this page

swift crag
#

A major effect of this is that you can access static members from anywhere, since you just need the class name

#
BattleData.enemies = ...
ivory bobcat
#

Log the value and see if the function is called. You'll also see what the value is and why it might not be doing what you're expecting it to be doing.

strong wren
clear river
#

Where does Debug.Log show up in the interface?

swift crag
#

it writes to the Console window

strong wren
clear river
#

I tried to use this earlier but the app was full screen

strong wren
#

here

clear river
#

I assume since it's a log it should go somewhere even after it closes

strong wren
clear river
#

I think I am missing that tab. I'll try to get it back

ivory bobcat
swift crag
#

Window > General > Console

clear river
#

Cool.

swift crag
#

that will reopen it

strong wren
clear river
#

Also, when you have the time I have a main question

swift crag
#

ask it!

clear river
#

It's back up at 7:50

ivory bobcat
clear river
#

Should I repeat it?

strong wren
swift crag
strong wren
swift crag
#

are you unsure how to give a SOWorld to the BattleHandler ?

strong wren
ivory bobcat
strong wren
clear river
#

I do not know the basics. =w=

swift crag
#

If you're experienced with programming but don't know Unity's interface, I'd check out the documentation

swift crag
#

the whole "Working in Unity" section will be useful

strong wren
#

thats why i added the 1

swift crag
#

and what was this error?

ivory bobcat
swift crag
#

You have to actually read error messages..

strong wren
#

i also tried to have it like this

ivory bobcat
#

Subtracting zero isn't going to be very productive

swift crag
#

well that's just completely mangled syntax

strong wren
swift crag
#

you didn't add 1 *

#

you added 1

#

Health.value -= * Time.deltaTime; would produce that error

#

get rid of the * operator.

ivory bobcat
strong wren
#

oh theres not an error no more

#

i always tought u always have to * by Time.deltaTime

swift crag
#

you multiply by deltaTime in many cases

clear river
#

My last attempt saw me create an Image in the BattleHandler.CS named BattleBack, then access that image via dropdown in the UI and link it to the actual background image on the canvas... but when I went to say "battleback.sprite = WorldDataSet[a].Worlds.encounterBackground.Sprite;

The UI said 'Images do not have sprites, you silly bean.'

swift crag
#

you don't literally slap * Time.deltaTime everywhere

strong wren
#

well that still didnt fix it

swift crag
#

If you just want to subtract one per second, do Health.value -= Time.deltaTime

#

If you want to subtract by some other rate, do Health.value -= rate * Time.deltaTime;

clear river
#

Also I just made many typoes. Sorry

#

Pseudo

strong wren
#

so i was subtracting by 1?

swift crag
#

There are a lot of classes called Image

ivory bobcat
#

If value is an integer, it'll not retain the accumulated decrements.

clear river
#

Uhhhoh

#

Okay thanks

swift crag
#

You want using UnityEngine.UI;

clear river
#

Is there a better way to do it then the general method I'm attempting?

swift crag
#

the code looks fine

clear river
#

Or do I have the best/a "good enough" method? I guess it's ok

#

Okay, let's go learn more about the various types of Images

#

Thanks again

lost hamlet
#

There are only 2 Image classes by default. The Image component and the UI Toolkit Image

swift crag
#

oh good heavens!

strong wren
lost hamlet
swift crag
#

maybe your IDE is smarter than mine :p

#

this is VSCode

lost hamlet
#

Yeah I use VSCode too

ivory bobcat
clear river
#

... typoes?

strong wren
clear river
#

Is Unity case sensitive??

lost hamlet
#

What exactly in Unity

strong wren
paper peak
#

C# is very case sensitive

strong wren
#

coding in unity is Case Sensetive

clear river
#

:[ I KNOW WHAT I DID

#

Thank you.

paper peak
#

Is it possible to change a public variable of a script from another script that resides in another gameObject?

lost hamlet
#

If you get a reference to that GameObject yes

molten dock
paper peak
#

How do i access the script after referencing the gameObject?

lost hamlet
#

<reference>.publicMember

ivory bobcat
lost hamlet
#

Oh sorry

#

GetComponent indeed

strong wren
swift crag
#

Show us the entire script.

#

I need to see what you are actually doing.

#

!code

eternal falconBOT
strong wren
swift crag
ivory bobcat
swift crag
#

You probably want to create a serialized reference, where you drag one object into another object's inspector

ivory bobcat
#

You'll want to update the float variable if you change the health's value elsewhere

paper peak
#

Is there someway i can change a gameObject's scale without having its children be affected as well?

ivory bobcat
#

Container
-Renderer
-Everything Else

#

If you separate the renderer, you'd be able to modify it alone without affecting everything else

#

These would all be Game Objects

ivory bobcat
# strong wren yep

Have it unchecked and you won't need to maintain any extra variables. You'd be able to simply decrement itcs Health.value -= Time.deltaTime;

atomic sierra
#

did unity remove their new monetization policy?

lost hamlet
#

They reworked it

#

And this is a code channel

ivory bobcat
atomic sierra
#

my apologies

fossil tree
rich adder
#

video alone doesn't help

fossil tree
#

but the camera dont depend of the code...

molten dock
#

have you guys noticed ontriggerenter sometimes responding to non trigger collilders

rich adder
fossil tree
rich adder
rich adder
fossil tree
#
using UnityEngine;

public class cloud_controller : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(move());
    }

    // Update is called once per frame
    IEnumerator move()
    {
        while(true)
        {
        for(int i = 0; i < 140; i++)
        {
        transform.Translate(new Vector2(0,-0.2f));
        yield return new WaitForSeconds(0.05f);
        };

        transform.position = new Vector2(Random.Range(-10, 10),9 );
        }
    }
}
storm pine
willow scroll
#
    1. Why are you not using the default naming conventions?
    1. Why are you moving the cloud in a Coroutine?
    1. Why are there no serialized values?
fossil tree
rich adder
#

that too me seems 100% a choppy behavior waiting 0.05 each iteration

fossil tree
#

that not my problem i know my code is bad

rich adder
#

how you know thats not the problem

willow scroll
rich adder
#

yet look how it behaves

#

sum random 140 times for loop inside a while loop

#

weird

fossil tree
#

ty for the help

rich adder
#

just put this in Update
transform.Translate(Vector2.down * moveSpeed * Time.deltaTime)

#

you don't need anything else

fossil tree
willow scroll
#

🔃

transform.Translate(moveSpeed * Time.deltaTime * Vector2.down)
rich adder
#

wdym

fossil tree
#

like tp on top

willow scroll
#

Basically have a bottom edge, and when the position <= edge, move the cloud to the startPos

#

This way you don't have to care about its speed

fossil tree
#

how can i get the position of my cloud

willow scroll
fossil tree
#

ok no i got it

willow scroll
#

I hope so

fossil tree
#

ok i patch this but the problem is the same

rich adder
fossil tree
#

i think i understand why my balloon are slow

#

i dont * by time.deltatime

#

but how can i do for the camera?

rich adder
#

wdym for the camera?

#

are the objects moving down or is the camera moving up

#

unclear

fossil tree
crystal vale
#

Hi I’m new to Unity and I just want some tips for the Visual Scripting since I have worked a lot with Scratch when I was younger.

rich adder
#

i'm not in mood to play 20 question, you should #854851968446365696 on how to properly get help here by being clear and descriptive

fossil tree
rich adder
fossil tree
#

i patch the problem with time.deltaTime

storm pine
fossil tree
#

but my other problem is my camera screen size are not the same in build

rich adder
fossil tree
# rich adder

yes i say i have patch the speed problem with * time by time.deltaTime

#

sry if i have bad explain i'm not english

rich adder
#

you asked how you can do it for the camera

#

hence why I said, why would you want to do it to camera if its not moving

fossil tree
#

yes mb

storm pine
#

Because when you are playing it on the Editor have the Free Aspect set ( and it looks so extended) and when you play on fullscreen is 16:9 frequently

fossil tree
#

ty

flint python
#

Hi, i am making a space shooter game, and I am uncertain whether to use object pooling or instantiate + destroy.

So far I know object pooling helps performance, by having duplicate objects ready and just reusing them, but if I want to shoot a bullet every 0.5s and deactivate the current bullet when it's outside the screen, for this I will need to create 50+ or more duplicates.

If my game has many bullet types, I will need to create thousands of duplicates, is it worth having better performance but a larger game size?

Please give me some advice, thanks.

rich adder
#

make a prewarm of 150+ and you should be fine

#

Instantiating and Destroying will cause much more garbage

wintry quarry
#

If so do that

#

Otherwise make a pool per type

storm pine
flint python
#

Thanks all

rich adder
#

ScriptableObject is also another way to just make the Bullet class flexible with multiple data

ivory bobcat
#

Why not both.

blazing warren
#

I'm trying to make a very basic player character for my VR project. I want the player to have a ship model attached to them, which matches the players position and head rotation (minus up and down). But I'm not sure what the model of the ship should really be parented to

#

Currently my setup is like this, with the "Blue Viper" prefab being the ship model. Everything else is self explanatory I think. Does this parenting hierarchy seem logical?

swift crag
#

perhaps you should just copy the head's position and rotation with a script

#

The XR Origin is the center of your playspace. Parenting to that means the ship is not following the player's head

lost hamlet
#

Wouldn't player camera fit the best then?

blazing warren
#

Should the XR Origin not be moving along with the player when the player moves ingame (not in real life)?

lost hamlet
#

No

tough cave
#

I made a Gameobect/prefab that was outisde the canvas. But now I want it inside the canvas visable. How do I make the gameobject visable in my canvas? I hoped adding the Canvas renderer would fix that lol. but no.

rich adder
#

your object is still in Transform and not Rect Transform which is what happens when it becomes part of canvas

blazing warren
# lost hamlet No

So to be clear, you think the XR Origin shouldn't move when provided ingame input like from a controller? I'm not referring to head movement IRL

honest haven
#

Cannot instantiate objects with a parent which is persistent. New object will be created without a parent. if (activeBattlers[currentTurn].isEnemy) { activeBattlers[currentTurn].ChildPartickleEffect(activeBattlers[currentTurn].zoneHighlight); } the parent object is now an instaticated prefab. but i dont understand the error

fluid glen
#

I went on unity version control once now I can’t get rid of it, how do I get rid of it?

lost hamlet
blazing warren
#

I believe it's called the XR Interaction Toolkit. The XR Rig might be considered a starter asset from it, I'm not sure

honest haven
#

i have two errors

rich adder
#

the Instantiate

honest haven
#

line 654

rich adder
#

what is ChildParticleEffect() method

honest haven
#

yep two secs

rich adder
cursive hinge
#

if i use paint trees i seem to lose the tag of the tree prefab, how else can i check if the object is a tree?

honest haven
rich adder
honest haven
rich adder
#

ohh

honest haven
#

i found this, could it be thins

verbal dome
#

Looks liketransform belongs to a prefab

rich adder
#

but ur not passing the prefab

#

ahh that might do it

honest haven
#

thats where im lost i dont understand

#

but the prefab is a game object, so would it belong to the gameobject

verbal dome
#

You are calling this method on a prefab, not an instance

#

Petsistent = prefab

honest haven
#

So what would be the fix

#

thats good to know 'Petsistent = prefab' thanks

verbal dome
#

Use an actual instantiated object

#

You are trying to parent it to a prefab, that can't work

#

If it's still unclear, show how you are calling that method

honest haven
#
    {
        foreach (var battlers in StaticBattleEnemys.enemies)
        {
            activeBattlers.Add(battlers.gameObject.GetComponent<BattleCharacters>());
        }
        
        if (cubes.Length == StaticBattleEnemys.enemies.Count)
        {
            for (int i = 0; i < cubes.Length; i++)
            {
                // Assign the enemy to the cube's position
                Instantiate(StaticBattleEnemys.enemies[i], cubes[i].position, Quaternion.identity, cubes[i]);
            }
        }
        else
        {
            Debug.LogError("Number of cubes does not match number of enemies.");
        }
    }``` So my game objects are instantiated objects of a prefab
verbal dome
#

But where are you calling the ChildPartickleEffect method from?

honest haven
verbal dome
honest haven
#

So these SS level 1 clones hold a script called BattleChars

#

thats where that method is

verbal dome
#

Looks like you have added prefabs to activeBattlers

honest haven
verbal dome
#

You should add the instantiated objects instead

honest haven
#

yes

#

let me expalin

#

so a npc holds a script called Battler Starter it holds a list of BattleCharcters(scripts). Im using a Static Class to pass this to a new scene

#

Then on my battle manager im Adding the static list to a cleared New list

#

then im getting this error

#

so yes they are prefabs to start off with then i instaciated them in the battle scene

verbal dome
#

Ok but again, activeBattlers should have the instances, not the prefabs

#

How are you adding stuff to activeBattlers?

verbal dome
#

So they come from battlers

honest haven
#

2 secs let me make a video

verbal dome
#

And those are prefabs. Dont do that

honest haven
#

yes those are prefabs

#

So the goal was to pass active batters to the battle scene .ie the models and attached scripts

verbal dome
#

Instantiate returns the newly created object. Add the BattleCharacters from that, instead of from the prefab.

honest haven
#

i understand, so the ref from the Instantiate, use that?

#

Instantiate(StaticBattleEnemys.enemies[i], cubes[i].position, Quaternion.identity, cubes[i]);

#

make this a new list

#

and do my work to that?

verbal dome
#

Something like this cs foreach(var battlers in StaticBattleEnemys.enemies) { var instance = Instantiate(battlers); activeBattlers.Add(instance); }

honest haven
#

i have a error

#

but somthing like that

#

yes

#

thanks

rotund egret
#

Hey guys :D i need help On unity with my game

#

I basicly need a object to always follow another object

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.UIElements;

public class player_move : MonoBehaviour
{
public GameObject bullet;
public float jump_power = 1f;
Rigidbody2D RG;
// Start is called before the first frame update
void Start()
{
RG = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{

    if (Input.GetButton("Jump"))
    {

        RG.AddForce(Vector2.up * jump_power, ForceMode2D.Impulse);

    }
    if (Input.GetKeyDown(KeyCode.R))
    {
        GameObject newbullet = Instantiate(bullet);
        newbullet.transform.position = new Vector2(-10f,0);
    }

}
private void OnTriggerEnter2D(Collider2D collider)
{
    Debug.Log(collider.name);
    if (collider.name == "smallpipe")
    {
        Application.Quit();
        UnityEditor.EditorApplication.isPlaying = false;
    }

}

}

#

this is the code basicly

#

You can see it spawns the bullet

#

but not where the player is at

#

only the middle

#

and i want to change that

#

any ideas

languid spire
#

I suggest you read the Instantiate documentation and look at all of the method overrides

#

also !code

eternal falconBOT
honest haven
rich adder
#

if you want to spawn it on player, pass in the player position..

onyx vortex
#

Hello all, I am placing my character on a moving platform but I am getting two issues.
1: The character isn't sticking on the second moving platform.
2: There character mesh gives off weird stretching when it stands on the moving platform as you can see above.
I have been at this issue for nearly 2 days now, any suggestions are appreciated.

rich adder
#
  1. is probably you not properly un-parenting and re-parent to second platform ?
    (just assumptions based only what you give so far, show the code / setup)
languid spire
#

you need the following setup
Empty GameObject
-- Platform
-- Player

onyx vortex
#

Here is the platform code im using its pretty simple

rich adder
#

!code

eternal falconBOT
rich adder
onyx vortex
#

Sure lemme take a few images rq and link em up

weary finch
#

If I want to make a question about the asset submission process, which channel should I use?

rocky canyon
#

good question..

#

their guidelines and documentation is pretty good

onyx vortex
onyx vortex
onyx vortex
#

Isn't this the only way to keep the player on top of the moving platform?

languid spire
#

no because the platform and player are children of the empty so when you move the empty they both move

onyx vortex
#

Its starting to make sense, a moving/deformed platformed will deform the player set as a child as well, giving weird results

languid spire
#

any object which is scaled will pass that scale to their children

onyx vortex
#

I see, well what about the script? It only works on the first platform but the player will slide like ice on the second one, even though the script is on the other one as well~

onyx vortex
spare mountain
languid spire
onyx vortex
#

This is jumping onto the moving platform then jumping back to the normal one

#

This is jumping onto the moving platform then jumping to another moving platform (Player doesn't stick to the second moving platform for whatever reason) ¯_(ツ)_/¯

languid spire
#

then your platform setup is probably incorrect

onyx vortex
#

Perhaps, I have multiple collisions and rigid bodies on the Jumping character, might that cause this problem or its def the platforms?

languid spire
#

I would say it's the platform. put a debug outside of the if to see if the code is being called at all

onyx vortex
#

I think I got it, there are multiple collisions working against each other lol

#

I feel so stupid

rocky canyon
#

glad u fixed it.. platforms are always a Bich

stuck palm
#

how can i remove a gameobject from a parent in code?

rich adder
#

you don't have a reference?

stuck palm
#

sorry i mean like

stuck palm
rich adder
#

.SetParent(null)

stuck palm
#

okay

#

thanks

#

is that on transform or gameobject

rich adder
#

yes transform

stuck palm
#

cool

#

thank you 😄

amber veldt
#

Yo guys, call me crazy but what the hell is a constructor? Why do we need this guy? Is it a class? Is it a function? Why does it have to have the same name as the class? This is driving me insane!

rich adder
rich adder
amber veldt
#

Why is that??

rich adder
#

because Unity creates them internally

amber veldt
#

Why hides things from me?

rich adder
#

huh?

amber veldt
#

I'm having so much trouble man

#

Learning C# first then trying out Unity Logic is driving me loco

#

Thank you though, I'll check out the documentation

rich adder
#

yes there are differences between unity objects and regular c# objects, but in the end they all are objects

amber veldt
#

This is what confuse me the most, the fact that MonoBehaviour is an "autoconstructor"

#

When in C# I need to define the constructor

rich adder
#

MonoBehaviour is part of a bigger system

swift crag
#

You are forbidden from creating a "naked" MonoBehaviour that isn't part of one

#

It would be bogus to do Component oopsie = new MyCoolComponent();

swift crag
rich adder
#

GameObject for example has a constructor

swift crag
#
public class Whatever : MonoBehaviour {
  public int x = 123;

  public Whatever() {
    Debug.Log("Value: " + x);
  }
}

This will log Value: 123, even for scene objects / instantiated prefabs that have a different value saved for the field

#

This is why you have Awake: it runs immediately after Unity creates the component and restores the serialized properties into it

#

(assuming its game object is active, at least)

swift crag
#

consider this example:

public class DestroyMe : MonoBehaviour {
  public int val = 100;
}

public class Destroyer : MonoBehaviour {
  public DestroyMe target;

  void Awake() {
    Destroy(target);
  }

  void Update() {
    target.val += 1; // completely fine
    target.transform.position = Vector3.zero; // throws an error
  }
}

Destroying a Unity Object just tells Unity that it should go away from the game world. You are no longer allowed to use things Unity provides you (like the transform property), but everything else is fair game.

rancid zenith
#

am i a ding dong orrrrr, its saying PlayerLook aint a thing

rocky canyon
#

ur referencing a class called PlayerLook..
unless you have a script called PlayerLook.cs

#

it show an error

paper peak
#
public string[] lines;
```What does [] at the end of string word do
#

I tried looking on google but i dont know how to phrase it correctly

rocky canyon
#

theres probably more to the tutorial or something you've missed @rancid zenith

paper peak
#

Nice thanks

rancid zenith
#

i legit know nothing, i just started, im using it the same way im using playerinput & playermotor

eternal falconBOT
#

:teacher: Unity Learn ↗

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

rocky canyon
#

ya, thats what it is.. ur project just doesn't have a class called PLayerLook yet..

rocky canyon
#

once you make one.. that error will go away

rancid zenith
#

alr lemme rewatch the past couple mins of this video

rocky canyon
#

care to share the video? ill skim it

rancid zenith
#

The first video in a series where we are creating a First Person game!
In this video we look at setting up our characters movement.

I've setup a Discord!!! and I would love to have you help me start up a friendly community where we can all help each other grow as game developers!

Discord invite link:
https://discord.gg/xgKpxhEyzZ
Can't wait t...

â–¶ Play video
rocky canyon
#

he creates it around here..

#

so just keep doing the tutorial.. and it'll work out.. not sure why he wouldn't create the script before trying to access it in another script

#

or perhaps he does..

rancid zenith
#

got it, yeah i missed that part up top, thanks!!

#

thats what i missed

rocky canyon
#

important part.. thats what defines the name of the class

rancid zenith
#

noted

amber veldt
#

Going back to the constructor thingy, there is this stuff called "Primary constructor" where you can put parameters to the class no?

#

It's a preview feature nah? sorry I'm a noob

swift crag
#

Primary constructors are introduced in C#12

#

Unity is on C#9

rocky canyon
#

future man!

amber veldt
#

Got it, it's not confusing enough

#

plz end me boyz

swift crag
#

A primary constructor is just used to reduce the amount you have to write.

amber veldt
#

yeah I figured

#

But man the "instance" thing is my demon

#

everytime I see the "new" keyword, I have a panic attack

rocky canyon
#

simple, an instance is just a creation of a thing..

swift crag
#

take a chill pill and go follow some Unity tutorialsl

amber veldt
#

I'm around 1 year and a half of Unity tutorial

#

I need courses

#

So much stuff badly explained or plain wrong, now I only do official doc lol

#

But this is where the real journey start I guess hehe

rocky canyon
#

i learned with tutorials..and yea lot of stuff can be wrong.. but thats when u learn to fact check.. or get a 2nd opinion..

#

good skill to have in general

storm pine
amber veldt
paper peak
#

Is it possible to add an entire string array to an already existing string array?

polar acorn
rocky canyon
#

you shouldn't add to arrays

#

use Lists<> instead

strong wren
#
    public GameObject Coin;
    [SerializeField] float RespawnTimer;
    [SerializeField] bool isCoinGone = false;
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Coin.SetActive(false);
        SS.Score++;
        SS.HealthVal++;
        isCoinGone = true;
    }

    private void Update()
    {
        if (isCoinGone == true)
        {
            RespawnTimer -= Time.deltaTime;
            Respawn();
        }
    }

    public void Respawn()
    {
        if (RespawnTimer <= 0)
        {
            Coin.SetActive(true);
        }
    }``` why is the respawn void thing not working?
#

wait leme make it so only the important stuff shows up

rocky canyon
#

it should work.. after isCoinGone gets changed to true

strong wren
rocky canyon
#

are u sure it doesn't get called? or rather Respawn Timer conditional isn't true

#
    public void Respawn()
    {
        Debug.Log("RespawnFunctionCalled");
        if (RespawnTimer <= 0)
        {
            Coin.SetActive(true);
        }
    }```
#

try debugging

strong wren
#

i put a log in the if isCoinGone statement

#

and ive noticed that its always on

#

theres a bug

#

if i turn it on manually the timer goes down but if it turns on from the collision it doesnt start

#

so the code should work?

#

like the code isnt the issue?

rocky canyon
#

use debugs and find out.. put them everyhwere so u can trace whats happening

strong wren
#

but idk how to fix

rocky canyon
#

possibly ur collision isn't working correctly

strong wren
storm pine
#

On Respawn I think you should reset your RespawnTimer

rocky canyon
#

^ thats 1 thing i noticed as well..

strong wren
storm pine
#

Your RespawnTimer just go down and down but it is never reset

rocky canyon
#
public void Respawn()
{
    if (RespawnTimer <= 0)
    {
        Coin.SetActive(true);
        Debug.Log("Coin respawned.");
        
        // Reset the RespawnTimer
        RespawnTimer = initialRespawnTimerValue;
        Debug.Log("RespawnTimer reset.");
    }
}```
strong wren
# strong wren

as you can see all coins are present, the isCoinsGone bool is set to false yet the Debug.log is happending

rocky canyon
#

ya, after that first respawn.. ur timer is already lower than the threshold..

#

gotta reset it for it to be useful

storm pine
strong wren
#

sorry im still learning the inital thing is new to me

rocky canyon
#

ya, at the start of the script u should cache what ur starting value is..

#

and then once u trigger the respawn reset the timer back to what it started as

polar acorn
# strong wren

Add this log in Update:

Debug.Log$"{gameObject.name}'s IsCoinGone = {isCoinGone}, Respawn Timer = {RespawnTimer} Coin = {Coin.name}");
rocky canyon
#

i usually count upwards.. that way i dont need an extra variable..

strong wren
rocky canyon
#

i just reset the timer to 0..

strong wren
#

so in my case i just do RespawnTimer = 3;

rocky canyon
#

if 3 is the value u want..

strong wren
#

i tought if i put initial it would like reset the value of the variable to the value i gave it by default

rocky canyon
#

hardcoding like that is frowned upon tho..

#

not unless u tell it to

strong wren
#

my float is Serialized cause i have multiple and i wish for them to respawn well at diff times but thats kinda hard to do so i gave each coin a diff value

rocky canyon
#

digi's debug is a good choice imo shows all ur data in 1 string/sentence

rocky canyon
#

so u can use different values if u wish..

#

and thats y i said to cache the value..

#

u shoulnd't need to hardcode a value

strong wren
rocky canyon
#
[SerializeField] float initialRespawnTimer;
float RespawnTimer;```
strong wren
#

if i do RespawnTimer = 3; then every coin will respawn every 3 seconds

#

wait im kinda stupid

#

nvm

rocky canyon
#
 RespawnTimer = initialRespawnTimer;```
#
private void Start()
{
    // Store the initial respawn time when the coin is instantiated
    RespawnTimer = initialRespawnTimer;
}```
strong wren
#

bro, how fast can you type?

rocky canyon
#

b/c i already have the script in a notepad

#

copy and pasting

#

thats y we urge people to post code.. instead of screenshots 😄

strong wren
#

no but i tough if i do do RespawnTimer = 3; then they all would respawn at the same time lol, that would only happen if all coins were picked up at the same time

rocky canyon
#

soo if u use a coin with a 4 it'll reset the timer to 4.. if u use one with 3. itll reset to 3

strong wren
#
    public GameObject Coin;
    [SerializeField] float RespawnTimer;
    [SerializeField] bool isCoinGone = false;
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Coin.SetActive(false);
        SS.Score++;
        SS.HealthVal++;
        isCoinGone = true;
    }

    private void Update()
    {
        if (isCoinGone == true)
        {
            Debug.Log("You picked up a coin");
            RespawnTimer -= Time.deltaTime;
            Respawn();
        }
    }

    public void Respawn()
    {
        if (RespawnTimer <= 0)
        {
            Coin.SetActive(true);
            RespawnTimer = 3;
        }
    }```
#

this is the whole code

rocky canyon
#

because it just caches the value in start

storm pine
rocky canyon
#

^ this

strong wren
#

sorry i forgot

strong wren
rocky canyon
#

it'll only work if ur Timer is set to 3

#

any other value wont

strong wren
#

uhj

#

i think i found an issue

storm pine
rocky canyon
#

magic numbers suck

strong wren
#

what are magic numbers?

rocky canyon
#

hardcoded values..

strong wren
#

like values set in the code?

#

like int Money 10;

rocky canyon
#

myCar.color = blue; vs

and then u can set desiredColor however u want in the inspector ```
#

the first one would be a magic number / color..

strong wren
#

uhm so i did smth and now smth else happened

storm pine
#

Yep, you can use direct values to initialize a variable, but no far from there

strong wren
#

everytime i ran the game this if (isCoinGone == true) { Debug.Log("You picked up a coin"); RespawnTimer -= Time.deltaTime; Respawn(); } would always go on now i turned smth off and it doenst spas out anymore

#

the isCoinGone bool was turned on in the inspector

#

which is wierd to give me an error since i made it so the bool is false by default

#

hm wierd

#

the if statement isnt working

#

this is interesting

#

if i start the game and i check the isCoinGone bool on in the inspector the code works

#

but if i pick up the coin which still turns on the bool it doenst

storm pine
rancid zenith
#

my game feels like its running in like 30fps, its very choppy when i move, i.e: i can see the cubes skip frames when I move

rocky canyon
#
public class TimerScript : MonoBehaviour
{
    [SerializeField] private float startingTimer = 10f;
    private float currentTimer;

    private void Start()
    {
        currentTimer = startingTimer;
    }

    private void Update()
    {
        currentTimer -= Time.deltaTime;

        if (currentTimer <= 0)
        {
            currentTimer = startingTimer;
        }
    }
}``` here is a timer that i could use for different objects all having different values to count to... in the start method we just cache w/e we have set in teh inspector

```cs
using UnityEngine;

public class TimerScript : MonoBehaviour
{
    private float currentTimer = 10f;

    private void Start()
    {
        
    }

    private void Update()
    {
        currentTimer -= Time.deltaTime;

        if (currentTimer <= 0)
        {
            currentTimer = 10f;
        }
    }
}``` this version uses a hardcoded value... it can only ever work if our value is 10
rocky canyon
#

true or false... (on or off) (0 or 1)
bool

strong wren
#

but if i write if(isCoinGone) how would the code know to check if it should only run if the bool is TRUE

storm pine
rocky canyon
#

u already using it..

#

the condition returns true or false

strong wren
#

so just remove the == true?

storm pine
strong wren
#

well nothing really changed

#

what if i move the if statemnt into the OncollisionEnter Void?

strong wren
rancid zenith
strong token
rancid zenith
#

the edges become a little fuzzy and less defined

rocky canyon
#

i use coroutines more often than not myself

valid roost
#

any idea why this occurs

strong wren
#

i so i put the if statement into the oncollisionEnter method and it fixed smth

#

now it works but not rlly

rocky canyon
strong wren
#

if i pick up a coin it tells me that and it also only goes off once

storm pine
strong wren
#

but the RespawnTimer only goes down by 00.2

valid roost
strong wren
#

its cause it only happends once

valid roost
#

it occurs

strong wren
#

if i maybe add another if statement then i can make it so it goes down

#

what if i make it so if the respawntimer is smaller then 3 it should make it even smaller

valid roost
#

😭

rocky canyon
storm pine
rocky canyon
#

it gone..

valid roost
#

oh shit

#

i didnt see this

#

thx

rocky canyon
#

remove that

valid roost
#

thx

storm pine
# valid roost thx

To ensure, shut down your pc and change the hard disk, it doesn't look ok

valid roost
#

what

rocky canyon
#

idk lol

storm pine
# valid roost what

Just joking, I thought the file of your script was corrupted by a bad hard disk

valid roost
#

i still

#

have that error

#

although there is no script

strong wren
#

i think theres an issue with my update method

paper peak
#

I have a public array(X1) in a script(Y1) and i have another array(X2) in another script(Y2),
Is there someway i can replace array X1 with array X2 while using script Y2?

#

Theyre both string arrays

storm pine
west sonnet
#

What's the best way to get an object to ignore collisions with another specific object, but collide with everything else?

west sonnet
paper peak
#

Array X1 is just there to be modified, its empty most of the time. I want to replace the contents of array X1 with the contents of array X2

storm pine
# west sonnet How?

Set a tag on you object and in the method OnTriggerEnter2D(Collider2D other) just add a simple condition like: if(other.CompareTag("Player")), so it will only work if the object that start the trigger is the type of player

strong wren
#
    public GameObject Coin;
    [SerializeField] float RespawnTimer;
    [SerializeField] bool isCoinGone = false;
    [SerializeField] bool TimeStart = false;
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Coin.SetActive(false);
        SS.Score++;
        SS.HealthVal++;
        isCoinGone = true;
        if (isCoinGone)
        {
            Debug.Log("You picked up a coin");
            TimeStart = true;
        }
    }

    public void Update()
    {
        if (TimeStart)
        {
            RespawnTimer -= Time.deltaTime;
            Debug.Log(RespawnTimer);

            if (RespawnTimer <= 0)
            {
                Respawn();
            }
        }
    }
    public void Respawn()
    {
        Coin.SetActive(true);
        isCoinGone = false;
        TimeStart = false;
        RespawnTimer = 3;   
    }``` why is this code not working 😩
scarlet skiff
#

so i started making my game work for multiplayer, but then it kinda messed up the single player, this prob related to the player or whatever having netcode properties while the scene doesnt have an object woth a network manager, but i dont know exactly what to od here, here is the error:

#

what is liek the best way to make a scene not think of the multiplayer stuff?

storm pine
storm pine
strong wren
#

idk why

#

yeah now the debug isnt even working

#
 public GameObject Coin;
 [SerializeField] float RespawnTimer;
 [SerializeField] bool isCoinGone = false;
 private void OnCollisionEnter2D(Collision2D collision)
 {
     Coin.SetActive(false);
     SS.Score++;
     SS.HealthVal++;
     isCoinGone = true;
 }

 public void Update()
 {
     if (isCoinGone == true)
     {
         RespawnTimer -= Time.deltaTime;
         Debug.Log("You picked up a coin");
         Respawn();
     }
 }

 public void Respawn()
 {
     if (RespawnTimer <= 0)
     {
         Coin.SetActive(true);
         isCoinGone = false; 
         RespawnTimer = 3;
     }
 }``` this is the original code
#

and it still doenst work which makes no sense

storm pine
strong wren
#

if i pick up the coin then the bool should be set to true and every frame it checks if the bool is true

strong wren
strong wren
storm pine
#

private void OnCollisionEnter2D(Collision2D collision)
{
if(!iscoinGone){
Coin.SetActive(false);
SS.Score++;
SS.HealthVal++;
isCoinGone = true;
}
}
try changing this method, this way it will just iterate once

strong wren
strong wren
storm pine
storm pine
#

It's translated like a not

strong wren
#

nothing changed

#

wait i found smth interesting

storm pine
#

Try changing like this:
public void Update()
{
if (isCoinGone)
{
RespawnTimer -= Time.deltaTime;
if (RespawnTimer <= 0)
{
Respawn();
}
}
}

public void Respawn()
{
Coin.SetActive(true);
isCoinGone = false;
RespawnTimer = 3; // Reset timer
}

#

So it's the update the one that checks if the timer is less than 0

strong wren
#

but i found smth interesting

#
{
    if (isCoinGone)
    {
        Debug.Log("Coin isnt there");
    }
    else
    {
        Debug.Log("Coin is there");
    }
}```
#

i added this to my

#

update method right

#

well it works as intented

#

but it only says Coin Isnt There if i pick up ALL the coins

storm pine
#

Your code is not that complex, something may be wrong in other part

strong wren
#

the Debug.Log("Coin isnt there"); only runs if i pick up ALL the coins

rocky canyon
#

it may be there but being pushed out of view by ur debugs..

#

shuld collapse ur debugs so duplicates just get a number added to the side of it

strong wren
#

doesnmt everyone?

storm pine
#

add private to your variables
[SerializeField] private float RespawnTimer;
[SerializeField] private bool isCoinGone = false;

rocky canyon
#

lol.. somepeople dont

rocky canyon
strong wren
rocky canyon
#

can't remember if its default setting or not

strong wren
strong wren
rocky canyon
strong wren
rocky canyon
#

by using serialized field on a private variable.. u keep it so other scripts still cant access it. but its visible in the inspector (as a public field would be)

strong wren
#

oh ok

#

still didnt fix anything btw

storm pine
rocky canyon
#

i think its just a tip more than a fix..

#

learning the right way to do things..

strong wren
#

dude why is it not working 😩

#

its such a simple code

storm pine
rocky canyon
#

i dont even understand the issue tbf

strong wren
#

this isnt running

#

it should run when the isCoinGone bool is set to true

rocky canyon
#

true

strong wren
#

which gets set to true if i collide with a specified thing

rocky canyon
#

show that part

strong wren
#

this works tho

#

when i collide with the specified game object the isCoinGone gets checked

rocky canyon
#

Coin.SetActive(false); if the coin gets set to InActive.. the update loop wont run anymore

strong wren
#

so the code stops with it too?

rocky canyon
#

yes..

#

if u disable the object.. the update loop wont function anymore

strong wren
#

how.... do fix it tho?

#

where should i play the Coin.SetActive(false);?

#

i cant place it in update can i?

rocky canyon
#

after u do all the stuff u want it to do

#

u should probably use a Coroutine..

strong wren
rocky canyon
#

that way u can delay the setactive part.. until the rest of hte code finishes

strong wren
#

idk what that is

rocky canyon
#

lets back up..

#

what is it that you want to happen?

#

and also !code share ur code in a paste-bin link so i can see the entire thing

eternal falconBOT
strong wren
#

when i collide with the Coin i want it to dissapear then i want to get 1+ in the score and an extra second to live (u get 5 at the start) then i want the coin to respawn after 3 seconds

#

pretty simple

rocky canyon
#

okay.. cool yea, that does sound pretty simple..

#

now share ur code in a paste link

strong wren
#

here

tepid pike
#

can someone walk me threw on how to export your game as a apk

strong wren
#

you go into build settings and switch the platform to andriod

#

tbh i should also ask why i couldnt export my game i had some issues with gardle and i couldnt export it

#

which sucks but maybe i can get help here

tepid pike
#

can i share my screen

#

to you

strong wren
#

sure/

tepid pike
#

ok i made a call

storm pine
# strong wren https://hastebin.com/share/cafaxalelo.csharp

You can use the same code, but don't add it to the object that it's your coin. You can have a parent (we could call it Coincollider for example) that will have the component Collect and the Collider and a child object inside of it that will just have the sprite of the coin

strong wren
#

oh

rocky canyon
#

the graphics are seperate from the coin.. that way i can disable the gameobject..
you could use a single object. and just disable the meshrenderer instead.. meshRenderer.enabled = false;

strong wren
#

wont that make it so you can always colide with it?

rocky canyon
#

but what happens is i enter the trigger:

  • the coroutine starts
  • it disables the graphics
  • and disables the collider (so now we can't collide with it anymore)
  • it then waits 3 seconds
  • and re-enables everything
rocky canyon
#

orr.. u could reference the Mesh Renderer.. / sprite renderer/ or w/e and disable that instead

#

but i disable the graphics and the collider <-- thats the main point.. b/c we want the gameobject to still be active and run the Update()

rocky canyon
#

u could also

  • Coin Object
  • Graphics + Collider <-- just disable this gameobject
#

to disable both the graphics and the collider at the same time

strong wren
#

oh wait

#

i can do that

rocky canyon
#

many ways to do it. but the idea is to keep the Coin (Script) running

#

just disable the collider intead

#

and i Use a coroutine.. b/c its better than a timer.. (imo)

strong wren
#

alr

stuck palm
#

how can i repeat a block of code a set amount of times? i know theres a for loop, but what if i want a delay between loops?

strong wren
#

it should still work right?

#

if it collides with the GameObject specified in the inspector which is coin 1 it should turn it off but its not the gameobject running the code

rocky canyon
#

Collision events have to be run from a script on teh same gameobject as the collider

strong wren
#

oh

rocky canyon
#

u can't put the script else-where and expect it to log collision events

#

from a different collider

#

the reason i referenced the collider is just so i can disable it.

strong wren
#

how can i turn the collision off on a gameobject?

rocky canyon
#

now u can disable other colliders and things from different scripts.. but the Collision events dont work that way

rocky canyon
#

and put ur objects on that layer that u want to ignore

#

u can also do it globally from here

#

u can uncheck certain layers.. soo entire layers ignore each other

strong wren
#

huh?

#

but cant i dissable the collider of the empty GameObject Thru Code?

#
float SpeedX, SpeedY;
Rigidbody2D RB2D;
public SpriteRenderer SR;
void Start()
{
    RB2D = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
    SpeedX = Input.GetAxisRaw("Horizontal") * MovSpeed;
    SpeedY = Input.GetAxisRaw("Vertical") * MovSpeed;
    RB2D.velocity = new Vector2(SpeedX, SpeedY);
    if (RB2D.velocity.x > 0f)
    {
        SR.flipX = true;
    }
    else if (RB2D .velocity.x < 0f)
    {
        SR.flipX= false;
    }
}``` as u can see here im turning the FlipX thing on and off at will
rocky canyon
#

you can disable any collider u have a reference to..

storm pine
rocky canyon
#

a collider is just like any other component

#

component.enabled = true/false;

strong wren
rocky canyon
#

CC.enabled = false;

strong wren
#

oh

#

i tought smth like CC.Collider = false

#

wait im so stupid it makes more sense if u say it idk

rocky canyon
#

no.. ur referencing a collider..

strong wren
rocky canyon
#

aCollider.aCollider doesnt make sense

strong wren
#

yeah i just realized

storm pine
strong wren
rocky canyon
#

^ if u referened a gameobject with CC
then it would be
CC.GetComponent<CircleCollider2D>().enabled = false;

#

which would get a CircleCollider2D from the gameobject thats called CC

strong wren
#

ok

#

omg it works

#

dude @rocky canyon me and 4 other guys have been stuck on this issue for 8 hours

rocky canyon
#

glad i could help

strong wren
#

im not kidding i started making this feature at like 15:00 now its 00:27

#

ive asked in brackeys in the gamejam server

rocky canyon
#

😅

strong wren
#

and it was such a simple thing 😭

rocky canyon
#

ya, i figured once i wrote a script and showed a video.. it'd kinda start to make sense

#

heres a tip to keep in mind..

#

keep ur graphics and ur logic seperate

#

always!

#
  • Root Gameobject
  • Graphics
strong wren
#

oh

rocky canyon
#

it'll save soo much trouble in the long run

#

if u want to do stuff w/ ur graphics u shouldnt have to worry about ur scripts stop running

#

same w/ the colliders and whatnot..

#

its not always the case.. but its easier to know that ur script is running on its own gameobject

#

and physics and rotations go crazy when ur scales are different than 1:1:1

#

so thats another reason..
ur root object should always be scaled to 1.. and that way ur graphics can be resized as a child object and it wont affect the way physics interact w/ ur object

#

like the example i sent earlier.. my coin is actually a squished sphere..

rocky canyon
#

but i squish the child object.. so the Coin object is still scaled to 1:1:1

minor musk
#

Quick question, is there a Physics.SphereCast equivalent for Physics2D? All I'm trying to do is to check if there's a collider in the specified area but they all require to provide a Collider2D list, or RaycastHit2D list, or they return a RaycastHit2D/Collider2D result, I don't know how to check if there's an object or not in the specified area

eternal needle
minor musk
#

I have to filter or check if there's more than one collider 'cause it detects the 2d capsule collider as well, I have the controller as a children

#

so far everything I've tried always returns true so I'm trying to understand what's happening

#

coming from the 3D side this is quite weird for me x)

eternal needle
blazing plank
#

Does anyone know how to input small float values in the Unity inspector?
I can't fade the image out smoothly because small steps are visible during the fade

#

0.001 seems to be fine, but steps of 0.0001 aren't visible

slender nymph
#

show the code you are using to actually fade it out. because it seems like you are hard coding the steps rather than gradually fading over time

quaint mica
#
if (heartcounter == 4 && SceneManager.GetActiveScene().name == "Level2")
{
    SceneManager.LoadScene("Level3");
}

This code works sometimes but sometimes the other scene doesn't load

#

Does anyone know why that happens

slender nymph
#

well for starters, why do you need to compare the active scene's name instead of just incrementing the current scene index and loading the next scene with that? also have you done any debugging to ensure this code is actually running and that your conditions are what you expect them to be?

quaint mica
#

Would it make a difference if I used an index vs using the scene name

#

Is it for performance?

slender nymph
#

no, it would reduce the amount of very similar code. because i'm just gonna go ahead and assume you have a very similar check for moving from Level1 to Level2

#

and it would remove a mostly useless check

spare mountain
slender nymph
#

that is someone entirely different

spare mountain
#

OH

#

my bad

#

sorry scar

quaint mica
#

I have debugged it and it works but sometimes the scene doesnt load

slender nymph
#

have you confirmed that code is running at the time you expect the scene to load but it doesn't?

quaint mica
#

Yes it usually only doesnt load when its built. It works fine most of the time in the game view

slender nymph
#

and have you done any debugging in the build to ensure the code is running and your conditions are what you expect them to be?

#

you've also not shown the context for this code, so this is really the only advice i can provide

quaint mica
#

How do i debug in a build

slender nymph
#

build as a development build and attach the debugger. you can use breakpoints and tracepoints to see what your code is actually doing

quaint mica
#

Ok thanks i will try that out

blazing plank
# slender nymph show the code you are using to actually fade it out. because it seems like you a...

The code is a bit complicated, but here it is:

float opacitySpeed = CalculateOpacitySpeed(Mathf.Abs(OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, ovrGrabber.GetM_Controller()).y));

//Checking for controller input, that's just the example for the downMovement of the stick:
if (downMovement)
                {
                    currentColor.a = (Mathf.Max(currentColor.a - (opacitySpeed * Time.deltaTime * 0.8f), 0f));
                    
                    controllerItemCollection.opacityDownIcon.transform.localScale = Vector3.Lerp(controllerItemCollection.opacityDownIcon.transform.localScale, downIconScale /*the target*/, Time.deltaTime / scaleLerpTime); //TODO: put the code from the bottom from scaling inhere, this seems more responsive
                }

float CalculateOpacitySpeed(float thumbstickPosition)
    {

        if (thumbstickPosition < activationAmount) return 0; // No scaling below 20%
        else if (thumbstickPosition >= activationAmount && thumbstickPosition <= 0.95f)
        
        {
            float normalizedPosition = (thumbstickPosition - activationAmount) / (0.95f - activationAmount); // Normalize position to range 0-1
            float speedFactor = normalizedPosition * normalizedPosition; // Apply quadratic curve for more noticeable speed change
            return minOpacitySpeed + (maxOpacitySpeed - minOpacitySpeed) * speedFactor;
        }
        else return maxOpacitySpeed; // Use maxSpeed above 80%
    }

The whole code is in the update method

spare mountain
strong wren
#

hi

spare mountain
#

```cs

#

not
```
cs

strong wren
#

i have this simple issue where i cant call a function from my other script

spare mountain
blazing plank
strong wren
slender nymph
#

yours is on the next line

blazing plank
spare mountain
strong wren
spare mountain
spare mountain
strong wren
#

as you can see i am trying to call on my script SoundManager but it gives me an error, the thing is ive called ScoreSystem the same way and still no error

blazing plank
#

ah, fixed it

strong wren
#

it just says the namespace couldnt be found

spare mountain
strong wren
#

simple code

rocky canyon
#

it says that cuz it assumes that u wouldnt try using a script that doesn't exist
so.. if it does exist.. its probably a simple mistake like u forgot to add the namespace
but most newbies.. the script is just missing

strong wren
#

very tiny

spare mountain
strong wren
spare mountain
strong wren
#

and whilsts i was calling on the sound manager script it just gave me this error

spare mountain
#

does this error show up in the editor?

strong wren
#

no

strong wren
rocky canyon
#

odd

blazing plank
rocky canyon
#

y u have so many problems

strong wren
strong wren
rocky canyon
#

oof

rocky canyon
strong wren
#

ive been ther

#

but the error doenst show up in the console

spare mountain
#

then just ignore it or re set up your ide idk

blazing plank
spare mountain
eternal falconBOT
strong wren
#

oh yeah found the issue

spare mountain
#

if you try this again it might go away

spare mountain
strong wren
#

its set as a misc file

spare mountain
#

lol

strong wren
#

how... do i change it?

#

everything else is in asemble.C#

#

leme just reboot visual studio

#

yep there u go

stuck palm
#

if unity used doubles instead of floats, would that glitchy effect not happen when you get far away from the world?

swift crag
swift crag
#

Although, that glitching is caused by rendering

#

you'd have to be using doubles on the GPU

stuck palm
swift crag
#

because floats are smaller (4 bytes vs. 8 bytes), and float math is much faster

stuck palm
#

right

swift crag
#

it's the same reason that you use half-floats for machine learning

stuck palm
#

are there any engines that use doubles?

swift crag
#

dunno off the top of my head

#

Unity does have a Double4x4 matrix struct that you can use to do all of the usual transform math with doubles

#

I've experimented with using that for one of those "scale of the universe" visualizers

#

you know, where you zoom out from a cell to the size of the universe or whatever

#

everything stored its actual position as a Double4x4, which was then used to set its actual position, rotation, and scale

stuck palm
#

yeah

#

interesting

#

idk why i asked i was just curious lmao

#

thank you

quick kelp
#

hey
kinda need some help. Made my items persistent by attaching a dontdestroy on load script to them the items are children to the dontdestroy script
found this bug that i have no clue on how to fix for the time being where if i pick up one in the room it shows up in the slots but if i leave with said item come back to said room pick up another the 2nd item does not show up in the 2nd slot

rocky canyon
#

is float3 still a thing?

quick kelp
#

getting hastebin code now

swift crag
cosmic dagger
rocky canyon
#

i think so..

#

thats where im seeing it

#

wasn't sure if it was outdated

#

but it is indeed in the mathematics lib

#

float3 is more performant.. i think

#

im still reading on it

rocky canyon
quick kelp
small mantle
#

@ashen niche What happened after you did it?

ashen niche
feral moss
#

How do I have an object instantiated after the game starts running set a reference to an object that's existed since the game started running?

small mantle
feral moss
#

I have a grid whose tiles are prefab objects, and I'd like them to have a reference to the gridManager object that created them

slender nymph
small mantle
frozen steeple
#

I'm creating the player controller and Im using a CharacterController to have the player walk around. The thing is, I want to have the player fly on a broom occasionally. Can I still use the CharacterController for that? or do I just disable it and enable a RigidBody?

frosty hound
#

You can use the CC still

small mantle
slender nymph
#

moving via the transform is 100% the cause of their issue. doing so does not respect colliders so they are more easily able to penetrate into other colliders even with continuous collision detection

twilit pilot
#

I'd think most likely you're clearing the _slots list/array somewhere

quick kelp
#

here the whole inventory select

twilit pilot
rocky canyon
#

he mentioned his items are children of a DDOL i think

quick kelp
#

the menu no
the way it works is the player, misc controllers and inventory are children in a dontdestroy object

#

i do it this way cause the script has an object index

#

as to destroy duplicates

feral moss
#
//In Tile.cs used by the Tile prefab within the Tile class object
public GridManager grid;

//Class header in the script used by the GridManager object present in the scene
public class GridManager : MonoBehaviour

Why am I getting a type mismatch here?

slender nymph
#

are you trying to drag a scene object into an asset like a prefab? because that's not possible

quick kelp
small mantle
#

I am making a game where the Player can turn into two types of forms (outside of their default), a Gear Form or a Super Form. I am wondering how I should keep track of these two Groups. Should I use GameObject arrays or Lists. I ask because I won't have more than 10 forms for each Group. Which method would be more effective and easy to navigate for this concept?

feral moss
#

How do I do that in code?

quick kelp
#

if it helps this is how the ddol is laid out

feral moss
#

Ah thank you

#

I'm also curious why Type mismatch is the error it gives me

#

Or why it lets me try to select a scene object for that field

slender nymph
twilit pilot
slender nymph
small mantle
slender nymph
#

i mean your arrays should also not be GameObject type but rather the type of component you actually care about using

quick kelp
#

ok to explain before i got back and try with debug logs

if i start to play and pick up item A it shows up in the inventory slot not problem the problem arises when i leave the room to next scene and come back to pick up item B thats were the problem is im able to pick it up cause the object disappears as it pickup code tells it to do

#

its that item B upon pickup wont show up in the second slot

#

even tho i picked it up

#

and now that i think about it i might need to look at the pickup code

twilit pilot
#

to be clear I understand the problem, but I don't follow your explanation of which script is which

#

if InventorySelectController is not on a DDOL object, that is your problem

quick kelp
quick kelp
twilit pilot
#

if it is, then I'd add some debug logs to check what the status of that list is as you change rooms

quick kelp
#

ok pick up script works according to logs

#

so must be the ui controller

twilit pilot
#

yeah, sounds like a reasonable next step if the data structure is correct

quick kelp
#

yeah

#

its the ui controller

quick kelp
#

pick up item before leaving room

#

debug log tells me a slot has been filled

#

leave room and come back and pick up test cube

#

debug log says nothing

#

only the first log of a slot being filled

misty coral
#

this is a location in the gameworld right? Im tryna lerp toward it but it seems my object just goes endlessly

deft grail
#

this gives absolutely zero information

misty coral
#

err...

#

I dont necessarily need a direct answer to the problem

#

because its like 250 lines long

#

I just need to know what Im doing

#

(I dont)

deft grail
#

a lerp is not 250 lines long

misty coral
#

well its not just lerp

#

it handles a lot of other stuf

deft grail
#

and no one can help of saying
"this is my add force is it correct?"
transform.postion + 65f + other.position - 32.0005f

deft grail
misty coral
#

I think the problem Im having is I have multiple areas where I call lerp, and Im finding out that stacking lerp calls doesnt work that great

deft grail
#

impossible for me to know the problem by just seeing a bit of maths

#

so i cant really help either

misty coral
#

I think Ill try a different solution

#

I dont rlly want you to have to read 250 lines of spagetti

deft grail
#

i wouldnt read 250 lines anyway 😂
just find the lerp and what i need

misty coral
#

Like you can see from the vid, I am lerping to a bunch of positions

#

I changed it now to a timer, but it still looks jank

deft grail
#

why not use an animation?

misty coral
#

Am compsci student and thought it would be fun to do it that way

#

because if I animate it its not a "coding project"

deft grail
#

well theres probably better ways than lerping anyway

misty coral
#

also isnt procedural better to be able to apply recoil patterns to a bunch of things? Instead of animating them individually

#

Like I can just change some numbers and have a different recoil strength for a dif gun

deft grail
#

this is the opposite of procedural im pretty sure

misty coral
#

huh

deft grail
#

but looking at your code there isnt even a lerp?

#

your using move towards

misty coral
#

I changed it

#

I was just messing around

deft grail
#

sooo, show the code we actually need to be looking at?

misty coral
#

(Im tryna figure out the difference)

misty coral
#

just imagine the movetowards is a lerp and that is the code

deft grail
#

the current code, the one with the lerp, the one your trying to fix

misty coral
#

So the issue Im having is that because (as you can see from the video) I am lerping/movingtowards a bunch of different positions, and they dont work well with eachother

deft grail
#

ive never seen if(UnityEngine.Input.GetKey)
you import Unity for a reason so you can do just Input.GetKey

misty coral
#

Yea I had it like that and then VS kept flagging it

#

I am pretty sure it works either way

deft grail
#

i guess, just unnecessary and long for no reason

misty coral
#

you mean my entire code? LOL

#

But yeah I was thinking to fix the issue Im having I could have all the lerp/movetowards handled by one lerp call, and I use different methods to adjust where it lerps towards

#

that could work right?