#💻┃code-beginner

1 messages · Page 719 of 1

silver fern
#

since the one thing all the effects have in common is being an EffectObject, I was hoping I could check through that

rich adder
#

maybe you can just implement an interface

#

if(other.TryGetComponent(out ISomethingCoroutine routine))
routine.DoStuff()

#

also you don't need to StartCoroutine directly, you can just use a method inside that class (probably interface) that runs coroutine

silver fern
#

or maybe I'm doing this whole thing wrong, I have something like this ```EffectObject effect = null;

    switch (effectType)
    {
        case EffectType.Burn:
            effect = new BurnEffect();
            break;
    }```
#

but then I can't start the coroutine on effect

rich adder
#

ohh are these not MBs

silver fern
#

yeah

#

the EffectObjects are not MB, that's why I have to start the coroutine from outside

rocky canyon
#

subtle + solid

rich adder
silver fern
rich adder
#

I mean Coroutines can be stored in Coroutine type , just need a way to Return that

ionic zephyr
#

My problem is that my interactor detects objects taking in account the layer "Interactable" but my Enemy AI detects de player throwing a Raycast and detecting if it is in layer "Occlusion" but what if I have an object that is Interactable and should have occlusion (Door)??

naive pawn
#

imo - you could just have the coroutine on the thing being damaged, just have the effect supply the info for the coroutine

rich adder
#

ya was also thinking something like this ^

silver fern
#

oh yeah

#

good call

#

I knew it was obvious

#

thanks

rich adder
tiny crag
#

how do i fix my "writing cursor" looking like this in vs code

naive pawn
#

press insert

#

on your keyboard

tiny crag
#

insert?

naive pawn
#

might be abbreviated to "ins"

tiny crag
#

ohh thank you!!!

naive pawn
tiny crag
slender quiver
#

https://paste.ofcode.org/ExwDaR5nhcmV89PCdsf8Ug

I have been attempting to lock my ship turrerts from rotating towards the superstructure of the ship. I thought I had it working great, but apparently I am working relative to world space. Can anyone suggest how I might easily convert this code to be relative to the local space of the turrets?

naive pawn
#

yawPivot.eulerAngles -> yawPivot.localEulerAngles
yawPivot.rotation -> yawPivot.localRotation

slender quiver
#

thanks

#

i knew itd be simple

naive pawn
#

but again - you should not rely on eulerAngles to be consistent

#

save the state yourself

slender quiver
#

hmm, this is stuff im not good at

#

or understanding of

naive pawn
#

// Get current yaw angle
float currentYaw = yawPivot.eulerAngles.y;
this is not necessarily the value you set last frame

naive pawn
# slender quiver hmm, this is stuff im not good at

the canonical representation of a rotation is the quaternion
when you assign to eulerAngles, that's converted into a quaternion before actually being assigned as the actual rotation
when you retreive eulerAngles, that's converted from the actual rotation quaternion

that process is lossy - converting eulerAngles to a quaternion and back again won't necessarily give the same eulerAngles

#

Because, there is more than one way to represent any given rotation using Euler angles, the values you read back out may be quite different from the values you assigned. This can cause confusion if you are trying to gradually increment the values to produce animation.

To avoid these kinds of problems, the recommended way to work with rotations is to avoid relying on consistent results when reading .eulerAngles particularly when attempting to gradually increment a rotation to produce animation. For better ways to achieve this, see the Quaternion * operator.

slender quiver
#

right

#

i understand the issue with euler angles

#

about order mattering and usch

#

gimbal lock

#

etc

naive pawn
#

no, those are separate issues

#

that's not what i'm talking about here at all

slender quiver
#

so the conversion process doesnt always result in the same ordering?

#

why else would it be a different rotation

naive pawn
#

the conversion doesn't result in the same values

naive pawn
#

it'll be the same rotation

#

but it might be represented differently

#

so the values you're doing math on will be inconsistent

slender quiver
#

so should convert back to quaternion before applying?

naive pawn
#

no that doesn't do anything

#

that's already being done when you assign to eulerAngles

slender quiver
#

okay

naive pawn
slender quiver
#

okay, and eulerAngles/localEulerAngles is the function that is extracting it from the quaternion

naive pawn
#

(or turning it into a quaternion, depending on if you're getting or setting)

slender quiver
#

can you give me a sample of what storing it myself might look like?

rich adder
#

make a field

slender quiver
#

doesnt have to be relevant to my function

#

just something

rich adder
#

add/minus the field value

naive pawn
#

for example, if you were just yawing 90° per second, you might have something like this (analogous to your code, the bad version)

float speed = 90;

void Update() {
  float currentYaw = transform.eulerAngles.y;
  currentYaw += speed * Time.deltaTime;
  transform.eulerAngles = new Vector3(0, currentYaw, 0);
}
```you should instead have something like this:
```cs
float speed = 90;

float currentYaw;

void Start() {
  currentYaw = transform.eulerAngles.y;
}

void Update() {
  currentYaw += speed * Time.deltaTime;
  transform.eulerAngles = new Vector3(0, currentYaw, 0);
}
#

in the assignment line, it could also be transform.rotation = Quaternion.Euler(0, currentYaw, 0);, im pretty sure that's completely equivalent?

slender quiver
#

okay so it is better to do just get currentYaw at the start of the script instead of every frame

silver fern
naive pawn
#

lists are a thing

rich adder
naive pawn
#

or a dict, for mapping the effect enum to the coroutine

slender quiver
#

right

#

and still better to use localEulerAngles

naive pawn
#

better than what...?

slender quiver
#

because currently as my ship rotates the disallowed angles rotate relative to the ship and it gets silly

silver fern
naive pawn
#

im confused what you're asking here

slender quiver
#

well for my purpose

#

nt better

#

notbetter, but correct

naive pawn
#

oh, localEulerAngles vs eulerAngles?

rich adder
#

localEulerAngles will give you the value relative to parent

slender quiver
#

to keep it relative to local space

naive pawn
#

yeah, everything about eulerAngles vs rotation also applies to localEulerAngles vs localRotation
i just used the former for simplicity

slender quiver
#

so that the turrets can still be prvented from facing the superstructure as the ship rotates

#

sur sure

#

sorry if i am being obtuse

#

just trying to be explicit

naive pawn
#

yeah that's fine

silver fern
neon forum
#

'Cannot Apply attribute class 'RpcAttribute' because it is abstract. Does that mean I have to implement it in the code? Why the tutorial giving me so many errors

naive pawn
silver fern
rich adder
rich adder
naive pawn
#

the entire point of coroutines is concurrency

#

what is the actual issue you think you have

silver fern
#

but how, I have to define the coroutine and then I can use that one coroutine I defined

#

how do I add coroutines on demand

naive pawn
#

you might be confusing coroutines vs the methods that create them

naive pawn
rich adder
silver fern
#

wait, so if I do StartCoroutine(TakePeriodicDamage(damage, effectFrequency); multiple times, each one will start a new coroutine?

naive pawn
#

yes

silver fern
#

ah ok

naive pawn
#

that's the entire point of StartCoroutine

slender quiver
silver fern
#

I thought it would restart the same one

naive pawn
#

what has invoke taught you man 😭

rich adder
#

if you ever worked with Tasks async, its similiar concept

naive pawn
naive pawn
#

just for convenience/ease of maintenance

slender quiver
#

oh shit

#

i didnt notice that shouldnt be there

#

that is called iniside an Initialize() function i have in the controller too

#

which is called from outside the controller when the object gets instantiated

#
    public void Initialize(ShipData.TurretMount mountData)
    {
        mountName = mountData.mountName;
        section = mountData.turretMountSection;
        minRotation = mountData.minRotation;
        maxRotation = mountData.maxRotation;

        SetupPivots();

        // Set initial rotation reference
        if (yawPivot != null)
        {
            initialYawRotation = yawPivot.eulerAngles.y;
            initialRotationSet = true;
        }

        // Auto-assign gun barrels and muzzle transforms
        FindGunBarrels();
        FindMuzzles();

        // Initialize barrel recoil components on muzzle transforms
        InitializeBarrelRecoil();
    }
naive pawn
#

you could probably have the currentYaw set here as well

slender quiver
#

sure could

neon forum
#

How do I implement RpcAttribute the unity networking tutorial doesn't cover this part

naive pawn
silver fern
#

I store the ongoing effects in a list of EffectObjects, what's the smartest way to store the coroutines together with them or linked with them in some way?

#

since the coroutines need to stop when the corresponding effect ends

rich adder
silver fern
#

good idea, thanks

grand snow
#

why not have this be done within each EffectObject instance?

#

though I think I already said this like 3 times so

silver fern
grand snow
#

you actually only need a monobehaviour to "start" it

#

so you could pass a reference to your EffectObject at somepoint for it to use

#

e.g. your player component

silver fern
#

the different effects like BurnEffect, SlowEffect, etc all inherit from the EffectObject, and some contain coroutines. And when I try to check effect.EffectCoroutine, where effect is an EffectObject, it says EffectObject does not contain a definition for the coroutine

#

so my current approach is to define the coroutine in the MB and make the EffectObject supply the parameters for it

rich adder
#

I suggested earlier you can use a Interface to check if the Effect has implemented a Coroutine

grand snow
#

okay let me write a quick example to demo how this can be done

rich adder
#

shouldn't this work ?

public interface IEffectCoroutine{
    IEnumerator EffectCoroutine();
}
public class BurnEffect : EffectObject, IEffectCoroutine{
    public IEnumerator EffectCoroutine(){
        yield return new WaitForSeconds(2f);
        Debug.Log("Burn damage tick!");
    }
}
if (effect is ICoroutineEffect coroutineEffect)
    StartCoroutine(coroutineEffect.EffectCoroutine());```
