#💻┃code-beginner

1 messages · Page 717 of 1

remote sparrow
#

no i figued it out, so i have a thing in my code that makes my gravity higher when falling but somehow its being applyed when i move left can ik that happening cause it set it to zero and it worked normally

zealous talon
#

i'm kinda losing my mind .....

rich adder
#

it will explain whats happening, is basically wat was mentioned before, you push forward it goes off the slope then gravity pushes down again and repeat

#

so you keep playing ungrounded animation because thats what you set to happen if not grounded

#

so it needs to follow the slope direction instead of going just straight

#

did you debug why it wasn't moving with the added velocity ?

zealous talon
rich adder
remote sparrow
#

i fixed it

rich adder
#

but it wasn't working for some reason ? so something you should look into, I did it similar

zealous talon
zealous talon
#

mh

rich adder
#

Kinematic though

#

You can use dynamic depending on the mode of your game , if you lock constraints

zealous talon
#

so you add on the controller the rb.velocity's platform?

rich adder
#

yes the player moves according to how much platform moved

#

I use a raycast instead of triggers to detect it though, my platform knows nothing about the player

zealous talon
#

ok and you calculate velocity with kinematic rigid body as something light new position - last position / time.deltatime?

zealous talon
zealous talon
#

when the platform detects a trigger with the player it access the externalVelocity in the controller script and set it as its velocity

#

so it should be pretty much the same

rich adder
#

I mean sure but design choice, platforms shouldnt really know anything about the player

patent hazel
#

slopeRotation = Quaternion.FromToRotation(Vector3.up, hitinfo.normal); so what this does is basically turning player movement vector with the angle between vector3.up and hitInfo.normal right?

wintry quarry
#

it doesn't do anything with any players

rich adder
patent hazel
#

if we multiply movement vector with slopeRotation thats what happens right?

patent hazel
patent hazel
wintry quarry
#

I think the more appropriate tool here would be to project the movement vector on the surface plane

wintry quarry
#

the quaternion needs to be on the left

patent hazel
#

slopeRotation * movement

#

yes sorry

wintry quarry
#

I think it would approximately do the same as projecting the movement vector on the slope yes

#

(and then fixing the magnitude)

compact sundial
#

I am using the onEnable function for my UI buttons. can I put multiple lines of

uiDoc.rootVisualElement.Q<Button>("LifeStealButton").clicked += OnClick;

in the enable function and they activate multiple buttons? or do I have to make a script for each button?

#

here is the full script

#
using UnityEngine;
using UnityEngine.UIElements;
public class ButtonOne : MonoBehaviour
{
    [SerializeField] private UIDocument uiDoc;
    [SerializeField] private ExtendedCharacterController characterController;
    [SerializeField] private GameObject player;
    
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Update()
    {

    }

    void OnEnable()
    {
        uiDoc.rootVisualElement.Q<Button>("LifeStealButton").clicked += OnClick;
        //Debug.Log(uiDoc.rootVisualElement.Q<Button>("LifeStealButton"));

    }

    void OnClick()
    {
        //Debug.Log("YEET");
        player.TryGetComponent<LevelUpScript>(out LevelUpScript levelUpScript);
        if (levelUpScript.playerSkillPoints >= 1)
        {
            characterController.quickSlashAttackMultiplier += 1;
            levelUpScript.playerSkillPoints -= 1;

        }


    }
}
rich adder
compact sundial
wintry quarry
#

Such that the listener will run every time the button is clicked

#

there's no limit to how many listeners you can add in a single script

rich adder
#

also good practice clean these up ondisable/destroy clicked -= OnClick;

compact sundial
#

like the OnClick function did not activate

wintry quarry
#

+= is correct, I didn't say it wasn't

compact sundial
#

oh

wintry quarry
compact sundial
#

yeah I had it the name of the script because I thought I was gonna have to make a script for each button

plush zealot
#

For some reason this outputs the last card 5 times instead of outputting the top card then removing it and then outputting the top card again... these are the debug outputs im getting when I run it
https://hastebin.com/share/itiwizihah.csharp

#

I'm genuienly losing my mind here please help T-T

wintry quarry
#

showing the full script would probably help

#

as well as the ElementPage type

#

and any other relevant code

#

or perhaps you're doing some static variable stuff

plush zealot
#

I tried both those possibilities and checked the debugger neither is the case....
It doesn't have duplicates as the initial debug messages show it generates random ones
I thought the second too but it shouldn't be doing that since as also seen in the later debug messages the deck is shrinking....

Gamelogic
elementPage

wintry quarry
#
        List<ElementPage> importD = new List<ElementPage>();
        ElementPage toAdd = new ElementPage("unassigned",1);
        int e;
        for(int i=0; i < 30; i++)
        {
            e = rnd.Next(6);
            switch (e)
            {
                case 0:
                    toAdd.element = "fire";
                    importD.Add(toAdd);
                    break;
                case 1:
                    toAdd.element = "earth";
                    importD.Add(toAdd);
                    break;
                case 2:
                    toAdd.element = "water";
                    importD.Add(toAdd);
                    break;
                case 3:
                    toAdd.element = "wind";
                    importD.Add(toAdd);
                    break;
                case 4:
                    toAdd.element = "lightning";
                    importD.Add(toAdd);
                    break;
                case 5:
                    toAdd.element = "dark";
                    importD.Add(toAdd);
                    break;
                case 6:
                    toAdd.element = "light";
                    importD.Add(toAdd);
                    break;
            }
            Debug.Log($"element of added card: {toAdd.element}. currently there are {importD.Count} cards in the Deck.");
           
        }
        startTurn(importD);
        #endregion  
    }```
#

You make ONE object here - ElementPage toAdd = new ElementPage("unassigned",1);

#

and then you're adding that one object to the list 30 times with importD.Add(toAdd);

#

And when you're doing toAdd.element = "water"; you're just modifying that same object

plush zealot
#

yes

wintry quarry
#

So - it's exactly like I said

#

you don't have 30 different cards

plush zealot
#

why does the debu.log message give out different results tho

#

im so confused

wintry quarry
#

You have a list with 30 references to the same card

wintry quarry
#

you're doing this:

  • Make the card
  • change the element to dark
  • print the current element
  • change the element to light
  • print the current element
    ... so on
#

you still only have one card, you're just modifying it a bunch of times and printing the current state of it

plush zealot
#

ugh yeah ok

wintry quarry
#

You are probably get confused here because you're not understanding how references work in C#

plush zealot
#

if i put the toAdd in the for loop

#

it wouldnt happen that way

#

and work as intended

wintry quarry
#

to do this properly you would need to be doing ElementPage toAdd = new ElementPage(...); inside the loop

plush zealot
#

yeah...

wintry quarry
#

so that it creates 30 different objects

plush zealot
#

really quick

#

this would work how i'd want it to in java though right?

#

or did i completely shit the bed?

wintry quarry
#

no

#

Java works the same way

plush zealot
#

nvmd then

#

thx tho

wintry quarry
#

It would work how you want if you were using struct instead of class
i.e. if ElementPage was public struct ElementPage instead of public class ElementPage

#

but Java only has class, so would work the same way as here.

plush zealot
#

ah ok

#

yeah no makes sense why it doesnt work

#

thought it would just copy the values

#

and put them in

wintry quarry
#

nope, that's not how references work

plush zealot
#

but it just points to the variable the entire time

#

-,-

#

lesson learned

wintry quarry
#

Yep - structs work that way - copying every time

#

classes use references

plush zealot
#

yeah I wanted to put it in the loop at first but then thought that's not entirely optimal since it would declare the variable a bunch of times

#

but it just doesnt work i guess

#

is there a way to do it cleaner?

#

I put it in the loop and it's still doing the same thing

#

O_O

wintry quarry
plush zealot
#

ah alright

wintry quarry
#
List<ElementPage> importD = new List<ElementPage>();
string[] elements = ["fire", "earth", "water", "wind", "lighting", "dark", "light"];
for(int i=0; i < 30; i++)
{
    int e = Random.Range(0, elements.Length);
    ElementPage toAdd = new ElementPage(elements[e],1);
    importD.Add(toAdd);
    Debug.Log($"element of added card: {toAdd.element}. currently there are {importD.Count} cards in the Deck.");
}```
#

