#💻┃code-beginner

1 messages · Page 112 of 1

rich adder
#

regen project files again and open script from unity

hushed badge
#

the colours look different

rich adder
#

oh there we go then..

#

now you're coding properly

hushed badge
#

thanks

rich adder
hushed badge
#

sorry if i came off as fighty

#

didnt mean to

rich adder
#

just in case

hushed badge
rich adder
#

you'd be surpised how many people get combative when asked to configure ide for some reason lol

hushed badge
#

i can imagine

#

but still

#

is it ok to have if statements like that

#

for toggles

#

i cant think of a better way

rich adder
#

2 Move function should be combined into one

#

even though the unity docs does it 🙄

hushed badge
#

how so

#

you mean like

#

an else if?

#

or

rich adder
#

just + to add 2 verctors

hushed badge
#

yeah but where would i do that

rich adder
#

move * speed * Time.deltaTime + velocity * Time.deltaTime should do it

hushed badge
#

oh

#

and then i just delete the one at the top

rich adder
#

not a code question #📲┃ui-ux
make sure you properly anchor and use correct scaler mode

hushed badge
#

thanks again

honest matrix
#

Guys am I right to say that Scriptable Objects are interfaces that are imported from another script?

ivory bobcat
hushed badge
#

now i gotta figure out how to add animations

rich adder
honest matrix
#

i wasnt aware it could hold on to data

rich adder
#

interfaces meerly enforce a contract between class and interface

honest matrix
#

correct

ivory bobcat
honest matrix
#

right

#

so ScriptableObjects are blueprints, containing prefabs and methods that other scripts can use?

frosty hound
#

They're data containers

honest matrix
#

I get it, they can store all kinds of values

ivory bobcat
#

SOs do not enforce implementation of methods - very different from Interfaces.

swift crag
#

They're Unity objects that don't exist in a scene

#

compare to MonoBehaviours, which must be attached to a GameObject

honest matrix
swift crag
#

SOs let you create new kinds of assets.

#

These assets can be referenced like any other asset (materials, prefabs...)

honest matrix
#

is it like class inheritance?

#

it sounds similar

ivory bobcat
#

It has nothing to do with polymorphism

swift crag
#

SOs are not a fundamental C# concept.

modest dust
#

basically a class instance, but in a file

#

you can do with it whatever you want

swift crag
#

They aren't "like" classes or interfaces or methods or whatever

ivory bobcat
#

Think of it as a special struct or class that exists without being instantiated.

honest matrix
#

all of its use cases sound like polymorphism

#

thats why i was confused

ivory bobcat
#

Maybe read up on polymorphism.

honest matrix
#

you fix values, give it prefabs, and methods to hold.

and you create new objects from it

rich adder
honest matrix
#

I see

swift crag
#

since it's a Unity object, you can instantiate and destroy it

storm fractal
#

Hi I'm new, can someone build a game for me and tag me as the author.

frosty hound
storm fractal
frosty hound
#

If you're here to shitpost, you may as well leave the server now

honest matrix
frosty hound
#

For storing data definitions

ivory bobcat
#

Sharing data.

rich adder
frosty hound
#

If you have a bunch of items, for example

rich adder
#

they can both be used as they do different things

swift crag
frosty hound
#

SO's and prefabs are not comparable

swift crag
#

prefabs exist to be instantiated and put into scenes.

honest matrix
#

okay so SOs may exist as data only

#

that makes sense

swift crag
#

A ScriptableObject can be instantiated, like any other unity object, but it's never in a scene

honest matrix
#

I see

swift crag
#

Anything deriving from Component is attached to a GameObject

rich adder
swift crag
swift crag
#

SOs are custom asset types. That's the long and the short of it.

swift crag
#

They let you create new sorts of assets.

honest matrix
#

This raises a question. Can I change data on a scriptableObject and expect that value changed for all other scripts

swift crag
#

I was just talking about this with someone else!

rich adder
honest matrix
#

ah great

#

imma read

swift crag
#

might be kind of rambly

ivory bobcat
swift crag
#

You just can't permanently alter them.

honest matrix
swift crag
#

When you get a reference to a ScriptableObject asset for the first time, the asset is loaded and a new C# object is created.

swift crag
#

Anyone else referencing the same asset will get the same object

#

The tricky thing is that, once the asset unloads, the changes you made are gone.

#

When the asset loads again, you get the values it was serialized with.

#

If you switch from Scene A to Scene B and Scene B doesn't have any references to your ScriptableObject, it unloads

honest matrix
#

yeah thats understandable

swift crag
#

That's the footgun. You play around with it in the editor and see that changes persist

rich adder
swift crag
#

Each Setting asset has serialized fields for things like name, description, default value, maximum value...

#

as well as a non-serialized value field

rich adder
#

I think most Unity settings are SO no ?

swift crag
#

When the game starts, I load an asset that references every single setting asset

#

and I keep a reference to that asset forever

#

thus, every single setting asset remains loaded forever, and nothing ever unloads

rich adder
#

yeah very useful as shared static assets

swift crag
#

then I write default values into those setting objects before checking if the user has saved settings

#

if so, I deserialize them and write the new values

swift crag
#

(i thoroughly tested this after getting baffled by the behavior for the nth time)

#

It makes perfect sense if you understand that ScriptableObjects are assets.

#

They aren't magic. They load when they're needed and they unload when all the references are gone and Unity decides to clean house.

#

(generally during a scene transition)

#

There's nothing special about them!

ivory bobcat
#

Sounds pretty special 😉

swift crag
#

Although, I don't understand why writing to material assets does permanently change the asset on disk in the editor

#

hey, we can't know everything...