grand snow
#
public class EffectObject
{
    public void StartEffect(MonoBehaviour mono)
    {
        var coroutine = mono.StartCoroutine(DoEffect());
    }

    public IEnumerator DoEffect()
    {
        yield return new WaitForSeconds(1f);
        //do shit
    }
}

public class Player : MonoBehaviour
{
    private EffectObject effectObject = new();

    public void Start()
    {
        //Can do it this way
        StartCoroutine(effectObject.DoEffect());

        //Or like this
        effectObject.StartEffect(this);
    }
}
#

Yea all you need is to have a monobehaviour to start the coroutine. my example shows 2 ways to do this.

#

@silver fern

silver fern
#

I see, thanks

#

let me try that

#

seems to be working, even though it's complaining that the assignment of the coroutine variable is not necessary

rich adder
#

var coroutine is local, it doesnt do anything outside of StartEffect

#

if you had a field you could assign it to that, otherwise there is no use for it

silver fern
#

now I can just destroy the EffectObject to stop the coroutine?

#

or do I still have to make the dictionary

rich adder
silver fern
#

ah

#

then I still need the dictionary anyway

rich adder
#

btw you can probably return the Coroutine directly

public Coroutine StartEffect(MonoBehaviour mono)
    {
        return mono.StartCoroutine(DoEffect());
    }
rich adder
silver fern
#

I thought I just start it since I'm passing in the MB from the player anyway

