#💻┃code-beginner

1 messages · Page 162 of 1

rare basin
#

why not?

nocturne phoenix
#
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    [SerializeField] int speed;
    Rigidbody rb;
    // Start is called before the first frame update
    void Start()
    {
 
        rb = GetComponent<Rigidbody>();

        speed = 5;

    }

    // Update is called once per frame
    void Update()

    {

        float x = rb.velocity.x;
        float y = rb.velocity.y;
        float z = rb.velocity.z;

        float verticalInput = Input.GetAxis("Vertical");
        float horizontalInput = Input.GetAxis("Horizontal");


        if (Input.GetButtonDown("Jump"))
        {
            rb.velocity = new Vector3(rb.velocity.x, speed, rb.velocity.z);
            Debug.Log("Jumped!");
        }

        if (Input.GetButton("Vertical"))
        {
            rb.velocity = verticalInput * speed * transform.forward;
        }

              if (Input.GetButton("Horizontal"))
                {
                     rb.velocity = (horizontalInput * speed * transform.right, y, z);
                       }
                
    }
}
#

this wont work

#

and i cant figure out

#

how else to do it

rare basin
#

jezus

#

i just told you

#

10 times

hexed terrace
#

then you have somewhere else changing the Y val

frank flare
#

for my object it's right and left

rare basin
#

and you are still passing vector3 for a x parameter

nocturne phoenix
#

that was showing

#

that wont work

#

*that was for showing

#

so what else can i use

rare basin
#

dude

nocturne phoenix
#

i removed that already

rare basin
#

did you read my messages

nocturne phoenix
#

i know why its not working

nocturne phoenix
rare basin
#

i already explained you how to do it

nocturne phoenix
#

OH

#

i just

#

understood what that does

#

😭

#

my brain is a little slow

#

so essentially manipulate velocityvector instead of rb.velocity

#

and then declare rb.velocity the same as velocityvector

#

right?

rare basin
#
  if (Input.GetButton("Horizontal"))
  {
         Vector3 velocityVector = horizontalInput * speed * transform.right;
         velocityVector.y = y;
         velocityVector.z = z;
         
         rb.velocity = velocityVector
   }
frank flare
#

Ignore cow rotating when moving forward

nocturne phoenix
#

i understood that

#

ty

frank flare
#

it's because something else is wrong

nocturne phoenix
#

thats a question i got

rare basin
#

jezus xd

nocturne phoenix
rare basin
#

you cannot set x to a vector3

frank flare
fickle plume
#

!warn 756739408379510814 Please remove the transphobic meme from pronouns or you will be removed from the server.

eternal falconBOT
#

dynoSuccess norwxy has been warned.

tawdry rock
#

im trying to make a laser pointer but it seems like it has a delay when looking around with the mouse. Any smart fix for it?

if (Physics.Raycast(laserStartPoint.transform.position, laserStartPoint.transform.forward, out laserHit, 100f, ~ignoreLayer))
{
    if (laserHit.collider != null)
    {
        lineRederer.SetPosition(0, laserStartPoint.position);
        lineRederer.SetPosition(1, laserHit.point);

    }
nocturne phoenix
#

dw i aint transphobic

fickle plume
#

Put debug messages where this is called and see if they are delayed

tawdry rock
fickle plume
#

then keep dropping debug messages up the chain to find the source

#

This involves physics as well so will be executed on physics frame (not sure exactly when raycasting is called in this case)

#

You can have more Update cycles before it executes

restive ore
#

can anyone teach me how to make a better map for my 2d rpg game?

rare basin
#

this is a code related channel mate

restive ore
#

oh wait

#

oh sorry

keen dew
#

There's nothing in this that involves mouse movement so potentially the code that rotates (?) the laser pointer is what causes the lag

rare basin
#

or the if just doesnt execute

#

everytime you would expect

#

put debug logs in there

tawdry rock
rare basin
#

nothing in this code could cause delay

tawdry rock
#

Well then idk what causing this. (the delay, not when i look up to skyebox and it lose the connection)

fickle plume
#

Yea, it looks like raycast would give you an immediate result in Update or FixedUpdate, but if you expect to see changes affect something physics related, those will be only after next Physics frame.

hexed terrace
#

It breaks when you look up because there's no hitpoint in the empty sky

#

The visual for this also doesn't even need to be updated.. just have it as a child of the gun, positioned correctly, and toggle it on/off

tawdry rock
restive ore
#

uhh anyone can help me idk how to script

#

when i click edit script

tawdry rock
restive ore
#

it says blender word point and those randoms

#

what do i press?

tawdry rock
#

but yea i might end up using some photoshoped image instead of this stupid linerenderer

hexed terrace
eternal falconBOT
restive ore
#

or do i have to download visual studio?

#

oh

#

so i gotta install visual

hexed terrace
#

You've got to install something to code with

restive ore
#

ok

tawdry rock
#

Notepad blushie

fickle plume
celest spoke
#

Is there anyone here that is good at 2D games, im currently trying to make a scenechanger but my player is not colliding with the scenechanger object that i have created, and i cant for the love of my life find what the problem is.a Any help is greatly apperitiated! ❤️

restive ore
#

but then suddenly he just randomly start scripting

fickle plume
tawdry rock
restive ore
#

but now im in visual studio

#

i pressed unity

#

game development with unity

#

do i have to press C++?

fickle plume
#

@restive ore course explains everything, including VS install

restive ore
#

ohh

#

ok

celest spoke
modest dust
celest spoke
celest spoke
#

That didnt really help but ty anyways, i have been looking at that page all day yesterday. Something is just wrong and i cant find it 😦

languid spire
#

start with screenshots of the inspectors of your 2 objects and post your !code

eternal falconBOT
celest spoke
languid spire
#

I posted the bot for a reason

celest spoke
#

i dont understand how it works sorry im new here

hexed terrace
#

You're using OnCollisionEnter2D and both colliders are set to Triggers

hexed terrace
somber sun
#

Does anyone know how to fix this, it gets an error everytime i press space😭.

languid spire
#

rb is null because you never assign it to anything

hexed terrace
celest spoke
somber sun
tawdry rock
# celest spoke

The player boxcollider doesn't need to be a trigger if the scene changer's is ticked. also should work:

public void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.CompareTag("Player"))
        {
            Debug.Log("Player is colliding");
            SceneManager.LoadScene(sceneToLoad);
        }
    }
hexed terrace
#

remove the rigidbody from the scenechanger too.. you only need 1

languid spire
thorny wedge
#

Yo. i got 5 extensions installed at vscode : unity ,C# , .NET, C#dev kit and intellicode. They take 2.7gb ram, which is concerning. is this normal?

hexed terrace
#

If you downloaded them from within VSC, yes ..

celest spoke
hexed terrace
celest spoke
#

