#💻┃code-beginner

1 messages · Page 603 of 1

rocky canyon
#

well u can have two prefabs.. 1 with 0,0,0 and 1 with 90,90,90

#

and they'll both spawn the exact same place..

#

up to you to feed in the position and rotation to the Instantiation() call

alpine gyro
#

GridObjectFactory.CreateByTypeAndParent(BookShelfTypes.BookShelf1)
My init is very generic X_x

polar acorn
#

If you duplicate it, you are probably passing a copy of the list of colors for it to use. Then they'd both be sharing the same lists and changes to one would affect both

alpine gyro
#

maybe change the model in blender and export it again is the best option..
THANK YOU VERY MUCH!! LOVE TO LEARN!!

#

❤️ 🙏 🔥

earnest wind
#

thanks

wintry quarry
#

I mean I don't know how many times I have to say you're using the same list

#

I said it like 3 times beforew

earnest wind
polar acorn
#

Basically this entire script probably needs to be Ol' Yeller'd and rewritten as like twelve different scripts

earnest wind
#

but not for data

earnest wind
#

i will probably look back at this in like 2 years and face palm myself

#

i know it is very bad code but its cause i was trying to get it to not copy itself 😭

polar acorn
earnest wind
#

i do these mistakes so he wont do any in future

keen owl
#

kind of find it annoying how they went from Rigidbody.velocity to Rigidbody.linearVelocity in unity 6 😦

polar acorn
#

Well, it's more consistent with angularVelocity now

keen owl
#

Yeah the naming is better I guess. I was so used to using velocity lol

keen owl
wintry quarry
#

Well I just made these helper functions and used them everywhere so I only had to add them here.

astral falcon
#

Imagine the velocity would have returned linearvelocity in unity 6 by default 😄

humble hound
astral falcon
humble hound
#

Ok shukran

warm raptor
#

why does the value of each of the 3 rotation axes vary when my script is only supposed to affect 2 axes and not 3 ?

private void Sway(float SourisX, float SourisY)
    {
        float sway = SourisX * Time.deltaTime * SwayForce;
        float swayUp = SourisY * Time.deltaTime * SwayForce;
        float swayBack = Time.deltaTime * SwayForceBack;
        float swayUpBack = Time.deltaTime * SwayForceBack;
        CurrentSway += sway;
        CurrentUpSway += swayUp;
        if (sway != 0 && System.Math.Abs(CurrentSway) <= MaxSway)
        {
            Head.transform.Rotate(0, 0, -sway);
        }  
        else if (sway == 0 && CurrentSway > 0 )
        {
            Head.transform.Rotate(0, 0, swayBack);
            CurrentSway -= swayBack;
        }   
        else if (sway == 0 && CurrentSway < 0 )
        {
            Head.transform.Rotate(0, 0, -swayBack);
            CurrentSway += swayBack;
        }       


        if (swayUp != 0 && System.Math.Abs(CurrentUpSway) <= MaxSway)
        {
            Head.transform.Rotate(-swayUp, 0, 0);
        }
        else if (swayUp == 0 && CurrentUpSway > 0 )
        {
            Head.transform.Rotate(swayUpBack, 0, 0);
            CurrentUpSway -= swayUpBack;
        }   
        else if (swayUp == 0 && CurrentUpSway < 0 )
        {
            Head.transform.Rotate(-swayUpBack, 0, 0);
            CurrentUpSway += swayUpBack;
        }
    }
wintry quarry
#

friends don't let friends use euler angles

#

Long story short - euler angles are not unique. There are infinite ways to represent any rotation with euler angles, and some ways use some axes and some ways use others.

warm raptor
wintry quarry
#

The computer doesn't know or care or have any way to "prefer" one way or another to represent the rotation

#

it's not just gimbal lock - it's the ability for rotations to be represented in different ways

grand snow
#

thats true, its stored as a quaternion so as it changes it spits out what it thinks it is in euler for us dumb humans to read

warm raptor
#

But what I don't understand is how we can have problems of this kind. Isn't the reference frame for each of the three axes supposed to be a right-handed triad?

wintry quarry
grand snow
#

tbh i dont know but the xyz euler rotation is not really what the rotation is, i dont know how quaternion -> euler conversion is done but dont worry about it if its working

wintry quarry
#

And since the rotation is not actually stored as euler angles, it will just try its best to come up with something human readable

warm raptor
polar acorn
#

The general rule is "Always Read or Always Write, never both".

Store your own copies of what you want each angle to be, and set the eulerAngles to them. Never read the values from it, use your stored values instead

wintry quarry
teal viper
wintry quarry
#

So far it seems to be just "I don't like these ugly numbers in my inspector"?

warm raptor
wintry quarry
#

I would just have a Vector3 localRotation variable

#

and modify that

#

and set transform.localEulerAngles to it

#

you wcan fully manage that vector

warm raptor
wintry quarry
#

and it won't ever stray out of control

#

the fact that you're using transform.Rotate means all this logic is unbounded

#

it's just additive, and there's nothing keeping it near 0

warm raptor
wintry quarry
#

you're not staying in control of the values

#

you're kind of blindly adding

#

by keepiung your own variable you will stay in full control of it

mossy jasper
rich ice
low token
mossy jasper
wintry quarry
#

capitalization

#

of the letter "i"

mossy jasper
wintry quarry
#

Also you need to configure your IDE

eternal falconBOT
wintry quarry
#

!ide

eternal falconBOT
wintry quarry
#

also...
new Vector3(0, 0-1)...?

#

If you are copying code from somewhere you need to pay closer attention and not make typing mistakes.

mossy jasper
wintry quarry
#

you are simply not copying it exactly. You're making mistakes

#
  1. Configure your IDE
  2. Stop making mistakes when you copy the code
mossy jasper
wintry quarry
mossy jasper
wintry quarry
#

you have to configure it

wintry quarry
#

if you did, you wouldn't have these errors

#

go back

#

try again

#

look closer with your eyes

#

And CONFIGURE YOUR IDE
!ide

eternal falconBOT
wintry quarry
#

Follow the VSCode link and do what it says^

wanton epoch
#

I have 2 issues with my player movement which I would love to have people's suggestions to fix.

  1. When I turn, I am flipping my sprite/animations, the problem is that when I am next to a wall and turn, I go through the wall and fall

  2. Now I have set it to if I am not grounded, I cant jump, the problem is that when i go off a platform without jumping, I can use a "saved" jump and jump midair.

https://paste.mod.gg/ggjwokwhyvgo/0

wintry quarry
mossy jasper
wintry quarry
mossy jasper
wintry quarry
wintry quarry
#

follow the VSCode link

#

as I said above

mossy jasper
#

im switching to roblox studio bro😭 🙏

wanton epoch
wintry quarry
#

or modify the animator to animate the child object instead

rich ice
eternal falconBOT
#

:teacher: Unity Learn ↗

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

slender nymph
#

you should try reading the error message

toxic frigate
#

hello everyone, does anyone know why the gas leaks dont destroy themselves once the gasbag is out of air?