#
    {
        mono.StartCoroutine(DealDamage());
    }```
#

actually, should I make this override a virtual function in the EffectObject or better not

#

I suppose I don't have to check if it exists if there's an empty virtual function

rich adder
#

if you want, personally I think the Interface is cleaner
especially if you mentioned certain derived classes wont even need Coroutine

grand snow
#

I presumed you would understand this by now my bad

#

The point of this was to demonstrate to you how you can handle this within each instance nicely 😐

rich adder
silver fern
#

I can just run it and if its empty nothing happens

rich adder
#

sure if you wanna do it that way.. its your design at the end of the day, you're the one who's going to be working on it, use what's comfortable, preference at this point.

#

If you come back to the code in a few months it has to make sense to you not us

silver fern
#

well apparently I can't have a virtual coroutine method so my idea doesn't work anyway

silver fern
#

it says not all code paths return a value

past yarrow
#

would that doc still work today in Unity 6 ?

silver fern
#

public virtual Coroutine EffectCoroutine(MonoBehaviour mono) {}

rich adder
silver fern
#

ah

slender quiver
#

@rich adder @naive pawn this is my new and updated version, hopefully this appears to be better according to your advice and instructions

slender nymph
silver fern
grand snow
#

Seems pointless to do this tbh

silver fern
#

why?

grand snow
#

You could just start the mono where you intend to call this...

#

Look at it and think

slender nymph
#

but also yield return null as nav suggested would not be the proper fix for that, you'd want to either make the method abstract (assuming the containing class is also abstract) or return default in the base virtual method (if the base doesn't actually do anything)

silver fern
grand snow
#

let me do another example so you understand what I meant

#
public class EffectObject
{
    private Coroutine coroutine;
    private MonoBehaviour coroutineMono;

    public void StartEffect(MonoBehaviour mono)
    {
        coroutineMono = mono;
        coroutine = mono.StartCoroutine(DoEffect());
    }

    public void StopEffect()
    {
        if (coroutineMono != null && coroutine != null)
        {
            coroutineMono.StopCoroutine(coroutine);
            coroutine = null;
            coroutineMono = null;
        }
    }

    public IEnumerator DoEffect()
    {
        yield return new WaitForSeconds(1f);
        //do shit
    }
}
rich adder
surreal wagon
#

I have a basic movement script for a rigidbody but it's really frictionless and not snappy. I've tried to just directly set the velocity but that ends up interferring with dashing and I've also messed around with the drag but that makes the gravity act really weird. Is there anyway to make this stop sliding as much?

Vector3 velocity = (transform.forward * Input.GetAxis("Vertical") + transform.right * Input.GetAxis("Horizontal")).normalized;
rb.AddForce(velocity * speed, ForceMode.Force);

silver fern
rich adder
grand snow
silver fern
grand snow
#

as you get more knowledge and experience with OO programming it will be easier to design things better

surreal wagon
# rich adder how was velocity interfering with dash ?

The Dash works by adding force but it's instantly overwritten when the movement velocity is set

    Vector3 velocity = (transform.forward * Input.GetAxis("Vertical") + transform.right * Input.GetAxis("Horizontal")).normalized;
    rb.velocity = new Vector3(velocity.x * speed, rb.velocity.y, velocity.z * speed);

    //Dash
    if (Input.GetKey(KeyCode.LeftShift)&&!dashCooldown)
    {
        StartCoroutine(Dash());
    }
}
IEnumerator Dash()
{
    dashCooldown = true;
    rb.AddForce(transform.forward * speed, ForceMode.Impulse);
    yield return new WaitForSeconds(2);
    dashCooldown = false;
}
silver fern
#

learn something new every day as they say

rich adder
surreal wagon
rich adder
rich adder
ivory bobcat
#

You'd need to have that offset gradually decrease to have a burst effect though

slender quiver
#

@rich adder nope, it d oesnt. took me amionute to get on and test. but now its all rotating about the Z axis, not the Y

#

sso the turrets are rollign over on their sides intstead of rotating lol

surreal wagon
#

Well im going to add a mechanic where you can use a shotgun to launch yourself which i feel like would be a pain to do with the rb.velocity setup. Is there anyway i could just use the addForce way without the player being so frictionless?

rich adder
#

put material with more friction on the player collider 🤷‍♂️

rich adder
rich adder
#

@slender quiver Okay just got back and was able to take better look at code, aside from those very sketchy limits that you need to change asap, everything else should rotate as expected on Y..

slender quiver
#

yea they were set as a test awhile back, but min/maxRotation are always set so the hardcoded fallbacks dont ge tused

rich adder
#

== is pointless on floats anyway

#

you're never going to get exact values unless you explicitly write them

slender quiver
#

even for a null check?

rich adder
#

the reason you don't for floats is they are not precise, and have "float point inaccuracy"

grand snow
rich adder
#

Oh nice they also mention solution

#

or < >

grand snow
#

yea c# docs are amazing they often have extra remarks and things

rich adder
#

ya glad to see that microsft finally puts those, i recall the old school docs were more robotic. maybe I remember wrong from msdn

slender quiver
#

@rich adder aye i am aware - am i checking for quality against a float that isnt a null check?

#

i dont see it

#

@rich adder Ive also used Mathf.Approximately()

#

at times

rich adder
slender quiver
#
  if (yawPivot == null)
        {
            Debug.Log($"yawPivot is null!");
            return;
        }
#

well yawpivot is a transform

#

sorry

rich adder
#

yes thats a reference type

slender quiver
#

i still dont see whre i am checking == on a float

rich adder
#

by default value types are never null

slender quiver
#

yee

rich adder
#

!= 0 is okay but even doing it on anything else, it would probably always be true

#

the rest of the limit thing just seems odd

slender quiver
#

i changed it to 320f and 40f anyways

#

but idk why they are rotating about the Z axis now

#

instead of about t he Y

rich adder
slender quiver
#

i watched it happening

rich adder
#

I just tested your code for shits and gigs, aside from limits (i commented those out)
it works fine

slender quiver
#

ill double check

rich adder
#

@slender quiver

slender quiver
#

should be proper orientation

rich adder
#

you'd have to show the heirarchy / pivots n all that jaz

slender quiver
#

it was working before

rich adder
slender quiver
#

before i converted the code over

rich adder
#

you have something else not properly rotated then

slender quiver
#

hmm it must be different axis in local space

rich adder
#

wdym ? the inspector is LocalSpace

slender quiver
#

for that reason

#

no my words are just poor

#

i meant that the axes arent corresponding to each other due to a rotation issue or something

rich adder
# slender quiver

maybe show the scene view with gizmo on show arrows, see if the child turret matches the pivot of YawPivot

#

or if YawPivot makes sense on the parent

slender quiver
#

axes seem to be same

#

oh yea

#

one sec

rich adder
slender quiver
rich adder
#

ah

slender quiver
#

thats with yawpivot selected

#

but they all kinda face the same

rich adder
#

no shit now it makes sense why its tilting lol

slender quiver
#

yep

rich adder
#

i guess before you were rotating "wrong" on z and now that its accurate you can adjust it properly

languid pagoda
#

I wrote a custom wheel collider with pakejka tire friction. Am still pretty new to unity and c# could someone give my code a look and tell me if you spot any no no's

https://hastebin.com/share/jegufafeno.java

eternal needle
# languid pagoda I wrote a custom wheel collider with pakejka tire friction. Am still pretty new ...

just skimming through, not gonna look deep into the algorithm itself and i doubt anyone would
the main thing id point out here is your magic numbers. theres a ton of numbers here which look like you'd want to configure them in editor but are just defined purely in a function. they dont have an explanation or variable describing why that number is used. Im not too familiar with the algorithm you're using, so if those are supposed to be static coefficients in the algorithm then its fine for them to not be configured in editor
the variable names like B_lat also clash with the convention you're using in other names. id suggest just finding a way to name it with camel case still
I would split up more of the logic if you want to improve readability. for example look at line 238, it calls MapRangeClamped inside a Mathf.Lerp so the line gets pretty long and this can usually make logic harder to follow

languid pagoda
#

Awesome I will give those a tweak now. As for the "magic numbers" thats kinda just the way the algorithm works. Its called the magic formula and the numbers just kinda work for "realistic" tire friction. I really appreciate the advice!

eternal needle
#

it seems to fit for most people

slender quiver
#

man shits so wonky with my turretsn now

languid pagoda
#

The wheel collider I posted it good for making games that are a simcade level of car physics(think forza and gran turismo)

rich adder
#

its all visuals, thats an easy fix

hallow acorn
#

hey, does someone know what would be the best pathfinding solution without a grid in 2d?

eternal needle
hallow acorn
sour forge
#

hey. i'm struggling with c# in unity, can someone help me? i need a help with my school project thanks in advance 💞

rich adder
#

that depends on the game lol
some games stil use A* / Navmesh and some use a bunch of sensors

eternal needle
eternal falconBOT
rich adder
#

particularly the last bulletin point

sour forge
ivory bobcat
#

What kind of help?

rich adder
ivory bobcat
#

Normally folks would describe what they're needing help with in specific and show the necessary details.

rich adder
#

"can someone help me" isnt useful to anyone. we already know you need help, thats why you're here

ivory bobcat
#

If you're just looking for someone to collaborate or tutor you, you can try asking on the forums but tbh you'll probably not get the help you're wanting within the specific time limit etc !collab

sour forge
eternal falconBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
Collaboration & Jobs

rich adder
#

if you mean someone to write the code for you then this isn't the place, if you mean how to approach a problem with code or fixing existing issues then sure.

swift elbow
sour forge
swift elbow
#

then do it. nothing is stopping you

rich adder
#

if you are looking for project collaborators then you need to make a post on !collab 👇

eternal falconBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
Collaboration & Jobs

rich adder
ivory bobcat
#

I don't think anyone has been rude though UnityChanThink

grand snow
#

its !learn ing time

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

languid pagoda
# sour forge I have never created a VN with C# before. I have used Python, but I can't say I'...

im show you how you ask for help in a programming discord since you seem to be oblivious to what they're saying.

Hey guys I made a custom wheel collider it works great and I am also simulating an engine. The engine has a torque curve(ie it produces different torque depending ont he RPM of the engine. That number is then multiplied by the current gears gear ratio in the gearbox script. It works great however the only way I can seem to get it work on hills is by amping up the gear ratio of first gear but then when I am back on flat ground it produces too much acceleration. Is this a problem with my curve you think?

#

The options I am thinking is maybe more torque at low rpms but idk

ivory bobcat
#

Could probably have another curve that would scale the value relative to the normal of the surface or something.

languid pagoda
#

I like this idea

sour forge
rich adder
forest mirage
languid pagoda
languid pagoda
rich adder
#

@sour forge btw you should look into something like INK it should similify doing a visual novel since well..it was built for them.

languid pagoda
#

I could be off base here but cant a visual novel be built with timeline?

rich adder
#

You could do that too, or even combine the two.. there is no limits / set ways to do it

#

Ink simplifies mostly the dialogue and reacting to specific choices

languid pagoda
#

oh nice

sour forge
#

I'll check that

#

Creating VN with c# is bs at first point 🤦‍♀️

rich adder
#

whys that? the language is irrelevant to the project type

languid pagoda
#

its kinda a low level language for such a high level concept is what I think she means.

rich adder
#

c# is way easier than python imo

languid pagoda
sour forge
#

i think py is easier

forest mirage
languid pagoda
forest mirage
languid pagoda
rich adder
#

in fact most c languages are

ivory bobcat
sour forge
#

Actually creating vn could be fun

rich adder
hallow acorn
#
float targetX = Random.Range(-transform.position.x - sightRadius, transform.position.x + sightRadius);
float targetY = Random.Range(-transform.position.y - sightRadius, transform.position.y + sightRadius);
Vector2 target = new Vector2(targetX, targetY);
Vector2 direction = (target - new Vector2(transform.position.x, transform.position.y)).normalized;```
does someone know why the magnitude of the vector `direction` isnt 1? i dont really get that
forest mirage
hallow acorn
hallow acorn
ivory bobcat
rich adder
hallow acorn
ivory bobcat
#

I'm assuming you're expecting 1 from the normalized direction

forest mirage
forest mirage
rich adder
#

at lest you sent a message that makes sense this time..

hallow acorn
#

wait

#

it is 1

#

then its something else

rich adder
#

is this like an XY problem here..

#

you aren't asking us about your original issue..

modest dust
#

The first param for both X and Y

hallow acorn
modest dust
#

I would assume you're looking for a target within sightRadius

ivory bobcat
#

You're probably wanting to use positive x and not negative x (relative to position). Same with y etc

rich adder
#

would help knowing what original problem they were trying to solve 🤷‍♂️

ivory bobcat
#

ie Initial point plus/minus some range

hallow acorn
#

ohhhhhh

#

that makes sense

astral flame
#

Have you seen what's wrong with him? He does that thing where he jumps the piece instead of staying still.

languid pagoda
languid pagoda
#

and tbh I think your issue is the small snap size but that cant really be changed now can it?

#

are you just doing transform.position = new Vector3(mousePositionTOWolrdPos);

?

astral flame
languid pagoda
#

no i mean show the code you're using to make the object follow the cursor position

astral flame
languid pagoda
#

please paste the code

#

also

rich adder
#

this person been here forever and still doesnt post it properly..

languid pagoda
#

I need to see the "movepiece()" method to assist

astral flame
#

!code

eternal falconBOT
languid pagoda
languid pagoda
#
 // Enganchar en X
                    if (Mathf.Abs(newPos.x - col.transform.position.x) <= snapRange)
                        newPos.x = col.transform.position.x;

                    // Enganchar en Y (arriba de la pieza)
                    if (Mathf.Abs(newPos.y - col.transform.position.y) <= snapRange)
                        newPos.y = col.transform.position.y + other.sizeY;

                    // Enganchar en Z
                    if (Mathf.Abs(newPos.z - col.transform.position.z) <= snapRange)
                        newPos.z = col.transform.position.z;

This is your issue

#

you need to use one of unities many smoothing methods

#

Mathf.Lerp may help you here but setting the position like that is going to cause jittery movement like you showed.

slow blaze
#

In my game I'm drawing shapes using multiple Polygons smooshed together to give the illusion of lines
I want to check what shape the lines form after releasing the mouse, how would I go about that? I tried to think about it but I have no idea how to make that translation

wintry quarry
#

Can you explain the gameplay mechanic here?

rocky canyon
#

if u mean simple gesture stuff id imagine ud find some resource thru this thread ^

slow blaze
rocky canyon
#