Nope they are not colliding because im not getting a message :/

remote sequoia
#

When player collide with tagged "Enemy", enemy acts like player has powerup. İ dont want this but i couldnt find where is the problem?

hexed terrace
hexed terrace
remote sequoia
#

what?

thorn holly
#

The variable hasPowerup is set to true

hexed terrace
#

Oh, actually.. your condition is

if ((enemy) OR (enemy fast AND hasPowerup))

#

so any normal enemy will trigger the first one

thorn holly
#

Ah

#

Yep that’s it

hexed terrace
#

You'll want to put brackets round the enemies

if ((enemy OR enemyFast) && hasPowerup)

remote sequoia
#

lets try

#

yeey its worked!

#

but how

hexed terrace
#

or not

hexed terrace
remote sequoia
#

i saw

celest spoke
#

Sorry i had to listen through it since it had audio lol

remote sequoia
#

thankss

thorny wedge
arctic ibex
#

hello! I'm having an issue with my code (atleast i think it's code related)
In the inspector, it keeps tellign me "Object reference not set to an instance of an object" but i cant find any references that dont have objects set? And it doesn't cite any code, just some long list of things related to an animator. THe animator currently isn't working, the clips, start and end states aren't showing up, even though i deleted the whole thing and made a new one. I think it is an issue with the object I'm trying to animate, but i can't figure out what it is.

hexed terrace
#

argh, why did you not show the inspector

hexed terrace
thorny wedge
languid spire
arctic ibex
#

I have been trying to figure that out for half an hour:)

thorn holly
celest spoke
languid spire
#

The UnityEditor bit is a bit of a giveaway

arctic ibex
languid spire
#

you should never get UnityEditor errors unless you write your own Editor code

arctic ibex
#

It worked

#

thx

#

oh side note, any reason why this isn't jumping?

hexed terrace
thorn holly
arctic ibex
#

thankyou

celest spoke
#

the top one if for collision objects so i cant go through certain objects and the other one is so i can interact with specific objects when pressing E

hexed terrace
#

It's possible this affects your trigger collision

celest spoke
#

want me to send you the code?

thorn holly
celest spoke
thorn holly
arctic ibex
#

but i keep my velocity when i jump

#

I just tested it

#

oh wait maybe not

thorn holly
#

I was wrong yeah

#

You’re setting transform.position for horizontal velocity so yeah you’re good

#

Mb

arctic ibex
#

alright! I'll keep that in mind tho, i didn't know you could add velocity instead of setting it

thorn holly
#

Or just += to the velocity

arctic ibex
eternal falconBOT
arctic ibex
#

out of curiousity, is there any easy way to set where a player spawns depending on which scene you just left? or do i just need to make a logic script any a bunch of variables?

celest spoke
#

I honestly dont understand how to paste code with that tool

hard hornet
#

a variable reference to the last scene you were in

celest spoke
arctic ibex
hard hornet
#

i dont think so, you'd need to take care of that yourself

#

you could make it a singleton to set it more easily

arctic ibex
hard hornet
#

so it can be accessed in every script easily

#

without references and all that stuff

languid spire
arctic ibex
hard hornet
# arctic ibex whats that?
using UnityEngine;
using UnityEngine.SceneManagement;

public class LastSceneManager : MonoBehaviour 
{
  public static LastSceneManager Instance { get; private set; }
  public int lastScene;

  public void Awake() {
    Instance = this;
  }

  public void SetLastScene(int sceneId) {
    lastScene = sceneId;
  }
}

then you can reference it anywhere in your scripts like this:

LastSceneManager.Instance.SetLastScene(0) //for example
#

let me know if something doesnt work i dont have unity to test if it works lol

#

you can also just directly do

LastSceneManager.Instance.lastScene = 0;
``` btw
hexed terrace
celest spoke
#

So how am i colliding with my NPC:s, enemies and colisionobjects?

hexed terrace
#
Vector3 newPosition = transform.position + new Vector3(direction.x, direction.y, 0) * speed * Time.deltaTime;

        // Check if the new position is walkable
        if (IsWalkable(newPosition))
        {
            // Move the object to the new position
            transform.position = newPosition;```

this is just teleporting the player to it's next position each time
hard hornet
# hard hornet ```cs using UnityEngine; using UnityEngine.SceneManagement; public class LastSc...

i forgot to also add, change it to this so it stays between scenes:

using UnityEngine;
using UnityEngine.SceneManagement;

public class LastSceneManager : MonoBehaviour 
{
  public static LastSceneManager Instance { get; private set; }
  public int lastScene;

  public void Awake() {
    Instance = this;
    DontDestroyOnLoad(this);
  }

  public void SetLastScene(int sceneId) {
    lastScene = sceneId;
  }
}

then add it to a random object in the first scene

hexed terrace
arctic ibex
arctic ibex
celest spoke
hard hornet
#

this script in this object

arctic ibex
hexed terrace
hard hornet
#