ripe shard
ivory bobcat
#

Compared to components and whatnot.

swift crag
#

that makes things easy

#

It's also consistent with how you normally use assets

ripe shard
#

I distrust any code that writes to a SO

dawn owl
#

public class Money : MonoBehaviour
{
    public Text text;
    public float moneyVal = 100;

    void Start() {
        text.text = moneyVal"$"
    }
}

how would i make it display 100**$** instead of just 100 by just changing the moneyVal?

swift crag
#

"$" + 100 will produce "$100"

#

more general option: string interpolation

ripe shard
#

Use a format string

swift crag
#

$"money: {moneyVal}" will produce "money : 100"

#

and $"${moneyVal}" would be "$100"

#

kinda ugly, since you're using a $ there :p

#

hence the simpler example...

dawn owl
#

i did moneyVal+"$" and it worked! tysm

swift crag
#

oh right, you want it at the end

dawn owl
#

yeah it works either way

ripe shard
#

It’s typographically incorrect though

swift crag
#

well guess who has 100$ here: not you 💸

dawn owl
swift crag
#

The third option is explicitly using string.Format

#
string.Format("{0}$", moneyVal);
#

This is extremely useful when you want to contorl how the number looks

ripe shard
swift crag
#
string.Format("{0:N2}", floatVal);

This shows the number with two decimal places

swift crag
#

I use P and N a lot

tropic shuttle
#

Please help, I can't see variables in the inspector. Similar code works, I don't understand why this one doesn't

ivory bobcat
summer stump
tropic shuttle
ivory bobcat
#

What do you see instead?

hushed badge
#

man getting animations to work is harder than i thought

tropic shuttle
verbal dome
hushed badge
ivory bobcat
tropic shuttle
hushed badge
#

should i play the animations from the player movement script or should i make a separate one

ivory bobcat
#

Fix the errors.

rich adder
#

Fix the error first then configure your IDE

ivory bobcat
#

Fix any errors from the top to the bottom.

swift crag
#

Unity will only recompile and use your new code once there are no errors.

#

That's why nothing changed.

#

This includes errors in other scripts.

#

It's an all-or-nothing deal.

split dragon
#

Hi. I have created a public field: public Display Cameras. I want to switch between the display (camera) by pressing a key. I have done everything that is necessary, but I do not know exactly how to switch the display number. I couldn't find it on the Internet :(. Which method should I use?

dense cargo
#

Display number?

tropic shuttle
#

Guys, how to make the object change GameObject.SetActive(true) to (false) after 5 seconds, let's say. How can this be done?

hushed badge
#

aint no way

tropic shuttle
#

Okay

dense cargo
#

There are multiple ways to do this. Don't just hop in here and tell people it's not possible.

cosmic quail
rich adder
frosty hound
#

You can interrupt it

rich adder
#

also this ^

frosty hound
#

You can modify it, speed it up or slow it down

cosmic quail
rich adder
#

no timers do

#

so you're calling the C++ kinda expensive function just to run a timer

cosmic quail
rich adder
cosmic quail
rich adder
#

no Update loop is

cosmic quail
#

ah ok

summer stump
cosmic quail
#

yea cause i've only been using couroutines everywhere, i refuse to do a timer in an update method cause its really hard to understand lol

rich adder
#

I just don't see the purpose of running such a loop just for timers

frosty hound
#

I never use coroutines for timers. They're purely used to sequence a set of actions.

summer stump
dense cargo
#

More or less.

rich adder
#

for the slowing /speeding point

cosmic quail
dense cargo
summer stump
hushed badge
rich adder
#

bools just to not run timer but Update loop still calls the C++ backend 🤷‍♂️

cosmic quail
#

with couroutine you can just StopCoroutine

summer stump
rich adder
#

my main gripe is having an uneccessary Update loop open in a script

cosmic quail
#

yea thats what im worried about too

rich adder
#

its not big deal for 1 script but they add up

#

and in a unity doc i was reading, Update even empty ones still allocate

gaunt ice
#

I just use existing loop to update all my timer

rich adder
#

yeah I usually do that for other things, I subscribe to a global update

#

no need to have 100 enemies all running Update

cosmic quail
#

if u need extra functionality than just a super simple timer, then putting it into update the code is gonna get messy imo

#

idk im just used to couroutines and they have worked perfectly for every scenario

rich adder
#

as long as it works , this is prob the last channel to talk about micro optimizations haha

#

although good habits should start early

cosmic quail
rich adder
#

Distance inside a while loop for example

#

or like enemy patrol

cosmic quail
rich adder
#

its clean imo 🤷‍♂️

#

and it can be stored in an object

#

Coroutine

cosmic quail
#

yep

tropic shuttle
#

Help please with the timer, I don't understand what I'm doing wrong, the slender doesn't disappear

eternal falconBOT
rich adder
#

no ide config = no help

#

oh wait you nested coroutine in OnTriggerEnter oof

#

wtf. config IDE first though

cosmic quail
#

is that even possible

rich adder
#

the synax is valid

#

just wont work as is

#

coroutine still needs to be Started

hushed badge
#

also does anyone know how i can get the visual style of lethal company

#

its like

#

cell shading

#

with

#

retro stuff

#

ion know

cosmic quail
hushed badge
#

so is that all

cosmic quail
hushed badge
#

low resolution and cell shading

hushed badge
rich adder
#

not really code related

cosmic quail
#

yeah i was gonna say that

hushed badge
#

ok

rich adder
#

also this can be easily done with a shader

hushed badge
#

should i delete the messages

cosmic quail
#

nah its ok just repost it to unity-talk i guess

hushed badge
#

ok

tropic shuttle
rich adder
tropic shuttle
#