private IEnumerator AirLeakageRoutine()
    {
        while (amountOfGas > 0)
        {
            amountOfGas -= totalAirLeakageRate;
            if (amountOfGas < 0)
            {
                amountOfGas = 0;
            }
            yield return new WaitForSeconds(1);
        }
        OnAirDepleted();
    }

    private void OnAirDepleted()
    {
        Debug.Log("Gasbag is out of air!");
        for (int i = gasLeaks.Count - 1; i >= 0; i--)
        {
            var leak = gasLeaks[i];
            if (leak != null)
            {
                leak.GetComponent<ParticleSystem>().Stop();
                Destroy(leak);
            }
            gasLeaks.RemoveAt(i);
        }
        gasLeaks.Clear();
    }
wintry quarry
toxic frigate
#

particlesystem

slender nymph
#

also the RemoveAt call is pointless

toxic frigate
#

oh wait

wintry quarry
#

not the GameObject

#

also yes this particular RemoveAt is pointless

#

as is the reverse iteration

toxic frigate
#

its a list with gameobjects

#

i misread, apologies

wintry quarry
#
Debug.Log($"Destroying {leak.name}");```
#

it's possible your list is empty or full of null references

last owl
#

is it possible to lerp random.range numbers to another random.range numbers? so for example random.range(4, 8) to random.range(1, 4) over a certain amount of time

wintry quarry
#

Random.Range immediately returns a random value

#

you can create two random numbers and lerp from one to the other sure

#

but beyond that it's not clear what you're asking

wanton epoch
wintry quarry
#

pay attention to your code

last owl
#

I have a spawner that spawns enemies every 4-8 seconds but over the course of game runtime I want it to increase to every 1-4 seconds

#

but not instantly switch from 4-8 to 1-4 I want it to gradually increase

wintry quarry
#

min = Mathf.Lerp(startingMin, endingMin, time / duration);

#

Honestly though you should use an animation curve for this

#
public AnimationCurve MinCurve;
public AnimationCurve MaxCurve;
float timer = 0;

void Update() {
  timer += Time.deltaTime;

  float min = MinCurve.Evaluate(timer);
  float max = MaxCurve.Evaluate(timer);
}```
#

then just use min and max in your Random.Range whenever you need to

#

which presumably is at the moment each enemy spawns

last owl
#

hm interesting thanks, I will have to look into animationcurves more I had no idea it could be used like that

mossy jasper
#

I cant be this unlucky

rich ice
#

go check !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

slender nymph
wintry quarry
#

stop making typing mistakes

wintry quarry
#

stop making typing mistakes

#

when you follow a tutorial, follow it exactly

slender nymph
#

that's not even the issue lol

wintry quarry
#

This as well

#

follow the tutorial

slender nymph
#

line 4 is the issue and the lack of configured vs code

wintry quarry
#

oh gosh lmao

#

yeah you still haven't configured your IDE

#

@mossy jasper we can't help you with anything until you configure your IDE.

slender nymph
wintry quarry
honest vault
wanton epoch
#

the left picture is the most I can run to the left.

#

before my collider touches the wall

wintry quarry
#

seems like your collider and your sprite aren't matching up

#

adjust the position of the sprite and/or the position and size of the collider so they match

#

Also good idea to make sujre this is set to Pivot

#

so you can actually tell where your objects are

zinc lintel
#

Hello, my OnTriggerEnter doesn't seem to be working for the objects i have with the tag "Obstacle", I think it's because i'm teleporting the object but i'm not sure it could be something else.
I'm spawning an item with a 2d collider at a random place, and i have an object with a 2nd 2d collider and a rigidbody, i'm trying to make it so that if that random place happens to be inside that object, it will try to spawn it again somewhere else but it's not working

wanton epoch
#

The thing is that for idle it is correct but the running animation moves the player to the side.

#

and i cant have a collide thats wide af

wintry quarry
#

and print out what oobject it's seeing and what its tag is

zinc lintel
#

I'll try that

wintry quarry
#

fix them

wanton epoch
#

wdym offset to the left?

wintry quarry
#

it's the red and green arrow thing

wanton epoch
#

ooooh you meant that

wintry quarry
#

your sprite and the collider are off to the left

wanton epoch
#

true true

wintry quarry
#

everything should be in the middle

#

for both directions

#

and you should double check your spritesheet and how the sprites were sliced

#

it may be that you have a bunch of empty space in the sliced sprites on opposite sides for the left and right facing sprites

#

make sure all the sprites are tight around the actual pixels

wanton epoch
#

ill have to check since its a free asset. Also, im trying to center the stuff so that they arent offset but everything just moves with the pivot

wintry quarry
#

you can change the center

#

and the offsets or whatever

#

(and there should be an edit collider button too)

zinc lintel
wintry quarry
zinc lintel
wintry quarry
#

I assume that's some part of the code I haven't seen?

#

I have no idea what choosing a random location means

wintry quarry
#

If that code is running, it's running

#

Debug.Log to make sure it's running

#

but, presumably it's running if you called the SpawnFood function

#

Now if the logs STOP then it's not running anymore

wanton epoch
wintry quarry
wanton epoch
#

the clipping through walls and not being able to go completely left

wintry quarry
#

Show this same screenshot but when you're facing left

wintry quarry
#

show it with the gizmos

#

in scene view

#

like the above shot

wanton epoch
#

oh

wintry quarry
#

yep see

wanton epoch
#

ye okay

wintry quarry
#

I think this is clearly an issue with your sprites

zinc lintel
wanton epoch
#

too much empty space?

zinc lintel
wintry quarry
#

or maybe on both

wintry quarry
zinc lintel
wintry quarry
#

Then there's nothing entering the trigger anymore

hollow palm
#

Greetings, I want to ask something that has been really bothering me lately. Is there a performance difference between:
-The 5 enemies each have their own script for moves.
-1 script manager controls all moving enemies.

Enemy move logic will be like this:

Transform[] pathPoints;

public void Move()
    {
        if (currentPathIndex < pathPoints.Length)
        {
            transform.position = Vector2.MoveTowards(transform.position, 
                pathPoints[currentPathIndex].position, speed * Time.deltaTime);

            if (Vector2.Distance(transform.position, pathPoints[currentPathIndex].position) < 0.1f)
            {
                currentPathIndex++;
            }
        }
    }
zinc lintel
wintry quarry
wintry quarry
#

it only happens when you first enter it

#

if you didn't exit

#

you won't enter again

zinc lintel
#

Ohhhhh, i see, thanks !!

#

So something like this should work right ? If everytime it enters it i put it far away and do it again ?

wintry quarry
#

no

#

honestly I'm not sure i understand what you're trying to do here

hollow palm
wintry quarry
#

OnTriggerEnter etc only will run during the physics update

wintry quarry
wanton epoch
wintry quarry
#

if you encounter a performance problem, worry about it then

zinc lintel
wintry quarry
#

use the profiler to see what your performance bottlenecks are if you have a framerate issue.

hollow palm
wintry quarry
#

e.g. Physics2D.OverlapSphere

hollow palm
#

really help me

wintry quarry
zinc lintel
wintry quarry
#

SPheres are 3D 😛

summer thorn
hollow palm
#

i see

#

Pardon me, I'm paranoid about my current mobile game project

#

