#archived-code-general

1 messages ยท Page 105 of 1

dusk apex
#

Another example would be converting angles to a direction such as forward and losing data on the roll - you'd know where it's pointing but not necessarily it's up direction.

#

Likely so, good luck.

lean sail
#

thanks for trying to help through this as well, such a weird bug

swift falcon
#

I am a bit less experienced with 3D physics and have been trying to make this code work properly

    public class Hand_Controller : MonoBehaviour
    {
        [Header("Physics")]
        public Transform controller;
        public float maxForceRange;
        public float handMovementForce;

        private new Rigidbody rigidbody;

        public void Start()
        {
            rigidbody = GetComponent<Rigidbody>();
        }

        public void FixedUpdate()
        {
            Vector3 offset = controller.position - transform.position;
            float distance = offset.magnitude;
            offset = offset.normalized;

            rigidbody.AddForce(offset * Mathf.Lerp(0, handMovementForce, Math.Min(1, distance / maxForceRange)), ForceMode.Force);

            Quaternion rotation = controller.rotation * Quaternion.Inverse(rigidbody.rotation);
            Vector3 torque = new Vector3(rotation.x, rotation.y, rotation.z) * rotation.w;
            rigidbody.AddTorque(torque, ForceMode.Force);
        }
    }

everything works fine except the movements are extremely springy, and will either result in the object constantly bouncing around the target point or shaking right at it. Rotation behaves significantly better, but still suffers from the same issue

lean sail
# dusk apex Likely so, good luck.

sorry for reply after convo over, i think u would be interested in knowing...
restarting unity fixed it kekwait i swear this might be a bug because my pc shut down unexpectedly last night

hollow stone
swift falcon
#

I'm aiming at a relatively physics based system, wouldn't resetting velocity mess up handling of heavy objects?

#

assuming that when a heavy object grabbed forces are applied to it as well

hollow stone
#

Yeah, something like springs would work better.

#

Or add some dampening perhaps that mitegate when it's close to target.

lean sail
#

i feel like a damper would be needed regardless

hollow stone
lean sail
#

springs will still cause the issue of bouncing around a target, or shaking at it. Dampers are specifically for "object constantly bouncing around the target point or shaking right at it"

#

yea

#

im not entirely sure what the use case of this is, which is why i didnt suggest a spring

swift falcon
#

hmm, taking current speed into consideration and dampening it when closing on the target does sound like a good idea

#

whats your suggestion on how picking up heavy objects in this case would function then? attaching spring joints between the hand and contact point on the object?

hollow stone
#

Spring between your vr hand and physical. Your carry force is in the spring force.

swift falcon
#

using unity's physics component spring instead of my code? am I understanding you correctly? just a bit sleepy, may be misunderstanding

lean sail
#

the spring force, if the object is attached to your hand, will drag the object directly towards your hand

#

it depends on how the movement is supposed to look

#

when u pick up an object, is it flying to your hand? or is it supposed to be contacting your hand and never leaving

swift falcon
#

yeah no I'm only interested in physically picking up objects, launching them towards the player is done separately

#

imagine a player putting their hand on a crate and trying to lift it, I simply want some weight to exist, not completely inertia-less handling

#

not boneworks level nauseating physics, just some weight for a nicer feeling

hollow stone
#

With weight you mean hands won't match real world hands position?

swift falcon
#

yeah

#

thats what I'm trying to achieve

#

separate controller and hand objects

lean sail
#

a spring could help then but u would have issues with customizing the spring force. Its only 1 force, not a customizable force in every axis

swift falcon
#

the force should dynamically adjust to a certin point to avoid the distance becoming too long and the player losing conrol

#

again, been doing it with my code

#

I'll add dampening and check how it looks, gonna make grabbing later once I got hands themselves working

#

the best way to add ranged grabbing is probably via alyx-like ballistic trajectory launching, they aren't super complicated to calculate and keep the physics feeling

#

should be good as long as I don't forget 7th grade physics

lean sail
#

trajectory sounds odd, why not just a raycast

swift falcon
#

wdym

#

I am talking about picking up objects from afar

lean sail
#

unless u mean something else, not really sure what alyx-like ballistic trajectory launching means

#

i just mean if u have a trajectory height, it might hit something unexpected along the way

swift falcon
#

games usually do it via simply pulling them towards the player

lean sail
#

oh u mean to send the object to the player, not detect the object i get it

#

yea thats just 1 formula to calculate

swift falcon
#

a bit more complicated, but imo the best way is to give the player some more control. Launch the object when a player pressed a grip button and makes a sharp movement, with the object trying to make the trajectory match with the pull direction

#

could potentially allow for curve ball grabs but thats just cool if the player pulls it off

night harness
#

Anyone have a suggestion on how I can get all children of a parent including children of children etc.

#

like every single object that might be under an object

night harness
#

I couldn't put together in my head how I would set that up

potent sleet
#

there a reason to need it to do it this way?

night harness
#

Yes and no

#

longterm probably not

#

Looking to combinebatch a ton of instantiated objects

potent sleet
#

GetComponentsInChildren iirc does search all children and grandchildren etc

night harness
#

How would I go about doing it recursively?

potent sleet
#

This method checks the GameObject on which it is called first, then recurses downwards through all child GameObjects using a depth-first search, until it finds a matching Component of the type T specified.

#

depth-first search meaning it should be able to reach

night harness
#

i see i see

#

ok lemme try and cook

lean sail
#

you dont even need to do it recursively yourself, yea the method gives u every child but also it gives u the parent too

#

since its DFS, its guaranteed that the parent is the first element so you can remove that or skip it if u want. If they change how it searches then that logic breaks

potent sleet
#

it's easy too

#
  [SerializeField] private List<Transform> familyTree = new();
    private void Awake()
    {
        familyTree = GetComponentsInChildren<Transform>().Skip(1).ToList();
    }```
night harness
#

yeahhh it helped a ton

#

tyvm

topaz gate
#

Guys i have a system to set my UI toggle to on if my int is 1 and off if it is 0 but now i cant change the Toggle value in game pls help

#

my Up date function

#

private void Update()
{
if (Mute == 1)
{
MuteToggle.isOn = true;
}
else
{
MuteToggle.isOn = false;
}

    if (MuteToggle.isOn == true)
    {
        Mute = 1;
    }
    else
    {
        Mute = 0;
    }

    
    
}
knotty sun
primal wind
#

also !code

tawny elkBOT
#
Posting code

๐Ÿ“ƒ Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

topaz gate
topaz gate
knotty sun
topaz gate
#

Where else tho bc i am using player prefs and i want to be able to change the value in the editor via a int or smthing that works with player prefs like a string or float or int

primal wind
#

convert the bool to an int

#

it's technically an int under the hood anyway (at least it is in C, probably is the same in C#)

topaz gate
#

yeah but i cant go PlayerPrefs.GetBool

knotty sun
primal wind
#

I don't remember if you can cast it to int but you can do PlayerPrefs.SetInt("key",yourBool ? 1 : 0)

#

At least i think you can use ternary operators in methods

lean sail
primal wind
#

Yeah, I'm never too sure since i basically never used it like that

lean sail
#

also the bool in C is kinda different from bool in C#, u cant do the exact same logic

#

idk how to word that, u can do the same things obviously by converting. But not the same syntax if thats a better word

primal wind
#

Yeah i forgot that bools technically don't even exist by default

#

C really confused me

knotty sun
#

in c and c++ a bool is a concept. In c# a bool is a type

lean sail
#

like in C/C++ you can add a bool to a number directly

topaz gate
primal wind
#

i think there is a method that allows that but i forgot it. Otherwise you can use another ternary operator yourBool = PlayerPrefs.GetInt("key") == 1 ? true : false;

primal wind
#

what does the error say

knotty sun
#

and the isOn ?

prime sinew
#

true or false is a boolean

primal wind
#

Oh yeah

#

so it should be Mute.isOn

topaz gate
#

MuteToggle.isOn?

primal wind
#

yes

topaz gate
#

Wait what if i add a bool that is called MuteBool and give that bool the same values as the toggle?

knotty sun
#

no

topaz gate
#

Ok nvm

primal wind
#

Why would that help

topaz gate
#

Idk Wytea said i need a bool

knotty sun
#

because he does not understand the difference between reference types and value types

primal wind
#

MuteToggle.isOn is one

topaz gate
#

Oh ok I have no errors now ill let you know if it works

#

Okay it half worked

#

The toggle saved but the audio didnt mute as the toggle is on

#

Wait nvm didnt work at all

#

the toggle is always on nomatter what'

swift falcon
#

I can calculate the force necessary, but I dont know after which point to stop acceleration and start dampening it instead

#

theoretically speaking the dampening force could be static, but I am still unsure if it will prevent bounciness

topaz gate
#

Wait its only showing and loading data from the first save you cant change the value and save it will stay at what you had it as first

thin aurora
#

I don't understand why you want us to spoonfeed your whole project if you clearly have no clue how to program

#

No offence, but please learn basic c# first, before you even consider Unity

#

We could help you now, but we both know you will be back within the hour with another basic question that any tutorial would cover

prime sinew
knotty sun
#

he does seem to do this, if he doesnt like/understand the answer in one channel he just posts in another. He even had this is advanced yesterday

#

his player prefs issues, which should have taken 5 minutes has been going on for days

thin aurora
#

Imagine the stuff he would have been able to learn in that time

knotty sun
#

if he could be arsed, which apparently he cannot

thin aurora
#

Sure, I would love to start on my amazing mod, but I've been looking at various articles and videos for the past three weeks because I know the moment I even consider starting it I would be stuck because I have no clue how stuff works

#

(Not Unity btw, but (G)ZDoom and Zscript)

knotty sun
#

As with anything, you first build up a conceptual understanding of what you want, then you dive into the nitty gritty of 'how do I do that'

mossy minnow
#

hey, so im trying to add perlin noise to a grid of cells.

for (int x = 0; x < gridArray.GetLength(0); x++)
        {

            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                float n = Mathf.PerlinNoise(x, y);
                n = (n + 1) / 2;
                c.buildCost = n;
                GameManager.GM.cellList.Add(c);```
