#💻┃code-beginner

1 messages · Page 429 of 1

rocky canyon
#

ahh simple as that

rich adder
#

properties for ya

rocky canyon
#

soo even if u could manipulate it.. it'd do nothing for ya

ripe shard
rich adder
#

yeah because its value type

rocky canyon
#

words 😈

rich adder
#

lmao

rocky canyon
#

i love lamp

rich adder
#

wait let me remove it before i get muted

cinder crag
#

damn , is there any workaround for that

ripe shard
rocky canyon
#

thers a different timescale u can change if i remmeber correctly @cinder crag

#

navarone would know

rich adder
rocky canyon
#

unscaledTime

rich adder
cinder crag
rocky canyon
#

ohh is it..

#

TIL

rich adder
#

oh Timescale ? It would not affect Inputs unless you're doing * time.deltaTime

rocky canyon
#

soo might as well learn w/ ya

rich adder
#

yes assigning value to unscaledTime makes not much sense, its like trying to assign time.deltaTime

rich adder
cinder crag
rich adder
#

why are you multiplying time.deltaTime for timescale

rich adder
rocky canyon
#

a few of em aren't some of em are..

#

just covered bases

rich adder
#

timescale would not affect inputs, but it does affect physics loop

rocky canyon
#

maybe using the new input system could be a solution

cinder crag
#

maaannn

rocky canyon
#

iono ¯_(ツ)_/¯

rich adder
#

putting inputs inside triggerstay is likely a big issue

cinder crag
#

yeah

#

maybe a raycast2d?

rich adder
#

use a bool you detect in Update for inputs

rocky canyon
#

ahh physics

rich adder
rocky canyon
#

yup yup

#

i have to re-do my pause system.. b/c it uses timescale.. i dont believe i wish to use that

rich adder
#

mainly physics and animations are 100% affected by timescale (that includes fixedupdate etc.)

rocky canyon
#

i instead need a static bool to wrap my stuff up in

#

to stop systems from running

rich adder
#

I use a static Event

rocky canyon
rich adder
#

if something in script cares about "pausing" it will do so

rocky canyon
#

sounds gucci

rocky canyon
rich adder
#

Action

#

public static event Action<bool> OnGamePaused

rocky canyon
#

ahhh. okay.. I have a custom class called Action

#

mmhmm :smart:

cinder crag
#

okay fixed evetrything

rocky canyon
#

can either be automatically triggered (onenable) or.. manually called

cinder crag
#

oh my god

#

even the pistol dmg being bugged

rocky canyon
cinder crag
#

the problem was i wasnt puasing the game when in the shop so when i press to buy the pistol , it charges the bow then destroys it and adds the pistol fast so thats why it would be stuck with the bow dmg

#

so now that im pausing my game it works epicly

rocky canyon
#

my player still jumps around while navigating my Pause menu 🫣

#

lmao

#

im glad it doesn't just <crash> lol

#

my problem is the exact opposite.. (when i built my pause menu) i was under the assumption that everything would pause..
MouseClicks do not count

#

my player doesn't move around (b/c of physics) soo i thought if he didnt move he couldnt shoot.. thats not how it works

rocky canyon
cinder crag
cinder crag
#

even made it soif u press E again , it closes it

#

fixed the problem i had since last night , man that feels good

rocky canyon
#

doesn't it?

cinder crag
#

yes indeed

#

i love coding but man its painful

#

good for experience

languid spire
rocky canyon
#

(thats when ur learning)

zenith crown
#

Spawn camps u used a character controller right?

#

How did you fix the camera when crouching so it changes eye heights

#

with the crouching

sand heath
steep rose
#

thats what i do

zenith crown
zenith crown
#

im still really new to unity

#

im 4 days in

steep rose
zenith crown
#

In my character

sand heath
cinder crag
# cinder crag even the pistol dmg being bugged

it didnt get fixed , the pistol dmg is now 0 , the buy happens when i shot and enemy with the bow doesnt matter what dmg i deal then go to the shop , buy the pistol and the dmg is still 0

zenith crown
sand heath
#

You should be using a cinemachine camera if you want anything more complex than a static camera

zenith crown
#

Let me check what im using

steep rose
#

so scale your parent object down and it should move your camera down, although janky. otherwise you could make another script that makes that camera object snap to another object i this case an empty called camtarget. and it will scale the camtarget instead of the camera

#

easier

#

and you do not need cinemachine to make good camera movements, you can code them too.

rich adder
#

the camera target / offset is the best way

steep rose
#

every way is different

steep rose
#

it does that

rich adder
steep rose
zenith crown
rich adder
steep rose
zenith crown
#

also what does it mean when someones code isnt "safe"

#

my friend said that to my code

polar acorn
eternal needle
polar acorn
#

It could mean prone to errors, it could mean vulnerable to attacks

#

it could mean literally using the C# keyword unsafe

eternal needle
#

He could feel very threatened by your code

zenith crown
#

He said that to the way i used enums

polar acorn
rich adder
#

nsa watching their code

zenith crown
#

I simply sent this screenshot and he called it unsafe

#

the use of enums in here

round plover
#

having a problem i want my cube to stop when it hits the obstacles and i got it to work but it only works for 3 when i add a new obstacle and i run into it with my cube it will keep going idk why

rich adder
eternal needle
zenith crown
polar acorn
round plover
polar acorn
round plover
#

2 work fine but the 3rd one doesnt work

rich adder
zenith crown
#

well it works and i dont use the variable yet so im perfectly fine with how it is atm

round plover
#

collision layer?

polar acorn
#

It'll also be significantly easier to work with

zenith crown
#

In your inspector window top left you can see what collision layer they are on. Its always on default in the beginning but for safety change them all to the same collision layer

zenith crown
polar acorn
#

to the enum type you've made

zenith crown
#

ohh now i get it

polar acorn
#

The entire point of an enum is to be a type you can store in a variable

round plover
zenith crown
zenith crown
#

it says layer

round plover
#

ph yeah

#

oh

zenith crown
#

Yeah that one

#

do that on all collisions so they are on the same layer

round plover
#

kinda lost ngl

#

mb

zenith crown
#

dw its a part of the process

round plover
#

what layer do i put it on

zenith crown
#

Which ever you want aslong as they are on the same one

#

are you following a brackeys tutorial?

round plover
#

yeah lol

zenith crown
#

haha knew it

round plover
#

he doesnt do anyuthing with layeers tho

#

layers

#

it al works the same

tranquil hollow
#

what software you use to create yours sprites? (Pixel Art)

zenith crown
#

yeah cause default hits all of them but im teaching you a good habit to have so they only hit what they are meant to hit

zenith crown
#

is solid

#

its a website

#

but works well

round plover
tranquil hollow
zenith crown
#

are the collision boxes checked?