Okay, I just rolled it all back, no more problem.

silver heron
#

Guys can you help? I cant run a file on VC 2022

#

thats what happen when i press un that green run button

verbal dome
#

Doesn't really seem Unity related

silver heron
rich adder
eternal falconBOT
silver heron
clear seal
#

i want to repeat the first code but are the loop compatible?

summer stump
clear seal
#

aren't the coroutine act like the wait functions

rich adder
#

no?

clear seal
#

oh

fierce shuttle
#

Which "wait functions" are you referring to?

summer stump
rich adder
#

idk what you want to loop though

#

oh like a submachine gun

clear seal
#

yeah

rich adder
#

yeah def use coroutine and timeBetweenShots

swift crag
#

Coroutines let you write code that suspends itself, then gets resumed later.

#

A common pattern is to write a loop that yields after each iteration

#

To do bullet shooting, I like to do this...

clear seal
#

so i change ubpdate to ienumerator

#

and add stuff to start

swift crag
#
[SerializeField] shotInterval;
private float shotDelay;

void Update() {
  shotDelay -= Time.deltaTime;

  while (shotDelay <= 0) {
    Shoot();
    shotDelay += shotInterval;
  }
}
#

this correctly fires multiple times per frame if needed

#

it also runs forever if you forget to make shotInterval non-zero...

rocky canyon
#
    void Update()
    {
        if (Input.GetMouseButton(0) && !isFiring)
        {
            StartCoroutine(FireBullets());
        }
    }```
swift crag
#
[SerializeField] shotInterval;
private float shotDelay;

void Start() {
  StartCoroutine(ShootForever());
}

IEnumerator ShootForever() {
  while (true) {
    shotDelay -= Time.deltaTime;

    while (shotDelay <= 0) {
      Shoot();
      shotDelay += shotInterval;
    }
    yield return null;
  }
  // i put yield return null here by mistake
}
rocky canyon
#

w/ the StartCoroutine

swift crag
#

something like that

#

oops that's bogus

#

that will run forever!

rocky canyon
#

lmao

#

INFINITE AMMO GLITCH

swift crag
#

For something where the player can start and stop firing, I'd probably just do it in Update

#

Starting and stopping the coroutine sounds annoying

rich adder
#
    private void Update()
{
    if (Input.GetButton("fire") && canShoot)
    {
        StartCoroutine(Shoot());
    }
}
public IEnumerator Shoot()
{
    canShoot = false;
    FireBullet();
    yield return new WaitForSeconds(timeBetweenShots);
    canShoot = true;
}```
Whats wrong with this 🥲
rocky canyon
#
public class MachineGun : MonoBehaviour
{
    public float fireRate = 10f;
    private bool isFiring = false;

    void Update()
    {
        if (Input.GetMouseButton(0) && !isFiring)
        {
            StartCoroutine(FireBullets());
        }
    }

    IEnumerator FireBullets()
    {
        isFiring = true;
        FireBullet();
        yield return new WaitForSeconds(1f / fireRate);
        isFiring = false;
    }