this is my current method, though when i try it, every single cell has the same cost
cosmic rain
#

Perlin noise takes a value between 0 and 1. Then it repeats.

mossy minnow
#

its always 0.7326366

mossy minnow
cosmic rain
swift falcon
#

hmm, still can't figure this out. Directly setting velocity to difference between positions divided by fixedDeltaTime works just fine, obviously, but then hands are completely weightless. Still can't figure out the bounciness with forces

#

(talking about VR hands)

rancid hornet
prime sinew
#

what are you expecting to happen, and what is happening instead

#

is this some chatGPT code

#

oh you're crossposting

rancid hornet
#

im sorry yeah im just trying to meet a deadline

prime sinew
#

so is this chatGPT code?

rancid hornet
#

yes most of it

prime sinew
#

if your plan was to just get some ai generated code, find out it doesnt work right off the bat, and have other people come in and fix it for you, I'm out

rancid hornet
#

no its not that i lost sleep over this

#

i just dont know how to explain best im gathering screenshots

swift falcon
#

don't trust AI to write your code unless its a helper like copilot that just quickly completes or suggests you lines

#

ChatGPT doesn't understand anything, its just a text generator

restive ice
#

How do you guys deal with naming private properties?

prime sinew
#

@rancid hornet you should open a thread before you start posting all those screenshots

dusk apex
swift falcon
#

usually toss an underscore as the first symbol of their name

restive ice
#

I like to use properties over fields, but the only thing I dislike is how private properties generally should start with PascalCase

rancid hornet
#

ok so is anyone down to help?

prime sinew
dusk apex
swift falcon
rancid hornet
#

alright fair enough

restive ice
swift falcon
#

well yeah

#

thats what Im suggesting

restive ice
#

but properties start have Pascalcase too

dusk apex
swift falcon
#

yeah, private props also should use pascal usually

restive ice
#

so public SomeProp { get; set; } and private SomeProp { get; set; } look the same.

swift falcon
#

perhaps use _PascalCase?

prime sinew
#

why not _SomeProp

rancid hornet
#

im actually at work on break rn so im gonna continue this in about 6 hours

dusk apex
#

What they've suggested - underscore.

restive ice
rancid hornet
#

sorry guys for the inconvinence and for being a disgrace ๐Ÿ˜”

swift falcon
prime sinew
swift falcon
#

yeah just tell the thing to fuck off and disable that particular warning

dusk apex
restive ice
swift falcon
#

why are you making it a property btw?

#

and not just a field

restive ice
#

because it may have some additional logic

swift falcon
#

props make sense if you want for example to make it public to read and private to set

#

ah, you didnt write virtual so I assumed that it didnt

#

gotcha

#

yeah you still should go with the underscore, readability matters more

swift falcon
#

forces are what makes it hard

soft shard
# restive ice because it may have some additional logic

I think if its private, "additional logic" could make it a function, if its public where you need to validate the data as "additional logic", a public property could make sense, unless its a requirement of your internships code structure

restive ice
#

it also feels weird to do something like this
because now in the class itself as it's now a question of 'do i need a field or a prop'

#

and then there's this which just screams 'please make me autoproperties'

swift falcon
#

...? why, just why

#

you're making a lot of unnecessary properties

restive ice
#

no those four properties are neccessary, i need them to be available publically

#

but i don't want other classes to set them either.

#

hence the properties, which literally do that with { get; private set; }

#

tell me what's unnecessary about that

foggy dragon
dusk apex
#

Sounds intuitive but is it necessary? Should others really only have read access to these members (or any access at all)? They can already be acquired using GetComponent with reference of the instance. Caching sounds great but depending on how often it's used, a get component would suffice.

restive ice
foggy dragon
restive ice
dusk apex
#

Privatizing the fields makes sense as you're wanting to cache but not expose the members. However exposing component caches is usually for convenience or design-integrity purposes and not necessarily "necessary" - often associated overengineer.

crude mortar
#

If your concern is that public Rigidbody Rigidbody { get; private set; } does not have some indicator that the setter is private, I think you are overthinking things..

swift falcon
#

iirc like this

dapper sparrow
#

Do anyone know if it s possible to center the pivot point of an object through some coding lines?

thin aurora
#

So what he had is correct

thin aurora
#

I would say what he's doing is the perfect way, code style and everything

#

Then again, I'm starting to wonder what code to actually look at since there are two different styles

hybrid relic
#

we not gonna fix the bad code some ai gave you, go and learn on how to code and then actually code

#

then we gonna help you cuz by then you know how to fix it by yourself with some help

#

but like you want us to fix the code for you

#

not gonna happen

inner pine
#

oh no, are people asking humans to fix AI-generated code? Why can't they ask the AI again?

humble hinge
#

lol

rain minnow
pearl cypress
#

Is it possible to create an instance renderer that doesnt take a full matrix but instead a buffer of 2d positions? (Using a custom shader offcourse.)
If yes, does anyone have an example in code of this, I can only find how to do it with full 4x4 matrices and not using custom data

Thanks guys

noble mortar
#

Hello, someone on my development team wrote a script to assign keys to certain images. I was wondering if there was a better way to do so.
https://gdl.space/ayorotuqux.cs

plush sparrow
#

anyone knows how to implement a replay system, where it shows how you died as a gif or something

swift falcon
leaden ice
pearl cypress
#

@steady moat I dont think that works for instance data

green oyster
#

Speaking of dictionaires, im having a dictionary problem, ```cs
public AudioClip PRsound4;
public AudioClip PRsound5;
private Dictionary<string, AudioClip> musicDatabase = new Dictionary<string, AudioClip>().Add("S1", PRsound1);

leaden ice
#

Use awake or start to do it

green oyster
heady iris
#

also, calling Add like that wouldn't make sense anyway; it returns void

#

you can, however, use an object initializer

#
var numbers = new Dictionary<int, string>
{
    [7] = "seven",
    [9] = "nine",
    [13] = "thirteen"
};
#

stolen straight from the C# docs

#

note that this still doesn't refer to other fields.

green oyster
#

ah ok

#
        PulseRifleSoundsList = new List<AudioClip>(){PRsound1, PRsound2, PRsound3, PRsound4, PRsound5};
        PulseRifleSoundsList.ForEach(AudioClip clip, index => PulseRifleSoundsDict.Add("S"+index, clip));
``` Also another issue but where have i gone wrong here
#