#

in the inspector you see the mesh and collision box

round plover
#

yeah

zenith crown
#

collision box needs to be checked for collisions to work

round plover
#

it is

zenith crown
round plover
#

wdym

zenith crown
#

If its unreasonably fast it could go thru the thing without a frame being loaded in to see what actually happened

round plover
#

no its not to fast

#

but idk why when i plant new obstacles it doesnt work

zenith crown
#

that is pretty odd idk what it might be

polar acorn
round plover
#

oh wait

#

when it hits, my playermovement doesnt turn off

#

off

#

only foes for the three i have on right now

#

weird

polar acorn
#

What is supposed to be turning off and what makes it do so

zenith crown
#

well im going to bed so ill let the others help you out

#

its getting late in CET

round plover
#

it tunrs of the collision of my cube and obstacle colliding

#

turns off*

#

wait

polar acorn
tranquil hollow
polar acorn
still pond
#

Does this mean that im trying to access a deleted object?
NullReferenceException: SerializedObject of SerializedProperty has been Disposed.

round plover
#

okay when my cube collides withb the obstacle the obstacles are coded to turn off my playermovemtn when impacted with my cube

polar acorn
round plover
#

it works for 3 obstacles but the rest dont work

polar acorn
#

!code

eternal falconBOT
still pond
polar acorn
#

it'll be in the bottom of the console window

#

Just follow the breadcrumbs and look for a script you wrote. It's an editor-only bug, so unless it's from something you wrote you can just ignore it

#

it won't affect a build

still pond
#

Ok, thanks

round plover
#

@polar acorn

polar acorn
round plover
#

player collision

#

when impacted with obstacle

polar acorn
round plover
#

obstacles

#

3 work but when i add more thye dont do what i want them to do

#

weird ot me

polar acorn
polar acorn
round plover
#

oops

#

mb

polar acorn
#

you have literally cropped out the most important part of this object

round plover
#

yeah mb

polar acorn
#

Scroll up

#

Send a screenshot with the thing you're actually checking for

#

The name

round plover
#

wdym

#

oh

#

ok

polar acorn
round plover
#

yeah

#

wait jno sorry

polar acorn
#

Make sure the object is named Obstacle and not Obstacle or something

round plover
#

it works

#

its weird sometime it works sometime it doesnt

polar acorn
#

||or better yet don't make the name relevant in code and check something else||

round plover
#

usally when i add a 3rd one

polar acorn
round plover
#

yeah this one

#

first 2 work fine

polar acorn
#

Notice

#

that this name

#

is not Obstacle

round plover
#

wdym

polar acorn
#

What does this line of code do

round plover
#

if collided

#

enable movemt flase

#

movement

polar acorn
round plover
#

obastacle

polar acorn
#

Just the one line I linked

round plover
#

obstacle

polar acorn
#

what does that one line do

#

what is it checking for

round plover
#

it states if collided to obstacle

#

it will do something

polar acorn
polar acorn
round plover
#

,mmmmmmmmmmm last time i even changed ot obstacle it didnt work lemme check again

#

loll

polar acorn
#

Code does exactly what you tell it to

#

If you code in "Check if the object I hit is named Obstacle" then that is exactly what it does

#

Obstacle (1) is not Obstacle.

round plover
#

yeah still doiesnt work

polar acorn
#

There's no such thing as "close enough"

round plover
#

i changed it

#

to Obstacle

#

still wont work

knotty kernel
#

hi.

round plover
#

it hits it then continues on its way

#

😭

polar acorn
# round plover still wont work

Show a screenshot of your entire Unity window with:

  • The scene view showing the player intersecting with this obstacle
  • The obstacle selected and its inspector visible
  • The console window open and visible
fickle plume
#

Should put this in a thread as well. @round plover

polar acorn
#

Yes, when you have the screenshot open it in a thread

round plover
round plover
fickle plume
#

@round plover Thread

round plover
#

as for the other three fine i moved them aside

summer stump
toxic pine
#

i have this line to acces the playerscript: public Playerscript script;

#

but for some reason i cant drag the playerscript inside of unity

slender nymph
#

make sure you are dragging an instance of the component and not the script file itself

polar acorn
toxic pine
#

no

polar acorn
#

I'm assuming one of them is a prefab

#

you cannot drag a scene object reference into a prefab

round plover
#

digiholic how to i dup without it becoming Obstacle(1)

#

each time

#

i want it to just stay as Obstacle

cinder crag
#

good lord , i deleted the chargeable bow code and the pistol dmg is literally being copied from the bow dmg for some reason and i dont know how to fix it at all

polar acorn
toxic pine
#

thanks

polar acorn
round plover
#

confused

#

mb

fickle plume
#

@round plover Why are you posting outside of the thread again?

round plover
#

i didnt'

fickle plume
#

track down the origin of values

#

See the debugging guide in the pinned messages

cinder crag
fickle plume
steep rose
#

we would need to see pistol damage script and bow script to find this issue

cinder crag
#

theres no bow script or pistol damage script , its jsut one script that handles all of that

steep rose
#

lets see it

cinder crag
#

theres not a single line of code that sets the weapon dmg to the bows dmg , i looked in every goddamn script and i cant find one line of code that does that

steep rose
#

what is the WeaponStats script and can we see it?

fickle plume
#

Don't forget to show how you are debugging it as well

cinder crag
steep rose
#

lets see the WeaponsSO script, im having a hard time believing you are not setting damage in any script

cinder crag
#

wait hold on

#

I FIXED IT

#

OH MY GOD

#

I FIXED IT

summer pilot
#

Trying to create a 3D game that operates like a 2D game (much like overcooked! and plateup!

the way my character moves right now is fine, however when I stop moving the character automatically rotates back to facing north.

how can I make it keep it's current rotation when the player stops their input?

using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
    public float speed;
    private Vector2 move;
    public void OnMove(InputAction.CallbackContext context)
    {
        move = context.ReadValue<Vector2>();
    }

    void Update()
    {
        movePlayer();
    }

    public void movePlayer()
    {
        Vector3 movement = new Vector3(move.x, 0f, move.y);

        transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement), 0.05f);

        transform.Translate(movement * speed * Time.deltaTime, Space.World);
    }
}
primal trench
#

hey- im somebody from godot trying out unity
how would i, in an if statement, do or
like
if (blah=true or blah=false)

crystal chasm
#

||

#

For or

primal trench
crystal chasm
#

Also ==

steep rose
#

sorry i didnt respond, i was making potatoes

#

yummy

cinder crag
#

enjoy ur potatoes

#

and nw

teal viper
cinder crag
#

i wanna show my game here like 1 vid of it , but idk if i can

summer pilot
teal viper
summer pilot
teal viper
teal viper
# summer pilot