this is really all you need

plush zealot
#

huh it is thx xD

#

problem solved though idk what happened but it works now

river pecan
#

Is there a built in method to check the distance where 2 colliders overlap?

naive pawn
#

what value are you actually trying to find?

#

an overlap would be an area or a volume

#

perhaps draw out a diagram?

river pecan
#

Where the colliders overlap

naive pawn
#

just the horizontal overlap?

river pecan
#

Yeah

naive pawn
#

i don't think there's a method for that exactly, but you can compute it from their bounds probably

river pecan
#

Yeah I'm trying to calculate movement with colliders in the sense of

#

Calculate total distance between colliders

#

Then the distance of the overlap

#

Then move both by half of whatever the smallest distance is

naive pawn
#

and you can't let the physics engine handle that?

#

that's called depenetration

river pecan
#

Well I don't want them to be able to jump on top of each other

naive pawn
#

you could probably just apply a force outwards

river pecan
naive pawn
#

and you don't want that?

river pecan
#

No

naive pawn
#

so you want them to collide horizontally but not vertically?

river pecan
#

Yes

#

If they jump on the opponent

#

They should be pushed back

#

And continue their fall

#

Ideally both characters pushed away by half the distance

naive pawn
#

ngl i feel like this would be jarring

river pecan
#

It's how every fighting game collision I've ever played functions

naive pawn
#

hm, maybe i just haven't really encountered it

#

i'm thinking of minecraft collision lol

#

wait so - if you walk into another player, you should just be stopped?

#

and then if you jump on top of another player, you would then be teleported outwards to depenetrate?

#

or pushed out over time?

river pecan
#

They push each other

#

When you land on top of one another

naive pawn
#

so teleported, but narrow hitboxes so it's not super jarring?

river pecan
#

Yeah

#

I was thinking you could like

naive pawn
#

gotcha, that makes more sense

river pecan
#

Calculate the total distance

#

Calculate the overlap distance

#

Teleport both by half the smallest distance

naive pawn
naive pawn
#

and are they axis-aligned?

river pecan
#

Axis-aligned?

#

What is that?

#

I assume like they're on the same Z-axis?

naive pawn
river pecan
naive pawn
#

basically, are they at right angles to world axes

river pecan
naive pawn
eternal needle
tropic orbit
#

Can someone help me with this code because when i run it nothing happens when i press spacebar

naive pawn
naive pawn
eternal needle
river pecan
naive pawn
river pecan
#

Oh okay

naive pawn
steel relic
#

Hey everyone, I just released v1.0 of a utility I've been working on called FileMover Pro. It's a tool for developers to help organize messy asset folders with features like content-based duplicate finding, a review screen before any changes are made, and an undo button. I'm looking for any and all feedback! You can grab it for free on itch.io:
https://rottencone83.itch.io/filemover-pro-the-smart-file-organize

naive pawn
#

mmm not sure about that one

#

we don't really allow advertisement here. unsure if that counts

river pecan
#

If I could get both insert positions

polar acorn
naive pawn
#

doesn't the yellow box on the left mean unsaved changes

eternal needle
river pecan
#

Then just subtract their x positions

#

Cuz that's how I'm doing the camera zoom

#

So possibly

naive pawn
#

finish a though before hitting enter please

sour fulcrum
#

god i love ms paint drawings

river pecan
#

Oh okay, I have a habit of separating lines in discord

eternal needle
river pecan
naive pawn
river pecan
#

So basically

#

Every collider is 1, 1

naive pawn
#

buddy use full sentences

river pecan
#

Sorry, bad habit

eternal needle
#

if the collider is on some child object which is scaled up then sure, but if you have some weird scaling on every single parent object then id reconsider your setup

naive pawn
#

you really should just use the sizing the collider provides instead of the scale

#

easier to manage, doesn't affect other stuff

river pecan
#

Every player collider is a child of the player. The colliders all have (1, 1) size, and the size is determined by scale of the transform. So that I can have the hitbox physically able to be seen.

naive pawn
#

So that I can have the hitbox physically able to be seen.
none of what you said, specifically enables that

river pecan
#

I have a sprite renderer on the collider object

naive pawn
#

for visualization at runtime?

#

or what?

#

the gizmos are a thing yknow lol

river pecan
#

Visualization in runtime

naive pawn
#

yeah can't you just use gizmos for that

river pecan
#

That's why I have it the hack way

eternal needle
#

gizmos dont display in a build

naive pawn
#

....would one want the hitboxes to show up in the build?

river pecan
#

There should be an option to turn them on and off

#

Ideally in fighting games

naive pawn
#

aight then

river pecan
#

Being able to visualise every hit/hurt box is important

tropic orbit
sly vortex
#

I need assistance with learning how to move my created character and NPCs. Basically, I have a zombie game I'm making

silk night
eternal falconBOT
#

:teacher: Unity Learn ↗

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

light mica
#

Hey, can anyone here gimme some advice on how to start going deeper in C#?

keen dew
#

I don't think you're ready to go deeper when you're still flailing with the basics. Follow the Unity Learn courses, the link is right above your message

light mica
#

Ok, thanks a bunch!

grand snow
light mica
rough sluice
#

Will "Look" still get triggered if I dragged on-screen joystick?:

rigid pike
#

Hi, i'm trying to make breakout clone, i just recently started learning Unity. I wrote this code for the ball movement, but no matter what value i enter, it still goes the same speed. Even if i use Time.deltaTime it still doesn't change anything. Can anyone help?

using Unity.VisualScripting;
using UnityEngine;

public class BallScript : MonoBehaviour
{

    public float ballSpeedX = 10;
    public float ballSpeedY = 1;
    public Rigidbody2D BallRigidBody;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        BallRigidBody.linearVelocity = new Vector2(ballSpeedX, ballSpeedY);
    }
}
hexed terrace
rigid pike
#

nevermind figured it out. this seems to work for some reason:

using Unity.VisualScripting;
using UnityEngine;

public class BallScript : MonoBehaviour
{

    public float ballSpeedX;
    public float ballSpeedY;
    public Rigidbody2D BallRigidBody;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        ballSpeedX = 2;
        ballSpeedY = 1;
}

    // Update is called once per frame
    void Update()
    {
        BallRigidBody.linearVelocity = new Vector2(ballSpeedX, ballSpeedY);
    }
}
#

if i set the values in start

hexed terrace
#

Part of the point of using public' is to expose the value to the inspector. This 'serializes' the field (saves it), so any changes you make in the code these values are not updated in the scene

#

If you want to change the values , then you do it in the inspector on the selected object

hexed terrace
#