tryna do a for each lambda expression

steady moat
# noble mortar Hello, someone on my development team wrote a script to assign keys to certain i...
  • There is no usage of OOP. Group things together. (UpImage, UpInput, Up)
  • GetComponent should never be called in an Update function.
  • Using string for binding is weak. Use enumeration instead.
  • The naming convention is not uniform private static SpriteManager instance; and private bool ImageChange=true;
  • There is static variable same if we are in a Singleton. public static bool CanChange = false;
  • The spacing is not uniform. ImageDelay <= 0&&CanChange
  • The mapping should be done with Serialized Data such as ScriptableObject
  • The UI should try to not be refresh every frame, but use events to refresh its state only when necessary.
    Do not forget the usage of Atlas
steady moat
heady iris
#

also, I believe you need parentheses for multiple arguments

#

FooList.ForEach((foo, bar) => Debug.Log(foo + " " + bar));

#

wait

green oyster
#

ah i see, alr thansk lol

heady iris
#

is there an overload of ForEach that provides two arguments?

green oyster
#

im sure there msut be right, 2 args

#

1 is for index, and then the other is the item

heady iris
#

false

#

it takes an Action<T>

#

Action being a function that has a void return type

#

so, it accepts a function that has one argument of type T

#

There's probably something in LINQ for that.

green oyster
#

for real? damn, i guess i will just do a List.getIndexOf(item)

#

to get the index

heady iris
#

O(n^2) moment

swift falcon
#

tried writing some dampening, the issue still persists, but in a different shape. All of my attempts result in the hand moving extremely slowly and having issues when changing directions, sometimes going orbiting. Lowering dampening power speeds the hand up but significantly worsens the orbiting and redirection issue

long pilot
#

Hello, I have issues with Admob. It works fine on Android but crashes everytime at startup on ios. What can I do to fix it?
Here is the AdManager code. I don't know what to do anymore tried everything online. It workes fine without admob plugin.

Error: libc++abi: terminating with uncaught exception of type Il2CppExceptionWrapper

static matrix
#

This is fine

#

let me look deeper

#

guys
im going
to read the documentation

green oyster
#

ok good luck

steady moat
static matrix
#

probably

#

lots of objects

steady moat
#

You cannot have 12k batches...

#

Use appropriate batching and culling method.

static matrix
#

that might have been that one frame

#

it seems to only go up to 9k

steady moat
#

Only 9k...

#

Do you even know how much this is.

#

You should target 2k for pc.

green oyster
#

why is temperature in lights in kelvin?

#

who decided on this metric

static matrix
#

ok how do i reduce batches then

steady moat
green oyster
#

im on URP lol

steady moat
#

I guess URP does too then.

static matrix
static matrix
#

bro literally said "Just do it lol" ๐Ÿ’€

noble mortar
#

What are some 2D coding concepts I should learn for unity? If you have any resources for topics that I should learn that would be great.

swift falcon
#

2D or 3D

#

also what do you mean by coding concepts

steady moat
#

Does it really matter if it is 2D or 3D ?

static matrix
#

yes

swift falcon
#

yeah sorta

steady moat
#

He probably meant Clean Code, Polymorphism, OOP, etc.

swift falcon
#

ah, well, the standard OOP package then

steady moat
swift falcon
#

just keep in mind that unity still uses hella old .Net (iirc its 4.8 or 4.7.2)

steady moat
#

You could use C and still be able to apply "coding concept".

noble mortar
noble mortar
swift falcon
#

...

#

what is this unholy amalgamation of a switch case

steady moat
noble mortar
swift falcon
steady moat
#

!learn

tawny elkBOT
#

๐Ÿง‘โ€๐Ÿซ Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/

swift falcon
heady iris
heady iris
#

Change from the โ€œFilter and Temperatureโ€ mode if you donโ€™t want that

steady moat
# noble mortar Both

Just take the coding course. But, this will only show how to make things. A lot of how to make "good things" are not included in those specific tutorial.

steady moat
steady moat
noble mortar
#

I try to maintain clean code that is maintainable but I wanna improve it more and learn more coding concepts. I know a little OOP but feel like I donโ€™t know it too well and concepts like Atlas and ECS seem interesting.

steady moat
swift falcon
#

youuu wanna learn the basics first for sure

noble mortar
swift falcon
#

...

#

how hard is it to use a dictionary

#

or better, a byte enum

noble mortar
#

Thatโ€™s what I told him to use

swift falcon
#

well no

#

it uses strings, right

#

then dict

noble mortar
#

Yes

swift falcon
#

still can't figure out how to handle force-based VR hands, interested in the physical approach because simply setting the velocity will make all objects feel completely weightless, but all relatively simple approaches I've tried either result in extremely slow or extremely springy/orbiting hands. I have a theory that would require much more extensive calculations but it just feels so bootleg and wrong and I'm not even sure if my idea will work

steady moat
swift falcon
#

wdym

steady moat
#

Rigidbody.MovePosition() ?

swift falcon
#

there are two ways, either setting velocity or applying force, setting velocity removes weight and has issues with portraying inertia

#

same reasoning?

steady moat
#

You want things to have a weight ?

#

When hold ?

swift falcon
#

yes, so that picked up objects don't feel fake

steady moat
#

If you do that, you will "unsync" the hand with the real hand.

swift falcon
#

...yes, thats what I'm talking about

#

I have two separate objects, my controller (visible for testing purposes) and the hand itself

#

but whatever I try either results in the hand being super slow or too fast without dampening

#

and flying past the controller

steady moat
#

Do you have Use Gravity activated on the Rigidbdy ?

swift falcon
#

no

#

on the hand I'm assuming

#

I'm not that dumb

steady moat
#

It is always best to check it first.

swift falcon
#

yeah no the issue is with dampening

steady moat
#

Then, you could use Rigidbody.MovePosition with lerping.

#

Joint with the physics of the Rigidbody.

swift falcon
#

I am trying to use forces here, you have to keep in mind that we're talking about VR, hand collisions are a pain in the ass and you really want to avoid direct movement

steady moat
swift falcon
steady moat
#

And, you will always have orbiting with a force.

swift falcon
#

...I just said, I'm not stupid - I perfectly understand this

steady moat
#

This cannot be mitigate if you want to use force. You will need to remove the whole force at a specific points.

#

Redoing what a MovePosition does, but with the usage of a force.

#

Personally, I would do a lerping.

swift falcon
#

I do understand that I need dampening to negate the force, the issue is how much of it

#

...christ how hard is it to understand

#

simply teleporting will not give objects around any inertia or weight

#

you will be able to pick up and move them around without any inertia

static matrix
#

lets goooooo ive already increased fps by 10 frames

steady moat
#

If you do not reset to 0.

#

You are going to orbit.

swift falcon
#

okay I think its pointless to try explain the issue and my intentions to you, sorry

#

but you are trying to solve an entirely different problem

steady moat
#

Alright, I might not understand your issue. However, this is seems like you do not want to try to use the available tool (Rigidbody.MovePosition), or to solve an impossible issue (Orbiting with forces).

thick socket
#

I have this disabled...however when I save a script it still refreshes everythng

#

what am I doing wrong?

steady moat
swift falcon
steady moat
# swift falcon while MovePosition would work to move the hands, it simply teleports them, spawn...

What do you mean by teleport ? It does not...

Rigidbody.MovePosition moves a Rigidbody and complies with the interpolation settings. When Rigidbody interpolation is enabled, Rigidbody.MovePosition creates a smooth transition between frames. Unity moves a Rigidbody in each FixedUpdate call. The position occurs in world space. Teleporting a Rigidbody from one position to another uses Rigidbody.position instead of MovePosition.

swift falcon
#

it still ignores any weight

thick socket
lost wave
#

