#💻┃code-beginner

1 messages · Page 468 of 1

crimson saffron
#

hello, i was trying to implement a death screen into my game - however when the scene resets and the player reloads their gun i get this error. any ideas?

mint remnant
#

Handling stack sizes was complex, someone suggested I chould use scriptable objects too. I have the whole thing working now, but it's fragile and a nightmare to debug, so it will probably get a re-design before done

#

Scene loads destroy objects, you can set them to not destroy on scene load but I forget the method off hand

raw robin
#

My guess is the gun is not referenced to the player after reset

polar acorn
raw robin
#

You're right, I misread that lol

crimson saffron
#

how would i use the notdestroyonload function? sorry if this sounds dumb i only started a couple weeks ago 😅

polar acorn
# crimson saffron how would i use the notdestroyonload function? sorry if this sounds dumb i only ...

https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
This makes an object persist between scenes. It's probably not what you want actually, and your error likely stems from something that does have DDOL already holding on to references from the previous scene. I think more likely what you want is to have that script re-acquire references when the scene changes:

https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager-sceneLoaded.html

stark summit
#

How do I make is so that the box I put code in is in c# on discord? I completely forgot

indigo mirage
#

I'm trying to get gravity to work properly while falling, when it jumps and falls it has the correct amount, however whenever you simply walk off a platform, you fall very quickly much more than if you jumped

#

my jump just adds a force with moveDirection.y = jumpForce, but im wondering if theres a better way, since in order for it to be responsive, i set the gravity and jump force higher

steep rose
#

reset Y velocity while on ground

indigo mirage
#
private void ApplyFinalMovements()
    {
        if(!characterController.isGrounded)
        {
            moveDirection.y -= gravity * Time.deltaTime;
        }
        if(willSlideOnSlopes && isSliding)
        {
            moveDirection += new Vector3(hitPointNormal.x, -hitPointNormal.y, hitPointNormal.z) * slopeSpeed;
        }

        characterController.Move(moveDirection * Time.deltaTime);
    }
#

i realized that the moveDirection.Y glitches out on slopes and spheres

#

but im not sure how to rememdy that

steep rose
#

keep in mind character controllers have slopes built in

indigo mirage
#

normally on a flat surface the move direction will be around -8 to -10, but after sliding down a sphere its all the way to -150

steep rose
#

so you dont need to make them

indigo mirage
#

well this is so you arent able to just jump on top of them

#

because the normal character controller allows you to jump over them

steep rose
#

🤔

indigo mirage
#

this makes it so you slide down and cant go up something you shouldnt

steep rose
#

just move the character controller by Vector3.down via move method and you should be good

#

if you detect you are on a steep slope ofc

indigo mirage
#

still in moveDirection?

steep rose
#

you probably coud just make another move method and if on a steep slope move the character controller down

#

it should slide down

#

as long as you dont translate it

#

using translate will ignore collisions

indigo mirage
steep rose
#

do you want to move while sliding down?

indigo mirage
#

one moment let me get a short video of what it does currently

#

note the moveDirection in the bottom right

#

how to goes up to insane values

indigo mirage
steep rose
#

then reset the Y movedirection while grounded

#

once off steep slope

#

reset it

indigo mirage
#

that fixes the amount

#

however now I am able to jump over the slopes, because it resets the value while on the slope

steep rose
#

when off steep slope

#

you need to check if you are on a steep slope

#

if not then reset it

indigo mirage
#

oh I see what you mean

#

hmm it still seems to think im on the ground even when on the slope

steep rose
#

are you checking the slope angle?

indigo mirage
#

Ohh wait i see what I did wrong

#

i think it was a mistype, let me test it

#

Ok this works, i think the only thing I need to figure out now, is that if the slope goes right over an edge

#

because the -y movedirection will still rack up, but there wont be any ground to reset it

steep rose
#

you can reset it while in air but you need to make gravity seperate then

#

or else you wont have gravity

indigo mirage
#

Alright, well thanks for you help

#

I appreciate it

steep rose
#

👍

#

come back anytime for help

indigo mirage
#

actually, (im sure this is just me being dumb) do you know why this ramp lets me stand at the very bottom?

#

its probably something to do with my isSliding bool...

    private bool isSliding
    {
        get
        {
            if(characterController.isGrounded && Physics.Raycast(transform.position, Vector3.down, out RaycastHit slopeHit, 2f))
            {
                hitPointNormal = slopeHit.normal;
                return Vector3.Angle(hitPointNormal, Vector3.up) > characterController.slopeLimit;
            }
            else
            {
                return false;
            }
        }
    }
eternal needle
indigo mirage
#

Ah, I see what you mean about the unnecessary work, thats simple enough, as for the debugs, it seems that its not detecting anything, which is causing me to believe that because the raycast comes out from the center, at the very edge the hitbox is still on the slope, but the center is over the edge, im not sure how to fix that without an obscene amount of raycasts on all sides

steep rose
#

its because you are using the built in charactercontroller.isgrounded I believe it detects the ground via the collider hit points

#

i could be wrong

#

so its detecting you are on ground but not on a slope

indigo mirage
#

the raycast IS running, its just not hitting anything

#

yes

main karma
#

so I managed to solve the issue by removing deltaTime all together

void CheckDeceleration(ref Vector3 moveDir3D, Vector2 inputVector)
    {   
        moveDirDecel.x = moveDir3D.x /6;
        moveDirDecel.z = moveDir3D.z /6;

        if (gravity_Check)
        {
            moveDir3D += ((inputVector.y * transform.forward) + (-inputVector.x * transform.right)) * 2 - moveDirDecel;
        }
        else
        {
            moveDir3D += ((inputVector.y * transform.forward) + (inputVector.x * transform.right)) * 2 - moveDirDecel;
        }
        
        Debug.Log(moveDir3D);
       
    }

works somehow like a charm

steep rose
#

or just orient your raycast to the slope

meager sinew
#

These are in 2 different scripts
and i keep getting NullReferenceException: Object reference not set to an instance of an object
how do i fix it?

rocky canyon
#

set an instance of the object to the reference

indigo mirage
steep rose
#

its 1 line of code

rocky canyon
languid spire
steep rose
#

depending on what you want

rocky canyon
#

check the references within that line

  • one of em is not assigned
#
  • figure out a way to assign it
meager sinew
indigo mirage
steep rose
rocky canyon
#

well since u cropped the line numbers that information is only useful to you

meager sinew
rocky canyon
#

we still dont know what line 16 is..

steep rose
#

give us the full !code

eternal falconBOT
meager sinew
steep rose
#

preferably in a paste site

meager sinew
#

oh

rocky canyon
#

its _gameUIHandler

rocky canyon
#

you have a private reference.. and no logic that assigns it

#

since its private i know its not assigned in the inspector.. so how is Unity supposed to know what instance of it, you are trying to use

#

you either need to