ahh yea that'd just be detecting gestures

slow blaze
rocky canyon
#

ya theres a couple on the store but most are paid.. i just added github to my search in google

wintry quarry
#

You might want to look into both and understand the difference

rocky canyon
#

:TIL:

wintry quarry
#

A gesture recognizer might care about how the shape is made (e.g. did you start at the top left and end at the bottom right) whereas OCR only cares about the final shape

rocky canyon
#

ya, i imagine gesture recognition is just a continuous line... press -> release

#

while u could have a more complex one that takes multiple lines and makes something out of that

#

i myself have never done either.. sounds like a fun project..

tacit prism
#

ive tried for the last 3 days and cant figure it out
how do i import a heightmap for terrain. I put the .RAW in where it says import, but it just gives me a slightly elevated, flat terrain. Im choosing places with rivers and places with mountains. For example, this is the Himalayas

wintry quarry
rocky canyon
#

ya awesome! ^ i was hunting one for a thumbnail/screenshots

remote vault
#

hey guys i was refactoring my input system and i dont know how to solve this issue, let alone what even is the issue

rocky canyon
# remote vault hey guys i was refactoring my input system and i dont know how to solve this iss...

https://unity.huh.how/runtime-exceptions/nullreferenceexception

Assets/Scripts/GameInput.cs:15
means that line 15 of that script is trying to access or modify something that isn't assigned [correctly]

it'd be like having a public MyScript myScript; and then trying to run myScript.DoSomething(); when I never assigned the variable in the inspector

remote vault
#

what do you recommend i should do?

rocky canyon
#

look at that line, see what variables/ references that ur using.. check and make sure they're assigned...
you can use Debug.Log(); to print it out in the Console to make sure they're actually there.. also the website i linked goes over it all..

#

i can already pretty much guess that its this... is that assigned in the inspector?

remote vault
#

yeah i assigned it

rocky canyon
#

well what else is on line 15?

#

it does look like from the error that somethings going on here... GetMovementVectorNormalized()

remote vault
#

sorry im just quite confused what should i do?

rocky canyon
#

!code well for starters show the code thats relevant

eternal falconBOT
rocky canyon
#

we can't know exactly whats going on at line 15

rocky canyon
remote vault
#

yeah i got it fixed it was quite a silly mistake

rocky canyon
#

wouldnt you assign the yellow in Awake() instead?
like playerInputActions = new PlayerInputActions();
but to be honest im kinda lost as to how this works (the new input system)

remote vault
rocky canyon
#

we finally got it 😅

#

(i didn't actually realize the two screenshots were code)

pale stratus
#

I'm creating a 2D action game, but should I separate the character scripts? If so, how should I separate them?(I'm using a translation)

tacit prism
#

I don’t know too much though so I can’t help you past that.

#

I’ve heard people will even split character movement scripts like sprinting, jumping, and crouching outside of a general movement script so…

teal viper
tacit prism
#

All the render sites I’ve tried render as png

#

I’ve tried like 6

teal viper
#

You should share more details and screenshots in the terrain channel.

tacit prism
brisk ibex
#

I keep having to switch my external editor to vscode and then regenerate csproj files for my external editor's language server then switch back, surely there is an easier way to do this?

#

Manually reconfiguring the settings every time I make a change that introduces a new symbol is a real pain.

teal viper
eternal falconBOT
teal viper
#

One thing that could theoretically cause an issue is if you have used the user installer instead of the system one. It have caused some issues for me in the past.

potent turtle
brisk ibex
#

Guess I have to make a plugin or something

potent turtle
#

I just make an empty file named code and set that as my external editor then edit all my code in my IDE separately 🤷

brisk ibex
#

I use the external editor thing to open vim

#

so I need to have it set to an external editor

potent turtle
#

Then set it as a symlink or shortcut

brisk ibex
potent turtle
#

Or you're on Linux. Yeah just make a symlink named code

rare wave
#

Hope It's okay to ask here and if this is even the right place, is there anyone here with experience modding unity games willing to do a simple mod for a commission? please dm if you do or lemme know so I can dm you with the details

potent turtle
#

Or just rename your unity.sh file to code instead

brisk ibex
#

I'm on mac, are you saying that all it checks to automatically regenerate metadata is if the file name is code?

potent turtle
#

Yeah

rare wave
potent turtle
#

I've not had any issues doing that

#

Though I also don't use the external editor setting for anything really. I just open files through my IDE instead of through Unity

brisk ibex
#

Does it need to be cap'd (Code) or something?

potent turtle
#

All lowercase

brisk ibex
potent turtle
#

It should show checkboxes or buttons or someuthing to generate the csproj files when it thinks you're using vscode

brisk ibex
#

might be a mac thing (unity seems v odd on mac so far)

potent turtle
#

Maybe. I know it works on Windows and Linux, might be different on macOS

#

That would kinda suck though 😢

#

FWIW it's not that bad to just use Telescope in Neovim to switch files

brisk ibex
#

I use command-T it's faster 🙂

potent turtle
#

Sure, whatever file switcher 🤷

brisk ibex
#

even then do I still have to press regenerate project files all the time?

potent turtle
#

I don't think so? I've never had issues with that

brisk ibex
#

Using omnisharp?

potent turtle
#

But if it insists on using the actual VSCode exe on macOS maybe it's different for the csproj files too

potent turtle
brisk ibex
#

The price of using a non-slow-editor-strikes-again

potent turtle
#

Hopefully it works out 😅

#

It always amazes me how slow VSCode and especially VS are

#

Though Neovim opens horrendously slowly on Windows so 🤷

#

Opens fine in WSL on Windows though

brisk ibex
potent turtle
#

The Powershell startup time is abysmal 😭

#

Even Powershell on Linux opens instantly. It's just Windows

nimble apex
#
    private Int64 nextUpdateTimestamp = 0;
    private Int64 GetCurrentTimestamp() => DateTimeOffset.UtcNow.ToUnixTimeSeconds();

    private async UniTask Update()
    {
        if (GetCurrentTimestamp() < nextUpdateTimestamp)
        {
            await LoadData();
        }
    }```

i guess this should be fine
#

shouldnt be too expensive tho

grand snow
#

Who writes Int64 instead of long

#

But using long would imply it's ms not seconds

nimble apex
grand snow
#

int64_t feels like home

nimble apex
#

lol

grand snow
#

But no performance issues to me here seeing as it's a single check then an await

nimble apex
#

ok nice

grand snow
# nimble apex ok nice

Actually I realise it's a bad design because if the timestamp condition is met it may call LoadData many times

#

Perhaps a single UniTask.Delay to wait the time instead?

nimble apex
#
    private void Update()
    {
        if (nextUpdateTimestamp != 0 && GetCurrentTimestamp() > nextUpdateTimestamp)
        { 
            LoadData().Forget();
        }
    }

    public async UniTask LoadData()
    {
        nextUpdateTimestamp = 0;
        Debug.Log("passed");
        //server loading action (async)
    }```
grand snow
#

Update() doesn't need to await anything

#

Basically the design of this is a bit naff

nimble apex
#

but if its like this i think using coroutine should be fine

grand snow
#

Change Update() to a function that loops on its own then