I am using the standard asset character controller in a project, the project has a swimming mechanic that is work so far, but I need to rotate the character controller collider 90 degrees on the y when the player is in the swim animation. I have tried several different approaches but the collider always stays in its original position. this was the last thing i tried. swimRotation = Quaternion.Euler(0f, 90f, 0f);.

#

when the swim trigger is activated i have this characterController.transform.localRotation = swimRotation;

steady moat
swift falcon
#

...

#

that STILL ignores the weight of the held objects

#

when you hold something heavy it should have more inertia than something light

steady moat
#

It will.

swift falcon
#

you're just slowing the movement down to make it smooth

steady moat
#

Test it.

#

You have nothing to lose except maybe 15min.

#

If it works, it works. If it does not, then it does not.

#

This is what I would do.

#

Otherwise, you gonna fight with the velocity of the Rigidbody.

ashen yoke
#

that should only take effect on assets

swift falcon
thick socket
steady moat
ashen yoke
#

no idea, according to some blog post auto refresh should disable compilation

thick socket
swift falcon
#

@steady moat yeah just as I expected, your method gives the body exactly 0 inertia, making it completely unable to interact with other bodies

thick socket
#

lets see if its fixed

swift falcon
#

here I attached a spring joing

thick socket
ashen yoke
#

if its supposed to stop compilation but doesnt its a bug

thick socket
#

of course it is

#

ffs

ashen yoke
#

never had to turn it off, why do you?

thick socket
#

its annoying

ashen yoke
#

what is?

#

maybe there is alternative solution to this problem

steady moat
swift falcon
#

...yeah there's no point in this

static matrix
#

ok I have a question
I like having the individual wall blocks like in minecraft, but I have a feeling that is really inefecient and will cause a lot of lag. However, just scaling the blocks causes the material to not appear well. Do you guys have any idea how i can have the materals scale with the object? or can i not do that

ashen yoke
#

if your materials dont scale it means the shader is world space

#

use different shader

static matrix
#

no like

#

I think its a uv issue

ashen yoke
#

uvs dont change from scaling

static matrix
#

looks nice but is multiple objects, so more lag

#

it stretches

#

I think wait can I just

ashen yoke
#

yes its how its supposed to work

static matrix
#

do repeat instead of clamp or smth

#

id rather have it repeat

ashen yoke
#

if you want them to remain constant, you need to use world space shader

static matrix
#

hold on maybe this is easy

ashen yoke
#

typically its triplanar shader

swift aspen
ashen yoke
#

if youre on urp google how to make one

#

the nodes should be there already

static matrix
#

im not on urp

#

and too far in to switch

#

but

#

its fine theres other issues anyways

ashen yoke
#

then find/write one

static matrix
#

like the wall bases stretch out

#

cant do anything about that

#

I can also try mesh merging

#

that might work

#

ill take a look and see if I can do it before runtime

ashen yoke
#

you can

#

but its not pretty

static matrix
#

ok

#

ill try static batching instead

#

maybe that will helo

#

*help

#

this is an LTS version right?

ashen yoke
#

dont know, you can also use instancing

static matrix
#

yeah imma look at allllllllllllllllll the things

#

bcause 15 fps is prettty bad

#

so I need to fix it

ashen yoke
#

did you profile it?

static matrix
#

oh

#

yes I did

ashen yoke
#

just to exclude any fixes based on guesswork

static matrix
#

This is fine

#

well its just all under drawing opaque it seems

ashen yoke
#

are you in deferred?

static matrix
#

or much of it

#

where do I check that

ashen yoke
#

quality/graphics settings

thick socket
#

gotta love this crap

static matrix
#

oki

ashen yoke
#

how many lights in the scene?

static matrix
#

which is fastest?

thick socket
#
        Application.targetFrameRate = Screen.currentResolution.refreshRate;
        Application.targetFrameRate = Screen.currentResolution.refreshRateRatio;
static matrix
#

theres a lot but the profiler said it wasnt really that

ashen yoke
thick socket
#

"refresh rate is obsolute, use the one that doesn't work instead please"

static matrix
#

I changed my camera to deferred ill see if its any faster

ashen yoke
#

if it is faster it indicates a massive problem

static matrix
#

its slightly faster but also hideous

#

from ~20 to ~30

ashen yoke
#

yeah seems like you have lots of lights

static matrix
#

unless I changed something

ashen yoke
#

your lights are prefabbed?

static matrix
#

it just suddenly started looking ugly wtf

#

let me fix this first

ashen yoke
#

the ugly looking part is most likely your post processing

#

which needs to be setup differently sometimes for deferred/forward

static matrix
#

no like It was looking good then it stopped looking good

ashen yoke
#

ive no idea what you mean by that

static matrix
#

I mean

#

my textures died wtf

steady moat
# swift falcon <@208422197348401152> yeah just as I expected, your method gives the body exactl...

It is true that rigidbody does not seem to interact correctly with other bodies if the body is not kinematic which does goes against what you were trying. Maybe the following would work for you. The only issue, is that forces applied to the hand are lost.

using UnityEngine;

[RequireComponent(typeof(Rigidbody))]
public class Hand : MonoBehaviour
{
    [SerializeField]
    private float _velocitySync = 1.0f;

    [SerializeField]
    private Transform _target = null;

    private Rigidbody _rigidbody;

    private void Start()
    {
        _rigidbody = GetComponent<Rigidbody>();
    }

    private void FixedUpdate()
    {
        Vector3 vector = _target.position - _rigidbody.position;
        Vector3 velocity = Vector3.ClampMagnitude(_velocitySync * vector.normalized, vector.sqrMagnitude / Time.fixedDeltaTime);
        _rigidbody.velocity = velocity;
    }
}

static matrix
#

should be an easy fix

#

wdym by "are the lights prefabbed"

#

they are I believe

ashen yoke
#

do you have a prefab per light type

#

alright

#

then edit the prefabs in such a way that the light range goes only as far as it is absolutely necessary for it

static matrix
#

okki

ashen yoke
#

light range is the key perf drain

#

also the shadows

static matrix
#

im also a blithering idiot I accidently turned something off I think

ashen yoke
#

but that should be handled by "important light"

static matrix
#

ok ive chopped the lights down to 18 from 42

#

should help

ashen yoke
#

you can balance that with intencity

static matrix
#

yeah

green oyster
#

but why would the lights kill yo textures

static matrix
#

ok so
pros its faster now
cons its different
pros 2 I actually like it more

green oyster
#

btw if lights are static and dont move, u can bake them

static matrix
static matrix
#

so I cant bake them

ashen yoke
#

do you have shadows?

static matrix
#

yes

#

its up to ~35

#

which is good enough for me for the editor

ashen yoke
#

lower shadows to absolute bare minimum necessary per light if you can

#

on top of that, disable "cast shadows" on all mesh renderers that dont need them

static matrix
#

bibut they loook niiiice

ashen yoke
#

its all procedural right?

static matrix
#

ok but I'll chop shadows next if things get worse

#

yeah

ashen yoke
#

you were the one we talked about navmesh?

static matrix
#

well I do the layout

#

yep

#

thats me

ashen yoke
#

alright, i dont know if there are already solutions but you need to find some culling solution that works at runtime

static matrix
#

its good for right now

ashen yoke
#

unity built in requires offline baking

#

culling will give you the most perf boost of all

static matrix
#

like occlusion culling?

ashen yoke
#

its old but has lots of stars, didnt test

static matrix
#

ooh ok

#

ill look into it

ashen yoke
#

most likely works, there are probably more

#

another one

swift falcon
#

its pointless

ashen yoke
#

yeah there are plenty of those

swift falcon
#

maybe its language barrier, dunno

#

maybe I've fried my brain and having issues with explaining again

steady moat
static matrix
#

how does it look
imma stylize the bars later dw

swift falcon
#

wait, wdym by forces then

steady moat
swift falcon
#

OH I get what you've done there, hmm

#

yeah this could work, I'm assuming that dragging a heavy object also would be harder

steady moat
#

It is.

swift falcon
#

didn't expect that of all things to work, huh, I think I'll need to look into how unity handles velocity again

steady moat
#

But, if you want the hand to react to something like an explosion.

swift falcon
#

apologies for my previous messages

steady moat
#

It wont work.

swift falcon
#