private void Awake(){
   _gameUIHandler = some sort of logic to assign one;
}```
or use
`[SerializeField] private GameUIHandler _gameUIHandler;`
so you can assign it via the inspector
indigo mirage
meager sinew
#
public class CharacterManager : MonoBehaviour
{
    [SerializeField] public int _playerHealth = 8;

    private GameUIHandler _gameUIHandler;

    public void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.CompareTag("Enemy"))
        {
            _playerHealth--;
            _gameUIHandler.ChangeHealthBarSprite();
        }
    }
}
public class GameUIHandler : MonoBehaviour
{
    [SerializeField] private Sprite[] _healthBarSprites;
    private Sprite _currentHealthBarSprite;

    private CharacterManager _characterManager;
    private int _playerHealth;



    #region HealthBar Sprite
    public void ChangeHealthBarSprite()
    {
        _playerHealth = _characterManager._playerHealth;

        for (int i = 0; i < _healthBarSprites.Length; i++)
        {
            if (i == _playerHealth)
            {
                _currentHealthBarSprite = _healthBarSprites[i];
                gameObject.GetComponent<SpriteRenderer>().sprite = _currentHealthBarSprite;
            }
        }
    }
    #endregion
#

oh i figured out how to post code lol

rocky canyon
#

yea, the solution has already been provided tho..

#

little too late

meager sinew
#

ik

steep rose
#

you probably would want a seperate float as well for the radius of the sphere

indigo mirage
#

wouldnt I want the radius to be the same as the character controller, to see if it is the one touching anything?

steep rose
#

if it was the same

#

so just make it a bit smaller

rocky canyon
#

or do as dec, sed and just use a different gameobject or something..

#

public Transform feetLocation;

meager sinew
rocky canyon
rocky canyon
meager sinew
#

still got error

rocky canyon
#

whats the error say now?

#

if ur still getting an error that means theres another null reference error somewhere

#

its probably this one now

meager sinew
#

its the _playerHealth = _characterManager._playerHealth

rocky canyon
#

ahh okay..

#

well gotta assign _characterManager then

meager sinew
#

oh ye

rocky canyon
#

things like floats, ints, vectors and stuff.. don't need assigned b/c they have default values

terse spindle
#

hey spawn camp

rocky canyon
#

but if ur using custom scripts and stuff

#

they always have to be told what instance of it ur using

meager sinew
#

oh ok

rocky canyon
#

or create a new one on the fly

meager sinew
#

so can i assign it in the inspector?

rocky canyon
#

u can put [SerializeField] in front and yea

#

then assign it

#

^ thats the go to way of assigning things quickly

#

it doesn't always work.. for things like prefabs.. u cant assign stuff in the scene until they get spawned

#

soo u have to do things like GetComponent or Find.. or something lik ethat in the Awake() / Start() fuctions

meager sinew
#

oh ok

rocky canyon
#

but for things u can. assign them in the inspector

meager sinew
#

ty

#

error is gone

terse spindle
#

do anyone got active ragdoll tutorial that you can recommend to me

#

website or video

rocky canyon
indigo mirage
steep rose
rocky canyon
#

make the Z coord 0 for the love of all thats precious

steep rose
#

you adjust the variables in the inspector to get the desired effect you want

#

not the position

indigo mirage
rocky canyon
#

why?!

#

is ur player offset?

indigo mirage
#

my camera probably

#

its in the front of the player

rocky canyon
#

do u have it set to pivot?

steep rose
#

just put it in the bottom middle of your character

indigo mirage
steep rose
#

it doesnt need to be centered (to much)

rocky canyon
#

pivot shows u the origin of the object u've got selected...

indigo mirage
#

oh yeah, its on pivot

rocky canyon
#

if its set to center it shows the general center of all objects

#

ya, somethings not lined up correctly lol

indigo mirage
#

heres on center and pivot

steep rose
#

oh my

rocky canyon
#

ohhh yae...

#

thats gnarly

steep rose
#

lol

#

not that offset

rocky canyon
#

when u go to rotate stuff around its gonna break all to heck

steep rose
#

lmao

indigo mirage
#

oh boy

rocky canyon
#

show ur heirarchy

#

and the inspector

indigo mirage
rocky canyon
# indigo mirage

okay.. so far soo good.. b/c the position of the ROOT object doesnt really matter

steep rose
#

zero them out

rocky canyon
#

the main camera tho.. lets see it..

#

it should be 0, (some number), 0

steep rose
#

then adjust via Y

#

only the children though

rocky canyon
#

wait no

steep rose
#

not the parent

rocky canyon
#

why why.. is the center of this guy all jacked up?

indigo mirage
#

heres everything(children) zeroed

rocky canyon
#

ya, i didnt see ur Player Capsule...

steep rose
#

change the center on the character controller to 0,something,0

rocky canyon
#

its center should be 0,something,0

indigo mirage
#

ohhh, my bad i misunderstood

rocky canyon
#

we did too

#

ur all good..

indigo mirage
rocky canyon
#

ur camera probably is right then

#

yes... thank you!!!

steep rose
#

clean

rocky canyon
#

u were giving me anxiety

steep rose
#

calm

#

and collected

rocky canyon
#

NOW back to the foot at hand

#

lol

indigo mirage
#

lol

rocky canyon
#

yea ur ground check should be just below the capsule

steep rose
#

if you want to use they raycast method you can if needed

rocky canyon
#

if u want to raycast from that position it should be a little above the edge

indigo mirage
#

Might as well learn the check sphere while im here

rocky canyon
#

something like that

steep rose
#

well you did everything correct but is the 10 a layer?

#

dang

#

i didnt reply

indigo mirage
steep rose
#

then you are fine

indigo mirage
# rocky canyon

rq how do you get the highlight of the char controller, and still able to move just the empty object

#

i have to unhighlight the controller whenever i want to move it

steep rose
#

his character controller is on his parent object

#

and hes moving the parent

indigo mirage
#

oh I see

steep rose
#

he has a capsule to tell him where is player is

#

which is preferred

rocky canyon
#

yea, i use a capsule mesh renderer for my Graphics object

#

just make a capsule 3d object and remove the collider from it.

steep rose
#

its pretty much a standard

rocky canyon
#

(the CC already has a collider within it)

#

really helps when writting ur controller code..

#

so u dont have to keep clicking and seeing the gizmos

indigo mirage
#

Ah i see, no collider in the graphics

rocky canyon
#

just make sure its lined up to the controller's collider

rocky canyon
#

so i just created a 3D > Capsule and removed hte collider

indigo mirage
#

cool

steep rose
#

if you had a collider on the graphics then it would most likely fly in the air

#

which is not preferred

rocky canyon
#

it would spaz out

#

and get all jittery and stuff.. it'd break my gun raycast, my groundcheck raycast, and alot of other stuff

indigo mirage
#

my char controller is not a perfect capsule

steep rose
#

thats fine

indigo mirage
#

how do you change the radius of the graphics capsule

steep rose
#

just from the inspector

rocky canyon
steep rose
rocky canyon
#

(since its just graphics)

indigo mirage
rocky canyon
#

.25, some height, .25

rocky canyon
#

that way u can scale it any way u want.. and it wont affect ur physics/ code

#
  • Main GameObject (the root) [1,1,1]
    • Graphics [anything you want]
#

i said scaled to 0.. but then it wouldnt exist 🤣 i meant scaled to 1

indigo mirage
#

sorry i may be confused but that breaks everything at 0,0,0?

#

ohh yeah its alright

rocky canyon
#

yea.. sorry

#

lol

indigo mirage
#

one final thing, its not quite matching up

rocky canyon
#

its fine... w/ that weird tall shape it wont exactly

indigo mirage
#

ok

#

NOW, finally on to the actual issue

rocky canyon
#

yessir!

steep rose
#

i have zero clue why i have 2 groundchecks but oh well

wintry quarry
rocky canyon
#

lol.. j/k 🤣

wintry quarry
#

Like where it's being called from and how the move3d vector is used

mental coral
#

Hello Anyone know how can i fix this error

steep rose
#

pure insanity 😂

summer stump
rocky canyon
steep rose
#

thats true

#

lmao

rocky canyon
mental coral
rocky canyon
#

gives good detection w/o being too expensive

summer stump
eternal falconBOT
mental coral
rocky canyon
#

sorry Aethenosity wrong ping

steep rose
#

i have never been good with arrays

#

they scare me

summer stump
rocky canyon
#

arrays are sooo ez dec

steep rose
#

bet

rocky canyon
#

u should def look into them when u got some free time

#

👍

steep rose
#

i probably will, i know a lot of times where an array would come in handy

rocky canyon
#

altho.. i can probably do that w/o the array.. and just add to the values in the loop

#

but loops scare me

fading mountain
#

Hey guys. I'm trying to set up input with the new input system. In my input actions file/window, there is no option for the spacebar, or any other keyboard inputs. Specifically how do I set up the spacebar for my game?
This video shows that the input actions doesn't even listen for the keyboard and also that I can't type it in. Maybe im typing it wrong though.

rocky canyon
#

press the Listen button

#

and then press a key and see what happens

steep rose
#

thats the input system?

#

what even is that

#

i must be under a rock or something

fading mountain
rocky canyon
#

weird

rocky canyon
steep rose
#

the keyboard/mouse bool isnt enabled

#

enable it

rocky canyon
#

lol look at u.. problem solving things u never even heard of

steep rose
#

still i have never seen the new input system

#

bro im serious

rocky canyon
#

ya, get out from under ur rock

steep rose
#

i havent seen it before lmao

fading mountain
#

no I did try that and it didnt work

#

tried it again right now, thats not wat its for

rocky canyon
#

its basically a must-have if u want to do things like Dynamic Key-binds

#

for the menu's

#

or 2 player games or w/e

iron steeple
#

Does ontriggerenter effect still works if both object istrigger is enabled

indigo mirage
#

So now the sliding isnt working at all, its not detecting that its on a slope at all
heres the check sphere

Physics.CheckSphere(groundCheck.transform.position, characterController.radius  - 0.05f, 10)
steep rose
#

i would make the radius a float

#

and adjust it from there

steep rose
indigo mirage
#

well right now I just have the whole checksphere in place of where isGrounded normally goes

#

while testing

iron steeple
#

I tried it it doesnt work

indigo mirage
rocky canyon
#

Value Vector2

#

My Axis-Type Keybinds are under an action using 2D Vector DigitalNormalized

steep rose
#

the new system is 🤔

#

this is gonna take a lot of time to learn it

fading mountain
#

ty

indigo mirage
#

So i tried setting the groundCheckRadius to 0.1,0.2,...0.6 and it didnt detect at all in any

Physics.CheckSphere(groundCheck.transform.position, groundCheckRadius, 10)
steep rose
rocky canyon
indigo mirage
rocky canyon
#

its basically Events being called when stuff happens (instead of polling [every frame in update]) for example

steep rose
#

but 0.6 and 0.2 is very small

#

just adjust it till you get a hit

indigo mirage
#

tried all ints from 2-10 none are sliding

steep rose
indigo mirage
#

nope

steep rose
#

layering wrong?

fading mountain
#

@rocky canyon you fixed by issue tysm. works like a charm

indigo mirage
summer stump
steep rose
#

and do what spawn said

indigo mirage
#

layermasks look like this correct?:
layerMask:10

#

never used them before

#

also what did spawn say, that was with the raycasts instead of checksphere?

summer stump
#

I recommend just making a layermask variable and changing it in the inspector btw. That is the easiest.

Otherwise if you want layer 10, it would be 1 << 10
You need to use a bitwise operation

A bitmask (layermask) is like a list of bits. Each a flag

rocky canyon
#
    private void OnDrawGizmos()
    {
            // Set the color for the Gizmo
            Gizmos.color = Color.yellow;
            // Draw a wire sphere with the radius specified by groundCheckRadius
            Gizmos.DrawWireSphere(groundCheck.transform.position, groundCheckRadius);
    }
``` i said u can use OnDrawGizmo's to help u visualize
pallid nymph
steep rose
#

