#💻┃code-beginner
1 messages · Page 112 of 1
the colours look different
thanks
screenshot
just in case
its fine lol we try to help but a configured IDE will solve 98% of issues
you'd be surpised how many people get combative when asked to configure ide for some reason lol
i can imagine
but still
is it ok to have if statements like that
for toggles
i cant think of a better way
just + to add 2 verctors
yeah but where would i do that
move * speed * Time.deltaTime + velocity * Time.deltaTime should do it
yeah, make sure its working
not a code question #📲┃ui-ux
make sure you properly anchor and use correct scaler mode
Guys am I right to say that Scriptable Objects are interfaces that are imported from another script?
They are data containers used to save large amounts of data, independent of class instances.
now i gotta figure out how to add animations
no interfaces are completely different
I understand that interfaces give shape and structure
i wasnt aware it could hold on to data
interfaces meerly enforce a contract between class and interface
correct
Interfaces do not hold data.
right
so ScriptableObjects are blueprints, containing prefabs and methods that other scripts can use?
They're data containers
I get it, they can store all kinds of values
SOs do not enforce implementation of methods - very different from Interfaces.
They're Unity objects that don't exist in a scene
compare to MonoBehaviours, which must be attached to a GameObject
Oh thats important I didnt think of that
SOs let you create new kinds of assets.
These assets can be referenced like any other asset (materials, prefabs...)
It has nothing to do with polymorphism
SOs are not a fundamental C# concept.
They aren't "like" classes or interfaces or methods or whatever
Think of it as a special struct or class that exists without being instantiated.
It surely does not.
Maybe read up on polymorphism.
you fix values, give it prefabs, and methods to hold.
and you create new objects from it
its literally just a regular class that inside unity can be created as an .asset
and has a few special methods unity related
I see
since it's a Unity object, you can instantiate and destroy it
Hi I'm new, can someone build a game for me and tag me as the author.
Not the place for ridiculous requests, no.