    void FireBullet()
    {
        Debug.Log("Bullet fired!");
    }
}``` here's my example
swift crag
#

Coroutines are great for things that have complex state to keep track of

clear seal
#

but like a simple basic example

rocky canyon
#

my example is as basic as u can get pretty much

#

unless u use like a 1 line Invoke() method or something

#

but ppl say dont use Invoke

rich adder
#

ohgod no

rocky canyon
#

^ see

#

lol

swift crag
#

ah, we used coroutines for different things; i misunderstood the goal

rocky canyon
#

yea, mines not technically a loop

swift crag
#

My coroutine fires bullets. The others decide when you're allowed to shoot again

#

Those make more sense :p

rocky canyon
#

its just that the mouse button being held restarts the ienumerator each time it runs

#

while its being pressed ofc

rocky canyon
cosmic dagger
#

If you only ever need to run smth once that repeats, using Invoke is preferred . . .

rich adder
#

while loop + ienum

rocky canyon
#

while loops scare me

#

i try to use them very very sparingly

rich adder
#

youll use nothing but while loops xD

clear seal
#

o_o

rocky canyon
swift crag
#

we've probably made a mess for Gold here

swift crag
cosmic dagger
swift crag
#

When you click the mouse, it calls ShootBullet

clear seal
#

yeah

#

yep

swift crag
#

and only when the mouse goes down, not every frame

#

You want it to shoot many times.

#

Is that right?

clear seal
#

yep

swift crag
#

But not every single frame.

#

You probably want it to shoot, say, 10 times per second

clear seal
#

yeah let's sy this

swift crag
clear seal
#

like it'S customable

rocky canyon
cosmic dagger
swift crag
#

As long as isFiring is false, holding the mouse will start the FireBullets coroutine

#

That coroutine will call FireBullet and set isFiring to true

#

It will then wait for a little while.

#

in this case, it waits for 1/10th of a second

#

Then, the coroutine sets isFiring to false and ends

rich adder
#

how would you even embed the console Exe inside

rocky canyon
#

then when it loops back around in the update if ur still holding the fire button the coroutine starts again, fires, waits and rinse and repeat

rocky canyon
#

i havent actually ever used the legit c# console yet

rich adder
#

ohh

#

i meant this by console

clear seal
#

from what i understood

rocky canyon
#

ya, the stuff i shoulda learned first

#

i know what ur referencing lol

#

i'll get there sometime

rich adder
#

oh ok lol I did after i learned some unity but helped me greatly solidating just logic because of not worrying of UI
also makes it tricky to make ticks and loops, hence while loops become your bff

clear seal
#

it doesn't shoot

rocky canyon
#

id need a scratch sheet of paper just to keep up with the flow

swift crag
clear seal
#

the gun

#

machine gun

rocky canyon
#

put some debug.log's scattered around and make sure ur logic is executing like u think it should

swift crag
#

Your code isn't working?

#

Show us what you have now.

rich adder
#

logic wise

swift crag
clear seal
rich adder
#

that one scares me more haha

rocky canyon
swift crag
rocky canyon
#

like having stuff in an external class

clear seal
swift crag
#

That's just going to print "BANG!" to the console

rocky canyon
#

and calling it from within the main logic

rich adder
rocky canyon
#

oh oka

swift crag
#

make it call your ShootBullet method

rich adder
rocky canyon
# clear seal

from first glance i would think that would Print the "Bullet FIred!" over and over

clear seal
#

ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh i foud the problem

#

so the IEnumerators call for the function

rich adder
#

you need your ShootBullet method there

rocky canyon
#

the Ienumerator is just what a coroutine is

clear seal
#

and so i need to add an other function&

rocky canyon
#

yea u need a function to Start the coroutine

rich adder
clear seal
#

but wait

rocky canyon
#

u coulda slotted the function into where the debug is

rich adder
#

you would use that instead of Debug.Log

rocky canyon
#

ShootBullet();

clear seal
#

is it possible to call a function from a function

rocky canyon
#

ur update calls the coroutine.. the coroutine calls the shoot method.. then waits ..

rich adder
#

thats literally how you call functions

summer stump
rocky canyon
#

then it repeats b/c of the update loop

#
    IEnumerator FireBullets()
    {
        isFiring = true;
        ShootGun();
        yield return new WaitForSeconds(1f / fireRate);
        isFiring = false;
    }

    void ShootGun()
    {
        // Replace this with your actual shooting logic
        Debug.Log("Gun shooting!");
    }
#

like this ^

#

u call the FireBullets() from ur update using ur inputs.. then it will call the ShootGun() function from within it

clear seal
rich adder
#

you deleted all your declerations 🤷‍♂️

rocky canyon
#

sure did

#

ur class is telling you that the variables ur trying to access dont exist

clear seal
#

i forgot the top part lul

rich adder
#

in c# you must declare a type before you can use it

swift crag
#

you can't just paste a bunch of code together and expect it to work

rocky canyon
#

unless its a built in variable like Camera.main or others

swift crag
#

look at what spawncampgames did, then do something similar with your own code

clear seal
#

it works :D

#

tysm

rocky canyon
rocky canyon
rich adder
rocky canyon
#

if it is its coincidence

#

just some unity cubes layered together

#

lol

rich adder
#

no I meant the functionality didnt see its a gun

rocky canyon
#

wanted something ez to animate..

#

ohh it has 3 modes..

#

projectile raycast and gravity

#

soo i guess its very similar

rich adder
#

can you weld objects together?

rocky canyon
#

lol not yet?

#

that sounds hard

rich adder
#

😏

#

Hinge joint gun 😆

rocky canyon
#

unity joints are nothing but heartache

clear seal
#

should i add it as an assault or as an smg?

rocky canyon
rocky canyon
clear seal
rocky canyon
#

u can even use the same class and just modify the values

clear seal
#

oh you tryna make a sandbox

#

kwel

rocky canyon
#

or u can duplicate it and change the name

rocky canyon
#

😄

clear seal
#

are you gonna add gor like gore box or smth

rocky canyon
#

not sure.. this project is kinda on the backburner.. i just keep it handy to help beginners. it has almost all the code that beginners start with

#

working with world space UI atm..

clear seal
#

on a scale to 1 to 10, what level of coding you think you are

rocky canyon
#

so 3D UI panels basically

#

a 6?

#

ive been learning unity for about 2 years now

clear seal
#

for me it'S 3 years

#

my parent put me in coding class

rocky canyon
#

i can't do advanced stuff yet.. a lot of the coders in here.. like navarone, fen, and randomdiscord all have me out-coded by a mile

clear seal
#

your stuff are fire bro

rocky canyon
#

thanks.. im a graphic artist

#

so i can make things look better than they actually are

#

😄

clear seal
#

that's even better

clear seal
#

i had a team cuz it was like a project

rocky canyon
#

lmao

#

my guns just float

hollow raft
#

i am using visual studio, but it give me the "The type or namespace name 'type/namespace' could not be found" error, but the game works fine (without error) when i launch it via unity, but i can't code if it can't access the namespaces (this error started when i switched pc)
(the namespaces should be referenced i check in the solution explorer, i thus have no idea what to do)

clear seal
rich adder
rocky canyon
#

lmfao!!! my friend in another channel has been working on a fishing game for years

#

u ever looked into faux rope?

#

might be a cool addition

unreal imp
#

guys 2 things,first merry christmas and one more things: how i do get a Vector3 as a position for the instantiate? var collisionTransform = col.ClosestPoint(transform.position); //Debug.Log("It Works"); var collisionNormal = transform.position - collisionTransform; AudioSource porcelainHit1i = Instantiate(porcelainHit1, error->collisionTransform<);

rich adder
rich adder
#

I just wish the joint wasnt so drastic lol

#

too "elastic"

rocky canyon
#

really ez to set up. could be cool with ur fishin rod

rich adder
#

exactly what i needed thx!

clear seal
rocky canyon
#

just remember to try to settle on a style before u go adding models..

#

u dont want everything to be low poly but the weapon

#

and vice versa

rich adder
rocky canyon
#

awesome.. glad i could help.. i use it for electrical cables..

clear seal
#

so at the end i make my own

rocky canyon
#

Vector3 myNewVector = transform.position - thatothertransform.position;
should result in a vector3

#

if u stick with a transform.. u can still use that too.. Transform myTransform = bla - bla;
then to get the vector its just myTransform.position;

#

and merry christmas to u 2

unreal imp
#

its var collisionNormal

rocky canyon
#

well var just assigns it to w/e it should be automatically

#

var myBool = false;
var myVector = Vector3.zero;

rich adder
rocky canyon
#

both var are different types in that example ^

unreal imp
summer stump
rich adder
summer stump
#

Ahhh, this ^

rocky canyon
#

in the top corner it should say Assembly-CSharp.. if it says anything else.. like Miscellaneous then its not working correctly and is probably not linked to Unity anymore

rich adder
#

ah yes didnt even catch that

sudden grove
rocky canyon
rich adder
#

oh you cant see it on ss

lapis halo
#

Im trying to make the camera follow the player, but whenever the game starts it doesn't show anything

rocky canyon
#

not sure its the right assessment tho

lapis halo
rich adder
summer stump
rich adder
#

check Z positions

#

camera should be less than the things infront
ie cam.z -10 ; objects.z = 0

sudden grove
lapis halo
#

idk why

rocky canyon
#

why not disable the collider of the torch when u pick it up?

#

or better yet go into the physics settings and disable them from interacting w/ the player

sudden grove
rocky canyon
#

well thats a different issue

sudden grove
summer stump
rich adder
#

you have to parent it to something at 1,1,1

sudden grove
#

yeah the whole thing is set to 0.3 crap

rocky canyon
#

if u parent a cube thats 1,1,1 to something with a scale of 10,10,10 its all of a sudden gonna be a 10,10,10 cube

sudden grove
#

is there an easy wway to keep it at size?

#

if that makes sense?

rich adder
#

all parents of objects should be 1.1.1

sudden grove
#

wwithout having to readjust the whole thing?

rocky canyon
#

u can parent it to the object and then adjust it to the size it needs to be

#

and then unparent it

sudden grove
#

im a little confused?

#

cause if i set everything to 1,1,1 then the torch wwont be the same size anymroe? itll reset all shapes back to its original shape?

rich adder
rocky canyon
#

w/o modifying the main player or w/e u can make the pickup the size it should be.. (like as if it was already parented) that way when u unparent it.. it will be the correct size it needs to be in order to be the size u WANT it to be once it gets parented

rich adder
#

always separate your graphics from ur root object

rocky canyon
#

otherwise u can either fix the scale's and make ur obejct 1,1,1 like it should be

#

u can adjust the size in script After u parent it.. OR u can NOT parent it.. and use code to move it around to match the transform of the player or w/e

sudden grove
#

which would you advise to be easiest?

rocky canyon
#

the most proper is to keep ur gameobjects scaled to 1

#

it will save u heartache in the end

sudden grove
#

so right now which wwould be my first step to achieving this

sudden grove
#

im so sorry if im annoying or slow

summer stump
sudden grove
#

ohhhh

#

noww the torch is the original size

rocky canyon
rich adder
#

xD

sudden grove
#

but i still need to make it smaller?

#

unless thats the process of making the children smaller noww?

rich adder
rocky canyon
#

yea. u need to readjust things

summer stump
sudden grove
#

i dont know 😭

rocky canyon
#

in order for the parent to stay 1,1,1

rich adder
sudden grove
rich adder
#

just resize this one

#

then create empty object inside, then unparent it and parent mesh to that

rocky canyon
#

the graphics should just be a child of the main object..

#

that way u can adjust its size scale or anything else.. and it doesnt impact the main logic of the parent

sudden grove
#

so this is better?

rocky canyon
#

always better

rich adder
sudden grove
#

okay so the body is fine

#

the spotlight, fine

#

is the button and the tip i need to figure out

rich adder
sudden grove
#

teach me master

rich adder
#

you have to put meshes into 1 object

#

then scale the parent

#

thats itself inside the ROOT

rich adder
#

like this

rocky canyon
#

heres another example..

#

just make a container called Graphics or w/e

#

and scale that instead

rich adder
#

button and tip need to be reset to original size so they match

rocky canyon
#

the 'Tree' or the Root object should never change from 1,1,1

sudden grove
#

OHHHH

#

hang on

#

my torch looks like this but i think my heirarchy is correct now?

rich adder
#

is this what the torch original looked like though ?

sudden grove
#

not at all 😭

rich adder
#

can you drag the original model file in scene

#

and ss it

sudden grove
#

how do i do that?

#

cause its not a premade model

rich adder
#

oh?

sudden grove
#

i literally got a few cylinders and put it together myself

#

i probably should have mentioned that shouldnt i

rich adder
#

so thats how it supposed to look?

#

its just big

sudden grove
#

no 😭

#

its meant to look like a flash light

#

but you were saying reset everything to 1,1,1

rich adder
#

We dont know what the original looked like

sudden grove
#

so i did

#

this but smaller

rich adder
sudden grove
#

ohhhh

rich adder
#

then sacale parent

#

then attach that to another 1,1,1 parent

#

pretty simple

sudden grove
rich adder
sudden grove
#

graphics is 0.3, 0.3, 0.3

rich adder
#

if so, only scale graphics until the flashlight is whatever size you want

rich adder
#

delete colliders for each mesh

rocky canyon
# rich adder delete colliders for each mesh

if the parent is 1:1:1 then the thing u parent it to are both 1:1:1 no scaling will happen

and yup, every piece doesn't need a collider anymore. u can use a primitive collider like a cube,sphere, or capsule on the root object that fits teh general shape of all ur graphics

#

my tree for example

sudden grove
#

hang on im breaking a bunch of stuff cause im panicking

rocky canyon
#

the colliders aren't even aware of the graphics.. they just fit the shape enough where the player doesnt notice

sudden grove
#

lemme just start from the beginning

#

imma delete the torch then we'll go from scratch

ionic fjord
#

How can I change animation easly?

I made a Animation Controller but making a trigger for each possibility "from --> to" is annoying. Can I just make a variable and a "Change state (and animation) to variable" ? based on the name of the animation.

sudden grove
#

okay torch is gone, whats my first step @rich adder

rocky canyon
sudden grove
rocky canyon
#

basically yea

summer stump
sudden grove
#

or are they the same thing?

rich adder
#

Graphics is empty yes

ionic fjord
sudden grove
rocky canyon
#

the actually mesh parts are the only things that arent empty

#

so that way u can scale the parts to any scale u want.. and the parent is still gonna be 1:1:1

#

that will prevent u from having scaling and rotation errors and etc

sudden grove
#

okay so all of the stuff under graphics has its owwn scale value

#

and torch object is set to 1

rich adder
#

yes

rocky canyon
#

yup,

sudden grove
#

let me add the script to the torch

#

and ill let you know what happens

rich adder
#

you have to also fix the empty parent scale you're attaching wep to

sudden grove
#

cause i need a box collider and a rigid body for the script to work, so would i add those to the main torch object also?

rocky canyon
#

u add those to the root object

#

yes

#

and u scale the collider within the component itself.. not the main object

sudden grove
rocky canyon
#

it can be on the main obejct

rocky canyon
#

the TorchObject

sudden grove
#

okay

rocky canyon
#

u dont want ur code having to look thru the entire hiearachy to find the components

#

u want them at the top

sudden grove
#

wwhy tf

rich adder
rocky canyon
#

ya, the graphics should just be graphics..

rich adder
#

even tho scale doesn't affect it

rocky canyon
#

if u have a spotlight or something that can be on teh same level as the graphics

rich adder
#

being child of Torch is fine

rocky canyon
#

my setup would look like this..

#

if i disable "Graphics" i just want all the graphics to disable

#

not the light /scripts/ or anything else i added

rich adder
#

also things should always face blue in LOCAL pivot mode
this would be bad

#

esp for weapons, you want the front to always be blue

#

all you would do is rotate Graphics unitil it faces blue

sudden grove
#

okay guys i got good news

#

it works now no issues

#

i just gotta get it so its in view of my camera

unreal imp
sudden grove
#

is this okay?

rich adder
rich adder
#

put 1 capusle on main object

unreal imp
#

ah oka

unreal imp
sudden grove
rocky canyon
rich adder
#

prob overkill being soo chunk but you get the point

rocky canyon
#

^ good example

unreal imp
rocky canyon
#

just abouts the same size

rocky canyon
#

if u used a Vector3 u'd just put that in the place

rocky canyon
#
       // Example 1: Using Vector3
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out RaycastHit hit))
            {
                Vector3 hitPosition = hit.point;
                InstantiatePrefabAtPosition(hitPosition);
            }
        }

        // Example 2: Using Transform
        if (Input.GetMouseButtonDown(1))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out RaycastHit hit))
            {
                Transform hitTransform = hit.transform;
                InstantiatePrefabAtTransform(hitTransform);
            }
        }```
