#💻┃code-beginner
1 messages · Page 665 of 1
oh, a = a or b?
oh oh oh ye right
it's so when you say like "was the button pressed this frame"? we don't reset to false if you haven't consumed the previous button press yet
I'm not quite sure how to implement that. I was thinking of, in my Update(), to read the values and then look.x += ReadValue<Vector2>().x and then after my Replicate (when its consumed) I set look.x = 0;
is that inferior in any way?
that's the same thing I'm talking about (although why not just look += ReadValue<Vector2>()
but I'm referring to button inputs vs joystick
button vs value type thing?
joysticks vs buttons
does mouse delta count as a button or joystick
more analgous to joystick
how and when would you use this? If you pressed W but it hasnt moved the char yet? (might be a waste of time trying to explain it, mbmb)
if you're reading button inputs in Update but jumping in FixedUpdate, for example
using "wasPressedThisFrame"?
bool userWantsToJump = false;
void Update() {
userWantsToJump |= jumpAction.WasPressedThisFrame();
}
void FixedUpdate() {
if (userWantsToJump) {
Jump();
userWantsToJump = false;
}
}```
simple example
so userWantsToJump |= jumpAction.WasPressedThisFrame();
means, either he already wants to jump, or he asked to
I get it 😄
Well, new knowledge, new attempts. Let's hope it works this time, thank you very very much anyhow!
Filtering collision.Contacts
Mb for not being specific. Yes, codemonkey did a video on that topic, but it didn’t help me at all as with most of the Unity forums. I get something like this at the end, but it still didn’t do anything for me.
which object you placed the component on ?
Main Camera
are you certain this is the exact scene in your Build Settings? Also send the code not as screenshot so I can double check it
@wintry quarry So, I decided to Debug.Log() both when I was Updating (but not accumulating) and when the inputs where consumed. Here are the results. This is my earlier code running at 120 ticks/s (you were very right)
one last question, was this an issue or not? (yaw = x, pitch = y)
Shure bout the first one, also about unchecking DXGI flip model
@wintry quarry ILYILYILYILYILYILYILYILY ❤️ ❤️ ❤️ <3< 3< 3
activated free nitro just to send this
this is the smoothest it has EVER looked. Although I have to greed just a tad bit more
There is a BIG difference between Cinemachine Damping and not. Is this because my code sucks otherwise, or it is because thats how it is?
I mean, a damping of 0.05 (which is nothing I would assume) basically completely fixes it. But I'm afraid that there might still be something I'm fundamentally NOT understanding
where did you get the code btw ?
oh alright, looks slightly different from one I seen on CodeMonkey, which version of unity are you using btw ?
Yeah, Ive gone through at least 4 variations of TransparancyManager
can you show your camera inspector rq
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
how do i delete that bot emssage i sent
u cant
it will go away on its own eventually
i wanted to see how to do
a | b
😮
i wanted to see how to do
a | b
is that and or then?
no
did you make sure you had 0 transparency when exporting?
just tested your code and it worked for me..
Praetor can I ask you two more things (three including this)
Where i should check it?
seems like it is from your camera screenshot you sent here #💻┃code-beginner message
im saying did you change that recently , ie before the build ?
Nope
are you exporting a windowed build? ~~not fullscreen window, just "windowed" ~~(actually fullscreen windowed should be fine)
Yep, windowed. It completely empty on screenshot, but it rapidly flashes with black, and sometimes get stuck for 1-2 second on object that i needed. 2nd screenshot
Is it true that I should handle inputs in update and handle the action the inputs do in fixed update if said action is physics related?
fullscreen windowed gives me that (just fullscreen version of the same problem)
It depends on the details of what you're trying to do
so it does get transparent but when exactly does it not ? what are those images and what do you do to make them appear?
are these sprites or meshes btw..
Well let’s say I want do make it so when the player presses down space they jump, can I just put in fixed update
jump();
}```
Or do I have to do some shenanigans where the input is recorded in update then handled in fixed update
You definitely don't want to do GetButtonDown(“Jump”) in FixedUpdate
that will result in inconsitent responsiveness
Depending on the details of what is in the jump(); function, you may be able to do it all in Update
for example if it's just adding a one-time force with AddForce, you can do that in Update
Say it’s just an rb.addForce straight up
So when are times you need to handle it in fixedupdate?
ideally -best practice- with physics is to do everything in FixedUpdate
you can get away with doing one-off things in Update
for everything else physics related you must use FixedUpdate
input handling on the other hand usually needs to go into Update except things that are "continuous" like - taking the current joystick actuation, for example
they're kind of opposites.
Ok makes sense
So for something like sprint being held down I can just stick that in fixed update
yes usually
assuming you're using something like Input.GetButton(..) or equivalent
It's not visible in the recording, but every time I move my cursor, it flashes especially when I'm dragging it.
if you have time, you should read the help I got form Praetor above, it's really informing about how character manipulation works in at least 3d space, and probably 2d except for rotating methods*
starts here
vids need to be mp4 to embed, if its too big use streamble.com
well that was...uneventful..
kinda odd that it doesnt show it on recording though
gpu issue or something local ?
I am using the same code and moving the window around doesn't do anything weird to bg, (I'm also running it on windows ARM in VM)
From phone
Idk
yeah thats pretty strange...
- Restart Pc or something ?
- Try a brand new project and put a simple sprite ? ( try the 3D project/renderer )
- Nope, i have that problem for 2 days straight, so reboot wont help
- Thats already brand new project... But ill do 3d for test
Anyway, thanks for help
3d same result?
ye
what computer do you have? drivers up to date? (grasping at straws)
This singleton setup would destroy the script on the object, not the object itself right?
Supposing I make a new one
correct
Well, shit now I have to change it for all objects lol
Should not even come the case that 2 Instances can be on the same Scene together how I am doing it, but destroying just the script is pointless
IDE rename all instances should at least simplify it
for me it worked with HDR on, but you tried without HDR on in the renderer asset?
What I am doing is placing all the main, ddol items on the scene 0, and loading that one before anything else if it was not done already, then loading the actual scenes I want, but that's actually pretty annoying to do testing. So I was wondering how could I run directly on a specific scene with that setup
maybe use a prefab instead?
Just adds new layer of bugs to it...
well shit..
you might want [RuntimeInitializeOnLoad] stuff?
Probably what I should do, ye, but I kinda like just having it as an object in the scene, and not having to Instantiate it each time
Which stuff?
I meant the bootstrapper could be a prefab, also prefabs dont need to be instantiated only in code, you can also just drop one in any scene and it will do the bootstrap / DDOL warmup
you can use [RuntimeInitializeOnLoad] on a static function in order to run code before the first scene is run
Ye, I mean, I kinda like just having a single one that is not destroyed onload ever and it's not making the scene load a bunch of stuff a bunch of singleton stuff that is gonna be destroyed anyways
That way I am 100% sure it's the same object with the same values
So I would... load the scene 0 on the RunTimeInitializeOnLoad?
or perhaps a scene just full of your managers or whatever you prefer
the idea is in general you can run setup code that will run regardless of the scene your pulling up
Yeah, that would have worked if I have a gameManager on scene to even trigger with that
I guess I need to place that on executeAlways script lol
So... this should work? Even if there is no instance?
Yes, although for your needs you may be looking for beforesceneload?
Oh, ye, I think so
Oh actually
astrisk on that
so you probably want beforesceneload which runs this code before the first scene load, but that first scene load is still going to happen non additvely
so anything you want to preserve will need to be dontdestroyonload
unless im just wrong
Eveyrhing on scene 0 is ddol
easy then
Mmmm... so, beforeSceneLoad should... call the scene to be loaded, but this will always happen after the initial scene is loaded anyways right? Cause, well, it doesn't finish the frame until the first scene is loaded and the load call happens at the end of the frame, am I wrong?
I think doesn't matter at which point of the load I call that actually
if you call a scene load that isn't async in RuntimeInitializeOnLoadMethod(BeforeSceneLoad) that "injected" scene load should finish before the original one does
Ok, then I think scene 0 is getting a free frame somwhere, cause is doing weird stuff that wasn't doing before
a free frame?
Yeah, basically checks if there is anything on the current "level/scene" and since there is nothing cause it's not loaded yet, is basically considering it a finished scenario
Wasn't doing that before
how do I open this gizmos thing shown in the unity essentials pathway I have the Icon but idk how to open this
This is a channel for coding related questions
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Hey i'm trying to do a script that i can place on a gameobject (a container) with a tilemap, a grid, and the tiles i wanna place
using UnityEngine;
using UnityEngine.Tilemaps;
using UnityEngine.EventSystems;
public class RuntimeTilePainter : MonoBehaviour
{
[Header("Tilemap à peindre")]
public Tilemap tilemap;
[Header("Tile à placer")]
public TileBase tileToPlace;
[Header("Grille associée (parent de la Tilemap)")]
public Grid grid;
private bool paintingMode = false;
void Update()
{
if (!paintingMode) return;
if (Input.GetMouseButtonDown(0))
{
if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject()) return;
Vector3 worldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
worldPos.z = 0;
Vector3Int cellPos = tilemap.WorldToCell(worldPos);
Debug.Log($"Placing tile at {cellPos}");
tilemap.SetTile(cellPos, tileToPlace);
}
}
public void TogglePaintMode()
{
paintingMode = !paintingMode;
Debug.Log("Mode peinture : " + (paintingMode ? "ACTIVÉ" : "DÉSACTIVÉ"));
}
}
now with this i can place the script on the gameobject, and with a button using onclick i can call it to place my tiles, but i want to be able to choose multiple tiles, how should i do it ? thanks
Im Trying To Make A RayCast Script In 3D But I Want It To Be A Set Amount Of Length What Do I Change?
All It Dose Is Make A Recurring Line Until It Comes Into Contact With An Object
Have you tried changing the float value in the raycast?
5f
You can't use hit.distance in the else clause
It is undefined, because it hit nothing
quick question guys, so i am learning about OOP, i am going to implement it rn, but i got a question before i start. is OOP basically a script that holds my classes? the way i think of oop is that i make a script, put the classes i need, categorize and arrange them, and i could add variables outside of the classes, then i connect this OOP script to my other script, like lets say i have a script connected to a capsule called player, its still fresh. i first open this script. then i attach my oop script. then do i call the class that i want in update and thats it? if i am wrong please correct me, thank you
if i am missing anything please ping me
No, I don't think you understand OOP at all
Whatever you just described is completely unrelated to OOP
yeah i guessed so thats why i came to ask, i guess iw ill redo my research many thanks
https://www.youtube.com/watch?v=Jvss8fb1LdA
i was thinking of watching this series
This tutorial series is for those who are experienced with Unity's & C#'s basics and are willing to know about the principles of object-oriented programming.
All scripts and project contents used in the tutorial can be found on GitHub: https://github.com/danqzq/unity-principles-of-oop-tutorial
In this video I cover the two main aspects of OOP ...
OOP just means Object Oriented Programming. It's just a paradigm of organizing the code into classes (logical units that contain data and methods). It does not specifically address what type of classes and how you should use them.
so smth like this
and it contains the base, if i wanna link it i can basically call it from another script. after calling it i can assign the name and string and yeah
That is a class and hence OOP, yes. Then there is SOLID and such guidelines to figure what is good and what is bad way to practise OOP but that sure is a class
ah yeah so i am on the right path i guess at the moment, i was trying to explain this exact picture in my text, anyways thank you, iw ill be back in like tmr hopefully a better understanding
WHCould You Help Me Wit Something
PLzz
i am not the best but i can try a bit. i think @night raptor would be much better
Do not ask specific people for help. Just ask the question and someone might help
Could You right code to help me understand
pretty sure you need to change the 5f in there, its now set to 5 units only, make a serialized field name it like "maxDistance" and replace with the 5f, and try tweaking that to find what you need
hey, was wondering if games play better in builds or in the unity project window?
deltaTime was:0,1022872
UnityEngine.Debug:Log (object)
PredictedCharacterController:Update () (at Assets/__Scripts/PredictedCharacterController.cs:145)
im getting some very annoying frame lag, this for example, where delta time was 0.1 s
In builds, where there is no editor overhead
So The f in 5f means how long the raycast will be?
No, that indicates the number is a float
well, i guess we pray then
not the f, but the 5 might
Or profile it and fix the issue
I dont know what you mean
how do I do that?
I think thats too advanced, my game is literally just a CC. Wondering why it freezes on me
no 5f is float. just create a serialized field with float and call it maxdistance, and replace the 5f with maxdistance, and then tweak it as you like
`[SerializedField] float raycastLength = 5f; // Declare this at the top of your script outside of any methods
void Update()
{
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), out RaycastHit hitInfo, raycastLength))
{
Debug.Log("Hit Ground");
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.down) * hitInfo.distance, Color.red);
}
else
{
Debug.Log("Hit Nothing");
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.down) * raycastLength, Color.green);
}
}`
it should go along the lines of smth like this @timid salmon
Ty Sm
did it work?
Yess
Your acc A Life Saver🙏
Im New To Scripting And This Also Helps Me Understand Raycasts
Lengend
Let's say I have a struct that hold the base stats, another that holds the bonus/temporal ones and a other one that holds the ones comming just from items. Is there a quick way to just summ them all for a final value of each stat or manually one by one is the way?
Okay, I have a strange issue now. I'm building the game to simulate multiplayer with it + unity editor. However, the instance that doesn't open the server and only connects via client has altered rotational movement. Is this a common issue? What could cause it?
It has lowered Yaw, but increased Pitch. Super strange
You need a way to identify respective stats across all structs.
It could be an enum, a string or even an int. Then you need to store them in a way that you can fetch the stat by identifier.
How?
Which part?
I have a strange issue. I'm "building" an instance of the game to simulate multiplayer with "the build" + unity editor. However, the instance that doesn't open the server and only connects via client has altered rotational movement. Is this a common issue? What could cause it?
It has lowered Yaw, but increased Pitch. Super strange
But I Do Need To Ask What Is A [serialisedFeild]
Like how wold I set up an identifier
It could be as simple as a Dictionary<SomeTypeUsedToID, Value>
e.g. you have an enum with HitPoints, Damage, MoveSpeed, you can store those in the dict with their respective values. You then can provide a method for other classes to fetch the values from the dict by providing the identifier
serialize fields exposes the variable in the inspector, so you select your gameobject with the specific script in the scene and then edit that value in the inspector. It makes it easy to change (mostly) private values without hardcoding them inside the script
okay ty
hello i've been trying to make a simple incremental game by myself but i don't know how to code a text box to show the currency
but i don't know how to make a text with my currency appear
did you google it? this is like the simplest thing to put in the UI
yes but im having a hard time with coding it
then show the code and explain what isn't working
this is all i got 😦
well you need to start by getting your !IDE configured. then go actually pay attention to the relevant search results instead of staring blankly at your screen and expecting other people to make your game for you
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
I have a dout i have a cube i place camera inside i use raycast to spawn the object where the ray is hit how to do that please any one explain me
there's a setting so rays can hit backfaces iirc
Oh ok bro what is the solution bro
I cannot figure that
Anyone know about it please tell me
edit -> project settings -> physics
Ok
wording makes me believe it doesn't apply to primitives though
What i want to do there
Disabled everything
Player body only detect
Camera and player is same layer
nevermind, I was mistaken. Can't hit cube from the inside, applies only to mesh colliders.
I tryed it bro
If you were to make your cube a mesh collider, it'd work. Depends on your needs, cubes are much much faster to deal with in a sim than a mesh collider
It is also not working
Do you know how to slove that
Maybe depending on your needs you could flip your ray. Cast from cam pos + dir * max dist, flip dir
Okay, I'm here now. Yes, I can help you with that.
how to i get my AI to work i think the code is done but i have not a clue how nav mesh and stuff works
Do not crosspost
If you're wondering why I said that, it's because I was talking to someone else.
id love to know what that means
don't spam the same question over multiple channels
Hello, i want to ask about Profiler, does this channel help? If not, which channel should i ask?
okay then:
Semaphore.WaitforSignal is high every time I test shaders, from simple to complex shaders, are there any ways to improve this?
// Define shader variants
#pragma shader_feature _USE_CUSTOM_HDR
#pragma shader_feature _USE_CUSTOM_ADDTOAPB
#pragma shader_feature _USE_CUSTOM_GRAYSCALE
#pragma shader_feature _USE_PANUV_MAINTEX
#pragma shader_feature _USE_CUSTOMPANUV_MAINTEX
#pragma shader_feature _USE_FLIPBOOK
#pragma shader_feature _USE_SUB_TEX
#pragma shader_feature _USE_PANUV_SUBTEX
#pragma shader_feature _USE_DISSOLVE_TEX
#pragma shader_feature _USE_CUSTOM_DISSOLVE
#pragma shader_feature _USE_DISTORT_TEX
#pragma shader_feature _USE_MASK_TEX
#pragma shader_feature _USE_SOFTPARTICLE
i'm creating shader that containt variants shaders (sorry for my bad english), so i can disable/enable those variants by using [Toggle] on Properties, does this costly and affected render perfomance?
so in OOP, am i supposed to remove the "monobehaviour" or not? i think i read somewhere thats its preffered to remove it, but i would like to double check
https://discussions.unity.com/t/semaphore-waitforsignal-causing-performance-issues/775762
check this thread maybe
you don't have to, no
what do you mean by "in OOP"?
OOP means everything is an Object, Your class that inherits MB is still an Object and you're doing Object based
the only difference in Unity itself is MonoBehaviours are Components and must be on a gameobject to do anything
Looks like not just shader, then i have to check animations as well.
it also mentions In another thread I think that you can use GPU analyzer or something
Thanks, i will take a look 💪
goodluck 🫡 If I knew a bit more on profiling I'd help more lol I just profiled scripts so far
I need help with a music on/off toggle
i have most of it working, but i only want the toggle to show in the main menu scene
and the music player is present in all scenes, so when i load a new scene, the music player does not know what toggle to reference anymore
So i tried using GameObject.Find becuase i usually just make everything public and then drag in the inspector
why not just make a DDOL
however i keep getting the error "Cannot implicitly convert type 'UnityEnginge.GameObject' to 'MusicToggle'"
And i dont know why and can't find anything online
What is that
DontDestroyOnLoad
Oh
I thought then the music toggle will stay in other scenes tho
thats what im using for the musicplayer so it stays
currently
Like the button for turning music on and off
that should only exist in the main menu
yes show more of the setup
including screenshots of the components / objects in scene
void Start()
{
if (GameManager.notFirstTime)
{
n = Random.Range(0, 3);
PlaySong(n); }
else
{
}
mtoggle = GameObject.Find("MusicToggle");
}
This is in the music player script
the mtoggle = is throwing the error
yes because GameObject.Find returns a GameObject type
public class GameMusicPlayer : MonoBehaviour
{
public AudioSource song1;
public AudioSource song2;
public AudioSource song3;
MusicToggle mtoggle;
private int n;
private int newSong;
This is at the top of it
again, why does the music Player care about a toggle ?
it should just have a Toggle function that gets called from Toggler itself
the toggle contains the variable for if the volume should be on or not
using UnityEngine;
using UnityEngine.UI;
public class MusicToggle : MonoBehaviour
{
public Button musicToggle;
public Sprite spriteOff;
public Sprite spriteOn;
public bool musicOn = true;
public void ChangeSprite()
{
if (musicOn)
{
musicToggle.image.sprite = spriteOff;
musicOn = false;
}
else
{
musicToggle.image.sprite = spriteOn;
musicOn = true;
}
}
}
this is the music toggle script
Its a button
and the music player is trying to access the musicOn part
musicPlayer should be the one tracking the bool not the toggler
you have it backwards
yes the musicPlayer should not be coupled that tight to somethig external that controls it
what even is a GameObject type lol i get this issue everytime ive tried doing stuff like this
Just for future knowledge
gameobject
like how do i replace that line to get it to do what i want
The stuff in the hierarchy
its the basic type for the gameobject you see in the scene
so normally you would GetComponent on that to find any scripts / components on it
no musictogger, is MusicToggle type
Button just controls the visuals / sets bool
its on a gameobject
the type itself , aka the component is of MusicToggle type
Button is a component on a game object. So is MusicToggle.
so you would technically do
mtoggle = GameObject.Find("MusicToggle").GetComponent<MusicToggle>();
but in this case no reason for musicPlayer do find this thing at all
If I'm using a linked list to describe something in my game, does it mean that I've gone wrong somewhere
so is the canvas the original gameobject?
Everything in your hierarchy is a GameObject
Yes those are all GameObjects
GameObjects are basically "containers" for components
Button is a component, Canvas is a component etc.

is there a specific reason you're using a linked list instead of a normal List<T>?
but is it suggestvily better, incase i accidetly attach it to a object, so its better to remove it
The MonoBehaviour components on the GameObject are not GameObjects however
Hmm okay
what give you that assumption?
well I was trying to make a basic farming game, and some crops can be repeat harvested, and others one time only, so I thought a repeat harvest can just have a cycle in the list, and the one time crops have no loop
thats bad right
they both serve different purposes, if it doesnt need to be a component sure you can remove the MB inheritance @thick spoke
i had a little course, when i created a node script, he removed monobehaviour, i forgot the reason, but i thought it might relate to oop for some reason
but technically they are both Objects, nothing to do with OOP
ah i see, then i will prob keep it removed and maybe in the end add it if needed
thank you
probably because it doesnt need to be a component , aka be on a gameobject
i mean . . . if it works, it works, right? it definitely doesn't sound ideal but first priority is making something that works before focusing on making it good
same ig, i would prefer not to have my oop script on a gameobject
i guess
you are confusing POCOs here... as I said, everything you're doing in C# is object based..That includes monobehaviours
POCO is when you have ```cs
public class Foo {}
this is a Component
```cs
public class Foo : MonoBehaviour{}
Both are Objects
MonoBehaviour are also UnityEngine.Object but they are still Objects at the end of the day they just have extra logic unity implemented
so all you're doing is still OOP based
you put a integer in MB, guess what? thats still an Object inside another Object
Hmm okay another issue
that i dont understand at all yet
I turn the music off, i go back and forth between the game and the main menu
so then whats the issue?
This is before
And this is after i go back to the main menu
Another gamemusicplayer is being created, and this one is connected to the toggle
yes make a singleton
However music is still playing from the first, so this 2nd music player is useless
Whats that
its a programming pattern, it ensures only 1 type of this object should exist (if properly cleanedup)
check example here
https://unity.huh.how/references/singletons
because you're going back to the scene that has one ?
and both are DDOL so they live in the same DDOL scene
actually the toggle isnt' ddol rn
the toggle has nothing to do with anything here
yea i didn't think so
But anyway so going back to the scene creates all the game objects that are supposed to exist in it?
But one of them was never deleted, so its just creating it again, in addition to the one that wasn't deleted?
normally when you switch scenes all objects in other scene are deleted , then new one loads with new objects
because its a DDOL its not destroying the original one because DDOL scene objects dont get destroyed unless you explicitly tell it to
thats what a scene is , a collection of objects that should exist
if you have no way of check if ObjectA already exists and delete new one, it will create a copy as many times as you load that scene (cause of DDOL)
Ok cool so basically what i was saying i thought was happening
Ahh i swear ive seen people do this singleton thing on tutorials without explaining and i never understood what it did
so i just ignored it
yes so if you load old scene with a Singleton implemented properly (shown in link)
It will see "oh this already exist, delete new gameobject with this component we dont need"
Yep
Alr will lyk in 2 minutes if this works
Hmm not yet
but ima try to debug this myself real quick and if i dont know ill send
ok i got the singleton part of it working
but when i load back into the main menu, even tho the right musicplayer stays now, the toggle no longer does anything to the musicOn boolean
what you need to do is instead Find the singleton , thats why we made it a singleton for easy access from other scenes and their objects
so if you had a bool inside MusicPlayer for MusicOn and its public you could do for example
MusicPlayer.Instance.MusicOn = value
or better to make a method, public fields are kinda ugly
with a method you can put an event or something inside to notify if something changed, much neater than just changing a field value and not know about it
eg MusicPlayer.Instance.ToggleMusic(true)
in the toggle script?
yea methods are better
the toggle scripts only cares about calling the method on MusicPlayer for example.
the method itself is implemented in the MusicPlayer script
okay i can do that
but im a little confused even with my original implemtation still
what are you confused on ?
Im thinking
i guess i want to understand the core issue a bit more
because its a singleton, the toggle doesn't know how to access the musicplayer anymore?
when did MusicToggle ever touch MusicPlayer
you originally had it MusicPlayerlooking for MusicToggle for some reason
Ah yea this is wahts happening
yea cause im a beginner and didn't know the best way of implementing
So when i load back into the main menu]
yes you cannot link a component thats going to go into a DDOL scene
that would be called "Cross Scene Referencing" which cannot happen through a Serialized Field
thats why we now can simply get rid of the Field for it and just access it through the Singleton
okay, ill change to a method
Your music player should be a Singleton object as well or you ought to register your available scene music player after loading. Or as suggested, do not reference your music player etc
is there a way to fix this not using method implementation?
My musicplayer is the singleton object
not the toggle
wdym fix this without using method implementation
Like is there a way to fix this while still trying to access the singleton through the toggle
the method is so you can toggle musicON from toggler to MusicPlayer
You no longer need the music player reference then (on the button).
You'd simply access the music player through code using the instance field
Can you show an update of your !code for the music player toggle component?
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
SURE
oops caps lock
using UnityEngine;
using UnityEngine.UI;
public class MusicToggle : MonoBehaviour
{
public Button musicToggle;
public Sprite spriteOff;
public Sprite spriteOn;
public GameMusicPlayer musicplayer;
void Update()
{
if (musicplayer.musicOn)
{
musicToggle.image.sprite = spriteOn;
}
else
{
musicToggle.image.sprite = spriteOff;
}
}
public void ChangeSprite()
{
if (musicplayer.musicOn)
{
musicplayer.musicOn = false;
}
else
{
musicplayer.musicOn = true;
}
}
}
sorry im having long responses cause this is quite confusing for me
so im trying to think of a productive question first
you don't need musicplayer anymore
I guess im confused about, how to do i toggle a method in MusicPlayer without having to create a reference to it anwyay?
because now you have the singleton
crude example
public class MusicPlayer : MonoBehaviour
{
public static MusicPlayer Instance { get; private set; }
public bool IsMusicOn { get; private set; }
void Awake()
{
if (Instance != null)
{
Destroy(gameObject);
return;
}
Instance = this;
}
public void ToggleMusic(bool isOn)
{
IsMusicOn = isOn;
if(isOn)
{
//do stuff
}else
{
//do other stuff
}
}
}
public class MusicToggle : MonoBehaviour
{
public void ToggleMusic()
{
MusicPlayer.Instance.ToggleMusic(true);
}
}```
singletons are new to me so i dont understand how this fixes anything yet
how do i toggle the method in the singleton then?
Okay
makes a little more sense when i see it like that
if this is going to be a button you could potentially just make it a switch On/Off thing without passing a bool
howdy yall! What do i do when i get an ambiguity error when i only have one version of each script in my project? is it just Visual Studio Code freaking out?
show screenshot maybe ?
You'd get better suggestions by showing the actual error
ambiguity could be from another Unity class conflicting with your own or a System one etc.
namespaces are very important for that reason
Or conflicting directives (System Random vs Unity Random etc)
wait i just realized-
i cleaned up my hard drive to make space for a big download, and i accidentally put a bunch of files in my projects assets folder instead of my general game dev assets folder 😭
i just tabbed over to the games assets folder and saw a bunch of random shit including some backups of my scripts, lol
Still hella confused ngl sorry
I feel like i want to access the boolean in musicplayer from the toggle
becuase i want the toggle to display the right image based on that boolean
And i know you said i could just not use a boolean, but for the sake of my learning im sure ill have to access variables in singletons later in my life
Like idk how do you want me to have this code still working?
I know this doesnt make sense as code but like
i can make that method run but i still want that variable accessed somehow
Show your music player script.
Its hella long and has stuff thats not that relevant to this
ill just send the methods that matter
What is musicplayer
Just send the Instance reference field
.. or the variables
using UnityEngine;
using System.Collections;
using Mono.Cecil.Cil;
public class GameMusicPlayer : MonoBehaviour
{
public AudioSource song1;
public AudioSource song2;
public AudioSource song3;
public bool musicOn = true;
public static GameMusicPlayer instance;
private int n;
private int newSong;
...
public void ToggleMusic()
{
if (musicOn)
{
song1.volume = 0.1f;
song2.volume = 0.1f;
song3.volume = 0.1f;
}
else
{
song1.volume = 0;
song2.volume = 0;
song3.volume = 0;
}
}
.....
void Awake()
{
if (instance != null)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(this.gameObject);
instance = this;
}
}
GameMusicPlayer.Instance.musicOn
It was a reference to the musicplayer but i deleted it cause they said i dont need it anymore
but then im like Idk how to get that variable still
without it
So you would replace it with the static variable that references your instance of GameMusicPlayer
It should be in this pattern to be a Singleton:cs ClassName.Instance.fieldNamewhere in your case you should have had something similar tocs MusicPlayer.Instance.IsOn = ...
i mean yeah you have to use it
Yeah, you're missing all of the other details to be a Singleton
I suggest you check back on this message #💻┃code-beginner message
Oh lol mb
damn i got the whole server helping me with this easy ass shit 😭
this is like my first month of unity
YOOOOO TS WORK NOW
So.. you need to do something with that.. like suggested by the IDE, assign it something or whatever
THANK U ALL LMAOOO
I think most of my confusion for the last 10 minutes has been that
i didn't know i could do that
ye thats the appeal
Very grateful
the rough idea is that because we're ensuring that only 1 instance of GameMusicPlayer exists, we don't have to go around trying to find it
now just gotta make an online highscore leaderboard and my games done
How do i fix this the whole word just screen tears glitches jitters etc
I started using unity yesterday
its usually b/c your camera is moving in update but ur character is moving in fixed update..
Update is every frame.. Fixed Update runs on the physics tick (50fps) default..
its a sync problem..
thats what i said...
no worries
you can search google.. its a very common issue with multiple fixes
cant say which one is quite right for you..
i have been searching since yesterday
isnt there another fix i saw this vid and tried what he done but it didnt work
The third part of my Rigidbody FPS Controller series. In this video, I covered slope handling, fixing the weird jitter, and improving the ground detection. In the next one, we will start working on the wallrunning *yay. Make sure to subscribe so you don't miss it :)
Discord Server Invite: https://discord.gg/6ASySnPVXB
GitHub Repository: https:/...
i saw that vid too
this looks like jibrish to me since i started yesterday 😭
https://discussions.unity.com/t/character-controller-jittering-while-moving/257889/2
ya, i understand that..
this may be a problem u need to sort out after becoming a bit more familiar and comfortable with unity and coding
btw i dont think the vid is showing it but the issue isnt really like a jitter its like screen tearing
if its screen tearing it could possibly be VSync issue
ye the vid doesnt show it
this vid looks cooked
how do i fix it
ngl
ya, lol i noticed that after i posted it..
prob vsync is causing it cause in my view the screen is tearing
this
or another option is to cap ur framerate
turning off the vsync count didnt change anything
i even tried to put the movement part in update instead of fixed update same issue
🤔 hmmm
I feel like its smthn else maybe thats why the vids dont work
u try building it to see if its in the build as well
Hello
hello there
Ye its in build as well
why doesnt it show in the video
wth
on my screen the whole screen is breaking
like idk how to explain it
its tearing and it looks like the world is a titkok filter
the thing one waves one
screen tearing is common when the framerate is above the monitor refresh rate, not unique to unity: https://www.displayninja.com/what-is-screen-tearing/
Can u test my game and see if u get it too
I already did
this right?
Yes. Is that on the correct quality setting thats the default for the build target?
wdym
First day in unity btw 😭
Check you changed it on the default quality level for the platform (so its actually doing what you want)
otherwise it will be using a different quality with different settings
mine looks like this
double check its set in "Ultra" then
I've had windows be stupid with games before. Windowed and fullscreen windowed games dont tear but exclusive fullscreen will. Check player settings for what mode its using.
player settings?
Im sorry for being dumb its js that its my first day using unity
and i have had to spend my whole time trying to fix the issue instead of learning unity 😭
I dont think its your fault but learning about this stuff helps in the long run!
vsync should be fixing this though so ideally we would verify the fps of the game in the build
tearing happens when the framerate is too high so as your display "shows" the new frame, the data keeps changing causing visual tears in the image.
vsync should fix it as it caps the framerate to the monitor refresh rate (e.g. 60 hz)
where do i enable vsync
dont i already have it enabled
the vsync count
i have that
but it still doesnt work
not only that but i have tried other peoples codes and theirs work but mine doesnt
yea which is why this is strange and i wanted you to verify it was using the correct quality level in a build.
(you want it to be ON)
is vsync set to "every vblank"?
yes
that affects game builds. The editor game window has its own setting:
@copper jasper ^
show stats, what is the fps?
HA clearly its not on
You've got a fast monitor
yea something is bugged, restart the editor maybe?
60hz 😭
alr ima try that
welcome to development, shit breaks randomly
ye 😭
I miss working on roblox now
but its filled with idiots that play trash games over good games
its a jump from that to a full game engine
Still not working after restarting it
fps isnt being capped
You dont have any code changing Application.targetFrameRate do you?
nope
like this?
using UnityEngine;
public class FPS : MonoBehaviour
{
void Awake()
{
Application.targetFrameRate = (int)Screen.currentResolution.refreshRateRatio.value;
QualitySettings.vSyncCount = 1;
}
}
yes EXACTLY THAT
didnt work 😄
oh do i make a game object for
i js made the script only XD
oopsies
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Think you need to follow some tutorials
ye 😄
some core knowledge missing there! dont worry about this tearing stuff for now
I thought it would be easy cause i was a master at roblox
In a game engine you have to do everything but means you can do everything!
ofc there are pre made things you can add and use but at its base unity can do a lot but needs you to do it
how many years have u been on unity
@grand snow So a lil issue even the frame limmiter didnt work
I added the script into a empty object
and still got 1k fps
try clicking the vsync button here https://europe1.discourse-cdn.com/unity/original/4X/1/9/1/191596e9e4b989cb04a83789bf4a22627275a5a0.png
Already done that
are you checking the fps here during play mode? https://i.sstatic.net/sKnxl.png
yep
pretty evident that its correct cause im getting screen tearing
YES IT FINNALY WORKED
But now my camera is broken...
and the screen tearing is not fixed
I wanna quit unity 😭
typical roblox dev
so enabling this stops my fps cap from working but then when it does work my whole game breaks
you should prefer vsync over changing target frame rate (except on mobile platforms where vsync does nothing)
neither fixes anything
and target frame js makes it worse
I dont get it why cant it just work
it should when capping my fps to 60 but still doesnt
at this rate i dont even know what the issue is
is my code wrong or smthn
void HandleLook()
{
// Get mouse input and apply sensitivity and frame-rate independence
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
// Update rotation values based on mouse movement
xRotation -= mouseY; // Subtract because Unity's rotation is inverted
xRotation = Mathf.Clamp(xRotation, -maxX, maxX); // Limits looking left/right
camTransform.localRotation = Quaternion.Euler(xRotation, 0f, 0f); // Camera transform
transform.Rotate(Vector3.up * mouseX); // The players transform
}
without deltatime the cam is snappy and broken
You don't need delta time as mouse input is already a rate
why are you multiplying mouse movement with deltaTime?
decrease mouse sensitivity
and as always i still have screen tearing
no like its slow but teleports it just snaps into place
ima record it 1 sec
and the video isnt showing all of the screen tearing
looks wayyy worse on my screen
If you're moving your character with physics but moving the camera outside of physics, you'll get some strange snapping etc
but i wasnt even walking
and it wasnt happening when i had 1k fps
and was using delta time
dont parent camera to rigidbody
The mistake here is that you are not using the inputs as they should be.
tried that before
wdym
If you want to see how you have your inputs configured?
In the code
In my case I use the horizontal and vertical and putting the speed variable and from there I put the time.deltatime and everything works out fine.
correct.
im gonna loose my mind
using 60fps doesnt fix the tearing
the cam is broken now
everything is getting worse instead of being fixed
i had so much planned today like learning unity but i spent the whole day tryna fix this bs
that happens when your learning 🤔
there may be a chance u have to scrap and rebuild complete things
It's better that you use that like I do so you won't have teleports anymore because yes
I js wanna fix this
i think ur in over ur head already.. and need to step back and learn/experiment some more
the screen tearing issue needs to be sorted out first..
if it were me i'd build a new project.. and i'd try simple animations. maybe even import a mp4 and use the VideoPlayer component.. see if the screen tearing is still ther...
it doesnt even make sense cause 60fps cap and vsync should fix the tearing
Well, use the one I told you and it will be fixed.
where
Put the horizontal and vertical inputs first
Just a reminder that you wouldn't want to include delta time as the mouse delta per frame is already relative to time (an issue with brackeys and a bunch of older tutorials)
For rotation
Is my cam script even correct
void HandleLook()
{
// Get mouse input and apply sensitivity and frame-rate independence
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
// Update rotation values based on mouse movement
xRotation -= mouseY; // Subtract because Unity's rotation is inverted
xRotation = Mathf.Clamp(xRotation, -maxX, maxX); // Limits looking left/right
camTransform.localRotation = Quaternion.Euler(xRotation, 0f, 0f); // Camera transform
transform.Rotate(Vector3.up * mouseX); // The players transform
}
can u js fix it i cant do nothing at this rate
like its been a whole day and my dumb ah still hasnt fixed it
We don’t do that here
X rotation is a float right?
ye
float xRotation = 0f; // Horizontal rotation (looking up/down)
wanna see my whole code to see how crap it is 😄
You won’t gain much from beating yourself up like that
It would seem you've got some weird camera jittering going on rather than screen tearing.
Code is hard, physics is hard, learning is hard
but its been a day
also don't do transform on a rigidbody, you are doing that in HandleLook()
and i want to atleast do the basics before school starts again i have mocks 😭
you dont learn a new skill in 1 day
its been a day
5-year Noob laughin his ass off over here
You’ve done a lot in a day
but i have years in roblox it should have been easy and nothing i do works even when i took other peoples code to test if it would work
no it shouldnt be easy lol
You lack the understanding on how to use their code or what it even does
u cant make this stuff up
but now that im using a 60 fps cap the cam is broken and i have tearing so computer wise it doesnt make sense
capping my fps 60 should work
it's highly highly likely because you're doing transform on the rigidbody
i had similar camera issues because of that
test an animation or video like i mentioned earlier
Why
but i need that so that i can make the player face where the cam is
use the physics rotation, like MoveRotation()
tell the physics of Unity to rotate it not transform
also rn i can only look up and down not only that but since i unparented the camera from the player its not following the player
This?
rb.MoveRotation(rb.rotation * Quaternion.Euler(0f, mouseX, 0f));
but i can only look up and down
should i make the camera child of the player
or leave it outside
I have the camera separately
and the camera's position is tied to an empty gameobject on the player
HOLD UP I FIXED THE SCREEN TEARING
I stopped using the max fps thing
and js used this again
Only jitters left
well moving my cam fast ends up creating wave like effects
and how's the camera being moved?
well for the left and right its working cause i placed the cam under the player capsule
and up and down is this
void HandleLook()
{
// Get mouse input and apply sensitivity and frame-rate independence
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
// Update rotation values based on mouse movement
xRotation -= mouseY; // Subtract because Unity's rotation is inverted
xRotation = Mathf.Clamp(xRotation, -maxX, maxX); // Limits looking left/right
camTransform.localRotation = Quaternion.Euler(xRotation, 0f, 0f); // Camera transform
rb.MoveRotation(rb.rotation * Quaternion.Euler(0f, mouseX, 0f));
}
did u see
rn its working wayyy better
but theres tiny jitters
and if i move cam around fast then the thing tears
like wave effect on tiktok
so the jitters is probably because of it being a child of the player's capsule (or rigidbody in this case)
but then it doesnt go left and right and doesnt follow the char
well you'd place an empty gameobject on the player for the camera to follow using a following script i imagine
i myself use cinemachine so i don't have to worry about the following
I made the cam follow the player like this
camTransform.localPosition = transform.localPosition;
But still no left and right
what's confusing me in your HandleLook() is that you're telling yourself that xRotation is limiting left/right, when in fact it's handling up/down
and you don't have anything in there that specifically handles left/right movement
well, specifically the xRotation = Mathf.Clamp(xRotation, -90f, 90f); part
that one is what prevents you from looking too up or down, or at least it should be
im js as confused as u are
but that's besides the point, you don't have anything that handles left/right
I made a new script
using UnityEngine;
public class CamMover : MonoBehaviour
{
public Transform CamPosition;
// Update is called once per frame
void Update()
{
transform.localPosition = CamPosition.localPosition;
transform.localRotation = CamPosition.localRotation;
}
}
Then i made a cam positon empty object in the player
moved the cam holder out of the player
don't put it in Update, it's FixedUpdate
But the looking on this is messed up
void HandleLook()
{
// Get mouse input and apply sensitivity and frame-rate independence
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
// Update rotation values based on mouse movement
xRotation -= mouseY; // Subtract because Unity's rotation is inverted
xRotation = Mathf.Clamp(xRotation, -maxX, maxX); // Limits looking left/right
yRotation -= mouseY; // Subtract because Unity's rotation is inverted
yRotation = Mathf.Clamp(xRotation, -maxX, maxX); // Limits looking left/right
camTransform.localRotation = Quaternion.Euler(xRotation, yRotation, 0f); // Camera transform
rb.MoveRotation(rb.rotation * Quaternion.Euler(0f, mouseX, 0f));
camTransform.localPosition = transform.localPosition;
}
because you're following a physics object
my cam direction is messed up though
lemme record it 1 sec
always goes in the same direction
why do you have yRotation calculated like that?
like what
that's not how you calculate yRotation
Why is your left/right rotation controlled by the mouse up/down? And why is yRotation created by clamping the X rotation?
Idk man im loosing my mind i went from trying to fix screen tearing to now this and more
When you're rotating, you give it an axis to rotate about. Imagine a stick stabbed through the object at that axis, then you grip the pole and spin it in place.
Rotating about the X axis is up/down motion for the object, and rotating about the Y axis is left/right
(rotating about the Z axis is rolling sideways)
I have no clue what allat means
first day in unity
i just want to fix it so i can learn properly
i dont get it
do you have a pencil?
Please read the messages again
I explained how in both words and pictures
X is red
it's not that x is up and down
it's that you're moving it about the x axis
Y is green
you could also just take a break
do you think you're going to accomplish much with your brain being fried, by your own words
Then we don't have time to keep repeating the explanation until you decide to read it
like literally take a walk for 15 minutes
so X axis is up/down and Y axis is left/right
but what i dont get is why is my camera moving like this
To be more accurate, X axis is Pitch, Y axis is Yaw
Becase you're telling it to do so
You've set yRotation to the same value as xRotation
yeah that's not what digi said
dont u mean cause i was doing xRotation -= mouseY; for both
okay what does the line after this look like
I mean, that was a problem
but you weren't even using that value for yRotation before you just overwrote it the very next line
So it didn't matter anyway
Probably
well you don't want to CLAMP it, because that would lock you from doing a 360 spin
ye XD
you SHOULD limit it somehow though
but you definitely shouldn't set the yRotation to the clamped value of the X rotation variable
so that worked but my movement is messed up
ima add a cube to see my direction rq
ye im blind
is this wrong then
using UnityEngine;
public class CamMover : MonoBehaviour
{
public Transform CamPosition;
// Update is called once per frame
void FixedUpdate()
{
transform.localPosition = CamPosition.localPosition;
transform.localRotation = CamPosition.localRotation;
}
}
ignore that for now, focus on your movement
def wrong
so now show what the camera look script looks like
void HandleLook()
{
// Get mouse input and apply sensitivity and frame-rate independence
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
// Update rotation values based on mouse movement
xRotation -= mouseY; // Subtract because Unity's rotation is inverted
xRotation = Mathf.Clamp(xRotation, -maxX, maxX); // Limits looking left/right
yRotation -= mouseX; // Subtract because Unity's rotation is inverted
camTransform.localRotation = Quaternion.Euler(xRotation, yRotation, 0f); // Camera transform
rb.MoveRotation(rb.rotation * Quaternion.Euler(0f, mouseX, 0f));
camTransform.localPosition = transform.localPosition;
}
so you still have the issue of yRotation being calculated incorrectly
no, nothing has to be removed, just one little thing has to be changed
this works better i think
yRotation = mouseY;
nope
but it looks correct
only issue i see is the cam is not going where the cam postion object is
it looks correct but does it work correctly?
- Make camera child object of player at position you want.
- When move mouse X, rotate player about Y-axis.
- When move mouse Y, rotate camera object about X-axis, clamped if you want it to be
so i make the cam a child of the player
Or the virtualCamera if you're using Cinemachine but it doesn't look like you are
naw cinemachine would've solved the following without anything extra
I wish there was a vector3.side struct. My OCD doesn't like just using Vector3.right or left with the HorizontalInput lol:
What would a "Vector3.side" even mean
What value would it hold?
I have never been so confused in my life
Which side?
Everything except the three steps I gave you is unnecessary and should be removed
It's just weird to put vector3.right and the player can move left and right
Because left is negative right
Are the boxesoverlapping?
I think you can just use a single translate without the if statement
vector3.right does not exist for player movement or any movement. It just exists to be right of 0,0,0
How do i fix the jitter
Yeah I could just have one. This movement finally clicked for me and I thought it was weird lol
Are you moving the camera in LateUpdate
Fix that
lemme try again
didnt fix it
oops
Im so happy that atleast the tearing is fixed
well now you've come full circle back to the jitter we were thinkin was the original issue
Just wanna say, the learning does get easier. Can’t be expecting magic in a single day but the early part of learning this stuff is the hardest
Takes a lot of effort to force yourself to troubleshoot with strangers online for so long, glad your making progress
js gotta fix the annoying jitter then im done
ya, it takes alot of effort for the strangers to help for so long when they say things like
"i wanna quit Unity" and "just fix this for me"... sooo props to you and the other guys as well 👍
How do i fix this 😭😭😭
I do not like you and I do not think you’ve provided nearly enough help to justify such a elitist attitude. This comment helps nobody.
okie doke.. i take my props back..
so anyone know how to fix it 😄
ok this is a long shot, but this might just be your monitor
do you have anywhere else to try your game?
maybe you could try limiting your fps again
bet
only works when i turn this off
I also got someone to test it and they got the same issue @keen cargo
Anyone by chance know why my prefab pizza is going backwards when I instantiate it?
Script attached to pizza prefab
public class MoveForward : MonoBehaviour
{
[SerializeField] float speed = 40.0f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
}
Instantiate on playercontroller script:
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Instantiate(projectilePrefab, transform.position, projectilePrefab.transform.rotation);
}
}
It's going forwards
Translate uses the object's local space by default
oooo, so I need to rotate the prefab. The prefab is currently facing the way the pizza is flying in the video
Since it's facing down (relative to the screen), it's going down
Rotated it 180 and it's working now, thank you!
how do i fix this 😭
Did you use snipping tool to make video? I don't see a preview and didn't want to download a file lol
Hey, what i did wrong? For an odd reason when i talk with an NPC and end its dialogue, when i try to do so with another, this one only displays it first message and thats it 😦
A tool for sharing your source code with the world!
I recorded on my phone
@lilac cape Not a file now
dear god no
idk whats going on bro
i try to fix one thing then the next breaks
its getting worse and worse
im shocked at the video being a screen recording of a video which is a phone video
its cause on obs it doesnt show the video
so i had to use my phone to show the tearing
is it recorded at 60fps?
do other games act like this?
does this happen in a new scene if you rotate the camera back and forth via the inspector?
wdym
btw it even happens in the editor
like without going in game
so its unity
but its js way worse in game
I must be doing this wrong right
void HandleLook()
{
// Get mouse input and apply sensitivity and frame-rate independence
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
// Update rotation values based on mouse movement
xRotation -= mouseY;
yRotation = mouseY;
xRotation = Mathf.Clamp(xRotation, -maxX, maxX); // Limits looking left/right
camTransform.localRotation = Quaternion.Euler(xRotation, yRotation, 0f); // Camera transform
rb.MoveRotation(rb.rotation * Quaternion.Euler(0f, mouseX, 0f));
}
void LateUpdate()
{
HandleLook();
}
I think i just made the code worse
how come this guy dont got ithttps://www.youtube.com/watch?v=E5zNi_SSP_w&t=110s
im gonna blame your pc
using
navMeshAgent.SetDestination(Player.transform.position);
in update causes the enemy to just stay still and keep recalculating
https://docs.unity3d.com/6000.1/Documentation/ScriptReference/AI.NavMeshAgent.SetDestination.html
Note that the path may not become available until after a few frames later
so recalculating it every frame means it is never completing
don't calculate it every frame
whats the optomized one
after specifc seconds causes it to jerk
everytime it recalculates
the docs I linked also says in the next sentence
While the path is being computed, pathPending will be true
firstly you'd only set a new destination if the destination was changed from the previous one.. or they've reached the destination.. (conditional)
no need to set a destination everyframe.. or even more often than u need to
okay, ill try this
theres also navagent gizmo's and overlays in Unity that can really help vizualize whats going on.. where its going, when it changes all that good stuff
when its the players position, id assume its likely changing every frame. I'd really either just set it every X seconds, or if they moved far enough from the agents destination
either one would solve the issue. your agent isnt going to take seconds to calculate the path ever. if it does, you shouldnt be calculating such a large path
good point.. i also feel it adds a bit of organic feels/randomness when its not updating instantly every single step u take
how do i fix this 😭
yes
happens in editor and game
all of unity not only in unity
i even made another project empty still happened
and in game it happens to others too i let people install the game happend to them too
how 😭
Somebody knows how to use Ink?
or what channel is better for stuff like that
thanks guys 🙂 it worked @rocky canyon @eternal needle
what version of unity do u use
you'd have to see if they have some discord or forums. or start debugging and figure out what exactly your issue is
using 6
Using 6.1
how come i have screen tearing bro 😭
is it your monitor? What's your monitor hz set to?
60
Some combination of GPU, monitor, and drivers
it happens to everyone that installs my game and not only that but it happens in the editor without even playing the game
rtx 4070 ti
amd ryzen 7 9800x3d
as i said it happens to anyone who installs my game too
Could be a broken editor installation
Do you manually set the frameRate in a script? Does graphics card have sync settings enabled? Does the stutter happen in URP and HDRP
Or something you're using in the project. Try a new empty project
This is definitely lack of vsync.
I tried a empty project too
Ima try using unity 2022
Maybe unity 6 is bugged
Im also gonna try the lts version of unity 6
Vsync is likely off
Ig u could say my pc is so powerful it cant even be stopped by vsync 😭
i have 3 versions of Unity6.. no screen tearing on any of my projects.. new or older ported ones.. soo thats not it
You should make sure vsync is enabled and test in a build
Take a screenshot of your quality settings. With he platforms and vsync visible
Here
Is this quality settings actually being used? Take a screenshot of the top of the page.
Okay. And if you build and run now, does it still screen tear?
yes
Ok, well, thanks
MP4 please
its an mp4
lemme use obs to record the vid
its cause i recorded it on my phone
1 sec
overlay?
not working idk why
thats js great
even with this
pretty sure ye
ye i did
it says 1
I tried to use this for capping fps at 60 it worked but made the screen tear even worse and laggy as hell
using UnityEngine;
public class fps : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
Application.targetFrameRate = 60;
}
}
are u using unity 6 and is it on dx12
ye i tried without vsync
I dont use unity 6 and I use dx11
do you have a gsync monitor
monitor plugged into GPU and not motherboard right?
ye
how do i use dx11