If you're here to shitpost, you may as well leave the server now
in what use case would i use SOs and not prefabs?
For storing data definitions
When you're not wanting to instantiate an instance.
Sharing data.
its not one or the other..
If you have a bunch of items, for example
they can both be used as they do different things
A prefab is an asset created from a GameObject.
SO's and prefabs are not comparable
prefabs exist to be instantiated and put into scenes.
A ScriptableObject can be instantiated, like any other unity object, but it's never in a scene
I see
Anything deriving from Component is attached to a GameObject
SO can only be attached something else, they can't be put on a gameobject
just like materials, and meshes, and all sorts of other assets
correct
SOs are custom asset types. That's the long and the short of it.
I understand this
I see
They let you create new sorts of assets.
This raises a question. Can I change data on a scriptableObject and expect that value changed for all other scripts
it will change across all SO yes
might be kind of rambly
Assets do not exist during runtime. You'd create a new instance by mutating it.
The SO will not be the same in a different scene.
Sure they do.
You just can't permanently alter them.
by changing SO values? is that mutating it?
When you get a reference to a ScriptableObject asset for the first time, the asset is loaded and a new C# object is created.
yes
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
yeah thats understandable
That's the footgun. You play around with it in the editor and see that changes persist
very useful when you want everyone to share a common list without using a static class
I use scriptable objects for my settings system
Each Setting asset has serialized fields for things like name, description, default value, maximum value...
as well as a non-serialized value field
I think most Unity settings are SO no ?
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
yeah very useful as shared static assets
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
This is the footgun.
(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!
Sounds pretty special 😉
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...
Hence the common advice to treat them as immutable
Compared to components and whatnot.
Indeed.
that makes things easy
It's also consistent with how you normally use assets
I distrust any code that writes to a SO
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?
trivial option: + operator
"$" + 100 will produce "$100"
more general option: string interpolation
Use a format string
$"money: {moneyVal}" will produce "money : 100"
and $"${moneyVal}" would be "$100"
kinda ugly, since you're using a $ there :p
hence the simpler example...
i did moneyVal+"$" and it worked! tysm
oh right, you want it at the end
yeah it works either way
It’s typographically incorrect though
well guess who has 100$ here: not you 💸
im still learning so it doesnt matter much for me 😁
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
No reason to practice/learn the wrong things 😉 (applies to English only btw.)
string.Format("{0:N2}", floatVal);
This shows the number with two decimal places
yep! this lists all of the ways to format numbers
I use P and N a lot
will do! ty :D
Please help, I can't see variables in the inspector. Similar code works, I don't understand why this one doesn't
Is your ide configured?
Are there errors in the console tab of Unity?
Did you save?
Is the file name EXACTLY Slenderman.cs?
Yes
What do you see instead?
man getting animations to work is harder than i thought
What learning resources are you using?
tutorials
Are there errors in the console tab?
should i play the animations from the player movement script or should i make a separate one
Fix the errors.
The console generally shows more than what the bottom of the Editor shows:
https://docs.unity3d.com/Manual/Console.html
Fix the error first then configure your IDE
Fix any errors from the top to the bottom.
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.
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?
Display number?
Guys, how to make the object change GameObject.SetActive(true) to (false) after 5 seconds, let's say. How can this be done?
aint no way
Timer or Coroutine
Okay
There are multiple ways to do this. Don't just hop in here and tell people it's not possible.
whats the advantage of using a timer over couroutine? it seems coroutine is always better, no?
not having an update loop running ?
You can interrupt it
also this ^
You can modify it, speed it up or slow it down
wait coroutine runs an update loop?
oh i asked whats the advantage of a timer tho
idk less scary than an IEnumerator for noobie?
im confused so is couroutine the expensive one?
no Update loop is
ah ok
Neither are really expensive
I guess update is COMPARATIVELY, but both are extremely cheap either way
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
I just don't see the purpose of running such a loop just for timers
I never use coroutines for timers. They're purely used to sequence a set of actions.
time += deltaTime
If time > threshold
Do thing
Time = 0
More or less.
while loop yield fixedUpdate or end of frame 🤷♂️
for the slowing /speeding point
but if you want the timer paused then u gotta start checking a bool in the update loop whereas with ienumerator the program has to do nothing, right? no update loop overhead and no bool checking
#🏃┃animation is the place
Bool checks are so cheap they're basically free 🤷♂️
aight thanks
it gets messy quick now you need a timer ended bool, then you need a pausing bool
bools just to not run timer but Update loop still calls the C++ backend 🤷♂️
with couroutine you can just StopCoroutine
And you would need some check for when to stop coroutine...
my main gripe is having an uneccessary Update loop open in a script
yea thats what im worried about too
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
This is correct
I just use existing loop to update all my timer
yeah I usually do that for other things, I subscribe to a global update
no need to have 100 enemies all running Update
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
as long as it works , this is prob the last channel to talk about micro optimizations haha
although good habits should start early
couroutines are the good habit here right?
no, I wouldn't say that.. I personally prefer them for most things people use update loops for
Distance inside a while loop for example
or like enemy patrol
do you prefer coroutines even for shooting guns? cause i've seen many gun tutorials that have a messy update loop that handles all the firing and reloading and everything
yeah exactly
yield return new WaitForSeconds(reloadTime)
canShoot = true; //or w.e
its clean imo 🤷♂️
and it can be stored in an object
Coroutine
yep
Help please with the timer, I don't understand what I'm doing wrong, the slender doesn't disappear
before help
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
no ide config = no help
oh wait you nested coroutine in OnTriggerEnter 
wtf. config IDE first though
is that even possible
anyone willing to help me out in #🏃┃animation
also does anyone know how i can get the visual style of lethal company
its like
cell shading
with
retro stuff
ion know
well step 1 is locking your resolution to 640x480 or whatever it was. cause lethal company does it (or did idk if they changed it) but people made mods to get it to 1920x1080 so you probably dont want to do this step
tbh i like the low resolution
so is that all
definitely no
low resolution and cell shading
oh
not really code related
ok
also this can be easily done with a shader
should i delete the messages
nah its ok just repost it to unity-talk i guess
ok

uh I have no context to this . did you follow the steps in the guide
Okay, I just rolled it all back, no more problem.
Guys can you help? I cant run a file on VC 2022
thats what happen when i press un that green run button
Doesn't really seem Unity related
i need vs for unity
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
i try, thanks!
i want to repeat the first code but are the loop compatible?
You should look into a coroutine for this
aren't the coroutine act like the wait functions
no?
oh
Which "wait functions" are you referring to?
Kinda. Not really.
It is asynchronous code.
So you can wait INSIDE it (like the delay between firing bullets)
yeah
yeah def use coroutine and timeBetweenShots
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...
[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...
ur coroutine is an ienumerator.. u call that from elsewhere
void Update()
{
if (Input.GetMouseButton(0) && !isFiring)
{
StartCoroutine(FireBullets());
}
}```
[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
}
w/ the StartCoroutine
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
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 🥲
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
Coroutines are great for things that have complex state to keep track of
but like a simple basic example
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
ohgod no
ah, we used coroutines for different things; i misunderstood the goal
yea, mines not technically a loop
My coroutine fires bullets. The others decide when you're allowed to shoot again
Those make more sense :p
its just that the mouse button being held restarts the ienumerator each time it runs
while its being pressed ofc
or maybe i did /shrug you never know
If you only ever need to run smth once that repeats, using Invoke is preferred . . .
while loop + ienum
make a game inside Console
youll use nothing but while loops xD
o_o
on my bucket list
we've probably made a mess for Gold here
so coming back to your original question:
That's what I'd do, make the coroutine for the time between shots. But if doing burst fire, using the coroutine for each bullet works fine . . .
So this is your code.
When you click the mouse, it calls ShootBullet
and only when the mouse goes down, not every frame
You want it to shoot many times.
Is that right?
yep
yeah let's sy this
This code does what you want, then.
like it'S customable
im kinda hooked on world-space UI atm.. but a console program Within my canvas could be pretty cool
Me as well. I hardly — if ever — use them . . .
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
looks better there lol mind as well keep it inside unity imo
how would you even embed the console Exe inside
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
i mean like a command console
i havent actually ever used the legit c# console yet
ohh
i meant this by console
from what i understood
ya, the stuff i shoulda learned first
i know what ur referencing lol
i'll get there sometime
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
it doesn't shoot
logic in a command program seems sooo scary to me
id need a scratch sheet of paper just to keep up with the flow
what doesn't shoot?
put some debug.log's scattered around and make sure ur logic is executing like u think it should
its pretty much the same stuff you use in Unity minus the Monobehvaior stuff xD
logic wise
i've built like 1/10th of a game engine a few times
you told me to use spawn camp games's script
that one scares me more haha
i use the functionallity of monobehaviours to break up my logic tho.. to keep it organized.. can u do the same in command programs?
you're going to have to modify it :p
like having stuff in an external class
That's just going to print "BANG!" to the console
and calling it from within the main logic
yeah ofc
oh oka
make it call your ShootBullet method
usually c# applications will also consider a folder to be its own namespaces
from first glance i would think that would Print the "Bullet FIred!" over and over
ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh i foud the problem
so the IEnumerators call for the function
you need your ShootBullet method there
the Ienumerator is just what a coroutine is
and so i need to add an other function&
yea u need a function to Start the coroutine
you didnt have to delete your ShootBullet method
but wait
u coulda slotted the function into where the debug is
you would use that instead of Debug.Log
ShootBullet();
is it possible to call a function from a function
ur update calls the coroutine.. the coroutine calls the shoot method.. then waits ..
thats literally how you call functions
Update is a function
You were already calling something from it
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
you deleted all your declerations 🤷♂️
i forgot the top part lul
in c# you must declare a type before you can use it
you can't just paste a bunch of code together and expect it to work
unless its a built in variable like Camera.main or others
look at what spawncampgames did, then do something similar with your own code
im just robbing my basic character controller
Very much welcome
is that like the ToolGun from Garrys Mod
no I meant the functionality didnt see its a gun
wanted something ez to animate..
ohh it has 3 modes..
projectile raycast and gravity
soo i guess its very similar
can you weld objects together?
unity joints are nothing but heartache
should i add it as an assault or as an smg?
same functionallity for both
ok
u can even use the same class and just modify the values
or u can duplicate it and change the name
are you gonna add gor like gore box or smth
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..
on a scale to 1 to 10, what level of coding you think you are
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
your stuff are fire bro
thanks.. im a graphic artist
so i can make things look better than they actually are
😄
that's even better
abt that
i had a team cuz it was like a project
lol, ur stuff looks cool too.. atleast urs has arms
lmao
my guns just float
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)
thx but i didn't put any effort lol
tell me about it....Me trying to make a fishing pole with joints lol
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
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<);
its a horror game but you get to fish.
Oh def should look into it that line renderer aint gona cut it
I just wish the joint wasnt so drastic lol
too "elastic"
really ez to set up. could be cool with ur fishin rod
exactly what i needed thx!
i found a good waepon with optic and laser
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
Coincidentally I'm working on a project where you can pump gas and this actually perfect for that too. nice!
awesome.. glad i could help.. i use it for electrical cables..
just prefabs while i am working
so at the end i make my own
u should be getting a vector from the get-go.. no need to use the transform..
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
i was wrong,its isnt Transform collisionNormal
its var collisionNormal
well var just assigns it to w/e it should be automatically
var myBool = false;
var myVector = Vector3.zero;
is this a raycast bullet or physics?
both var are different types in that example ^
well my objective is to play a sound when the bullet hit some material
Hmm. Try removing them and using quick fix on each resulting error to add the right namespaces.
are you u using assembly definitions
Ahhh, this ^
it seems to me like ur IDE isn't configured anymore
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
ah yes didnt even catch that
im about to pastebin the code AND the tutorial i was looking at
ya, the UnityEngine.UI; being underlined led me to taht conclusion..
oh you cant see it on ss
Im trying to make the camera follow the player, but whenever the game starts it doesn't show anything
not sure its the right assessment tho
Is the camera too close?
Its 2d.
prob this
It can be too close in 2d
check Z positions
camera should be less than the things infront
ie cam.z -10 ; objects.z = 0
https://www.youtube.com/watch?v=8kKLUsn7tcg
@rich adder the main issue is is that im picking up the torch, lovely! and i can drop the torch, lovlier! but wwhen i pick it up it makes it massive, pushes my character around indefinitely until i drop the torch, and then its stuck being big
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
because the colliders
because the issue is it still turns massive and faces upwards
well thats a different issue
what about the size?
Do you do cam.transform.position = player.transform.position ? Or something like that?
You want
cam.transform.position = player.transform.position + new Vector3(0,0,-10)
your parent scale probably
you have to parent it to something at 1,1,1
yeah the whole thing is set to 0.3 crap
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
all parents of objects should be 1.1.1
wwithout having to readjust the whole thing?
u can parent it to the object and then adjust it to the size it needs to be
and then unparent it
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?
because u have to make it CHILD of something
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
always separate your graphics from ur root object
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
which would you advise to be easiest?
the most proper is to keep ur gameobjects scaled to 1
it will save u heartache in the end
so right now which wwould be my first step to achieving this
im so sorry if im annoying or slow
Make everything scaled 1,1,1 except the bottommost child of a chain
239 foot long fishing Rod
xD
but i still need to make it smaller?
unless thats the process of making the children smaller noww?
omg why does it have so many colliders
yea. u need to readjust things
Make the child the right size
i dont know 😭
in order for the parent to stay 1,1,1
dw once you learn it once youll do it as second nature
so i sorta gotta "remake" the torch a lil bit?
just resize this one
then create empty object inside, then unparent it and parent mesh to that
and seperate ur graphics from ur logic.. ALWAYS
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
so this is better?
always better
you need to show scales but looks better
okay so the body is fine
the spotlight, fine
is the button and the tip i need to figure out
no you're doing it wrong
teach me master
you have to put meshes into 1 object
then scale the parent
thats itself inside the ROOT
heres another example..
just make a container called Graphics or w/e
and scale that instead
button and tip need to be reset to original size so they match
the 'Tree' or the Root object should never change from 1,1,1
OHHHH
hang on
my torch looks like this but i think my heirarchy is correct now?
yes and you only scale graphics
is this what the torch original looked like though ?
not at all 😭
oh?
i literally got a few cylinders and put it together myself
i probably should have mentioned that shouldnt i
no 😭
its meant to look like a flash light
but you were saying reset everything to 1,1,1
We dont know what the original looked like
we were talking about the root parent but you scaled everything without getting further clarification
ohhhh
make an empty parent and parent those 3 meshes to it
then sacale parent
then attach that to another 1,1,1 parent
pretty simple
like this?
is TestTorchParent 1,1,1 and graphics ?
graphics is 0.3, 0.3, 0.3
if so, only scale graphics until the flashlight is whatever size you want
ok so is fixed now?
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
hang on im breaking a bunch of stuff cause im panicking
the colliders aren't even aware of the graphics.. they just fit the shape enough where the player doesnt notice
lemme just start from the beginning
imma delete the torch then we'll go from scratch
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.
okay torch is gone, whats my first step @rich adder
- TorcheObject
- Graphics
- Mesh1
Mesh2
- Mesh1
- Graphics
is Torch Object an empty object?
basically yea
There is the anystate box too
But this is more of an #🏃┃animation question (they can talk about code there too)
is graphics empty, or empty parent?
or are they the same thing?
Graphics is empty yes
Thanks, I'm watching now
and now the mesh im assuming is 3d objects?
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
okay so all of the stuff under graphics has its owwn scale value
and torch object is set to 1
yes
yup,
you have to also fix the empty parent scale you're attaching wep to
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?
u add those to the root object
yes
and u scale the collider within the component itself.. not the main object
wait so which one of these is the box collider and the rigid body going onto?
the TorchObject
okay
u dont want ur code having to look thru the entire hiearachy to find the components
u want them at the top
wwhy tf
dont put spotlight in graphics
ya, the graphics should just be graphics..
even tho scale doesn't affect it
if u have a spotlight or something that can be on teh same level as the graphics
being child of Torch is fine
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
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
okay guys i got good news
it works now no issues
i just gotta get it so its in view of my camera
wait but do you understand my error?it was var collisionNormal,not Transform collIsionNormal
is this okay?
delete all those colliders
thats teh same thing
put 1 capusle on main object
ah oka
no because in the collisionNormal only accepts Vec3
you right, i have colliders now 😭
u could just do Vector3 collisionNormal = too
prob overkill being soo chunk but you get the point
^ good example
yeah but i do to turn it into a transform?because instantiate(object,pos) only accepts transforms and not vec3
just abouts the same size
doesnt matter.. if u had a transform.. u could just grab teh vector from it.. like Instantiate(theTransform.position)
if u used a Vector3 u'd just put that in the place
you're using wrong signature then
notice which signature has position
// 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);
}```
how do i make the y position smooth
same thing..
at the moment it just teleports
thanks and merry chritsmas
i tried doing this but it give me weird resultscs cameraPosition.localPosition = Vector3.Lerp(cameraPosition.localPosition, targetCameraPosition, Time.deltaTime * crouchDuration); cameraHolder.localPosition = cameraPosition.position;
got any code to go along side that?
thanks
wrong lerp
the height here is smooth
like it goes down over time instead of teleporting
but when i look up and down
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?
its also lerping the position
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
}
SO +1
not sure thats possible
ive asked a similar question and was told C# isnt a macro language
but could different use-cases
i'd have to send u my whole movement code
you mean switch it at runtime ?
its possible but shouldn't prob be doing it not for this..
um do yall think making NVG on unity is simple or hard?
ya u sent it while i was typing.. ignore that last message
make a dictionary<string, sprite>
serializable dictionary so you can edit it in the editor
so got any idea how to make it so that it only lerps the height?
At its simplest it can be a post process effect
or dictionary<enum,sprite>
that might be a solution
yes but for multiplayer is it possible?
There's nothing networking-specific about a night vision effect, so yes
so it wont affect other player vision?
check out the link he sent.. its a problem with the way ur using lerp..
u should not pass in the same thing ur trying to lerp.. so
for example
transform.position = Mathf.Lerp(transform.position, newPosition.... is wrong
not unless you told it too..
It still doesn't work for me, the problem is that when my object collides with the other it disappears/is destroyed and therefore the position is null,i tried what you say
everyone is running their own version of the game
Well no, because you of course activate it only on the client that has NVG turned on
thats all multiplayer is to sync those versions
its not that
well couldn't u cache the position before its destroyed?
its not about the lerp
what you posted had wrong lerp so I sent it 🤷♂️
true
so is that screenshot u sent instead the code u tried?
what
i have to do it when they collide at the right moment with another object but as I said the problem is that the bullet disappears
If you can tell me an alternative, I have no problem
ya, ur gonna have to figure out a way to cache the position u wanna use before u destroy it.. and find a way to use that data..
still wrong lerp
rather than pulling it from the bullet
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
What is the value of lowerLookLimit?
88.5
AHhhhh or i can make that the bullet generates a bullet hole which plays the sound of the hit material if its colliding with a certain material
thank you 😘
u could have the bullet hole check what material its on
and have it play the sound
lots of ways ¯_(ツ)_/¯
🍀 gl
Do you mean when you crouch/uncrouch?
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
but when i lerp it u saw what happened here
I would have a float for crouching too, something like crouchLevel or crouchAmount
i have that
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
Lerpception
Paste this as code so I can show an example
says lerp is not wrong but wrong lerp everywhere lol
The current code has correct lerp
in some places
Yeah I mean the HandleCameraPosition method
the crouching lerps not so much
that class finna get bigger and bigger
@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);
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?
my CC has the same style crouching.. so i cant say for sure
yup
i lerp my height and center just like u do
This would go inside the if(xRotation > 0) if-statement
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
If the problem is the jankiness when crouching/uncrouching then this should solve it ^
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
so this is how it works
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
So why don't you just say "yes" when I ask if it's about crouch/uncrouch??
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
If currentCrouchHeight is a float that goes between 0..1 gradually, then yes it looks right
If it's the height of your character then it won't work, or is inverted/wrong scaling
^need info

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
How are you spawning the bullet hole?
If it's a raycast, use raycastHit.normal
If a collision, use collision.normal
As transform.forward or Quaternion.LookRotation
these are the rotations
oh its with trigger,same?
what they said
How do you get the hit position currently?
Remove the MeshCollider btw
hella expensive for no reason 😆
On the bullet hole I mean
Just noticed the bullet has one too
Better use a capsule, sphere or box
Sphere FTW
Ok so use hit.normal
Also use hit.position for the position in Instantiate
yup hit is a variable that gives u all sorts of details about the collision
whats my mistake?
GetAxis does not return a bool
your logic makes no sense rn
A small problem is that if I also use instantiate it will ask me for the position of where it wants me to put the bullet and I will need the contact
what should i change?
unlike raycast it is more complicated
make a comparison on the float returned
== to compare
= to assign
or also > <
also >= <=
I dont know what you mean
just say my mistake pls
its basic math not even code related
hahahha
GetAxis returns a float
its a trigger so it doesnt have col.normal
do you know what a float is
lets say its 0.4f
Your first if statement is doing if(0.4f) ? ? ??
which ofc makes no sense
Again, you are also using a Raycast which returns hit, which is a RaycastHit, which has point and normal which you can use here
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
contactOffset
correct
so then what are you comparing that number against
no no, of the raycast, HIT is the contact the point the raycast hit something
yeah but i want to make it when the bullet hits the wall exxactly
hit.point
ohhh ok
but it will detect when the bullet exatly hit the wall?
but for decal facing correct you still need hit.normal
yes
like Osmal said
or will do it without matter that and generate the hole even if the bullet doesnt hit the wall
well when the raycast hits the wall..
I'm wondering, how is the bullet's trigger even being used? Seems like only raycast
Quaternion.LookRotation
thanksssss
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
indeed
but live and learn
thanks
🥲 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); } }
😖
i thought the main problem was contactOFfset.Equals
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
do you guys have a good tutorial for headbobbing with a rigidbody?
outside the box kinda programming 😛
dont think it matters if its rb or not..
just animate the camera holder
yeah i thought that it will detect when the hit collider (the gameobject colliding with the raycast) is hit with a bullet
i cant seem to find one that agrees with my code?
im very dumb
yea, ud be moving the camera up and down in its own container
Nah it's nonsense tbh
make an extra container for ur camera..
this shouldnt affect anything mostly
and bob the container instead
You are already detecting the bullet hit with the Physics.Raycast
You are overcomplicating it
if i move the camera thing about, nothing bad should happen right?
animate the object that holds the camera, not the camera itself
okay bet
That not will make detect when you shoot and you have a wall or gameobject? But it doesn't detect if the bullet collide generate the bullethole
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
this keeps happening?
can't have any errors in it
and make sure the name of the class matches the name of the script
is the script deriving from monobehaviour?
i believe?
usually when this happens to me I just have to invoke a recompilation event and then it will go away
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
so change something in a script, save it, undo it and save it agian
Again -_-
https://pastebin.com/TFFG0EK2 this is the code
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I believe I see the error
wwassup?
the script name does not match with the class name
or theres some logic errors.. and that will prevent it from saving correctly and you'll also get that error
So like in this image it's called HeadBobbing, but the class itself is HeadbobSystem
they need to equal each other
bingo
HeadBobSystem is not the same as HeadBobbing
okay 1 second then
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
it still doesnt seem to be working?
show screenshot
You never initialize InventoryManager.Instance
or something