#archived-code-general

1 messages · Page 270 of 1

simple egret
#

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)

crimson plaza
quaint rock
#

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

crimson plaza
simple egret
quaint rock
#

it depends on the person, though if brand new to things its prolly a good idea to follow some introductory learning content

wicked scroll
crimson plaza
quaint rock
#

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

pulsar holly
#

Where did you change the code?

simple egret
spring creek
crimson plaza
spring creek
lean sail
# pulsar holly Where did you change the code?

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

naive swallow
#

Instantiate returns a reference to the instantiated object. so you use that reference to access any public members

somber nacelle
naive swallow
#

Kinda wild to not understand the answer in #💻┃code-beginner and think going into the more advanced channels would explain it simpler

alpine harness
#

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.

cold parrot
#

just have it call the base.OnGUI() and append your custom properties after that.

alpine harness
#

oh gosh, that makes sense 🤦‍♂️ didn't realize there would be a custom editor associated with Toggle thanks!

kind fog
#

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

quaint rock
#

it matters alot since AssetDatabase is not something you can use in builds

kind fog
#

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 🤷

quaint rock
#

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

cobalt gyro
#
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
cobalt gyro
#
 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();
     }
 }```
tight ice
#

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

dense estuary
#

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.

somber nacelle
#

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

hexed pecan
#

Their current code does the same thing as projecting it on a plane

#

The FromToRotation part, I mean

dense estuary
#

So my issue is that it isnt normalized?

ruby nacelle
#

PostBattleUI Suggestions

cosmic rain
dense estuary
#

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.

cosmic rain
#

If input normalization is the problem, you need to normalize the actual input.

dense estuary
#

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.

thorny osprey
#

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

quartz folio
#
  1. If you're getting an NRE when you call GetComponent, then it sounds like obj is null
thorny osprey
#

try

loud wharf
#

I personally think that the get component should just throw when null.

thorny osprey
#

everything online says its supposed to just return null

#

but thats not whats been the case for me

loud wharf
thorny osprey
#

meant to be ty lol

spring creek
thorny osprey
#

it mightve just been an oversight and what vertx said, 3, could be happening

cosmic rain
spring creek
thorny osprey
#

but i wouldve thought that even if that was the case, trying getcomponent on a null obj would still return null

cosmic rain
#

You can't do null.GetComponent

#

That's invalid

loud wharf
#

That throws null reference exception.

cosmic rain
#

Because null doesn't exist.

cosmic rain
loud wharf
#

(The box is your obj in this example)

vocal bramble
#

Has anyone done Sebastian Lague's procedural generation tutorial I'm having some questions about it

spring creek
cosmic rain
vocal bramble
#

It kind of is but I'll try

cosmic rain
#

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.

vocal bramble
#

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

cosmic rain
#

You would need to generate each mesh and assign it to the collider.

#

Or use an approximation, like a sphere collider

vocal bramble
#

I'll look for some other ways cuz there can be like 2 million seeds and I need a pretty exact collider

cosmic rain
#

Why do you need a collider for all of them at the same time? Is that a quantum object in superposition or something?😅

vocal bramble
#

Oh no I mean that when a play randomly gets a seed there is that one collider for that one mesh

spring creek
vocal bramble
#

But there can (randomly) be many different maps/meshes that need their own collider

cosmic rain
vocal bramble
spring creek
spring creek
vocal bramble
#

My bad

cosmic rain
ruby nacelle
#

Hey! I opened a Thread so it's easier to find but if anyone gets a second I would greatly appreciate some advice

simple ridge
#

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?

latent latch
#

You could just disable the button

#

but otherwise I don't see a big deal

fallow veldt
#

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

craggy veldt
#

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?

latent latch
#

the last key should indicate the total time

craggy veldt
#

oh ok, thanks 👍

lost imp
#

hi, someone can help me pls ? How to fix error CS0246 ???notlikethis

#

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

fervent furnace
#

what is CS0246

#

no one will remember the error code

lost imp
#

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?)

mellow sigil
#

wtf is that mess

fervent furnace
#

do you know what is using static and using

#

they are obviously completely different

lost imp
#

ok

fervent furnace
#

also

static extern void Start();
#

and !ide probably

tawny elkBOT
opaque forge
#

is there a way to create a mesh through code but have it available in the editor without needing to press start?

lean sail
restive falcon
#

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

latent latch
#

Mathf.DeltaAngle probably

deft timber
#

Vector3.Angle

#

any will work

#

it's simple vector math

restive falcon
#

I've Vector3.angle and it doesnt work

deft timber
#
Vector3 dir1 = obj1.forward;
Vector3 dir2 = obj2.forward;

float angle = Vector3.Angle(dir1, dir2);
restive falcon
#

also its limited to 180 degrees? Im looking for a solution that will give me 360 degrees

deft timber
#

yes, it's from 0 to 180

restive falcon
#

this is for a radar im implementing in my game and I wanted to make a cone to represent where im currently looking at

latent latch
#

if you need the inverse just subtract from 360

deft timber
#

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

restive falcon
#

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

restive falcon
latent latch
#

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

restive falcon
latent latch
#

ah ok there is one

deft timber
restive falcon
deft timber
#

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

fervent furnace
#

offset the angle by 360 - the angle if < 0 or angle= (angle+ 360) % 360

deft timber
#

yea or this

#

althought atan2 with cross/dot should work just fine

restive falcon
deft timber
#

🤔

#

show how did you implement it

restive falcon
deft timber
#

add this

#

to the end

#
angleDegrees = (angleDegrees + 360) % 360;
restive falcon
deft timber
#

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

restive falcon
#

is there a voice chat we can use so that I can demonstrate this?

deft timber
#

no

#

just show the code

restive falcon
#

        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;
deft timber
#

the entire class

#

where do you use it

#

and the console debug log values

#

also transform.forward is a local vector

lavish frigate
#

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.

deft timber
#

if you need them in global vector, then use Transform.TransformDirection(Vector3 dir)

#

it transform local direction to world space

fervent furnace
#

tf.pos+=vec3?

lavish frigate
#

might i need to multiply that by deltatime?

deft timber
#

no, dont use +=

restive falcon
# deft timber where do you use it

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

deft timber
#

and adapt your code

lavish frigate
#

ah i realised now i shouldve kept track of original pos

#

is there a way to check if script is running in OnDrawGizmos?

deft timber
fervent furnace
#
val+=lerp(100,1000,fraction);
#

just float case, not vec3

lavish frigate
#

it works

deft timber
#

nice

lean sail
deft timber
#
private bool hasStarted = false;

private void Start()
{
    hasStarted = true;
}

public void OnDrawGizmos()
{
    if(hasStarted)
    ////
}
#

i guess?

#

if that's what they meant

lavish frigate
urban lintel
#

How do you architecture the following:

  1. I have a circle spawner script, which handles spawning some circles and parameterising them
  2. 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

deft timber
#

fire OnDeath event

#

subscribe to that even with all dependant systems

#

and so your stuff

#

update ui etc

urban lintel
#

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?

thick terrace
#

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

tardy crypt
#

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.

humble pumice
#

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).

cosmic rain
fossil shadow
chilly surge
fossil shadow
#

bleh

craggy veldt
#

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

bitter oar
#

!code

tawny elkBOT
bitter oar
#

i want the instantiated Object to move to the player

#

but this doesnt work

#

it just instantiates and then stays on position

next seal
#

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

deft timber
#

unles you have A LOT of objects it doesnt make a difference

#

A LOT meaning milions iterations

next seal
#

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?

deft timber
#

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

next seal
#

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

deft timber
#

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?

next seal
#

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?

deft timber
#

maybe in miliseconds

#

not something you will notice

next seal
#

yea but not only between scenes, im wondering if i should just let my array live in the scriptable object permanently

deft timber
#

performance-wise

next seal
#

as this data needs to be accessed from all kinds of sources

deft timber
#

but what is that array containng

#

what type of data

#

is it persitant data or does it change runtime

next seal
#

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?

deft timber
#

you have several approaches

#
  1. singleton + DDOL
  2. scriptable object
#

i'd avoid cloning the array

#

between each scene transition

#

bad idea

next seal
#

its game state bools basically

deft timber
#

then yea, make it a singleton and DDOL

next seal
#

I heard bad things about singletons

#

I am a new programmer and want to like adopt uhh healthy practices lol

deft timber
#

if used incorrectly they are "dangerous"

#

it is a helthy practice

next seal
#

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?

deft timber
#

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

next seal
deft timber
#

just really, do the singleton+ddol

#

for global managers

#

cleanest and fastest way

next seal
#

but you cant access them from other scenes right?

deft timber
#

you can

#

that's the entire point

next seal
#

YOU CAN? I thought thats illegal in unity

deft timber
#

do you know what's DDOL?

next seal
#

no not really

deft timber
#

do you see DontDestroyOnLoad?

next seal
#

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

deft timber
timid depot
#

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?

deft timber
#

it's like a additional scene

#

to your main scene

next seal
#

oh yea dont destroy on load ive heard of that

deft timber
#

so whenever you transition

#

your game manager and gold manager etc

#

will "follow"

next seal
#

but then how do your actual gamescenes access any of the universal systems? they cant refrence them right?

deft timber
#

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

next seal
#

does unity then say ah nevermind thats allowed?

deft timber
#

then you do GameManager.Instace.

next seal
#

because when i had a essential scene with my systems all my cross scene refrences werent working

deft timber
#

if you are in game scene, you can also do GameManager.Instance

next seal
#

ohhh with instance huh

#

i see

deft timber
#

and without a singleton

#

make your manager a singleton, and DDOL

timid depot
#

anybody?

next seal
#

yea no they were DDOL i just didnt know the shorting for it, i know dont destroy on load

deft timber
#

that's your job

deft timber
#

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

next seal
#

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

chilly surge
#

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.

next seal
#

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

chilly surge
#

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.

next seal
#

Yea my plan was just to keep it in memory because, I mean, performance but it really doesnt matter that much on small scale

fervent furnace
#

you should know what mmap is

next seal
chilly surge
#

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."

next seal
#

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

next seal
#

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

chilly surge
#

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"

next seal
#

Right exactly singletons are useful

chilly surge
#

Understand the pros and cons, weigh them yourself to see if they are relevant to your particular use case, then decide from there.

next seal
#

Right, thank you

fallow veldt
leaden ice
cold egret
#
  • 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?
hard viper
#

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”

meager pendant
#

which is more readable:

before or after

deft timber
#

neither

#

why don't you keep the dialogues in scriptable objects for example

#

or fill them through inspector

meager pendant
#

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

hard viper
#

to your question, if you have default arguments, you should use them.

But dialogue should be in scriptable objects, not code

deft timber
#

but why not in scriptable objects

#

imagine you wnat to add translation

#

to your game now

#

to other languages

hard viper
deft timber
#

on larger projects

#

for sure not designer friendly

#

not translation friendly

#

and just not dev friendly at all 😄

hard viper
#

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

meager pendant
deft timber
#

read again

#

what i wrote

#

and what @hard viper wrote

hard viper
#

we are literally explaining to you why it is a problem

meager pendant
#

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

hard viper
#

🤦‍♂️

deft timber
#

do whatever suits you then

hard viper
#

and… how much dialogue is going to be in your game?

#

if you have actual decision trees here, it sounds like a fair bit

meager pendant
deft timber
#

its not about the memory

#

its about work ethic

hard viper
#

it’s an architecture issue

deft timber
#

im out of this convo, explaining things like that makes my energy drained 😄 good luck tho 😄

chrome berry
#

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.

meager pendant
#

now that is a good reason to do it separately

#

that makes sense

hard viper
#

xaxup literally said that earlier lmao

chilly surge
# hard viper And if something shouldn’t be a singleton, it prompts the question of “why would...

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.

meager pendant
#

my bad

hard viper
hard viper
chilly surge
meager pendant
hard viper
hard viper
chilly surge
#

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.

deft timber
hard viper
#

that is true. but you need to be aware of what sort of committments you make with singletons

latent latch
#

this is why service locator pattern should be what's thrown around more and not singleton

hard viper
#

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

latent latch
#

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.

chilly surge
#

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.

hard viper
#

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.

hard viper
#

it is a committment

#

the lack of flexibility has pros and cons

chilly surge
#

And "now and forever" is an extremely harsh condition, you are essentially predicting the future, and that's what makes singleton bad.

meager pendant
#

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

hard viper
knotty sun
hard viper
#

if you don’t know or aren’t sure; then you can’t make a singleton

chilly surge
#

Exactly, and accepting that "we can't always predict the future" is part of the design process.

hard viper
#

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

chilly surge
#

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.

meager pendant
hard viper
#

don’t be a dick, steve

#

ad hominem is not cool

knotty sun
#

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

hard viper
#

then you should say that instead of name-calling

knotty sun
#

because it's always students that spout theoretical bullshit when they have no real experience

meager pendant
hard viper
meager pendant
hard viper
#

you catch more flies with honey than vinegar

deft timber
#

it's the same as when you are on your car driving lessons

#

you dont learn how to drive at all

meager pendant
#

you were once a student too steve

chilly surge
#

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.

deft timber
#

you only learn how to pass the exam

#

and then you learn the learn driving skills later when you gain road experience

meager pendant
#

ive never been in a cs class so i wouldnt know

knotty sun
chrome berry
meager pendant
#

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

hard viper
meager pendant
#

idk why they teach html in a cs class

hard viper
#

is html even turing complete?

deft timber
knotty sun
#

of course it's not, it's not even a programming language

meager pendant
meager pendant
#

not cs classes

hard viper
#

i ask because why the hell would you teach a non turing complete system for introductory cs

spring flame
cosmic rain
#

computer science is a wide field.

hard viper
#

i would not call web design cs

#

web design is more like art generated by text interpretted by a computer, than a programming language

deft timber
#

it's a sign language

knotty sun
#

the name says it all
Hyper Text Markup Language. I.e. nothing whatsoever to do with programming

meager pendant
#

"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."

cosmic rain
#

While writing html might not be part of cs, understanding how it works, might.

hard viper
#

an interpretter for html, yes

#

teaching html, no

meager pendant
#

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

cosmic rain
#

html and python aren't really interchangeble terms xD

knotty sun
meager pendant
deft timber
#

probably quite a lot

meager pendant
#

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

knotty sun
meager pendant
#

ok let me rephrase

#

you will be good at making websites look good and be well formatted

deft timber
#

by learning html?

knotty sun
#

still wrong

deft timber
#

no

meager pendant
#

ok well i dont make websites so im just speaking from what i know

deft timber
#

typical then 😄

meager pendant
#

but if i paid for a cs course and i got taught html id be pretty pissed

#

is all im saying

deft timber
#

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

meager pendant
#

my friend has been in a college cs course for years and they just went from html to javascript like months ago

deft timber
#

then he picked weird fucking college lol

meager pendant
#

no thats like all colleges

#

from what ive herad

deft timber
#

then you've heard wrong

cosmic rain
#

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?

knotty sun
#

yep, dumbed down the complete learning of cs and yet students still have the chops to pontificate

naive swallow
meager pendant
#

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

naive swallow
deft timber
#

then as i said multiple times, your friend picked some very special shit school

#

or you understood him wrong or he's lying

hard viper
#

or his friend doesn’t know that web design isn’t programming, which is the most likely

meager pendant
#

im pretty sure its the university of Sidney australia

naive swallow
#

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

meager pendant
#

ive gtg now

hard viper
#

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

fervent furnace
#

first language course is C

hard viper
#

every following teacher in the CS program would immediately realize their students didn’t know anything that they were expecting as prerequisite knowledge

hard viper
fervent furnace
#

i heard the first course will switch to python

naive swallow
#

Teaching cs concepts unrelated to actually making a program in a language

hard viper
#

i started with python. learn with training wheels. Then learned C, to learn the low level shit at play. Then C++ to build up

naive swallow
#

Like algorithms, assembly, design, etc.

hard viper
#

then other classes were purely theoretical

knotty sun
slow shoal
#

yo anyone is here?

deft timber
#

stop spamming and crossposting

hasty canopy
#

Wish I had dontasktoask copied on my clipboard

deft timber
#

not hard to remember

slow shoal
deft timber
#

yes

slow shoal
#

How so

hasty canopy
deft timber
#

crossposting is against the rules

slow shoal
#

I realized the problem i was facing wasn't beginner coding

deft timber
#

not related, don't need excuses, just saying ;p

thin aurora
deft timber
#

still, cannot make a good website just with HTML

#

that was the point

#

of entire conversation

#

atleast css+js

surreal blaze
#

depends what it's for

thin aurora
#

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

deft timber
#

yup

slow shoal
#

Alright

knotty sun
thin aurora
#

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

knotty sun
#

there is no 'one size fits all' solution to any computer system implementation

deft timber
#

noone told there is

knotty sun
#

that's what frameworks profess to be

fossil shadow
# deft timber that was the point

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?

fossil shadow
# meager pendant no thats like all colleges

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.

fervent furnace
#

i think they will teach you full stack instead of just front end

west lotus
knotty sun
dense estuary
icy rock
#

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?

dense estuary
icy rock
#

ill send the script soon

spring creek
#

Mkv requires a download for mobile (maybe desktop too?)

icy rock
#

oh sry

#

heres the script

spring creek
# icy rock

Haha, you're gonna hate me, but !code
That's just a download link too

tawny elkBOT
icy rock
#

does this work?

spring creek
icy rock
#

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)

spring creek
#

It looks like it would be in a different script if that helps

rigid island
#

I think they mentioned UI butto's onclick

spring creek
#

Ahhh ok

#

Maybe show the inspector for that button

rigid island
#

what is Multiplier amount, and why are u not debug.logging these values to make sure they are correct

icy rock
#

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

rigid island
spring creek
icy rock
#

i am stupid you were right i do run it twice sorry

rigid island
#

thats good, at least its solved now yes

icy rock
#

i have coded the entire day so i guess my brain has just melted and my last braincells are gone

rigid island
#

haha yeah,good to give the brain time to breathe once in a while

icy rock
#

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

rigid island
#

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

heady iris
#

if the problem is with anything other than the player pref values, then this code is the wrong place to look

icy rock
#

cause when i press "r" money and money per second should return to 0 but they dont

heady iris
#

this code resets your player prefs

#

it doesn't do anything else

icy rock
#

yes i know but playerprefs is my saving system i can try to take a bigger screenshot

heady iris
#
int x = 123;
PlayerPrefs.DeleteAll();
print(x); // logs 123
#

I know it's your saving system

icy rock
#

does this change anything

rigid island
#

why would money per second return to 0 if you're only changing playerprefs

heady iris
#

Why do you think resetting the playerprefs values is going to do anything to MoneyPerSec?

heady iris
icy rock
#

before just the money per sec was not resetting but after that line of code it did

heady iris
#

Your code does literally nothing to change MoneyPerSec after the game starts

#

Of course MoneyPerSec isn't changing

icy rock
#

this is my upgrade code when i buy shit and it updates after every purchase and sets the playerprefs to the desired value

rigid island
#

!screenshots

tawny elkBOT
#

mad No

Be mindful, if someone requests your code as text, don't send a screenshot!

heady iris
#

Yes. It sets the player prefs values.

rigid island
heady iris
#
PlayerPrefs.SetInt("foo", 100);
int val = PlayerPrefs.GetInt("foo");
PlayerPrefs.SetInt("foo", 0);
print(val);
#

What value does this log?

rigid island
#

Im gonna go ahead and say cause they're static xD

icy rock
icy rock
#

100

heady iris
#

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

icy rock
#

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

heady iris
#

What value is written into the player preferences?

icy rock
#

five

heady iris
#

Why?

#

Where did I ever assign a 5 to x?

icy rock
#

+= 5

heady iris
#

And what was the value of x on that line?

#

before x += 5 was evaluated

icy rock
#

zero

heady iris
#

Why?

rigid island
heady iris
#

PlayerPrefs.SetInt("foo", 0);

How does this line of code set x to zero?

icy rock
#

oh

rigid island
#

100+5 is not 0

heady iris
#

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)

rigid island
#

yup, you only load it on Start

heady iris
#

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.

heady iris
#

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

icy rock
#

its baisically the code that i stole but its working

heady iris
#

then it does something different

icy rock
#

can you take a look since i have a slight feeling you understand c# better than me

heady iris
#

if you can point me to the specific part that shows the code, yes

icy rock
#

did you get the vid?

heady iris
#

just post it here.

icy rock
#

didnt know you could send yt links here

heady iris
#

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

icy rock
#

yes but that is not working for me

#

its just a way for me to delete all of my progress before i release it

heady iris
#

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

meager pendant
#

yo

#

how do you use this

#

in a script

#

i have tried google

steep herald
#

was google graced with a better description

heady iris
#

this looks like Visual Scripting

rigid island
earnest gazelle
#

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)

meager pendant
heady iris
#

consider reading the visual scripting documentation

rigid island
heady iris
#

assuming you're actually trying to use visual scripting

spring creek
# meager pendant

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?

topaz galleon
#

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

upper pilot
#

    [SerializeField] public Sprite CharacterSprite;
    [SerializeField] public RuntimeAnimatorController IdleAnimation;
    [SerializeField] public RuntimeAnimatorController AttackAnimation;

Is that a correct way of setting up CharacterSO animation/sprite?

heady iris
#

there's no need for [SerializeField] on a public field, mind you

upper pilot
#

doing it for consistency 😄

#

I will take that as a yes 😛

rigid island
#

I generally avoid public

#

SerializeField if you need inspector and do a prop

#

[SerializeField] private Sprite characterSprite; public Sprite CharacterSprite => characterSprite;

heady iris
#

this looks like a data container

#

I often just use fields in that case

#

all those methods calls have to add up eventually

timid depot
#

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

#

🙏🙏🙏

topaz galleon
#

id take that as an inaficient way

timid depot
#

can I somehow make prefab of component?

steady moat
steady moat
timid depot
#

or for example make door prefab and copy component from prefab

steady moat
#

Just make an a whole prefab

timid depot
#

it wont work for me

#

it would require rewriting whole car parts code

steady moat
#

If it is what it takes

timid depot
#

why cant I copy component from prefab

#

I dont get it

upper pilot
dense estuary
#

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:

rigid island
dense estuary
#

I tried using ProjectOnPlane, but it does the exact same thing.

hexed pecan
#

Yeah as I said before, your FromToRotation does exactly what ProjectOnPlane would

#

While keeping the magnitude

hexed pecan
#

And where does hit come from?

rigid island
dense estuary
hexed pecan
#

Without this code, does it go down in a stair-like movement?

#

Forward, down, forward, down

dense estuary
#

Yes

#

He looks like he is hopping down the slope

hexed pecan
#

How are you checking ground?

#

That's probably relevant here

dense estuary
hexed pecan
#

Did you make sure that the spherecast hits downward slopes too?

#

Like does it extend downwards at all

dense estuary
#

Yes

rigid island
#

but yes Raycast for slope is diff from grounding ( this is important)

dense estuary
#

So I shouldnt use the ground check for slopes?

rigid island
#

nope

dense estuary
#

Okay, I'll be sure to change that once I get to my PC.

hexed pecan
#

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

tacit solar
#

hi! im looking for a way to get the angle between objects velocity and a plane when they collide

rigid island
#

or SignedAngle

hexed pecan
#

Let's just pretend that the green is a capsule

#

Sphere doesn't have to start that high, I exaggerated a bit

tacit solar
rigid island
hexed pecan
#

collision.normal/hit.normal

tacit solar
#

alr ill try it out

#

am i missing something?

spring creek
#

Not a collision

#

OnCollisionEnter passes a collision

rigid island
#

triggers arent exactly the same as collisions

timid depot
#

ok thanks a lot!

dense estuary
hexed pecan
#

Not sure what you mean

#

Is that a question?

tacit solar
hexed pecan
rigid island
#

triggers dont have contact points

#

You can do GetClosestPoint iirc though

hexed pecan
#

I though you have a solid collider

hexed pecan
tacit solar
dense estuary
# hexed pecan Not sure what you mean

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.

tacit solar
#

im pretty sure its moving to fast to get detected

rigid island
#

also put NeverSleep

hexed pecan
hexed pecan
dense estuary
#

Cause I get shooting it slightly ahead of the player's feet, how do I know how far?

hexed pecan
hexed pecan
tacit solar
hexed pecan
#

But I can't give you any accurate numbers, you gotta try yourself

tacit solar
#

its attached to the parent

hexed pecan
#

@dense estuary So the distance from the sphere start to the bottom of the character, PLUS some value like 0.25 - 0.5

rigid island
#

you just said you had a rigidbody

tacit solar
#

rigidbody is on the parent object

rigid island
#

the parent of what?

hexed pecan
#

@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?

rigid island
tacit solar
rigid island
#

huh why is the collider on the child

tacit solar
#

because i have multiple colliders

#

ok give me a sec ill try to explain

rigid island
#

so did you change the rigidbody collision detection mode first?

#

to see if work

dense estuary
tacit solar
#

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

tacit solar
#

sooo i should put rb on my walls?

spring creek
#

The collision messages are sent to both objects involved. So if one senses it, both will trigger

heady iris
#

Simpler colliders tend to be more reliable, yeah

tacit solar
#

doesnt seem to fix it sadly :(

#

what about interpolate?

heady iris
#

Interpolation is a visual thing.

tacit solar
#

oh, ok

heady iris
#

that doesn't match my understanding. using sweep-based collision detection on an unmoving object is pointless

hollow isle
#

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?

heady iris
#

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.

hollow isle
#

like this?

heady iris
#

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

hollow isle
#

one moment

#

Everything uniformly scaled

#

in the scene view it's attatched to the gun properly

timid depot
#

how can I with script copy one component to another gameobject?

#

in runtime

hexed pecan
#

You could instantiate a prefab that has that component, though

#

And add it as a child

heady iris
#

Do their settings match, and are they moving together?

hexed pecan
#

@timid depot Or you can add a fresh component with AddComponent and copy values to it manually

heady iris
#

they're having problems with hinge joints, apparently

timid depot
#

ill check that but im not sure if it work

#

beacuse objects like vector3 will just copy references

#

need to copy each value separately

tacit solar
hollow isle
#

yeah I believe they're moving together and their settings match.

#

I think I know what the problem is though

tacit solar
hollow isle
#

the UI camera only sees ui, but the gun is parented to the other camera

tacit solar
#

cuz im pretty sure i can see it bounce off for a split second before freezing in place

hexed pecan
#

How exactly is it wrong currently?

#

Does it seem to stick too early?

hexed pecan
tacit solar
#

yeah a gap like this

#

but again i can see it hitting the wall and then bouncing back

#

for a frame maybe

hexed pecan
#

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

tacit solar
#

sounds like it might work

#

ill make sure to try it

#

thank you!

timid depot
#

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?

tacit solar
hexed pecan
#

Yeah, maybe move it forward only by the length of the tip?

#

velocity.normalized * tipLength

#

Or something

timid depot
#

Im losing all hopes im starting to think its not possible to create hidge joint between 2 rigidbodies in runtime

hexed pecan
# timid depot

Try disabling the collider(s) on the door when you attach it

#

To see if it's just colliding with near parts

hexed pecan
#

I usually use ConfigurableJoint though, as it gives full control

#

But Hinge might be sufficient here

timid depot
#

whats configurablejoint?

#

I can make door with it too?

hexed pecan
#

It's a joint that can do anything that the other joints can

#

It exposes all settings to you

hexed pecan
timid depot
#

yeah now car doesnt jitter

#

hmm interesting

hexed pecan
#

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

timid depot
#

100% chassis thats sure

#

but whats the difference in collision when I attach it before game start and on runtime?

#

im making it child

hexed pecan
#

You shouldn't make a rigidbody a child of another rigidbody

timid depot
#

but when I do it before game starts, it works

hexed pecan
#

Yeah I don't know why that is.

timid depot
#

i will debug one thing wait

hexed pecan
#

It can lead into unexpected behaviour

timid depot
#

im not ignoring just checking if its the case

hexed pecan
#

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

timid depot
#

its not the reason

#

I moved it far away from chassis so it wont collide with anything

#

and its still broken

chrome summit
#

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.

hexed pecan
timid depot
#

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

hexed pecan
#

You should paste your code btw.

timid depot
#

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

timid depot
#

maybe I'll give it a try later

hexed pecan
#

Yeah, but you might run to the same issue

#

It's hard for me to figure out what is causing it currently

timid depot
#

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

hexed pecan
#

So if you disable the door's collider, it works fine?

timid depot
#

I can't disable doors colliderb

hexed pecan
timid depot
#

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

hexed pecan
#

I said "disable collider" not "remove collision"

timid depot
#

I need working physical door not ghost door

hexed pecan
timid depot
#

children boxes

hexed pecan
#

So the door has children that have colliders?

timid depot
#

yes

hexed pecan
#

So disable those

timid depot
#

and it didn't spin car

hexed pecan
#

So what can we assume from that?

#

The child colliders are colliding with the chassis.

timid depot
#

no not really

#

I tried few days ago with mesh collider without children but it's the same

hexed pecan
timid depot
#

so what can I do

#

I need collision

#

I don't need ghost door

hexed pecan
#

You could call Physics.IgnoreCollision manually for each collider in the door and each collider in the chassis

timid depot
#

I have option for that in my parts system

#

I'll try tommorow and let you know if it worked

hexed pecan
#

Alright

timid depot
#

but wait

timid depot
#

because collision is one problem

#

and this spinning thing is bigger problem

dense estuary
#

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

hexed pecan
#

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

dense estuary
#

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.

heady iris
#

If you want something more intuitive, log the eulerAngles from the quaternion

hexed pecan
dense estuary
#

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.

hexed pecan
#

You are still raycasting from transform.position instead of a bit above

hexed pecan
rapid stump
#

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

somber nacelle
#

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

lean sail
rapid stump
lean sail
odd arrow
#

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

quaint rock
odd arrow
#

proper as in not scuffed?

quaint rock
#

though you tend to be forced into mono spaced looking things and have no kerning

odd arrow
#

nah i have the data necessary for each character and their correct widths n all that

quaint rock
#

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

ashen yoke
#

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

quaint rock
#

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

odd arrow
#

for my case that's unnecessary tho, everything is already styled as needed in each glyph

ashen yoke
ashen yoke
#

seemingly they just api call fontforge

odd arrow
#

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

ashen yoke
#

that may take a little while

dense estuary
heady iris
#

This will malfunction if you're on a 90-degree slope

#

actually, will it? I guess you'll be falling at that point anyway..

dense estuary
# heady iris Remember the original velocity. Normalize the slope-corrected vector, then multi...

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;

}```

heady iris
#

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.

dense estuary
#

It essentially does the same thing as projecting on the slope

heady iris
#

Projecting onto a plane reduces the magnitude of the vector. Rotating it doesn't.

dense estuary
#

Um, but it still is, so I just kinda assumed that they are practically the same thing

heady iris
#

Log the magnitude of the rotated vector and see if it differs from the original magnitude.

#

It should not.

dense estuary
heady iris
#

I'm talking about the magnitude of rotatedVel, not whatever your velocity winds up being at the very end.