i thought that mobile game should do more optimization

hollow palm
summer thorn
#

you'll know you need to use a more optimized approach when you need to

hollow palm
#

okok

summer thorn
hollow palm
#

yea im sorry, just stupid question

zinc lintel
#

Uhm what does this mean ?

#

It happens when i try to build

polar acorn
#

What is on the line the error indicates

polar acorn
timber tide
#

as well as their own probably

#

imagine the best job you can get in your country is a deskjob at a video game company

drifting cosmos
#

i dont get how gameobjects work like can you spawn them like an object in c# like a class and its constructor parameters like enemy(speed, damage)

slim salmon
timber tide
#

and no, you don't have the ability to use a normal c# constructor with them since it's required to use Unity's instantiation method

#

doesn't mean you can't make your own initialization method or serializing the values in the editor

teal viper
timber tide
#

Whatcha mean? It uses the default constructor

#

Serialization is done through reflection bullcrap, right (when instantiating)

teal viper
timber tide
#

Oh yeah, I guess what I mean is you can't use a constructor on your monos, but for gameobject yeah you can create them in code if you wanted. I actually didn't know you could pass in components like that though

#

Not that I would ever do that, haha

drifting cosmos
timber tide
#

Yeah, that's where you can also do some initialization as well as like I said you don't have a constructor for your monobehaviours

#

Ideally you should be just using prefabs, and not constructing new gameobjects. Unless you're doing something generative game, but even then you'd have something templated where you are only adding onto those objects after instantiating that template.

teal viper
drifting cosmos
rocky canyon
#

prefabs are just gameobjects, with pre-configured components

wintry quarry
#

You can use either, depending on the effect you're going for

#

Although this is not a code question

tough shard
bitter apex
#

okay so I have a gameobject with a rigid body which acts as a character, and then thousands of other game objects which do not have rigid bodies and only have box colliders. I don't particularly want the ones with box colliders to collide with eachother, which is why I haven't just given them all rigid bodies, but I do want the rigid body game objects to collide with the box collider ones

#

I'm not quite sure how to go about doing that, though?

#

all in 2d

trail bloom
#

The game I built as an APK in Unity doesn't work the same way as it does in the Unity editor. Some objects that should appear on the screen are missing

#

gpt said its all about resulation or eventsystem or screen render mod but its not

#

can anyone help me with that

bitter apex
#

stupid problem required a stupid solution

wintry quarry
#

Certainly use a hashset instead of a list

#

Hashsets don't allow duplicates

nimble apex
#

no, i want the duplicates

wintry quarry
#

Then why are you calling Distinct

nimble apex
#

im brainrotten rn 💩

#

hold on

#

lemme think of another way

wintry quarry
#

What's the actual question then

grand snow
#

HashMap is better to avoid duplicates as you add things (also try to give the list a start size)

#

though for a small list, a Contains() check isnt so bad

wintry quarry
#

HashSet you mean**?

grand snow
#

bleh yes

#

i was just reading some cpp forgib 🙏

nimble apex
#

temp is now populated with all objects , find out repeated objects

        List<GameObject> temp = new List<GameObject>();
        
        foreach (AllStepObj_Value key in allObj.Steps)
        {
            foreach (GameObject value in key.Objects)
            {
                temp.Add(value);
            }
        }

        possibleRepeatedObj = temp.repeatedobj();//pseudo code```
#

im not trying to delete duplicated objects btw, i need all of them exists, i just need to use it for other purposes

wintry quarry
#

When you call Add if it returns false it was a duplicate

#

You can put the duplicates into a second HashSet or a second list

nimble apex
#

damn it can use intersect and union?

#

nice

wintry quarry
#

Yes

tulip stag
#

Is there an opposite to [SerializeField]?

#

As in, a field that you want to be public so you can do stuff with it in code, but when using the JSON utility it won't get serialized into the JSON?

keen dew
#

[NonSerialized]

#

or make it a property

tulip stag
#

Aight perfect

rugged beacon
#

i have a random path that can branch off into other paths, trying to find the furthest point, so like find the furthest node in a graph ? any recommend approach?

night raptor
rugged beacon
#

no

#

furthest point

#

along the paths

night raptor
#

I don't see the difference

rugged beacon
#

A is start i want to find C, not B

night raptor
#

That's what I meant, maybe didn't articulate it very clearly

night raptor
# rugged beacon A is start i want to find C, not B

What I meant by shortest path is that you are not looking to find the absolute longest path (pictured below) from A but the furthest away from A that one could get (longest distance from the shortest paths between A and all the other nodes)

#

So this would be what you are looking for right?

rugged beacon
#

in my case the graph wont be connected, there will be deadends, i want to find the furthest deadend

#

more like i want to find the furthest point, not the furthest path

#

get it ?

night raptor
night raptor
rugged beacon
#

idk im lost

keen dew
#

You can use A* and let it run until it has covered the entire graph. The last node it reaches is the furthest point.

night raptor
#

One could definitely use dijkstras algoritm but for trees I believe simple BST would be faster

rugged beacon
#

or in this case

keen dew
#

🤷 try them both and measure

night raptor
#

I don't think A* would do much in this case since there's no target point

#

A* is useful to reduce the search space (focus the search more towards the target), in this case all nodes must be searched anyways I think

rugged beacon
#

i have tried to use a* for the shortest path, just a plug and use, never know it can do furthest point

night raptor
#

Can it? At least I cannot think of a way to use A* in this case...

rugged beacon
#

do you have a guide walking through djikstra on unity ? 2d would be nice

night raptor
#

no, I don't know of dijkstra tutorial on unity

queen adder
#

NEED HELP ASAP

When i change teh scene, it instantly chabges back to the original one

proper yacht
#

Why is it so? I've read from docs this method to access actions within code but it throws this

night raptor
#

@rugged beacon Let me put it this way. If you take any two points A and B from your graph, is there always at most one possible route from A to B? I also assume your graph is not directed (any edge can be travelled both ways)

rugged beacon
#

im researching what the diff between tree and graph lol

proper yacht
#

that object

night raptor
night raptor
rugged beacon
#

yes that can happend

#

my dugeon

#

actually no this generation

#

actually i jsut checked, im fairly certain there wont be loop

#

its tree

queen adder
#

oh shoot never mind its even worse

#

every scene that changes just goes to the game scene instantly

#

regardless of the scripts or anything

#

it goes for a second

night raptor
# rugged beacon its tree

If it is always a tree it will make your life easier by a lot. For tree you don't need dijkstras algoritm or anything as complicated. You can just do a DFS (depth first search) from the starting position and keep track of the path lengths for each node, at the end you can figure the longest path

queen adder
#

and then goes back to the game scene

rugged beacon
#

you just make me realize the generation flaw lmao, i need to update it to have loops, guess it will be djik then

night raptor
# rugged beacon you just make me realize the generation flaw lmao, i need to update it to have l...

Yup. If you need cycles/loops, use dijkstras. Games usually want to find the shortest path between two given points which suits A* very well. A* is basically just extension to dijkstras algorithm where heuristic is added to guide the search. To implement dijkstras, you could follow any A* tutorial and just leave out the heuristic calculations and use the G cost alone in the place of G + H that is used in A* to choose which node to search next