or do what Aethenosity said

indigo mirage
#

OK perfect, its sliding now,

steep rose
#

also preferrably a [seriliazed] private layermask

indigo mirage
#

yeah i did a serialized private layermask

#

yep

rocky canyon
indigo mirage
#

however it still has the same issue with isGrounded :/ im stuck at the edge of the ramp

summer stump
indigo mirage
#

its at 0.1575 right now

#

and im sliding but not falling off

steep rose
#

okay

pallid nymph
indigo mirage
#

any lower and it doesnt slide at all

steep rose
#

and do what spawn said

indigo mirage
steep rose
#

and visuallize the sphere

#

using what spawn suggested

indigo mirage
#

ok one minute

steep rose
summer stump
#

I see what you mean now. Yes I get it. My bad
It would "convert" it to what you said

rocky canyon
#

and you don't need to Call OnDrawGizmos() from update or anything..
its one of those magic unity methods.. that just work on its own

indigo mirage
#

but it still shows it

rocky canyon
#

sooo its in the right location it seems

sleek gazelle
#

'Default parameter value for 'rotation' must be a compile-time constant'

    private void SpawnObject(GameObject obj, Vector3 pos, float scale = 1, Quaternion rotation = Quaternion.identity){

How can I fix that please?

rocky canyon
#

try = Default

#

u shouldnt name it rotation btw

cosmic dagger
sleek gazelle
rocky canyon
#

call it myRotation or summin

zenith cypress
#

.identity is a property, you cannot use it as a method param default value

main karma
#

did you guys know that if you call deltaTime in fixedUpdate, it calls fixedDeltaTime instead?

cosmic dagger
summer stump
rocky canyon
#

i just had the same error w/ Vector3

#

default worked in my case

sleek gazelle
main karma
sleek gazelle
#

Ok thanks

cosmic dagger
zenith cypress
#
void SpawnObject(GameObject obj, Vector3 pos, float scale = 1) => SpawnObject(obj, pos, Quaterion.identity, scale);

void SpawnObject(GameObject obj, Vector3 pos, Quaternion rotation, float scale = 1) {}

A default quaternion is invalid

rocky canyon
#

🪄 wooOOoOooo

main karma
#

imo it should just call for the one I'm interested in

summer stump
summer stump
main karma
sleek gazelle
#

thanks anyway

zenith cypress
#

A default quaternion is not valid.

rocky canyon
summer stump
rocky canyon
#

but idk ¯_(ツ)_/¯

rocky canyon
#

lol.. ik im just guessing thats what he means tho

summer stump
sleek gazelle
#

Ah

#

No

#

You're right, I didn't use it lol

rocky canyon
#

thats b/c u assigned it lol..

#

but if u don't not sure what default would throw

cosmic dagger
zenith cypress
rocky canyon
#

aye ^

#

two methods that work.. is better than 1 that doesn't i guess

sleek gazelle
#
    [SerializeField] RenderTextureMakerCamera renderTextureMakerCamera;
    [SerializeField] new Renderer renderer;

    void Start(){
        PrefabsReferences prefabsReferences = WorldManager.instance.worldsPrefabsReferences[renderTextureMakerCamera.id];
        renderer.materials[0].color = prefabsReferences.planeColor;
        SpawnObject(prefabsReferences.tree, new Vector3(0f,0f,0.3f), 0.025f);
    }

    private void SpawnObject(GameObject obj, Vector3 pos, float scale = 1, Quaternion rotation = default){
        GameObject prefab = Instantiate(obj, pos, rotation);
        prefab.transform.SetParent(this.transform, false);
        prefab.transform.localScale = new Vector3(scale,scale,scale);
    }
#

This is my code

#

and it worked fine

#

And I did use the quaternion defualt to set the rotation of the prefab in Instantiate()

rocky canyon
#

soo if u exclude rotation in ur method params it spawns it at Quaternion.Identity?

#

today, im learnin!

sleek gazelle
main karma
# cosmic dagger how so?

so basically I got a cube that pushes my player away, the player movement is in update and it decelerates over time
but the raycast that detects if the player collided happens in fixed update.
My player accelerates faster with more FPS, but also decelerates faster and so it keeps a constant speed across all framerates
But I had to divide the speed that the cube uses to push my player away using Time.DeltaTime because the deceleration speed of faster framerates is bigger and so the value of acceleration it gives must be bigger just like in movement.

And so took me 3 hours to figure out that the reason it wasn't working was because physics use fixedDeltaUpdate and so it converted it to that. In the end I just stored the actual deltaUpdate in a variable and applied it there and now it works

indigo mirage
rocky canyon
#

theres not a collider on ur empty foot object is there??

indigo mirage
#

nope

main karma
rocky canyon
#

its probably just not enough force to push u up that steep of a slope

#

i'd see what happens on a shallower slope

indigo mirage
#

OHHH WAIT

#

I'm stupid

steep rose
indigo mirage
#

yep

#

tahts what i just realized

rocky canyon
#

ahhh

summer stump
steep rose
#

best use a sphere raycast

indigo mirage
#

is there a way to get the info like a raycast hit, from a sphere check

#

well there it is

steep rose
#

for this aplication

indigo mirage
#

thank you

steep rose
#

spherecast at the rescue

#

again

indigo mirage
#

lol

main karma
zenith cypress
#

Hm I wonder if instantiate does an invalid quaternion check then in C++ land before using it 🤔

rocky canyon
#

you should find out and let us know

sleek gazelle
#

Is there a channel for questions about textures rendering issues? Cause I can't find one

rocky canyon
zenith cypress
sleek gazelle
rocky canyon
zenith cypress
#

Gotta have the big bucks for that PensiveJoy

summer stump
rocky canyon
#

i was waiting for someones response

steep rose
#

🤔

main karma
# summer stump 1) why apply speed in update. FixedUpdate would be better for that 2) what does ...

ok so once I detect collision, I call for a function that calculates the speed and gives it back to the player.
The problem is that I call the function from from the collision detection function that happens in fixedUpdate
My player runs physics in Update and that's because when I tried making it move in fixed update it was very laggy for some reason and I gave up. And now I got so much code built up upon it that I'd rather work around it instead

#

I need delta time in fixed update to account for the player moving in update

#

so I just created a variable that stores it locally instead

zenith cypress
#

It wasn't laggy in fixed update, you just saw it without any interpolation

main karma
#

I don't even know what that means

rocky canyon
#

interpolation.. it guesses the inbetweens and gives u a smooth render

zenith cypress
#

Fixed update runs on a fixed interval, you saw it only on that interval, instead of smoothed out

main karma
#

ah I see

zenith cypress
#

You can see this if you add a rigidbody to a cube with interpolation disabled, see how it stutters, then enable interpolation, and it is smooth

main karma
#

can you enable interpolation for the default character controller?

zenith cypress
#

Nah that doesn't use physics itself

rocky canyon
main karma
main karma
rocky canyon
#

np, i just like filling up my hd w/ video 😅

zenith cypress
#

CC is fine in Update since it is a kinematic body (aka not on the physics tick). I've done checks in Fixed to then use in Update for various things, but update is fine for a CC.

rocky canyon
#

tbh, im amazed w/ myself.. how was able to get that little tilt when i go back and forth

summer stump
main karma
rocky canyon
#

👀 im better than i thought i was

rocky canyon
main karma
summer stump
main karma
#

what

zenith cypress
#

or vice versa

main karma
#

but when I run them in update they happen like 2-3 times per frame

summer stump
#

So what?

main karma
#

I only need them once

rocky canyon
#

wait... he said he using CC right?

#

im lost now

summer stump
#

Then do a bool to only do them once. In update

steep rose
summer stump
steep rose
#

ah

rocky canyon
#

CC / RB carrot cake, and red balloons

steep rose
#

i guess i didnt know the abreiviation lmao

#

Cruise Control

rocky canyon
#

why is there fixed update being used again?

zenith cypress
#

If you want checks that are from physics, and you don't want to over-check them, you can always just check them in Fixed, save to a variable, then read from Update to check/reset it.

Or just keep them in Update. Whatever works for what you want/need.

summer stump
main karma
rocky canyon
#

if ur relying on CC it has its own collisions 🤔

summer stump
rocky canyon
#

and if ur raycasting you can do that in update.. as well as fixed

#

i gotcha

main karma
rocky canyon
#

lol.. the next time it runs

#

but.. u could use a timer/ or a coroutine/ or a custom tick rate.. to control how often things happen..
or throw it in fixed update.. lol

steep rose
#

you could use a coroutine

#

he got to it first

rocky canyon
#

but yea.. when something happens u flick the bool...
exactly one frame will happen befor its considered again.. but then it'd be a different state.. soo 1 frame has run

summer stump
# main karma how would you check if a frame as passed with a bool?

I think we are talking past each other. You want to not hit walls. Ok, so check every update if you are moving towards the wall. If you are hitting the wall, don't move that way. Not sure why the number of times it is called even matters. But you could set some bool when you hit the thing, and reverse it when you don't

Maybe show your code. Because your descriptions are confusing me a lot.

rocky canyon
#

ive been confused.. im still trying to put it all together

main karma
#

how do you upload large codes again?

cosmic dagger
summer stump
steep rose
#

!code

eternal falconBOT
amber spruce
#

hey so i want to check if the gameobject is on a certain layer how can i achieve this?

cosmic dagger
#

that's an easy google answer . . .

rocky canyon
#

maybe this can help us @summer stump
lol.. just for some context while reading the code

amber spruce
#

im dumb

cosmic dagger
polar acorn
rocky canyon
amber spruce
rocky canyon
#

oh its a layer... 🤦‍♂️. sorry i need discord scaling

amber spruce
#

ye

cosmic dagger
main karma
rocky canyon
#

ohh deer

main karma
#

wait

amber spruce
main karma
rocky canyon
main karma
#

ok I think it works now

rocky canyon
#

the paste? yea...

#

holy using statements batman

summer stump
#

You are doing three separate raycasts in the check collision method....

#

Then omg five in the other. Ok, I guess those ones make sense. They are pointing different ways

main karma
#

well I need to check up, down, and then I also need to check if the cube is at my feet or my face in the direction that I'm walking towards

rocky canyon
#

weird code lol..

main karma
#

my first unity code

#

been working at it for months

rocky canyon
#

cool cool...

mint remnant
rocky canyon
#

sounds like my character controller..

#

8 months

#

ur player moves in update..
yet u only jump in fixed?

main karma
#

the Y direction is completely separate from the other 2

rocky canyon
#

yes... theres no other way, esp not random

#

not sure else u could mean by loaded.. unless ur talking initialization type stuff

main karma
rocky canyon
cosmic dagger
rocky canyon
#

if u let me move 60 times in a second during update.. but u only allow me to jump every 50.. it wouldnt feel balanced

#

but im just nitpicking.. its not like its broken or anything so ignor me lol

main karma
rocky canyon
#

b/c my gravity is interpolation during the update

#

also w/ my grounded/slope checks

mint remnant
rocky canyon
#

that is random..unless u specify

indigo mirage
#

I updated all the isGrounded to the customIsGrounded, and im getting this weird bug when in the top corners of platforms

rocky canyon
#

thats why singletons and initializations of those can error.. unless u have one awake b4 the others or 1 start b4 the others

main karma
rocky canyon
#

and then you'll have a race condition.. its best to use

  • Awake to initialize self
  • Start to initialize/grab components or w/e from others
main karma
indigo mirage
#

my character controller is slimmer than normal, but i wouldnt say you cant see it

cosmic dagger
indigo mirage
#

my radius is 0.25

main karma
#

very slim nonetheless

indigo mirage
#

i see

main karma
#

I think that that's just how the character interacts with slopes edges I guess

#

actually I figured this late and never used it but there's a better character controller in the asset store made by unity if I'm not mistaken

#

for free

indigo mirage
#

whats different about it?

main karma
#

idk let me look it up again

indigo mirage
#

alr thank you

main karma
#

a lot

#

it has gravity, uses cinemachine

#

I see android joysticks on some images

#

ah yes those are included

indigo mirage
#

neat, but il stick with this custom 'basic' one for now, as this is just me learning unity

main karma
main karma
indigo mirage
#

or just because you already wrote it

main karma
indigo mirage
#

ofc ofc

amber spruce
#

how do i instantiate smth as a child of a specific gameobject

slender nymph
#

look at the available overloads for Instantiate

frosty hound
#

Instantiate has a parent parameter you can set. Or you can set it afterwards with .SetParent(...) on the transform of the object you've instantiated.

flat gale
#

I am making a turn based rpg and am currently stuck on an issue where the enemy I touch doesnt delete in the overworld scene after I finish a battle. Im pretty new to unity and my only thought so far has just been to destroy the enemy object when its touched by the player but when I destroy it the enemy it reapears in the overworld when the battle is over. Any ideas?

rich adder
rocky canyon
indigo mirage
rocky canyon
#

you can check out how my flow worked atleast.. (just commenting back from when i mentioned your jump)

#

but if it aint broke dont fix it.. ya know.

rocky canyon
#

what happens if u made ur spherecast just a little smaller than the player

indigo mirage
#

it is by 0.01

rocky canyon
#

ah, nvm that may make it worse

#

ohh its that dang gizmo thats throwing me off

#

u should remove that if its not like that anymore

indigo mirage
#

the gizmo is the custom is grounded radius

rocky canyon
#

or comment it out // unless ur still using it

indigo mirage
#

shouldnt i be using it because this is a isgrounded issue

rocky canyon
#

when that happens i bet ur isGrounded is flickering on and off

#

whats ur groundcheck code look like

indigo mirage
#

one sec

rocky canyon
#

thats a crazy list of variables lol

indigo mirage
#

lol its in debug

#

i have a bunch of headers in normal

rocky canyon
#

still.. the white ones arent 😅

indigo mirage
rocky canyon
#

its ur sliding logic + ur grounded logic

#

they arent playing well together

indigo mirage
#
private bool IsSliding
    {
        get
        {
            CustomIsGrounded = Physics.CheckSphere(groundCheck.transform.position, groundCheckRadius, groundLayerMask);
            if(CustomIsGrounded && Physics.SphereCast(transform.position, groundCheckRadius, Vector3.down, out RaycastHit slopeHit, 2f))
            {
                hitPointNormal = slopeHit.normal;
                return Vector3.Angle(hitPointNormal, Vector3.up) > characterController.slopeLimit;
            }
            else
            {
                return false;
            }
        }
    }

put the customIsGrounded in here just to show what it is

#

just tried to set all other customIsGroundeds back to regular charcontroller.isGrounded still didnt work

rocky canyon
#

hmm.. u could buff up ur regular ground detection...
or you could use a cooldown buffer or something to the isSliding.. soo once u start sliding you can't begin sliding for a few milliseconds or w/e.. soo that way once that isSliding starts to flicker like it does.. ud be able to override it and walk up just enough to where the next time the issliding check goes u wouldnt be sliding..
then finally.. you could use a more complex ground check.. or additional raycasts.. to check if ur up on the ledge

#

it looks like one of those really hard to solve unless ur right in front of it, tinkering w/ it urself.. kinda problems

steep rose
#

ah

#

the spherecast could be hitting the wall reading 90deg and thinking its a slope

#

but like spawn said, you can use a cooldown to be able to slide. like

if(Wassliding){
  //some corountine to wait a certain time then allow sliding again
}
sleek marten
#

Hey, everyone! I'm having some real trouble with an array. I've tried a few things but I still end up stuck with this one issue I can't solve.

What I'm trying to do:
I have buttons set into an array. I have a reference to a counter that goes up by 1.
When the counter has a value that's equal to a button's element number, that button should change animation states.

What the problem is:
Only the first button in the array is being effected.

{
    public Button[] buttons;
    public PersistentCounter counter;

    private string currentState;

    public const string LEVEL_BUTTON_ACTIVE = "Level_Button_Active";
    public const string LEVEL_BUTTON_UNLOCKING = "Level_Button_Unlocking";
    public const string LEVEL_BUTTON_IDLE = "Level_Button_Idle";

    void Start()
    {
        CheckButtonsAgainstCounter();
    }

    public void CheckButtonsAgainstCounter()
    {
        int counterValue = counter.GetCounterAmount();

        for (int i = 0; i < buttons.Length; i++)
        {
            Animator buttonAnimator = buttons[i].GetComponent<Animator>();

            if (buttonAnimator != null)
            {
                if (i <= counterValue)
                {
                    ChangeAnimationState(buttonAnimator, LEVEL_BUTTON_UNLOCKING);
                }
            }
        }
    }
    void ChangeAnimationState(Animator animator, string newState)
    {
        // Stop the same animation from interrupting itself
        if (currentState == newState) return;

        // Play the animation
        animator.Play(newState);

        // Reassign the current state
        currentState = newState;
    }
}```
indigo mirage
#

        if(willSlideOnSlopes && isSliding)
        {
            moveDirection += new Vector3(hitPointNormal.x, -hitPointNormal.y, hitPointNormal.z) * slopeSpeed;
        }
#

heres the part in my ApplyFinalMovements();

steep rose
indigo mirage
#

but if its starting to slide on the corner wouldnt it continue to start to slide?

steep rose
#

no

#

actually now that im thinking about it, it would probably do the slide once and then act normally

#

not just act normally

steep rose
indigo mirage
#

sorry was starting to work on the coroutine, i think it would do the first slide movement then stop you on the ramp not sliding until to stalltime completes, then would do that one movement then go back to standing still

steep rose
#

that would work

#

or an angle over your steep angle

#
if(angle >= 90){
 //dont slide
}

//or

if(angle >= steepslopeangle && !angle >= 90){
 //slide 
}
#

something like that would work

rocky canyon
#

no matter how u do it.. basically it comes down to prioritizing 1 of 2 things..

#

either u climb up on the ledge.. or u fall of it

#

i have one of each lol.. (my character controller always grabs the ledge like a champ (b/c he only has 1 raycast).. the other i paid for.. and he tends to fall off of edges.. (it uses an array of raycasts in a circle)

#

one has a better detector.. it can know when ur not techanically on the ledge

#

and it yeets u down

rocky canyon
#

i think ur slope detection shouldnt detect over soo steep an angle

indigo mirage
#

Sorry, my discord was breaking, and wasnt letting me send any messages

rocky canyon
#

like at all

indigo mirage
#

right now it just uses the character controller slope limit

#
Vector3.Angle(hitPointNormal, Vector3.up) > characterController.slopeLimit;
#

how something like this

#
if(!(Vector3.Angle(hitPointNormal, Vector3.up) >= 90))
                {
                    hitPointNormal = slopeHit.normal;
                    return Vector3.Angle(hitPointNormal, Vector3.up) > characterController.slopeLimit;
                }
rocky canyon
#

so u can keep all the buttons idle except for the one ur changing? edit: nvm, misread the problem

indigo mirage
#

So i added a debug variable to show me what the angle in, and it doesnt even seem to get to 90 or 0 at all when jittering on the corner of the platform

sleek marten
rocky canyon
#

ohh sequential gotcha

#

yea, i cant read today..

sleek marten
#

you and me both

steep rose
#

this is mine

    private bool OnSlope()
    {
        if (Physics.Raycast(transform.position, Vector3.down, out Slopehit, Slopehitrange * 1.5f))
        {
            //calulates angle between vector3.up and slopehit.normal to get the angle of the slope
            angle = Vector3.Angle(Vector3.up, Slopehit.normal);
            if (angle < 40)
                slopehitrangefloat = Slopehitrange / slopediv;
            else if (angle > 40)
                slopehitrangefloat = Slopehitrange;
        }

        if (Physics.Raycast(transform.position, Vector3.down, out Slopehit, slopehitrangefloat))
        {
            //returns false if not on slope (basically means to not use slope code)
            return Slopehit.normal != Vector3.up;
        }

        return false;
    }
#

this is modified so ignore the extra stuff

#

you would only need 1 raycast

steep rose
#

and you should be good

fading mountain
#

Hey guys. I'm making a sort of top down 2d game, and I want the player to rotate and look towards the mouse at all times. This is my code so far, and this is what it is producing. Any suggestions?
`void OnLook()
{
Vector3 screenPosition = Mouse.current.position.ReadValue();
screenPosition.z = Camera.main.ScreenToWorldPoint(transform.position).z;

    mousePos = Camera.main.ScreenToWorldPoint(screenPosition);
    mousePos.z = 0f;

    Vector3 directionVector = (mousePos - transform.position).normalized;
    float rotationDelta = Vector3.SignedAngle(Vector3.right, directionVector, Vector3.forward);
    transform.rotation = Quaternion.Euler(0f, 0f, transform.eulerAngles.z + rotationDelta);
}`
#

nevermind I guess the video is in 2 fps

#

so you guys cant see anyway

steep rose
#

try and record it again, it was working before you pressed play

fading mountain
steep rose
#

I guess your OBS is being weird but

fading mountain
#

let me close some programs

#

I have a weak pc

#

yeah i cant do anything more

#

just a performance issue

steep rose
#

you probably shouldnt use OBS if you have weak PC

fading mountain
#

whats the alternative

steep rose
#

look it up on youtube

#

or google

#

personally i use oCam

rocky canyon
#

i can't tell but could it be because its the transform.right thats pointing at the mouse and not the up

fading mountain
rocky canyon
#

u see how the right (the red axis points at the mouse) even tho i want the transform.up (axis) to point at the mouse.

fading mountain
#

updated video (ty dec_ves)

rocky canyon
#

ur calculating from vector3.right to the mouse position

#

but u keep adding that to the rotation each time..

#

(thats why it keeps spinning around in one direction)

#

do transform.rotation = Quaternion.Euler(0f, 0f, rotationDelta); instead (i think)

slender nymph
#

just FYI, the atan2 call and stuff is unnecessary. you can just assign the transform.up or transform.right to the direction from the object to the mouse's world position

rocky canyon
#

lol, i always forget thats the easiest way

fading mountain
#

update, looks like it's working now but inverted.

deft grail
#

get OBS or geforce experience or windows recording

fading mountain
deft grail
ionic zephyr
#

if an object like a tree has an "object" script attached to it and I am creating a procedural dungeon, should that be a prefab or part of a tilmap?? Maybe its a stupid question but I am confused

deft grail
#

usually anything that you will use more than once / in other scenes can be a Prefab

ionic zephyr
#

it has the "breakable" logic on it

ionic zephyr
deft grail
ionic zephyr
rocky canyon
#

aye, did it w/o atan2.. (took me a minute.. as i forgot about the camera's Z position mattered)..

    void Update()
    {
        Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        mousePosition.z = transform.position.z;
        Vector3 direction = mousePosition - transform.position;
        transform.up = direction.normalized;
    }```
slender nymph
# fading mountain how do I do that?

exactly like i said. use the direction as either the transform.up or transform.right depending on the direction the object faces at 0 rotation.

fading mountain
#

it's inverted though

cosmic dagger
#

then . . . switch it . . .

slender nymph
#

if you used that code that spawn just gave you and it is facing the opposite direction, then your object points down when not rotated which is not ideal. but you can just negate the direction

rocky canyon
#

can u fix the rotation in sprite editor? like u can change a pivot?

#

doubtful nvm

fading mountain
#

No i think that the rotation is being applied inverted. not the sprite

#

that's what I meant to say

slender nymph
#

what direction does the sprite point when it is at 0 rotation

fading mountain
#

it points up. its a triangle

slender nymph
#

show your code then, sounds like you maybe have your direction calculation backwards

rocky canyon
#

then transform.up = direction should be pointing at target

#

did u do transform.pos - mousePosition or mousePosition - transform.pos

fading mountain
rocky canyon
#

well if ur using Look now, ur mousePos isn't being updated

#

not unless OnLook is being run from somewhere

steep rose
fading mountain
slender nymph
#

screenPosition.z = Camera.main.ScreenToWorldPoint(transform.position).z;

fading mountain
#

I tried putting it in update but it has the same effect

slender nymph
rocky canyon
#

lol, i see where ur going with this..

fading mountain
steep rose
#

im thunkin rn

rocky canyon
#

its not that thats broken

#

its the way he trys to integrate the z value into all of it

slender nymph
fading mountain
#

but I still need that line

rocky canyon
#

when u Debug directionVector just before u assign it as transform.up
it's Z coord should match ur gameobjects Z coord

slender nymph
#

if you are using an orthographic camera (which i would assume you are if you're doing 2d) then the position returned by ScreenToWorldPoint when the Z axis is 0 will be the correct position but with the camera's Z axis value in the Z axis of the returned Vector3. you do not need that first assignment to the z axis of the screenPosition object, you only need to assign to the z on mousePos

fading mountain
slender nymph
#

no

#

not at all

#

that's literally the same thing

fading mountain
#

you said use transform.position.z for the z axis of mousePos

rocky canyon
#
    void OnLook()
    {
        Vector3 screenPosition = Mouse.current.position.ReadValue();        
        mousePos = Camera.main.ScreenToWorldPoint(screenPosition);
        mousePos.z = transform.position.z;
    } ```
#

like this ^ fam

fading mountain
#

I'm sorry if I'm missing something, im still new to coding and unity

#

oh okay

slender nymph
rocky canyon
#

u confused urself, and us w/ the two methods, and the strange screenPosition.z thing

fading mountain
#

thank you spawn camp games as well

rocky canyon
#

do u know why tho..

#

thats the question.. lol

fading mountain
#

I was calculating the world position using the wrong z value

rocky canyon
#

simply yea. 👍 ultimately its gotta look at its own Z coord or else it tilts to and away from the camera

#

i just fixed up my own look at mouse script now lol. i've always used atan2 until i seen boxfriends comment

#

i guess its still useful in other departments

ionic zephyr
#

Does somebody know how to place (trees,rocks, bushes, etc... ) randomly in an already generated (procedural) terrain in Unity 2D?

peak python
#

so i am trying to move the tile 1 tile size down if there are no tiles below and if it is still in camera view
i have 2 issues

  1. cell size is bigger than the actual tile size for some reason,
  2. how i can get cell size in int and not float? so i can avoid the vector being 1.0000001
radiant meteor
#

is it a problem is i put too many regions in a script? i keep getting lost in my own code when i'm trying to work on one specific thing

cosmic dagger
radiant meteor
#

i probably should organize it lol

cosmic dagger
#

each script should only handle one behaviour . . .

zenith cypress
#

The two phases of using regions:
"Wow these will make it easier to hide stuff I don't need to see!"
"Wow I hate clicking so much more where is my code aaaaaaa-"

radiant meteor
#

it's a player movement script, and it has movement, jump, walljump, different kind of movement while in the air, ground check, gravity, wall checks, and i'm planning to add dash and ground slams

cosmic dagger
#

i've seen people use #region — including myself — to section off or organize code, so it's not terrible . . .

radiant meteor
#

the more i wrote that the more i'm convincing myself to separate it in scripts

cosmic dagger
radiant meteor
#

i just felt it was more convenient since they share some variables and i dont want my inspector to be a pile of scripts

cosmic dagger
#

this makes it easier to add scripts onto GameObjects to build a player, enemy, or npc. what if you want movement but no jumping?

radiant meteor
#

also, didnt seem like things i'd re-use for other gameobjects, just the player

#

that is a good point

#

it's a lot easier to deactivate a certain mechanic

cosmic dagger
#

great for testing and bug fixing as well. only turn on the component you want to check . . .

radiant meteor
#

alright, you convinced me to spend the next half hour doing this

cosmic dagger
#

i just made a separate move and rotate script myself, for a player . . .

grand badger
#

ransomink surely not drunk? 😛

cosmic dagger
#

or another example: i have a gun with separate scripts for shoot, reload, fire mode. that way, i can choose what functionality i want for each gun, even automated turrets . . .

grand badger
#

I guess this goes along well when working with a designer that likes getting hands-on and experimenting in Unity

cosmic dagger
# grand badger 👀

i first used it in the longest script i've ever written: the Timer class i made into a package. to be honest, it's only that long because i created summaries for every single field, constructor, property, and method . . .

cosmic dagger
#

@grand badger here, you can see why there are so many lines. i made summaries so anyone using it will understand what everything does, as if i was releasing a package (asset) . . .

#

i done so many one-off projects or helped with certain mechanics, i've never really finished any concrete system or mechanic myself. now i have mind map of every system i'm working on and where i'm at to try and finish something . . .

peak python
grand badger
#

usually you'll want to be working with floats all along for more precise math, then use Vector3Int.RoundToInt(myVector3)

peak python
deft grail
#
var y = 1.6f / list.Count;
foreach(GameObject obj in list)
{
    obj.transform.position += new Vector3(0, y, 0);
    yield return new WaitForSeconds(0.2f);
}
``` if the y position starts at `0.4`, should this end at `2`? because it ends at 3.6 for some reason
#

y is 0.08 so that x 20 would be 1.6, so not sure why this doesnt work

cosmic dagger
#

we don't know what Count is . . .

deft grail
grand badger
deft grail
rocky canyon
grand badger
deft grail
#

thats inside the foreach statement

grand badger
#

the code is saying that you're increasing y of a bunch of objs

cosmic dagger
deft grail
rocky canyon
#

classic 🙂

grand badger
#

yeah that's totally not what you're doing here 😛

deft grail
rocky canyon
#

i thought we were witnessing some type of brain teaser

deft grail
#

but the one im increasing position of is at 0.4 and i want to increase it by 1.6

#

to make the total of 2

grand badger
#

show actual code that has the issue?

peak python
rocky canyon
#

need to make sure to run ur move logic in steps then

deft grail
# grand badger show actual code that has the issue?
    private IEnumerator Spin()
    {
        var y = 1.6f / weapons.Count;
        foreach(GameObject weapon in weapons)
        {
            Debug.Log(y);
            baseWeapon.transform.position += new Vector3(0, y, 0);
            yield return new WaitForSeconds(0.2f);
        }
        yield return null;
    }
peak python
rocky canyon
#

well i just mean.. its not ur typical.. bunch of move calls in update()

rocky canyon
grand badger
#

your code needs work though 😛 still badly written

deft grail
deft grail
grand badger
#

it's misleading again -- you're not using weapon at all besides its count

#

plus y is a misleading name by itself -- instead of yOffsetPerFrame or something

deft grail
#

so if theres 1 item or 15 or 100 i want it to increase by 1.6 anyway

grand badger
#
var yOffsetPerIter = 1.6f / weapons.Count;
for (int i = 0; i < weapons.Count; i++) {
    baseWeapon.transform.position += new Vector3(0, yOffsetPerIter, 0);
    yield return new WaitForSeconds(0.2f);   
}
peak python
grand badger
grand badger
#

yeah it's the same functionality,

deft grail
#

foreach is easier to use IMO

grand badger
#

it's misleading

deft grail
grand badger
#

if you want to use the foreach without having it be misleading, use foreach(var _ in weapons)

deft grail
grand badger
#

I told you -- it goes to 3.6 instead of 2 because you're calling the coroutine twice, in code you don't show us

deft grail
#
    private void Start()
    {
        StartCoroutine(Spin());
        Debug.Log("Starting");
    }
grand badger
#

are you adding and/or deleting stuff from weapons then

deft grail
eternal needle
#

just curious, why should that go to 2? you said the count was 20 i believe
1.6 / 20 added 20 times is just 1.6

deft grail
#

unless this code here is deleting/adding which i dont think it is

grand badger
#

try this instead:

var yOffsetPerIter = 1.6f / 20;
for (int i = 0; i < 20; i++) {
    baseWeapon.transform.position += new Vector3(0, yOffsetPerIter, 0);
    yield return new WaitForSeconds(0.2f);   
}
eternal needle
#

also you should add a debug in the coroutine to see when its started, not in start. not saying thats the issue though

deft grail
cosmic dagger
grand badger
#

inb4 its a child of another object that has scale 0.5

eternal needle
deft grail
#

ah

rocky canyon
#

i think he meant the parent

deft grail
#

the parent has a scale of 0.5 yes

rocky canyon
#

mmhmm

deft grail
#

making it 1 makes it work

grand badger
#

xD

deft grail
#

see i know my code works fine

rocky canyon
#

phew, my brain was starting to hurt just spectating

cosmic dagger
eternal needle
#

this is why its always said to not just read the values in inspector, its local values

radiant meteor
#

how do i make a variable that is checked and changed by multiple scripts?

deft grail
rocky canyon
grand badger
deft grail
#

i can code, but i cant unity 👍

grand badger
#

always approach from math standpoint

#

if you want 1.6 units in LOCAL scale, use transform.localPosition instead of transform.position

radiant meteor
eternal needle
deft grail
grand badger
#

that makes scale and potentially rotation be accounted for

deft grail
rocky canyon
summer stump
deft grail
grand badger
#

yeah. using local is the correct solution lol

summer stump
cosmic dagger
rocky canyon
#

precision offsets i bet

deft grail
summer stump
deft grail
summer stump
#

Ok. So the problem was that it didn't look good.
Got it

deft grail
#

and found a value i want

rocky canyon
#

the ole gizmo ruler

deft grail
#

now i gotta do the same thing for the time for the yield return 🤣

eternal needle
#

this just looks like you could use an animation

deft grail
eternal needle
#

it could be a frog jumping for all it matters. you've hardcoded moving an object with a coroutine when it could be an animation

#

which would give you way greater control too

deft grail
#

that does make sense 😂

#

then i would just need to code the actual changing of things in the list

eternal needle
#

i have no clue what the list was for, and you never really stated the true problem. You did say a few times that no matter what you just want it to go to 2 on the y axis. So i dont see why the list affects anything

cosmic dagger
eternal needle
#

the only thing thats affected i guess is how slowly it goes up. in which case you still could use an animation and set the speed accordingly. even at runtime

deft grail
cosmic dagger
#

if it travels from a to b, then it will go through every one in the list, no?

#

a = original position; b = a + 2 . . .

deft grail
eternal needle
#

right now all you have is an object that moves up by a hardcoded amount every 0.2 seconds which i really dont see why this 0.2 seconds is needed. It will look pretty jittery

#

basically an object moving at 5fps

deft grail
cosmic dagger
eternal needle
#

what id do, if you dont wanna use animations, is have a start and end point defined as their own gameobject. Or at least some way to visualize it in unity using 2 vector3's and gizmos. Define a float for how long the total movement should take
lerp between start point position and end point position at (currentTime / totalTime)

cosmic dagger
#

where did the weapon model changing come from?

deft grail
cosmic dagger
#

exactly, use two empty GameObjects (or Vector3) fields for the start and end position. another field for the duration. then use a coroutine to lerp using all three fields . . .

deft grail
#

yes my IDE is finally configured.
at the expense of half my C drive storage

peak python
#

@rocky canyon it works now
with delay it looks even nicer 🙂

radiant meteor
#

ok, so i made a get; set; for a private variable in one script and i want to use it in a different script, i reference it in Awake/Start to a variable of the same type in another script and anytime i check it, it will be updated based on that private variable, and if i change it, it will update that private variable, right?

peak python
#

also extracted the actual tile movement, cuz idk if i can adjust positions in the list during iteration through the list in c#
since moving tiles technically shall change positions

radiant meteor
#

basically turned both into the "same" variable, right?

deft grail
#

and in your other script you can just reference the public one

#
    private int something;
    public int Something{
        get {
            return something;
        }

        set {
            something = value;
        }
    }
radiant meteor
#

yeah, i meant "that private variable" as in the variable the get set variable is getting

deft grail
#

and returns you the private one when you try to access the public one

grand badger
grand badger
cosmic dagger
grand badger
#

that means that no matter what changes you do to the smth variable, someObj.someStruct will not be changed

radiant meteor
#

i was mainly trying to make multiple scripts have the """same""" variable so i dont have to say "GetComponent<Script>().variable" whenever i wanted to change or get that variable

grand badger
#

I'd go with the [field: SerializeField] public MyClass field { get; private set; } case then

#

accessibility modifiers is not really a beginner topic so for now there's nothing wrong with just a public field if you're just starting (e.g.: public MyClass field;)

ivory bobcat
radiant meteor
# deft grail ```cs private int something; public int Something{ get { ...

i'm confused, if this for example, "if (!MyBool)" checks "_myBool" which is in another script, and "MyBool = true" sets "_myBool", again, from another script, into true, then why not use this instead of having to reference the script in question every time i want to check/change "_myBool"? if this works the way i think it does, i only need to reference it once in start or awake

grand badger
#

@radiant meteor also just to make sure you're aware of static variables:

public class Settings : MonoBehaviour {
    public int volume;

    public static Settings instance { get; private set; }
    void Awake() => instance = this;
}
```..here you can access the volume from any script via `Settings.instance.volume`
#

Similarly with:

public class Settings : MonoBehaviour {
    [SerializeField] int volume;

    public static int Volume => instance.volume;

    static Settings instance { get; set; }
    void Awake() => instance = this;
}
```..here you can access the volume from any script via `Settings.Volume`
#

typically allowing other scripts (/users) to change a variable that could potentially affect multiple systems is a no-no

cosmic dagger
#

isn't that the first thing you learn along with classes, fields, methods, etc.?

grand badger
#

yeah, as in I would allow my beginner mentee/student to just use public for everything instead of narrowing scope with { get; private set; }

#

then 2-4 weeks in I'd slap in a long-ass refactoring assignment to make everything accessible only to minimum-required scope 😆

grand badger
cosmic dagger
grand badger
#

there's also the possibility that my teaching priorities might be just weird 😛 Imagine I 100% absolutely always start with teaching about how variables translate to RAM blocks

native thorn
#

Is there an easy way to understand how world maps are usually done

grand badger
#

easiest way to understand how they can be done is to try making one and see what works 😛

#

how they're usually done is quite vague

native thorn
#

I'm not all that far into my world map yet

#

Sorry, I more so ment the logic behind translating locations and player position into map UI icons

#

This is done with world to screen point right?

cosmic dagger
grand badger
#

oh yeah my var --> RAM lesson also intends to teach the stack and the heap 😄

#

nice to hear there's at least someone else who finds that absolutely fundamental

cosmic dagger
#

well, the stack vs heap convo would lead into reference types and value types . . .

grand badger
#

Ah. Then it's a very complex task. Might wanna look into the following concepts little by little:

  • Fade in/out (e.g.: Loading screens)
  • Scriptable Objects (e.g.: EntryPoint if you wanna add scene changing like entering buildings)
  • Callbacks (e.g.: OnSceneChanged --> TeleportPlayer(EntryPoint))
  • Minimap (e.g.: Projecting a 2D icon for a 3D Object over a 2D-projected 3D world)
#

Mind though that making a minimap is quite a complex task. Since you're asking in #💻┃code-beginner, I'm inclined to recommend skipping it and going with fake world map + transitions

#

High-quality world maps (like WoW's) are essentially fully-expanded minimaps.

cosmic dagger
#

whoa, it disappeared . . . 😲

solemn fractal
#

Hey guys.. Is there a way to show the value of a variable in the inspector but in a way I cant change it? Like just readonly? So I dont have to use Debuglog to see if the value is changing?

cosmic dagger
#

the quickest way is to switch the inspector to Debug mode. it will display private variables for you . . .

solemn fractal
#

how do I do that?

cosmic dagger
#

click the three vertical dots on the side of the Inspector tab and select 'Debug' during gameplay to show private fields . . .

#

it's right next to (after) the lock icon . . .