nimble apex
#
    private void Awake()
    {
         StartCoroutine(ConstantValidation());
    }

    private IEnumerator ConstantValidation()
    {
        while (true)
        {
            yield return new WaitForSeconds(1);
            
            if (nextUpdateTimestamp != 0 && GetCurrentTimestamp() > nextUpdateTimestamp)
            { 
                LoadData().Forget();
            }
        }
    }```
nimble apex
grand snow
#

Why make it a coroutine 😭

#
public async UniTask Loop()
{
  while(this != null)
  {
    if (nextUpdateTimestamp != 0 && GetCurrentTimestamp() > nextUpdateTimestamp)
    { 
          await LoadData();
    }

    await UniTask.Yield();
  }
}
#

then call it with Loop().Forget();

#

this way it will actually wait for data to load and then continue to check each frame

daring sentinel
#

Any idea why I am getting this exception, when the animator is still assigned on the script within the editor.

This is my code for the script:


using Cysharp.Threading.Tasks;
using UnityEngine;

public class AnimationController : MonoBehaviour
{
    public Animator animator;
    public OptionsMenu optionsMenu;
    protected virtual void Awake()
    {
        animator = GetComponent<Animator>();

        if (animator == null )
        {
            Debug.LogError("No animator attached");
        }
        GameState.decisionTime += PlayerSpeaking;
        GameState.distributeDecision += (choice) => NPCSpeakingCaller(choice);
        GameState.verdictTime += PlayerSpeaking;
       
    }

    protected void NPCSpeakingCaller(int choice)
    {
        NPCSpeaking();
    }

    public virtual void NPCSpeaking()
    {
        //Debug.Log("NPC Speaking");
        animator.ResetTrigger("Player_Speaking");
        animator.SetTrigger("NPC_Speaking");
        if (optionsMenu.IsPlayerSpeaking())
        {
            optionsMenu.TogglePlayerPanel();
        }
    }

    public void PlayerSpeaking()
    {
        animator.ResetTrigger("NPC_Speaking");
        animator.SetTrigger("Player_Speaking");
        
    }


    protected virtual void OnDisable()
    {
        GameState.decisionTime -= PlayerSpeaking;
        GameState.distributeDecision -= NPCSpeakingCaller;
        GameState.verdictTime -= PlayerSpeaking;
    }
}

This only happens when I load the next level scene, not when playing the scene individually

#

Also what the hell does this error mean?

It doesn't affect anything when testing it just appears

grand snow
#

It was destroyed

#

Or was never assigned

daring sentinel
#

Is it not assigned in the editor and the script??

#

Like this only happens when I transition between level scenes, not when testing the levels individually

naive pawn
#

you probably have stale event listeners

#

(choice) => NPCSpeakingCaller(choice)
this one was never unsubscribed

naive pawn
grand snow
#

Huh yea it subs a lambda which is not referenced to unsubscribe with later.
The missing ref exception is not a great name

#

Also you should use OnDestroy instead of disable

daring sentinel
#

Alright thanks, I'll try that, I thought for some reason that I wouldn't need the lambda on unsubscription. Just wanna skip to the write up for this dissertation haha.

daring sentinel
#

How come?

grand snow
#

Yea because if it gets disabled and re enabled well your event subs are gone

naive pawn
grand snow
naive pawn
daring sentinel
naive pawn
#

parameters don't make a difference, no

#

(if they're being consumed in the same order)

#

if you wanted to ignore them, you would use a lambda then, but then that wouldn't work for the unsubscription

i thought you'd already figured that out, given the separate NPCSpeakingCaller

grand snow
#
Action myLambda = () => DoShit();
Game.event += myLambda;
//...
Game.event -= myLambda;

How to do this properly

#

you need a ref to the exact "function" you subscribed with

#

Thats why using a method is easier

daring sentinel
naive pawn
#

or if you want to change the order, yeah

#

basically - if you use the method (or an action) directly, the parameter list must match exactly

#

if the parameter list doesn't match, you need an intermediate function to handle the disconnect (which could be a method like you have here or a lambda in rob's example)

grand snow
#

This is why I just make a method with the matching args for event subscriptions

#

VS will even generate it for you if you do += SomeCoolNamePlzMakeForMe; (using the 💡)

daring sentinel
#

Ok I'll sort out the event subscriptions like that then, thanks so much! It's all good as all I need to show my supervisor is just a little demo so even if I can't get it to work it's all good, but it's just nice to have it as a little bit of polish

grand snow
#

The main thing is unsubscribing will prevent your event trying to interact with "destroyed" gameobjects/components

#

the cheaty way is to add a if (this == null) return; to stop early if it was destroyed

daring sentinel
#

And the handling of event subscriptions is why I was getting this error?

grand snow
#

I suspect so but I cant read the stack.
Use a debugger if you are interested and you can check if this == null to see the mono instance is "destroyed"

#

same for the animator/any component /gameobject type

naive pawn
#

(imo you should let it fail fast to pick up bugs like this though)

grand snow
#

Yea the exception informed you of this problem ᵗʰᵃⁿᵏ ᵘ ᵉˣᶜᵉᵖᵗᶦᵒⁿ

daring sentinel
#

So from that, is it because I never made an instance of the AnimationController class?

Because I already have:

if (animator == null )
        {
            Debug.LogError("No animator attached");
        }

And the error is on about UnityEngine.animator

grand snow
#

If you have a monobehaviour on a gameobject and it has valid references its all good BUT when that gameobject is destroyed so are the components.
Our monobehaviour instance still exists because a class instance cannot just be deleted, our event sub is still called but it now will try to interact with a destroyed animator... Thats why there is an exception.

daring sentinel
#

Oh right, so is it because I am transitioning between scenes, and these scenes have different NPCs with different animators attached. It's giving me this exception? But then again it's already assigned in the editor?

grand snow
#

you are confused, your NEW scene has a NEW instance of AnimationController

naive pawn
#

the issue was never about something not being assigned

#

the issue is about something that's been destroyed

#

the previous scene had an AnimationController that subscribed to GameState.distributeDecision with a method that ultimately called NPCSpeaking and accessed animator

animator was part of that previous scene, which wouldve been unloaded, thus destroying it
but the event listener was never unsubscribed, so the stale listener persists
then when it's triggered, it tries to do stuff to that destroyed animator, that's where the error comes from

timid pawn
#

any one here know why i cant download Visual Studios on my mac? im new to game dev (it says error -10661)

grand snow
#

its not supported anymore so try something else like vs code

timid pawn
#

oh thx

#

can any one tell me why my IntelliSense thingy isn't working on vs code?

naive pawn
#

!ide

eternal falconBOT
daring sentinel
# naive pawn the previous scene had an `AnimationController` that subscribed to `GameState.di...

ah ok so I fixed up the event stuff I think, but I still got the exception

using Cysharp.Threading.Tasks;
using UnityEngine;

public class AnimationController : MonoBehaviour
{
    public Animator animator;
    public OptionsMenu optionsMenu;

    protected virtual void OnEnable()
    {
        animator = GetComponent<Animator>();

        if (animator == null )
        {
            Debug.LogError("No animator attached");
        }
        GameState.decisionTime += PlayerSpeaking;
        GameState.distributeDecision += NPCSpeakingCaller;
        GameState.verdictTime += PlayerSpeaking;
    }

    protected void NPCSpeakingCaller(int choice)
    {
        NPCSpeaking();
    }

    public virtual void NPCSpeaking()
    {
        //Debug.Log("NPC Speaking");
        animator.ResetTrigger("Player_Speaking");
        animator.SetTrigger("NPC_Speaking");
        if (optionsMenu.IsPlayerSpeaking())
        {
            optionsMenu.TogglePlayerPanel();
        }
    }

    public void PlayerSpeaking()
    {
        animator.ResetTrigger("NPC_Speaking");
        animator.SetTrigger("Player_Speaking");
        
    }


    protected virtual void OnDestroy()
    {
        GameState.decisionTime -= PlayerSpeaking;
        GameState.distributeDecision -= NPCSpeakingCaller;
        GameState.verdictTime -= PlayerSpeaking;
    }
}
naive pawn
#

🤨 you have subscription in OnEnable but unsubscription in OnDestroy?

daring sentinel
#

For more context, this is the class that inherits this, which is used in this scene:

using Cysharp.Threading.Tasks;
using JetBrains.Annotations;
using System;
using UnityEngine;

public class Level2Animation : AnimationController
{
    public GameState gameState;
    public Level2Timelines level2Timelines;

    protected override void OnEnable()
    {
        Level2GameState.EndOfInterruption += RecallingToTalking;
        Level2GameState.interruptionOption += PlayerSpeaking;

    }

    public override void NPCSpeaking()
    {
        base.NPCSpeaking();
        level2Timelines.UpdateTimeStamp();
    }

    public void DisclosureResponse()
    {
        if (gameState.understandingNPC)
        {
            NPCSpeaking();
        }

        else
        {
            NPCArguing();
            optionsMenu.TogglePlayerPanel();
        }

    }


    public AnimatorStateInfo GetCurrentState()
    {

        return animator.GetCurrentAnimatorStateInfo(0);
    }

    public void Recall()
    {
        animator.SetTrigger("Recalling");
    }

    public void NPCArguing()
    {
        animator.SetTrigger("NPC_Arguing");
    }

    public void RecallingToTalking()
    {
        animator.SetTrigger("Finished_Recalling");
    }

    public async UniTaskVoid InterruptedAnimation()
    {
        animator.SetTrigger("Player_Speaking");
        while (!GetCurrentState().IsName("Waiting"))
        {
            await UniTask.Yield();
        }
    }

    public async UniTaskVoid IdleToArguing()
    {
        animator.SetTrigger("NPC_Arguing");

        while (!GetCurrentState().IsName("Arguing"))
        {
            await UniTask.Yield();
        }
    }

    protected override void OnDestroy()
    {
        base.OnDestroy();
        Level2GameState.EndOfInterruption -= RecallingToTalking;
        Level2GameState.interruptionOption -= PlayerSpeaking;
    }
}

naive pawn
#

oh god

#