rugged beacon
#

bet thanks, i understand your first 2 sentences

night raptor
rugged beacon
#

i will try finding dijkstra tutorial, there has to be some

night raptor
#

There might. If one specifically for unity doesn't exist, I'm not too surprised though

#

@rugged beacon May I ask, what you need the furthest point for? Just to make sure were are not in the XY land

rugged beacon
#

furthest room is exit room

#

furthest room contain the furthest tile stuff

#

but when i generate the dungeon, i store the corridor in a seperate list so just need furthst point

night raptor
queen adder
#

its the lasgt thing keeping it from beign finished

night raptor
queen adder
#

should just be this using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Ded : MonoBehaviour
{
private string nextSceneName;

private void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.CompareTag("Player"))
        SceneManager.LoadScene(2);
}

}

#

i can share the whole scene that teleports back too if need

night raptor
queen adder
#

Yes

#

Scene one pops up instantly after the appropiate scene does

night raptor
#

Are you sure there's no other script that loads scenes? I don't see a way this script could load anything other than scene 2

queen adder
#

il look around

#

AHA I FOUND THE CULPRIT HOPEFULLY

#

theres a stray script that loads it

night raptor
#

I'm not surprised

rich ice
eternal falconBOT
queen adder
#

wow it was that simple

#

it works now

#

thank yall!!!

wild island
#

Unity noob here, I couldn't find good information on this:
I need to allow users to add custom content (animated meshes, textures etc.)
not just one but more like a prefab, things that will spawn randomly in large numbers

I'm trying to use UnityGLTF for this.
There's no way to create a gameobject hierarchy at runtime without instantiating it into the scene like GLTFSceneImporter does?
It feels wrong to put a gameobject hierarchy, only to remove it again to make prefab out of it
Actually creating prefabs at runtime is also not possible? why?

I'm kind of confused what the correct approach is, I can't call the GLTFSceneImporter and then setup the components for each single instance i want to spawn

rich adder
#

lord..how did you manage you send the raw html and not the generated link to the code on site

#

thats a first around here I think

#

delete and try again

cobalt relic
#

Hello,
How can I force old users to update their app before continuing the game?
am using playfab and photon in my game

rich adder
rich adder
#

1 per script

stray thorn
cobalt relic
stray thorn
rich adder
#

btw you should not multiply your mouseInputs by deltaTime, you can remove that and lower sens

#

I bet you cranked sens to really high numbers cause of it

#

Mouse inputs return you the distance mouse has moved since last frame, its already framerate-independent

rich adder
stray thorn
rich adder
subtle veldt
#

Oh okay sry

long drum
#

'MonoBehaviour' does not contain a definition for 'OnTriggerEnter'

Can anyone help with this? I don't know why it thinks this isn't a method/message

rich adder
long drum
#

I am trying to inherit this, as the class I want to use it isn't directly monobehaviour but inherits from a class that is

#

public virtual void OnTriggerEnter(Collider collider)
{
base.OnTriggerEnter();
}

#

this is in the class that is

#

intellisense says it's ok but Unity doesn't

polar acorn
polar acorn
long drum
#

how do I call a collision trigger from a class that isn't a monobehaviour, but inherits from one?

polar acorn
steep depot
#

hello y'all! I wanted to know if there's a platform to learn C# or just how to do it

long drum
#

intellisense wasn't initially saying it was a predefined function, but I reset visual studio code, and now it does (but OnCollisionEnter still doesn't show up with intellisense)

steep depot
#

thx

polar acorn
long drum
#

I've removed that now, but if I have a class that inherits from a class that inherits from monobehavior, I can use ontriggerenter?

polar acorn
#

Yes

long drum
#

it wasn't working initially, so I tried this to form a chain to get it, but apparently that's not how it works

polar acorn
#

A class that extends MonoBehaviour is a MonoBehaviour, and as such, something that extends that is also a MonoBehaviour

long drum
#

I think vscode was bugging out or something; but I still can only see intellisense detecting some monobehaviour methods and such

rich adder
long drum
#

what window?

#

well, intellisense partially works; and debugging works between unity and visual studio code

rich adder
long drum
#

yeah, it's definitely a bit broken or something

#

now GameObject variables aren't highlighting yellow/being autocompleted with intellisense

rich adder
void dawn
#

i programmed a zombie enemy but he comes at the player backwards

rich adder
#

You likely setup everything in Global mode

long drum
#

no, it doesn't say that, from what I can see

void dawn
rich adder
rich adder
long drum
#

that's where it says debug configuration stuff

#

currently it's "Attach to Unity"

rich adder
#

oh idk to me its at top right . check its actually connected properly

long drum
#

it is, because debugging works

rich adder
#

well only showing some variables/methods sounds like it isn't but idk

long drum
#

actually, next to projects at the bottom left, it has a loading circle spinning

polar acorn
long drum
#

before that is where it says attach to unity (and my project name)

rich adder
#

with a script open normally it should say what i sent in SS. If its stuck loading something it might be cause of wonkly intellisense

long drum
#

yeah, I restarted it before and it fixed some intellisense stuff, but also then did a .NET update/download of some kind

#

maybe that broke something even more

rich adder
#

I use the latest .net 9 sdk and works flawless. Unity extension version 1.1

#

make sure also your unity Visual Studio Editor package is full up to date too . might help

#

close VSC and regen project files button from External Tools in unity maybe.

long drum
#

well, I just found something saying restart to update

#

but that still didn't fix it :l (it did do something though)

rich adder
long drum
#

it all seems broken right now; I just reconfigured it to open with visual studio 2022 instead now; maybe I'll try again tomorrow, but maybe this will work better anyway

#

Thanks for the help. If I can get this working properly in visual studio 2022, it'll probably be better. Intellisense is definitely already working in this

rich adder
#

VSC has its quirks sometimes

long drum
#

one more thing, I guess OnCollisionEnter triggers if any colliders collide I guess, and OnTriggerEnter only triggers if a collider that "Is Trigger" collides?

#

I think I'm right because I changed the prefab units' box collider is trigger checkbox setting (that was wordy :P) and now my code works, yay

cosmic dagger
#

If you need more info, always check the Unity !docs for each method . . .

eternal falconBOT
long drum
#

@cosmic dagger oh, I have been. I looked up the Collider.IsTrigger page just after I guessed at what a box collider's is trigger checkbox does when I saw it

cosmic dagger
late burrow
#

i forgot once again how to make script run automatically without gameobject

swift crag
mystic ferry
late burrow
#

i want it both editor both runtime

#

basically executealways something

rich adder
#

You can use editor script to also do continuous polling (you need [InitializeOnLoad] )

#
static EditorUpdateExample(){
        EditorApplication.update += Update;
    }
    private static void Update(){
        Debug.Log("editor updating...");
    }``` some like that
#

oh just saw runtime.. this wont work in build nvm

late burrow
#

well none of these seem to work

[ExecuteAlways]
public class ab
{
    static ab()
    {
        Debug.Log("works2");
    }
    [RuntimeInitializeOnLoadMethod]
    static void stuf()
    {
        Debug.Log("works3");
    }
}```
slender nymph
swift crag
swift crag
#