it works the same as ```cs
GetComponent<LastSceneManager>()

celest spoke
hard hornet
arctic ibex
hard hornet
#

but of course there can be only one object with this script then, since more will just overwrite each other

arctic ibex
hexed terrace
# celest spoke do you mind helping mea finding a fix? i really aperitiate all the help you are ...

You either need to change to using forces to move, so you're actually using your RB.. or.. you could just use existing code to make your own trigger.

It'll be easier to do your own thing.
I'm not going to hold your hand through it.. look at your Interact() and IsWalkable() methods, look at how they detect things.. use that as the base for your level change. Doing this means you can remove rigidbodies from the player etc

arctic ibex
hard hornet
#

but basically private set means it can be only set by this script, even though its public

arctic ibex
#

haha, I'm so used to Visual studio code automatically doing the other half o f the brackets i totally forgot to do them

hard hornet
#

you can totally remove it

rich adder
#

You still need a safeguard or when 2 instances exists

arctic ibex
#

so i just add LastSceneManager.Instance.SetLastScene(0) to my trigger before it switchs scenes?

celest spoke
slender cargo
#

Whats the best way of going back and re-getting a random array element?

rich adder
hard hornet
#

you can add that to the script

arctic ibex
rich adder
#

safeguarding

arctic ibex
#

agaisnt what?

hard hornet
#

if there's more than 1 object with this script it'll destroy the rest

#

and keep only one

hexed terrace
rich adder
#

if you somehow happen to have a copy in another scene

arctic ibex
#

oh okay

rich adder
#

you dont want to ovewrite it

slender cargo
rich adder
#

idk what ur asking tbh

hard hornet
#

you can just copy and paste it of course but that looks ugly

rich adder
#

yes DRY code

hard hornet
#
private GameObject GetRandomModule() {
  return CityModules[Random.Range(0, CityModules.length)];
}
#

you could add this

#

if citymodules is in the scope of the class

slender cargo
#

I'm trying to make it so it will re-roll it if it was the same city module as the module before

#

if that makes sense

scarlet skiff
#

isnt this correct? i still get a NullReferenceException: Object reference not set to an instance of an object Fireball.Update() error

rich adder
#

give it a max iterations too as a guard clause

scarlet skiff
rich adder
#

love it...posts screenshot of editor 🙄 but clips the line numbers

#

genius

swift crag
#

do you have line numbers disabled?

slender cargo
arctic ibex
scarlet skiff
swift crag
hard hornet
swift crag
#

The exception is on line 17 of Fireball.cs

rich adder
swift crag
#

You've shown us FireballSpawner.cs

arctic ibex
scarlet skiff
scarlet skiff
rich adder
#

you just sent the wrong script

#

capish?

swift crag
#

Assets/Scripts/Fireball.cs:17

scarlet skiff
swift crag
#

Fireball.cs, line 17

rich adder
#

there we go

swift crag
#

Turn on line numbers in your editor.

rich adder
#

now why are ur efin lines disabled

swift crag
#

They will make your life significantly easier.

scarlet skiff
rich adder
swift crag
#

The default configuration for visual studio has line numbers enabled.

#

oops, this is...a random language

#

serbian!

#

well, the actual article isn't translated

hard hornet
#

also next time you can double click on the error

scarlet skiff
hard hornet
#

and it'll direct you to the exact line and script

#

if you didnt know that

rich adder
scarlet skiff
rich adder
#

so playerMovement is null

scarlet skiff
#

but ye i got it on now

scarlet skiff
swift crag
#

because playerMovement is null...

rich adder
swift crag
#

A prefab cannot reference a scene object.

#

So there is absolutely no way for the fireball to have a reference to playerMovement as-is

hard hornet
#

you'd have to set it through the fireballspawner script

swift crag
#

bingo

rich adder
#

yes you need DI

swift crag
#

I wouldn't even called this "dependency injection"

#

i mean

#

i guess it is

rich adder
#

in unity it is

#

thats the best we got 😢

swift crag
#

but when I hear "DI" I think of 34-layer casseroles of wildly overcomplicated containers and frameworks

rich adder
swift crag
#

the fireball spawner is in the scene, so it can reference a PlayerMovement in the scene

#

then it can assign the playerMovement field on the fireballs it instantiates

rich adder
swift crag
#

⚠️ extreme DI in progress ⚠️

hard hornet
swift crag
#

bri*ish

#

MonoBehaviour moment

rich adder
#

are they or I think aussie, same tomatoes xD

scarlet skiff
#

ok ok so the problem is when i assign this in the inspector, as a perfab it doesnt save it

#

the Player Movement

slender cargo
#

Will this work? So it will keep calling newModule() until the previousObj isn't equal to next module?

rich adder
swift crag
rich adder
late bobcat
#

Hey guys i made a 2d soccer game and i wanted to test it out with my friends online, do you have some sort of tutorial to do that?

#

like setting up multiplayer etc

late bobcat
#

i tried tarodev one but i couldn't accomplish much

hard hornet
#

especially if youre starting out

rich adder
late bobcat
#

ye exactly what i tought

rich adder
#

multiplayer isnt trivial

slender cargo
rich adder
#

why not just return and obj

slender cargo
rich adder
#

instead of void

late bobcat
slender cargo
late bobcat
#

so any idea on how to do that? like should i make it from 0 while adding multiplayer at the same time or

rich adder
slender cargo
#

oh right

#

that makes sense

thorn holly
hard hornet
rich adder
late bobcat
hard hornet
#

soo i'd start with a new simple multiplayer game made from a tutorial

late bobcat
#

just had some knowledge in c

hard hornet
#

i recommend mirror or fishnet, i dont recommend photon

rare basin
#

dont make a multiplayer game

#

when you are just starting with unity

#

why would you shoot yourself in a foot

late bobcat
#

ahahah

rich adder
#

3 days in unity you should not be doing multiplayer at all

late bobcat
#

i didn't think it was that hard

rich adder
#

no one does

late bobcat
#

my bad then 😛

rich adder
#

they think its like roblox or something

late bobcat
#

never played roblox but i get what you mean

rich adder
gaunt ice
#

some knowledge.... have you used socket?

rich adder
slender cargo
late bobcat
#

guys is alteruna a scuffed multiplayer version?

slender cargo
rich adder
late bobcat
#

i'm just asking

rich adder
#

frameworks are made different for diff use cases / needs

#

you have to know your own cases which you gain by experience. Not by jumping head first in a shark tank

arctic ibex
#

@hard hornet It's working perfectly! That you so much!

slender cargo
late bobcat
#

Never said i wanted to buy alteruna (didnt' even know you could tbf). I just saw that tutorial yesterday and it felt like a short, not so-good way, of transforming your game into a multiplayer

rich adder
celest spoke
#

Hey just a general question, when im coding in Microsoft visual studio i dont get any colors for classes, functions etc. But all of the people that are on youtube does. is there some kind of package that i have to download? It makes it really confusing when everything is the same color.

slender cargo
rich adder
rich adder
slender cargo
#

also how many max iterations would you let it do?

celest spoke
gaunt ice
#

!ide

eternal falconBOT
rich adder
slender cargo
rich adder
#

you have not assigned a value and its a local var so needs init

slender cargo
#

but then surely it wouldn't count up?

#

Ohhh wait its a while, not an if

#

yeah that makes sense

scarlet skiff
#

this fixed the problewm

rich adder
scarlet skiff
#

😢

rich adder
#

i dont understand why not just Inject it on spawn like we suggested

scarlet skiff
#

ngl i didnt understand stuff from the link u sent

slender cargo
thorn holly
#

@slender cargo are you trying to make this while loop happen over multiple frames?

celest spoke
#

I have unity addon installed through viual studio but i dont get this like the guy on y outube does

eternal falconBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

rich adder
#

follow guide

#

only installing the Unity plugin isn't enough

rich adder
scarlet skiff
#

hmmmm one moment ill try

gaunt ice
#

actually you dont need to loop to find a random thing

int someInts[100];//some ints here
int choices=100;
each time when you get a random value from someInts
int index=rand()%choices;
int val=someInts[index];//swap the value with back
someInts[index]=someInts[--choices];
someInts[choices]=val;
buoyant knot
#

btw ty on the cellular automaton recommendation, Tina. It helped quite a bit

rich adder
gaunt ice
#

the basic idea is remove the chosen item from current collection and put it in somewhere (maybe you need to reset it)

#

i just put it in place

buoyant knot
#

if you need a uniformly randomly distributed item from an indexed collection, you can just select a random index

rich adder
#

true

scarlet skiff
#

is this right?

swift crag
#

Bingo!

rich adder
#

thats one way to do it sure

swift crag
#

One improvement, though.

#

public GameObject fireballPrefab;

scarlet skiff
#

can i shorten down to this

swift crag
#

you could just make this a public Fireball fireballPrefab;

hard hornet
rich adder
swift crag
#

now you don't have to do GetComponent<Fireball>() -- Instantiate will just return a Fireball

hard hornet
#

evenb etter

rich adder
#

default for value type is already 0,0,0

#

in this case

scarlet skiff
#

oh for that i had cuz im likely going to change the spawn point, just have to 0 for now

rich adder
#

oh wait it local var.. nvm

swift crag
#

I would prefer to use Vector3.zero anyway

supple jungle
#

how to make missing (game object) in arrays null? i tried by comparing tag in every index

                {
                 
                    rockAmount[i] = null;
                }```