!code

eternal falconBOT
naive pawn
#

see the section on large code blocks

daring sentinel
#

Oh right, sorry

naive pawn
#

you aren't even doing the subscription there lol

naive pawn
#

the point rob made was about, symmetry i guess? not sure what to call it

#

Awake and OnDestroy are analogous
OnEnable and OnDisable are analogous
use 1 set of those for the subscription and unsubscription, rather than mixing them

#

if you subscribe in Awake, unsubscribe in OnDestroy
if you subscribe in OnEnable, unsubscribe in OnDisable

daring sentinel
grand snow
daring sentinel
#

@naive pawn @grand snow Thank you both so much, it works now. Can't believe I forgot to call base when overriding haha

#

You guys should honestly get paid with how helpful you are in this server

#

Idc if it comes off as me glazing you like it's krispy kreme but unity should deadass give some of you lot a piece rate.

grand snow
#

When you have used unity for many years you just learn all this stuff 😆
Glad to pass on some knowledge

woven crater
#

hi. wanna ask if using multiple material on one object is a good idea. like using one to rendering 2d character sprite then add more material to it to add vfx on top

#

or do i have to add all the effect logic into one shader?

tiny crag
river bone
woven crater
#

adjust your collider bound on your character

river bone
#

👍

#

I'll give that a go

median yew
hexed terrace
median yew
naive pawn
#

that link doesn't work either

naive pawn
#

if someone is available and able to help, they will be in #1390346492019212368.
if there isn't anyone available, you won't get an answer here either

#

so, don't crosspost

median yew
#

ok but how do i make it public

pulsar helm
#

I need help. Does anybody know how I can access the local scale of an object? Like, from what I can understand, it isn't as simple as controling the position and rotation.

naive pawn
#

what's your actual issue?

pulsar helm
#

yes

naive pawn
#

the scale of an object doesn't affect its position or rotation, it affects the position and scale of its children

pulsar helm
#

Ok, so im trying to make a health bar, my plan is to reduce the X axis scale of the bar as the hp goes down. I have tried a lot of stuff But I cant figure out how do I control the transform.scale with code.

naive pawn
#

if it's a UI element, why not just use the built-in facilities like slider

slender nymph
#

pro tip: don't use scale or a slider for an HP bar. use an image set as a filled image and you can assign a value from 0 to 1 to manage its percentage
this also has the bonus of looking better too

pulsar helm
pulsar helm
slender nymph
#

it's an image component where its type or whatever is set to filled. you can literally test it out yourself

pulsar helm
#

Interesting, that could actually work

#

Thanks

grand snow
#

Yea thats what you should do instead of your initial crazy idea

hexed terrace
#

you need to assign a sprite to an image component for the option to set it as 'filled' to show

pulsar helm
hexed terrace
#

it isn't

grand snow
#

they must not know much about unity 😆

hexed terrace
#