#

both examples pass in the same Vector information.. 1 is doing it via the Vector3 and one is just grabbing that from the transform cs void InstantiatePrefabAtTransform(Transform transform) { // Instantiate the prefab at the position of the transform Instantiate(prefabToInstantiate, transform.position, Quaternion.identity); }

#
    void InstantiatePrefabAtPosition(Vector3 position)
    {
        // Instantiate the prefab at the specified position
        Instantiate(prefabToInstantiate, position, Quaternion.identity);
    }```
tender stag
rocky canyon
#

same thing..

tender stag
tender stag
unreal imp
tender stag
#

i tried doing this but it give me weird resultscs cameraPosition.localPosition = Vector3.Lerp(cameraPosition.localPosition, targetCameraPosition, Time.deltaTime * crouchDuration); cameraHolder.localPosition = cameraPosition.position;

rocky canyon
#

thanks

tender stag
#

the height here is smooth

#

like it goes down over time instead of teleporting

#

but when i look up and down

terse raven
#

Hi everyone! I'm making a card game and I was wondering whether to use scriptableObjects or not, or whether to just have instances of classes. What would you suggest is the best option?

tender stag
#

its also lerping the position

ionic fjord
#

How can I turn a "string" into a part of the code like the name of variable like:

//emotion is the variable set to "Normal"
if (emotion == "Normal")
  {
    frame_renderer.sprite = Normal_frame;  //I have to repeat it several times and I don't want a else if for each of them
    frame_renderer.sprite = "emotion"_frame;  //or something to turn emotion into part of the name of the var
  }
rocky canyon
#

ive asked a similar question and was told C# isnt a macro language

#

but could different use-cases

tender stag
rich adder
#

you mean switch it at runtime ?

tender stag
#

i send all i really needed to send

#

i think

rich adder
#

its possible but shouldn't prob be doing it not for this..

clear seal
#

um do yall think making NVG on unity is simple or hard?

rocky canyon
rare basin
#

serializable dictionary so you can edit it in the editor

tender stag
verbal dome
rare basin
#

or dictionary<enum,sprite>

tender stag
clear seal
verbal dome
clear seal
#

so it wont affect other player vision?

rocky canyon
rich adder
unreal imp
rich adder
#

everyone is running their own version of the game

verbal dome
rich adder
#

thats all multiplayer is to sync those versions

rocky canyon
tender stag
#

its not about the lerp

rich adder
tender stag
#

true

rocky canyon
#

so is that screenshot u sent instead the code u tried?

tender stag
#

what

rocky canyon
#

this.. is this the logic we're watching in the video?

tender stag
#

yup

#

when the rotation is above 0

verbal dome
#

And have you logged its value?

unreal imp
tender stag
#

xRotation is calculated correctly

unreal imp
rocky canyon
rich adder
#

still wrong lerp

rocky canyon
#

rather than pulling it from the bullet

tender stag
# tender stag

all this code does is when a player starts looking down, it moves the cameraPosition forward and down a bit

#

according how much the player is looking down

#

as you can see in the video

#

but the problem is that its not smooth

verbal dome
tender stag
#

88.5

unreal imp
rocky canyon
#

^ yea could be..

#

its all about problem solving

unreal imp
#

thank you 😘

rocky canyon
#

u could have the bullet hole check what material its on

#

and have it play the sound

#

lots of ways ¯_(ツ)_/¯

unreal imp
#

👆

#

👏 👏 👏

rocky canyon
#

🍀 gl

verbal dome
tender stag
#

this is without the lerp

#

and it works

#

but when i crouch and uncrouch

#

the camera position gets instantly set

#

and it just teleports to the walk or crouch position

tender stag
verbal dome
#

I would have a float for crouching too, something like crouchLevel or crouchAmount

tender stag
#

i have that

verbal dome
#

Is it like smoothed?

#

And moves gradually to 0 when uncrouched and to 1 when crouched?

#

You should use that to lerp between thet targets of those lerps

tender stag
verbal dome
#

Lerpception

tender stag
#

this is how i was doing it before

#

and it was working

verbal dome
tender stag
#

just have the whole code

#

your looking at HandleCameraPosition()

rich adder
#

says lerp is not wrong but wrong lerp everywhere lol

tender stag
#

i said i know its wrong

#

but its not about the lerp

#

i can fix that later

verbal dome
#

The current code has correct lerp

rocky canyon
#

in some places

verbal dome
#

Yeah I mean the HandleCameraPosition method

rocky canyon
#

the crouching lerps not so much

rich adder
#

that class finna get bigger and bigger

rocky canyon
#

lol.. its a hefty class rn

#

but i give it a pass b/c its a CC

verbal dome
#

@tender stag I guess something like this cs Vector3 targetCrouch = Vector3.Lerp(cameraCrouchPosition, cameraCrouchRotPosition, t); Vector3 targetStanding = Vector3.Lerp(cameraWalkPosition, cameraWalkRotPosition, t); targetCameraPosition = Vector3.Lerp(targetStanding, targetCrouch, crouchAmount);

tender stag
#

should the camera position have a parent, and when i crouch i'd lerp the parent height up or down, and then just add the positions to the camera position position?

rocky canyon
rich adder
#

yup

rocky canyon
#

i lerp my height and center just like u do

verbal dome
rocky canyon
# tender stag should the camera position have a parent, and when i crouch i'd lerp the parent ...
        private void CrouchCheck()
        {
            // a little jerky
            if(Input.GetKey(KeyCode.LeftControl))
            {
                isCrouching = true;
                // Height and Center deltaMaxs need to match
                characterController.height = Mathf.MoveTowards(characterController.height,1f,(7f * Time.deltaTime));
                characterController.center = Vector3.MoveTowards(characterController.center,playerSettings.crouchingVector,(7f * Time.deltaTime));
            }
            else if(!obstacleOverhead)
            {
                isCrouching = false;
                // Height and Center deltaMaxs need to match
                characterController.height = Mathf.MoveTowards(characterController.height,2f,(5f * Time.deltaTime));
                characterController.center = Vector3.MoveTowards(characterController.center,playerSettings.standingVector,(5f * Time.deltaTime));
            }
        }```
i use `MoveTowards`
#

so i dont have to make a extra variable for lerps

tender stag
#

the thing is you think im on about something different

#

its hard to explain it

verbal dome
tender stag
#

its not

#

its the camera position

rocky canyon
#

no.. u asked should the camera position have a parent, and when i crouch i'd lerp the parent height up or down, and then just add the positions to the camera position position?

i just answered with a sample of how i did my crouching.. after i said my CC has the same style crouching.. so i cant say for sure

#

just an example.. ur very much free to ignore me lol.. i dont know how to resolve ur camera issue, as Osmal is dealing with that

verbal dome
#

Or what

tender stag
#

you see how the camera position is getting moved down and a bit forward when i start to look down?

#

and the more i look down the more it gets moved to the target position

#

same when i crouch

#

thats whats supposed to happen

#

but the problem comes in the i crouch and uncrouch

#

because i need to move it down slowly

#

so lerp it

verbal dome
#

I already gave a solution to that

#

Don't ignore it

#

Of course the transition is not going to be smooth if you use a boolean

tender stag
#

so this?

verbal dome
#

If currentCrouchHeight is a float that goes between 0..1 gradually, then yes it looks right

tender stag
#

i have no idea what is happening lmao

verbal dome
#

If it's the height of your character then it won't work, or is inverted/wrong scaling

tender stag
#

its not

#

hold on

verbal dome
unreal imp
# rocky canyon 🍀 gl

One last last last thingy, how do I rotate the bullet hole so that it looks outside? I want to do it with OnTriggerEnter() but idk how to deal with the rotation

verbal dome
unreal imp
verbal dome
#

If it's a raycast, use raycastHit.normal
If a collision, use collision.normal
As transform.forward or Quaternion.LookRotation

unreal imp
#

these are the rotations

rocky canyon
#

what they said

verbal dome
verbal dome
rich adder
#

hella expensive for no reason 😆

verbal dome
#

On the bullet hole I mean

#

Just noticed the bullet has one too

#

Better use a capsule, sphere or box

rocky canyon
#

Sphere FTW

rich adder
#

that would be a ray

#

hit is unused , time to use it

verbal dome
# unreal imp

Ok so use hit.normal
Also use hit.position for the position in Instantiate

hollow carbon
rocky canyon
#

yup hit is a variable that gives u all sorts of details about the collision

hollow carbon
#

whats my mistake?

verbal dome
rich adder
unreal imp
hollow carbon
rocky canyon
#

thats what Hit is

#

tahts the contact

unreal imp
#

unlike raycast it is more complicated

rich adder
#

== to compare
= to assign

#

or also > <

#

also >= <=

hollow carbon
#

I dont know what you mean

rich adder
#

then you outta go do some basic c# courses

#

learn how to compare stuff esp numbers

hollow carbon
#

just say my mistake pls

rich adder
#

its basic math not even code related

hollow carbon
rich adder
unreal imp
rich adder
#

lets say its 0.4f

Your first if statement is doing if(0.4f) ? ? ??

which ofc makes no sense

verbal dome
rocky canyon
#

This is a raycast just like You have it spits out the Hit information that I use to debug the name of it. but it has other things too.. like the normal.. (that would be the facing direction of the thing you hit)

soo im confused by the way youre trying to get teh position and the normal.. its all prepackaged right there in the raycast for you

unreal imp
hollow carbon
rich adder
rocky canyon
#

no no, of the raycast, HIT is the contact the point the raycast hit something

unreal imp
rocky canyon
#

hit.point

unreal imp
rich adder
#

but for decal facing correct you still need hit.normal

rocky canyon
#

yes

rich adder
#

like Osmal said

unreal imp
#

or will do it without matter that and generate the hole even if the bullet doesnt hit the wall

rocky canyon
#

well when the raycast hits the wall..

verbal dome
#

I'm wondering, how is the bullet's trigger even being used? Seems like only raycast

rich adder
#

Quaternion.LookRotation

unreal imp
#

thanksssss

rocky canyon
#

yea, i think he's using the bullet hole to get what material he hit..

#

and play an appropriate sound effect

#

when u can do all that inside the raycast

rich adder
#

indeed

rocky canyon
#

but live and learn

hollow carbon
#

thanks

unreal imp
#

🥲 if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, shootForce)) { var bullet1 = Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation); bullet1.GetComponent<Rigidbody>().velocity = bulletSpawn.transform.forward * shootForce; if (hit.collider.contactOffset.Equals(bullet1)) { var bulletHole1 = Instantiate(bulletHole, hit.point + (hit.normal * 0.1f), Quaternion.FromToRotation(Vector3.up,hit.normal), hit.transform); } }