but it stays at missing and i cant replace it with another gameobject
rich adder
scarlet skiff
#

is the middle of the scene 0, 0 ,0?

rich adder
scarlet skiff
#

hmmm
its now spawning the fire balls at the origin and not at the spawner itself

rich adder
#

world pos

scarlet skiff
#

i wanted the local 0, 0 ,0

rich adder
#

if you want the spawner position just pass the spawner position

scarlet skiff
#

oh ye

swift crag
#

I don't see how this would stop you from assigning a new game object into the array. Gonna need some more context here.

rich adder
#

use a list and remove the element 😈

supple jungle
swift crag
#

a destroyed object will equal null

#

i.e. obj == null will return true

scarlet skiff
#

okay so what the fire ball does now is move in a sinus wave, rotating towards the direction its moving to, but also following the player.

right now however its turns after the player in a sharp manner and feels unnatural.

My solution to this would be to not update the players position every frame, but instead every 10 frames maybe.

Timers and such is also something that confuse me and to time stuff i use DateTime

so the way id solve this rn would be to have an if statement that checks if the DateTime timer is equal to or less than the current date (if its now or already happened), and if it has, it updates the players position but also sets the DateTime timer to current date + 0.5seconds, would this approach work?

swift crag
#

Time.time is the time since game start in seconds

#

you can use that basically identical to how you're currently using DateTime

scarlet skiff
swift crag
#

you generally care about in-game time, not about real world time

#

for example, if you pause the game, cooldowns shouldn't be progressing

rocky canyon
#

unless u want to shame the player for not playing for X: amount of time 😄

arctic ibex
#

Okay so I have this piece of code on my player to stop them from colliding with the fence tile map, and it's still colliding, do I need this code on the tilemap too? or have I written it wrong?

Physics2D.IgnoreCollision(fence.GetComponent<Collider2D>(), GetComponent<Collider2D>());
#

It's in void start by the way

#

wait nevermind I forgot to actulaly asign the tag

#

lol

scarlet skiff
#

i see

#

but otherwise the structure would work, ye?

#

dang cant use add seconds tho

#

or ill just do + the number

#

like + 0.5

green island
#

im using public MonoScript attack; for getting an interface into an Scriptible object but when i trie building the game i get this error

error CS0246: The type or namespace name 'MonoScript' could not be found (are you missing a using directive or an assembly reference?)```
scarlet skiff
#

something like this i suppose

rich adder
#

are you not getting underlines in your IDE btw

swift crag
#

Time.time is a float.

#

So, yes, you just add a number to it.

#

There's no need to add all those (float) casts.

verbal dome
#

It won't work in a build

green island
swift crag
#

What are you trying to accomplish?

#

this is an obvious XY problem

verbal dome
green island
#

to link an interface into an scriptible object through the editor

verbal dome
#

What would you do with that interface

swift crag
#

a MonoScript is the actual script asset. it has nothing to do with the classes defined in that script

#

I don't understand what "linking an interface" would entail

#

Are you trying to serialize a field of an interface type?

ivory bobcat
swift crag
#

You can't do that by default. Unity will only serialize types deriving from UnityEngine.Object

#

(along with some other types like float/int/etc., List<T> where T is serializable, and a few others)

green island
# verbal dome What would you do with that interface

every character has a diffrent attack so i need to add an interface to the player if this character is used

public class TestAttack : MonoBehaviour, IAttack
{
    public void LeftClick()
    {
        Debug.Log("Left");
    }

    public void RightClick()
    {
        Debug.Log("Right");
    }

    
}``` this is the interface im testing with
iron wind
#

You need to put ScriptableObject/MonoBehaviour as the type though

ivory bobcat
green island
#

this is IAttack:

public interface IAttack
{
    void RightClick();

    void LeftClick(); 
}```
verbal dome
#

So are you trying to store the type of the interface in the ScriptableObject?

green island
green island
ivory bobcat
#

The component would only be a prefab though.. maybe the referenced object should also be an SO?

#

Or a regular class

swift crag
#

You have a few options here.

#

You can make an abstract Attacker class that derives from MonoBehaviour

#

The player could then derive from Attacker

#

This starts causing problems when you want to have lots of different interfaces, though

green island
#

i have just one interface

swift crag
#

You can also split the "attacker" logic out from the player component and into a separate component.

verbal dome
swift crag
#

So you'd have a Player component that has no idea about attacking itself

#

and then a separate component that, again, derives from an abstract class with the attack methods on it

#

This is what I've done in my game: lots of small modules

#

It's a composition-based approach.

rocky canyon
#

can i somehow inspect this list as i could with a list of gameobjects

  void AddOrRemoveSelectable(ISelect selectable)
    {
        //if its in the list remove it
        if(selected.Contains(selectable))
        {
            Debug.Log("Removed Selectable");
            RemoveSelectable(selectable);
        }
        else
        {
            Debug.Log("Added Selectable");
            AddSelectable(selectable);
        }
    }``` im adding and removing, and debugging was a PITA

i remember something about serializeable , or maybe odin's free attribute asset thing, its on teh tip of my tongue and i cant think of it
swift crag
#

There are several assets that let you serialize interface-typed fields.

#

notably, Odin Inspector can do that with one of its features, iirc

rocky canyon
#

is the odin one the way to go?

#

i would assume yea

swift crag
#

I've never used Odin, though.

rocky canyon
#

they have that free version that does this?

#

i think so

ivory bobcat
rocky canyon
#

yea, even when its public its not visible.

#

i just made it private b/c of that

#

and i was getting editor draw errors

green island
#

yeah i have one attack script that does some checks if it passes it gets the component from the player that comes from IAttack and calls the func now i need to add the interface on the start dependeing on the scriptible objects on the player

ivory bobcat
rocky canyon
#

first time ive used a list with something other than gameobject

swift crag
rocky canyon
#

ive been spoiled by seeing the dropdown in teh inspector 😅

swift crag
#