yeah that can be done separately

#

huge thanks

gritty spindle
static matrix
#

lemme try no shadows see if it looks nice still

steady moat
#

Next time, work with me. Not against. I do not know everything.

swift falcon
#

I tried a slightly different approach and it didn't work before

static matrix
#

ooh it does still look good and its slightly faster

ashen yoke
static matrix
#

hmmmm

#

how could I remedy that

ashen yoke
#

also if you want to push for realism you can use a cheap trick

static matrix
#

maybe no grain

static matrix
ashen yoke
#

you basically find or make yourself a light cookie

#

with an actual physical IES light profile

static matrix
#

I know what a light cookie is what is an ies light profile

ashen yoke
#

its what they use in archviz to fake realistic lights

thick socket
#

Assets\Scripts\DontDestroy\GameManager.cs(17,39): warning CS0618: 'Resolution.refreshRate' is obsolete: 'Resolution.refreshRate is obsolete. Use refreshRateRatio instead.'

#

anyone know how to do that?

static matrix
#

neat

thick socket
#
       Application.targetFrameRate = Screen.currentResolution.refreshRate;
#

this works

static matrix
#

so, so much nicer without grain

thick socket
#
        //Application.targetFrameRate = Screen.currentResolution.refreshRateRatio; 
#

this does not

static matrix
#

maybe
just maybe
its because you commented out the line

ashen yoke
static matrix
#

henceforth preventing it from being run

thick socket
#

it has an error

static matrix
#

oh

thick socket
#

top is obsolute

#

yet bottom doesn't work

static matrix
#

just ignore the error itll be fine trust

ashen yoke
#

red is unity falloff

#

green is theoretical correct falloff

static matrix
#

let me turn off vignette

ashen yoke
#

which is remedied with different shaders

#

its not vignette

static matrix
#

I dont have vignette even

#

ok i'll look into different shaders

ashen yoke
#

this is cool

#

By default, Unity lights use a linear falloff model

#

you want inverse squared like irl

swift aspen
ashen yoke
#

we should probably move out of here with graphics discussions

static matrix
#

ig

#

but ok im fine for rn ill just look into it

green oyster
#

JUST spent 5 hours making lights flicker back and forth with some lerp sheesh

thick socket
#

wonder why they changed the code for that

green oyster
#

most people have 60hz

#

i think lemme check

thick socket
#

yeah thats true

green oyster
#

ok i thought steam survey

#

would show how many people use 60hz

#

but apparently they dont collect data on refresh rate on monitors

thick socket
#

Im using more because some phones only get 30hz

green oyster
#

hmmm, isnt that coz most videos shown on phones

#

are converted to 30hz?

fallow gate
#

Thsi server is made for

green oyster
fallow gate
#

For what

green oyster
#

for anything to do with unity

simple egret
#

My man joins random servers without knowing what they're about

static matrix
#

ill get a light cookie going at least

fallow gate
#

Where are you from guys

green oyster
static matrix
#

discover prob

#

or they could be a bot

fallow gate
#

Just typed "unity

#

๐Ÿ˜‚

green oyster
#

why unity in particular? lol

fallow gate
#

I was searching random words

static matrix
#

what are these words

#

I need to make sure

fallow gate
#

๐Ÿคฃ๐Ÿคฃ

#

U guys are funny

green oyster
#

now do the captcha

static matrix
#

what are the words

fallow gate
static matrix
#

oh my god they're a bot

simple egret
#

This is a code channel people

fallow gate
#

Oh

static matrix
#

bots are written in code

stuck wigeon
#

hey im fully stumped and confused on this 1. As shown in the video when i have my slope movement "enabled" its making my jump go weird only when walking. ive tried to comment out the code to figure out where the problem is but only found what function is causing it. ive tried to just stop that slope movement by only enabling it when im not jumping or if im grounded both of those didnt work. https://gdl.space/akexaticuc.cs

glossy temple
#

i need help on this error when opening unity

potent sleet
static matrix
#

correct

#

ok

swift aspen
fallow gate
#

I'm in ohios peris

potent sleet
static matrix
#

well the bot clearly failed the captcha so we should kick them trust

potent sleet
static matrix
#

anyways back to code

swift falcon
fallow gate
glossy temple
#

oh sorry

#

but when i download it

#

it gives me this error

fallow gate
#

Only serious talks guys

knotty sun
stuck wigeon
potent sleet
swift falcon
glossy temple
#

sorry

#

but no one is guiding me

swift falcon
#

keep the channels on topic then please its bussy enough

fallow gate
potent sleet
static matrix
#

yes please

potent sleet
swift aspen
glossy temple
fallow gate
simple egret
#

There we go

fallow gate
#

So u guys studying

green oyster
#

i dont think that pings the moderators but ok lol

glossy temple
fallow gate
#

๐Ÿ˜ญ๐Ÿ˜‚

simple egret
oblique spoke
#

!mute 915205642262835270 7d Shitposting

simple egret
#

Here it comes

tawny elkBOT
#

dynoSuccess THE SAGAR ๐Ÿงฉ#6969 was muted.

potent sleet
glossy temple
potent sleet
simple egret
#

If I ping these IPs, both time out.

glossy temple
#

So what do I do

potent sleet
simple egret
glossy temple
#

It's just that I don't know what do I even explain it

potent sleet
#

what

stuck wigeon
thin maple
#

I want to generate some terrain heightmap on the GPU for later simulation and tesselation

I'm confused about what tool I should use to do that

shaders? shader graphs? compute shaders?

thin maple
#

alright, thanks

vestal summit
#

how do I fix this error?? It's in visual studio

simple egret
#

It's not an error

#

You can ignore it if it doesn't break Visual Studio

vestal summit
#

what about this?

simple egret
#

Same thing

#

Restart Unity if it broke something

peak halo
#

Hey, so I have an interface called IPausable. As the name suggests, it is for making objects pause themselves when the main TimeManager class tells them to. The interface has a function called OnPause() and I want to call this function in all inerfaces of this type when the game is paused. How can I do this without using FindGameObjectsOfType() and such? I thought of initialising them and making everyone add themselves into a static list at start but I don't think that's very practical either. How would I go about achieving this?

leaden ice
peak halo
#

Hm yeah I thought of that too but didn't know if it was a good idea. Thanks a lot!

leaden ice
#

I wouldn't make IPausable at all

#

I'd probablty just have TimeManager have an OnPause event

#

and things that care about the game pausing and unpausing can just subscribe themselves to that event

#

you could even make it a static event to make things easy

vestal summit
# vestal summit

these errors are still popping up. I actually just updated my unity to the latest version 2022

peak halo
solemn rune
#

I'm having a problem (I think I'm just dumb).. I have this gameObject, it has to move 90 units. I need to clamp the max movement speed, so I have a maxMovement variable, and I need to multiply that by time.deltaTime, to make it framerate independent. But, now I need to calculate the max amount of time it could take the object to move the 90 units and I'm having a brainfart on how to do that, with time.deltaTime not being a constant. Could anybody point me in the right direction?

modern creek
#

I'm using a ScriptableObject as a database of GameObjects that I want to instantiate at runtime. Can I not do that? I'm just trying to get a reference to a gameobject as a prefab, but it seems to be instantiating the game object as well..

    public class PropDatabase : ScriptableObject
    {
        [SerializeField] private GameObject GreenGlupiePoseA;
        ... etc ...
        public GameObject GetProp(CutscenePropType propType, PropPoseType poseType) => (propType, poseType) switch { ... }
    }

// elsewhere..
GameObject newPropPrefab = PropDatabase.GetProp(prop.PropType, prop.PoseType);
GameObject newProp = Instantiate(newPropPrefab, propTransform);
// do some stuff to newProp .. but nothing to "newPropPrefab"
leaden ice
modern creek
#

(two props in each - only one of which is doing the animated stuff)

leaden ice
#

not sure I understand the question/issue?

modern creek
#

I'm getting two instances instead of one

leaden ice
#

you're likely calling Instantiate twice

#

add Debug.Log

modern creek
#

PropDatabase.GetProp just returns a gameobject that's referenced in the scriptable object

leaden ice
#