#

😖

verbal dome
#

Does it work correctly?

#

I assume your bulletHole's forward vector is actually up

unreal imp
verbal dome
#

Uhh I didn't even notice that line

#

What is it even supposed to do? 🤔

#

contactOffset is a float and you are checking if that float is the bullet you just instantiated

#

Makes no sense

sudden grove
#

do you guys have a good tutorial for headbobbing with a rigidbody?

rocky canyon
#

outside the box kinda programming 😛

rich adder
#

just animate the camera holder

unreal imp
sudden grove
unreal imp
#

im very dumb

rocky canyon
#

yea, ud be moving the camera up and down in its own container

rocky canyon
#

make an extra container for ur camera..

rich adder
rocky canyon
#

and bob the container instead

verbal dome
#

You are overcomplicating it

sudden grove
rich adder
sudden grove
#

okay bet

unreal imp
verbal dome
#

I'm really confused now and gtg for a moment anyway

#

Someone else take over lol

rocky canyon
#

the raycast can do everything it can spawn a bullet, it can spawn a bullet hole on the object it hit.. u can rotate it to match the normal of the thing u hit.. can even play the audio

#

all within the raycast

sudden grove
rocky canyon
#

can't have any errors in it

#

and make sure the name of the class matches the name of the script

sudden grove
#