i am so smart

pliant ridge
#

trying the new input system - my button is started and performed twice from one press?

#

okay somehow i fixed it by deleting and resetting stuff idk

static stag
#

hey guys, i'm using line renderer to render a grid for my 2d map editor. Now i was implementing a zoom out and the grid just get messed up as soon as i change the fov. Any advice ?

rich adder
static stag
#

normal

static stag
rich adder
#

ohhh i see

#

could be some setting on the camera filtering or something like that?
I'm no expert on these, but might be better off using a shader for grids

static stag
#

like removing details when zooming out, so maybe it's really not a code question 😄

rich adder
#

hmm def not the code at all if looks fine zoomed in. Its either the prospective warping or the camera far away / filtering causing distortion

rich adder
#

shouldnt you be using Orthographic

static stag
#

testing purpose, using Orthographic and changing "Size" results in the same result

rich adder
#

maybe try pixel perfect ?

static stag
#

the funny thing is (i used unity zoom for this pic)

#

the line renderer , renders on the texture 😄

rich adder
#

ahh fawk

#

def dont wanna be zoomin with that lol

static stag
#

yea it was just to take a screenshot of the behaviour 😄 that the line renderer, render on the sprite texture

#

let's see

rich adder
#

ah maybe, like i said before I also suspect something to do with filtering

static stag
#

okay setting MSAA to 8x fixxed the problem 😄

#

funny to see what can cause this type of problems 😄 Maybe i'll take a look at shaders next. Thx for help anyway

rocky canyon
#

ya, game-dev is chocked full of little things that no one would ever plan for..

#

fun thing.. is even if u come up with a solution u may find out months later u actually found one of the worst solutions lol

prime cobalt
#

Does anyone know a good perspective trickery method to make guns aim at the center of the screen? Because in order for the gun to look nice in the view model it has to be tilted a bit making the projectile take a noticeable angle at long ranges.

gleaming wagon
#

Hey, I don't find where to post this so I will just ask it here. Why can I not move stuff in my unity folders anymore? Like at all... I tried to search for a solution but nothing works.

#

The rest works fine btw its just that

wintry quarry
wintry quarry
#

It doesn't have to match up with the actual projectile

gleaming wagon
wintry quarry
#

you can have an imaginary "visual projectile" the player sees that looks nice but isn't the actual raycast

prime cobalt
#

The game has bullet time so you can see the projectile leave the gun

wintry quarry
gleaming wagon
swift crag
#

i know that drag-and-drop can get screwed up by that

prime cobalt
swift crag
#

I've tried doing a "real" first person view before. You can compensate for the offset by having the gun rotate to point exactly at whatever the crosshair is over

tired wigeon
#

Is there a better way to begin learning c# than using https://learn.microsoft.com/en-gb/dotnet/csharp/tour-of-csharp/tutorials/list-collection?tutorial-step=1 ? it's really uninteresting to me and doesn't engage me nicely I tried their video guide but as most people say in those comments it doesn't tell you what you already need and assumes prior knowledge (which I probably have now from doing some of this) but I'd just like something more engaging? there's a chance I could go back to the Learn unity now I have a very basic understanding I just don't want to go in half cocked but it's taking me days to get through this because it burns me out so fast

swift crag
#

but this can cause a slight change in aim to dramatically change where the weapon is pointing

swift crag
wanton epoch
#

I am having this issue where I am trying to set my camera a bound so that it doesnt show the blue background thing. The issue, is that soon as I set this bound on my cinemachine camera, my player gets teleported outside the bound when I start the game.

Would love a suggestion on this.

swift crag
#

put it on a layer that doesn't interact with the player, or just turn off the collider

wanton epoch
#

Well that fixed that issue

#

now I need to learn how to put the same bound on my player

gleaming wagon
#

Should I try

swift crag
#

Nope -- it should not be run that way

#

can you drag a file from outside unity into the project window?

gleaming wagon
#

the red block one

wanton epoch
swift crag
#

You could slap some colliders on the side!

#

or you could manually clamp the player's position

#

find their screen position, clamp that to 0..screen width and 0..screen height, and turn that back into a world position

wanton epoch
muted pawn
gleaming wagon
swift crag
#

so you opened the copied project?

gleaming wagon
#

Yep, same issue

muted pawn
#

i think once the folders are in onedrive is kind corrupts them idk how to explain it in good english sorry

#

that sucks tho

gleaming wagon
#

Ugh

#

I have a github repository

#

Think I should copy it from there

#

and try again?

#

Man I always get the weirdest unity bs bugs

muted pawn
#

I just read ppl experience same issue with github repository ._.

swift crag
muted pawn
#

seems like it yeah

gleaming wagon
#

How am I supposed to back up my projects 😭

polar acorn
#

Version control

#

such as git

gleaming wagon
#

I will try downloading the latest file from my github repo. Then opening that project. If it still doesn't let met I will just use my mac from now on for unity

random sorrel
gleaming wagon
#

Omg it worked

#

Github the goat

#

Thanks for the help though @swift crag and @muted pawn

tulip stag
#

Does anyone know how to parse a list using JsonUtility.ToJson?

slender nymph
#

the list must not be the root object, but otherwise as long as the field that contains the list is serialized and the type the list contains is serializable it should JustWork™️

tulip stag
#

ohhhh ok. The list was the root object lol

slender nymph
#

yeah jsonutility can't handle that

warm mason
#