public abstract class Attack : MonoBehaviour

#

Since this derives from MonoBehaviour, Unity can serialize it.

ivory bobcat
#

Maybe reference a base class that's inherited and implements the Interface. You'd be able to show it's members.

swift crag
#

It's a very annoying hangup. I wish there were some way to promise that I'm always going to be referencing a unity object.

ivory bobcat
#

Assuming there's a common base class

rocky canyon
#

theres not one yet, but i could make that alteration if need be

#

basic as beans

ivory bobcat
#

Yeah, so reference a list of type friendly selectable

#

It would then be available from the inspector

green island
rocky canyon
#

👍 i also have an NPC version

swift crag
rocky canyon
#

i may use two lists.. with those specific types

ivory bobcat
#

Maybe have a base class called Selectable

swift crag
#

assets can't reference scene objects

ivory bobcat
#

Where all types of selectable would inherit - it would dictate what's shown in the inspector

swift crag
#

it would also not be useful to reference the Attack component on the player prefab

#

since that would always be the player prefab's Attack component

#

It sounds like the Player component should be able to tell you about its Attack component

verbal dome
#

@rocky canyon There's always the ugly hack of serializing it as Component and then casting it to your interface type when used

swift crag
#

or maybe even components, if you have several attacks

swift crag
#

sometimes I click on a field of that type and I get hit by a massive wall of choices lol

#

every single asset in the entire project

rocky canyon
#

i may do something temporary until i get the selection and deselection working.. currently its working but i gotta guess whats in the list (as i suspect)

#

list of a base class like u mention

green island
swift crag
ivory bobcat
verbal dome
#

I hope interfaces become more inspector-friendly in the future. SerializeReference is dope but I want more

iron wind
#

You "can" serialize an interface by serializing the MonoBehaviour directly. The downside is you have to cast the value (so you should probably cache it) in runtime.

interface IMyInterface {
    void DoAction();
}

class MyImplementer : MonoBehaviour, IMyInterface { } //code etc..

class SomeReferenceThing : ScriptableObject  {
    public MonoBehaviour TheScript;
    public IMyInterface Value => (IMyInterface)TheScript;

    void OnValidate() 
    {
        if (TheScript != null && TheScript is not IMyInterface)
        {
            Debug.LogError($"{script.GetType()} does not implement {nameof(IMyInterface)}!")
            TheScript = null;
        }
    }