it will look awful the smaller it gets (if it's not just a colour)

pulsar helm
hexed terrace
#

it's just a beginner mistake

grand snow
#

Beginners teaching beginners rip

pulsar helm
hexed terrace
#

why's that funny?

pulsar helm
#

Cus it's the one exception

naive pawn
pulsar helm
hexed terrace
#

you can disbale the interaction

#

Using a slider for health, you want to remove some of the components/ elements that get auto added when you create it

slow blaze
#

I think vs is not recognising the dotnet sdk
I can write code and it works but I can't see references and the Using directives are "unnecessary"
Other and new projects work fine, unity ones do not

hexed terrace
slender nymph
eternal falconBOT
naive pawn
grand snow
#

slider does work with filled too btw

pulsar helm
hexed terrace
#

A downside to image filled is that it's hard,flat cut off,

hexed terrace
pulsar helm
hexed terrace
#

it could, but scroll bar has a built in field for setting its position.. so it's much easier to use

pulsar helm
#

I see

naive pawn
#

the scrollbar i mean

hexed terrace
#

tweened, but pretty much yeah

#

Gotta normalise the values first

slow blaze
naive pawn
#

are the "other" projects where it works, using dotnet?

pulsar helm
naive pawn
#

it is an image with image type filled

#

the component is just called Image

pulsar helm
#

ooh thanks

slow blaze
#

creating a new dotnet project works fine, Opening old unity projects works fine

#

this one worked fine till this morning idk what changed

hallow acorn
#

what does Vector2 direction do in a Physics2D.CircleCast()?

naive pawn
naive pawn
hallow acorn
naive pawn
#

no

polar acorn
naive pawn
#

you may be confusing an overlap check vs a cast check

polar acorn
#

CircleCast is not OverlapCircle.

#

It's more like firing a beach ball out of a cannon

naive pawn
hallow acorn
#

ohhhhhhh okay thank you guys

pulsar helm
naive pawn
#

you need to not have one

#

SpriteRenderers are for rendering sprites in the world
Images are for UI, in a canvas

pulsar helm
#

so how do I get it to show up?

naive pawn
#

show up where?

pulsar helm
#

on the screen, The sprite

naive pawn
#

what step are you on right now

#

you've added the component, right

pulsar helm
#

yes

hexed terrace
#

... the image component displays it on the UI

pulsar helm
#

and set it to filled

naive pawn
#

and how filled have you set it to be

hexed terrace
#

!learn -> do UI tutorials

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

hexed terrace
#

this is now beyond the scope of this channel, it's nothing to do with code

pulsar helm
naive pawn
#

that.. doesn't answer my question
go do some tutorials

pulsar helm
naive pawn
#

the fill amount

#

but yeah you should go do UI tutorials

polar acorn
pulsar helm
#

huh, yeah Im going to get some tutorials. i have no clue wtf im doing

slow blaze
hexed terrace
simple prism
#

When setting the vertex attributes and triangles of a Mesh, does the check of whether triangles indexes out of bounds of the vertex attributes happen when any of the vertex attributes or triangles is set, or only when triangles is set?
In other words, when I am changing the lengths of multiple vertex attributes, can I always set triangles last (this corresponds the case where the check only happens when triangles is set), or do I have to set it first or last depending on whether I am shortening or lengthening the vertex attributes?

hallow acorn
polar acorn
hallow acorn
wintry quarry
#

Meaning it didn't find any colliders

polar acorn
#

So check all of the .s and see what is the thing that's being .ed

#

If that thing is something that can be null, check if it's null

hallow acorn
#

nvm

polar acorn
#

bools do not have a CompareTag function

hallow acorn
#

so i have to check if th overlapcircle returns something, and then i check if the tag is correct?

polar acorn
#

Yes

twilit aurora
#

I am learning Unity in 3d currently,
I have gotten my camera to spin around a pivot at the centre of a sphere but I cannot get a zoom in/out function to work

        float scroll = Input.GetAxis("Mouse ScrollWheel");
        zoomDistance = scroll += zoomDistance;
        zoomDistance = Mathf.Clamp(zoomDistance, MaxZoomOut, MaxZoomIn);
        cameraTransform.localPosition = new Vector3(0, 0, zoomDistance);

        // Tilt up if close
        if (zoomDistance <= -2.5f)
        {
            
        }```
This code above is the one that doesn't work (Only the actual position change doesn't work)
```    private float zoomDistance = 1f; //Starting distance of camera
    private float MaxZoomIn = 10f; //Max in
    private float MaxZoomOut = -10f; //Max out```
These are the floats I am using ☝️ 

Can someone please help because I haven't found any online solutions that work?
naive pawn
#

zoomDistance = scroll += zoomDistance;
this seems a bit off.

#

but have you tried debugging what you're getting zoomDistance as?

#

do you see the position changing in the inspector?

#

are you getting any errors?

twilit aurora
wise cairn
#

hey guys so i'm trying to make a game with my friend and we're using unity version control, how do i make packages sync?

frosty hound
#

There is a manifest.json in the Packages folder which list your packages and versions.

twilit aurora
#

As I scroll up, it slightly breaks (I think) I am new to Unity to I am not sure

naive pawn
#

what value are you logging?

twilit aurora
#

"zoomDistance"

naive pawn
#

that's not really broken, the value is still increasing

naive pawn
twilit aurora
#

I have a pivot at the centre of the sphere and the camera rotates based on where the pivot is

naive pawn
#

that's not what i asked

polar acorn
naive pawn
#

check in the inspector of the thing you're trying to move, see if the value in there changes

twilit aurora
twilit aurora
wise cairn
naive pawn
wise cairn
#

none of them are installed on his side

#

he showed me his screen

naive pawn
#

ok, and what did it show

#

what exactly is saying that the packages aren't installed

twilit aurora
wise cairn
#

like he showed me his package manager

naive pawn
#

you shouldve gotten errors, this

and after "zoomDistance = scroll += zoomDistance;" nothing is logged,
wouldve been a hint to that

naive pawn
twilit aurora
naive pawn
#

we need info to actually help you

wise cairn
naive pawn
#

is the package.json checked in

#

(is it added to vcs)

wise cairn
#

package.json?

polar acorn
naive pawn
wise cairn
#

oh ok

#

yeah it is

naive pawn
#

has unity done the refreshing assets library thing

#

you should just have your friend ask here instead of playing this game of telephone

wise cairn
#

alright

sleek gazelle
#

Hey, I have a problem, I switched one of my unity projects to another laptop and now when I run it I get an error telling me that PlayGamesPlatform (part of the googleplaygames plugin v0.11.1) does not exist in the current context when running PlayGamesPlatform.Activate();, I am running using using GooglePlayGames; so I don't really see where the problem comes from

#

The platform went back to Windows from what I can see, idk why, I'm gonna try to switch

#

That fixed it

languid pagoda
polar acorn
trim quarry
#

do i need to use rigid body for character controller?

slender nymph
#

no, ideally you wouldn't be using those two components on the same object at all

trim quarry
#

also im flying up

#

tried to use YSpeed float thing

#

that most of the videos telling to do that

slender nymph
#

you need to provide actual details

polar acorn
#

You're probably going to have to share !code because "YSpeed float thing" doesn't really help at all

eternal falconBOT
trim quarry
#

ok wait

#
    void FixedUpdate()
    {
        if (gameObject != null)
        {
            jumpcooldown = !(Time.time >= last_jump_tick);

            YSpeed += Physics.gravity.y * Time.deltaTime;

            if (Input.GetButtonDown("Jump"))
            {
                YSpeed = -0.5f;
                onground = false;
            }

            if (charController.isGrounded)
            {
                YSpeed = -0.5f;
                onground = true;

                float horizontal = Input.GetAxis("Horizontal");
                float vertical = Input.GetAxis("Vertical");

                MoveDirection = new Vector3(horizontal, 0, vertical);
                MoveDirection.Normalize();
                float MoveMagnitude = MoveDirection.magnitude;
                MoveMagnitude = Mathf.Clamp01(MoveMagnitude);

                charController.SimpleMove(MoveDirection * MoveMagnitude);

                if (CameraObject != null)
                {
                    Vector3 CameraForward = CameraObject.transform.forward * vertical;
                    Vector3 CameraRight = CameraObject.transform.right * horizontal;

                    Vector3 CameraLookMove = (CameraForward + CameraRight).normalized;

                    MoveDirection = SetVectorZeroY(CameraLookMove);
                    MoveDirection.Normalize();
                }

                if (jumpcooldown == false && Input.GetButtonDown("Jump"))
                {
                    YSpeed = 20f;
                    onground = false;

                    last_jump_tick = Time.time + .3f;
                }

                Vector3 Movement = MoveDirection * MoveMagnitude;
                Movement.y = YSpeed;
                charController.Move(Movement * Time.deltaTime);
            }
        }
    }```
#

the movement lines

polar acorn
#

Build up a vector containing all of the movement you want this frame, and call .Move at the end with that combined vector

trim quarry
#

ok

#

wait

#

ill feedback later

#

maybe its because of charcontroller and rigidbody is in the same gameobject?

naive pawn
#

that's definitely not right

#

they will fight for control

#

have rigidbody or charcontroller, not both

trim quarry
#

but having only the charcontroller making my capsule frozen

polar acorn
naive pawn
trim quarry
daring sentinel
#

Any idea why the list still has an element in it, after restarting the scene? Even though I clearly use List.Clear() in the script that it's established in both in awake and ?

    public List<string> sceneFlags;

     protected virtual void Awake()
    {
        decisionNum = 0;
        timesStared = 0;
        timesAverted = 0;

        if(sceneFlags != null){
            sceneFlags.Clear();
        }

{...}

    protected virtual void OnDestroy()
    {
        Debug.Log("Scene end");
        Debug.Log(sceneFlags.Count);
        sceneFlags.Clear();
        optionsMenu.optionSelected -= relayDecision;
        metreManager.GazeWinCondition -= SetGazeCondition;
        metreManager.TriggerInterruption -= relayInterruption;
        gazeDetector.GazeDetected -= setGazeValues;
        metreManager.EnergyDepleted -= EndGame;
    }

protected IEnumerator StareAndAversion()
{
    while (!sceneOver)
    {
        if (gameState.sceneFlags.Count > 0 ) { Debug.Log("metres paused");
            Debug.Log("pause flags active: " + gameState.sceneFlags.Count);
            Debug.Log(gameState.sceneFlags[0]);
            yield return new WaitUntil(() => gameState.sceneFlags.Count <= 0); }
{...}

}

 protected IEnumerator GazeGaugeMetre()
{
    while (gazeGauge.fillAmount < 1f && !sceneOver)
    {   
        if (gameState.sceneFlags.Count > 0) { yield return new WaitUntil(() => gameState.sceneFlags.Count <= 0);}


What happens is that coroutines like this freeze after restarting the scene#

polar acorn
#

unless you have another yield statement in that {...} you cut out

hallow acorn
daring sentinel
# polar acorn If `sceneOver` is false, but `gameState.sceneFlags.Count` is less than or equal ...

Here's the rest of the class, cut it to save on characters:

protected IEnumerator StareAndAversion()
{
    while (!sceneOver)
    {
        if (gameState.sceneFlags.Count > 0 ) { Debug.Log("metres paused");
            Debug.Log("pause flags active: " + gameState.sceneFlags.Count);
            Debug.Log(gameState.sceneFlags[0]);
            yield return new WaitUntil(() => gameState.sceneFlags.Count <= 0); }

       {...}
        yield return null;
    }
}

protected IEnumerator GazeGaugeMetre()
{
    while (gazeGauge.fillAmount < 1f && !sceneOver)
    {   
        if (gameState.sceneFlags.Count > 0) { yield return new WaitUntil(() => gameState.sceneFlags.Count <= 0);}

       {...}
        yield return null;
    }
    if (gazeGauge.fillAmount >= 1f)
    {
        GazeWinCondition?.Invoke();
    }
}
protected void ResetBars()
{
    staringScale.fillAmount = 0f;
    aversionMetre.fillAmount = 0f;
}

protected virtual IEnumerator energyMetre()
{
    while (energyBar.fillAmount > 0f)
    {
        switch (gazeStatus)
        {
            case GazeStatus.maintainedOnTarget:
                energyDrainRate = 3f;
                break;

            case GazeStatus.maintainedNearMiss:
                energyDrainRate = 2f;
                break;

            default:
                energyDrainRate = 1.0f;
                break;
        }

        energyBar.fillAmount = Mathf.Clamp01(energyBar.fillAmount -= energyDrainRate * (Time.deltaTime / totalEnergyTime));
        yield return null;
    }
    EnergyDepleted?.Invoke();
    StopAllMetres();
}

void StartMetres()
{
    StartCoroutine(energyMetre());
    StartCoroutine(StareAndAversion());
    StartCoroutine(GazeGaugeMetre());
}


protected enum GazeStatus
{
    OffTarget,
    maintainedNearMiss,
    maintainedOnTarget,
}

void StopAllMetres()
{
    sceneOver = true;
    StopAllCoroutines();
    
}

How is it infinite if it's a WaitUntil then is opposite to what is inside the if brackets?

eternal falconBOT
polar acorn
eternal falconBOT
daring sentinel
#

My b soz

polar acorn
eternal needle
# hallow acorn https://hastebin.skyra.pw/curagutowa.csharp hey can someone tell me why my chara...

add logs and see for yourself why it is not moving, theres a lot of logic here that you should be able to narrow down rather than saying its "most likely" in the food function. There should be no guessing here, use logs to find out where the actual problem is
Also please for all thats holy, cache the Physics2D.OverlapCircle(transform.position, sightRadius) that you do 3 times in LookForFood. you only need to do it once

polar acorn
hallow acorn
polar acorn
#

Significantly.

hallow acorn
#

fixed it. idk whhy but i fixed it

daring sentinel
# polar acorn Okay, so it _does_ have a `yield return null` outside the condition, so that's f...

I restart the scene and then even though I clearly use List.Clear(), it acts like there's still a string in the list. I'm using LoadSceneMode.single to reload the scene as well for more context. How the coroutines work is that they're based on these two boolean values from another class that get fired when the player hovers their mouse over a specified area. At first when restarting the list is empty, but then when hovering again, it now says there's 1 element in the list and locks my coroutines. I really don't get it:

Here's the class that fires an event based on mousehover that passes those two booleans:

https://paste.ofcode.org/KccaPPd6vKFsccRSzvQAPm

rich adder
polar acorn
hallow acorn
rich adder
daring sentinel
#

I think I might have figured it out now, turns out I never unsubbed from an event that causes one of the specified strings to be added to the list

#

Just tested it twice, yeah it was to do with events. Still thanks for the help tho @polar acorn

trim quarry
#

im still having the issues with character controller

#

it just floating

#

it cant move

#

oh i just fixed it

pulsar helm
#

Hello, Does anybody here know how unity calculates scale based on position. Im trying to determine the edge points of a box from one another.

polar acorn
pulsar helm
pulsar helm
#

ok, I'l trust you

#

ok I might be dumb, but the documentaion barely explains how to use it, Is it through code or do I need a specific component for it to work?

polar acorn
#

You would use the Bounds to get the center and extents in any given direction

#

Then you could use that point for doing your math

glass ivy
polar acorn
# glass ivy

You know that one Austin Powers bit where they're very slowly driving a steam roller at a guard and he just stands in the way screaming for like five full minutes instead of getting out of the way?

Sometimes when you're coding you're that guard.

toxic cove
#

anyone know how to get unity 5.3.3f1 working 😭

polar acorn
#

I'd say probably don't

glass ivy
polar acorn
glass ivy
toxic cove
glass ivy
ashen sorrel
#

I need help PLEASE

#

first project

chilly copper
#

how do i share my project

wintry quarry
chilly copper
#

my friend

wintry quarry
#

Version control (either Git or Unity Version Control)

wintry quarry
#

if the former, version control

#

if the latter, make a build and share that

chilly copper
#

yes developing

#

but it does not show up for him

#

i have him added to everything

wintry quarry
#

what doesn't show up for him

#

what did you add him to

chilly copper
#

the project

#

the org

wintry quarry
#

You could have started your question like "I'm using Unity version control to share my project with my friend, but he can't see it even though he's added to the org"

chilly copper
#

oh mb

wintry quarry
chilly copper
#

ok

#

gimme a sec

chilly copper
wintry quarry
chilly copper
#

how would i see that

wintry quarry
#

you would know if you had

chilly copper
#

yes

#

i have

#

so what could be the problem

chilly copper
#

i really need help

wintry quarry
chilly copper
#

he is on the unity hun

#

hub

#

and yes he is

#

@wintry quarry

tame relic
#

How would I make a web request in a custom editor window

umbral bough
#

Hey, I'm trying to get started with the gtk.
Making the ui seems pretty easy but I can't find any resources, other than the 2 attached samples, on writing the backend.
Can somebody recommend a good source for understanding that?
I am looking to make a tool that functions in a similar way to the shader graph, several nodes with math operations going down into a single node(the final float result).
Please @ me and thanks in advance!

neon glade
#

anyone active rn

#

so ive made a 'guard' type enemy so they have a spotlight with a range of 10, and i want it so that if the player is seen within the radius the enemy changes direction

hollow slate
#

if you have a fixed light-cone, you could model a mesh in blender and use OnTriggerEnter for certain layers, and then use RayCasts to check if the object is actually visible from the light.

#

if you're in 2D you can use the Polygon-collider, to make one without blender.

#

if you're okay with losing some performance you could also do a non-alloc box/spherecast every FixedUpdate and then use maths to find out if the object is within the cone.

#

plenty of ways.

sudden prairie
#

Hello mates, I'm trying to tilt this rocket by pressing left-arrow and right-arrow keys from keyboard. Here is the rotation script I used for it: -

    {
        float rotationInput = rotation.ReadValue<float>();
        Debug.Log("Here is your rotation: " + rotationInput);
        if (rotationInput < 0)
        {
            transform.Rotate(Vector3.forward * rotationSpeed * Time.fixedDeltaTime);
        }
        if (rotationInput > 0)
        {
            transform.Rotate(-Vector3.forward * rotationSpeed * Time.fixedDeltaTime);
        }
    }```
And ofc I added the namespace InputSystem.
Also, I tried `Debug.Log("Here is your rotation: " + rotationInput);` and it perfectly prints out -1 (by pressing left-arrow key) and 1(by pressing right-arrow key) on console.

PROBLEM: This rocket isn't giving even a slightest tilt after all this. idk why.
river pulsar
#

Does anyone know how to learn Unity engine professionally?

#

@hollow slate

rich ice
eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

hexed terrace
#

this is a code channel (hence the name), delete your post from here and ask in #📲┃ui-ux after doing some tutorials on !learn 👇

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

snow flint
hexed terrace
snow flint
#

🤣

naive pawn
#

what "passive aggressive" are you seeing...

hexed terrace
#

the (hence the name) - though when I typed it I was thinking it in a more haha tone, but ¯_(ツ)_/¯

pulsar helm
#

Is it possible to give a line renderer collision?

naive pawn
pulsar helm
#

matey im just asking for help😢

naive pawn
#

yeah and im saying that google is a great place to start for a broad question like that

verbal dome
#

Do the positions of the line change?

pulsar helm
#

im trying to make a closed box, and the line renderer is the outlines of the box.

verbal dome
#

Why not just use a box collider

pulsar helm
#

Well, the line itself isn't an object, so the collider would just be wherever the line renderer object is. Also, the box changes size at times and so do the lines.

hexed terrace
#

box colliders can change size

#

could use quads (though that's just using a really thin box collider) instead, which would allow you to have the colliding bounds "grow" with the line renderer

light frost
#

hello there friends

#

I need some help with a project, I created a simple cube in a plane just to test some theories i saw

#

but for certain i have misplaced some line of code

#

i mean, let me pass the code here

#

there is the code and video of the bug, anyone knows how to fix this behavior?

naive pawn
eternal falconBOT
naive pawn
patent wedge
#

i have a basic interface but for some reason the override doesn't work?

public interface SimpleInterface
{
    void DoSomething() {}
}

public class SimpleScript : MonoBehaviour, SimpleInterface
{
    public override void DoSomething()
    {
        Debug.Log("worked");
    }
}
naive pawn
light frost
patent wedge
light frost
patent wedge
naive pawn
naive pawn
light frost
#

yes, i will

#

one moment

patent wedge
naive pawn
#

show your current code

light frost
naive pawn
#

ah wait @patent wedge you don't need override on interface impls

#

override is for methods marked abstract or virtual

patent wedge
naive pawn
naive pawn
#

(why not just use a base class though)

naive pawn
polar acorn
light frost
naive pawn
light frost
#

oh ok

naive pawn
#

choose either a rigidbody+collider, or character controller

light frost
#

right, thank you

polar acorn
patent wedge
naive pawn
#

isn't that a class

#

you could just have your base already extend networkbehaviour

#

or are you trying to get multiple inheritance?

patent wedge
naive pawn
#

so you want multiple inheritance?

patent wedge
polar acorn
polar acorn
teal viper
#

Doesn't network behavior inherit from MonoBehaviour?

patent wedge
teal viper
#

Thats 2 different methods. Not sure how that's related to inheritance.

light frost
naive pawn
#

maincamera is just a name

#

and a tag i guess

#

it doesn't really have behaviour

light frost
#

yes, it has a component called camera, i dont know if conflicts or something like this

naive pawn
#

cinemachine depends on camera

#

it controls the camera, rather than fighting with it over control of something else

#

(rigidbody and cc would fight over control of transform)

light frost
#

ok, thank you

patent wedge
polar acorn
patent wedge
naive pawn
polar acorn
slender nymph
# patent wedge ok i have just realized that interface types aren't forced to have the methods i...

what you've just stumbled across is called Default Interface Methods, yes they allow you to declare the body of a method directly in the interface but that should not be used just so you don't have to implement an interface's method. the entire point of an interface is that the members declared on it are accessible. Split it up into multiple interfaces if you want only partial functionality on some things

patent wedge
slender nymph
#

what do you need that for

naive pawn
#

that's pretty irrelevant to default methods

naive pawn
patent wedge
polar acorn
slender nymph
#

no they cannot

patent wedge
slender nymph
#

that's not a field

polar acorn
rich adder
#

thats a property mate

#

" fancy methods "

naive pawn
#

well, they can have static or const fields
but not instance fields

#

so that doesn't really help you

patent wedge
naive pawn
#

this seems like a nightmare of an architecture

slender nymph
#

you have yet to explain why you need this

naive pawn
#

you should probably plan out some stuff about what you're trying to achieve with this

polar acorn
#

This literally is not what interfaced are for

patent wedge
naive pawn
#

ok, that sounds like it's doing too much