And yes, you can see in the example that they use it differently from you

summer pilot
# teal viper Read the description

"Use this to create a rotation which smoothly interpolates between the first unit quaternion a to the second unit quaternion b, based on the value of the parameter t. If the value of the parameter is close to 0, the output will be close to a, if it is close to 1, the output will be close to b."

#

from what I am understanding
take point a (my current rotation)
take point b (take the location of where i want to move to and grab the rotation that would cause me to look)
but im confused on wtf T even is, if it's not the rotation speed

teal viper
teal viper
#

Do you understand what an interpolation is?

summer pilot
#

not really

#

i thought i had a grasp of it, but im confused

teal viper
#

Imagine a slider going from 0 to 1. t would be the value where that slider is currently at.

#

If you want to slide it to 1, t needs to be 1.

#

Interpolation is taking two values and returning a value in between them based on t, where 0 would be equal to a and 1 would be equal to b.

steep rose
#

ah i understand, i never knew what slerp did

toxic pine
#

im using this to make "frisbee" come to a stop but for some reason it doesnt work if (collision.CompareTag("stop point"))
{
Debug.Log("STOOOP NOW");

            frisbee.GetComponent<Rigidbody2D>().velocity = Vector2.zero;


        }
summer pilot
#

so i need T to gradually move t from 0 to 1 over time from the point of pressing the key to when it starts to move in game

teal viper
#

If it's 0.05, that would be 5% between a and b

toxic pine
#

frisbee is a prefab

summer pilot
#

so how would i go about doing that?

#

instead of having a flat value

mint remnant
#

Lerp

summer pilot
#

Lerp?

eternal falconBOT
mint remnant
#

stands for Linear Interpolation

toxic pine
#

im using this to make "frisbee" come to a stop but for some reason it doesnt work ```

if (collision.CompareTag("stop point"))
{
Debug.Log("STOOOP NOW");

            frisbee.GetComponent<Rigidbody2D>().velocity = Vector2.zero;


        }```
teal viper
summer pilot
teal viper
#

Either one. The way you use them is the same

summer pilot
#

okay

teal viper
#

That being said, in your case you might want to use a different function

teal viper
#

One that moves the rotation by a flat value

steep rose
#

is the script on the object?

teal viper
summer pilot
sand heath
summer pilot
#

my a is my current rotation
my b is the rotation i want
my t is the timeCount, which is where in the "slider" my rotation is currently sitting

#

my a and b are always changing, so you want me to have a fixed rotation value

toxic pine
summer pilot
#

but i don't understand how that makes sense if you told me that having a fixed value where timecount goes is my issue

teal viper
sand heath
steep rose
steep rose
#

ah

#

okay

#

now we are getting somewhere

summer pilot
sand heath
summer pilot
#

i feel like im understanding how slerp lerp works

steep rose
summer pilot
#

but its not usable in my case?

toxic pine
#

could it maybe be because the frisbee is a prefab

sand heath
sand heath
teal viper
sand heath
#

you could be modifying the prefab instead of the instantiated gameobject

summer pilot
teal viper
summer pilot
teal viper
#

While you certainly could do it with angles, that would just make things more complex than they need to be.

toxic pine
sand heath
toxic pine
#

beware youre gonna be looking at spagheti code

summer pilot
sand heath
ivory bobcat
#

It says you've got two speed variables declared

#

Showing the console window might reveal other issues that you've got

teal viper
summer pilot
toxic pine
#
{
 if (Input.GetButtonDown("E"))
        {
            Debug.Log("e");
            var pllayertrans = frisbeetransform.transform.position;
            var bullet = Instantiate(frisbee, frisbeetransform.transform.position, frisbeetransform.rotation, gotothis.transform);

            
   
            if (isfacingright == true)
            {
                bullet.GetComponent<Rigidbody2D>().velocity = frisbeetransform.right * frisbeespeed;
            }
            if (isfacingright == false)
            {
                bullet.GetComponent<Rigidbody2D>().velocity = -frisbeetransform.right * frisbeespeed;
            }


}


public void OnTriggerEnter2D(Collider2D collision)
        {
        if (collision.CompareTag("stop point"))
        {
            Rigidbody2D RB;
            Debug.Log("STOOOP NOW");

            RB = frisbee.GetComponent<Rigidbody2D>();
                RB.velocity = Vector2.zero;
           
        }

#

bullet is the right var

sand heath
#

how is update even being called?

#

its not written correctly

#

do you have your IDE configured?

ivory bobcat
summer pilot
# teal viper Sounds like you have 2 `speed` fields.

player doesn't rotate at all now :/

public class PlayerController : MonoBehaviour
{
    public float playerSpeed;
    private Vector2 move;
    public float rotateSpeed = 1.0f;
    public void OnMove(InputAction.CallbackContext context)
    {
        move = context.ReadValue<Vector2>();
    }

    void Start()
    {

    }
    void Update()
    {
        movePlayer();
    }

    public void movePlayer()
    {
        Vector3 movement = new Vector3(move.x, 0f, move.y);

        var step = rotateSpeed * Time.deltaTime;

        transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(movement), step);

        transform.Translate(movement * playerSpeed * Time.deltaTime, Space.World);
    }
}
toxic pine
eternal falconBOT
ivory bobcat
sand heath
#

im suspicious of 'frisbee'

toxic pine
teal viper
summer pilot
teal viper
sand heath
toxic pine
sand heath
summer pilot
# teal viper Yes

rotates v slow (fixed by turning the value up to 500), but still rotates back to north position after i let go of the controls

toxic pine
#

yea

sand heath
#

Does frisbee have a rigidbody2D

#

important that its rigidbody2D not rigidbody

ivory bobcat
#

Reference the object as the common and specific component type to avoid having to make get component callscs public Rigidbody2D frisbee;You can always access the GameObject component with the gameObject property - cached and faster than a Get Component call.

toxic pine
sleek marten
#

Could someone please help me? I'm feeling very stupid and confused

copper python
sleek marten
#

I've disabled my pause menu button start and I use a script to turn it on at runtime

#
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PauseActivator : MonoBehaviour
{
    [SerializeField]
    private Button pauseButton; // Assign this in the Inspector

    void Start()
    {
        // Ensure the pause button is enabled
        if (pauseButton != null)
        {
            pauseButton.gameObject.SetActive(true);
        }
        else
        {
            Debug.LogWarning("Pause button is not assigned in the inspector.");
        }
    }
}
#

and that works well enough

#

but this ONLY works on one scene

#

every other scene, the pause UI has to be enabled otherwise the buttons inside it won't work when I load into that scene from the start

#

I really don't want to have to disable and enable the menu every time I leave a scene in the editor

ivory bobcat
#

Also, if you're trying to stop the instance of a frisbee maybe the trigger function should be on the frisbee object instead of this object. Else check if the frisbee made contact with this object (assuming this is on the player - implied by naming conventions: player script) and access the component (rigid body) on the other object to modify its speed and whatnot.

sand heath
#

i wonder if its something to do with changing the velocity outside of fixedupdate

sand heath
#

can you describe your goal?

toxic pine
copper python
sand heath
#

pause menu button start is a lot of words

sleek marten
copper python
sand heath
teal viper
sleek marten
#

let me collect my words

summer pilot
#

i don't want it to rotate when the player isnt actually moving

sand heath
#

describing the problem and how you're trying to solve it to yourself also helps with that

sleek marten
#

I've got a pause button. Inside I have a single option to mirror the gameplay (it's for mobile and it makes it easier to play left handed). I am putting the button in the pause menu so that it's always accessible but not in the way.