    void Update()
    {
        Value.DoAction();
    }
}```
swift crag
#

Your scriptable object is an asset. It can't reference scene objects.

#

I don't understand your design.

#

I almost always have references to scriptable objects

#

scriptable objects don't have references to me

rocky canyon
#

For plain C# classes you could also think about using a reflection-based approach by storing a string representation of the class and interface and then using the Activator class from the .NET framework to create instances when you need them.

iron wind
#

Another downside to the method I linked is that the inspector will not filter your interface properly

verbal dome
rich adder
#

reflection is slow af ye

swift crag
green island
ivory bobcat
verbal dome
#

I just said

added to the character
So I'm confused

iron wind
iron wind
#

class BaseClass1 : IMyInterface
class BaseClass2 : IMyInterface

Can't reference either which is why you want interface in the first place

ivory bobcat
green island
# verbal dome You need what to add what to the player

each chracter has a scriptibleobject and you can choose one on the start in the so all stats for the character are saved and i need to add a script to handel the attacks but the gamobject stays the same for each character and movement just the attacks and model change

iron wind
#

Yeah in this case it's a bit of a weird case as you typically want to ref an SO instead 😅

green island
iron wind
green island
verbal dome
polar acorn
stark girder
#

what is empty Vector3int is it equal to null?

verbal dome
#

Most of people use SO's as just data containers but they can also be instantiated and can have logic in them

polar acorn
#

it's not any different

swift crag
rich adder
#

default vector3int.zero

polar acorn
swift crag
#

scriptable objects are assets. the game can't modify them on disk.

green island
#

these are the default stats how can i add code here

swift crag
#

Changes will stick around in the editor for a bit

#

but that's not how it's going to work in the built game at all

stark girder
verbal dome
swift crag
#

you don't shove the code into the inspector. you just..write it. in the class.

green island
polar acorn
ivory bobcat
polar acorn
#

the one that you made that defines this asset

#

not the asset itself

verbal dome
errant spear
#

Hi, i have a problem when launching my C# code through Unity as it write : "No installed .NET SDK was found on the computer. If it is installed, make sure it can be found through the PATH environment variable. C# Dev Kit does not work without a supported version of SDK. After installing the SDK, you need restart the VS Code session, or the computer."
But i open it only with VSCode i don't have that

iron wind
errant spear
#

Someone have a solution ? (i'm on linux, I've installed Mono, .net, having this in my bashsrc : export PATH=$PATH:$HOME/dotnet)

green island
remote sequoia
iron wind
errant spear
remote sequoia
ivory bobcat
rich adder
#

what distro are you using ? @errant spear
I have a video showing the whole config process on Linux Mint

errant spear
#

this one

errant spear
#

you mean Ubuntu ?

rich adder
#

Distribution of linux

rich adder
errant spear
remote sequoia
#

Press the Windows key and then look for System Settings.
Click System Settings, System tab.
Click Advanced system settings.
Click Environment Variables.
System variables can be set, find the PATH variable.
In the Variable Value field, add the directory path where the .NET SDK is installed. For example, if the .NET SDK is installed in C:\Program Files\dotnet\sdk\5.0.101, add the following to the Variable Value field:
C:\Program Files\dotnet\sdk\5.0.101
Click OK.
Close the system settings window. Then restart your pc

rich adder
#

using Linux Mint

#

which is a Ubuntu distro

swift crag
errant spear
rich adder
#

sorry for AI voice, i had no mic that week xD

remote sequoia
stark girder
#

if default value is 0,0,0
that why does this not even run
shouldnt the i be 0,0,0?

swift crag
#

what if activeFires is empty?

rich adder
swift crag
#

the default value isn't in an empty list. nothing is in an empty list.

verbal dome
swift crag
#
Vector3Int myVec;

myVec can never be "empty". there's exactly one Vector3Int here, and it's stored in myVec. If you don't assign anything else to it, then myVec will store the default value.

#
List<Vector3Int> vectors = new();

vectors can contain zero, one, or many Vector3Int values.

remote sequoia
#

I prepared such a spawn method, but I have a problem. For example, in the 3rd wave, there are only 3 a prefabs or 3 b prefabs. What should I do to make this happen randomly too? For example, in the 3rd wave, 2 prefabs A and 1 prefab B will be spawned randomly.

swift crag
#

just pick randomEnemy inside the loop

stark girder
swift crag
#

why do you think activeFires isn't empty?

remote sequoia
#

let me show

swift crag
stark girder
swift crag
#

it picks randomEnemy once and then spawns that enemy many times

swift crag
swift crag
stark girder
remote sequoia
#

Like this. İn the one wave, all enemys are same

remote sequoia
swift crag
swift crag
#

do exactly what I said

errant spear
swift crag
#

ctrl-shift-P to open the command palette, then search for "JSON"

Open both of these and look at the config files.

errant spear
remote sequoia
swift crag
swift crag
#

anything to do with "dotnet path"

remote sequoia
rich adder
#

and did you install it via the command line like the video ?

errant spear
errant spear
swift crag
# remote sequoia im not native speaker sorry
int number = UnityEngine.Random.Range(0, 10);

for (int i = 0; i < 10; ++i)
{
    Debug.Log(number);
}

vs.

for (int i = 0; i < 10; ++i)
{
    int number = UnityEngine.Random.Range(0, 10);
    Debug.Log(number);
}
swift crag
errant spear
swift crag
#

Now examine the user settings. There's probably more stuff in there.

swift crag
#

I'd definitely do a restart before digging around any further, though!

#

do the easy step first

errant spear
#

restarted but no

#

here's user json

rich adder
errant spear
rich adder
#

this is french 🤷‍♂️

errant spear
#

wait i'll trad it

rich adder
#

don't need the whole log you can just tell me

errant spear
#

$ sudo apt-get update && sudo apt-get install -y dotnet-sdk-7.0
[sudo] Student password:
Reached: 1 http://fr.archive.ubuntu.com/ubuntu jammy InRelease
Reached: 2 http://fr.archive.ubuntu.com/ubuntu jammy-updates InRelease
Reached: 3 https://download.mono-project.com/repo/ubuntu stable-focal InRelease
Reached: 4 http://security.ubuntu.com/ubuntu jammy-security InRelease
Reached: 5 http://fr.archive.ubuntu.com/ubuntu jammy-backports InRelease
Reached: 6 http://packages.microsoft.com/repos/code stable InRelease
Received from: 7 https://deb.nodesource.com/node_16.x jammy InRelease [4583 B]
Reached:9 https://packages.microsoft.com/ubuntu/20.04/prod focal InRelease
Reached: 8 https://hub-dist.unity3d.com/artifactory/hub-debian-prod-local stable InRelease
Reached: 10 https://download.sublimetext.com apt/stable/ InRelease
Reached: 11 https://paulcarroty.gitlab.io/vscodium-deb-rpm-repo/debs vscodium InRelease
4583 o received in 3s (1463 o/s)
Reading package lists... Done
N: The configured file “main/binary-i386/Packages” will not be considered because the repository “https://download.mono-project.com/repo/ubuntu stable-focal InRelease” does not support l “i386” architecture
W: https://download.sublimetext.com/apt/stable/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: https://paulcarroty.gitlab.io/vscodium-deb-rpm-repo/debs/dists/vscodium/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
Reading package lists... Done
Building the dependency tree... Done
Reading status information... Done
dotnet-sdk-7.0 is already the most recent version (7.0.405-1).
0 updated, 0 newly installed, 0 to remove and 8 not updated.

errant spear
rich adder
#

says you already have sdk

#

type dotnet --list-sdks in terminal

swift crag
#

It sounds like the C# extension is looking in the wrong place.

errant spear
swift crag
#

ah, hm

rich adder
#

weird, not even error if command is working or not..

swift crag
#

or there are zero SDKs!

errant spear
#

That's really strange

errant spear
swift crag
#

Here's a thought

#

which dotnet

#

what does that give you?

errant spear
swift crag
#

I bet that you got dotnet from one repository and the dotnet SDK from another repository.

#

Check this out

#

The fix is going to be to tell apt that you much prefer Microsoft's repository for anything dotnet related

#

(or to just remove the Microsoft package feed entirely)

scarlet skiff
#

i want the sine wave to be less apparent/weaker valleys n tops when coming closer to the player

rich adder
#

nice code comments

shrewd swift
#

i wish i knew where they come from

scarlet skiff
#

and athe closer you are, the smaller the number after division becomes

#

which should make the waves less intense

timber tide
#

time to take out your pen and paper

errant spear
#

like through commands i have

#

but not manually

shell sorrel
#

would create a 0 to 1 number based on distance, and multiply the sin by it

swift crag
errant spear
shell sorrel
#

inverselerp can be used to take a range of distance and get your 0 to 1 multplier from it

errant spear
#

so not everything is clear for me

timber tide
#

could really just use an animation curve and multiply by that

#

and have more freedom on the editor vs hard coding values

swift crag
#

for example...

#
float distanceFactor = Mathf.InverseLerp(5f, 20f, distance);
#

You could then plug this into an animation curve

#
float strength = curve.Evaluate(distanceFactor);
timber tide
#

also speaking of animation curves is there a way to steal the animation curve from line renderer

#

that one is like extra polished

#

Rather, I want it because it clamps 0 to 1

quick ruin
#

If the bool manaOn == false it still runs and changes the material color. is this just bugged?

quick ruin
#

set it to public and viewed in inspector

ivory bobcat
#

Well, it's definitely true if the code is occurring.

swift crag
#

what is manaBlue? a reference to a material you assigned in the inspector?

quick ruin
#

yes

swift crag
#

perhaps you have multiple objects using the material?

#

and multiple copies of this component in various places?

ivory bobcat
#

Maybe log thiscs Debug.Log($"Mana On: {manaOn}", this);

shell sorrel
#

how is your reference to manaBlue created?

ivory bobcat
#

Assuming this isn't spamming the console, click the message when it's supposed to be false but not.

void dawn
#

heelo

quick ruin
#

its returning false and still running it for the false ones

#

im so lost lol

void dawn
#

i was following a tutorial

swift crag
void dawn
#

as i was trying to make a fps

ivory bobcat
void dawn
#

but something broke my game

polar acorn
void dawn
#

i will send my project , can you guys help me with this one

#

fuck i cant send my project

#

what do i do

shell sorrel
#

no one is going to review a whole project for you, break down the problem smaller and figure out what part is broken

modest dust
#

describe what the issue is

ivory bobcat
swift crag
#

when you modify them, the changes will persist

void dawn
#

i cant add the start scripts to the main menu part , this is vital since it would make the whole thing work

shell sorrel
void dawn
#

also i think something is wron with the camera

swift crag
void dawn
#

because its centered in the characters face

shell sorrel
#

that way your modificitons will not effect multiple objects at once and they will not dirty the state of the mateirals in your assets folder

ivory bobcat
void dawn
ivory bobcat
void dawn
#

4:26

ivory bobcat
#

Can you show your hierarchy and that you've selected the three buttons?

rocky canyon
#

NaughtyAttributes + Text Area

#

i casted them as Monobehaviours, then debug the names

#

then i realized i hadn't imported naughtyattributes, and i love that asset, so i made it work w/ that instead with the little mini-debug-string-window

#

lol

timber tide
#

I've tried some packages but I've just surrendered to not using interfaces this way

#

unity really needs editor support updates

rocky canyon
#

ya, troublesome to say the least. there was a bug yesterday and i couldn't tell what was happening, so i wrote alot of debugs just to visualize what was happening

#

once i get the bugs worked out, i can get rid of this completely..

#

but swapping to interfaces really cleaned up my code, so im fine with them 🙂

#

went from something long and nasty like this

#

to a much more legible

#
                if(!selected.Contains(selectable))
                {
                    AddSelectable(selectable);
                }
                else
                {
                    RemoveSelectable(selectable);
                }

                // first we need to know if this is already selected, if it is do the following

                // we need to check if we start dragging

                // if after so long our focused raycast position hasnt changed we can assume we want to open the units menu

                // we also need to check if we're holding down

                // if was a single quick click then we just need to deselect

                // if it wasn't selected we can just assume we want to select it

            }
            else
            {
                // we clicked something that wasn't selectable

                // are we selected?

                // if we are what happens?

                // if we're not what happens?
            }``` still got a crazy interaction system to setup 😅
