Not true! Spacing out code allows air to flow through far easier, dissipating more heat, and in terms making it run faster!
Jokes aside the more I look at it, the worse it gets, even logic-wise. The if statement on line 67 cannot be reached because it's not possible to have Spawn to false if dropSet == -1 (which sets Spawn to true on line 52). The block on lines 70-73 always runs (missing else)
#archived-code-general
1 messages · Page 270 of 1
Is the pastebin mentioned above some sort of tutorial that everyone follows and encounters the exact same issues
someone else might have a guide, i don't really got anything on the top of the mind or if i did it would be like a decade outdated
My current plan is to screw around and find out, I'd assume that's how majority learn as well right
No I think it's pure lack of scripting knowledge, to be honest. It's roughly the same code they've posted for the past months
it depends on the person, though if brand new to things its prolly a good idea to follow some introductory learning content
This is invaluable
https://www.hallgrimgames.com/blog/unity-layout-groups-explained.html
Roger that
Oh the same person or something?
Thanks! I'll take a look
found when you been doing something for a very long time, it can be easy to help with specific problems but hard with more generally how to approach learning it all since its been a long time since i had to do that
Where did you change the code?
Yep same user. At least the code style improved after mods told them to format before posting, or they would be muted lmao
The only change was to formatting
A very needed change
mhm. Thanks for the advice; you'll see me arounddd
There is honestly SO MUCH that needs to change, it's hard to know where to start with the logic.
But this is a good start
#archived-code-general message
Considering that you've pasted (almost) the same code every single time, all with this broken logic, you definitely need to change a lot.
Like what is this script even for? How come its moving with such hard coded if statements? You would benefit greatly by just following a basic tutorial for what you want
You also need to make sure there's enough space that the code gremlins can move around. How else are they going to access your variable if it's in a giant block of text they can't fit through? Are you trying to get a NullReferenceException?
Instantiate returns a reference to the instantiated object. so you use that reference to access any public members
inb4 "i don't understand what you mean by that"
#💻┃code-beginner message
||There it is, I was trying to reference that message but couldn't find it, edited||
Kinda wild to not understand the answer in #💻┃code-beginner and think going into the more advanced channels would explain it simpler
Hey folks! I’m trying to make a class that inherits from Unity’s Toggle class, but any public properties I add to the class don’t appear in the inspector. No console errors or warnings or anything. Any ideas? Thanks in advance.
you need to override the custom editor too
just have it call the base.OnGUI() and append your custom properties after that.
oh gosh, that makes sense 🤦♂️ didn't realize there would be a custom editor associated with Toggle thanks!
hey so i’m trying to get all my scriptable assets from a folder and make a list on it using AssetDatabase.Find Asset but i’m unsure of how to do it. i’ve search it up too but i don’t rlly get it lol
for what purpose
it matters alot since AssetDatabase is not something you can use in builds
well so i have a player locker and i have a folder that has all the scriptable objects that have the cosmetic information, sprite, all that stuff
i just wanted all the cosmetics (the scriptable objects in the folder) to show up in a list on the player locker script so it can access it without me having to put each cosmetic in the list every time i make a new one
i know it’s a bit extra but yk 🤷
so you cant use the assetdatabase for that
i would use addressables so you can mark the whole folder with a addressable label and load them all at once
sheetTexture.LoadImage(File.ReadAllBytes($"{Application.dataPath}/Textures/{animation.spriteSheetPath}"));``` for some reason this isnt allowing me to load a texture and neither are other methods
public void Start()
{
sheetTexture = new Texture2D(2, 2);
animation = ScriptableObject.CreateInstance<MAnimation>();
animation.keyFrames = weapon.fireAnim;
animation.spriteSheetPath = weapon.fireAnimationTexture;
byte[] texture = File.ReadAllBytes($"{Application.dataPath}/Textures/{animation.spriteSheetPath}");
if (animation.sheetPath == MAnimation.SheetPath.Resources)
sheetTexture = Resources.Load(animation.spriteSheetPath) as Texture2D;
else if (animation.sheetPath == MAnimation.SheetPath.Mods)
{
sheetTexture.LoadImage(texture);
sheetTexture.Apply();
}
}```
hi guys, I'm using a hingejoint and having a problem where the player Capsule only wants to go up like 80% of the way (rather than spinning the whole way around it) of the hingejoint.
this happens regardless of how much force I add to rigidbody (via _movementMultiplier)
Interestingly, when _movementMultiplier value is high enough, using a single keyPress of WASD to move the rigidbody DOES allow it to spin the whole 360 around the hingejoint.
but holding down WASD always makes it stop spinning at the pictured angle. something about holding it down is telling rigidbody to stop spinning at that angle
Any ideas? code for the rigidbody-based capsule controller: https://hastebin.com/share/yefuzamika.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I figured out how to fix the slope bounce, but now I gotta reprogram the sliding.
Nevermind. This logic makes my player move super slowly down slopes, but normal speed up them.
project the velocity on a plane represented by the ground's normal. you'll probably want to normalize and multiply by the original magnitude again so it doesn't change the speed, but it will likely work better than whatever that is supposed to do
Their current code does the same thing as projecting it on a plane
The FromToRotation part, I mean
So my issue is that it isnt normalized?
You mean like this?
PostBattleUI Suggestions
Assuming vel is not just the input vector, that wouldn't work.
vel is the input vector for the function, I use it here. And you are right, it doesnt work.
I'm pretty sure the way I have it, its multiplying the velocity by the adjusted one every frame, so it just keeps multiplying forever.
or until I'm not on a plane, which is pretty fast.
If input normalization is the problem, you need to normalize the actual input.
Input normalization isn't the problem
My issue is when rotating the velocity I lose speed, I'm trying to figure out how to prevent that, and I was told to normalize it and multiply it by the original magnitude.
Could someone help me out... I'm trying to test if an object has component of MeshRenderer before I'm running my function, but the GetComponent<>() here just errors out with the "Object reference not set to an instance of an object" anyways
How am i able to check it without it just erroring? is there even a way to check
- Don't use modern null-checking operations with Unity Objects https://unity.huh.how/unity-null
- Use
TryGetComponentinstead of this
- If you're getting an NRE when you call GetComponent, then it sounds like
objisnull
try
I personally think that the get component should just throw when null.
everything online says its supposed to just return null
but thats not whats been the case for me
Huh?
meant to be ty lol
Why do you say that?
it mightve just been an oversight and what vertx said, 3, could be happening
It would return null if the method is valid to invoke
3 is definitely what is happening
Otherwise the error would be in a different place
but i wouldve thought that even if that was the case, trying getcomponent on a null obj would still return null
That throws null reference exception.
Because null doesn't exist.
You can't take out items from a box that doesn't exist. It doesn't make sense.
(The box is your obj in this example)
Has anyone done Sebastian Lague's procedural generation tutorial I'm having some questions about it
Best to just ask the questions
Many have, but you should still phrase your question such that it's not dependent on the tutorial.
It kind of is but I'll try
Because even if we did watch the tutorial, chances that it was in the last few days and we remember any of it are very slim.
Fair point
If I had a mesh which has a seed that completely changes the mesh shape, how could I create a mesh collider that gives collisions to all the seeds that could be generated
You would need to generate each mesh and assign it to the collider.
Or use an approximation, like a sphere collider
I'll look for some other ways cuz there can be like 2 million seeds and I need a pretty exact collider
Why do you need a collider for all of them at the same time? Is that a quantum object in superposition or something?😅
Oh no I mean that when a play randomly gets a seed there is that one collider for that one mesh
Then why not dlich's first option?
But there can (randomly) be many different maps/meshes that need their own collider
Then just assign the mesh to the collider at runtime🤷♂️
Because there’s practically infinite (around 2 million or something)
I’ll try that
You're going in circles
That was the original suggestion
My bad
I'm pretty sure Sebastian Lague handles colliders generation for his procedural terrain as well in the tutorial.
Hey! I opened a Thread so it's easier to find but if anyone gets a second I would greatly appreciate some advice
Hi everyone, this is a bit of a more information based question then one on implementation advice, but I've been using UGUI for a while now and I've always had the assumption that it is a bad idea to let images, buttons and so on off the canvas (specifcally rotating them, moving them on the z or putting them outside the canvas border). That said however, this has always been from a perspective of neatness. I have been working on several different projects where a button for example would be placed quite far off of the canvas it was attached too, is there actually a specific code / implementation based reason this would be a bad idea? For example, are their cases where rendering would fail, or the Raycast wouldn't hit?
Right now I have a line render that generates a random line and a border for that line (2D game), and I need to add a collider to the outside (there will be other rigid bodies inside of it that I don't want escaping). Because the lines are randomly generated, I cannot add a collider like normal, does anyone know how i could do this? I think it would look something like this (see attached image) when viewing the colliders
Use EdgeCollider2D
is this how you'd you get the total time(duration) of an animationCurve?
var time = animationCurve.keys[animationCurve.length-1].time;
getting the last one would be correct or should I sum them all up from the very 1st index?
the last key should indicate the total time
oh ok, thanks 👍
hi, someone can help me pls ? How to fix error CS0246 ???
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using static UnityEngine.GameObject;
using static UnityEngine.MonoBehaviour;
static extern void Start();
static extern bool GetKeyDown(KeyCode key);
Input.GetKeyDown(KeyCode.Z);
GameObject.transform.Translate(0, 0, 0);
void OnCollisionEnter(Collision collision)
{
Debug.Log("Collision avec " + collision.GameObject.name);
}
static extern void Destroy(object obj);
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
Destroy(GameObject);
}
{
if (Input.GetKeyDown(KeyCode.Z))
GameObject.Transform.Translate(0, 1, 0);
if (Input.GetKeyDown(KeyCode.S))
GameObject.Transform.Translate(0, -1, 0);
if (Input.GetKeyDown(KeyCode.Q))
GameObject.Transform.Translate(-1, 0, 0);
if (Input.GetKeyDown(KeyCode.D))
GameObject.Transform.Translate(1, 0, 0);
}
static extern object Instantiate(Object original, Vector3 position, Quaternion rotation);
//using System;
public class PlayerMovement : MonoBehaviour
{
GameObject copy;
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
Instantiate(copy, GameObject.transform.position, Quaternion.identity);
}
}
my script
Assets/PlayerMouvement.cs(45,31): error CS0246: The type or namespace name 'MonoBehaviour' could not be found (are you missing a using directive or an assembly reference?)
Assets/PlayerMouvement.cs(47,5): error CS0246: The type or namespace name 'GameObject' could not be found (are you missing a using directive or an assembly reference?)
wtf is that mess
do you know what is using static and using
they are obviously completely different
ok
💡 IDE Configuration
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
is there a way to create a mesh through code but have it available in the editor without needing to press start?
you can run code in the editor with context menu
https://docs.unity3d.com/ScriptReference/ContextMenu.html
or if you have some tool, like NaughtyAttributes then you can use its [Button] attribute
hello does anybody here know how to calculate the angle between 2 forward directions in unity? im trying to get the angle made when my camera is currently looking at relative to the forward direction of another game object Im using as my world forward the two objects are roughly in the same position
Mathf.DeltaAngle probably
I've Vector3.angle and it doesnt work
Vector3 dir1 = obj1.forward;
Vector3 dir2 = obj2.forward;
float angle = Vector3.Angle(dir1, dir2);
also its limited to 180 degrees? Im looking for a solution that will give me 360 degrees
this is for a radar im implementing in my game and I wanted to make a cone to represent where im currently looking at
if you need the inverse just subtract from 360
if you want more than 180 degress
use Dot product of these vectors and then Mathf.Acos
Vector3 dir1 = obj1.forward;
Vector3 dir2 = obj2.forward;
float dotProduct = Vector3.Dot(dir1, dir2);
float angleRadians = Mathf.Acos(dotProduct);
float angleDegrees = angleRadians * Mathf.Rad2Deg;
something like that, might be spelling errors
the problem is that forward isnt world forward so I need it to use the forward of a transform im currently setting as the world forward
let me give that a try
does the order matter here? object1 = world forward and object 2 is camera forward?
if it's a local forward there may be a method for it, but otherwise you can probably use transform point and derive a direction with that
why would it matter
im asking if it does