That button must ALWAYS be enabled when a scene is loaded otherwise it won't work. Enabling it once you're in the scene breaks it. Therefore the pause menu must also be active otherwise the button will still not work.

My idea was that if I enabled it at runtime then I could get around this. This idea works ONLY at my first scene. If the pause menu is disabled in any following scene then the button to mirror will not work.

#

If the pause menu is enabled in any subsequent scene first, then it all works fine!

#

But now I have the issue of the pause UI ALWAYS needing to be turned on (which blocks the editor)

copper python
#

hmm that makes sense in a logical way

sand heath
sleek marten
#

I have my script search for a component (by string in this case)

#

it's not good but it works in a pinch

sand heath
#

why

sleek marten
#

however if any of those listed things are disabled, then it can't find it

#

I tried doing a serialized field

#

but that works even less

#

not sure why

sand heath
#

ok first off you can reference the main camera with Camera.main

#

there's no reason to even have the first thing

copper python
#

Heard of the Singleton system before?

sleek marten
copper python
#

Look it up, it's usefull

sand heath
#

thats not what they need

#

why dont serializefields work?

sleek marten
#

The script uses PlayerPrefs because I wanted the setting to be persistent across scenes

#

when I use a SF, the game just forgets what's supposed to populate the field and leaves it empty

sand heath
#

What?

summer stump
sand heath
#
[SerializeField] Camera secondCamera;

did you do it like this?

sleek marten
#

yes

sand heath
#

ok and you filled the slot in, what do you mean it forgets?

teal viper
sleek marten
summer pilot
sand heath
#

because the cameras dont transfer to the other scene

copper python
#

What's DDOL? o_O

sleek marten
#

Don't Destroy On Load

sand heath
#

dont destroy on load

sleek marten
copper python
#

ah that makes sense ty

sleek marten
#

so that wasn't the problem

sand heath
#

just because you made an object that looks the same doesn't mean it is the same

#

even if its a prefab

summer stump
#

Oh I see, because you need a reference to the new scene

sand heath
#

so when you go to a new scene you need to set those fields again

teal viper
sand heath
#

main camera you dont need to worry about, second camera i guess is fine to find by name but its really not optimal

#

you could find by tag which would be much faster

sleek marten
copper python
#

Sounds like a good plan

sleek marten
#

so if there's a better way to do it, that's what I need to do

sleek marten
#

what do I do about the button, though?

#

OH THEY TAKE TAGS TOO

#

wow

copper python
#

what do

sand heath
copper python
#

What does that mean? XD

sand heath
#

whatever the problem is is deeper than this button 😭

sleek marten
summer pilot
copper python
#

console log would say true

sleek marten
summer pilot
copper python
#

Vector3.zero equals new Vector3(0, 0, 0), or 0 btw

sand heath
#

Is it just a prefab you have in every scene?

sleek marten
#

I've got the ability to pause the game time

#

and a button that pulls the UI up

sleek marten
#

the camera's aren't, atleast

#

neither is anything in the UI

sand heath
sleek marten
#

didn't think about it

#

didn't know they needed to be

sand heath
#

if you ever use an object more than once and you need changes to be synced you should use a prefab

sleek marten
#

didn't know a camera could be a prefab, either

#

but I'll do that now

sand heath
#

all gameobjects can be prefabs

#

a camera is literally just a gameobject with a camera component on it

sleek marten
#

so should both the Main and Second be prefabed?

sand heath
sleek marten
#

alright that's done

sand heath
#

are they identical?
do you want them to stay identical across all instances?

sleek marten
#

yes

sand heath
#

then prefab

sleek marten
#

Done

silent tree
#

could anyone help me figure out why my game object isnt centered? when i put my game object at (0, 0) it isn't in the center, but things like my camera are centered at (0, 0)

sleek marten
summer pilot
sand heath
cosmic dagger
sand heath
silent tree
#

the sprite is broken up into both a child (the base) and the tower itself as the parent, but they are both at 0,0

sleek marten
#

oh so then I should use tags?

sand heath
#

whenever you load into a new scene you need to update those fields

#

yes use a tag to find secondCamera

#

main camera can be found by camera.main

cosmic dagger
sleek marten
#

how should I tag my UI? Just call it all "UI"?

sand heath
#

only tag things that need tags

sleek marten
#

well the pause menu needs to be found across scene, so that should be tagged shouldn't it?

#

or atleast the specific button within it

silent tree
cosmic dagger
silent tree
#

i meant the small blue circle near the center not the green one

cosmic dagger
#

can you show us the scene hierarchy to display the GameObject?

sand heath
#
public static MyClass Singleton {get; private set}

private void Start()
{
  if (Singleton == null)
  {
    Singleton = this;
    DontDestroyOnLoad(gameObject);
  }
  else
  {
    Destroy(gameObject);
  }
}

@sleek marten

sand heath
#

then accessing the singleton:

private void Update()
{
  if (Input.GetKeyDown("P")
  {
    MyClass.Singleton.MyMethod();
  }
}

@sleek marten

sleek marten
#

Oh no that means I have to redo this pause menu code atwhatcost

#

untangling it to fit this in would probably take longer

sand heath
#

Surely you have version control set up

sleek marten
#

No

#

I'm only on week 1 and so it's a cobbled together mess

sand heath
#

They never do

cosmic dagger
silent tree
#

0,0 for both the base and the tower

sand heath
#

I'm assuming you have

#

But it broke down at some point

sleek marten
#

yeah and they're all 6 years+ out of date or go over things that I'm not doing

sand heath
#

The only thing that might be outdated is input

#

Pause menus are pretty straightforward

sleek marten
#

yeah that's what I thought too

#

it's really cause of this button, I think

#

and it's weirdness that I have to work around

#

I think fixing that will make the other stuff easier

cosmic dagger
# silent tree

right underneath "Scene", change "Center" to "Pivot". does it change the position at all?

silent tree
#

it didnt move, but the handles are now at 0,0

cosmic dagger
# silent tree

okay, that's the actual pivot. before, you were on "Center" which moved the handles to the center of the GameObject, not the actual pivot location . . .

silent tree
#

can i move the pivot to a custom point?

cosmic dagger
#

yes, use the sprite editor . . .

sleek marten
#

@sand heath thanks for the help! I'll be busy for the next day or so getting this sorted

#

god willing I only have to address it once

sand heath
#

Where you realize the way you were doing something was wrong and you have to redo it

sleek marten
#

I'm getting it ready for future proofing, which starts with a functioning pause menu

silent tree
steep rose
thorn lake
#

Oh ok

cinder crag
#

Oops wrong channel

copper orbit
#

what does <> in class declaration mean again? e.g. public class Grid<TGridObject> { { }

#

is it related to generics?

sour fulcrum
#
    public static List<char> alphabet = new List<char>
    {
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
    };
        foreach (char letter in stringCode.ToCharArray())
        {
            Debug.Log(letter.ToString() + " - " + alphabet.IndexOf(letter).ToString());
            newSeedCode += alphabet.IndexOf(letter).ToString();
        }

alphabet.IndexOf(letter).ToString() is returning -1 and I'm not sure why?

#

a quick google didn't pop up anything about indexof returning -1 and I haven't seen that before

frosty hound
#

Quite literally the first few lines

teal viper
sour fulcrum
sour fulcrum
quick fractal
#

!ide

eternal falconBOT
static oracle
#

I'm using 3d tilemaps for a 2.5d game I'm making, using the gameObject brush for walls. is there equivalent to the tilemap collider for a set of gameobjects? or a way to bake the gameobjects together once I've placed them all

last edge
#

does anyone have a 2D character state system that i can have? lol

#

basically for when your character get snared or knock back

copper orbit
sour fulcrum
#

my question was unrelated to my answer to you

copper orbit
summer stump
#
public class List<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IList<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.IReadOnlyList<T>, System.Collections.IList
muted narwhal
#
            ...(somewhere in Start())
            foreach (Transform slot in inventoryParent)
            {
                if (slot == null)
                {
                    Debug.LogWarning("Found a null slot in inventoryParent.");
                    continue;
                }

                _slotPositions.Add(slot);
                Debug.Log("Slot added: " + slot.name);
            }

            Debug.Log("Total slots added: " + _slotPositions.Count);

...somewhere in the code

foreach (var slot in _slotPositions)

Why is _slotPositions null?

ivory bobcat
#

Where was the error thrown? Show the complete error

ashen trail
#

What is wrong with my code? I'm trying to keep my player with from getting out of bounds, but when he reach's -5 on the x position the player will get teleported to -5 on the z position too, same thing in the opposite direction.

muted narwhal
#

Messed up a bit, looks like slot returns null, but... i don't really know.

ivory bobcat
raw token
ashen trail
#

Man, I've been doing the unity learn courses I don't know any other way.

#

I'm just beginning

muted narwhal
raw token
summer stump
ashen trail
#

okay, I will try that

raw token
muted narwhal
#

Maybe you could explain it a bit simplier? English is not my main language, and I didn't understand 80% of your message, especially since I'm kinda new to C# 😓

ashen trail
raw token
# muted narwhal Maybe you could explain it a bit simplier? English is not my main language, and ...

A "variable declaration" is just creating a variable with a type and a name:

List<float> foobar;

I now have a variable foobar. The type of the variable, List<float>, just describes what value the variable can hold. So I've sort of created a "box" that can hold a specific thing, but there's still nothing in it.

Right now, the value of foobar is null. It can refer to a List of floats, but I haven't told it which List of floats it should refer to. There's no value. The box is empty, because we haven't given it any value.

"Initializing a variable" is assigning a value to it for the first time. If I want it to refer to a brand new empty list, I have to write code to explicitly create that list, and then assign it to the variable:

foobar = new List<float>();

Now foobar is no longer empty - it refers to that specific empty list.

muted narwhal
#

I'm more interested in the word "reference", I hear it often but don't understand its meaning in C#.

raw token
ashen trail
#

No

summer stump
# ashen trail No

Should the second two conditions not be checking the z position? They are checking whether the x is within the zRange

ashen trail
#

OHHH sorry

summer stump
ashen trail
#

I guess I'm just blind

summer stump
ashen trail
#

thx for the help

raw token
# muted narwhal I'm more interested in the word "reference", I hear it often but don't understan...

When we create a variable, it's associated with a specific address in memory.

"Value types" are usually simple data like floats and are stored directly at that address. Assigning the value of one such variable to a second copies the value into second variable's address - so they're both unique:

float a = 5.2f;
float b = a;
a = 6.5f;

Debug.Log(a); // 6.5
Debug.Log(b); // 5.2

Meanwhile more complex data is usually a "reference type," meaning that instead of directly storing the value at the variable's address, it may be stored elsewhere, and the variable just holds the address of where it actually is. So our variable is just a reference to it.

When you assign one reference type variable to the other, it copies the address of the data into the second. So now they both refer to the same data instead of unique copies:

class FooBar {
  public float baz;
}

FooBar a = new FooBar();
FooBar b = a;
a.baz = 3.14159f;
b.baz = 42f;

Debug.Log(a.baz); // 42
Debug.Log(b.baz); // 42
muted narwhal
#

Ah, thank you so much

raw token
#

NP... My description of the addresses in particular may not be entirely accurate, but I think may be fine enough for a broad overview 👀

ember tangle
#

What are the "< >" when I use GetComponent<Foo>() or public event Action<bool> Bar

thorny basalt
#

They specify the type when using a function or creating an object

#

Here is an article that goes more in depth. :)

ember tangle
#

I guess what im curious is about is why isnt it GetComponent(foo)

#

Ill read that for sure

thorny basalt
#

if you did
MyMonoBehavior fee = GetComponent(foo);
It would work. But if you did
var fee = GetComponent(foo);
It would need a type parameter.

muted narwhal
#

Can I access Inventory from scene on prefab without creating a new one in the prefab itself?

raw token
muted narwhal
#

Yup

raw token
#

Nope - prefabs can't hold references to anything in a scene.

Ideally, you should assign that reference on the clone when the prefab is instantiated

muted narwhal
#

Could something like this work?

thorny basalt
muted narwhal
#

Yup, I understand, that's only the concept. What would be better to use?

thorny basalt
#

You can have a static variable, and have the inventory assign the variable to itself when it starts. You can have the object create an inventory when it spawns in. Etc.

sweet sierra
#

Hey guys! Hope y'all are doing great. I'm struggling with predicting a trajectory of the game object.

Currently, what's happening is that the trajectory is drawn AFTER the game object moves. I want it to be predicted. The code I'm using for the trajectory is:

public void EstimateTrajectory(Vector2 force, Vector3 startPoint, Vector2 minForce, Vector2 maxForce)
{
    Vector3 velocity = (force / rb.mass) * Time.fixedDeltaTime;
    float flightDuration = (2 * velocity.y) / Physics.gravity.y;
    float stepTime = flightDuration / lineSegmentCount;


    for (int i = 0; i < lineSegmentCount; i++)
    {
        float stepTimePassed = stepTime * i;
        Vector3 movementVector = new Vector3(
            velocity.x * stepTimePassed,
            velocity.y * stepTimePassed - 0.5f * Physics.gravity.y * Mathf.Pow(stepTimePassed, 2),
            velocity.z * stepTimePassed
        );

        points.Add(startPoint + movementVector);
        Debug.Log(points[points.Count - 1]);
    }

    lr.positionCount = points.Count;
    lr.SetPositions(points.ToArray());
}

And I'm calling it in another script like:

tt.EstimateTrajectory(maxPower, transform.position, minPower, maxPower);

Could anyone please help fix it?

raw token
sweet sierra
raw token
muted narwhal
#

Would like to hear it

raw token
# muted narwhal Would like to hear it

Instantiate() can also take a component on the prefab instead of the prefab's root game object, and then it will return a reference to that component on the clone. So it sort of saves you a GetComponent() call.

public NPCController Prefab;

// ...

NPCController npc = Instantiate(Prefab);
npc.inventory = whatever;

Here I've still dragged the prefab into the Prefab field in the inspector, but instead of referencing the GO it will reference the NPCController component on the GO.

thorny basalt
sweet sierra
thorny basalt
sweet sierra
#

And I don't want the trajectory to display bounces. I only need just 1 curved line as in angry birsd

raw token
#

(Even though Unity APIs don't always adhere to that notlikethis)

thorny basalt
sweet sierra
#

So, upon logging the force and velocity values. They are correctly collected and obviously the points would be calculated accordingly. But... It's probably not the case when I debug the "points" of the trajectory

#

They're all the same notlikethis

thorny basalt
sweet sierra
# thorny basalt Anyway, why are you multiplying the formulas over time if you are doing it as a ...

So, the idea is that...

  • I pass the force applied on the ball to the function. This is being calculated accurately.
  • Using this force, I get the velocity and the time of flight.
  • As for the multiplication, well, the trajectory of x axis stays the same over time. Only thing affected is gonna be the y axis. That's where I have used the formula.
  • So, whatever point I get, I'm adding it to the points for line renderer and that's it
#

The start point is the location of the ball from where to start predicting the trajectory

#

I just noticed I don't even need to pass min or max force as it's already calculated and clamped notlikethis

#

Like... in another script, I'm doing this:

if (Input.GetMouseButton(0) && distanceX <= 1 && distanceY <= 1)
{
    Vector3 mousePos = Input.mousePosition;
    mousePos.z = offset;
    currentPoint = cam.ScreenToWorldPoint(mousePos);
    
    
    force = new Vector2(
            Mathf.Clamp(startPoint.x - currentPoint.x, minPower.x, maxPower.x),
            Mathf.Clamp(startPoint.y - currentPoint.y, minPower.y, maxPower.y)
    );

    pt.RenderLine(startPoint, currentPoint);
    tt.EstimateTrajectory(force, transform.position);
}

This script is attached to the same object

#

So, the trajectory should be calculated as long as the mouse is held. But idk if i'm totally correct. I started 2 weeks ago 💀

muted narwhal
#

After some time of debugging, I roughly understood the problem. I have _itemGameObject, it works great, but once GO moves to another parent - it's just becomes null (still not sure), giving me NullReferenceExecption.
I tried doing something like

            if (transform.childCount != 0)
            {
                var child = transform.GetChild(0);
                if (child)
                {
                    _itemGameObject = child.gameObject;
                }
            }

But it doesn't seems to work

sweet sierra
raw token
sweet sierra
#

Basically, I just want the line to be drawn BEFORE the ball is released, not after which is happening rn 💀

thorny basalt
sweet sierra
#

Yes precisely. So, the amount of pull will affect the trajectory.

#

But... it doesn't 🤡

#

Start Point is from where I start pulling the ball, and current point is the point where the pull currently is located. Slingshot mechanism tbc

#

DistanceX and DistanceY are ONLY there to ensure that the pull works only close to the ball, not anywhere else on the screen

raw token
sweet sierra
#

Well... it's weird that now I multiplied the force by a factor of 5 and... I got 4.01 and 4.02 💀. I'll try a bigger factor to see if trajectory makes up

sweet sierra
#

Yesss!!

#

It's working... just in the opposite direction lol

#

The white line

raw token
# muted narwhal Yup

Okay, cool. Just making sure 👌

I'm not sure I see how these snippets are connected though, or which line is the one the error refers to. Could you post this script on like https://gdl.space?

sweet sierra
#

Now, just gotta make sure it lines up with the actual trajectory 😂

muted narwhal
#

Ah

raw token
#

oops

muted narwhal
tender pelican
#

Hey, I'm really new to coding and I have a small problem with the following code:

using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    private Rigidbody2D rb;
    public float Move;
    public float speed;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        Move = Input.GetAxisRaw("Horizontal");
        rb.velocity = new Vector2(Move * speed, rb.velocity.y);
    }
}```
So, I `GetAxisRaw("Horizontal")`, right? And this code works fine, the only issue is that `"Horizontal"` is mapped to `Q` and `D` in the input manager, but when I launch my game, it uses `A` and `D`, I've tried with `"Debug Horizontal"` and it has the same problem. I've tried remapping `"Horizontal"` to `J` and `L` and it worked fine, but `Q` always bugs out and uses `A` while in game, this shouldn't be a keyboard issue as it normally works fine.

P.S. : I'm on an AZERTY keyboard with an AZERTY config.
wary sonnet
tender pelican
#

Oki

#

It worked, ty! ❤️

raw token
# muted narwhal https://gdl.space/imumebaliz.cpp

I'm not experienced with drag events, but I'm sort of wondering if like... since the drag handlers are on the inventory slots instead of the item being dragged, if the callbacks are firing on different slots. Like, if you drag the item from SlotA to SlotB, if OnBeginDrag is called on SlotA, and OnEndDrag on SlotB... I'm struggling to find other reasons for a null exception

You might throw some Debug.Log()s in at the top of either method and pass in gameObject as the second argument, so the logs link to their respective game objects, just to check

sweet sierra
#

Like... it's got a good touch to it? Or I could improve more things

sharp laurel
sweet sierra
#

I just finished up designing that.. so, what do you think? 😂

sharp laurel
#

pretty good ngl

raw token
#

I definitely like the feedback

sweet sierra
#

😁 🫡

sweet sierra
raw token
muted narwhal
mint remnant
#

maybe add a toggle optoin to see the trails of the trajectory

sweet sierra
raw token
muted narwhal
#

Debug.Log(_itemGameObject.gameObject);

topaz mortar
#

Input.GetKey(KeyCode.LeftControl)
Why is this not getting detected?

raw token
# muted narwhal Debug.Log(_itemGameObject.gameObject);

Do like

Debug.Log("OnBeginDrag", gameObject);
Debug>log("OnEndDrag", gameObject);

This will add a little link to the log message which will highlight the respective inventory slot GO in the hierarchy. I'm wondering if, for one drag interaction, those game objects might actually be different

raw token
topaz mortar
#
{
    Debug.Log("Sell all");
    EventManager.StartSellAllItemsEvent();
}
else if (IsHovered && TownController.Instance.InTown && Input.GetKeyDown(KeyCode.S))
{
    SellItem();
}```
My else if triggers properly, my first if doesn't trigger
topaz mortar
#