dusty coral
#

how to filter gameobjects in the scene based on components?

rich adder
dusty coral
#

ye

languid spire
#

search using t:

rich adder
#

or you mean code?
FindObjectsOfType

#

its kinda slow so you should prob not use it in something like Update

#

use awake/start to store them

dusty coral
#

no i mean like from the hierarchy

rich adder
#

oh then what SteveSmith said

dusty coral
#

cause theres a random collider i cant click on

#

i dont know where its from]

rich adder
#

t:Collider

dusty coral
#

nice

unborn gale
#

hi

#

I had a question I was desprate to get an answer for

rich adder
#

if you were desperate why haven't you posted it yet ?

unborn gale
rich adder
#

this is a code channel

rocky canyon
#

lol

unborn gale
#

am pretty sure it has code involved

frosty hound
#

It's not, don't crosspost.

rich adder
#

oh wait 2d lights doesnt have that

frosty hound
#

And if you think it's code related, then remove it from there and ask here with the code you're using for it.

unborn gale
#

ama just ignore you

frosty hound
#

You will be warned if you crosspost, your question is and belongs in #archived-lighting. Stop being a child.

quick ruin
#

is GetChild and Find("") the same performance?

rocky canyon
#

doubtful.. GetChild is going to be constrained to just the parent and all its children

#

Find() is gonna search the entire Hierarchy

river roost
#

Find is slower, as it has to compare strings

#

but I don't think it's going to be noticable unless you're doing it a lot

ivory bobcat
#

Assuming you aren't referring to GameObject Find which searches the entire hierarchy.

meager sentinel
#

Idk why but i get this error on VSC sometimes, but other times (like rn) the IDE does work, what is happening?

rocky canyon
#

its faster to search thru a specific Parent

#

but i figured as much.. (very very little difference)

faint osprey
#
{
    public CinemachineVirtualCamera VC;
    public GameObject player;
    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(Delay());
    }

    // Update is called once per frame
    void Update()
    {

    }

    private IEnumerator Delay()
    {
        yield return new WaitForSeconds(3.9f);
        Vector3 deltaPos = player.transform.position - VC.transform.position;
        float timePassed = 0;
        while (timePassed < 1f)
        {
            timePassed += Time.deltaTime;
            VC.transform.position += deltaPos * Time.deltaTime;
        }
        VC.transform.position = player.transform.position;
        VC.Follow = player.transform;
    }``` why is my VC not moving towards my player
ivory bobcat
rocky canyon
#

lol, not sure, i did use about 20- 30 children.. w/ alot nested

#

but 100s or 1000s idk 😄

ivory bobcat
#

If Unity uses a dictionary under the hood, it should be pretty quick with the hashing else if they're comparing names for a list... the number of elements might matter a lot.

polar acorn
rocky canyon
faint osprey
rocky canyon
#

with the highlighted one holding the Test script i was hunting for

faint osprey
rocky canyon
#

ahh, i used GetComponentInChildren not Find.

polar acorn
faint osprey
ivory bobcat
polar acorn
rocky canyon
#

i just dont ever wanna seach with strings anymore 😄

#

i try to avoid it lol i've even stopped using CompareTag()..

#

much prefer a TryGet and a component now

faint osprey
faint osprey
polar acorn
rocky canyon
#

isnt the timeline like a glorified animator? couldn't u track the player thru a script, and maybe control that script via the timeline?

polar acorn
#

Seems like the issue is likely that the Timeline is overwriting the object's position, so this coroutine changes it, but the Timeline immediately changes it back

faint osprey
#

well i deleted the timeline and its still not moving

#

its just skipping to the position instantly

polar acorn
faint osprey
#

i have everything runs as it should

polar acorn
rocky canyon
#

Phantom code

faint osprey
#

could it just be happening so quickly that it looks instant

polar acorn
#

Try logging the camera's position before the while, during the while, and after the while

#

Make sure to actually include which one is which

#

See if the position actually changes

faint osprey
#

it does

#

its just jumping from the start location to the end

#

not gradually changing over 1 second

#

like it shod

polar acorn
#

Your only wait is at the beginning

#

It does the rest instantly

faint osprey
#

but its in a while loop

#

so shod update every time the while loops

polar acorn
#

Yes, that's why it runs instantly

polar acorn
faint osprey
#

what it does all loops in one frame

polar acorn
#

Yes that's how all loops work

#

The only code that exists is that loop until it's finished

#

If you want to run one iteration and then wait a frame you should actually wait a frame

#

yield return null

faint osprey
polar acorn
#

after you do whatever you want the loop to do

swift crag
#

(at the very end of the loop body, yes)

#

certainly not after the loop body

ivory bobcat
#

You probably forgot to yield in the loop

faint osprey
#

that works cheers guys

#
    {
        yield return new WaitForSeconds(4f);
        Vector3 deltaPos = player.transform.position - VC.transform.position;
        float timePassed = 0;
        while (timePassed < 1f)
        {
            timePassed += Time.deltaTime;
            VC.transform.position += deltaPos * Time.deltaTime;
            VC.transform.position = new Vector3(VC.transform.position.x, VC.transform.position.y, -35);
            VC.m_Lens.OrthographicSize = -45 * Time.deltaTime;
            yield return null;
        }``` im trying to change the orthographic size as well now but thats not changing for some reason
polar acorn
#

Why are you trying to set the orthographic size to a constant times deltaTime anyway

ivory bobcat
#

You aren't decrementing it. You're setting it to negative forty five multiplied by whatever value delta time was that frame.