theres not a single error

wild cargo
#

is the script deriving from monobehaviour?

north kiln
sudden grove
wild cargo
unreal imp
# verbal dome Someone else take over lol

I meant that it detects if the raycast line hits a gameobject and you click on a key to shoot not when the bullet just collide because otherwise it would be independent of that

#

Sorry for the bad english

wild cargo
#

so change something in a script, save it, undo it and save it agian

unreal imp
#

Again -_-

sudden grove
rocky canyon
#

these have to match at all times.. or it wont compile and give u that error

wild cargo
sudden grove
wild cargo
#

the script name does not match with the class name

rocky canyon
#

or theres some logic errors.. and that will prevent it from saving correctly and you'll also get that error

wild cargo
#

they need to equal each other

rich adder
#

bingo

rocky canyon
#

HeadBobSystem is not the same as HeadBobbing

sudden grove
#

okay 1 second then

zealous oxide
#

Hey friends. I'm trying to make a dynamic list to keep track of all pick/power ups acquired by the player by adding the parent object of the pick/power up to a list in an inventory manager but i'm having issues with the inventory manager. i've tried using a method within the inventory manager to directly add the object into the list, but thats not worked, list never changes when the game is running. so i've tried to make a separate gameobject variable [objectToAdd] in the inventory manager and set that as the parent of the game object im trying to add from the pick/power up script but I keep getting a NullReferenceException error. what am I doing wrong?

#

i've never used lists before, only arrays

sudden grove
wild cargo
north kiln
wild cargo
#

or something