that way you can change them at run time (they won't be saved) and have different objects with different values

#

Your script just needs to be this

using UnityEngine;

public class BallScript : MonoBehaviour
{
    public float ballSpeedX = 10;
    public float ballSpeedY = 1;
    public Rigidbody2D ballRigidBody;

    void Update()
    {
        ballRigidBody.linearVelocity = new Vector2(ballSpeedX, ballSpeedY);
    }
}```
#

there's nothing visual scripting related in it (atm anyway) -> remove the namespace use
Start is empty -> remove
those comments are messy -> remove, unless you like the reminder

ivory bobcat
rigid pike
#

but the one where i put the ballSpeedX = 10; in start works

ivory bobcat
#

Did setting a default value and assigning the value through the inspector not work?

#

I'm guessing there's a language barrier or something.

hexed terrace
rigid pike
#

i dont use inspector that much, only to assign for example the rigidbody so i didnt think of it even when you told me to do so. i gotta do some repetition to remember it :D

rough granite
silver fern
#

can I have multiple different variables with the same name inside of an array or similar?

sour fulcrum
#

you seem to maybe have a misunderstanding somewhere here

#

lets say i have a

int myIntNamedBobby this variable is this box

#

this box holds a int

#

and lets say i have

int[] myIntArrayNamedJames

#

this box can hold 16 ints

#

but this box holds 16 values, not 16 boxes

#

actually shit example since that container does contain 16 boxes

#

the array doesn't hold 16 different named variables

#

it's 1 variable holding 16 values

rough granite
sour fulcrum
#

no

silver fern
#

I'm thinking about how to implement debuffs. The debuffs are different and come from different sources so they would each have their own timer, and I thought about creating time variables on demand and pushing them into an array so they can be checked in Update() instead of predefining dozens of timer variables in case I might need that many

sour fulcrum
#

it doesn't matter what your storing

night mural
#

it can be stored in a variable just as an integer can

sour fulcrum
#

i have no idea why you have said this

night mural
#

because it's a better way to think about what you're trying to say than your picture with all the boxes

rough granite
silver fern
sour fulcrum
#

variables don't go in arrays

rough granite
sour fulcrum
#

values do

night mural
#

then some kind of debuff controller, either on the unit or more broadly which ticks down those debuffs

silver fern
#

My idea was to have a dictionary of debuff names with effects. When the debuff attack comes in, the debuff controller would pull the effects from that dictionary, apply them to the unit and start a corresponding timer, which removes the effect when it runs out

rough granite
#

Why ask about an array when you planned to use a dictionary

silver fern
#

the dictionary is just to translate a debuff name to the effects that need to be applied

#

the array would have been to store the timers

rough granite
#

Why not have a class as they array data type?

silver fern
#

how so

patent wedge
#

should i check ground type via tag or layer?

sour fulcrum
rough granite
#

Create a class something like

public class DebuffData
{
    public string DebuffName;
    public float DebuffLength;

    public DebuffData(string DebuffName, float DebuffLength)
    {
         this.DebuffName = DebuffName;
         this.DebuffLength = DebuffLength;
    }
}
public class DebuffController : MonoBehaviour
{
    DebuffData Debuff1 = (("DebuffName"), 1f );
    public DebuffData[] Debuffs;

    private void Start()
    {
         Debuffs = new DebuffData[] {Debuff1, Debuff1};
    }
 // change the second Debuff1 to whatever Debuff you make 
}

and use that as the array type.

#

Took a bit to write since im on my phone :/

silver fern
#

is the public DebuffData(string DebuffName, float DebuffLength) a method?

#

I don't really understand what you wrote I think

#

especially not the second box

rough granite
rough granite
#

One sec, fixed

patent wedge
#

for some reason hit.collider.tag is always returning "Untagged"?

sour fulcrum
#

that collider's tag is untagged

silver fern
rough granite
silver fern
#

and that debuff1 has to already be predefined in that controller class?

sour fulcrum
#

nope

silver fern
#

because of DebuffData Debuff1 = (("DebuffName"), 1f );

rough granite
#

No you can define it in the array i just didn't have intellisense to fix my writing since i wrote this on phone in discord

silver fern
#

so I can leave that line out basically

rough granite
silver fern
#
{

    public DebuffData[] Debuffs;

    private void Start()
    {
         Debuffs = new DebuffData[] {};
    }
 // change the second Debuff1 to whatever Debuff you make 
}```
#

initialize it like that?

rough granite
silver fern
rough granite
#

You might be wanting to use a list they can be dynamically sized

#

Arrays cant

silver fern
#

ah

#

yeah the amount of debuffs would be variable

#

it has to be able to store any number of them

slender nymph
#

then use a list

rough granite
#

Then yeah use List<DebuffData> Debuffs = new List<DebuffData>();

silver fern
#

alright cool thanks

#

public DebuffData[] Debuffs; would still be array though right? since that holds the name and length

rough granite
#

No that wouldn't be needed

#

But that is an empty array

silver fern
#

so to recap ```public class DebuffData
{
public string DebuffName;
public float DebuffLength;

public DebuffData(string DebuffName, float DebuffLength)
{
     this.DebuffName = DebuffName;
     this.DebuffLength = DebuffLength;
}

}

public class DebuffController : MonoBehaviour
{

private void Start()
{
     List<DebuffData> Debuffs = new List<DebuffData>();
}

}```

#

like that?

rough granite
#

Uh move the list out of start

silver fern
#

so just public class DebuffController : MonoBehaviour { List<DebuffData> Debuffs = new List<DebuffData>(); }

rough granite
#

Yeah

silver fern
#

alright nice

rough granite
#

Make it public or add a method to the class to add a debuff to it

silver fern
#

ok cool thanks

rough granite
#

And to add a debuff you can do Debuffs.Add(new DebuffData(DebuffName, DebuffLength);

#

Assuming you put it in a method

#

So it'd be

public void AddDebuf(string DebuffName, float DebuffLength)
{
    var Debuff = New DebuffData (DebuffName, DebuffLength);
    Debuffs.Add(Debuff);
}

silver fern
#

once it times out I can just use the iterator variable in a loop as id to remove the entry from the list right?

sour fulcrum
#

yup, or the reference itself

#

Debuffs.Remove(myDebuffReference) is also valid (assuming its in there)

silver fern
#

what's the reference?

sour fulcrum
#

as in a reference to a value

#

wherever you may have that

silver fern
#

I have two values for each list entry

#

well I gotta loop through it anyway to check each timer so id is probably easiest

#

I guess I'll have a second list that stores ids to be removed at the end of each loop

rough granite
#

Well you could in update use a foreach debuff in debuffs and reduce the debuff.DebuffLength -= Time.DeltaTime;
Then do if (debuff.DebuffLength <= 0);
Mark it to be removed and remove it after the loop is done.

silver fern
#

that seems more complicated

#

also how do I mark entries inside of a list

sour fulcrum
silver fern
#

yeah

#

I'd do something like for(var i=0;i<debuffs.Count;i++) to check each list entry's timer, store the value of i in a second list if the timer runs out, and then remove all id's in that second list from debuffs

sour fulcrum
#

your over complicating it

#
for(int i=0; i< Debuffs.Count; i++)
    if (debuff.DebuffLength <= 0)
       Debufffs.RemoveAt(i);
silver fern
#

oh I can just remove them during the loop?

sour fulcrum
#

or whatever you want

#

yes but actually theres a part of that i forgot

#

you can't remove them during a foreach loop and also you want a reverse for loop

#
for (int i = myArray.Length - 1; i >= 0; i--)
{
    // Do something
}

eg

silver fern
#

why's that?

grand snow
#

^ yea make sure to itterate backwards if you remove elements in that same loop

cosmic dagger
#

If you remove from a loop during iteration, you must do it bakcwards . . .

sour fulcrum
#

it just be like that

grand snow
#

When you remove an element, the ones after get moved up by -1

#

if itterating forwards you will then skip over an element

cosmic dagger
#

When you remove an item from a list, all items after it shift down . . .

silver fern
#

that makes sense

grand snow
#

a,b,c,d
remove c
a,b,_,d
shift up elements
a,b,d

silver fern
#

then d would have the same id as c did before right

grand snow
#

yep which is why itterating backwards is best and is often more efficient if removing many elements

sour fulcrum
#

another nitpick but it's not really an id, index is the explicit term for whats going on here

daring sentinel
#

Any idea where after reloading the current scene, the game freezes?

rich adder
# silver fern why's that?

just to add to this, a foreach wouldn't work because you cannot modify collection during iteration since it makes the collection immutable

sour fulcrum
#

i only point it out because id might imply the id itself has some sort of connection with the related value where in this case the index is just where something is in the collection, it's not specific to what that thing is, that just happens to be whats there

rich adder
silver fern
#

alright thanks

#

yeah by id I meant index

daring sentinel
# rich adder no you're giving us no context
using System;
using UnityEngine;
using Cysharp.Threading.Tasks;
using UnityEngine.SceneManagement;
using UnityEditor;

public class OptionsMenu : MonoBehaviour
{
    public ButtonHandler buttonsUI;
    public GameObject NPCDialoguePanel;
    public GameObject playerDialoguePanel;
    public GameObject dialogueOptionsPanel;
    public GameObject ResultsCanvas;
    public GameObject WinScreen;
    public GameObject gameOverScreen;


    public event Action<int> optionSelected;
    private bool sceneEnd = false;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    protected virtual void Awake()
    {
        ResultsCanvas.SetActive(false);
        NPCDialoguePanel.SetActive(true);
        dialogueOptionsPanel.SetActive(false);
        playerDialoguePanel.SetActive(false);
        GameState.decisionTime += chooseOption;
        GameState.sceneResults += (isWinner) => { displayResults(isWinner); };
        AnimationController.NPCResponse += () => TogglePlayerPanel(false);

    }

{...}

    public void nextLevel()
    {
        Debug.Log("Loading next level");

        return;
    }

    public void restart()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }

    public void QuitGame()
    {
        #if UNITY_EDITOR 
            UnityEditor.EditorApplication.isPlaying = false;
        #else
            Application.Quit();
        #endif
    }   
    protected virtual void OnDestroy()
    {
        GameState.decisionTime -= chooseOption;
        GameState.sceneResults -= (isWinner) => { displayResults(isWinner); };
    }

}

This is the code I have that reloads the scene

grand snow
rich adder
#

.also yeah assign actual method to the event if you want to properly unsub

grand snow
#

you can also store it in a delegate var like Action to unsubscribe correctly later but using a method is easier.

daring sentinel
#

What happens is that it plays the game fine, it just has this issue on reloading the scene if the player wants to restart the level

rich adder
#

by freezing what do you mean exactly? does the unity editor crash or

daring sentinel
#

No it just doesn't play, like it just becomes a still image, I can still exit out of play mode

rich adder
#

did you check the Console window for errors? could be pause on error is on

daring sentinel
#

Checked and there are no errors in the console, instead it's that the game's progress bars are now frozen and the timeline that plays when starting the game is not playing.

Also those Debug.Log messages are just in awake methods of scripts

rich adder
daring sentinel
#

Oh I probably forgot to reset it then

rich adder
#

could explain why most things stop moving

#

esp if you have things with deltaTime

daring sentinel
#

Yeah I do in this method of the script I posted


    protected virtual void displayResults(bool isWinner)
    {
        ResultsCanvas.SetActive(true);
        WinScreen.SetActive(isWinner);
        gameOverScreen.SetActive(!isWinner);
        Time.timeScale = 0f;
   
    }

#

Thanks for the heads up, I'll try it out

#

@rich adder Thanks so much, it works now!

rich adder
#

yup remember static variables like that are global and don't reset on reloads of scenes

daring sentinel
#

yeah cuz they belong to the class init

smoky ruin
rich adder
# smoky ruin could someone help with this?

In this Unity game development tutorial we're going to look at how we can prevent a character from bouncing, when moving down a slope.

We'll start off by explaining why the character bounces when moving down a slope, and then explain how we're going to solve the problem.

We'll create a method that will detect whether the character is on a slop...

▶ Play video
smoky ruin
#

I did it here, but I didn't understand why the player's speed is being reduced when he goes down the slope

slender nymph
#

show your code

rich adder
#

yea cause something sound off.. it should only be doing it on a downslope

smoky ruin
#

I think I solved it

#

basically:public bool IsGrounded()
{
Vector3 bottom = transform.position - new Vector3(0, baseHitboxHeight / 2, 0);
RaycastHit hit;

if (Physics.Raycast(bottom, Vector3.down, out hit, groundCheckDistance, groundMask))
{
    
    characterController.Move(Vector3.down * hit.distance);
    return true;
}
return false;

}

rough granite
smoky ruin
#

and how could I do it?

#

I've been stuck on this for a few weeks now

rough granite
#

Well what you are doing is like adding a new force irrelevant to the players move speed that just forces it down at a speed of the distance the player is away from the ground. The proper way is geting the angle from your move direction and the ground and making the move direction face parallel to the ground while going the same direction as it was before

#

You are basically applying a second gravity force when not on the ground, and not too high up

silver fern
#

also you're doing it inside of the method that checks if you're grounded?

pliant coyote
#

still having issues with my script, what is best way to spawn a ball prefab, and have it roll on the ground x distance?

#

its basically a similiar atatck to kogmaws ability if you are familiar in league of legends

smoky ruin
pliant coyote
rough granite
eternal falconBOT
pliant coyote
#

its actually working now

#

weird

frail hawk
#

i highly recommend learning the basics of programming instead of using ai

naive pawn
naive pawn
#

also, all that rb configuration should be generally done on the actual rb in the inspector instead of here

rough granite
naive pawn
#

i knew java before
you are in a different situation

#

also, damn that's really slow for already knowing such a similar language

rough granite
naive pawn
#

ah, the "hello world" way of "knowing a language" 😉

rough granite
#

Also the 7 months is what i consider it since i learnt it by making a game and once it was fully playable is when i considered myself to know c#

sly vortex
#

Coding with AI when you don't know code yourself will only ultimately end up destroying any decent size project you try to make with it. And once you get one error, just delete it and go back to the top. AI is NOT recommended

rough granite
rough granite
rough granite
naive pawn
#

derpThinking that's not c# nor java

silver fern
#

isn't that python

#

oh I didn't see the ;

naive pawn
silver fern
#

right

naive pawn
#

(and you can use semis in python. it's not usually there by convention but it is allowed)

eternal needle
#

assuming they're just confusing it with the unity print method

naive pawn
#

fair

rough granite
rough granite
eternal needle
#

i do often forget what method a language uses too, i use a few different languages/tools so theres like 6 different printing statements that I need. Kinda sucks when one is debug.log and another is log.debug

vocal fjord
#

wait what

naive pawn
eternal needle
#

but in unity id avoid using print also just because you dont have access to the 2nd parameter that debug.log has, which lets u specify an object to highlight

vocal fjord
naive pawn
#

what does MonoBehaviourPun extend?

smoky ruin
#

lol

vocal fjord
#

idk

naive pawn
#

oh it's from that Photon.Pun namespace?

vocal fjord
#

it wouldnt work properly if it wasnt that

naive pawn
#

i didn't notice that at first, thought that was your own

#

one sec

#

ok yeah it inherits MonoBehaviour

#

what's the name of the file?

vocal fjord
#

ye

#

its the same thing, PhotonVRPlayer

#

its really weird

#

since im making a fork of an open source thing on github, when i imported it, it had some wacky behaviour like that

#

no idea why

naive pawn
#

do you have any compiler errors

vocal fjord
#

nope

#

since its in a prefab it wont let me save it but i opened it like that

naive pawn
#

is it preventing you from adding the component?

vocal fjord
#

yea

naive pawn
vocal fjord
#

i meant some of the scripts that were already in the gameobjects in the prefab made it so i couldnt actually save the prefab

hexed terrace
#

you can open prefabs with missing components, but it won't let you save the prefab - and you won't neccessilarly have compile errors

naive pawn
#

have you recompiled?

smoky ruin
vocal fjord
#

yeah, it was really weird

naive pawn
vocal fjord
# naive pawn have you recompiled?

i tried changing the name of the script and also the class (because some of the other scripts were acting like that and thats how i fixed it) but it didnt work for this one for whatever reason, ill try that

smoky ruin
#

I've been stuck on this for a few weeks now, and I've already read several tutorials

hexed terrace
vocal fjord
#

im dumb

vocal fjord
#

ok i did NOT fix it

#

turns out im SUPER dumb and i need monobehaviourpun for photonview

hexed terrace
#

not knowing something != being dumb.

vocal fjord
#

according to unity MonoBehaviourPun is not a MonoBehaviour class

#

for

#

some reason

#

hmm what if i just put an empty monobehaviour class

#

along with the pun thing

#

yee it works

polar acorn
#

even if the compile error is in a different class

vocal fjord
#

the script only has 1 class tho

polar acorn
#

A compile error in any script will prevent it from compiling changes to any other script

#

do you have any errors elsewhere?

vocal fjord
#

no, i dont have any compile errors

#

i think

#

wait lemme check

#

no i dont have any

slender nymph
#

if it isn't happening now then you don't, and i'd bet that at the time you either did or it was still compiling

vocal fjord
#

yeah maybe

round mirage
#

Hello i would like to use setActive(false) but i know it will disable my script on my gameObject does i have to disable every component (exept my script) if i want to let my script run even if the object dont exist or something else exist to do this ?

slender nymph
#

if you want a component to still update, then yes. the object it is attached to must be active in the scene. you can either disable all other components on that object like you suggested or you could separate it to a different object

tacit prism
#

What’s the point if char literal, since you can just use
console.writeline(“b”);

Instead of using the char literal with
‘b’

#

Started unity, reading up and learning more

slender nymph
#

well you can't assign "b" to a char variable, you can only assign a char to a char. a char is a single character

naive pawn
#

you can do math to chars

slender nymph
#

it's also a value type and really just an integer that displays as a character

naive pawn
#

strings are just arrays of chars

tacit prism
#

I just don’t like the examples there using, the way they show it makes me think initially it’s just a less efficient means of writeline

naive pawn
#

i mean it is trying to show the basics

#

it's not showing the practical use, it's showing an example use that you can play around with to understand

tacit prism
#

As you can tell I’m on my phone
Wish I had the built in console but since I’m at work I have to make do with this, slow day, might as well try to learn while I’m doing nothing

#

Net fiddle still works tho

#

Also if I understand this correctly

String uses “
Char uses ‘
And int uses none

naive pawn
#

integer notation is just a separate thing from strings and chars

#

there's a system of suffixes for the numerics instead

ivory bobcat
#

For the very basics of programming with C#, you can probably reach out to the csharp discord server - !csds

eternal falconBOT
silver fern
#

is there a way to have like a placeholder for a game object in a method dictionary?

ivory bobcat
#

What's a method dictionary?

tacit prism
silver fern
#

well I'm storing my debuff effects in a dictionary that translates the debuff name to its effects, that way each effectcontroller can pull the effects from that dictionary so it all stays in one place. But now I'm wondering about how exactly to store a burn effect like dealing damage every second. Dealing damage is done through the damage controller of the player object, and the effect controller would have access to that but the dictionary wouldn't, so I wanted to put a placeholder for the damage controller in the dictionary

tacit prism
#

There’s just so much to not understand

tacit prism
rich adder
rough granite
tacit prism
#

I love logic, there just so many ways of doing things and not doing things I seem to overwhelm myself

rich adder
rocky heart
#

guys i have a GameObject variable thats an instantiated object using GameObjectVariable = Instantiate(blah blah blah); and Destroy(GameObjectVariable); but it still says destroying assets is not permitted to avoid data loss

rough granite
ivory bobcat
# tacit prism Already joined 3 servers to learn, I ask a lot of questions, so I try to spread ...

Although csharp is used for scripting with Unity and you'll get folks directing others who are wanting to learn csharp to the Microsoft learning resources, this server-channel mainly discusses beginner coding concepts with csharp in Unity and not plain csharp console programming. Just wanted to direct you to the proper community for the proper discussion/support. I mean, folks here (on the server channel) would talk about programming fundamentals overall but it's probably a bit off topic tbh

rich adder
tacit prism
#

I’ll try not to move my questions here if yall want

ivory bobcat
rich adder
tacit prism
#

Idk there’s some communities out there with pricks that “erm u need to use the proper area for questions” and such. Try not to encroach on those people

rough granite
rich adder
#

yea if your previous code didn't allow extension on it then you'd typically want a refactoring or sometimes just rewrite

silver fern
rough granite
rough granite
rich adder
cosmic dagger
#

☝️ This is true as well . . .

silver fern
#

debuffs are a headache

#

I think my whole idea doesn't actually work

grand snow
#

an OO approach would be adding an instance that is able to apply some effect via virtual functions/interface

ivory bobcat
#

If there aren't too many.. probably a state manager would suffice unless you're needing to know info about the source etc

silver fern
#

there's 28 different ones rn but there could be more later

#

and they affect different things, like one deals damage, another reduces movement speed, things that are handled in different controllers

#

the effect controller was supposed to take the effect, apply it to the correct controller, and end the effect when the timer runs out

round mirage
silver fern
#

and the effects should be stored in a common dictionary instead of being copypasted into every effect controller

slender nymph
silver fern
#

I suppose the question is, how to have the dictionary tell the effect controller where to apply the effects

grand snow
#

you have instances of these on the objects they effect instead?

silver fern
#

how do you mean?

grand snow
#

If my player can have effects then it can have a list of effect instances

silver fern
#

yes

grand snow
#

sounds like you went the other way, some class that applies effects to objects

silver fern
#

well it also keeps a list of them

cosmic dagger
#

If you're using SOs, you'll need to create instances of C# classes during runtime to track modified data . . .

silver fern
#

hang on I'll make a paste of my code to show you what I mean

cosmic dagger
#

Oddly enough, I'm doing smth similar right now. I only wanted to create a damage system to funnel through one point. Then I added damage types and it's blown up . . .

silver fern
#

this the controller, the object and the dictionary

hexed terrace
#

(delete from here so you don't get told off for crossposting)

grand snow
#

😴

pliant bramble
#

Okay, thanks 🙂

silver fern
grand snow
# silver fern I'm not sure what you meant here

Your current design does keep a list of "EffectObject" so if each thing that can have effects has their own list and instances then that should make it easier to manage.

I presume these Effect objects will modify/manipulate stats in some way so this also simplifies how that works

silver fern
#

but how do I get it to apply the effect to the right places?

cosmic dagger
#

I guess it depends how your effects integrate into your stats . . .

grand snow
#

Basically you need to plan out what can be modified and then how it can be done in a generic way for all effects

#

e.g.

public float GetStat(string statname)
{
  float stat = stats[statname];
  foreach(var effect in effects)
  {
    stat = effect.ModifyStat(stat, statname);
  }
  return stat;
}
#

some things may not work well with such a system but some things will

silver fern
#

some affect stats but others for example deal damage every second

grand snow
#

Then you can provide the effect with a ref to the player its attached to so it can do things when active?

#

e.g. tick effects each Update() so they can do stuff

#

Then some effect can choose to deal damage to the player every x seconds cant it?

silver fern
#

yes, that was my original question. for that I need some kind of placeholder for the player ref in the dictionary

grand snow
#

Okay that honestly makes no sense to me

silver fern
#

or how do I do this

vital vault
#

how should i move player in 3D for FPS?

grand snow
rich adder
small valve
#

or somewhere

#

idk

vital vault
vital vault
grand snow
#

@silver fern

public class EffectObject
{
  protected Player player;

  public EffectObject(Player player)
  {
    this.player = player;
  }

  //derived types can override this and do stuff!
  public virtual void OnTick();
}

//Example effect
public class PoisonEffect : EffectObject
{
    public override void OnTick()
    {
      player.Damage(1f);
    }  
}
rich adder
small valve
vital vault
#

also i want to add jumps

silver fern
#

that makes sense

grand snow
#

I dont know what you planned to do before but this is how id do it

silver fern
#

well I was storing each effect in a dictionary translating effect name to effect method

#

but I suppose this is better

grand snow
#

yea thats not great, using object oriented programming correctly is the way to go

#

its why it exists

rich adder
# vital vault what should i use

Try both and see which one feels best, there is no set solution. All depends on how you want it to feel. CC Is easiest to get goin

silver fern
#

I see, thanks

vital vault
vital vault
grand snow
# silver fern I see, thanks

btw in my example it will moan about public virtual void OnTick(); as it should instead be:

public virtual void OnTick() {}
//or
public abstract void OnTick();
rich adder
vital vault
#

also i need to be able to slide if like on a ramp or smth

rich adder
vital vault
rich adder
#

Rb has weird issues sometimes like dealing with outside forces or sticking to walls without the material trick

rich adder
cosmic dagger
vital vault
#

im making a really bare bones shooter lol

rich adder
grand snow
vital vault
cosmic dagger
grand snow
#

Mine was different, stats were stored in a dictionary (key as enum, float as value) and a modifier collection class held modification instances that were checked as a stat was retrieved

cosmic dagger
grand snow
#

I at one point needed to have modifications shared by whole groups of objects so I did it this way so they could all share 1 instance of this "modifier collection"

silver fern
#

in my case the modifiers are dynamic so I can't store them in a class

grand snow
#

plenty of ways to do it

cosmic dagger
grand snow
#

Just did what i needed for that game

#

I also had the option for time limited ones

silver fern
#

wait, if I store each kind of debuff in its own class, how do I actually add one to the list?

#

I can't just pass a string with the debuff name to get the right one anymore

dark herald
#

Good evening, I have a physics problem. I would like to make the wheels turn, but I can't do it. Where can I ask my question? Thank you!

grand snow
silver fern
grand snow
silver fern
#

there could be multiple instances of the same debuff so a dictionary wouldn't work I think

#

rn I have var effect = new EffectObject(characterController2D, damageController, effectAuthorityLevel, effectMultiplier, effectDuration); EffectsList.Add(effect);
but instead of EffectObject it would have to be PoisonEffect or SlowEffect or whatever

grand snow
#

well you can still loop over them to find one that meets your criteria
e.g. if(effect is PoisonClass) or if(effect.name = effectName

silver fern
#

loop over the class files yes?

grand snow
#

*elements in the list

#

you need to brush up on your c# and oo programming

silver fern
#

for example I have a string saying "Poison" or "PoisonEffect" and I need to find the correct effect class to add to the list

grand snow
#

Ah well you would ideally do this in your code:

player.AddEffect(new PoisonEffect(player));
#

its easier to just create the object of the correct type where required

#

If the system needs to be more flexable then you may need to have a more complex system to perform the object creation
You can use reflection to locate the type and create an instance but may be a bit advanced

silver fern
#

ok but how do I translate the string "Poison" into PoisonEffect(player)

grand snow
#

If you must do it that way then you need something to map a string to creating the correct object

#
switch(effectName)
{
  case "Poison":
    return new PoisonEffect();
}
#

again, learning more c# will help you figure out what to do

silver fern
#

that's what I'm doing

#

ok thanks

grand snow
#

using a string is not as good as using a custom enum

silver fern
#

I could do that too

cosmic grotto
#

Hi I have been trying to implement a main camera follow script and I have the object I want the camera to follow moving but camera only looks and rotates when the script was attached but does not move when the object moves and yesterday I remove the script and tried the cinemachine camera and I have only got the same results?

dark herald
#

Good evening, I am trying to make my wheel stay fixed but can move except that it circles on itself but it does not stay fixed, how can I correct this?

Thanks

ivory bobcat
grand snow
cosmic grotto
# ivory bobcat You'll probably need to provide more info for people to give proper suggestions

Hi this is code I have written so far. Not sure if this info is any help?
// The target that your camera will look at.
// Drag your ship's Transform into this field in the Inspector.
[SerializeField]
private Transform target;

// The speed at which the camera smoothly rotates to look at the target.
// Adjust this for a smoother or more immediate camera turn.
[Range(0.1f, 10.0f)]
[SerializeField]
private float smoothSpeed = 3.0f;

// Offset from the target (ship) to the camera
[SerializeField]
private Vector3 offset = new Vector3(0, 5, 8);

// LateUpdate is the best place for camera logic.
// It runs once per frame, after all other Update() and FixedUpdate() calls.
private void LateUpdate()
{
    //Debug.Log("cameraLookAt LateUpdate");
    // Essential check: If no target is assigned, the script stops to prevent errors.
    if (target == null)
    {
        Debug.LogWarning("CameraLookAt: Target is not assigned. Please drag the ship's Transform to the Target field in the Inspector.");
        return;
    }

    // Use local-space offset so camera stays behind the ship as it rotates
    Vector3 desiredPosition = target.position + target.TransformDirection(offset);
    // Smoothly move the camera to the desired position
    transform.position = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed * Time.deltaTime);

    // Rotate the camera to look at the target
    Vector3 directionToTarget = target.position - transform.position;
    Quaternion desiredRotation = Quaternion.LookRotation(directionToTarget);
    transform.rotation = Quaternion.Slerp(transform.rotation, desiredRotation, smoothSpeed * Time.deltaTime);

    //Debug.Log("Camera position: {transform.position}, Desired: {desiredPosition}, Ship position: {target.position}");
}
hexed terrace
#

share !code properly 👇

eternal falconBOT
cosmic grotto
silver fern
#

honestly I might just be too stupid for this stuff. this solution with the long switch can't be right but I can't think of anything better

small valve
#

ahgh

#

bored

#

Lazy

#

Tired

#

what should I do..

eternal needle
small valve
#

lazy = bored ?

fickle plume
small valve
#

okay okay fine

eternal needle
vital vault
#

how should i move non kinematic rigidbody for first person controller

rocky canyon
#

probably MovePosition()

vital vault
#

how can i rotate vector?

silver fern
#

quaternion probably easiest

rocky canyon
#

quaternion yes

#

heres how i do rotation.. (but for rigidbody it'd be a bit different) not sure exactly what ud use fo ra rigidbody

vital vault
#

i need to rotate vector

#

around some axis

#

but i think...

vital vault
#

im kinda caveman

rocky canyon
vital vault
#

so i think i will just use trigonometry

rocky canyon
#

yea look here..

grand snow
#

you can do Quaternion * Vector3 to rotate a vector

rocky canyon
#

this is all the methods u can use

#

for rigidbody theres MoveRotation() that u can use like the MovePosition()

#

best thing to do is start experimenting

#

look at methods.. then try to implement what u think fits best

#

u can expose the values in the editor.. or use debug.logs and just see what happens w/ the values

sturdy vigil
#

Hello guys, i have a question. I want to make a really big 2D world and i want to use a mesh. Do you know where i can learn how to do it?

rocky canyon
#

the more u practice the easier it comes

#

if u want to use a mesh and not a sprite its probably a 2.5D and not 2D

#

u can ignore one of the axis and have it act just as a 2d one would.. (u can still use all the sprites, 2d packages, all the 2d physics stuff and code) just in a 3D scene instead

#

like dis

sturdy vigil
#

omg

rocky canyon
#

all game are technically 3D in unity anyway 😄

#

the 2d scenes/templates just do certain things to make it appear 2D

sturdy vigil
#

and do you know where i can learn to do this? i started the catlike coding tutorials but they seem to complex

rocky canyon
#

what do u mean? like the basics and stuff?

rocky canyon
eternal falconBOT
#

:teacher: Unity Learn ↗

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

sturdy vigil
#

but more blocky, like terraria

rocky canyon
#

ohh u mean specifically the 2d terrain stuff

sturdy vigil
#

yeah like that

#

i dont know if i should use a tilemap or meshes, but searching i found meshes are better if i want to make a big world

#

because they are more performance friendly than the tilemap

rocky canyon
#

yea, if i had to chose id chose mesh's over tilemaps b/c i hate tilemaps 😄

#

but they're not really compareable most of the time.. ones for one thing anothers for another thing.. but yea both can be used kinda interchangeably

sturdy vigil
#

yeah tilemaps are more easy to implement than meshes

#

i mean i have the logic though but dont really know how to code it

rocky canyon
#

what specifically?

#

or just in general?

sturdy vigil
#

i know how meshes work the coordinates and the triangles and the arrays to save the data but dont know how to code it

rocky canyon
#

if u search terraria unity you'll find some devlogs and stuff

#

it may help guide you torwards more specific things to look up

#

im a 3d guy so i dont really know much tbh

sturdy vigil
#

oh okay dont worry you have helped a lot

sturdy vigil
rocky canyon
#

thats sorta how tilemaps would work

#

u just keep a collection of the pieces of the terrain

#

however u end up deciding to do that

#

im ass at procedural stuff as well 😄

#

but yea ^ stuff like this... might find a gem in the bunch

sturdy vigil
#

im only starting to learn about it and its a pain 🤣🤣 a lot of maths

rocky canyon
#

ya, you'll have to know a bit of math

#

its not super bad tho.. b/c unity has lots of functions (especially like in the Mathf class) that does alot of the common stuff for u

sturdy vigil
#

thats neat

#

thanks!

rocky canyon
#

no problem! 👍

vital vault
# grand snow you can do ``Quaternion * Vector3`` to rotate a vector

yea i did this

float cosa = Mathf.Cos(transform.rotation.y);
float sina = Mathf.Sin(transform.rotation.y);

float newX = moveInput.x*cosa - moveInput.z*sina;
float newZ = moveInput.x*sina + moveInput.z*cosa;

moveInput.x = newX;
moveInput.z = newZ;

Vector3 moveVelocity = moveInput*_speed*Time.deltaTime;
grand snow
#

well yea you can 2d rotate like this but you dont have to...

vital vault
#

but its just more familiar to me

#

i used to program my lil opengl games so im more used to rotate it in such way

grand snow
#

well yea you can do it manually like this, create a matrix or use a Quaternion

vital vault
#

and i forgot something

#

exactly deg2rad

grand snow
#

yea there are constants provided to go from deg to radians and back

vital vault
#

lol

#

i just pulled y from transform.rotation and i forgot that it was a quaternion

#

should i store camera as Camera or Transform?

primal trench
#

is there a way to make a monobehavior script, add context, and run it on runtime?

#

not context

#

uh, contents

vital vault
primal trench
vital vault
rough granite
#

like what, are you asking if you can change code mid runtime

primal trench
vital vault
#

how should i store camera? as camera or as Transform (or gameobject)

rocky canyon
#

just depends.. (if ur not accessing the variables of the Camera component) you can use Transform..

#

if u need to access the component u can cache it as a Camera instead.

vital vault
#

cuz i only need to move it

rocky canyon
#

if its the Camera thats tagged as Main Camera

rocky canyon
#

and i have many transforms doing different things (swaying, camera breathing effect, etc)

vital vault
smoky ruin
#

Dude, unity is going to kill me one day

vital vault
#

im not coding MonoBehavour script, but NetworkBehavour...

vital vault
boreal pawn
#

Hello,
I’d like to ask for your advice on something. The topic is about splitting my PlayerManager.cs into modular scripts. For example, when I separate the movement logic into a new script, I create PlayerMovement.cs. However, when I do this, the fields that need to be assigned in the Unity Inspector for PlayerMovement.cs no longer appear in PlayerManager.cs. Instead, I have to manually add PlayerMovement.cs to the player prefab.

What I actually want is to keep using PlayerManager.cs, but still be able to see and assign the Inspector fields of PlayerMovement.cs there.
Is this possible?
I’d really like to learn how to write my player code in a more modular and maintainable way, since my current code has grown beyond 2000 lines, which makes editing very difficult.

vital vault
rocky canyon
#

if the things ur assigning isn't part of the Prefab u have to do that at runtime

#

u can't assign things in a prefab to a script in the scene (unless the prefabs also in the scene)
and vice-versa.. you can't assign things in the scene to a prefab (unless the prefab is also in the scene or the things ur assigning are also in the prefab)

rough granite
eternal falconBOT
vital vault
#

tbh, at the end i coded my player like that:

#

that *exact * link?

rough granite
vital vault
rough granite
#

not everyone wants to download a file to read code

#

its the rules

vital vault
#

ok

#

but arent discord gives you a file preview?

rough granite
#

only on pc

vital vault
#

ohhhhh

#

well, thanks

vital vault
# eternal falcon

btw i heard about a paste tool that allowed everybody to change text and it often were changed to this: stop pasting your code using (this tool name), lil (n word)

vital vault
rich adder
vital vault
#

cuz i need slopes and stuff

#

i want to mimic one game

#

am i allowed to post gh links here?

#

its not my repo

rich adder
#

you do know that when you run rigidbody the clients will just see animations/tween and not physically accurate

#

by default in most server-client all rigidbody get turned into kinematic

vital vault
#

thats what i tried to mimic

smoky ruin
# vital vault why

I'm trying to fix a problem to finish moving my character, about the character controller bouncing when going down slopes

rich adder
rocky canyon
vital vault
# vital vault https://github.com/vectozavr/shooter

it has really funky movement, and i quote: "i just checked if player had collisions to check if he could jump. But i realised that this realization allowed players to climb walls and stick to ceilings, and i kept it as a mechanic"

rough granite
#

why not just make the velocity be affected by the angle of the face below it

rocky canyon
#

when grounded make gravity something static lke = -12

#

when ur airbourne u add it up.. += -12

rich adder
#

Project On Plane / move with angle of slope probably much more robust

smoky ruin
rocky canyon
#

ya, thats true.. i learned project on plane afterwards

rich adder
smoky ruin
vital vault
#

how to find child gameobject by tag

rich adder
#

sounds like a codesmell

vital vault
#

i only need to find local player's head

rich adder
#

if its a child why not just link the object directly in the inspector

vital vault
rocky canyon
#

each player has their own instance

#

it'd be their child.. so it'd work out for everyone

rich adder
vital vault
rich adder
#

as I said, if you dont know these baiscs should you really be doing networking now ? lol

rocky canyon
#

if u spawned (2) of em..
the first one would have their reference linked to it (in the children)
the second one would have their reference linked to it (in their children)

rich adder
#

for most setups, the clients know nothing about each other

rocky canyon
#

but just for giggles.. this is how u could find a child gameobject by Tag

foreach (Transform child in transform)
{
    if (child.CompareTag("MyTag"))
    {
        Debug.Log("Found: " + child.name);
    }
}```
rich adder
#

they are all running their own version of the game

rich adder
rich adder
# smoky ruin yeah

so whats happening ? how did you check the function was doing what was supposed to be doing ?

smoky ruin
#

I have been testing several methods, as I want to make a movement base and the only problem I am facing is about slopes

rich adder
#

yes you've been saying the problem has been slopes lol

#

we get it

smoky ruin
#

lol

rich adder
#

what you need to do is debug why the solution wasnt doing it, cause i personally used that same thing and it should be working , even the Project Vector stuff

#

if its not doing it you need to do the next step and debug WHY

smoky ruin
#

I had done a test, and basically, when I don't reset the player's vertical speed, he goes up and down normally, but when I reset it, he has this problem

rich adder
#

I don't see AdjustToSlope anywhere in your code

smoky ruin
smoky ruin
rich adder
#

instead of debugging you removed it..okay lol

smoky ruin
rich adder
#

first you said you added it from the video I sent, then just jumped into not answering about what wasnt working about it into " testing several methods, as I want to make a movement base and the only problem I am facing is about slopes"

smoky ruin
#

yes buddy, I stopped responding because I was trying to fix this problem

rich adder
#

why post here if you're not going to debug it or explain what was wrong with it

#

all the several methods that exists to solve this and somehow isnt working for you the issue isn't the source but the user

smoky ruin
#

lol

#

bro it just bounces

rich adder
#

then it sounds like you didn't apply the fix correctly

#

circling back to you not debugging it

rough granite
smoky ruin
rich adder
#

pretty bad solution and also not a good idea to call Move in multiple places at different times

smoky ruin
rich adder
rough granite
rich adder
#

the problem happens because the character is trying to go on a straight line while the gravity occasionally pushes it down, causing the intermitted / bouncing

#

hence why the solution is to go along the direction of the slope

smoky ruin
#

wait

rich adder
#

if it is working then its easier to take it from there and debug the speed issue rather than giving up and endlessly look for other solutions

#

DesiredMove speed or whatever you got goin on there

smoky ruin
#

yeah

#

wait

#

I noticed that the steeper the slope, the slower it gets, and the less steep, the faster

#

the desired move speed is just the horizontal speed

rough granite
rocky canyon
#

this is why i prefer the (double gravity) method..
first video showing the movement projected along the slope (i always have trouble with the tops, edges, etc)
second video showing the movement as normal (with gravity being static walkin along the slope and then accumulating when in the air)

smoky ruin
rocky canyon
#

most likely is a skill issue, ngl and the way its detecting the slope..
but i like the other method ngl

rough granite
rough granite
rocky canyon
#

yea i tried to do it real quick for the video.. but couldn't figure it out quick enough 😄

rich adder
rocky canyon
rough granite
#

fair i haven't made a full 3d project yet and my 2d one is a top down so i have yet to deal with slopes

rocky canyon
#

🍀 lucky you 🙂

rough granite
#

so not really the surest how they should feel

smoky ruin
rough granite
rocky canyon
#

this is my route to slopes

#

nice and simple but yea i wish i could project better

#

i might try working out the project little later

#

been meaning to get one working but not as of yet

rocky canyon
rough granite
rocky canyon
#

awesome

rough granite
#

reworking the weapon and skill system currently

vital vault
#

How can i make smth like convars in source? or basically a singleton that i can access from everywhere that contains some info, like references, settings, etc?

rocky canyon
#

just make a singleton.. put it in the scene add all ur references and tada finished

grand snow
#

"just make it!"

vital vault
rocky canyon
#

lol.. true story.. they apparently already know what a singleton is (or sorta)

grand snow
#

to replicate convars it would need a few things but its doable

rocky canyon
#

singletons are easy and elegant to reference already...

#

MySingleton.instance.watever;

grand snow
#

I think here it doesnt need to be a singleton because i dont see why it needs to be a monobehaviour

rocky canyon
rich adder
#

its a source thing

#

like console commands

grand snow
#

in source engine a convar has a string name and holds some value. the value can be changed via the in game console or by map logic

rocky canyon
#

ahh gotcha

grand snow
#

concmd is a function you can call via the console and give arguments to

rocky canyon
#

yup, i was missing that little detail.. carry on. ill see myself out

grand snow
#

All i think you need to make convars is some object that has a name, description, holds a value and has an event to report when its value is changed

#

and some single place to keep em all

rocky canyon
#

ive used this before.. ^ not sure its exactly what ur hunting.. but it just uses Static methods + attributes to make things simple

rich adder
#

can probably do a Dictionary or some type of json mapping

grand snow
#

where did json come from?

vital vault
#

(or just javascript)

grand snow
#

nah thats where key values came from

rough granite
#

hey dont hate on Dictionaries

slim spade
#

I'm trying to make a game on mobile and I'm pretty sure my game is not really heavy because I get around 800+ fps on my pc but I can't even hardly get 30fps on my mobile (I didn't see the literal number I'm guessing purely on visual and the discomfort it gives me)

#

And I get around 60-120 fps on genshin, honkai or any other heavy game

slim spade
#

I don't exactly know what AA means

rough granite
#

anti aliasing

#

like TAA, SMAA

#

FSR

slim spade
#

Is it set on by default

#

Because I didn't set it on

rocky canyon
#

true.. it comes enabled

slim spade
rough granite
#

depends on quality level in settings, and camera

slim spade
#

It's disabled

#

Is this a problem?

rough granite
#

shouldn't be

#

it just restricts fps to that of your device

#

refresh rate

slim spade
#

My screen can support up to 120 fps so does it restrict it to 120 or 100 or 60?

rich adder
#

mobile doesnt care cause they're all capped at 30

slim spade
#

Oh okay thanks

slim spade
rough granite
#

turn it off i would assume

slim spade
#

Also

#

I turned off the optimized Frame Pacing

slim spade
slim spade
vital vault
# rough granite FSR

fsr isnt aa, dlss was marketed like aa, but the thing is that fsr or dlss is really bad for getting rid of aliasing, but really good for fps boost

rough granite
vital vault
#

its like reducing resolution

rough granite
#

not when it's at native resolution

vital vault
#

but there is no point to use it

#

fxaa will be really fast, and +- like fsr

rough granite
#

eh i guess alright

vital vault
#

how can i check if rigidbody has any collision

#

also i need its normal

rough granite
vital vault
rich adder
#

these are questions you should be simply googling..

vital vault
#

and i need to check every frame

#

i need collision normal

rough granite
#

point a raycast from the center of that object and make it face the collided object and do hit.normal

rough granite
rough granite
vital vault
#

i heard that raycast almost every frame is a big nono

rough granite
#

if you have like 1k maybe

rich adder
#

thats what RaycastCommand is for