maybe your code is running twice and you don't realize it

modern creek
#

hm, perhaps.. will check

worldly hull
#

if u really think that instantiate is the only one, then it might be executed more than once

simple egret
#

Also check for any new GameObject() potentially in that switch expression you elided

modern creek
#

correct you are, PB.

solemn rune
#

this is the code, running every update

#
    {
        float maxClamp = ballSwingMaxSpeed * Time.deltaTime;
        axis = Mathf.Clamp(axis, 0, maxClamp);
        anchorRotationEulers -= new Vector3(anchorRotationSpeed * axis, 0, 0);
    ballAnchorRot.transform.localRotation = Quaternion.Euler(anchorRotationEulers);
    }
#

In this case, it rotates 90 eulers, I set the maxSpeed to 800, so that should take, at max speed, 0.1125 seconds to complete. But it takes 0.23-ish at max speed. I confirmed that it does clamp every frame

jaunty sleet
#

Does anyone know how to rotate a vector3 point around another vector3 point?

rough jacinth
#

Hi! how to correctly make reference to ragdoll joints in prefab so when object instantiated, it doesn't link to prefab but his object

leaden ice
dusk apex
hexed pecan
#

rotation is a Quaternion here

dusk apex
jaunty sleet
#

Thanks, I know about rotating with quaternions I just couldn't figure out how to do it around a point

solemn rune
jaunty sleet
#

I need to find a course in unity quaternions / vectors lol. It's so hard to understand

hexed pecan
#

You "just" rotate other quaternions with Quaternion * Quaternion or vectors with Quaternion * Vector3

#

Learn to use the helper methods like LookRotation, AngleAxis, Slerp

#

Use gizmos/objects to visualize the rotations

vestal summit
#

Yo!
I got a problem here. I'm trying to find a Transform far away from the this transform. How do I do it?

#

by the way this is a prefab

hidden compass
#

hello, im playing around with .snippet files.. and i got a raycast shortcut working great.. only if i were to type out some of it and hit tab.. it leaves what is left over..
i would like it to remove the things i typed before.. but can't figure out how to do it..

hidden compass
#

heres my snippet

#

i do however notice the one i made is white.. rectangle. similar to the if snippet

#

however the ones that replace what you have typed with code look like ur normal methods.. so not sure what im missing tbh

simple egret
#

The Unity methods are custom, they're injected by the IDE package, they're not snippets

#

Your snippet works as expected, it adds the code in place, and can't modify things before/after it

stoic ledge
#

Hello everyone, quick question.
Having a lot of animated damage popups/health bars in the world, what is more efficient, 1 canvas in the world space for everything or multiple canvases (1 for every element in the world space)?

hidden compass
simple egret
#

Yeah it's whatever IDE you're using, the Unity package you installed for supporting it that registers these custom analyzers and completions

hidden compass
#

i used Expansion and SurroundsWith but there seems to be a <SnippetType>Refactoring</SnippetType> as well ๐Ÿค”

#

ya, thats the only thing i see different is Refactoring

#

meh, ill try messing with that.. but im clueless right now ๐Ÿ˜„ i just think its super cool to be able to define a raycast autocomplete..

#

ive been needing that w/o ever knowing it.. and if i can't get this working i'm still pleased ๐Ÿ™‚

#

i can go ahead and make a few for OverlapSphere, Input.GetKey stuff, and a few others i have planned now that i know how to do it

hidden compass
#

i try to have as few canvi as possible

simple egret
hidden compass
hidden compass
#