didnt work the angles once it reaches 180 then starts to decrement
worked always fine for me
to measure angles between 0-360
if you have a direction vector (1,0,0) and (0,1,0) it should return 90 degrees
dot product will be 0 between these vectors
how did you implement it
actually, wait i think that Mathf.Acos is also limited to 0-180
Vector3 dir1 = direction1.forward;
Vector3 dir2 = direction2.forward;
float angleRadians = Mathf.Atan2(Vector3.Cross(dir1, dir2).magnitude, Vector3.Dot(dir1, dir2));
float angleDegrees = angleRadians * Mathf.Rad2Deg;
that should work now
offset the angle by 360 - the angle if < 0 or angle= (angle+ 360) % 360
still the same. . . doesnt go beyond 180
I used your formula as sent here
still the same even with this added. . .
then your implementation is wrong
if angleDegrees is 210 for example
then 210+360 = 570
and 570 % 360 = 210
so it should be exactly 210
is there a voice chat we can use so that I can demonstrate this?
Vector3 dir1 = worldForward.transform.forward;
Vector3 dir2 = cameraGO.transform.forward;
float angleRadians = Mathf.Atan2(Vector3.Cross(dir1, dir2).magnitude, Vector3.Dot(dir1, dir2));
float angleDegrees = angleRadians * Mathf.Rad2Deg;
float angle = (angleDegrees + 360) % 360;
the entire class
where do you use it
and the console debug log values
also transform.forward is a local vector
Hey all, im trying to linearly interpolate between two points. These are 0.5 and -0.5 on the Y axis. The object is moving way beyond these points though. Am i missing something here? This script is attached to the object.
if you need them in global vector, then use Transform.TransformDirection(Vector3 dir)
it transform local direction to world space
tf.pos+=vec3?
might i need to multiply that by deltatime?
no, dont use +=
ok so world forward is a transform im using for my north and the camera moves around based on where im currently facing right. this is for a radar implementation so if the camera is facing the same direction as the world forward, the angle should be 0 and so on depending on where im facing
read what i said
and adapt your code
ah i realised now i shouldve kept track of original pos
is there a way to check if script is running in OnDrawGizmos?
just do = instead of +=
my points are relative to the things world position so im now doing = with original pos
it works
nice
What do you mean if the script is running? What does running mean in this sense
private bool hasStarted = false;
private void Start()
{
hasStarted = true;
}
public void OnDrawGizmos()
{
if(hasStarted)
////
}
i guess?
if that's what they meant
In game, so i used Application.Isplaying
How do you architecture the following:
- I have a circle spawner script, which handles spawning some circles and parameterising them
- One of the parameters is something like an item, which on death of the circle, should appear in the UI
I'm roughly familiar with events/delegates/observer pattern, and have a brief idea of how one would go about it, but not entirely sure.
Would the circles invoke an onDeath event? If so, I'm assuming the circleSpawner can do something with that information, but what about the link between the circleSpawner and UIManager, how should those communicate
fire OnDeath event
subscribe to that even with all dependant systems
and so your stuff
update ui etc
So if my circleSpawner has a reference to the created Circle, what am I doing to expose that circle's onDeath event to the UI manager. Should the CircleSpawner also throw an event that the UIManager accesses through a reference to CircleSpawner?
that should work fine, you could have an CircleDied event on the spawner, or an alternative would be have a CircleSpawned event where your UIManager could add its own listener to each circle when it spawns
Use a free, already existing system from the asset store? No, I only need a very simple version of this thing, I’ll roll my own. <2 years later>. I just wasted a ton of effort rebuilding a crappy version of the free asset for no reason.
If I have a bunch of objects that represent chunks, with a script with no active code containing its data on all of them and all their contents as children. Will those alone still impact performance if there are too many of them? I am planning on leaving them active while keeping their contents disabled (if the player is far enough away).
Probably not enough to tell the difference.
Anybody know why WaitAsync is seemingly missing? It was added back in .net 6, so it should be available, right?
Unity doesn't use .NET 6 (or any .NET Core)
ah, right, I was mixing up .net version and c# version
bleh
you're going to use it to await for a token to be cancelled? you can make your own custom awaiter
it's basically the same
you can schedule the await for anything basically
!code
Posting code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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.
i want the instantiated Object to move to the player
but this doesnt work
it just instantiates and then stays on position
hey everyoneee just wondering if its better to handle data on scene transition one way or another
say in my scene I have an array of bools "originalArray" that sits on a component (which will be destroyed during scene transition) and I want to keep that it, would it be better to have an array point to this array so that it stays in memory even during the scene load (by just doing keepArray = orignialArray) so that i can then continue to use it after loading the new scene by just "holding on" to the array, or would it be better to make a completely new array like basically clone the entire thing, hold onto the CLONE in a scriptable object and then repopulate the original array component when were in the new scene?
basically 1) would be just point to array using another array using a scriptable object or 2) would be clone array and then repopulate the array on the component in the new scene
basically asking if theres a massive difference between them because if i do this for large amounts of arrays and even dictionaries then it could maybe increase load time?
both methods would be using a scriptable object, the main difference is cloning vs pointing to and keeping it in memory
wont do disk saves because that is a bit unecessary for temp data
unles you have A LOT of objects it doesnt make a difference
A LOT meaning milions iterations
okay i wont, good to know, but lets pretend it is a large amount of data which one would be more efficient just like time and resource wise?
thank you first of all but also i do also just wonder about that for curiosity sake
I would assume they dont really have a big difference even with large data?
pointing to a existing address in RAM would be more efficient of course
instead of creating new array containing milions of elements
but the best approach with such big data woul be external saving to a file
or as a json
do you think I should repopulate the component in the new scene at all or is it fine for my data to just live its best life on the scriptable object since its temp data
disk writing is slowest no?
isnt memory keeping much much faster than disk I/O
with SSD? its for sure much faster than creating a milion elements array in a for loop for example
what exactly are you trying to do
any tldr?
want to keep array between scenes?
right if we talk about millions of elements once again iguess so, but when we talk about a tiny amount of data again then memory should be faster again right?
again as i said, it wont make any difference
maybe in miliseconds
not something you will notice
yea but not only between scenes, im wondering if i should just let my array live in the scriptable object permanently
performance-wise
as this data needs to be accessed from all kinds of sources
but what is that array containng
what type of data
is it persitant data or does it change runtime
and its such a neat approach with like nto a lot of components that then depend on one another when you have a universal data SO right?
you have several approaches
- singleton + DDOL
- scriptable object
i'd avoid cloning the array
between each scene transition
bad idea
its game state bools basically
then yea, make it a singleton and DDOL
I heard bad things about singletons
I am a new programmer and want to like adopt uhh healthy practices lol
is the danger that components rely on one another and if the system changes the entire code ahs to be changed?
or is there more danger?
for example, this is my project
i have all the managers i want to access globally
as a singleton, DDOL
so i can access GameManager.Instance in any scene etc
yea i mean if its fine and save to just point to and keep in memory thats prolly what i will do
but you cant access them from other scenes right?
YOU CAN? I thought thats illegal in unity
do you know what's DDOL?
no not really
I just have had that issue before where i had a "ESSENTIAL" scene but then my other objects were unable to refrence those components
and I really wanted to refrence sometimes.. like not all the time but there were instances where I wanted to do that
basically it NEVER gets destroyed
hey, I want to create hinge joint on runtime, I even printed all values to 100% recreate it
void Start() {
// print all HingeJoint properties
HingeJoint hinge = GetComponent<HingeJoint>();
print("HingeJoint: " + hinge);
print("HingeJoint.anchor: " + hinge.anchor);
print("HingeJoint.axis: " + hinge.axis);
print("HingeJoint.connectedBody: " + hinge.connectedBody);
print("HingeJoint.connectedAnchor: " + hinge.connectedAnchor);
print("HingeJoint.autoConfigureConnectedAnchor: " + hinge.autoConfigureConnectedAnchor);
print("HingeJoint.useLimits: " + hinge.useLimits);
print("HingeJoint.limits: " + hinge.limits);
print("HingeJoint.useSpring: " + hinge.useSpring);
print("HingeJoint.spring: " + hinge.spring);
print("HingeJoint.useMotor: " + hinge.useMotor);
print("HingeJoint.motor: " + hinge.motor);
}```
```cs
HingeJoint hinge = part.gameObject.AddComponent<HingeJoint>();
hinge.anchor = Vector3.zero;
hinge.axis = Vector3.up;
hinge.connectedBody = gameObject.GetComponent<Rigidbody>();
hinge.connectedAnchor = new Vector3(2.12f, -0.06f, -1.94f);
hinge.autoConfigureConnectedAnchor = true;
hinge.useLimits = true;
JointLimits limits = hinge.limits;
limits.min = part.hidgeJoint.min;
limits.max = part.hidgeJoint.max;
hinge.limits = limits;
hinge.useSpring = false;
hinge.useMotor = false;
but it doesnt work at all, when hinge joint is added from editor window it works, but from script its buggy a lot
does anyone have any idea why it behaves different when created from script?
oh yea dont destroy on load ive heard of that
but then how do your actual gamescenes access any of the universal systems? they cant refrence them right?
they can
that's why they are a singleton + ddol
let's say you are in main menu
and you want to access your game manager
does unity then say ah nevermind thats allowed?
then you do GameManager.Instace.
because when i had a essential scene with my systems all my cross scene refrences werent working
if you are in game scene, you can also do GameManager.Instance
beceause it wasn't ddol
anybody?
yea no they were DDOL i just didnt know the shorting for it, i know dont destroy on load
that's your job
okay then they werent a singleton
so you couldnt access them from other scenes
make a GameManager, make it a singleton, make your array in that GameManager, mark it as dont destroy on load
boom, now you can access GameManager everywhere
in any scene
i probably did it wrong yea that was a long time ago
I am probably gonna stick with the nonsingleton approach for this project because i will need different kinds of like systems for different scenes as the mechanics will be nt the same
Explicitly making a copy of the data and then operating on it, is a fine solution too, it guarantees that you have full ownership and control of the data and not constrained by the original data (eg if the original data is meant to be immutable, now you have the freedom to mutate the copy as you see fit)
Any sort of global state like singletons or statics have their downsides, but I have a feeling that it might not be something you need to worry about just yet.
Right but Singletons are really useful for scenes where the mechanics and systems dont change mostly right
like the systems needed in the different scenes differ and I really only need to carry a small amount of data
but if I was making a mechanically not changing game like a platformer id prolly do that now :D
I was really mostly worried about cloning data vs just pointing to it in RAM
Yeah the singleton/static is mostly a tangent, for cloning refers to first half of my comment. It's a fine approach, but obviously not cloning is faster, so it's up to you to decide whether the pros outweighs the cons.
Yea my plan was just to keep it in memory because, I mean, performance but it really doesnt matter that much on small scale
you should know what mmap is
havent profiled that much yet because to profile you need a game to profile and not just some basic systems :D
The singleton/static point, even for a system that never changes and has only one implementation, it still means that it becomes a hard dependency. Any system that relies on a singleton/static/any sort of global state, now cannot possible exist without it or change it.
Changing it is still useful for testing, and even if you don't care about testing your code, the fact that it being a hard dependency means that your system literally cannot run unless the hard dependency is initialized. This most commonly manifest as the problem of "I initialize my singletons/statics on a boot scene and make them DDOL, but now if I want to start from a particular scene I can't anymore, I have to find some way to still initialize them."
and i mean its better to ask first whats performant rather than just do trial and error with everything right?
at least with those things that wont be apperant until late in development i feel
Thats exactly why I havent touched singletons anymore since my like very firsts attempts in unity
I find the design idea around singletons like very understandable the wanting to have this overarching system but at the same time I love flexability to just completely scrap systems without having to redo other stuff
Well it's certainly not saying singleton/static/global state are true evils, everything has pros and cons, just like your original question of "should I make a copy or just reuse the data"
Right exactly singletons are useful
Understand the pros and cons, weigh them yourself to see if they are relevant to your particular use case, then decide from there.
Right, thank you
Do you know how I can add the collider to the edges?
It's the opposite, you add the edges to the Collider
- Hey. I'm constructing a render params instance and i need to set its rendering layer mask. The default layer mask can be casted to int; however, the parameter in the render params type is uint. Am i supposed to convert those using unsafe utility to reinterpret the type, or have i missed the actual way?
Singletons are great when they apply.
I don’t really see any drawback in using Singletons in the scenarios where they should be used.
And if something shouldn’t be a singleton, it prompts the question of “why would you make X a singleton”
which is more readable:
before or after
neither
why don't you keep the dialogues in scriptable objects for example
or fill them through inspector
no i think its better to store all the dialogues in one place and segment them into scenes
it will keep things all in 1 place
to your question, if you have default arguments, you should use them.
But dialogue should be in scriptable objects, not code
but why not in scriptable objects
imagine you wnat to add translation
to your game now
to other languages
this violates the open closed principle
that will become very unpleasant to work with
on larger projects
for sure not designer friendly
not translation friendly
and just not dev friendly at all 😄
this should 100% be done on scriptable objects, or other sorts of files that can be parsed by your code
i think there is a plugin called yarn weaver or something for this
how so
we are literally explaining to you why it is a problem
right now all i have to do is copy the dialogue object from 1 npc to another and then change a value in the npc so i can fetch their dialogue from the manager
shouldnt be a problem at all lol
🤦♂️
do whatever suits you then
and… how much dialogue is going to be in your game?
if you have actual decision trees here, it sounds like a fair bit
at most it will take up like 3mb of memory lol
this is not a memory issue
it’s an architecture issue
im out of this convo, explaining things like that makes my energy drained 😄 good luck tho 😄
History Lesson:
Dialog in JRPGs back in the 8bit and 16bit days was done this way. Hence why translating the games for foreign markets always had a long delay of months or longer, because all the strings were in code rather than separate data.
xaxup literally said that earlier lmao
Tbf if you use the "a pattern should only be used when it applies" then there's no bad pattern in the world according to that definition 😄
Most "bad" patterns are bad in the sense that the cons are not immediately obvious especially to first time users of the pattern, and it only emerges later on. Singleton for example is very bad if later on "there's a new scenario where the system is different unlike before where the system was always the same hence I used singleton, now it's a giant refactoring effort to get rid of it." Yes you can say that "well if you knew this was coming, then you should've never used singleton" but the problem is that you don't always know what the future has in store for you. Requirements can always change on a whim.
the conditions for Singletons are usually relatively obvious
and even without translation issues, you should understand the open closed principle to know why what you are doing has deep problems
Evidently not with how many people abuse it and regret it later on.
i dont know about the open closed principle
pain is the only cure for foolishness
look it up. learn
Well the point about singletons being hard to get rid of later on still stands, and like I said that point is not something you always have the fortunate foresight to decide because requirements can change in the future.
that sounds literally like a sentence from Darkest Dungeon game
that is true. but you need to be aware of what sort of committments you make with singletons
this is why service locator pattern should be what's thrown around more and not singleton
like, when I make a camera controller singleton, I commit to only having one camera. That is a committment that I make actively, and cannot take back
making things more generic than they need to be can cause issues. So i do not want to start making code to leave room for a second camera
if you are not ready for this committment, you cannot make a singleton
You make a class as another abstract layer of a class which you access that has references to the cameras. This way you can add as many cameras as you want without having to make this camera class a singleton.
There are other patterns which can replace singleton (service locator being one example brought up) that doesn't incur much more cons yet give you the flexibility that singletons lack.
yeah, but I know that my game will not ever support multiple cameras because of the nature of how the camera works in my game. I do not need to add layers that I know do not need to exist.
in my eyes, if you cannot know with certainty that you always want a class to have a SINGLE instance, now and forever, you are not ready to make a singleton.
it is a committment
the lack of flexibility has pros and cons
And "now and forever" is an extremely harsh condition, you are essentially predicting the future, and that's what makes singleton bad.
so for dialogue i should have files with text stored and then have separate files for each language i want to translate to, then when language is changed / when the game starts i load/reload the dialogues by reading lines in the file
there are some things where you do know that.
That is why we design software rather than just making it up as you go along
if you don’t know or aren’t sure; then you can’t make a singleton
Exactly, and accepting that "we can't always predict the future" is part of the design process.
it is. but you need to have a general idea of your needs to not make things way more generic than they need to be, which wastes time
Vast majority of the usages of singletons are simply not fit, and again like I've already said, I'm not saying singletons are always bad, but it's commonly considered a bad pattern for very good reasons. "A pattern is not bad if you only use it in the situation it fits" is not exactly a good defense, because "the situation it fits" for singletons is very narrow.
Spoken like a student
like
Author|Index|Dialogue|ResponseNumber
Index|Response|DialogueIndex
...
System|0|Hello, World!|2
0|Hi!|
1|Bye!|
-->
System|0|What's up?|2
0|Nothing much, how about you?|1
1|I don't have time for this|
System|1|Nothing much.|1
0|Cool.|
Look at this system: https://www.yarnspinner.dev/
but it's true. When you design software you analayse the requirements and you implement what best fits the need. Saying don't do this, don't do that is just plain nonsense
then you should say that instead of name-calling
because it's always students that spout theoretical bullshit when they have no real experience
id rather make my own from scratch otherwise it wont be as fun
the more you do not know the design parameters of what you are making, the less you can use singletons. This is more true in bigger projects where multiple people are working on something with different ideas. And then corporate changes their mind on feature set
in theory, if you took the stick out of your ass do you think you'd be more approachable?
not a chance
you catch more flies with honey than vinegar
it's very true
it's the same as when you are on your car driving lessons
you dont learn how to drive at all
you were once a student too steve
Welp, the conversation was back and forth in good spirit with everyone bringing up good points, now I see it just devolves into name calling and assuming about people's experience to discredit arguments, so I guess this is my cue to exit.
you only learn how to pass the exam
and then you learn the learn driving skills later when you gain road experience
ive never been in a cs class so i wouldnt know
true, 50 years ago
No, you must pick a side, and then rabidly attack the ones waving the flag that has a different colour than the one you are waving 😄
i do have a friend who is taking one and the stuff she has to do for class is the most useless and stupid stuff
i’m sad to see it devolve like this. we might have a better convo in the future
idk why they teach html in a cs class
is html even turing complete?
you picked the wrong school, fool ~Big Smoke
of course it's not, it's not even a programming language
its not
yeah html should be taught in web design or art classes
not cs classes
i ask because why the hell would you teach a non turing complete system for introductory cs
computer science is a wide field.
i would not call web design cs
web design is more like art generated by text interpretted by a computer, than a programming language
it's a sign language
the name says it all
Hyper Text Markup Language. I.e. nothing whatsoever to do with programming
"so i just graduated college, finally got my cs degree after months of working with html. time to get into the workforce? oh whats this? c++? never heard of it."
While writing html might not be part of cs, understanding how it works, might.
i mean
the cs teacher at my school teaches it like that except instead of just using html they use python and a game engine
so they actually understand how its working because they have to do it themselves
html and python aren't really interchangeble terms xD
And how many people (apart from me) actually write html rather than use a crappy framework to do it for them?
i mean the stuff they are doing is
probably quite a lot
you can say it like this
if you learn html you will be good at making websites and thats pretty much it
but if you learn an actual language you can pretty much do anything you want
no you won't. making good websites needs much more than just html
ok let me rephrase
you will be good at making websites look good and be well formatted
by learning html?
still wrong
no
ok well i dont make websites so im just speaking from what i know
typical then 😄
but if i paid for a cs course and i got taught html id be pretty pissed
is all im saying
that doesnt make sense at all
it's like
you paid for a car and got a ps5 console
how did you connect c# course to html course
my friend has been in a college cs course for years and they just went from html to javascript like months ago
then he picked weird fucking college lol
then you've heard wrong
I mean, if html is just one small part of a course that encompases a lot of other stuff, like C#, C++, OOP, etc... Then why not?
yep, dumbed down the complete learning of cs and yet students still have the chops to pontificate
Very incorrect
they teach it like its a web design course
atleast the school my friend is at
im not convinced she isnt going to the wrong classroom
Then your friend is at a shit school. Probably a diploma mill like university of Phoenix or DevVry
then as i said multiple times, your friend picked some very special shit school
or you understood him wrong or he's lying
or his friend doesn’t know that web design isn’t programming, which is the most likely
im pretty sure its the university of Sidney australia
There are web design courses at legitimate schools, but they're self contained and usually elective. My CS program didn't even offer any
The 100-level courses were taught in Java, after that it was either C or language-agnostic
ive gtg now
i find it more likely to be a communication issue than the school being so bad as to have a CS program that starts with html
yea there's no way
what? No ASM, that is so sad
first language course is C
every following teacher in the CS program would immediately realize their students didn’t know anything that they were expecting as prerequisite knowledge
my condolences
i heard the first course will switch to python
No, there's assembly. That's part of what I consider language-agnostic. All languages become assembly at some point
Teaching cs concepts unrelated to actually making a program in a language
i started with python. learn with training wheels. Then learned C, to learn the low level shit at play. Then C++ to build up
Like algorithms, assembly, design, etc.
then other classes were purely theoretical
good, I thought you were talking about logic and analysis as language agnostic
yo anyone is here?
stop spamming and crossposting
Wish I had dontasktoask copied on my clipboard
me?
yes
How so
O nice
crossposting is against the rules
I realized the problem i was facing wasn't beginner coding
not related, don't need excuses, just saying ;p
I'd rather have a plain HTML website than some oversaturated mess implementing all current cool frameworks
still, cannot make a good website just with HTML
that was the point
of entire conversation
atleast css+js
depends what it's for
Sure, you need a bit of css sparkle if you want to do anything that looks good on the eyes
But this whole thing is incredibly opinionated and depends on context
yup
Alright
agree absolutely, which is why I never use frameworks
That's not exactly my point though 🤔
I mean it's really not a problem if you use a framework. If you got time to do it yourself, by all means go ahead. But there are existing solutions that also work
there is no 'one size fits all' solution to any computer system implementation
noone told there is
that's what frameworks profess to be
wasn't the point that learning HTML (and CSS) is used almost exclusively for making websites and nothing else (except UI in a few games), so spending time on it is not useful for CS?
never heard of a college teaching only HTML+CSS (assuming you misunderstood and it's CSS too) in a CS course, except maybe on design focused ones. But then it's not a CS course but a design course at a CS college.
i think they will teach you full stack instead of just front end
https://motherfuckingwebsite.com/ css was a mistake
that is putting it very, very politely
However, normalizing it and multiplying it be the input velocity causes it to multiply every frame, shooting me off the screen.
hello my gamemanager script is for some reason running twice and i get twice the amount of "points" every second than i should be getting anyone know how to solve this?
You need to provide more information than that, like, for example; your script.
ill send the script soon
Mp4 will embed
Mkv requires a download for mobile (maybe desktop too?)
Posting code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
does this work?
Yep. Where do you call Increment?
im pretty new to this so maybe i should ask these questions in code-beginner but i use the Increment function as when i press the button it increases (i feel like i dont understand your question completly)
I'm asking WHERE you actually call the function. Somewhere you would have written Increment() to actually cause it to happen
It looks like it would be in a different script if that helps
I think they mentioned UI butto's onclick
what is Multiplier amount, and why are u not debug.logging these values to make sure they are correct
it was in a different script but i moved it to the gamemanager (long story) and it works just that the money per sec is double of what it should be
one
are you sure you dont have the script twice or something?
You're still talking about the declaration. I'm talking about the call
that was what i was thinking but i checked it like 10 times and i dont run it twice
i am stupid you were right i do run it twice sorry
thats good, at least its solved now yes
i have coded the entire day so i guess my brain has just melted and my last braincells are gone
haha yeah,good to give the brain time to breathe once in a while
but i have one more problem in my script, i use playerpr
oops
when i press r all values should go back to their normal state but it doesnt work ever since i moved it from another script into the gamemanager script
this worked but isnt anymore
what makes you say that
btw your variables are static , that might have to do with it
those need to be manually reset as wel
I personally would not use static for this
how do you know it's not working?
if the problem is with anything other than the player pref values, then this code is the wrong place to look
cause when i press "r" money and money per second should return to 0 but they dont
yes i know but playerprefs is my saving system i can try to take a bigger screenshot
int x = 123;
PlayerPrefs.DeleteAll();
print(x); // logs 123
I know it's your saving system
why would money per second return to 0 if you're only changing playerprefs
Why do you think resetting the playerprefs values is going to do anything to MoneyPerSec?
this is an identical situation
before just the money per sec was not resetting but after that line of code it did
Your code does literally nothing to change MoneyPerSec after the game starts
Of course MoneyPerSec isn't changing
this is my upgrade code when i buy shit and it updates after every purchase and sets the playerprefs to the desired value
!screenshots
No
Be mindful, if someone requests your code as text, don't send a screenshot!
Yes. It sets the player prefs values.
here's their code
https://hastebin.com/share/openofiruv.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
PlayerPrefs.SetInt("foo", 100);
int val = PlayerPrefs.GetInt("foo");
PlayerPrefs.SetInt("foo", 0);
print(val);
What value does this log?
Im gonna go ahead and say cause they're static xD
yes so by pressing r the values should go back to the start values which are 0
What value does this log?
100
Correct.
That's exactly what your code is doing
You're never resetting MoneyPerSec. You're only resetting the PlayerPrefs value.
If you want to reset MoneyPerSec, then you need to..well, do that
it was working before so thats confusing
but so it should just be if(Input.GetKeyDown(KeyCode.R))
{
MoneyPerSec = 0;
}
i thought that beacuse the playerprefs value of mps(money per sec) was changing with every purchase setting it back to 0 with the press of "r" would work, according to a tutorial i saw it does
int x = 100;
PlayerPrefs.SetInt("foo", x);
PlayerPrefs.SetInt("foo", 0);
x += 5;
PlayerPrefs.SetInt("foo", x);
What value is written into the player preferences?
five
+= 5
zero
Why?
basic math myg
PlayerPrefs.SetInt("foo", 0);
How does this line of code set x to zero?
oh
100+5 is not 0
the answer is that it does not
x is still 100
it doesn't matter that you happened to use x when setting the playerprefs value earlier
there's no "link" (that'd be extremely weird)
yup, you only load it on Start
Setting a PlayerPrefs value does nothing to any of your variables
It just changes what PlayerPrefs.GetInt will return later
That's it. Nothing else.
You probably used to assign MoneyPerSec = 0 while resetting
or you then read a value from PlayerPrefs and wrote it into MoneyPerSec
or that variable didn't exist at all and you were always reading from PlayerPrefs
can i send you a yt link
its baisically the code that i stole but its working
then it does something different
can you take a look since i have a slight feeling you understand c# better than me
if you can point me to the specific part that shows the code, yes
did you get the vid?
just post it here.
didnt know you could send yt links here
pressing R doesn't instantly reset the values in the video
it just makes it so that, the next time you launch the game, the playerpref values have been reset
yes but that is not working for me
its just a way for me to delete all of my progress before i release it
okay, I thought you were asking why it wasn't immediately resetting the numbers
It's probably the same issue, though
- reset prefs to defaults
- something writes to prefs
- game quits
the old values are back in your prefs again
especially if you added code to write to PlayerPrefs when the game quits
was google graced with a better description
this looks like Visual Scripting
We have many items in our 2d game. We have used spine to animate their characters.
Can we have these items as attachments while they are not inside spine as sprite atlas and add them in runtime?
Also, if we use bones and add runtime items to specific bones, how can we specify order for them?
For example a mom hugs her baby. The baby has their own animation. Now, we want to render it between some mom sprites (hands, chest)
that doesnt help
consider reading the visual scripting documentation
how does it not, you're asking a VS question and thats where it goes
assuming you're actually trying to use visual scripting
https://docs.unity3d.com/Packages/com.unity.visualscripting@1.9/manual/vs-variables.html
RTFM - read the fucking manual next time
What is "this" if not visual scripting? There is basically no information on what you're even trying to do
How could anyone help with that?
anyone please help me, i am having an issue where the player manager spawns on scene 0 even before an scene has been loaded, like when i start laoding a scene the playermanager spawns already and then spawns the player
[SerializeField] public Sprite CharacterSprite;
[SerializeField] public RuntimeAnimatorController IdleAnimation;
[SerializeField] public RuntimeAnimatorController AttackAnimation;
Is that a correct way of setting up CharacterSO animation/sprite?
there's no need for [SerializeField] on a public field, mind you
why are they public in the first place
I generally avoid public
SerializeField if you need inspector and do a prop
[SerializeField] private Sprite characterSprite; public Sprite CharacterSprite => characterSprite;
this looks like a data container
I often just use fields in that case
all those methods calls have to add up eventually
hey, I want to create hinge joint on runtime, I even printed all values to 100% recreate it
void Start() {
// print all HingeJoint properties
HingeJoint hinge = GetComponent<HingeJoint>();
print("HingeJoint: " + hinge);
print("HingeJoint.anchor: " + hinge.anchor);
print("HingeJoint.axis: " + hinge.axis);
print("HingeJoint.connectedBody: " + hinge.connectedBody);
print("HingeJoint.connectedAnchor: " + hinge.connectedAnchor);
print("HingeJoint.autoConfigureConnectedAnchor: " + hinge.autoConfigureConnectedAnchor);
print("HingeJoint.useLimits: " + hinge.useLimits);
print("HingeJoint.limits: " + hinge.limits);
print("HingeJoint.useSpring: " + hinge.useSpring);
print("HingeJoint.spring: " + hinge.spring);
print("HingeJoint.useMotor: " + hinge.useMotor);
print("HingeJoint.motor: " + hinge.motor);
}```
```cs
HingeJoint hinge = part.gameObject.AddComponent<HingeJoint>();
hinge.anchor = Vector3.zero;
hinge.axis = Vector3.up;
hinge.connectedBody = gameObject.GetComponent<Rigidbody>();
hinge.connectedAnchor = new Vector3(2.12f, -0.06f, -1.94f);
hinge.autoConfigureConnectedAnchor = true;
hinge.useLimits = true;
JointLimits limits = hinge.limits;
limits.min = part.hidgeJoint.min;
limits.max = part.hidgeJoint.max;
hinge.limits = limits;
hinge.useSpring = false;
hinge.useMotor = false;
https://cdn.discordapp.com/attachments/763495187787677697/1206950800216301578/2024-02-08_18-33-12.mp4?ex=65dddf86&is=65cb6a86&hm=4228f2e7ab2119b39c62fd5de4a8c04d4d04780bb7c1d5124f0eddaf807e3061&
but it doesnt work at all, when hinge joint is added from editor window it works, but from script its buggy a lot
does anyone have any idea why it behaves different when created from script?
anyone? sorry for asking again and again but I really need that and can't fix that for 6 days
🙏🙏🙏
Use a prefab ?
what if the prefab for whatever reason get moved or deleted?
id take that as an inaficient way
thats a good idea
can I somehow make prefab of component?
That is not really an issue...
No.
or for example make door prefab and copy component from prefab
Just make an a whole prefab
If it is what it takes
That wasnt my question, I was just asking if I used correct types for storing sprite animation or if there is a better way to do that.
Hi, currently I am struggling with my slopes, my character was bouncing and to fix that I rotated the movement to go along the normal of the slope. I think I may be applying the rotation wrong, because when logging the rotation value on slopes, it's always a decimal, so I am losing speed when going down slopes. Here is the function:
I guess? there is no context here
I tried using ProjectOnPlane, but it does the exact same thing.
Yeah as I said before, your FromToRotation does exactly what ProjectOnPlane would
While keeping the magnitude
Why are you only returning the adjustedvel when Y is negative? Is it because you only had problems downhill?
And where does hit come from?
negative implies going downslope instead of Up
Because I can go up slopes just fine
Without this code, does it go down in a stair-like movement?
Forward, down, forward, down
hit comes from the ground check, using a sphere cast
Did you make sure that the spherecast hits downward slopes too?
Like does it extend downwards at all
Yes
im actually doing the same in this vid
https://youtu.be/cEQdjYk51KQ?t=735
but yes Raycast for slope is diff from grounding ( this is important)
So I shouldnt use the ground check for slopes?
nope
Okay, I'll be sure to change that once I get to my PC.
I would use a spherecast that starts from the center of the player, casting downwards and maybe a bit forwards towards the movement direction
If a spherecast overlaps with the ground at its initial position, it will not detect it
So it's important to make sure it starts high enough
hi! im looking for a way to get the angle between objects velocity and a plane when they collide
Vector2/3.Angle
or SignedAngle
So the red here is the spherecast, yellow is the hit.normal that you want
Let's just pretend that the green is a capsule
Sphere doesn't have to start that high, I exaggerated a bit
but how do i get the vector of the plane?
the normal
collision.normal/hit.normal
That is a collider
Not a collision
OnCollisionEnter passes a collision
https://docs.unity3d.com/Manual/class-PhysicsManager.html
You could potentially get
Contact Pairs Mode to Enable All Contact Pairs
nvm this is for 3D
triggers arent exactly the same as collisions
ok thanks a lot!
Oh, the other issue is that the normal thst the ground check gets is at changed angle?
so i need to use contact points, right?
Yeah
I though you have a solid collider
Does the other collider need to be a trigger?
im not sure tbh, i was getting some collision detection problems so i just changed it to a trigger
Sorry, I was asking if the other problem is that the hit.point is determined by where on the spherecast is hit. I thought the hit.normal was just the normal of the object hit.
im pretty sure its moving to fast to get detected
switch rigidbody detection mode to Continuous
also put NeverSleep
Yeah it's the normal direction at the hit point of the spherecast.
An object doesn't just have one normal
Switch back to non trigger then
How can I get the direction down that I need to shoot the cast to get the correct normal
Cause I get shooting it slightly ahead of the player's feet, how do I know how far?
Well, you could just use Vector3.down
But I like to add a bit of your current horizontal direction to that
A bit further than the bottom of your character. Maybe 0.5
what if i dont have a rb on this object?
But I can't give you any accurate numbers, you gotta try yourself
its attached to the parent
@dense estuary So the distance from the sphere start to the bottom of the character, PLUS some value like 0.25 - 0.5
wdym u dont have a rigidbody
you just said you had a rigidbody
rigidbody is on the parent object
the parent of what?
@dense estuary Just as an examplecs float sphereStartHeight = 0.5f; Vector3 sphereCastOrigin = transform.position + Vector3.up * sphereStartHeight; float sphereCastDistance = sphereStartHeight + 0.25f;
Does that make sense?
how's that relevant to changing the collision detection mode
of object with a collider
huh why is the collider on the child
Yeah, I get it. I'll be sure to apply that as well.
basically im trying to make a spear that sticks into walls.
when the collider on the tip collides with a surface i simply freeze rb position.
but i ran into a problem: when spear was moving fast collision detection seemed to be kinda janky
like that
so i had to change the collider to a trigger box
hope that makes any sense
yeah ive tried setting it to continuous already
sooo i should put rb on my walls?
The collision messages are sent to both objects involved. So if one senses it, both will trigger
Simpler colliders tend to be more reliable, yeah
Interpolation is a visual thing.
oh, ok
that doesn't match my understanding. using sweep-based collision detection on an unmoving object is pointless
I have this textmesh text on my gun which uses a world space canvas and for some reason instead of staying in place, it moves up and down when I move the camera up and down. Any suggestions?
I bet it's non-uniformly scaled
If a child's parent has a non uniform scale, like [1, 5, 1], then it'll get skewed as it rotates
Can you show me the hierarchy while the game is running?
Have the text selected.
like this?
Precisely. Check each parent up to the root. Do any of them have a non-uniform scale?
[0.05, 0.05, 0.05] is fine
one moment
Everything uniformly scaled
in the scene view it's attatched to the gun properly
Components can't really be moved/copied to another object
You could instantiate a prefab that has that component, though
And add it as a child
Ah, I see that you have two cameras
Do their settings match, and are they moving together?
@timid depot Or you can add a fresh component with AddComponent and copy values to it manually
they're having problems with hinge joints, apparently
ill check that but im not sure if it work
beacuse objects like vector3 will just copy references
need to copy each value separately
could this be caused by some delay of OnCollissionEnter2D?
yeah I believe they're moving together and their settings match.
I think I know what the problem is though
like does it trigger the same frame as the collision happens?
the UI camera only sees ui, but the gun is parented to the other camera
cuz im pretty sure i can see it bounce off for a split second before freezing in place
Yes, at the end of that physics frame
How exactly is it wrong currently?
Does it seem to stick too early?
Because I see a gap here
yeah a gap like this
but again i can see it hitting the wall and then bouncing back
for a frame maybe
Ah, seems like it does collision depenetration for one extra frame
I think a good workaround would be to store the spear's velocity in a variable each FixedUpdate
Then after freezing the rigidbody, move the spear by that velocity * Time.fixedDeltaTime
I think that's how I did it
still same issue even when Im creating hinge joint same as from prefab
i have no idea at all how to do this
is this even possible to create hingejoint between 2 rigid bodies in runtime?
damn that might be too much 🫣
Yeah, maybe move it forward only by the length of the tip?
velocity.normalized * tipLength
Or something
I made it use prefab, same issue
Im losing all hopes im starting to think its not possible to create hidge joint between 2 rigidbodies in runtime
Try disabling the collider(s) on the door when you attach it
To see if it's just colliding with near parts
It is possible, just tricky
I usually use ConfigurableJoint though, as it gives full control
But Hinge might be sufficient here
It's a joint that can do anything that the other joints can
It exposes all settings to you
Try this though, as a debugging step ^
Okay, next you can try adding a test script with OnCollisionEnter on the door
And have it Debug.Log what it collides with
collider.name
100% chassis thats sure
but whats the difference in collision when I attach it before game start and on runtime?
im making it child
Oh. That's probably the issue
You shouldn't make a rigidbody a child of another rigidbody
but when I do it before game starts, it works
Yeah I don't know why that is.
i will debug one thing wait
Just dont ignore this ^
It can lead into unexpected behaviour
im not ignoring just checking if its the case
Hmm, I always wondered why creating a Ragdoll with the builtin tool works fine with child rigidbodies.
Maybe it's related to this, since the ragdoll is created before playing
There's some oddity in it for sure
its not the reason
I moved it far away from chassis so it wont collide with anything
and its still broken
Hi, quick question. I am using TMP text MaxVisableCharacters to display a string like an old console, and am using linked overflow to split the string into 2 TMP text objects. Is there a way to get the string length of each individual part of the split string? When I do text.length, they both just display the length of the entire string.
And is it still a child of the other rigidbody?
no
wait ill record
take a look
god bot blocked video
stupid ai times
look now world is parent but its still buggy
i think that might be very hardcoded unity bug
You should paste your code btw.
only thing I can imagine now is create attached door with hinge joint and just hide/show it when needed
if (name == "LeftDoor")
{
// set parent to parent of parent
leftDoor.transform.parent = leftDoor.transform.parent.parent;
}```
I dont really know what to paste its like 500 lines of parts code
// if hinge joint attach to parent
if (part.hidgeJoint != null)
{
HingeJoint hinge = part.gameObject.AddComponent<HingeJoint>();
hinge.anchor = new Vector3(4.12f, -0.06f, -1.94f);
hinge.axis = Vector3.up;
hinge.connectedBody = gameObject.GetComponent<Rigidbody>();
hinge.connectedAnchor = Vector3.zero;
hinge.autoConfigureConnectedAnchor = true;
hinge.useLimits = true;
JointLimits limits = hinge.limits;
limits.min = part.hidgeJoint.min;
limits.max = part.hidgeJoint.max;
hinge.limits = limits;
hinge.useSpring = false;
hinge.useMotor = false;
// print all HingeJoint properties
}```
debug creating hinge joint
did you try to make configurable joint in runtime between two rigid bodies before?
maybe I'll give it a try later
Yeah, but you might run to the same issue
It's hard for me to figure out what is causing it currently
i think one reason is collision with parent/other rigidbody
before game start it's getting disabled automatically
and second reason is weird positioning that makes it spin
So if you disable the door's collider, it works fine?
I can't disable doors colliderb
What did you do here then?
joint requires rigidbody and when I remove collision I can't use it at all
I mean I can but not really for game use
I said "disable collider" not "remove collision"
I need working physical door not ghost door
Look I get that, but we are debugging here
I don't have collision as component
children boxes
So the door has children that have colliders?
yes
So disable those
that's what I did herr
and it didn't spin car
So what can we assume from that?
The child colliders are colliding with the chassis.
no not really
I tried few days ago with mesh collider without children but it's the same
Then the mesh collider was colliding with the chassis, lol
Again, stop saying that, I know that
You could call Physics.IgnoreCollision manually for each collider in the door and each collider in the chassis
I have option for that in my parts system
I'll try tommorow and let you know if it worked
Alright
but wait
what about this spinning problem
because collision is one problem
and this spinning thing is bigger problem
Um, by the way, I dont know if this would work, since I just debugged the angle or the normal and its perfectly perpendicular.
My issue is that the quaternion, which I am multiplying by, is a decimal in every place. This is the quaternion from the last screenshot
That is how quaternions look
And the normal in your screenshot looks, well, normal
Multiplying a vector with a quaternion will rotate that vector
So I dont see any issues here
I still can't figure out why its slowing me down. I did what navarone said, and I'm not sure if I need to do what you said because the normal is correct.
If you want something more intuitive, log the eulerAngles from the quaternion
Alright
Honestly a video of the issue could help
One sec
Here is my whole script just incase: https://hastebin.com/share/icumebuyur.csharp. And here is the video: https://streamable.com/extgfb
I also noticed another bug while recording this. if I jump while on a slope and land back on it, it sends me flying in the direction that the slope is going down towards.
You are still raycasting from transform.position instead of a bit above
I can't see the problem in the first part. Are you moving slower downhill?
Yes
Sorry this isn't a coding question/problem, and I couldn't find a channel that matches what this problem is
I did 2 hours of work, forgot to save and when I tried entering play mode, it's loading indefinitely. If I Alt+F4/task manage kill task I'll lose all my progress. What do I do XD
you probably have an infinite loop in your code so it probably is actually code related. but you'll have to force close unity
don't open it immediately after force closing it, you can recover the scene backup (which you can google how to do). but once unity opens that backup is gone
Your code saves regardless because it is unrelated to unity. A temporary scene should be made when you run play mode, so you havent lost all your progress.
I thought that initially. But in the past I changed something small, had the same infinite loop and when I force closed, and reopened Unity the changes I made were undone.
Thank you
As boxfriend said, the scene backup is gone when you open unity up. The code is 100% unrelated to unity though
is there any proper way to create a font or text renderer using just textures?
i have a bunch of textures for each character with their respective char code but there doesn't seem to be any nice way to create a font from them using tmp and default unity stuff
define proper, bitmap based text rendering has been a thing games have done for a long long time
proper as in not scuffed?
though you tend to be forced into mono spaced looking things and have no kerning
nah i have the data necessary for each character and their correct widths n all that
also scuffed is not much to go on
really you prolly just want to turn of compression and texture filtering
it can really only look good for blocky pixel art type characters
is there any way to convert bitmap fonts to ttf ?
i would try to convert it in the os, then feed the result to tmp
since without the SDF based fonts tmp generates from regular fonts things do not remain crisp at all sizes
and you missing out on features like outline and shadows
for my case that's unnecessary tho, everything is already styled as needed in each glyph
tis worth a shot
there are some tools like that https://github.com/benob/png_font_to_ttf
seemingly they just api call fontforge
yeah was looking at this
unfortunately i dont have a spritesheet and there's like 1000+ characters for this font style so i dont know if combining it into one would be the best
im starting to think it might just be better to write my own text renderer to fit this case lol
that may take a little while
Yes that is my problem. When aligning the movement to the slope, the velocity magnitude decreases.
Remember the original velocity. Normalize the slope-corrected vector, then multiply it by the original velocity
This will malfunction if you're on a 90-degree slope
actually, will it? I guess you'll be falling at that point anyway..
Like this? ```cs
Vector3 SlopeVelocityChange(Vector3 vel)
{
if (Physics.Raycast(transform.position, Vector3.down, out slopeHit, 1.5f, ~LayerMask.GetMask("Player")))
{
var currentVel = vel;
var rotation = Quaternion.FromToRotation(Vector3.up, slopeHit.normal);
var rotatedVel = rotation * currentVel;
var adjustVel = rotatedVel.normalized * currentVel.magnitude;
if (adjustVel.y < 0)
{
return adjustVel;
}
}
return vel;
}```
oh, you're rotating the vector, not projecting it onto a plane
I don't see any reason for the velocity to go down on slopes if you rotate the vector.
It essentially does the same thing as projecting on the slope
Projecting onto a plane reduces the magnitude of the vector. Rotating it doesn't.
Um, but it still is, so I just kinda assumed that they are practically the same thing
Log the magnitude of the rotated vector and see if it differs from the original magnitude.
It should not.
It does. When going up a slope the magnitude of the velocity sits around 10, while going down decreases more depending on how steep the slope is.
I'm talking about the magnitude of rotatedVel, not whatever your velocity winds up being at the very end.