when organizing my project, do you think its best to have each like VFX (In this case im making like aura VFX's for the player) in its own scene that I could just reference when I want it to be applied to the main scene?

wintry quarry
warm mason
wintry quarry
#

Prefab is what you want

#

Search Unity docs

warm mason
#

"Unity’s Prefab system allows you to create, configure, and store a GameObject
complete with all its components, property values, and child GameObjects as a reusable Asset. The Prefab Asset acts as a template from which you can create new Prefab instances in the Scene
."

#

sounds about what i want

#

😄

summer thorn
warm mason
#

okay so im trying to teach myself how to setup a 3d camera in unity

    public float distance = 5.0f;
    public float sensitivity = 2.0f;
    public float minY = -20f;
    public float maxY = 80f;
    public float zoom = 5.0f;``` Although its working i have question about this part of the script. What exactly is f ?
#

and

#

for example

#

under the public float maxY = 80f; why is that a float and not an int?

swift crag
#

5.0f

This is a literal. It's a literal value, rather than, say, a variable

#

Numeric literals can have a few different suffixes to specify what type you want

#

5.0 is a double
5.0f is a float

#

A double is more precise than a float (the datatype is literally twice as big, hence the name)

#

So this would cause an error

#
public float foo = 5.0;
#

The compiler will not implicitly turn a double into a float for you

warm mason
#

wouldn't ... 5.0... be a float.. cuz its only one decimal 0.o

#

im confused

#

; d

#

ok wait i kind of understand

swift crag
#

5.0 and 5.0000000000 are both double literals

#

the number of digits is irrelevant

warm mason
#

okay

#

i understand

#

so by literal you mean its just a .. literal number?

#

or rather as in the number doesn't change

astral falcon
#

Maybe not the best example taking one decimal. But the more precise you calculate, the more you would see a difference in precision

grand snow
#

its also like doing 5L vs 5

warm mason
#

ok i think i understand now

#

and its like that becuase when i use the clamp() function later in the code it requires float calculations so thats why i dont use integers and thus where the 'f' comes in

#

ok

#

makes sense

grand snow
#

its very useful when you want to do a float/float instead of say int/int:
6/5f vs 6/5

astral falcon
#

or you will wonder why your console outputs full numbers, cause you forgot, that you are doing something with an int

pure drift
#

does anybody know how i could make my pause button exsist between scenes it brings up a panel with sliders like this but i cant figure out a way for them to persist

rich ice
astral falcon
#

This way, you always have one instance, that lives for your entire game if you want

pure drift
#

thank you guys i will look into that

#

by the entire main menu you mean the entire canvas right

red mason
#

hey guys, when putting forcemode.velocitychange into my player movement code, i can move it left/right but then theres tons of friction when you try to go the other way. can anyone help?

#

this is my code

rich ice
#

!code

eternal falconBOT
rich ice
rich adder
# red mason
  1. dont use time.deltaTime inside AddForce calls (notice how your forces are ridiculously high numbers)
  2. use Keycode instead of strings
  3. move rigidbody in FixedUpdate not Update
red mason
#

tysm!

ivory bobcat
#

You'd still want to acquire input from regular update though

#

Poll the states in update and use them in fixed update - create two extra bool variables etc

rich adder
#

Ya keydown 1 frame event not the best in FixedUpdate lol
Held key (GetKey) are ok

red mason
#

still feels very weird cause its taking multiple presses of the keys to change the direction

red mason
#

no how do i do tha

ivory bobcat
rich adder
#

^ if you want held do this

red mason
#

ok ty all it works now

#

but to make it feel normal i had to set forward force to 1000 and sideways force to 1 _:)_/

golden sand
#

Could someone help me with this problem.

Im currently building a top-down unity 2d game. It is a rougue-like wave game where the player pushes a button to activate the next wave of enemys. My problem is that I need a way to track the amount of enemy's that die. I used a int in the enemy's death code where it 'should' add to the int when the enemy's die but the int is not incrementing. Once it increments, I plan use get component to allow the enemy spawner to track the enemy's defeated and the ones spawned allow the next wave to trigger when the wave button is pushed. Idk if I need to rework the spawning system or find a roundabout way but I've been looking for answers for 3 hours.

#

First one is enemy health script, secon button press, third enemy spawner

eternal falconBOT
rugged beacon
#

maybe add an event for when one die?

supple wasp
#

eeeeeee help....

rich ice
#

also !ask

eternal falconBOT
golden sand
rich ice
golden sand
#

I'm using blazebin

rugged beacon
#

im learning the dijkstra to traverse all possible position, finding furthest position and reachable positions at the same time, however all the guides i've seen only have use the algo for finding the shortest path between 2 pre designated points, anyone know a similiar implementation? or the steps to achieve this

rich ice
rich ice
pure drift
#

!code

eternal falconBOT
golden sand
#

Wave button

pure drift
#

for my code to make an undestroyable gameobject i have something like this https://paste.ofcode.org/nMhUNfLnf4dAskgnBgEMsU and attached it to a parent in the canvas which has my button and pannel ui objects but i still doesnt destroy on load

golden sand
rich ice
pure drift
#

yep it doesnt show up at the bottom this is what comes up though

#

im not really sure whats going wrong'

rich ice
#

the script is on the wrong object

pure drift
#

i have the script on the persistent UI gameobject

#

the UI manager is for something else

slender nymph
#

you may want to double check your console for relevant errors/warnings

pure drift
#

ill try and see if i can use debug.log to see if the gameobject actually doesnt destroy on load

slender nymph
#

again, pay attention to your console

pure drift
#

so the ui does save technically but my hiearchy doesnt show anything

slender nymph
#

great, now read the information in the console

pure drift
#

ok i never experienced this message before about root game objects ill go read about it

slender nymph
#

do you know what a root gameobject is?

pure drift
#

no

slender nymph
#

it is a gameobject with no parent. in other words, it is at the root of the hierarchy

pure drift
#

so what you are saying is that it has to be a parent for dont destroy on load to work . but then how will i save specific things of my canvas then for the next scene if they are children

slender nymph
#

put them on a separate canvas and make that separate canvas DDOL

pure drift
#

ohh thank you

golden sand
spark sinew
#

hi y'all, I am displaying a cube in an app, and I would like to update the orientation of the cube so that its side is perpendicular to a given vector. How should I do this ?

rich adder
spark sinew
#

I think any face would work at the base, since our cube shape is basically the same value for each base side, and a different value for the height

void thicket
#

Given that your cube is aligned with axis

spark sinew
#

ok thanks! I will try this

#

if it is not aligned I will try with other vectors instead of forward

frigid sequoia
#

By default a Vector 3 is (0, 0, 0) and not null right?

rich adder
frigid sequoia
#

A vector3 of a non defined transform is also (0, 0, 0) then?

#

Even if the transform is null

rich adder
#

I mean, you wouldnt be able access it if transform is null

#

you would get nre before default value is grabbed

frigid sequoia
#

Ok

#

Shouldn't it give me a syntax error when I say something like this?

rich adder
#

why its valid syntax

frigid sequoia
#

In the same way that it does when I type this?

rich adder
#

transform has indeed a transform property

rich adder
#

also you need to give it a value for local var

frigid sequoia
#

This is also a vector3

#

And can never be null

#

Yet it does not tell me so

frigid sequoia
#

Why?

rich adder
#

.position is a property , similar to a method it returns vector3 whatever value that is

#

but yea the null check is useless

frigid sequoia
#

But... I mean, I think it should check that the type of property that it is sending back can never be a null

#

But ok

#

I know now

rich adder
frigid sequoia
#

Isn't it preloading the type of property that is expected to be returned?

#

Here tells me that it knows that does not return a int, even before doing the operation itself

rich adder
rich adder
#

Im saying it wasnt able to tell you that its an error cause it wont know what position is since its null transform

#

slight misunderstanding there I think lol

void thicket
#

Local variable does not have default value. It’s “uninitialized”.

#

default initialization happens for fields (i.e. member variable)

#

Anyways, if you assign some value to it it will compile same

rich adder
#

you can also check them by default keyword

#
Vector3 v = new();
  if (v == default){
      Debug.Log("I'm at default value");
}```
cosmic dagger
#

yeah, i'll default my variables all the time . . .

void thicket
#

Don’t default your Quaternion 🥹

cosmic dagger
#

I just don't f*** with them . . .

rich adder
#

Quaternions notlikethis

#

cursed

Quaternion q = new();
if (q.eulerAngles == default){
    Debug.Log("I'm at default value");
}```
frigid sequoia
cosmic dagger
#

My object pool was only used for reference types since it was ClassObjectPool<T> : IPool<T> where T : IPoolableClass<T>, class, new(), but since I changed it to use structs, I had to change all the null assignments to default . . .

rich adder
void thicket
cosmic dagger
void thicket
#

I wouldn’t be surprised if I get NaN or something

void thicket
frigid sequoia
#

I kinda want to tell the difference between if it's just the default value or it just happened to land exactly on position (0,0,0) lol

rich adder
void thicket
#

Do we have user defined struct new() in Unity

#

new() would be just same as default

rich adder
#

yea tru

cosmic dagger
rich adder
#
int i = 0;
int j = new int();
int k = default(int);```
void thicket
#

Newer C# we can have custom parameterless new() but I don’t remember Unity is on that

rich adder
#

yeah we do since 9

#

which we're currently stuck on 😢

drifting cosmos
#

is unity 6 the newest c#

rich adder
#

no

void thicket
#

No

rich adder
#

way behind

drifting cosmos
#

oh

rich ice
drifting cosmos
#

which one is it

void thicket
void thicket
#

It would create Quaternion.identity in ideal world

rich adder
#

but in Unity you always want to reset with Quaternion.identity

rich adder
void thicket
drifting cosmos
void thicket
polar acorn
#

All objects have their rotation stored in a quarternion. Regardless of what game you're making

rich adder
frigid sequoia
#

I am wondering, how can I actually check if a object didn't move since the last frame?

#

Cause the order of execution is not something I can control, maybe it just didn't move this frame YET

#

I could place the check in lateUpdate

#

But what if I want to move it on there later too?

void thicket
#

Order of execution is in fact something you can control

#

Not that I encourage it

bright zodiac
#

oh misread that mb

cosmic dagger
charred spoke
#

Wouldn’t the transform.hasChanged flag just work

rich adder
#

not well

#

idk cant just do?

var pos = transform.position
if(oldPos != pos){
..
oldPos = pos;
}```
bright zodiac
# frigid sequoia But what if I want to move it on there later too?

a simple diy like this would work

bool wasMoved;
Vector3 lastPosition;
int lastFrameMoved;

public void Move(Vector3 pos)
{
   lastPosition = pos;
   transform.position = pos;
   lastFrmeMoved = Time.frameCount;
}

public Update()
{
  if(TryMove(out var result))
  {
    //Do something and was moved
  }
  else
  {
    //Do something didn't move
  }
}

bool TryMove (out bool moved)
{
    moved = Vector3.Distance(transform.position, lastPosition) > float.Epsilon && lastFrmeMoved > Time.frameCount;
}

just make sure when you move them with the Move function

#

tho it might not be what you want, bcos this way you'll always be 1 frame late, but you won't need the LateUpdate

bright zodiac
frigid sequoia
#

And I kinda want to do some slight amount of physics too

teal viper
teal viper
# frigid sequoia Wdym?

Exactly what I said. Navmesh agent would override any transformations to the object, so if you want something else to move/rotate it, you'd need to disable the agent.

misty moon
#

My player shakes violently when I enable the InputManager script.

Unity Version: 6000.0.341f

Input Manager script

using UnityEngine;
using UnityEngine.InputSystem;

public class InputManager : MonoBehaviour
{

    private PlayerInput playerInput;
    private PlayerInput.OnFootActions onFoot;

    private PlayerMotor motor;
    
    void Awake()
    {
        playerInput = new PlayerInput();
        onFoot = playerInput.OnFoot;

        motor = GetComponent<PlayerMotor>();    
    }

  
   
    private void FixedUpdate()
    {
        Vector2 rawInput = onFoot.Movement.ReadValue<Vector2>();
        Debug.Log($"Raw input x: {rawInput.x}, raw input y: {rawInput.y}"); // shakes violently even when this evaluates to 0
        motor.ProcessMove(rawInput);
    }

    private void OnEnable()
    {
        onFoot.Enable();
    }

    private void OnDisable()
    {
        onFoot.Disable();
    }
}
#

Here's the playerMotor script

using UnityEngine;

[RequireComponent(typeof(CharacterController))]
public class PlayerMotor : MonoBehaviour
{

    [SerializeField]
    private float speed = 5f;

 

    private CharacterController characterController;
    private Vector3 playerVelocity;  
    
    
    void Start()
    {
        characterController = GetComponent<CharacterController>();
        if (characterController == null)
        {
            Debug.LogError("CharacterController is missing from PlayerMotor!");
        }
    }



    /// <summary>
    /// Processes the player's movement based on the given (raw) input. 
    /// The <c>input.y</c> value is used to move the player along the Z-axis (forward/backward).
    /// </summary>
    /// <param name="input">The raw input vector from the player, where <c>input.y</c> controls movement along the Z-axis.</param>
    public void ProcessMove(Vector2 input) {

        Vector3 moveDirection = Vector3.zero;
        moveDirection.x = input.x;
        moveDirection.z = input.y; // W should move player forward. this is what this line does
        moveDirection.y = 0f;

        
        Vector3 moveWorldDirection = transform.TransformDirection(moveDirection);
        Debug.Log($"world input x: {moveWorldDirection.x}, world input y: {moveWorldDirection.y}"); // even when this evaluates to 0, my player still shakes violently.

        characterController.Move(speed * Time.deltaTime * moveWorldDirection);
    }
}
frigid sequoia
#

That has to happen over a bunch of frames

#

I guess I wait until the force on the object is zero to reactivate the agent?

#

But what if I want them to happen at the same time?

teal viper
naive pawn
misty moon
naive pawn
#

i don't think it should, but im not confident; if there's a difference, it'd probably work in Update

#

also, have you tried logging speed * Time.deltaTime * moveWorldDirection?

frigid sequoia
novel nymph
#

I want to make some code that makes it so when you press LeftCtrl, it multiplies the enemyAI's sight range by .5, but I dont know how to connect the multiplying by .5 and enemy sight range together.

naive pawn
#

well how have you implemented the enemy sight range?

novel nymph
#

playerInSightRange = Physics.CheckSphere(transform.position, sightRange, whatIsPlayer);

teal viper
frigid sequoia
teal viper
#

An agent uses the navmesh api under the hood

teal viper
random sorrel
dreamy dune
#

i have a sepperate gameobject that acts as a parent of my camera and my camera is childed to that object is it best to rotate the whole holder or just the camera?

random sorrel
dreamy dune
#

really werid when i am trying to rotate the cameraholder nothing happens

dreamy dune
#

using first person btw

random sorrel
dreamy dune
#

allright will look into that

eternal needle
eternal needle
teal shale
#

Guys, i'm just making a simple 2d platformer. im using velocity for movements but why does it keep changing to linearvelocity everytime after i saved n changed

cosmic dagger
teal shale
tulip nimbus
#

How do i check wheter a Circle collider or a Box Collider has been touched by using OnTriggerEnter2D?

so something like this (not real code)

CircleCollider CC
BoxCollider BC

void OnTriggerEnter2D(Collider other) 
{
 if (other.touches.CC)
        { Do whatever Circlecollider is supposed todo }
 if (other.touches.BC)
        { Do whatever Boxcollider is supposed todo }
}```
teal viper
cosmic dagger
soft creek
#

Hi how i can move the camera of a fsp player in unity 6?

keen dew
#

What is a fsp player?

soft creek
#

first person

keen dew
#

fps?

soft creek
#

yes

naive pawn
#

you would have it as a child of the player and inherit the player's translation and yawing, and then the camera would do pitching

keen dew
#

There are about a billion FPS tutorials and they all show how to move the camera

soft creek
#

Yes, but in unity 6 is different and i don't know how to do it

keen dew
#

no it isn't

soft creek
#

I have this code and the character cannot look or move (I have been able to resolve the latter)

naive pawn
#

!code

eternal falconBOT
naive pawn
#

anyways have you tried debugging your input values

#

you might want to use GetAxisRaw instead of GetAxis

late burrow
#

any alternative to tuple unity errors when im trying to use it

naive pawn
#

what do you mean by "unity errors"

late burrow
#

The type 'Tuple<T1, T2>' exists in both 'ExCSS.Unity, Version=2.0.6.0, Culture=neutral, PublicKeyToken=null' and 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

naive pawn
#

ok that's not unity erroring

#

that's just c# erroring

#

tuples on their own should work fine, so this is more likely an issue with project setup, i guess?

late burrow
#

i guess i can just make separate class then

naive pawn
#

...what?

#

you should probably go fix the underlying problem here

late burrow
#

tuple is pretty much class without definition so if it doesnt work ima just use class then

naive pawn
#

wdym class without definition lol, it is defined

#

if it didn't have a definition, you wouldn't be able to use it

polar acorn
#

It's more like a struct

naive pawn
#

also it's probaby a struct, not a class

polar acorn
#

It's basically an anonymous struct

naive pawn
#

huh no it is a class

polar acorn
#

Tuple is to struct as lambda is to method

polar acorn
naive pawn
#

oh wait, im not sure that's the underlying thing for tuple types

#

ok yeah they aren't

polar acorn
#

Okay good I was about to take a long look in the mirror and contemplate my existence

naive pawn
#

they are structs, as suspected

polar acorn
#

Looks like there's just a class representation for when you need kinda a tuple but it has to be a reference type

naive pawn
cosmic dagger
#

Wait, I thought Tuples were structs?

naive pawn
swift crag
#

System.ValueTuple is what backs tuple types

naive pawn
polar acorn
cosmic dagger
#

There is a class version, I do know that . . .

#

I found the class version when I first heard about them . . .

naive pawn
#

tuple types are ValueTuples, and they're structs

queen adder
#

hey I have a problem with my code

cosmic dagger
#

It depends how you create the tuple, whether it's the immutable class version or the struct (using the newer syntax) . . .

queen adder
#

wdym

#

I want it to move straight but it falls right when I shoot

naive pawn
#

they aren't talking to you

cosmic dagger
queen adder
#

ohhh

cosmic dagger
eternal falconBOT
naive pawn
#

@queen adder did you see the bot message after my own message

cosmic dagger
#

Not everyone can view the code inline . . .

queen adder
#

I didnt

naive pawn
#

well here it is again

queen adder
queen adder
naive pawn
#

yes

queen adder
#

ok

#

I'mma do it

naive pawn
#

so have you debugged inside the if (rb != null) to see if that passes?

#

alternatively, you could change the type of BulletPrefab to Rigidbody to ensure it has one, then Instantiate would return the rb directly

queen adder
#

no

cosmic dagger
#

Also, you're setting the velocity for the bullet in both scripts . . .

#

Are transform.forward of the bullet (in Bullet.cs) and muzzle.forward of the muzzle (GunShoot.cs) the same direction?

naive pawn
#

well it's instantiated using muzzle.rotation, so probably, lol

cosmic dagger
#

You should remove the bullet code from the GunShoot script . . .

queen adder
#

I finally fixed it

#

I rewrote the entire code

#

I won

#

but at what cost

cosmic dagger
#

Now you are faster, stronger . . .

queen adder
#

the bullets fire from the tip not the back ✅
the bullets move realistically ✅
the bullets have a red trail behind them like the one in the game superhot ✅
the lightings are beautiful✅

warm mason
#
double b = 3.0;
Console.WriteLine(a / b);

decimal c = 1.0M;
decimal d = 3.0M;
Console.WriteLine(c / d);```

Why in this code do we have to use M to let the compiler know that we are using a decimal type, doesn't declaring decimal in the variable do that for us?
queen adder
# warm mason ```double a = 1.0; double b = 3.0; Console.WriteLine(a / b); decimal c = 1.0M; ...

Posting code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:

// Your code here

Add a comment with a line number if there is an error message.

Use Scriptbin to share your code with others quickly and easily.

swift crag
queen adder
#

probably because I dont know the command

swift crag
#

1.0 is a literal double

#

Hence needing the suffix.

warm mason
#

oh well

#

i guess not

warm mason
sterile radish
#

hi, i want to add a prompt in my game that comes up on screen that displays a letter for a limited time. how do i check if the player pressed this letter in the duration of time it was on screen for?

cosmic dagger
sterile radish
cosmic dagger
swift crag
sterile radish
swift crag
#

Is this a "quicktime event"?

sterile radish
#

yes

swift crag
#

and last thing: are you using the old input manager (e.g. Input.GetKey(...)), or are you using the new input system?

sterile radish
#

im using the old input system

swift crag
#

Okay, so you'll want to set two things when you start a quicktime event:

#
  • The time when the event ends
  • The key you're expecting the player to press
#

so a float for the time and a KeyCode for the key

#

You'll use Input.GetKeyDown(key) to check if the right key was hit. If that returns true before you run out of time, set a "success" variable to true

#

when time runs out, check if that variable is true

sterile radish
swift crag
#

You'd just go to a success state on keypress, and go to a fail state if time runs out

sterile radish
#

oh okay

soft creek
#

How i can solve this problem?

cosmic dagger
soft creek
#

But how i can change it?

cosmic dagger
fleet venture
#

How does unity work with inheritence?
I have a ZoomScalingObject class and a ScaleTransform and MoveTransform and RotationTransform class that extend it. I only have the Transform classes on objects and not the ZoomScalingObject class. How do i still make it so that Update runs? it doesnt seem to be running rn

brave helm
#

hello i am following a simple tutorial on getting a player character to move. everything works fine, other than when moving left to right the camera doesn't follow it. I apologize

keen dew
#

Save the file

brave helm
#

i did

keen dew
#

Well it's unsaved in the screenshot. After you've saved, check the console for errors and that playerBody is assigned and that the camera is a child of that object

brave helm
#

ok yeah that was the problem it wasnt nestled into the player object, it was just hanging out free floating. Thanks

keen dew
#

Unrelated, but don't multiply mouse input by deltatime. The tutorial is wrong

true tangle
#

im new as well but i suppose its because the sensitivity is really unrelated to the frames and theres no reason to time adjust it? idk

#

or input, sorry

keen dew
#

It's because mouse input is already the amount the mouse has moved since the last frame, multiplying again by deltatime is meaningless

cosmic dagger
true tangle
cosmic dagger
fleet venture
#

uh whats this

rich adder
fleet venture
#

okay

#

visual studio too?

rich adder
#

nah

#

something in unity got borked prob trying to display

split ginkgo
#

excuse me but where is the help tab?

rich adder
eternal falconBOT
cosmic dagger
split ginkgo
#

thnks