faint osprey
#

i want it to go from 50 to 5

#

and deltapos works in a similar way so i thought that would

polar acorn
ivory bobcat
#

... = 50 - 45 * an accumulating variable relative to time

swift crag
#

perhaps you were looking for the += operator

faint osprey
#

oh it was meant to be =- 45

polar acorn
faint osprey
#

i put a space on accident

polar acorn
#

= - and =- are not different

faint osprey
polar acorn
quick ruin
#

can you invoke while passing a var?

slender nymph
#

No

swift crag
#

Invoke must be given the name of a method to call.

It looks like you just want to call the method directly...

wintry quarry
faint osprey
#

its still not changing tho

swift crag
#

well, show us the code you wrote

faint osprey
#
    {
        yield return new WaitForSeconds(4f);
        Vector3 deltaPos = player.transform.position - VC.transform.position;
        float timePassed = 0;
        while (timePassed < 1f)
        {
            timePassed += Time.deltaTime;
            VC.transform.position += deltaPos * Time.deltaTime;
            VC.transform.position = new Vector3(VC.transform.position.x, VC.transform.position.y, -35);
            VC.m_Lens.OrthographicSize -= 45 * Time.deltaTime;
            yield return null;
        }```
swift crag
#

what isn't changing?

faint osprey
#

VC.m_Lens.OrthographicSize

swift crag
#

look in the inspector as the code runs. i see no reason for it to not go down over time

swift crag
#

is the code even running?

faint osprey
#

yes it is

#

cause evrything else is working

swift crag
#

and if so, does logging VC.m_Lens.OrthographicSize show the value is changing?

swift crag
#

i don't know how to interpret that. is it going down from 50 to 5, or is it just constnatly resetting to 50 and then getting reduced?

wintry quarry
#

You have to do this:

LensSettings lensSettings = VC.m_Lens;
lensSettings.OrthographicSize = -45 * Time.deltaTime;
VC.m_Lens = lensSettings;```
swift crag
#

shouldn't that be a compile error?

wintry quarry
#

One would expect so...

swift crag
#

assuming that m_Lens is a property

#

but it isn't. it's a field

#

I see no problem with doing that.

wintry quarry
#

Oh I see

#

You're right

swift crag
#

is the camera actually in orthographic mode?

ivory bobcat
ivory bobcat
#

So it's working UnityChanHuh

wintry quarry
faint osprey
wintry quarry
#

If it's a perspective camera you need FieldOfView not OrthographicSize

faint osprey
#

i thought u were asking what u want it to do

wintry quarry
ivory bobcat
# faint osprey no

It looks like the code works in decreasing the value. The behavior just isn't what you're needing.

swift crag
#

expand "Advanced"

faint osprey
swift crag
#

By default, the virtual camera will use whatever mode the main camera is using

#

Okay, so it's set to force the main camera to be orthographic

#

does changing the ortho size actually do anything?

#

as in, just changing it by hand

faint osprey
#

yeah zooms in and out thats why i set it to 50 cause it was 5 but i want it to zoom in

swift crag
#

I feel like you've got a second virtual camera that's following this virtual camera.

topaz pendant
#

OrthographicSize doesn't seem to be a parameter you can manually change

swift crag
#

that would neatly explain all of the behavior we've seen

swift crag
topaz pendant
#

Oh okay

swift crag
#

It's the height that the screen takes up in the game world

swift crag
# faint osprey nope

well, it seems like changing the orthographic scale of the camera is doing nothing, so something is wrong.

#

I would verify that you're actually moving the camera you think you are:

Debug.Log("Moving", VC);
faint osprey
swift crag
#

click on the log entry and make sure it selects the correct thing

swift crag
#

but if you let this coroutine change the orthographic size, the orthographic scale still drops from 50 to 5, but the camera barely zooms?

topaz pendant
#

Do you have any errors ?

swift crag
faint osprey
#
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;

public class SpawnCutsceneScriptCompanion : MonoBehaviour
{
    public CinemachineVirtualCamera VC;
    public GameObject player;
    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(Delay());
    }

    // Update is called once per frame
    void Update()
    {

    }

    private IEnumerator Delay()
    {
        yield return new WaitForSeconds(4f);
        Vector3 deltaPos = player.transform.position - VC.transform.position;
        float timePassed = 0;
        var lensSettings = VC.m_Lens;
        while (timePassed < 1f)
        {
            timePassed += Time.deltaTime;
            VC.transform.position += deltaPos * Time.deltaTime;
            VC.transform.position = new Vector3(VC.transform.position.x, VC.transform.position.y, -35);
            lensSettings.OrthographicSize -= 45 * Time.deltaTime;
            yield return null;
        }
        VC.transform.position = player.transform.position;
        VC.Follow = player.transform;
    }
}
faint osprey
swift crag
faint osprey
#

ive just done that now

#

didnt work

ivory bobcat
topaz pendant
#

but m_Lens is a struct

swift crag
#

It's a field.

#

I have to wonder if another camera is being blended to.

topaz pendant
#

when you do var lensSettings = VC.m_Lens;, you copy the content of m_Lens in a local variable

ivory bobcat
#

These settings will be transferred to the Unity camera when vcam is live
I'm assuming once or would it do so constantly with a poll?

swift crag
faint osprey
#

but its not working

swift crag
topaz pendant
#

Okay bcause you didn't write it in the above code

swift crag
ivory bobcat
swift crag
#

Screenshot its inspector after the coroutine is done.

faint osprey
swift crag
#

So it doesn't go down to 5. It goes down to 49.647 and sits there.

faint osprey
#

no i said thats what i want it to do

swift crag
#

Show me exactly what your code looks like right now.

ivory bobcat
#

So it didn't go down.

faint osprey
faint osprey
# swift crag Show me exactly what your code looks like right now.
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;

public class SpawnCutsceneScriptCompanion : MonoBehaviour
{
    public CinemachineVirtualCamera VC;
    public GameObject player;
    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(Delay());
    }

    // Update is called once per frame
    void Update()
    {

    }

    private IEnumerator Delay()
    {
        yield return new WaitForSeconds(4f);
        Vector3 deltaPos = player.transform.position - VC.transform.position;
        float timePassed = 0;
        var lensSettings = VC.m_Lens;
        while (timePassed < 1f)
        {
            timePassed += Time.deltaTime;
            VC.transform.position += deltaPos * Time.deltaTime;
            VC.transform.position = new Vector3(VC.transform.position.x, VC.transform.position.y, -35);
            lensSettings.OrthographicSize -= 45 * Time.deltaTime;
            VC.m_Lens = lensSettings;
            yield return null;
        }
        VC.transform.position = player.transform.position;
        VC.Follow = player.transform;
    }
}
swift crag
#

it's not in the code you just sent