#💻┃code-beginner
1 messages · Page 726 of 1
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
oh sorry
we don't need wall of texts here
so how do I use !code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
did you read any of it ?
why is it all commented out lol
nah that was an example for snippets , very small blocks like 5-6 lines
link the video as well as explaining what exactly is happening or not happening on your end
unity has a recorder package
how do I acces it ?
thats cumbersome for just capturing
use something like Snip or whatever is called on windows
didnt they add a recorder now ?
mine only does screenshots
w11 i think they added
ah I have w10
if you have Nvidia you can also use nvidia capture
or windows + G you get the recorder
screenshots will probably do for now while you figure it out.. more important you show the other stuff
what do you mean
where is the PlayerAnimationEvents
did you remove a screenshot?
alright then so whats supposed to happen again vs whats happening
so you should be in idle and be anle to jump with 2 animation jump and fall but the player starts as a falling animation or jump based on where it was under map or up and you cant jump, also the animation is blocked
okay so its stuck in a pose ?
are the transitions setup correctly
did you check it during runtime and seeing what animator is doing while its not working
you have to select gameobject with animator running to see the transitions working / params moving
yes I mean observing this during runtime while the gameobject is selected so you can see what happens from Air to Ground again
nothing its stuck
is the grounded check working right?
should is not the same as verified
have you seen the animator variable goes back to isGrounded?
no
so you cannot make assumptions its working, at least not fully
the problem is that the tutorial gets new scripts from 4 hour but a lot was made before so its hard to rewatch
isGrounded true
no exit time
then check if isGrounded is actually true
ok so thats where you start your search for debugging
as mentioned, you look at the animator and see what happens when you fall from jump
the Grounded is not checked
then you never go into grounded
there ya go, that tells you where the issue is
wait a minute
isGrounded = Physics2D.Raycast(transform.position, Vector2.down, groundCheckDistance, whatIsGround);
is that meant to be that way because raycast returns cast results
it should.. afaik Raycast has implicit cast on the collider to bool
yes Raycast is meant
how do I do that
oh right, you have to draw a debug ray
Debug.DrawRay(position, direction * distance, Color.green);
looks like it already has somewhat of an attempt
but its DrawLine
I dont see it tho
idk why it should been
which object has this script on it
Gizmos.DrawLine(transform.position, transform.position + new Vector3(0, -groundCheckDistance));
isnt the vector missing a coordinate
-groundCheckDist should in theory be the Vector2.down * dist
the Player
groundCheckDistance is declared as a float
yea inside Vector3
show it selected in the scene view with gizmos
usually something wrong you copied / missed something when following a video
yeah
those 1+ hours videos are the worst too
yiikes..its better watching those types of videos a couple of times before copying so you're kinda familiar with the process you will be doing
6hours is rough tho..too long man.. make the shit quick. get to the point lol
"Make Entire Minecraft in 7 hours"
he has a server so maybe but a little maybe he will be able to help
he is a 8k followers youtuber
not indian lol
sadly followers dont equate to quality
showing a quick feature or alternative approach to a problem is one thing..making those entire long session of "make x game in 5 hrs" or whatever is poor quality
easier game + start with small building blocks to learn
you will be able to make your own thing in no time
do you know even 5 % of what your current code does? or what some functions do ?
I learned a little C# from 12 hours video from CodeMonkey
I did C++ math
like Fibbonaci
bubble sort
so I know what things are quick
okay so at least you know the familiar cs concepts
yeah
unity is an API . so once you are comfortable with reading any API type with C# knowledge you're set.
the basics of unity concepts to know play into it too . What are gameobjects? components? lifecyle of them etc..
yeah most people want to jump to their personal project / the next big thing right away but that usually leads to failure
I like the b cart 3D videos but I am NOT ready for 3D lol
ik
3D is just as easy tbh
unity is already 3D engine, the only 2D components you been working with are physics
I was in some projects in Roblox same big idea and they failed
well keep at it, you will get to your big idea soon enough
Unreal is good on 3D but I dont like how it looks
its like a kidder version then Godot
really ? thats the whole gimmick is the quick AAA look
yeah the UI is weird
of buttons
can you give me some ideas for 2D games to make ?
like other then clicker
or flappy bird
or catch thing
2d factory game
the usual ones like you mentioned. A lot of those old school games, you know atari era
things where you can make a quick gameloop
thats not a simple game
yeah maybe I should go to GMTK 2025 games
the theme was loop
soo what I need a simple game
I am not making factorio lol
angry bird, flappy bird, simple platformer, breakout, any inifinte runner
what is breakout ?
those can be fun you can put your own spin to it once the initial game loop is done. Bonuses etc
and bouncy
yeah
Itch has good games in game jams other then that only horror
and they are the same
a night at a shop place
lol
lol I have an old project i was cleaning up and its quickie mart store owner sim lol occasionally you get robbed or ported into another world
cool
but ya it has become a tired genre since so meh
Itch should be the place for cool indie games but you can see only 20 that are popular
you need to dig for cool games
shame desura shut down
ya but we kinda steering offtopic of #💻┃code-beginner though..
whatever is on there is pretty old..
oh yeah
how do I debug collider collisions?
What information are you trying to find out
So this collider is set OnTrigger and while calling
OnTriggerEnter2D(){
}
I get no response back
(The checkmark is the player, does have a collider too)
it's related to the question I asked here #⚛️┃physics message
I can't explain the results I'm seeing at all and I'm not sure where to start figuring it out
depends how you're moving them too
and which one has rigidbody2d
I use rigidbody's linear velocity to move the enemy and player
they both have rigidbody
not rigidbody2d
since rigidbody2d refuses to have a collider with it
now that you mention rigidbody2d I might have screwed up lmao
The three commandments of OnTriggerEnter2D:
- Thou shalt have a 2D collider on both objects.
- Thou shalt tick
isTriggeron at least one of them. - Thou shalt be moving at least one of them via
Rigidbody2D
ah the 3rd commandment
were the colliders also 3D ? I dont see how else it would let you put a rigidbody on 2d cols
3D rigidbodies call 3D collision events on 3D colliders
no the colliders were 2d
I'll try again holon
im sure it wouldnt let you
I might have lapsed my judgement
I indeed tried to put 3d colliders thinking they were 2d lmao
yeah you prob want 2D then lol 3D colliders / rigidbody not work with OnTrigger2D
OnTrigger without 2D trollemoji
wat?
Try this package to make your overlap calls visible and see if they match up with what you expect:
https://github.com/vertxxyz/Vertx.Debugging
whats "in the insect"
Meta dosent have a Mac version for their desktop app so you can’t link your headset I’m asking if there’s any alternative ways
whats that got to do with unity coding question
There was nowhere else to put it
if its unity related somehow then #🥽┃virtual-reality
I think they meant "inspector"
ah ok
By which they probably actually meant "Editor"
But if your headset just isn't compatible with your OS, you aren't going to get far. You should consider getting an actual computer instead of a computer-shaped cellphone.
I presume this app exists for desktop vr and windows is the major platform for this
mac desktop gaming is dead or half dead and well linux is a second thought only some consider
ive only just started with unity, how come a public inputsystem doesnt show up in the editor for the script its in and then whines that not even enable is a real function?
using UnityEngine.InputSystem; // required
public class NewPlayerController : MonoBehaviour
{
public InputAction playerControlsNew;
void OnEnable()
{
playerControlsNew.enable();
}
case sensitive
what a pain in my ass this whole engine is, thank you for helping me
arm chips seem promising in growth for a decent market, about vr probably not any time yet unless you count vision, dropping games like cyberpunk for mac recently
hate to brake it to you but basically every programming lang that exists is like this, you were lazy or your IDE is not setup correctly to let you catch this simple error right away.
!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
• :question: Other/None
@subtle bronze ^ ensure its configured properly using the above
not fault of the engine lol
true but the amount of games that have native mac releases is super low and shows why apple are also trying to make their own version of proton
thanks. They don't match up at all and I have no idea why
it's detecting a ground collision here but ground is only the white stuff at the bottom
true true. I'm just being hopeful in a bigger market xD
what is?
the collisions list from Physics2D.OverlapCollider(bulletCollider, collisions);
is it set to ignore self / player and all that?
yes but why does it detect ground collision
are you talking about the green line on the character?
no the collider on the yellow shape
the function returns collider so print name of what is capturing
it does print the name of the white ground object, but why
they're not even close
they're obviously not touching
are you passing in the correct collider ?
it has to be, its type PolygonCollider and it's the only PolygonCollider I'm using rn
bulletCollider = GetComponent<PolygonCollider2D>();in Start()
if thats the only collider then should be fine..how many results are you returned with collisions.Count/Length
3, two of them are as expected
being the background and player
is this thing a moving object ?
collider background?
no it just appears, checks collision and disappears, but stays stationary
yeah I use that to remove bullets that leave the playing field
its not parented to mouse or anything
the collider?
yea
checks collision and disappears, but stays stationary
like rotation with mouse or any of that
it goes in the direction of the mouse yeah but it shouldn't be parented
it just gets a direction vector
its like an instantiated object ?
yep, its instantiated in the attack script, but it appears in the scene hierarchy on the top level so I don't think it's parented to it in any way
I certainly didn't parent it explicitly
i got it working but I definitely need to find the non existent artist in me to make it look good 😂 .
How do I make it so the particles live longer before being destroyed?
Hi sorry can i ask questions about game here?
about game code
ask your question
I’m making a 3D Unity game. It’s not my first, but I’m not very good yet, so I’m asking for help from more experienced people.
I want a “magnet” mechanic: the player has a sphere collider around them that detects objects (by tag or script). If they’re inside, the player attracts them. If I click the left mouse button, the effect inverts and the player repels them, like a real magnet.
I already made a script for attraction/repulsion (pasted at the end), but the result isn’t what I expected. I’d love some guidance — not full code from scratch, but maybe how to structure functions, or a simple customizable tutorial so I can learn for the future.
My idea:
Objects inside the trigger collider are attracted.
Left click repels them with opposite force.
Close to the player, they should orbit or stop on contact with a smaller inner collider, so they don’t push into the player or cause bugs (like flying away).
Maybe later I’ll add object switching or animations, but that’s secondary.
This is my concept. Any help would be greatly appreciated.
SCRIPT:
Attached file.
this
is big i know
go to particle system properties and change lifetime
ok this worked but the trail of smoke moves with the car. is there a way to make it so the particles de child themselves in the system
set particle system simulation space to world
Hmm so that makes it kinda stay still. Is there like a good resource for learning the particle system? There are way too many options in here to just goof around with .
https://streamable.com/k9spr5
I suppose you gotta decrese the lifetime again then
Free tutorials, courses, and guided pathways for mastering real-time 3D development skills to make video games, VR, AR, and more.
10 seconds is about how long it takes for the smoke from burning out takes
is there like a setting for a natural dispersion?
look at velocity over lifetime
in this example you'd want ur Duration to be 10 as well..
that way ur Lifetime of the particle has the time it needs to last for 10 sec
then for dispersion it a combo of color over lifetime -> alpha 0
size over lifetime -> towards zero etc
yea theres alot there to unpack.. but its not too bad (theres only a few that really matter all that much)
if ur doing it as a burnout u probably wouldnt need to be looping..
also nice to use the little gizmo 👇 (makes testing it alot easier)
how do I edit the shape of the curve lol\
like i can click it but the curve editor doesn't pop up
lol thanks
had it scrolle ddown
yup yup 👍
appreciate it!
np, and it just takes fiddling with it to learn.. you kinda get the hang of it as u work with it
for me the duration was the most confusing.. b/c u have the main duration.. and u have the start lifetime
which is a little different
but just for a simple example..
think of it like this
if ur Main Duration is 10
and you have it set to Loop
and ur particle Lifetime is 5..
then (2) sets of particles would exist within that (10) second timeframe
https://www.youtube.com/watch?v=0HKSvT2gcuk
https://www.youtube.com/watch?v=FEA1wTMJAR0
heres a couple of crash-course rundowns @languid pagoda
huh thats a pretty odd way to make it but thanks for clarifying for me!
im going to give those videos a watch
ya, i wouldnt make it like that.. but it kinda shows the difference
if u set ur start lifetime to 10.. it wouldnt make sense for ur main duration to be anything less
thats kinda the point i was trying to make
mine are ususally the same...
for a stable magnet mechaic i'd keep the player responsible only for detecting and applying forces
and let hte objects just be "magnetizable" rigidbodies.. use a normalized direction vector and scale that force by distance (clamped so its not too week far away or explosive up close).. switching between attraction and repulsion would be as simple as just inverting the force when input is pressed (-force)
to stop objects from clipping into the player you could add a smaller inner trigger zone where you either zero out their velocity once they enter... to make them stick or.. add a sideways force so they orbit..
handle all the phyics in FixedUpdate() and give the objects some drag so they dont fling uncontrollably.. start simple and work ur way up to the full mechanic
if it were me i'd just start with attraction.. get all the behaviour worked out.. (like the clipping and all that crap)
then it'd be easy enough to refactor it to add repulsion as well.. then if u wanna go all out u could use falloff Curves to refine how exactly it would feel..
what exactly does the mechanic do?
like whats the purpose of this mechanic? it might clear up some things
instead of Stay()
i'd use Enter and Exit
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Magnetizable"))
{
Rigidbody rb = other.attachedRigidbody;
if (rb != null && !magnetizedObjects.Contains(rb))
magnetizedObjects.Add(rb);
}
}
void OnTriggerExit(Collider other)
{
Rigidbody rb = other.attachedRigidbody;
if (rb != null) magnetizedObjects.Remove(rb);
}``` and I'd have a "Collection" of these objects
in the rest of the code you could loop thru the list applying the logic to each one
i rememeber not too long ago i did a 2D black-hole mechanic.. and i believe thats how i did it as well..
just adding the objects to a List<> and removing them once they exited
wdym "as an text object"
instead of an [serilzedField] priavte Tranform
i don't understand what you want to do..
if you already serializefield the other TMP_Text why do you want to write name like that
thx tomorrow i try if i have time and let you know
instead of an [serilzedField] private Tranform, basicly my highscore won't work with find and so i used gpt and it pointed me to [selized] tmp_pro.
[SerializeField] TMP_Text myText was correct
you just have to drag the text you want to change into it
the gameobject that holds it works too
code monkey alway says thst you should use [serlizeField] for string intead of find()
its often better to link it through the inspector, sure
the correlation is bad tho..
- you shouldn't ever want to use
Find()for anything unless you need to.. - you should assign mostly everything you can in the inspector when possible edit: until you get familiar with coding.. then you can assign things via code to exclude that step too, assigning things in the inspector makes it easier to change those things
- to do step 2 you should always lean on using
[SerializeField] privaterather than apublicfield
3a.publicfields are for fields you wan't to access publicly from elsewhere (other scripts)
also.. might wanna tighten up on your keyboard control as well..
coding is gonna be a bad time for you if you make typical spelling and grammar mistakes
3a I'd prefer a Method or Property over a public field ever, much better options too
gives you flexibility to invoke react to change or run some logic
also very true
you should probably be careful with that gpt shit
gpt can write some pretty advanced code
it wrote this multiline playable graph for me i just gotta feed the slip angles of the tires in, it can be used for lots of stuff and all I gotta do to use it drop it on an empty gameobject inside a canvas.
https://streamable.com/gvao61
ohh this old song and dance i heard hundreds of times
writing code isnt even the main issue
whats the issue?
i use it to write code I can probably write myself but cant be bothered doing
ie the graph
so, im new here, and i have a problem
too many to list..
ok
to say it doesn't have use is ignorant though
its a tool no different than visual studio or unity
let's keep the AI discussion where it belongs: https://discord.com/channels/489222168727519232/1352599815770341479
for the experienced, its super simple
but im working on a thirdpersongame and i nailed idle and running animations, but i have no idea wtf im doing, and for the life of me i cant get jumping/in air animations
ive tried many resources, and i cant get it to work
show relevant code
thank you
nowhere did i even say that.. but yes this is offtopic anyway
👇
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Bro can anyone help me
Oh I might have been doing that because I've been needing help so bad
@rich adder
As you were told, ask a question. Stop pestering.
if you needed help so urgently you'd actually ask the question in detail
Ok
I didn't know I'm not really used to being here it's just a simple question but okay
#💻┃unity-talk for some reason it's blocked for this when you try to say help me please
A simple question you have refused to ask for some odd reason.
lol true you been blabbin everything but the question
What are you talking about
What is your question?
So I made something on blender and I've been trying to figure out how to paste it in until unity project and I've been trying to switch for so many tutorials and nothing helps because it's so old
export to fbx -> drag into unity. done
First of all, not a coding question.
Secondly, export it as an FBX and drag it into Unity.
Okay cuz I might even use it differently but I couldn't find where I can ask the question the general doesn't allow you to say what I need which is stupid but yeah I guess I can go back and replace it and then do it again I'll grab my PC but thank you
you were typing just fine in UnityTalk...You probably tried to spam multiple messages and got bot blocked
Oh
next time open up with a question to your problem giving all the context and details in one message, no need to spam multiple "help" sentences, it does nobody any good just delays the help process..
Ok now could you explained export it as an FBX and drag it into Unity. Like how do you fully do that cuz I'm going on unity right now to my project
You can just look up how to export fbx from blender, surely you exported a model before if you used blender to any capacity ? there is nothing different to it..
Put into unity project window / assets folder, if you used a computer you know how to drag a file into a program..
How do you change a project name
you should google these basics things.
close project. Rename the folder. Add it to Unity hub once more.
delete any .csproj/.sln files to regenerate them to new name
I have no idea what you are talking about here..also again this is a code channel you should move it to approriate channel if its related to unity..
why does the capsule collider from a character controller module make the object slowly sink into the floor? also why does .Move choke up with 3 arguments when its a vector3? do people even use this garbage script? horrible to work with
you should not be adding a capsule collider to character controller
no i mean the one that it makes
then idk what you mean slowly sink into floor. there shouldn't be anything sinking it unless you coded something wrong
i figured it out, i tried setting up a rigidbody for the player bc i didnt think a character controller natively had movement
I good now thx
That command does not exist. Use =help to see all the commands.
Why don't these add up, like where did the remaining 7.35ms came from?
TryGetValue itself
oh :v
I really need hell wkth a game im making!
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Please I would greatly appreciate help! I have the whole game premise and stuff in there if you wanna help!
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
you should check this out.. https://learn.unity.com/course/3d-stealth-game-haunted-house
Me?
yes..
What do you keep adding a ".." to the end of your sentences?
just a habit.. from IRC times^^
Oh okau
Do you mind helping me a bit now?
just check the learn site with the ghost haunt game...
as ive read you try doing some stealth game reaching from point a to b.. with guards etc..
I can't im on mobile rn it's dying when I use mobile
Yeah
thats mostly what the ghost game is..
Now that I think of it, it was more like 2 years ago
Oh alr but like can you help with coding still like rn?
just check the site.. its a complete tutorial with codes etc..
I did I don't know what im looking at lol cuz my browser his bananas when I use my phone for no reason
then check out on a desktop environment..
I can't it's 4:00AM
then do it later^^..
Okay so, you just don't wanna help rn besides that okay
im not here to do your coding... i gave you a hint for what you search...
you were literally directed to a resource that covers most, if not all, of what you mentioned. you can also do the already mentioned learning portal learning. there is a tutorial there called John Lemon's Haunted Jaunt which covers many things too. Put In The Effort. and read the already linked to you #📖┃code-of-conduct
Is their some way that I make a new class that is inherited from a class that also is a component and the new class can also be a component. Can classes that inherit from class other than monobehaviour be used as components
yes because they are also components
that's the point of inheritance
MonoBehaviour isn't even Component
Component is Component, and stuff extending MonoBehaviour are also components because they inherit Component
So a class named component exist and monobehaviour and components (like rigidbody or collider) inherit from component class?
yes
How do I know where did the rest of the time ms came from? I know it came from the method call itself, but I wanna know the specific intensive part within it if possible :')
(this is also in deep profiling)
What's visible there adds up to 41 ms (and probably more in the part that's not shown) so in this case the cause is the sum of multiple small things instead of one big thing
well here is the entire stack, and it left with remaining 11.52ms
I think you can enable it showing GC alloc as well in the profiler which may also account for some of this time, not 100%
id make sure those optional things are enabled and then check again
the one on the side?
I think its in the call stacks dropdown button, someone correct me if wrong
You need to expand it more. There's something pretty heavy happening on your object getting activated and you're activating a lot of them too.
What kind of objects are you activating? What components do they have?
Also, because of the cropped screenshots, it's not clear, but do you have deep profiling enabled?
Already stated here
OK.
Another thing is that 900ms are coming from the editor, so might want to profile a build instead.
Or profile in the editor mode if you want to debug it.
Lanes and hitobjects
Respectively one dynamically pushes a mesh from vertices calculation in list, and the other is just 3D objects
Have been thinking about pooling the hitobjects but it's too tangled to do it atm
Well, whatever they're doing in Awake/Start/Enabled is probably quite heavy.
It's hard to say because of the editor noise. I'd suggest profiling a build.
Building it now
(must be dev build to support profiling)
whoops, that was close 😅
Overlooked the build settings
il2cpp may change perf a bit too but this should result in cleaner profiling
Are you implying I should switch to Mono, if I'm being pedantic?
well no because if you plan to use il2cpp for prod then why profile with mono?
i wouldnt change it and i presume a built wont take more than 20 mins anyway
ah crud it doesn't take mouse input
How do I simulate a touch input on a build?
@grand snow if you don't mind
Is this for mobile? If using input system you can have mouse input on your actions too or you need to add support for mouse explicitly for desktop.
Old input system makes touch work like mouse input but Input.touches is ofc only touch.
If the target platform is mobile, you're probably better of profiling on mobile anyway.
Yeah we're using the new one
Fair enough
profiling does work on mobile dev builds. android can be done over the network and usb, ios I think is network only.
Try adding mouse input to your actions if using them instead of enhanced touch.
Generally I would be against it because I would presume it would be hell to do, constantly having to build the entire thing, update through apk, connect debugger, make changes, repeat
(I've never done mobile debugging before)
Incremental builds should be pretty fast. And your environment should be configured to get into profiler in a minute.
At least, if you're serious about releasing the game on that platform.
mobile builds (especially with il2cpp) arent that fast
but to profile accurately its the only way
I don't mind waiting, it's just the cumbersome work to update the changes on the target device
If you built once already, a lot of stuff should be reused from the cache. Especially around assets and shader compilation, that is usually what's taking most of the time.
yea and with android build and run will install the app for you via adb and then open it
So no manual update cycles required?
you have to rebuild and update your app each time but it should build faster when little has changed
where can i find a developer or programmer, i want to commission for ai chatbot using 3d model in unity
!collab
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**
not here buddy
Couldn't create 'C:\Program Files\Unity 6000.0.54f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.unityanalytics/~UnityDirMonSyncFile~e0dd5c6f5e53c6a4bac68e47894e86c2~'
I knoy this is a common error but is there a FAQ for how to solve it ? (i downloaded unity from the archive rather than unity hub)
I also tried to set the editor folder to full control
hey everyone! can someone please help me fix a scipt?
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
@raw sonnet we can't help without info about your issue 😉
is ts code viable for camera switching https://pastebin.com/VzupdYFr
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.
can i send the error and the code?
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
well, does it work?
yes
then it's "viable", yes
alright thank you
update, I found this on build profiling
Well, 22k calls to an indexer is a lot, but it might also be the deep profiling mode that adds a lot of overhead to it.
this is definitely not adding up
It does. Self time means that it's the code inside the method itself that is taking all the time. Not one of the children in the profiler
I'd suggest putting several profiler markers in your UpdateMesh method to see what parts of it are heavy.
never heard of that
Good god yea 2 seconds is bad.
Markers will help increase the detail of this data
You can also use stopwatch to time async things
whats that
in deep profiling btw
Stopwatch is a type to let you measure time passed
Application.persistentDataPath how can I send this data on github?, also is it kept on build?
did anybody learn by making games with unity tutroials
yeah
following code monkey course, can someone explain why this doesnt work?
You most likely missed something
afaict you're trying to initialize getScoreMultiplier at a time when scoreMultiplier does not have a value yet
ahhh ok thx 👍
That's (probably going to be) a property - they've just missed a symbol
I noticed something weird about my projectile collider. When it's pointed to the right, it detects collision with the white ground object, and when it's pointed to the left it does not, regardless of it actually touching the ground or not. Anyone have any ideas why it would do that?
this thing is driving me crazy
I tried Collider2D.Overlap, Physics2D.OverlapCollider and PhysicsScene2d.OverlapCollider and they all give me the same results
Trying to make vs recognize the movement crap. ( ie :MonoBehaviour) It's not having it. Any advice
update visual studio editor package in your project
make sure unity has visual studio set to the external editor
otherwise follow the !ide guides
!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
• :question: Other/None
or does anyone have any ideas on how to debug the collisions beyond printing out the colliding object names?
or do I have to write my own collision logic somehow
the unity physics debugger will help you out and may be better incase you are using the gizmos incorrectly
thanks I'll have a look at that
is meshcollider the same as polygoncollider?
because it doesn't have an option for polygon colliders
yeah
That should be pretty good but if you are getting colissions that dont make sense then you probably did something wrong
more likely your gizmo is wrong than physics 2d
You can try things like using Debug.Break() to pause the game when a collision happens so you can check what state things are in
gizmo being the collider?
using break here right as the collisions are detected, and everything looks the way it should be, but it's still detecting the ground collision when pointed to the right side
the purple box is what vertx is showing me, so the colliders are definitely in the right location afaict
that is exactly my question. I can't explain the results I am seeing
do what i suggeted use Debug.Break() to pause the game when this bad collision happens so you can check the game state
I did, afaict the state is as it should be
Is the 3d mobile template good if i wanted to make something for android ? Or is 3d universal still the best
except for that collision
try greatly simplifying the collider to just have 4 verts or use another collider type.
might as well use 3d mobile, it surely uses urp anyway
Alright thanks
I'm using a normal CapsuleCollider2D now and it has the exact same issue
how is this even possible
i wonder if its how you move the object when you look left/right
it doesn't actually move, it gets instantiated with a rotation, checks collisions once, and then disappears
wait a minute, is it possible that it checks collision before rotation
hmm yea that sounds a bit sus
bullet = Instantiate(ultimateAttackPrefab, projectileSpawnerTransform.position, gunHandTransform.rotation); but it's instantiated with the rotation so that shouldn't happen right
do you change its parent or anything like that after?
no not at all
I just realized something weird
if i put Debug.Break(); in the line before instantiate, it will still show the projectile on the break
shouldnt it stop before that?
I think I just saw the projectile very briefly appear in a wrong rotation before correcting itself for like 1 frame and I'm trying to capture that but no luck
is there any way to make sure the rotation happens before anything else?
it pauses at the end of the frame
I fixed it in a really stupid way
instead of applying rotation in code I edited the sprite to be pre rotated and now it works
thanks for help rob
Is using "Resources.Load<GameObject>("PathToPrefab")" bad game design?
for some reason, it checked collision before rotation even when I apply a rotation in Awake()
depends on what are you doing exactly
I'd say that line by itself is not game design
it's probably a bad practice but it's unrelated to gamedesign, yeah
more about architecture
if it's a constant string, just.. use a serialized reference, this is arguably more work
dang i knew it had to do with rotation just couldnt put my finger on it..
it was really hard to tell
hah yea.. at least its finally fixed 😮💨
LerpAngle's values aren't in 360 range?
Vector2 Vel = (LastMousePos - UIMousemove.action.ReadValue<Vector2>()) * Time.deltaTime;
bool moving = UIMousemove.action.ReadValue<Vector2>() != LastMousePos;
float angle = Mathf.Atan2(Vel.x, -Vel.y) * Mathf.Rad2Deg;
var AngleSpeed = moving ? (MovingSpeed * Vel.sqrMagnitude) : StillSpeed;
currentAngle = Mathf.LerpAngle(currentAngle, moving ? angle : 45, Time.deltaTime * AngleSpeed);
Quaternion val = Quaternion.Euler(new Vector3(0, 0, currentAngle));
transform.rotation = val;
``` i've debugged angle and that appears to be in 360 range but not LerpAngle? (ps should velocity be divided or multipied by deltaTime)
multiplied
"Description
Same as Lerp but makes sure the values interpolate correctly when they wrap around 360 degrees.
This method returns the shortest path between the specified angles. This method wraps around values that are outside the range [-180, 180]. For example, LerpAngle(1.0f, 190.0f, 1.0f) returns -170.0f. To find the longest path use Lerp."
yeah i know that but the values's im getting aren't in that range. i'm getting values like -2834.33
what's your value for t?
Yo guys i need help so i have an plant and i want so see it from an diff ancle so i made an script and wenn i press E it gets me there but i want it so that it only works if i am near by any ideas?
A tool for sharing your source code with the world!
you can see it in the code?
distance check or overlap
overlap?
whats the actual value
yes like OverlapSphere to grab all colliders within a radius.
distance check could suffice too..
i have it 1440.
it has to be between 0 and 1
time.deltaTime isn't always between 0 - 1? and also remember i'm multiplying the value by velocity also.
make sure it ends up between 0 and 1
after multiplication
so...
Mathf.LerpAngle(currentAngle, moving ? angle : 45, Time.deltaTime * Mathf.Clamp01(AngleSpeed));
0 is the start point, 1 the end point
how am i intended to transform another game object? my code looks something like this and it says object reference not set to instance of an object
void Awake()
{
GameObject playerCamera = GameObject.Find("PlayerCam");
}
void Update()
{
playerCamera.transform.Rotate(0, 0, lookInput.y * mouseSens, Space.World);
}```
I might have got it https://paste.ofcode.org/TZP3ZcCTyE4M6emDvrFCUL
@grand snow
ok... that's just made it slow not actually fixing my problem.
ur storing playerCamera locally, not assigning the field
whatever is assigned, is only done within Awake()
you can think of t like a progress bar for your lerp, 0 is 0%, 1 is 100% aka the end of your lerp
what, in awake? am i supposed to have it in update? i thought finding it would be a massive performance hit if its done every frame
try making camera a serialized field and dragging in the camera object in the inspector
no you would just store it once in awake... no need to keep assigning in Update.
Anyway, its also better to just assign it in the inspector if its possible
you have to distinguish between Local variables and Fields, need to refresh on c# basics
Are you sampling animation curves for these? currentLaneStep.StartEaseX.Get(x)
and what is f_addLine(), a member func or a delegate?
@subtle bronze
void Awake(){
int myNumber = 3;}
void Method(){
myNumber = 2; // error because myNumber only exists in Awake
}```
that made it work, thank you
a method to push vertices data into a list (inefficient, I know)
void f_addLine(Vector3 start, Vector3 end)
{
// No AddRange here because the alloc overhead adds up
_Verts.Add(start);
_Verts.Add(end);
if (_Verts.Count > 2)
{
_Tris.Add(_Verts.Count - 4);
_Tris.Add(_Verts.Count - 2);
_Tris.Add(_Verts.Count - 3);
_Tris.Add(_Verts.Count - 2);
_Tris.Add(_Verts.Count - 1);
_Tris.Add(_Verts.Count - 3);
}
}
-# disclaimer I didn't wrote this so idk the numbers here
okay but do you understand why previously it didn't work ? thats more important
well apart from whatever that Add() stuff is, do you create these lists with a good size?
@rich adder thank you got it but now is there an problem so my player is blocking the view and i cant deaktivate him bc the camera is at the player so what could i do guys?
because once it got set in awake, no other void could see the value that awake set
make player transparent when camera is close?
I set the capacity to the lists
private static readonly List<Vector3> _Verts = new(2048);
private static readonly List<int> _Tris = new(1024);
i dont understand wdym? @silver fern
only because it was Local (you declared another camera in the method)
private GameObject playerCamera;
void Awake(){
playerCamera = GameObject.Find("PlayerCam");
}
void Update(){
playerCamera.transform.Rotate(0, 0, lookInput.y * mouseSens, Space.World);
}```
this would work..
but again, most times you want to assign inspector and avoid Find.
the player is blocking the view when the camera is right on the player?
Wait i show you
this is wronglerp btw
https://unity.huh.how/lerp/wrong-lerp
Applying lerp so that it produces smooth, imperfect movement towards a target value.
blocking it in what way ? what do you want to do change the angle or hide the player?
if latter just disable the mesh momentarily
move camera in front or make player invisible maybe
ok so what do you want to do..
Hide the player or change the angle
then you just reference the mesh component and disable it
no need to shut down entire gameobject for just visuals..
okay let me try it out
[SerializeField] Renderer r
r.enabled = isPlayerVisisble
Okay
So i made this but the codilor is still active but i think i deactivated it 🙁
A tool for sharing your source code with the world!
whats the issue with the collider
i cant click trouhg
u can really easily check the inspector and see if its enabled or not during playmode
btw why are these MBs instead of just their component/script name
public MonoBehaviour cameraScript;
should correspond to ur debug too..
ive done that before.. as a list... so i could enable / disable multiple scripts at one ;D
Yes let me check
shame on me.. lol
ohh.. but if they're all MBs/components they should still have .enable no ? or is the list for like a "generic" @rocky canyon
then its most likely some other issue besides that collider
use mp4 to have it embed in discord
I think you should be able to set the collider to ignore raycast
oh okay let me change it
thats why I've done it in the past... so i can access .enable on diff scripts
dont know their excuse tho
gotcha
for a single script... i wouldnt see why u wouldnt use the class type
just for clarity
(Component doesn't have enabled, it's from Behaviour/Renderer/Collider/Collider2D)
Urrmmm i cant keep up so what are my options now? xD
👀 👓 CLARITY
its probably not the collider thats the issue
oh yeah thats behaviour.. im buggin
thats where we at
hmm okay
good to bug from time to time
maybe some context
like the setup...
what are u trying to click thru..
and how
yea but how u clicking? is it a raycast? are u using the eventsystem?
ahh its a raycast i see now
debug the hit of the raycast and see whats blocking it
okay let me add it
hii
nav.. ur up
https://docs.unity3d.com/ScriptReference/Physics.Raycast.html you want to use the layerMask for it so it ignores the player
yea
yo gng, ive always been putting off learning c# because im scared that theres a massive difference if i watch a tut that uses smth like v2022, and im using unity 6 (v6000). is there acc a big diff in the coding part or am i just dumb?
is there an easy way to do that?
look at the link I posted
pretty much none
fr?
I made a class that inherit from rigidbody but i cant add it as component on dragging it to a gameobject it says the script needs to derive from monobehaviour.
damn, ive been putting it off since june
So i deactivate the player layer
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I JS WATCHED AN HOUR OF THIS "CODEMONKEY" TUT, THIS IS WAY COOLER! (i understood barely anything)
tyyy
codemonkey is more on the beginner -> novice side of things
so what should i use?
unity's learn
and if i only wanna learn 3d, should i still watch the 2d section or is it not important?
this is my suggestion
whats the difference?
okay i dont understand nothing anymore bro like what do i need to do @rich adder @silver fern @rocky canyon
2d and 3d work the same in terms of coding... u just use different components..
oh, makes sense
😅
create a layermask..
[SerializeField] LayerMask whatShouldRaycastHit;
real
plug that into the Raycast using the overload that takes the layermask
im js gonna do the unity one, ty!
put the player on a layer called Player or something. and exclude that from the layermask
I dont get it @rocky canyon
you know what a layermask is?
I got it guys @silver fern @rich adder @rocky canyon i really appricate it I THANK YOU ❤️
if its the correct project should be in this little Readme thing
or Tutorial folder check that
Trying to make vs recognize the movement crap. ( ie :MonoBehaviour) It's not having it. Any advice
Have already updated visual studio editor package, set vs to the external editor in unity, and followed the ide guides but still got the issue
!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
• :question: Other/None
its ide configuration time!
ye I've followed all of that but not managed to get it going
does serialize field actually prevent overwriting a value in code
no
its just saved to the scene/prefab and applied on load
after that you can do what you want to it, but only AFTER Awake (well when Awake is executed its safe)
this is really weird, I'm trying to change the value of a speed variable via a method but it keeps changing back to its original value when moving
Trying to make vs recognize the movement crap. ( ie :MonoBehaviour) It's not having it. Any advice
Have already updated visual studio editor package, set vs to the external editor in unity, and followed the ide guides but still got the issue
Have already configured as per the guide
animators can do this if the value is changed by an animation state
ohh
clearly not
I have done what the guide says to do, but yes that still claims to be compatable
go to edit > preferences, make sure visual studio is the editor selected and THEN press "regenerate solution"
remember that vs code is not the same as visual studio
thanks rob
I have just done this again, but still it hasn't worked
is your vs updated and has the unity tools feature added? Check in visual studio installer
yep have both installed
nun there
I'd really appreciate any other ideas 🙁
time to delete all sln and .csproj files in your project and try again
so delete those files and then regenerate them through unity?
yea it will re make them for you
Do u use abstract class or interface for state machines?
could someone help?
That didn't work. but I restarted pc and then it allowed me to reload the 2 fucked up projects at the top which has now fixed my problem. Thank you for help 🙂
After how many small games do you guys learn how to make a game without any help mostly
did you even extract the zip and open it thru the hub?i dont see any of these folders in there
Step 3.. <--- launching the project
it 💯 is there..
both ways work... extracting the zip download from the website..
or launching it thru the hub 👇
thanks you very much i made a fully functional script for literally what i've looking for if you wan't the code in dm to see if i did it right or i can change somethings or help for other questions just let me know. really thanks you. CatLick
its a zip?!
my bad 😔
!collab
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**
its either or.. #💻┃code-beginner message theres (two) ways to open it.. both work
nice 👍 glad u got it workin
Bug?
probaly with your project, not Unity
All I did is remove a script and add an empty one
Restarted, did the same thing, same error
If that prefab had the script you removed in it, then "all you did" was break your project
How is removing a script from a prefab breaking the project
If that's so that's bad
They are made to change
I took this to mean, from the project, not from the prefab
Yea I removed the prefab script that was an empty script and re-created a new empty one
Read the full console, rather than that tiny bit at the bottom
remove the prefab script
From where..
from the prefab
Ok, show a screenshot of the full console error
That isn't saved
Compilation can sometimes not finish or whatever, the fix is usually just to force another recompile
Is this code related? Is it something to do with code you've written? What's in the project? You need to provide more context.
If the animation of a sprite is larger than the sprite prefab that animates what would be the best way to have the animation sprites set to the same size as the prefab sprite? (animation results in it "expanding" size since they are different).
Guess I can pickup the prefab size and use it to resize the animation before playing in entry or so
yes, it is i Added a C# to HighscoreTable (Game object) with same name.
Drag in the highscoreEntryContainer , highscoreEntryTranforms and then the following (Text Mesh Pro UGUI) elements (PosText, scoreText and nameText.
Underneath the transform add Drag in the highscoreEntryContainer , highscoreEntryTranforms and then the following (Text Mesh Pro UGUI) elements (PosText, scoreText and nameText
Press play this is all i did, plus tryed to make the [Field] text objects in one c#, were as gpt had me make an c# for Tmp text ojbects
does it still happen after restarting unity
it happen late last night and today after i turn on my pc
what code do you have?
also i sent an bug report about it
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
A tool for sharing your source code with the world!
thx
np
at a glance this looks like it shouldn't crash
do you have the newest version of unity?
2021 and no it is 6.2 or 6.1
2021?
yes 2021.3.24
you're using a version from 4 years ago?
i have 6.1 in my OneDrive, 2023.2.16f1 in my program files, 2022.3.3f in my OneDrive, 2021.3.2f1 in my OneDrive
and which one are you using?
2021 for this project
try using 6.1 or 6.2
ok should i store it in my onedrive or nah use my portable hardrive
it fills it up with unity game engine files.
yeah on harddrive is probably easier
yeah don't put unity projects in onedrive
i have an hardrive with 1Tb
thats fine
random question what is called when you have like final fantasy 2.5d sprite but then during battle you see a detailed character model like you would see in an anime
I don't think that's really called anything in particular
i figured i though it would ahve a name but you know what i mean right
Does anyone have tips on some good baseline values for 2D Metroidvania-style movement? Right now my movement feels a bit off - I stay in the air too long and the speed doesn’t feel quite right. I’m just starting out, so I don’t have animations yet, but while testing and playing around it already feels off. Any advice would be appreciated!
(its just a capsule w/ rigid body and collider + camera)
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
idk how much of a coding question this is I imagine it has to be done via code but im not really sure, but how do racing games make it so the car engine sounds different when the camera is inside the car in first person view? I actually opened up the game files and there are not seperate sounds for inside vs outside view.
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
GameObject player;
Rigidbody2D rb;
[Header("Player States")]
public bool isGrounded = true;
public bool isHoldingKey = false;
[Header("Player Stats")]
public float moveSpeed = 3f;
public float jumpForce = 5f;
public float stoppingSpeed = 0.5f;
void Start()
{
player = this.gameObject;
rb = player.GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
if (Input.GetKey(KeyCode.A))
{
rb.AddForce(Vector2.left * 3f, ForceMode2D.Impulse);
}
if (Input.GetKey(KeyCode.D))
{
rb.AddForce(Vector2.right * 3f, ForceMode2D.Impulse);
}
if (Input.GetKey(KeyCode.A) == false && Input.GetKey(KeyCode.D) == false)
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x * stoppingSpeed, rb.linearVelocity.y);
}
Vector3 currentVelocity = rb.linearVelocity;
currentVelocity.x = Mathf.Clamp(currentVelocity.x, -moveSpeed, moveSpeed);
rb.linearVelocity = currentVelocity;
// Jump
if (Input.GetKey(KeyCode.Space) && isGrounded == true)
{
rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
isGrounded = false;
}
if (Input.GetKey(KeyCode.Space) == false && rb.linearVelocityY > 0)
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, rb.linearVelocity.y * stoppingSpeed);
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "ground")
{
isGrounded = true;
}
}
}```
^ this was the request right?
could be spatial audio
I dont really think so because colliders are solid, wouldn't none of the sound waves get in?
perhaps check out gmtk's platformer toolkit demo thing - you might need higher down gravity for example, or to tweak acceleration
stronger gravity could work ye
using audio effects probably
colliders are part of the physics system. the sound system may or may not care about the physics system, and there could also be extra processing
keep in mind sound waves don't exist in the game engine - that's not what spatial audio is
idk i haven't really touched it and when I did steam audio was what you had to use to use it in unity and it litteraly just did pathfinding and played the audio from the opened doorway for example instead of through the wall. I am very aware the sound waves dont exist in the game but my point was colliders would stop the sound from entering as that is the entire point of spatial audio or am I mistaken?
spatial audio is a concept, that's one possible implementation
spatial audio usually means you can hear from which direction a sound is coming
(also solid objects don't fully block sound irl)
can i ask something here?
hmm i guess I could look into an audio library to add some sort of effects on top of the existing clips that is probably the better idea
https://docs.unity3d.com/6000.0/Documentation/Manual/AudioMixerOverview.html you can apply some effects in the mixer
@languid pagoda in any case i think you should ask #🔊┃audio
it might be related to code but the folks there will know more about it
What do I need to learn on Unity Learn to get the Unity Professional certification?
everything
please don't crosspost
okey. sorry.
you are Meaning All of Path Way?
You don't get the certification from Unity Learn. To get the Professional cert you need several years of work experience
i have an odd error with building in Xcode. is this a good place to ask?
its for MacOS, im not porting to a mobile platform
#💻┃unity-talk then
thanks
hey so like how do you do ledge grabs in unity? I assume it has smth to do with raycasts but I'm not sure what the specifics are
break it down into steps that the character needs to execute and do the appropriate checks
https://streamable.com/n0me2i Well, my movement system has a small problem, every time it goes to a slope, and stays there, its vertical speed is not reset as it should be, causing it to have a residue of vertical speed, and when it leaves the slope, either from the sides or from above, it jumps by itself, simply by itself, could someone help me with this?
I'm using Kinematic Character Controller
show code
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
at no point do you appear to be resetting the vertical velocity, so unless the asset does that internally (which you'd have to consult its documentation and any relevant support channels to determine that) you should consider resetting the vertical velocity when it is on stable ground
The KCC engine already does this task automatically and, for some reason, it does not reset the Vertical when on slopes, only on flat terrain.
then either reset it manually like i suggested, or if you think this is a bug in the asset then you need to report it to the asset developer through whatever support channels they have
yo guys i need help i have an world text but i want it to be like XRAY so i can see it trouhg walls any ideas?
Why is this code making the rotation rotate in the shortest path?
void Update()
{
if (!needle) return;
float t = (maxRPM <= minRPM) ? 0f : Mathf.InverseLerp(minRPM, maxRPM, engine.engineRPM);
Quaternion target = Quaternion.Slerp(qMin, qMax, t);
current = target;
if (useWorldRotation) needle.rotation = current;
else needle.localRotation = current;
}
// Keep your original signature but return eulers derived from quaternion slerp
public Vector3 GetAngleFromRPM(float rpm)
{
float t = (maxRPM <= minRPM) ? 0f : Mathf.InverseLerp(minRPM, maxRPM, rpm);
return Quaternion.Slerp(qMin, qMax, t).eulerAngles;
}
i could try and take a guess and say the Lerp is incorrect or something? the min and max might be reversed
im not too good at scripting, i only started learning on tuesday
i hope its helpful though!
slerp always gives the shortest path
do they need to use Lerp instead?
rip what would be a good alternative?
animation tween I'd say
yuck
any other alternative?
I hate messing with those
lol
Thank you both for your intput tho none the less!
yo guys i need help i have an world text but i want it to be like XRAY so i can see it trouhg walls any ideas?
set the rotation to a variable thats a lerp from the starting value to the max value it my guess
then it shouldnt take the shortest path because the lerp variable is taking the longest path
that could work
what
I don't know how to do this, you will probably have to use a shader
okay but still thanks
Or you draw it in overlay UI which is the correct way to do this
how to make a game with multiplayer and also move with hands
still struggling with this if anyone has some suggestions, I tried making an animation but when I press play its doing a similar thing where it takes a shorter path on a different axis
Better question is why do you slerp but return as eulers
either case slerp will always rotate shortest anyway
so what is the alternative?
i think ive had success doing MoveTowards
looks like just using lerp like rebuild said is easiest
my switches did that originally.. or maybe it was a door.. (but they both use the same script)
it would rotate around backwards b/c the new angle was closer
I think the problem im having is in the editor I have to rotate it on 3 axis when I should really only have to on one too
theres options u can chose in the Animator to help sort that out too
try changing these options ^
oh yeah i tried that that didn't work either
im going to try movetwards
gud luck
private void Update()
{
float targetAngle = isOn ? max : min;
currentAngle = Mathf.MoveTowards(currentAngle, targetAngle, speed * Time.deltaTime);
ApplyRotation(currentAngle);
}
private void ApplyRotation(float _angle)
{
Vector3 euler = axis.normalized * _angle;
transform.localRotation = Quaternion.Euler(euler);
}``` this is the setup in the video ^ i sent
i have lots of things that require only a single axis to be rotated.. so i use the same script for everything that pivots..
Switches, Doors, Levers, Turntables, etc
i like doing it in code b/c i can easily reuse the code as well
ohh and i forgot to mention.. the axis is just a vector.. so i can easily swap which axis i want to use
0,1,0 1,0,0 or 0,0,1
I dont have the option, like yeah I should be able to rotate it on one axis, but when I use the rotate gizmo in unity it changes rotation on all 3 axis so I wrote this.
float t = Mathf.InverseLerp(minRPM, maxRPM, engine.engineRPM);
var tarX = Mathf.MoveTowards(qMin.x, qMax.x, t* Time.deltaTime);
var tarY = Mathf.MoveTowards(qMin.y, qMax.y, t * Time.deltaTime);
var tarZ = Mathf.MoveTowards(qMin.z, qMax.z, t* Time.deltaTime);
needle.localEulerAngles = new Vector3(tarX, tarY, tarZ);
not exactly sure what I did wrong but now the needle points out toward the driver.
theres a Vector3 MoveTowards if u wanna clean that up a bit 😉
i used the Mathf b/c i only use a single axis
Ill try that now but its probably going to result in same behavior.
I also tried needle.localRotation = Quaternion.Euler(new Vector3(tarX, tarY, tarZ));
ahh ur running into Gimbal lock situations
is it a speedo needle?
why would u need to do anything more than a single axis? (Z) ?
yep
idk why I need to but the 3d model is forcing me
i guess its a bad 3d model
but it looks good everything else about it is good so I am going to have to figure out a work around. I am about to just use a canvas ui and give it a digital dash 😂
if its a bad 3d model.. u can use EMPTY gameobjects and organize it inside of that..
making sure the EMPTY is orientated the correct way
and rotate the EMPTY instead of the model
Doesnt look like you need slerp here anyway. Just clamp and lerp between the new and old
angle^
https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Quaternion.AngleAxis.html
Can use that to get a rotation with the up being its local up
angles* the 3d model requires rotation on all 3 axis to rotate the way I need it to
we're talking about the speedometer here right
im uploading a video now even putting it in an empty gameobject results in weird rotation
looks like it's just rotating a single axis to me
and thats the way it should be but watch the end of the video in the inspector
changing the values on the inspector is eulers
this is why you use quaternions
if the pivot is correct you should not have a problem with angleaxis
I dont understand how I am meant to get the min/max angles if the inspector values arent relevant
also what axis should I rotate on if I cant look in the inspector to determine it
depends how it's all imported
ideally you import it y-up, z-forward
which in that case means angle 0 here is 4 on the speedometer, and y would be its rotational axis
I'd make yourself an editor executable script with angle axis and mess with those values instead of touching the inspector values
Well, this is under the assumption you're childing to the car that's also imported as z-forward. But in any case you know the range so all you need to do is find a min/max angle if it doesn't sit nicely
ohh i see.. i was thinking more along the lines that it was an Overlay.. or something like a HUD
ya those rotations are gonna be influenced by all its parent objects.. bit of a sticky situation
im trying the angle axis suggestion from Mao now and if that doesnt work it will be a UI Digital dash
probably could put a gameobject a parent of the dial.. (rotate it so the dial aligns with it's axis) and use local rotations for the "Dial"..
could eliminate that awkward rotations
from the video im guessing that "tach" object has some odd scaling/rotations and isn't zero'd out
tried it myself.. lmao i forgot how much of a pain it is to get smooth values when doing speedometers
needs moar smoothing!! 🫠
Its just an empty object
need clean values like 0,0,0
so if u rotate the Z.. then only the Z changes
i mean the gizmo makes it obvious..
that blue axis is not.. aligned with that needle 😅
ok i figured it out now
need zeroed out
adjust parent to make it visualy correct
then rotate the child
mmhmmm!
zero'd rotation
and 1,1,1 scaled
makes a happy 🌍
its always nice to test on things isolated too...
if ur working on scripting and logic.. best to use a simple object..
basic as can be.. zero rotation.. 1 scale.. no parents..
get the script working with that.. and u know the script is fine
does anyone have some good videos/papers on world generation with perlin noise? im trying to get into it but the stuff ive made so far doesnt involve erosion, octaves etc
and trying to implement them myself has resulted in not much
https://www.youtube.com/watch?v=wbpMiKiSKm8&list=PLFt_AvWsXl0eBW2EiBtl_sxmDtSgZBxB3
sebastian lague has a good series on it..
altho its not 💯 complete.. theres a few things he leaves out or assumes u know / find urself..
but overall its pretty decent
Creating even a modest world for a video game is a huge undertaking. However, games like Minecraft, Factorio, Terraria, Valheim and many more serve up fresh worlds with the click of a button. How do they do this? In this video, you’ll learn the inner workings of one of the foundational pillars of procedural world generation: Perlin Noise.
—
...
and heres another.. i haven't watched this one yet.. but the comments seem to give it praise
i think i kind of idled my way through most of them without paying attention, i guess ill have to go back and watch them and actually listen this time