so then i could type if(Physics.Ra.. and tab it out

#

it makes it soo.. when you press Tab it shuffles across all the parameters you can change

#

this is probably default behavior.. i changed it back and removed Refactoring, and it still allows this

#

thanks for the insight tho SPR2 ๐Ÿ‘ i know enuff to make a few QOL snippets atleast

granite nimbus
#

is it possible to expose class/struct member only to certain class/struct (no inheritance)?

#

like maybe I could try creating some custom property [ExposeTo("MyClass")], but is there a more convenient way?

leaden ice
#

much of those rules have to do with either inheritance or assembly boundaries though

granite nimbus
leaden ice
latent latch
#

Maybe like a delegate to a getter if you wanna subscribe to it

leaden ice
#

if you expose your object as an interface you can tightly control which members are exposed

granite nimbus
#

hmm, both approaches seem good. thanks

somber nacelle
#

depending on the usecase, you could even declare one type inside the other and the nested type would be able to access the non-public members of the containing type

granite nimbus
#

in fact one is even static and the other is not

somber nacelle
#

well i had no way of knowing that considering your vague "certain class member" statement. and is also the reason i started with "depending on usecase"

granite nimbus
somber nacelle
#

nesting is not inheritance

granite nimbus
#

oh well, I want no nesting too ๐Ÿ˜€

simple egret
#

You're describing an equivalent of C++'s friend keyword. We don't have that in C#

clever harbor
#

Do get; / set; fields have any overhead?

rapid stream
#

Im trying to automate spritesheet animation.
How can I get an array of all the cells of a png?

Sprite[] sprites = Resources.LoadAll<Sprite>(path);

Seems to always return nothing

rapid stream
clever harbor
#

I meant as in performance

rapid stream
#

Maybe an incredibly small amount, since they reference a field. But realistically, no

rapid stream
#

I am new to unity. What is the resource folder. I can only find the assets folder

#

The path im giving is "Assets/Sprites/Player/king"

potent sleet
rapid stream
#

searching on the web and docs

potent sleet
rapid stream
#

AssetDatabase also doesnt work

simple egret
#

Resources.Load<T>() and its variants requires a special folder arrangement to work, that's described in the docs

rapid stream
simple egret
#

Depends on what value you set into path

#

"Sprites/Player" will be the correct path here

potent sleet
#

The path is relative to any folder named Resources inside the Assets folder of your project.

rapid stream
#

whoa it worked!

#

Yea bet

#

I was mixing up some path stuff as I was using System.IO stuff to handle paths elsewhere, just needed to change the file structure like you said and edit the string

simple egret
rapid stream
#

Yea my system is pretty jank. Il probably just use my resource folder as temp storage to automate the animationsand outputting the result back to Assets

vale wren
#

anyone know how to achieve a card scroller like this?

quaint crypt
#

I have a ScriptableObject A. In A.OnValidate, I fire a System.Action OnValuesUpdated, so that methods subscribed to it can get updated.
I have a MonoBehaviour B, which has a reference to a A ScriptableObject, which I set in the editor. In B.OnValidate, I subscribe to A.OnValuesUpdated.
When I modify A in the editor, the B.OnValidate fires as expected, but is uninitialized. For example, if I have an int on B, and set the default value of it to 1, but in the editor I set it to 3, the OnValidate will debug.log it as 1.
How do I fix this?

granite nimbus
#

so realistically you never sacrifice code structure to performance gain of using field

granite nimbus
granite nimbus
#

I have to do extremely roundabout ways to achieve same thing

steady moat
#

It does not seem like what you are describing is an initialization process. For example, if I have an int on B, and set the default value of it to 1, but in the editor I set it to 3, the OnValidate will debug.log it as 1.

quaint crypt
steady moat
quaint crypt
steady moat
#

If you set the value at 3, then you should get the value with a value of 3.

quaint crypt
steady moat
#

There is something that is not working correctly that I cannot guess because I do not have the code nor the project. Try debugging using other means. Maybe do a GameObject.FindObjectOfType ?

quaint crypt
steady moat
#

Doing this way, I am pretty sure you gonna be able to get the correct value.

quaint crypt
#

Problem is I can't move on phsycologically until I know why it doesn't work

steady moat
quaint crypt
celest solstice
#

Hello people, I'm having trouble with vectors and the OnDrawGizmos ๐Ÿ˜ต, I can't manage to make it do what I want, displayed in this image

#

here's what I have so far in the code section

#
 void OnDrawGizmos()
    {
        foreach(var connection in connections)
        {
            bool hitted = Physics.BoxCast(connection.GetPosition(), Vector3.one, transform.position + connection.GetPosition(), Quaternion.identity, connection.DistanceFromCenter * 2);
            Gizmos.color = hitted ? Color.red: Color.green;
            Gizmos.DrawWireCube(connection.GetPosition(), Vector3.one*2);
        }
    }
#

I can't get it to "extend" in the correct direction

#

I'm using a physics raycast of a box and I would like to have a visual representation for it, to see if I'm messing it up (I am)

tame iris
cold parrot
# celest solstice Hello people, I'm having trouble with vectors and the OnDrawGizmos ๐Ÿ˜ต, I can't m...

To extend the box you need to use a direction vector, e.g. (0,0,1), not the (1,1,1) vector. If you want it rotated into local space of the object you need to set the gizmo matrix to the transform matrix of the object. You might also enjoy this little package https://github.com/vertxxyz/Vertx.Debugging

GitHub

Debugging Utilities for Unity. Contribute to vertxxyz/Vertx.Debugging development by creating an account on GitHub.

tame iris
celest solstice
# cold parrot To extend the box you need to use a direction vector, e.g. (0,0,1), not the (1,1...

But the DrawWireCube() method only gets a center and a size, I assume I should calculate the center of what I want but I'm not the best in vector calculations, all I can get together is : I have a middle point, the center of the object, I have the pseudo direction I want to go, that's one of the four points, let's say the forward one, is there something I can do to calculate stuff and tell it: "hey, draw this, move it in this direction by this amount?

tame iris
#

Native Gallery is also for Audio.

cold parrot
celest solstice
heady iris
#

oh yeah, that's how you do it

#

set the local to world matrix, then do everything in local space

#

bingo

oblique basalt
#

how can i check whether an object is colliding without attaching a script to that object? is that possible?

#

I instantiate it with the Instantiate method

cosmic rain
stable osprey
#

code looks ok if you don't ever touch it again, but why use matrix overall?

#
var pos = transform.position + 2 * oneoftheconnections.localPosition;
Gizmos.DrawWireCube(pos, Vector3.one);

or is it the size you were having issues with?

heady iris
oblique basalt
heady iris
#

i think that's clean

#

you know what's messy?

#

having a script with ten jobs, including doing physics queries on a bunch of objects it has spawned

oblique basalt
#

oh yeah doing it that way would be messy. but if unity stored whether it was colliding with anything i could have just had a single method rather than a whole new class and script

astral oriole
#

Maybe a dumb question, but I'm new to transitions, This changes the center of the camera's position, but it does it instantly without a smooth transition. How do I add a smooth transition?

rain minnow
rain minnow
oblique basalt
rain minnow
rain minnow
oblique basalt
#

๐Ÿ‘

rain wasp
#

is there a way to detect a unity action during a loop?

#
if(InputReader.onSubmit != null && index != 0){
                dialogueText.maxVisibleCharacters = line.Length;
                break;
            }
#

what I'm having trouble with

cosmic rain
rain wasp
#

action

#

public static event Action onSubmit;

cosmic rain
#

So basically an event. Checking if it's null simply checks if anything is subscribed to it.

rain wasp
#

*event action

cosmic rain
#

You should subscribe to it outside your coroutine and when it triggers raise a flag that can be checked in the coroutine.

#

Or maybe even stop the coroutine from the subscribed method.

#

Along with the logic for displaying all the text.

rain wasp
#

I see

#

lemme try

#

btw, is using events for input system a good idea?

cosmic rain
#

Sure. Why not?

#

That's the default approach that unity provides with the input system.

celest solstice
stable osprey
#

ah, well ok.. doing the proper math might not be worth it then

#

I assumed they were children of the object

celest solstice
#

Yeah, and since apparently the gizmos thingy works on world space only I had to make it be in local position just for a moment

molten thicket
#

Hey guys !

So my WebGL game stopped working in localhost and on my server.

It just gets stuck here and doesn't load?

It's been working fine for over a year now. Anyone else seen this at some point and able to help? ๐Ÿ™‚

#

Wow that's weird - It's requesting a double up of the original directory:

buoyant crane
molten thicket
#

Similar thing on Edge & Firefox

#

The heck ?! haha

buoyant crane
#

thatโ€™s very interesting

molten thicket
#

right! I'm investigating

blissful frost
#

i am having a vary frusterating issue with my code

#

may anyone help please

#

it is a lot

cosmic rain
hexed forum
#

@blissful frost what kind of game is it?

#

the genre, if you will

blissful frost
#

the help is in Begghiner code

clever canopy
#

i have 2 colliders how can i detect if on or the other was hit

heavy kindle
#

has anyone seen this before? trying to make a build for my game and the editor crashes reporting a ton of 'asset.cs' files that don't exist in the project?

Script 'Packages/com.betscript.citybuildings/City_Buildings_Pack_Vol.4/Building_331/Prefab/asset.cs' will not be compiled because it exists outside the Assets folder and does not to belong to any assembly definition file.
Script 'Packages/com.maksim.pbrmilitarypack/Characters/Elite_Soldiers/Models/Soldier/asset.cs' will not be compiled because it exists outside the Assets folder and does not to belong to any assembly definition file.
Script 'Packages/com.characters.actorcore/young-fashion-vol-3/casual-f-0030/Prefabs/asset.cs' will not be compiled because it exists outside the Assets folder and does not to belong to any assembly definition file.
Script 'Packages/com.```
vale wren
broken nest
stable osprey
frozen robin
molten thicket
# stable osprey fixed?

Just fixed it.

Turns out having a # in my build folder messed up the template URL somehow.

#

I wouldn't be able to tell you why or how or what, but using only plain characters seem to work

stable osprey
#

lol

#

fun

river kelp
#

I'm kind of at a crossroads for what movement method to use.

I was using the 2d rigidbody movePosition, but that interferes with gravity.
I was thinking of switching to setting the velocity in the RigidBody, but the unity doc recommends I don't do that.
I don't want to use AddForce as I lose too much control.
Lastly, I could try to make my own movement tech but then I would have to re-implement a lot of the existing functionality like gravity, collision etc.

What are other people doing?

Some extra information:
Many characters will be using the same movement tech, not just the player.
I want somewhat decent control over their motion.
The game is 2d, side view.

#

Any issues or benefits you encountered while using any of the systems would be helpful

broken nest
river kelp
#

It isn't actually a 2d platformer, they just share the view. So definitely agree that for 2d platformers faked 2d gravity will feel better for the player

soft shard
# river kelp I'm kind of at a crossroads for what movement method to use. I was using the 2d...

I work in 3D, though the options with physics are similar, I use velocity in FixedUpdate to handle physics-related movement, I use a Vector3 (in your case, maybe a Vector2) and MoveToward or Lerp that vector to the value I want, instantly add to it for jump, and subtract from it over time at a fixed rate in Vector3.down to apply unique gravity for that object/player, because I have the velocity managed, and I know I only manipulate it in specific places of my code, its one way you could handle your movement, MovePosition is often used for kinematic rigidbodies, if your implementing your own logic, as you pointed out may be more hassle than its worth, depending on how complex of a system you might be after, Unity also has a First Person and Third Person controller, you can maybe take a look at how their code is structured for movement, and translate it to 2D, essentially removing an axis

river kelp
soft shard
stuck wigeon
#

hey is possible to make my slopeMovement = zero just before i leave the ground/jump because i believe there's still values other than 0 before i do jump causing unwanted movement.

private void slopeSlider()
    {
        //1 Bug: When player gains speed by sliding they can jump with excesive speed and the vector.
        if (isGrounded == false)
        {
            targetSpeed = sprintSpeed;
            slideMovement = Vector3.zero;
            return;
        }

        if (SlopeChecker() && slopeAngle != 0)
        {
            if (isSliding)
            {
                isSlopeSliding = true;
                Vector3 slopeDirection = Vector3.up - slopeHit.normal * Vector3.Dot(Vector3.up, slopeHit.normal); //Gets direction of the slope
                slideMovement = -slopeDirection; //Makes it so -slopedirection goes down instead up
            }
            else
            {
                isSlopeSliding = false;
                slideMovement = Vector3.zero;
            }
        slideMovement = (Vector3.ProjectOnPlane(slideMovement, slopeHit.normal).normalized) * currentSpeed; //Makes players stay on slopes
        controller.Move(slideMovement * Time.deltaTime); //Move the character along slopeDirection
    }
river kelp
#

So in that sense gravity is off for your objects?

#

It's a good idea to limit the amount of places I alter velocity. Are you directly setting it when you move or are you += setting it?

stuck wigeon
broken nest
stuck wigeon
soft shard
# river kelp It's a good idea to limit the amount of places I alter velocity. Are you directl...

I am applying a constant downward force to act as my gravity, yeah, that does mean my player or object using the system would fall at a different rate than Units default physics, if I choose to change the default values, it allows me to change how fast I want gravity to be for the player, and how floaty I might want my jump to feel, maybe I want a trigger that changes things that enter it to zero gravity like space, etc

I set my velocity with interpolation, for example it may look something like rb.velocity = Vector3.MoveToward(someVector3, someTargetValue, t);, here are some resources I found helpful for building mine:
https://gamedevbeginner.com/how-to-jump-in-unity-with-or-without-physics/
(this video may give a better understanding of the math: https://www.youtube.com/watch?v=acBCegN60kw)
https://gamedevbeginner.com/the-right-way-to-lerp-in-unity-with-examples/ - I decided to build a wrapper for this, so I can treat t like time, and have the wrapper do the math and handle delta time

Learn how to jump in Unity, how to control jump height, plus how to jump without using physics, in my in-depth beginner's guide.

An update to the Better Jumping in 4 Lines of Code, including fixes to the Physics Update, along with some alternate methods of applying force and gravity to the player.

Support Board to Bits on Patreon:
http://patreon.com/boardtobits
Check out Board To Bits on Facebook: http://www.facebook.com/BoardToBits

โ–ถ Play video

Learn to animate buttons, move objects and fade anything - the right way - in my in-depth guide to using LERP in Unity (including copy / paste examples).

stuck wigeon
broken nest
#

can I see the jump code?

stuck wigeon
#

!code

tawny elkBOT
#
Posting code

๐Ÿ“ƒ Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

soft shard
# stuck wigeon hey is possible to make my slopeMovement = zero just before i leave the ground/j...

If you want to know the very moment you leave the ground/your bool becomes false, you could setup a second bool and use that as a "last state" to act like an event (or you could call an actual event too), for example:

bool lastSlopeState = false;
bool currentSlopeState = false;
System.Action onLeftGround;

if(someCondition) {currentSlopeState = true; DoOtherStuff();}
else if(someOtherCondition) {currentSlopeState = false; DoMoreStuff();}

if (currenttSlopeState != lastSlopeState) {onLeftGround?.Invoke(); lastSlopeState = currentSlopeState ;}

You can do something similar for landed or any specific condition you want to get notified about, it does mean youd need some extra variables and statements, but it could help, in this case you could subscribe to onLeftGround and reset whatever values you need there

stuck wigeon
broken nest
river kelp
broken nest
stuck wigeon
broken nest
broken nest
broken nest
broken nest
stuck wigeon
#

i believe this is what your looking for, its in every state that way u can jump in whatever state your in

 if (movement.controls.Player.Jump.WasPressedThisFrame()) ExitState(movement, movement.jump);
stuck wigeon
#

idk if this would work but im just gonna see if i press space bar to reset,

broken nest
# stuck wigeon i believe this is what your looking for, its in every state that way u can jump ...

I get it. That makes sense. I think the problem is a "kind of" race condition.
So you're setting the slideMovement to 0 when you enter the jump state, but as far as I can tell, you continue to run slopeSlider() every update which will set it back. I think you were counting on your ground check to be false immediately after you jump, but that will almost certainly not be the case. You probably need to find a way to give yourself a grace period after hitting the jump button where you don't do a ground check.

sweet perch
#

can anyone help with discord oauth integration with unity, i have got to the part where i open up the auth window and everything i just cant figure out how to extract the code from the URL and exchange it for user id and stuff

stuck wigeon
broken nest
soft shard
# river kelp Thanks a lot! This is a lot of information, I'm currently reading through it and...

Np, there are often many ways to approach problems, and each part of the API will have its uses in certain cases, if your confused about the functions of how rigidbody movement works, take a read through the docs, often they also explain use case and limitations of components API, but it is certainly good to also get some other opinions maybe when more people may be coming online later

stuck wigeon
river kelp
broken nest
night harness
#

If I run SetActive(true) on a already enabled object does that โ€œrestartโ€ the object? Or does it have something built in that would ignore the request

somber nacelle
#

you could always put a log in OnEnable and see if it is called when you call SetActive on an already active object

night harness
#

Fair call haha

#

Was surprised the answer wasnโ€™t on the documentation page

somber nacelle
broken nest
night harness
#

Once I get home Iโ€™ll test

stuck wigeon
# broken nest Maybe I should have asked this first: what is the behaviour you are trying to i...

ahh so when the player slides it changes the slideMovement Vector to the angle of the slope so player slide to the bottom (first part before jump), but when you do that and then jump u get that extra boosted jump where you go back where u started sliding. (not intended) i think the slideMovement still has the values of the slope angle before you jump which gives it that forward boost.

night harness
somber nacelle
#

well Start for sure won't run a second time

night harness
#

curious if it dirties canvases and initialises animators

broken nest
stuck wigeon
broken nest
#

That will also have problems since you are dealing with slopes and your character stays vertical on them leaving a gap directly below, which I'm guessing is where your ground detection sphere is

stuck wigeon
#

yeah no go on that 1, smallest it can possibly be before it wont allow player to jump

river kelp
#

Basically this

Vector2 gravityVelocity = (Physics2D.gravity * rb.gravityScale);
rb.velocity += gravityVelocity;

Appears to cancel out any horizontal velocity I had

clever canopy
broken nest
worn reef
#

Hi everyone

broken nest
# clever canopy What property would tell them apart?

something like this:

public Collider colliderOne;
public Collider colliderTwo;

public void OnCollisionEnter(Collision collision)
{
if(collision.collider == colliderOne)
{
Debug.Log("I guess it was Collider One");
}
}
I wrote that code in Discord not a code editor, so it probably doesn't run, but you get the idea I hope

clever canopy
#

Hmm when I did those public things in inspector they appear to both select the same collider

broken nest
pearl cypress
#

Does anyone know if it is possible to pass a array of positions, instead of matrices when using gpu instancing (fixed scale/rotation). Cant find any examples online, thanks a lot

soft shard
river kelp
#

I see. I had some success not applying any gravity of my own if I only altered the x-velocity of the unit and kept the y velocity from the last frame

#

and then just using the default rigidbody gravity

night harness
#

Howdy friends, I have this little trigger forwarder script

public class TriggerForwarder : MonoBehaviour
{
    public UnityEventCollider onTriggerEnter;
    public UnityEventCollider onTriggerStay;
    public UnityEventCollider onTriggerExit;

    [ReadOnly] public bool onTriggerEnterEnabled;
    [ReadOnly] public bool onTriggerStayEnabled;
    [ReadOnly] public bool onTriggerExitEnabled;

    private void Start()
    {
        if (onTriggerEnter.GetPersistentEventCount() > 0)
            onTriggerEnterEnabled = true;
        if (onTriggerStay.GetPersistentEventCount() > 0)
            onTriggerStayEnabled = true;
        if (onTriggerExit.GetPersistentEventCount() > 0)
            onTriggerExitEnabled = true;
    }
    void OnTriggerEnter(Collider other)
    {
        if (onTriggerEnterEnabled)
            onTriggerEnter.Invoke(other);
    }

    private void OnTriggerStay(Collider other)
    {
        if (onTriggerStayEnabled)
            onTriggerStay.Invoke(other);
    }

    void OnTriggerExit(Collider other)
    {
        if (onTriggerExitEnabled)
            onTriggerExit.Invoke(other);
    }
}

I have these bools so it doesn't waste time invoking stuff I have no interest in invoking, but is there a way to completely prevent these functions from running depending on my bools that exists outside of the function?

#

like I don't want OnTriggerStay being called if that bool isn't true

chrome pewter
#

You mean as in, a bool from another script right?

#

Wait nvm

soft shard