So if I hold shift and press s, while not hovering an item nothing happens
When I'm hovering an item it just sells that single item, but doesn't show the debug message for selling all

topaz mortar
# muted narwhal

looking at the full code you posted earlier, so not sure if u fixed it
nearestSlotInventorySlot.item = _currentItem;
but you never remove it from the old slot I think?

raw token
# muted narwhal

Huh. Maybe I've forgotten how that second argument works, lol. I'll have to play with that when I have Unity open again. I guess the instance ID might be more useful anyway:

Debug.Log("OnBeginDrag: " + GetInstanceID());
Debug.Log("OnEndDrag: " + GetInstanceID());
Debug.Log("OnDrag: " + GetInstanceID());
muted narwhal
#

I mean, there's still error on end drag

raw token
topaz mortar
#

Also not sure about this part:

nearestSlotInventorySlot.item = _currentItem;```
You set both to _currentItem, what's the logic there?
topaz mortar
muted narwhal
#

just forget to remove it

#

it's definetly a strange way of debuggin'

#

but that doesn't really matter

topaz mortar
#

I literally just implemented the same thing for my items yesterday and it gets pretty complicated -_-

raw token
muted narwhal
#

After adding this line

#

So first I'm making it null

#

And only then setting the current item

#

So it's leaves from first slot

raw token
#

Oh sorry I missed that interaction

topaz mortar
#

You would only want to set the original slot to null once the item has been put into the new slot

muted narwhal
#

It is already like that

topaz mortar
#

!code

eternal falconBOT
muted narwhal
topaz mortar
topaz mortar
muted narwhal
#

that's kinda trippy yeah

#

lemme think

topaz mortar
#

you want to set InventorySlot._currentItem of the OLD itemslot to null AFTER you assigned the item to the new slot

#

otherwise your inventory would think the item is in both slots

#

I have this logic on my Item btw, not in my inventory
you're dragging the items not the inventoryslots right?

muted narwhal
#

So just put it in the end of condition?

raw token
#

I need to go to bed imminently, but my best guess is still that it stems from the drag handling being on the inventory slots rather than the inventory items... If that's true, if you return the code to the state it was in when you could drag items around but keep the Debug.Log()s as they currently are, then the instance IDs which get logged will be different when you drag the item from one slot to another.

And if that's the case, you might consider switching to drag handling on the item rather than the slot. You could keep it on the slot, but I feel like the logic is more complex than the alternative

sweet sierra
#

Ughh guys... I just enhanced my trajectory to display more and...

            tt.EstimateTrajectory(50 * power * force, transform.position);

Why do I have to multiply it by 50? 😭😂

#

The trajectory is 100% accurately working... lemme show you

#

But this factor of 50 is kinda weird 💀

topaz mortar
# muted narwhal Yup

https://www.youtube.com/watch?v=BGr-7GZJNXg&t=561s
that's what I used, it explains everything pretty well imo

✅ Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=BGr-7GZJNXg
Let's make a very simple Drag and Drop in Unity, great for an Inventory System.

Simple Inventory System in Unity (Store, Use, Stack and Drop Items)
https://www.youtube.com/watch?v=2WnAOV7nHW0

If you have any questions post them in the comments and I'll...

▶ Play video
muted narwhal
#

So it seems like it's kinda... can't get components, since I'm getting the components only at start.

#

106 and 76 has _itemRectTransform has _itemGameObject respectfully

#

I don't think that's the case

muted narwhal
raw token
muted narwhal
#

Of what exactly?

raw token
#

Of the slots where these events are occurring #💻┃code-beginner message

My theory is that you start dragging an item, and everything is set and fine. Then you move it over another slot - now that other slot's responsible for OnDrag/OnDragEnd. But that slot doesn't have a _currentItem or a _itemGameObject. It's not at all aware of the item you're dragging, because all of that data is in the other slot alone. So it throws NREs.

muted narwhal
#

I think I already showed you Instance ID's already?

#
...
Debug.Log("OnBeginDrag: " + GetInstanceID());
...
raw token
muted narwhal
#

Without that one line

raw token
#

Yep

#

That confirms it

#

The slot which handles OnDragStart is different from the slot handling OnDragEnd, so they don't have access to the same fields

#

thus the NREs

muted narwhal
#

How can I fix it then?

raw token
#

Wait I might have spoke too soon - there's two different drag interactions in those logs. 😮‍💨

If the OnBeginDrag and OnEndDrag IDs for one interaction moving an item between two slots match, then I'm wrong.

I think using a script on the inventory item to handle some of these events would simplify things in any scenario, akin to what I assume CodeMonkey does

muted narwhal
raw token
#

yeah!

#

I've got to get to bed though. I'm sorry I wasn't of more help here, and for possibly leading you on a goose chase 🪿

muted narwhal
#

Dw, you pretty much helped me

#

Thank you!

raw token
#

Godspeed 🫡

winter tinsel
#

i cannot, i simply cannot make this up
same. exact. code.
same. exact. configuration.
the one that changes to sample scene DOES NOT WORk

#

W H Y

kindred marsh
#

I have this foreach loop, that for some reason breaks at line 31 and says that "object reference not set to an instance of an object"

winter tinsel
#

if i disable the main menu scene it still works from the sample scene, but if i try to move from the main menu to the samplescene the button WILL NOT WORK??

#

the text isnt a raycast target, the button is activated, the script is right ???

winter tinsel
#

wait i might be stupid

kindred marsh
winter tinsel
#

yeah im stupid nvm, help the other guy

languid spire
kindred marsh
#

at the top

teal viper
languid spire
#

yes, declared but NOT initialized, therefore null

ivory bobcat
# kindred marsh

That would be where you've declare it not where you've initialized it

teal viper
#

And see what is being null

kindred marsh
#

Ahh, how do I initialize it?

languid spire
#

= new()

ivory bobcat
#

= new ...

kindred marsh
#

But the other list works just fine

ivory bobcat
#

You can do so during declaration or in Start etc - in your case during declaration should be fine.

ivory bobcat
kindred marsh
#

Ohhh

languid spire
kindred marsh
#

That makes sense

winter tinsel
#

line 12 in question

#

im lost

languid spire
#

no object with that tag

winter tinsel
#

the object is in another scene thats currently unloaded

languid spire
#

then how do you expect to find it?

winter tinsel
#

the crazy part is the game works somehow???

languid spire
#

null ref will not srop the game just make pausy unusable

winter tinsel
#

ok well i need to refrence the code inside the object with the tag resume canvas, can i somehow keep it loaded in the same scene?

#

unload everything else EXCEPT that

languid spire
#

DDOL

winter tinsel
#

huh?

languid spire
#

Dont Destroy On Load

winter tinsel
#

rightt

#

let me look at that

ivory bobcat
# winter tinsel line 12 in question

Line twelve has a great amount of potential to blow up during runtime. Consider not relying on Find calls but instead: properly reference objects, use Singleton managers and whatnot.

languid spire
#

or at least split the line in 2 and check for null

zenith crown
winter tinsel
#

i deleted the error code and now it works?? but only once?????

#

ill start in the main menu

#

start game, game works, ill QUIT to the main menu, start the game AGAIN and this time the timescale is 0???+

#

nothing in the code that makes it 0

#

im completely lost

#

first image is the code that runs at the main menu that sends you to the game, the second one is the button that sends you to the main menu

#

im stupid wait

#

fixed?

#

fixed

muted narwhal
#

I swear to god, I'll see this error in my nightmares;

(DragDrop script, OnEndDrag event)
Debug.Log(Inventory);

why is inventory returning null?

rare basin
#

what's Inventory

#

where is it declared

#

and used

muted narwhal
#

[NonSerialized] public Inventory Inventory;

#

declared in DragDrop script

languid spire
muted narwhal
#

There's not one slot in the inventory

languid spire
#

why not?

#

but it is always the same value irrespective of the number of slots you just set the same thing again and again

#

and it doesnt get set at all if there are no slots

rare basin
muted narwhal
rare basin
#

the same as your class name tbh

languid spire
#

but you only have one dragdrop

muted narwhal
#

right now - yes.

#

but there's definetly will be more than one dragdrop

languid spire
#

not based on that code there wont be

muted narwhal
#

I'm still working on the code, there will be

#

Right now I have a problem

#

What the hell???

#

it returns null and not null at the same time

rare basin
#

show the code

muted narwhal
languid spire
muted narwhal
#

alright, I found the error

fervent abyss
#

is there any way i can make my animation run at a certain fps?

pastel blade
#

i make my object rotate left and right only !Grounded (it's a car) but sometimes it land flipped or by side it's considered Grounded and won't let me rotate how i can change the script from !grounded to !grounded + can rotate when it's not fully grounded like i said (for example it can rotate while it's not fully grounded) idk how to do it anyone ?

queen adder
pastel blade
#

if (!isGrounded)
{
// Rotate around Z-axis when in the air
float airRotateDirection = 0;
if (Input.GetKey(KeyCode.Q))
{
airRotateDirection = 1; // Rotate left around Z-axis while not grounded
}
else if (Input.GetKey(KeyCode.E))
{
airRotateDirection = -1; // Rotate right around Z-axis while not grounded
}

        transform.Rotate(Vector3.forward, airRotateDirection * airRotationSpeed * Time.deltaTime);
    }
queen adder
#

!code

eternal falconBOT
pastel blade
queen adder
pastel blade
#

like that ?

queen adder
#

This way is easier

pastel blade
#

yes i do

#

grounded is just a square setting layer on the car for it

queen adder
#

ChatGPT is awful at programming unless you intensely guide it

queen adder
pastel blade
pastel blade
queen adder
#

You have to use layers to exclude the car from being detected

pastel blade
queen adder
#

I dont know how IsGrounded is being set so I dont know how to write you an example

#

And using triggers for ground detection isnt good

#

CheckBox / Check[Shape] is the better way to do it

pastel blade
#

never used this, can a checkbox let the car only accelerate if it's landed

queen adder
#

Its a bool, true or false, false if the box isnt detecting anything, so you can do anything you want with it

pastel blade
#

but dectecting what exactly ? collision ?

queen adder
#

Yes

pastel blade
queen adder
queen adder
pastel blade
#

ah ok appreciated bro thanks for the information provided it helps

queen adder
#

Yeah

iron blade
#

Hello, how could I make something happen only while the user holds a key down? Right now it only happens once i press it down, but i want it to always happen while i hold it down.

topaz mortar
#

What's an optimal way to structure a "complex" inventory system?
I have different item types, some can be equipped, some can be put in a spellbook, other can be used on item to upgrade them, ...
When you equip an item it is removed from the inventory and put in the equipment
The spells are put in the spellbook instead and also removed from the inventory

Items can be clicked to move or dragged & dropped to inventory/equipment/spellbook if they can go there
Items are generated from combat and loaded from the server on game start

The most complex part is that each itemslot needs to know which item is in it and each item needs to know which itemslot it is in
Items can be dragged/dropped to empty slots or swapped when dragging an item on top of another item
When loading the game I want all items to be in their correct itemslot

My current system is a bit all over the place
I'm creating items in different places and mixing Inventory functions for click with the event system for dragging/dropping 😐

iron blade
#

I did that

slate haven
#

Can someone explain?

languid spire
iron blade
languid spire
iron blade
#

if i walk off my platform is just keeps walking and doesen't fall down

languid spire
#

yes, do you implement gravity?

iron blade
#

i use a rigidbody

languid spire
#

then you should not be moving using transform.position

iron blade
iron blade
languid spire
#

use the rigidbody methods

slate haven
iron blade
#

velocity?

slate haven
#

and use rb.velocity

#

if u want it to be affected by force use rb.AddForce

iron blade
#

rb.velocity.x = walkSpeed would work?

#

if i declare rb as a variable

slate haven
#

It has to be a vector 3

#

type

ivory bobcat
#
public Rigidbody rb;//assign it from the inspector``````cs
rb.velocity = transform.forward * speed;```
slate haven
#

inside the vector coordinates, u can write the walkSpeed

iron blade
ivory bobcat
#

Unity 6 has probably changed the name to linear velocity

slate haven
#

Not Update()

iron blade
#

it moves at light speed now

ivory bobcat
iron blade
#

i gotta use lower than that?

eternal needle
#

odd that you call it light speed, when its basically at 0, 1.5, 0.002

ivory bobcat
#

value/1000f if necessary