#💻┃code-beginner

1 messages · Page 45 of 1

uncut dune
#

I never tried it

#

Idk

weary crystal
#

Done. So if I build, will they be able to install like an Android apk file?

ivory bobcat
weary crystal
# ivory bobcat

It's a different question... Not related to the one I asked before...?

uncut dune
#

its in the wrong channel tho

gaunt ice
#

i think you need mac to build it

weary crystal
ivory bobcat
weary crystal
zenith cypress
#

So ask then wait? Inactivity doesn't dictate using other channels for unrelated questions. This isn't a coding question.

weary crystal
#

Got it, thank you and I'm sorry.

ivory bobcat
swift stag
#

Turns out I do have assets that need URP lol, but thanks

silent obsidian
#

I'm trying to animate my player, i've added some checks for the character's movement state (if he is running or jumping). I got the jumping animation right but the character keeps running even if in theory should not pass the checks.

Am I missing something here? I am sure the problem has to do with the timing of the code execution but I can't seem to be able to find a solution on my own.

void Update() {
        hzInput = Input.GetAxis("Horizontal");
        if (Input.GetKeyDown(KeyCode.Space)) {
            jumpKeyWasPressed = true;
        }
    }

    private void FixedUpdate() {
        Move();
        Rotate();
        CheckGrounded();
        CheckRunning();
        AnimationBrain();
        if (jumpKeyWasPressed && isGrounded)
        {
            Jump();
            jumpKeyWasPressed = false;
        }
    }

     private void CheckGrounded() {
        isGrounded = Physics.CheckSphere(groundCheckTransform.position, 0.15f, groundMask);
    }

// Player should be able to play the running animation only if he has velocity on the X axis and he is grounded
    private void CheckRunning() {
        isRunning = rb.velocity.x != 0f && isGrounded;
    }


    private void AnimationBrain() {
        // Jump animation brain
        if (isGrounded) {
            animator.SetBool("isJumping", false);
        } else {
            animator.SetBool("isJumping", true);
        }

        // Running animation brain
        if (isRunning) {
            animator.SetBool("isRunning", isRunning);
            Debug.Log("Rb.velocity.x: " + rb.velocity.x);
            Debug.Log("isGrounded: " + isGrounded);
        }
    }
uncut dune
#

how do I put a layer in my script without having to create a field for it

#

can I just do "LayerName"?

polar acorn
#

So once you're running once, the animator's parameter is always true

polar acorn
eager elm
polar acorn
#

These are all different things

uncut dune
silent obsidian
polar acorn
#

But you only ever set it in the animator when that bool is true

#

The animator's parameter is never set to false

uncut dune
#

something like this works?

silent obsidian
#

Ohhhhh okey i see. thank you a lot

unreal phoenix
#

if I add 'vector.x' to the the Y component of that vector that I'm adding, the Z value is getting affected somehow

    private void MoveCamera(InputAction.CallbackContext context) {
        var vector = context.ReadValue<Vector2>();
        var cameraRotation = cameraObject.transform.localRotation;
        var quaternion = new Quaternion {
            eulerAngles = cameraRotation.eulerAngles + new Vector3(vector.y * -1, 0, 0) * 0.1f
        };
        cameraObject.transform.localRotation = quaternion;

    }
polar acorn
#

You should never expect that getting the .eulerAngles of a rotation follows any sort of rules. It doesn't have any sort of "memory". If you apply a rotation on one axis, all it's going to know is the result. When you do .eulerAngles it's going to return whatever Vector3 represents that orientation it happens to compute first

unreal phoenix
#

Ah

heady nimbus
#

Just to confirm, if I have a prefab, I can't reference something in the scene to that prefab until that prefab exists in the scene right? (holy hell I'm not even sure that made sense to me...)

quiet dune
#

I have a question about understanding the connection between a game object (go1) and attached scripts (sc1): If i set a variable of type sc1 in a random script, can i drag any game objects that have sc1 attached to it into the variables field in the unity editor?

polar acorn
heady nimbus
silent obsidian
unreal phoenix
#

This works perfectly

    private void MoveCamera(InputAction.CallbackContext context) {
        var vector = context.ReadValue<Vector2>();
        cameraObject.transform.localEulerAngles += new Vector3(vector.y * -1, vector.x, 0) * 0.1f;
    }
signal tide
#

Can anyone help me configuring me IDE I am not able to do it. Does anyone know any tutorial or some video??

heady nimbus
#

!ide

eternal falconBOT
signal tide
subtle veldt
#

Is there a way to have a 2D joint with constant pulling force and affected by gravity ?
I tried with the Spring Joint 2D but the force is proportional to the distance of the 2 Rigid Bodies.
I also tried with a Distance Joint 2D but I cannot control the pulling force and it seems to change the gravity a bit because the object I've attached to it is slowed down although it's going into the same direction as the pulling of the Distance Joint 2D.

subtle yacht
#

Hi, i have a little problem on my project. I'm sure it's very easy but i don't know how to do it x)
I have this Sound and I want to drag it into a component in my player.
But when i'm going in my Player to acces my component, the hierarchy changes and i can't access my sound anymore.
Can someone know how to do it ?
(Sorry for my english)

slender nymph
subtle yacht
#

Oh okay so i need to create my Sound into my player ?

slender nymph
#

or you just need to pass it to the player when the player is spawned

subtle yacht
dawn sparrow
#

I know this isn't coding but not sure where else to ask:

I have a model which uses a texture with transparent pixels (area not circled in red), but when I tick "Alpha is Transparency" after converting the texture to a sprite, I get the second image, where the previously uncircled areas just seem to randomly sample a non-transparent part of the texture. Anyone know why this happens?

buoyant knot
hidden bone
#

What would be a simple code for changing a Text Gameobject to whatever is in a txt file? i have gotten explanations before but i still cant get it to work

polar acorn
twin bolt
#

I'm using Ontriggerenter, for a script that forces the player to crouch while inside of a trigger, but if the players collider, even somewhat exits the trigger, the function is called. How do i make it so that the function is only called when the player is fully in or fully out of the trigger?

hidden bone
#

How do i convert a string to a gameobject? I get this error when trying mygameobject = mystring, the gameobject being the Text Gameobject and the string being the data retrieved from the txt file

#

trying to put the string into this

eternal needle
polar acorn
#

Strings are not game objects and "converting" one to the other is patently absurd

hidden bone
#

ok, how should I do it then?

polar acorn
#

Setting a gameobject to a string makes no sense

eternal needle
#

You want to first get a reference to the Text component instead of the gameobject, then assign its .text field to your string

hidden bone
#

I want to get text from a .txt file and make this text object display the text from the .txt file

eternal needle
#

You probably want to use text mesh pro instead also

polar acorn
hidden bone
#

yes

polar acorn
#

I told you how to do that

hidden bone
#

i must have not understood

polar acorn
hidden bone
#

yeah i have seen that

#

i have a string

#

i just dont know how to put that in the text component of the gameobject

polar acorn
hidden bone
#

how?

polar acorn
#

using =

hidden bone
#

thegameobject = thestring.text?

#

thats the only thing I can think of

polar acorn
#

No

#

You're setting .text to something

#

not setting an object to something's .text

twin bolt
#

How could i go by forcing the player to be unable to uncrouch, when there inside of something that is to small to stand up in?

polar acorn
#

And strings don't have a .text property

hidden bone
#

public GameObject TheText;so turn this into text instead of gameobject?

polar acorn
#

Or spherecast, or boxcast, or whatever shape fits your character

twin bolt
polar acorn
polar acorn
hidden bone
#

im not getting any compiling errors but nothing seems to be happening

bitter carbon
#

hey, is there a simpler way of writing this:

also, si this correct

polar acorn
#

Well, actually

#

there is

bitter carbon
polar acorn
#

playerZ == 5

hidden bone
bitter carbon
polar acorn
bitter carbon
#

whats modulo

spiral oak
polar acorn
spiral oak
polar acorn
# hidden bone https://pastebin.com/ve4PpEJn
  1. You're getting the Text component from itself. You have the component already. You don't need to get it again.
  2. You immediately overwrite the text again with the file name of the object you're opening
  3. Does the log print anything?
hidden bone
#

yeah it logs

polar acorn
bitter carbon
#

so this better?

spiral oak
hidden bone
#

oh

bitter carbon
#

i remeber using in python i just sorta forgot what it did exactly but ik now

spiral oak
bitter carbon
hidden bone
polar acorn
bitter carbon
#

will the z go to 5 ever or will it just go to only floats as i need it to detect when 5 happens

polar acorn
bitter carbon
#

as the player is running i mean)

polar acorn
twin bolt
polar acorn
#

5.00000001 % 5 is not 0

bitter carbon
twin bolt
hidden bone
polar acorn
hidden bone
#

ok

polar acorn
twin bolt
bitter carbon
#

anyone know the word for like rounding in c# so i can search in unity api website

bitter carbon
#

that doesnt work

#

when i search it

polar acorn
bitter carbon
#

oh i just went to unity API website

unkempt locust
#

Guys, I wanted to know, how can I improve my programming knowledge, I wanted to make a boss batte, can anyone help me?

hidden bone
#

Im getting compiling error "Access to the path '...' is denied

polar acorn
hidden bone
#

fixed it, i forgot to add the .txt

upper yoke
#

Hey I think I already asked but what is the best way to do that without pattern matching in a MonoBehavior again?

short hazel
#
if (a == null || b == null)
    return false;

return a.Name == b.Name;
upper yoke
#

using == would recursively call the current method

short hazel
#

You can't, then

upper yoke
#

👀

#

Unity throw exceptions because of this :(

ripe shard
short hazel
#

I'd implement the standard IEquatable<EffectInfo> interface

#

And use Equals

cosmic dagger
#

use the Equals overload . . .

#

damn, late . . .

upper yoke
#

My Equals call == but I guess it shouldn't then

ripe shard
#

equals should check reference equality

#

not value equality

hidden bone
#
        TheText.text = readText;
        Debug.Log(readText);
        TheText.text = readText;``` the program successfully logs the contents of the .txt file but the Text component is not changing to the contents of the .txt file. im not getting any compiling errors
polar acorn
hidden bone
#

oh thats a typo i forgot to remove the bottom one

upper yoke
# ripe shard not value equality

I'm don't really know much about this but example in the documentation seems to say the opposite, would you have example on how to implement it?

hidden bone
#

i assigned TheText to this Text gameobject

polar acorn
ripe shard
hidden bone
polar acorn
# hidden bone

Okay, now show the same screenshot but after hitting play

upper yoke
hidden bone
polar acorn
#

Oh, wait, this is an input field

#

you haven't changed the value of the input field, so it's overwriting the text

#

It sets the text to whatever the value of the input field is, so it can be typed into and show up on the screen

#

Change .text on the InputField, not the Text component

short hazel
hidden bone
#

so public InputField inputfield; inputfield.text = readText;?

polar acorn
#

yes

#

except use the correct type

#

Wait nevermind

short hazel
polar acorn
#

ignore me

#

that's the wrong link

#

it is InputField

hidden bone
#

thx for all the help, it works

polar acorn
#

It's been so long since I've used non TMP, it just looked wrong to me but that's my bad

hidden bone
#

also sry for being so slow and bad

junior seal
#

if anyone could help that would be great

#

So im trying to make a project in Unity using assets from the unity store and included were some sliding doors that had code along with it. Im trying to make that code work with my player object but im having a hard time understanding what the code is doing. Code: https://paste.ofcode.org/NuPjadE2j8x3FW3RBVvHwh

silk night
junior seal
#

and I dont understand what its doing or what i need to do to make it work

silk night
#

Does your character have a Rigidbody?

junior seal
#

no but it has a collider

silk night
#

To trigger a trigger you need a rigidbody on one of the objects

#

preferably the player

junior seal
#

i do? can you explain why? im quite new

polar acorn
#

Rigidbody is literally the thing that calls OnTrigger

silk night
junior seal
#

okay so how exactly would i set up the rigidbody? i just kinda added it and pressed play and it went crazy

silk night
#

turn kinematic on

junior seal
#

ah okay cool!

#

Okay so i did all that and the doors still arent opening when the player gets close

silk night
#

what layer does your character have?

junior seal
#

characters

silk night
#

with a capital C?

junior seal
#

yes

harsh owl
#
 if (Input.GetKey(KeyCode.A))
 {

     Vector3 currentSteeringAngle = tireTransformLeft.localEulerAngles;
     currentSteeringAngle.y = Mathf.Clamp(currentSteeringAngle.y, -45, 45);


     if (currentSteeringAngle.y < maxSteeringAngle)
     {
         float rotationAmount = -steeringSpeed;
         Quaternion newRotation = Quaternion.Euler(currentSteeringAngle);

         tireTransformRight.rotation *= Quaternion.Euler(0, rotationAmount, 0);
         tireTransformLeft.rotation *= Quaternion.Euler(0, rotationAmount, 0);


         Vector3 clampedRotationL = tireTransformLeft.localEulerAngles;
         Vector3 clampedRotationR = tireTransformRight.localEulerAngles;

         clampedRotationL.y = Mathf.Clamp(clampedRotationL.y, -45, 45);
         tireTransformLeft.localEulerAngles = clampedRotationL;

         clampedRotationR.y = Mathf.Clamp(clampedRotationR.y, -45, 45);
         tireTransformRight.localEulerAngles = clampedRotationR;
     }
 }
 else if (Input.GetKey(KeyCode.D))
 {

     Vector3 currentSteeringAngle = tireTransformLeft.localEulerAngles;
     currentSteeringAngle.y = Mathf.Clamp(currentSteeringAngle.y, -45, 45);


     if (currentSteeringAngle.y < maxSteeringAngle)
     {
         float rotationAmount = steeringSpeed;
         Quaternion newRotation = Quaternion.Euler(currentSteeringAngle);

         tireTransformRight.rotation *= Quaternion.Euler(0, rotationAmount, 0);
         tireTransformLeft.rotation *= Quaternion.Euler(0, rotationAmount, 0); //


         Vector3 clampedRotationL = tireTransformLeft.localEulerAngles;
         Vector3 clampedRotationR = tireTransformRight.localEulerAngles;

         clampedRotationL.y = Mathf.Clamp(clampedRotationL.y, -45, 45);
         tireTransformLeft.localEulerAngles = clampedRotationL;

         clampedRotationR.y = Mathf.Clamp(clampedRotationR.y, -45, 45);
         tireTransformRight.localEulerAngles = clampedRotationR;

     }
 }



silk night
#

can you add a Debug.Log("test") in OnTriggerEnter to check if it even triggers at all? Like first line of that function

junior seal
#

yea sure

slender nymph
harsh owl
#

why it working for steering right tho

#

i can steer left and right like i want to, but just between 0 and 45

#

but not between -45 and 0

junior seal
polar acorn
silk night
junior seal
#

it does not

#

the console in unity right?

silk night
#

yes

junior seal
#

then no it doesnt

silk night
#

Can you show me a screenshot of your character inspector with all components?

junior seal
#

yes!

slender sinew
#

in the inspector, the eulerAngles are able to go negative

harsh owl
#

yea i figured that out now

slender nymph
#

it's almost like someone warned you not to rely on eulerAngles for this exact reason

slender sinew
#

if you want to do what you are doing, you should create your own variables to keep track of the angle

junior seal
#

@silk night

slender sinew
#

then just set the eulerAngles equal to your custom values at the end

silk night
junior seal
#

the character controller and the script. you want to see the code?

silk night
#

yeah, ill test something, give me a minute 😄

junior seal
#
using System.Collections.Generic;
using UnityEngine;

public class characterController : MonoBehaviour
{
    [Header("----- Components -----")]
    [SerializeField] CharacterController controller;

    [Header("----- Player Stats -----")]
    [Range(-10, -40)][SerializeField] float gravityValue;
    [Range(2, 8)][SerializeField] float playerSpeed;

    private Vector3 move;
    private Vector3 playerVelocity;

    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        move = Input.GetAxis("Horizontal") * transform.right +
              Input.GetAxis("Vertical") * transform.forward;
        controller.Move(move * Time.deltaTime * playerSpeed);

        playerVelocity.y += gravityValue * Time.deltaTime;
        controller.Move(playerVelocity * Time.deltaTime);
    }
}```
silk night
#

Ok, can you show me a screenshot of your door too?

silk night
junior seal
#

oh okay

twin bolt
#

I have a structure in my scene that causes a decrease in performance even when culled, or not being looked at, mostly because of the lights. I want to use ontriggerenter and exit to disable it, when in a area that you cant see it in. My problem is that the structure isnt just a square or rectangle, meaning i need to use multiple colliders, but that wont work since multiple colliders on one object, doesn't work all as one big collider. how do i fix this?

silk night
#

OnTriggerEnter should bubble up in the hierarchy

twin bolt
silk night
#

It wll trigger a OnTriggerEnter on the child, if your child does not catch that event it should bubble to the parent

cosmic dagger
unkempt locust
#

I have one question

#

How do I improve my knowledge of Unity programming?

polar acorn
silk night
#

and dont start too big

unkempt locust
#

Yes, but for example, now I wanted to do a boss battle, but I don't know how to do it, I tried looking on YouTube and I couldn't find any that were in 3D

unkempt locust
silk night
junior seal
unkempt locust
#

Yes, thank you

cosmic dagger
polar acorn
silk night
unkempt locust
junior seal
cosmic dagger
unkempt locust
#

I have a certain fear of not getting a Game Developer job.

silk night
junior seal
#

hek. I dunno what im doing wrong

silk night
junior seal
silk night
#

also just to test, create a cube, set its collider to trigger and add following script:

using UnityEngine;

public class Testscript : MonoBehaviour
{
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("test");
    }
}
#

then walk into it with your player

junior seal
#

i dunno if im doing it right lol

silk night
#

OHHH

#

your collider is not a trigger 😄

#

or is the trigger somewhere in the children?

junior seal
#

OHHHHHHH do i need to do that with the player one too??

silk night
#

No, the one that should trigger your door when you step in it, needs to have "is trigger" checked

cosmic dagger
# unkempt locust yes, I program every day in unity

typically, you improve as you create different mechanics and refactor old code based on new things you learned. a great practice is answering others' questions here or online in the forums/discussions . . .

silk night
#

trigger = does not block walking into it, just triggers OnTriggerEnter
no trigger = blocks walking into it, does OnCollisionEnter instead of OnTriggerEnter

junior seal
#

okay so my capsule needs to have Is Trigger activated?

silk night
#

Not your player

#

the door needs to have a trigger somewhere you can step in

junior seal
#

okay so how do i do that?

silk night
#

does your door have any children?

junior seal
#

no

#

should it?

silk night
#

Then add an empty child

#

and add the box collider component

silk night
#

size it to the area you want the door to open, and set trigger to true

unkempt locust
#

But lately my fear is not getting a job

cosmic dagger
junior seal
#

so that i dont have to add 2 empty children?

unkempt locust
twin bolt
eternal needle
silk night
unkempt locust
junior seal
#

no? they dont have parents they are just their own objects

cosmic dagger
twin bolt
eternal needle
polar acorn
unkempt locust
silk night
summer stump
unkempt locust
summer stump
#

There is no off-topic for the whole server.

I'm sure there ARE servers that could give you an estimate. But it would depend on so many things. The first question would be a WIDE range, and the earnings would almost definitely not be weekly

junior seal
silk night
junior seal
#

oh sure

silk night
#

maybe the doors just dont move or something

junior seal
#

nothing

silk night
#

so you have a child that has a trigger box collider?

summer stump
# junior seal nothing

This is an OnTrigger not working?
As told by Digiholic:
The Three Commandments of OnTriggerEnter:

  1. Thou Shalt have a 3D Collider on each object
  2. Thou Shalt tick isTrigger on at least one of them
  3. Thou Shalt have a 3D Rigidbody on at least one of them
summer stump
silk night
summer stump
#

Is the issue that you are not receiving an OnTriggerEnter message?

#

If so, those are the three main rules for getting it

junior seal
#

so news, as soon as i pressed play, it activated and lifted itself on the y axis into the sky, and then i got the test message, but i wasnt even near the door

#

but they opened

silk night
#

Oh yeah, the doors themselves trigger the trigger 😄

summer stump
junior seal
#

i didnt like, set them to trigger tho

silk night
#

Oh yeah, wait it checks for the layer

junior seal
summer stump
#

There are NO triggers touching the doors? OnTrigger is sent to both of the colliding objects. So maybe it's from something else?

junior seal
#

exactly?

summer stump
summer stump
silk night
#

with that you can find out what triggers it

junior seal
#

like theres not triggers on the doors-

silk night
#

But there is colliders on the door

#

that touch your trigger

junior seal
#

okay so you want me to debug.log on what?

silk night
#

in the OnTriggerEnter

#

do Debug.Log(other.name)

junior seal
#

ah okay

#

its my doorway

silk night
#

Did you write the layer check yourself?

#

or was it in the asset?

#

this line: if (other.GetComponent<Collider>().gameObject.layer == LayerMask.NameToLayer ("Characters")) {

junior seal
#

it was in the asset

#

so its getting the collider from the door frame?

silk night
#

Yes

junior seal
#

so do i need to remove the door frame collider?

#

or just add the box collider to the doorframe?

silk night
#
    void OnTriggerEnter(Collider other) {
        if (other.GetComponent<Collider>().gameObject.layer != LayerMask.NameToLayer ("Characters")) return;

        if (status != DoubleSlidingDoorStatus.Animating) {
            if (status == DoubleSlidingDoorStatus.Closed) {
                StartCoroutine ("OpenDoors");
            }
        }

        objectsOnDoorArea++;
    }
#

try with this

junior seal
#

it works sorta

#

like if my player moves towards it, the doors open and close and such, but they moved to rise in the air again

unborn veldt
#

How's that possible guys?

#

the main thread, with an async function, is blocked for 90% of the time just waiting

silk night
unborn veldt
junior seal
#

this is before

#

this is after

unborn veldt
#

Called there (that's a thread created by me)

silk night
unborn veldt
junior seal
silk night
#

you move the doors to 0, 0, 0 inside the parent

#

then move the parent around

junior seal
#

the parent is the script

silk night
#

yeah, if you type 0, 0, 0 they will be on the same position as the parent

junior seal
#

they move tho

silent obsidian
#

How can I listen for an input inside an OnTriggerStay?

 private void Update() {
        if (Input.GetMouseButtonDown(0)) {
            isMouse1Pressed = true;
        } else {
            isMouse1Pressed = false;
        }
    }

  
    private void OnTriggerStay(Collider other) {
        if (other.gameObject.layer == 8) {
                Debug.Log("i'm in first if");
            if (isMouse1Pressed) {
                Debug.Log("i'm in 2nd if");
            //     player.DamageObject(other);
            }
        }
    }

If i left click it never gets to the 2nd debug.log.

junior seal
#

i made it 0, 0, 0

#

and it moved into the sky

silk night
junior seal
#

OHH

#

okay yea they stay in place, but now they move forward and backward instead of in and out

short hazel
junior seal
#

for example

short hazel
#

at 60 fps

silk night
junior seal
#

nope

silk night
#

in the screenshot the x axis is rotated

#

0 it again and rotate the parent

junior seal
#

if i do that, the door will be flat instead of up and down. thats the way the asset is for some reason. everything that is vertical has that x rotation

silk night
#

alright, then make it flat 90 atleast

junior seal
#

okay

silk night
#

one min, ill change something in the script for you again

#
        leftDoorClosedPosition    = new Vector3 (0f, 0f, 0f);
        leftDoorOpenPosition    = new Vector3 (slideDistance, 0f, 0f);

        rightDoorClosedPosition    = new Vector3 (0f, 0f, 0f);
        rightDoorOpenPosition    = new Vector3 (-slideDistance, 0f, 0f);
junior seal
#

now they go inside of eachother

#

this is so weird-

silk night
#

switch the - slideDistance

#

add one at the top, remove it at the bottom

junior seal
#

THANK YOU

#

holy hek

silk night
#

And remember, dont drag the doors, only the parent, or you will have the same problems 😄

junior seal
#

thank you so much for the advice. this helped sooo much

silent obsidian
twin bolt
fair steeple
#

Evening. I'm getting these errors when trying to build my game. No idea how to fix them.

swift crag
twin bolt
swift crag
#

All code that references UnityEditor must not make it into a build. That namespace does not exist in builds.

#

In this case, "GUITools" sounds like something that's editor-only anyway

#

Any folder named "Editor" will be excluded from builds

polar acorn
swift crag
#

You can also use #if UNITY_EDITOR to conditionally exclude chunks of code, if you need more fine-grained control

swift crag
#

note that smooth damp never quite reaches the destination. I often combine both MoveTowards and SmoothDamp

fair steeple
#

Like, I should move all the with "using UnityEditor" to Editor?

fair steeple
#

fuck I have like 30 files lol

twin bolt
swift crag
#

i kinda wish you could just do transform.localScale.MoveTowards(...)

#

but, alas, struct returned from a property...

#

I set target in the if/else if/else statements, then just move towards the target unconditionally.

twin bolt
#

I'm setting my own values, so it keeps saying "cannot convert from floaat to Vector3"

swift crag
#

you could always do it inline, but it'll get ugly

#
transform.localScale = Vector3.MoveTowards(transform.localScale, new Vector3(1, whatever, 1), Time.deltaTime);
swift crag
#

I'd be repeating myself if I included the MoveTowards in every single branch, after all

#

MoveTowards is very reliable. It will exactly reach the target if you're close enough

#

I confidently do stuff like this all the time

#
thing = Mathf.MoveTowards(thing, 1, Time.deltaTime);

if (thing == 1) {
  ...
}
#

No wiggle room required. MoveTowards methods return their second argument if the first argument is close enough to it

#

SmoothDamp never quite reaches the target

twin bolt
#

Now it doesnt fully crouch, it goes down like half an inch.

twin bolt
fair steeple
#

Hey, I tried moving the files over to a Editor folder and now the game is broken and I can't just drag all the files over to their Game Object. Can I make Unity find those files or is there another way to build the game?

wintry quarry
#

that's the only one you need to move

#

oh and your AUdioManager you need to just remove the editor stuff from

#

or wrap it in a preprocessor directive

swift crag
swift crag
# twin bolt Would animation work?

Sure, but I prefer to use code, not animation. Notably, animators will always write values to every field they control, even if you're not currently playing an animation that controls that field

#

So they can be very heavy-handed

swift crag
#

You should be running MoveTowards every frame

#

All of the Vector3 methods just take some inputs and produce a result. You aren't starting a coroutine or something here

twin bolt
swift crag
#

You would set a target value in Crouch

twin bolt
#

Do i enable a bool when the player presses a key?

swift crag
#

then use that target value in Update

#

Or you could do that, yes

#

You could set a crouched bool, then use it to decide what to move towards in Update

twin bolt
#

Then have it keep going until the height equals what i want?

swift crag
#

You can just do it forever

#

But yes, that's what'll happen

#
void Update() {
  var bar = toggled ? Vector3.one : Vector3.zero;
  foo = Vector3.MoveTowards(foo, bar, Time.deltaTime);
}

void Toggle() {
  toggled = !toggled;
}
#

If you want to be able to just set the value once and have it work automatically, then you need something like DOTween, which handles all of that for you

#

I've always just done things myself.

silent obsidian
#

How do you guys handle the logic for health/attack systems where there are multiple types of enemies? Should I just create a base class like "CombatEntity" where i can store all the shared methods and properties?

swift crag
#

that's a common approach if everyone works roughly the same

#

you can also go with interfaces, e.g. Damageable

cosmic dagger
silent obsidian
#

Yes

swift crag
#

that interface would contain a TakeDamage metho

cosmic dagger
hoary citrus
cosmic dagger
silent obsidian
#

Correct me if I'm wrong please, I'm not really familiar with strong typed languages. That approach would allow to handle modifiers? For example if one type of enemy is rather a prick and requires different/more properties and methods than the base class can provide?

timber tide
swift crag
#

or go with composition

#

Composition is often the better approach.

#

For example, you could give each entity a list of damage modifiers

#

a damage modifier would be an object that you hand a damage instance to, and get a new damage instance back

#

so you could slap a 50% damage reduction on an enemy by just adding an object to that modifier list

#

I've been building games recently by making a very bare-bones Entity class, then adding features through composition

timber tide
#

Ye, OOP is kinda hard for this type of stuff

swift crag
#

an entity gets a Grabbable component if it can be grabbed by a larger entity

#

for example

timber tide
#

because you can dig yourself a hole pretty easily if you thin out the classes

silent obsidian
#

Composition in this case refers to @hoary citrus's proposal?

swift crag
#

Yes -- it's where you combine things

#

rather than inheritance, where you make a more specific version of an existing thing

swift crag
#

MoveTowards is going to return a vector that's a little bit closer to the target value

#

You have to do that over and over to reach the target

swift crag
#

Every "thing" in your game is a GameObject with components on it

swift crag
#

It moves towards that target every frame

#

I don't bother trying to "stop" the movement when you reach the destination. x = MoveTowards(x, 1, Time.deltaTime); simply does nothing if x already has a value of 1.

twin bolt
swift crag
#

Right. It now moves towards the crouched scale every frame as long as Crouching is true

#

You will also want to move towards the uncrouched scale every frame when Crouching is false

swift crag
twin bolt
swift crag
#

Sure. You aren't moving towards the standing scale.

#

You're just setting it, presumably

#

There is no "magic" here. The C# is doing exactly what you tell it to. If you want to smoothly approach a value, you must write code that smoothly approaches the value.

buoyant knot
#

you guys talking about a Grabbable component?

swift crag
#

i just mentioned the idea offhand

silent obsidian
# swift crag rather than inheritance, where you make a more specific version of an existing t...

As a webdev, the paradigm shift is rather confusing. Thank you a lot guys, but just to make sure.

Let's say that I have a Player and multiple types of enemies.
The recommended approach (composition?) would be to have multiple scripts that I can attach to those entities? such as:
HealthManager
MovementController
but if i want to add an item pickup system to the player and to one specific type of enemy I would only attach that script to the player and to that specific enemy type?

swift crag
#

Right.

#

I might do something like this

#
public class Entity : MonoBehaviour {
  public Brain brain;
  public Locomotion locomotion;
}
#

the Brain's job is to respond to questions, like "Which way do you want to move?"

#

PlayerBrain uses inputs to answer those questions. EnemyBrain has some basic AI logic in it.

buoyant knot
#

I use a GrabbingHandler on something that grabs. it checks for being able to grab.

When an entity hits trigger, we look into its EntityDataHolder for a flag to see if it is grabbale.

If grabbing, it puts an EntityAttachmentHandler onto the thing we grabbed.

swift crag
#

then the Locomotion's job is to look at what the Brain wants and make it happen

#

Things can get messy super quickly, of course

#

You can have trouble with 'leaky abstractions'

buoyant knot
#

EntityAttachmentHandler is used for various types of attachements, and I use an interface: IEntityAttacher, so the EntityAttachmentHandler can communicate with the script being used to attach it

#

I hope this whole system makes sense

swift crag
#

You will need some time and practice to make sense of these ideas.

#

I have prototyped a lot of games.

#

And I'm still footgunning myself

buoyant knot
#

the better you get, the less inheritance you use. But then you reach a point where every time you use inherittance, it’s really good

swift crag
#

I've been using a ton of state machines recently

buoyant knot
#

better said; novices trap themselves into shitty unnecessary inheritance patterns more than they need to

swift crag
#
public class Flyer : Enemy { }
public class Shooter : Enemy { }
public class FlyingShooter : ??? { }
#

meanwhile, with composition

#

a Flyer is just an enemy that uses a flying locomotion

#

a Shooter is just an enemy with a ShootingBehaviour attached to it

static cedar
swift crag
#

and thus a FlyingShooter is an enemy with both

timber tide
# silent obsidian As a webdev, the paradigm shift is rather confusing. Thank you a lot guys, but j...

"but if i want to add an item pickup system to the player and to one specific type of enemy I would only attach that script to the player and to that specific enemy type?"
Another way instead of checking interface/components is to just use flags. I'm not that big of a fan of changing prefabs up and checking components between similar types. I rather just have all enemies drop items, but if an enemy has nothing in their loot table then they wouldn't drop anything anyway.

swift crag
#

I've written code where it casts the entity's brain to PlayerBrain and does some special stuff if that's the case

twin bolt
swift crag
static cedar
#

Stuff like that?

swift crag
#

AAAAAAA

#

you reminded me

#
[Serializable]
public class InventoryMeleeWeapon : InventoryItem
{
    public WeaponSpec spec;

    [JsonIgnore]
    public override ItemSpec Spec => spec;

    [JsonIgnore]
    public override bool Stackable => false;

    [JsonIgnore]
    public override int StackCount {
        get => throw new InvalidOperationException();
        set => throw new InvalidOperationException();
    }
...
twin bolt
static cedar
#

So far, I think I'm winging this fine. UnityChanThink

swift crag
static cedar
#

I never had a method that I need to inherit but don't wanna. Even if I did, I squashed those.

swift crag
#

If you're going from [1,1,1] to [1,0.7,1], a speed of 1 would make you crouch in 0.3 seconds

silent obsidian
#

And there lies my next question. If i have a weapon system in which each gun has the same properties but different values, are there other ways to set that up instead of creating a separate script for each gun type?

timber tide
#

Same idea

swift crag
#

Instead of having separate scripts, you just configure the values differently.

#

Two common ways to do this:

  • ScriptableObjects let you create assets that store data. You can then reference these assets.
  • [SerializeReference] lets you serialize a parent class, but then store any object that derives from the parent
swift crag
#
[CreateAssetMenu(menuName = "Item/Consumable Spec", fileName = "New Consumable")]
public class ConsumableSpec : ItemSpec
{
    public Consumable prefab;
    public int stackCount;

    [SerializeReference]
    public List<Effect> effects = new();
}

here's a nice terse example, actually.

timber tide
#

Composition is prone to edge cases, but trying to squash all the bad combinations is simply just testing what assets you're going to add and as the programmer, not make your weapons completely overpowered by shooting ricocheting explosive shotgun shells. (Actually that sounds pretty badass)

swift crag
#

Effect is an abstract class.

#
using UnityEngine;
using UnityEngine.Localization;

[System.Serializable]
public abstract class Effect : Animancer.IPolymorphic
{
    public abstract string Label { get; }
    public abstract string Description { get; }
    public abstract string Magnitude { get; }
    public abstract void Apply(Entity entity, float magnitude = 1f);
}
#

Each deriving class implements Apply in its own unique way

#

A healing item might thus be configured like this.

#

(yes, even my stats are, themselves, scriptable objects)

#

turtles all the way down, baby!

#

it can be kind of annoying if you can't be sure that every entity will even have a health stat

#

but it's also wildly flexible

#

You have to put your foot down at some point and add some constraints

#

The more you hard-code, the easier it is to reason about your game

#

but the less room you have to play around

silent obsidian
#

I'm a little bit sleep deprived. Am I correct if I see scriptableObjects as being fixed (I'm thinking fixed as in interfaces) containers which stores data? If so I think that's what I was looking for in regards to my weapon system.

static cedar
#

Me: broke down every part of my weapon system at every last bit. UnityChanwow

swift crag
#

I would not relate scriptable objects and interfaces

#

A scriptable object is just an object that you can store as an asset.

#

They work very well as data containers, though.

swift crag
#

and that they all have states for flinching

#

and I mandate that they all have humanoid IK. huh.

#

...I think I should refactor this...

#

me from 6 months ago was a real dingus

static cedar
#

I think ScriptableObjects are more like JSON with some QoL.

swift crag
#

but hey -- programming is an iterative process

timber tide
#

JSON with types

swift crag
#

you discover where you over-constrained and where you under-specified

#

and you make adjustments

#

one funny thing I've noticed is that I've used very similar architectures for vastly different games: a horror game, a platformer game, and a soulslike game

static cedar
# timber tide JSON with types

And automatically adapts to the layout of the script.
But does SO adapt when you change to a closely related type like int to long? Would that cause the stored data to default?

silent obsidian
#

@static cedar with that i can very well relate to huh blushie

swift crag
#

It's a serializable object. That's it.

timber tide
#

well, that's up to how unity serializes

swift crag
#

there's nothing really special there

#

that's the magic

#

I used to use SOs entirely for configuration data, but now I'm branching out

#

I'm currently using them for a settings system. I store the current setting value in a non serialized field (loading it in when the game boots up)

timber tide
#

I was actually using JS for webgl and hated the whole no type aspect of it all and then my friend told me im an idiot for just not using typescript

swift crag
#

Everyone who references the SO can see the value.

static cedar
#

I think TS is bulky.

swift crag
#

It is! It adds lots of constraints.

#

Adding static type checking will, by definition, make some programs impossible to express

silent obsidian
#

As I just started learning C# I am actually starting to appreciate strong typed languages more. Perhaps I should just start doing typescript aswell

swift crag
#

and make others very annoying to express

#

but, in return, you can reject many kinds of invalid programs

#

and also make it more clear what your valid programs do

#

I've written some big pages in both JS and TS

#

Coming back to an old JS project is miserable. Zero idea of what's going on.

static cedar
swift crag
#

It does feel pretty unique compared to a lot of other langs

silent obsidian
static cedar
#

And type checking is a pain or just weirder in TS and JS. UnityChanDown

opal fossil
#

how to move gameobject to the next steering location without them having the navmeshagent component?

swift crag
#

i don't know what a "next steering location" is

teal viper
opal fossil
opal fossil
teal viper
opal fossil
#

:/

#

ill give it ashot

teal viper
#

Generate the path with a navmesh agent, but don't let it control the movement. Instead move along the path manually with an rb.

opal fossil
swift crag
#

by just reading its desired velocity and using that to move the object

#

Although, I just realized that it would probably be more reliable to just look at its path and move the object accordingly

#

I'll have to play with that

opal fossil
swift crag
#

lmao

limber laurel
#

I'm currently using the following code to rotate my camera in LateUpdate, but it causes the camera to rotate faster sideways when looking up or down. I'm assuming it has something to do with using quaternion multiplication, does anybody know how I should fix this?

//Get mouse input
mInput = new Vector3(Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0);
//Multiply current rotatation by all the mouse input stuff
actualCamera.transform.rotation *= Quaternion.Euler(Input.GetAxis("Mouse Y") * Time.deltaTime * vertSens * -1f, mInput.y * Time.deltaTime * mouseSens, 0);
//Lock Z axis
actualCamera.transform.localEulerAngles = new Vector3(actualCamera.transform.localEulerAngles.x, actualCamera.transform.localEulerAngles.y, 0);
wintry quarry
#

The other problem is the use of reading back euler angles to try to lock the z axis

#

The typical foolproof approach is to use two separate objects. The parent object rotates on the y axis, the child (the camera) rotates on the local x axis only

opal fossil
limber laurel
#

Removing deltaTime definitely helps the camera feel less jittery, but doesn't fix the main issue

wintry quarry
#

although I don't see why the camera can't be a child of a Rigidbody

limber laurel
#

Cameras on rigidbodies always lead to some jitter when moving and rotating, and a couple of reddit/unity forum threads told me the best way to fix it was to separate the two and do things in lateupdate

junior seal
#

Hey! im trying to build a basic fps game. I have made the level and one of the things you have to do to get into another room is destroy some glass. now, i already have a barrier up, but i was wondering if there was a way to replace the asset with another one once that one gets damaged. like for example, say you shoot a window, once the bullet goes through the window, the glass shatters. how do i do that in unity with low poly assets?

teal viper
wintry quarry
junior seal
#

and how would i do that in code?

#

or would i even do that in code? how would i do that in general lmao

teal viper
junior seal
#

okay ill try a few things and if i have trouble ill come back. thank you!

limber laurel
junior seal
#

hey so how would i instantiate something? like how would i even get access to the thing im trying to make appear? two different scripts?

junior seal
#

thank you

empty radish
#

i am having a problem where if you dash in a different direction as when you jump it dashes than goes back to jumping in the direction of the original jump

here is my dash and jump stuff

wintry quarry
#

share it in a paste site

empty radish
wintry quarry
#

Also you're using GetAxis, which has momentum to it

empty radish
#

not sure how to disable it

#

also what would an alternative to getaxis be?

wintry quarry
wintry quarry
empty radish
#

i got that part

empty radish
wintry quarry
#

or return early with an if statement

#

i.e.

if (!dashing) {
  // do normal movement stuff
}```
or
```cs
if (dashing) return;

// do normal movement stuff
empty radish
#

would yield return null work since its an IEnumerator

#

as in like the yield part of it wont cause any problems

wintry quarry
#

yes you can use yield return null in Dash since it's a coroutine. You're already doing this.

#

you can't use it in Update

#

not sure what that has to do with what we were just talking about though

empty radish
#

ohhh i see

#

i thought you were talking about putting that in the jumpevent

unreal imp
#

My freinds,how i could make that if my object fall like 30 meters or more and then collides with the floor or another transform it's destroyed?

empty radish
wintry quarry
#

record the position at which you hit the ground again

#

subtract the y parts

wintry quarry
empty radish
#

do you mean by where the PlayerMovement() is called in update

#

because that just pauses all movement

unreal imp
wintry quarry
#

you dont want the normal movement while that's happening

wintry quarry
#

it's a basic thing

unreal imp
#

Ah yes,this is referenced to Y coordinates

wintry quarry
empty radish
wintry quarry
#

you have to know where you fell from

empty radish
#

how do i make it so it stays falling in the dash direction

#

after the dash

wintry quarry
#

so it's going to go in whatever direction you're holding your input in

#

I see your Jump is also a coroutine for some reason?

#

that's really odd

empty radish
#

it was from the tut i watched for it ik theres other ways to do it

wintry quarry
#

Watch a better tutorial

empty radish
#

tbh

wintry quarry
#

that's pretty awful

#

especially combined with the SimpleMove that's happening all the time

#

and the fact that it's having you call Move like 3-5 times per frame

#

It doesn't work properly on obstacles if it's called more than once per frame

empty radish
#

does FixedUpdate only call once per frame then?

wintry quarry
#

FixedUpdate gets called once per physics update

#

I don't see how that matters or is relevant here

empty radish
#

it was just a question

#

im trying to use what information i know compared to what im working with, im sorry if its not "relevant"

#

just trying to learn

junior seal
#

okay so i can figure out how to make the intact glass disappear but i cant figure out how to replace it. i followed the code the website provided but its not working for some reason?

wintry quarry
#

what happens when you try

#

what code did you write

junior seal
#

so ill "shoot" the glass, the glass disappears but the new broken glass prefab does not appear

wintry quarry
#

what code did you write

#

is the code actually running

#

are there any errors?

#

have you looked in the hierarchy for the newly spawned object?

#

etc

teal viper
#

Also what "website" are you talking about?

wintry quarry
#

I assume the unity manual page I linked earlier to them

junior seal
#
using System.Collections.Generic;
using UnityEngine;

public class DamagedFullyObjects : MonoBehaviour, IDamage
{
    [SerializeField] int HP;
    public GameObject myPrefab;

    void Start()
    {

    }

    void Update()
    {

    }

    public void takeDamage(int dmg)
    {

        Debug.Log(gameObject.name);
        HP -= dmg;

        if (HP <= 0)
        {
            Destroy(gameObject);
            Instantiate(myPrefab, new Vector3(-3, -2, 11), Quaternion.identity);

Debug.Log("Spawning Broken Glass");
        }

    }
}```
#

thats the code

wintry quarry
#

ok so - is the code running?

#

put a debug.Log in there

junior seal
wintry quarry
#

that says like "Spawning Broken Glass"

wintry quarry
#

and check your console for errors

junior seal
#

i have one in there-

wintry quarry
#

we need to know if you got inside the if

junior seal
#

ahhh okay

wintry quarry
#

also kinda odd to hardcode a position like that new Vector3(-3, -2, 11)

junior seal
#

and theres no errors

wintry quarry
#

my guess is either:

  • you didn't assign the prefab and you're getting an error
  • the broken glass is spawning just in a different place than you think
junior seal
wintry quarry
#

why not use the position of the unbroken glass object?

junior seal
#

okay well what is it? this is my first time in unity so imi sorry

#

that is the position of the unbroken one, but it wouldnt necesarily work if i access the unbroken object directly because the item gets destroyed before i try and spawn the broken glass

wintry quarry
#

which is not a world position

#

transform.position to get your own position

junior seal
wintry quarry
#

which I assume this script is attached to the unbroken glass

junior seal
#

the message showed up, show its literally fine

wintry quarry
#

looks like it spawned just fine

junior seal
#

thats a different prefab

wintry quarry
#

that's not a prefab, since it's in the scene

#

prefabs only live in the asset folder

junior seal
#

thats for the window on the wall, im trying to spawn proken glass in the big gap

#

dude its a different asset

sour wren
#

Guys, i imported an Revuelto with an Door animation, but i wanna redo this animation for my door returns to the original place, how i can solve it?

wintry quarry
summer stump
wintry quarry
#

ehhh - in playmode/at runtime they're not blue

#

so it's hard to say 😉

junior seal
summer stump
teal viper
junior seal
#

no

junior seal
#

yee im confused

polar acorn
#

Dunno what the original problem is but here's something that might clear things up:

Prefabs only exist in the file system. Once you put it in a scene, it is no longer a prefab, it's an object. When someone says "Did you set this to a prefab" they mean specifically a file in the project folder. Not an object in the scene.

summer stump
#

Trying to catch up, you want to destroy a glass... wall? And then spawn a broken glass wall from a prefab?

#

And the wall is being deleted, but the broken model is not spawning, even though the debug is popping up?

junior seal
polar acorn
#

And the log is happening?

junior seal
#

i added the debug part to it but yes

#

both logs are happening

#

but the broken glass wall is not spawning

polar acorn
# junior seal i added the debug part to it but yes
GameObject newObject = Instantiate(...)
Debug.Log($"Spawning in new object {newObject.name}", newObject);

It'll have the name of the new object. Click on the log, and it'll highlight the thing in the scene that it created

junior seal
#

someone said something about world position?

polar acorn
junior seal
#

yea thats where the other glass is

nocturne parcel
#

Does RefreshAllTiles() refresh all the tiles at the same time or does it so one by one?

polar acorn
#

And try out that updated log, it should show you an object in the hierarchy when you click it. Show the inspector of that as well

junior seal
junior seal
#

WAIT

#

its spawning

#

just the scale and rotation is incorrect. how do i make it spawn with the correct rotation and scale?

polar acorn
#

And you're passing in a position and rotation

#

So give it the values you actually want

junior seal
#

how do i pass in the correct rotation bc the rotation passed in isnt correct

polar acorn
junior seal
#

okay thank you

summer stump
polar acorn
#

If the intention is to replace the one that has this script on it, why are you even using hard-coded values instead of just using the values from the object spawning them

tiny kiln
#

I have this prefab, which is a UI button to display different selectable avatars. I want the parent (Avatar) button Image to act as a container, that way when selected, the background shows a different color. And the child (Sprite) Image to display the actual avatar sprite.

Here is my current code:

GameObject avatar = Instantiate(avatarPrefab, avatarListContainer);
Button avatarButton = avatar.GetComponent<Button>();
Image avatarButtonImage = avatar.GetComponent<Image>();
Image avatarImage = avatar.GetComponentInChildren<Image>();

avatar.name = avatarSprite.name;
avatarButtonImage.color = defaultColor;
avatarImage.sprite = avatarSprite;

however Image avatarImage = avatar.GetComponentInChildren<Image>(); isn't selecting the child (Sprite) Image component, but is selecting the parent (Avatar) Image component. How do I correctly select the child Image component?

wild silo
#

Lowkey at this point im just planning on restarting, making a new script and trying harder to plan things out... There's just so much wrong with my first movement script and so many things depend on one another

#

For movement, given I want these functionalities, is a Rigidbody or CharacterController "better" or "easier"

MovementController
In charge of all physics of a gameobject, this will handle movement
1 - In air
1.1 - Velocity maintained from when the ground was left (player archs)
1.2 - No jumping
1.3 - Air strafing
2 - Grounded
2.1 - Not sliding
2.1.1 - Walking
2.1.1.1 - If neither run or crouch button pressed
2.1.2 - Running
2.1.2.1 - If run button pressed, even if crouch button is already pressed
2.1.3 - Crouching
2.1.3.1 - If crouch button pressed, given run isnt already pressed
2.2 - Sliding
2.2.1 - If crouch button pressed while run butten held down, or when player is moving faster than a certain threshhold
2.2.2 - Player starts at whatever speed they were at at start of slide, then decelerates. (Ie if coming from a slope the player can slide very fast)
2.3 - Steep Sliding
2.3.1 - If player is on top of a steep slope beyond a certain angle, they will slide down it
2.3.2 - The player should be able to jump off slope, but not up the slope
2.3.3 - The player can strafe left and right going down the slope
3 - All
3.1 - Gravity

#

I understand you can theoretically use either, but a time limit is approaching and I sort of have to make the right choice here

cosmic dagger
#

problem is, there is no 'right' choice. with a CharacterController you're beholden to its Move methods and how it checks for collision, and Rigidbody has multiple ways to move a GameObject — which is its own discussion . . .

teal viper
#

I'd say rigidbody regardless

#

Never seen a point in the character controller.

#

That being said, there are many approaches with an rb as well. The main branching being between kinematic and dynamic.

cosmic dagger
#

Rigidbody will give you the most control if using velocity for movement, but you need to consider *and * incorporate outside forces into your calculations to apply it correctly . . .

eternal needle
wild silo
#

The main reason I was leaning towards character controllers when I started the project is a lot of people were talking about having to "fight" with the rigid body to ge the physics you want. But 4 months into the project and I still cant get fking sliding to work properly

eternal needle
#

everything else you listed is quite simple with rb and forces

wild silo
#

Yeah, that was the other thing is most articles/tutorials to learn these, 90% use rigidbodies lol

teal viper
#

People that say that they had to fight with the rb, probably didn't spend enough time to learn how it works. Or misunderstand something about physics in general.

wild silo
#

Yeah, that makes sense. Either way switching to a completely different system is going to be rough, tbh I kinda get it done by next Tuesday... Which has got me wondering if its better to just leave sliding out for now and work with the character controller for the deliverables

teal viper
#

Deliverables?🤔

wild silo
#

Capstone for college

#

my group wanted to do a game

sour fulcrum
#

Right now I do it super grossly and cache the transform, enable a character controller, use it's Move(), disable the character controller and add the difference the cc added. works pretty well so far for super jank

wild silo
#

and we gotta launch a "beta" version next week

teal viper
#

Up to you. It's probably not impossible to implement whatever features you need with the current setup. Might be really messy though.

One thing to consider is what exactly that college task requires you to do.

wild silo
#

then polish it for the "final" deliverable in December

#

Well the requirements are kind of set by us

#

I think the idea is to sort of let us manage our own projects to get a feel for it.

#

I ended up doing Movement, Inventory, and Weapon controllers for scripting

#

so I have a gun script that more or less lets us make any type of gun from it

#

I have an inventory script with a bunch of item types using Scriptable objects

#

and the movement I had everything except slopes working, but I put it on the backburner for a while in favour of the other systems

teal viper
#

In which case it's totally viable to leave out a feature or two. Developers in the industry do that constantly.

eternal needle
#

This is like the hackathon advice, you can essentially hardcode the whole thing as long as it looks cool enough lol

wild silo
#

I guess, but I also lowkey wanted to work on this past capstone, and have it for a portfolio

wild silo
teal viper
#

Nothing prevents you from rewriting it afterwards.

#

Should have enough time to polish it.

wild silo
#

Hopefully... I might just leave out sliding for now then... Its really dissapointing cause I feel like I was so close in so many regards, but it just kept getting messier and messier

eternal needle
# wild silo Hopefully... I might just leave out sliding for now then... Its really dissapoin...

you could always keep the code but just leave it unused in the showcase, like comment it out/remove any input that would cause you to slide. I remember doing projects similar in school, so I assume yours is gonna be similar to mine. You probably wont have that long to showcase this to the marker, the code wont be read, and you'll be marked on stuff like meetings, documents (requirements and such). So having like 5 seconds of your showcase being sliding probably wont help your mark

unique violet
#

How would I make a script to scale this text objects corners to each of those dots?

#

im aiming to recreate the transform gizmo at runtime so the user can edit and make there own things

eternal needle
unique violet
#

no like scale the text object

#

just any object in general

timber tide
#

the transform scale?

unique violet
#

yup

cosmic dagger
#

a UI object is different from any object. it would work different in 3d . . .

cosmic dagger
#

i believe they just want to resize the UI in-game . . .

unique violet
#

yeah

#

but i want to scale the corners individually if possible

wild silo
#

The whole concept of the game was an FPS Roguelike

#

we initially went with 5 levels, 4 classes, and 10 items with all systems finished

#

now we are at 1 level, 1 class, and atp "most" features finished

#

With a team of 4 fyi

queen adder
#

Guys, does anyone know the best way to get started when making a game like Simulacra and Emily Is Away?

modest dust
#
  1. Open Unity and your IDE of choice
  2. Work
#

That's usually the best way people go for

#

Simply plan out your project and implement one thing after another

queen adder
#

I know, but i'm trying to figure out the logic of the coding. Like the chat bubbles, how to make it move up when a new message comes in. That's the thing that's holding me back, the rest is simple, like making a button that opens a new ui etc.

modest dust
#

Then ask how to make chat bubbles, not an entire game - be specific and you're more likely to get a valuable answer

copper pumice
modest dust
#

^

queen adder
#

Thank you 🙂

copper pumice
# queen adder Thank you 🙂

As for the code itself a quick search gave me this:

scrollRect.normalizedPosition = new Vector2(0, 0);
``` Havent tested it tho.
queen adder
solemn fractal
#

Hello friends, why cant I use the random method here?

verbal dome
solemn fractal
#

I read but I didnt understand that is why I am asking 😄

verbal dome
#

It probably does not know if you mean System.Random or UnityEngine.Random

#

Yeah

solemn fractal
#

How to fix?

verbal dome
#

Use quick fix to see the options

#

Do you see the light bulb?

copper pumice
#

You can type: UnityEngine.Random, or System.Random depending on the one you need.

#

Or configure the using statements at the top of the file

verbal dome
solemn fractal
#

So it seems that in Update I can use

#

But not in Start method

verbal dome
#

Is it a different script

solemn fractal
#

I mean outside

#

even using the ligh bulb it fixes 1 prob and give me others

verbal dome
#

You want to use UnityEngine.Random here. But you have using System; so it doesn't know which Random class to use, UnityEngine.Random or System.Random

solemn fractal
#

float randomNumber = UnityEngine.Random.Range(-8.2f, 8.2f);

#

Like that worked thank you

verbal dome
#

👍

#

If you use it a lot in a file, it can be cleaner to just type using Random = UnityEngine.Random at the top of the file

solemn fractal
#

got it, thank you!

teal viper
#

Don't keep unnecessary usings.

solemn fractal
#

Hey guys. I have a small piece of code where I spawn some stuff, and it works, but after getting 1..2.. or 3. It gives me an error. saying I want to access somethin I already destroyed. But yes When I pick it up I destroy it and eventually i spawn another one.. so why would it say I am trying to access something I already destroyed? ``` public IEnumerator PowerupSpawnRoutine(){

     while (true)
        {
            yield return new WaitForSeconds(2.0f);
            int randomPowerup = UnityEngine.Random.Range(0, 3);
            Instantiate(_powerups[randomPowerup], new Vector3(randomPowerup, 5.8f, 0), Quaternion.identity);
        }

}```
#

I use the same code to spawn some ships and work fine but for mypower ups doesnt work and its just the same.

#

my ships that work fine ``` public IEnumerator EnemySpawnRoutine(){

     while (true)
        {
            yield return new WaitForSeconds(2.0f);
            float randomNumber = UnityEngine.Random.Range(-8.2f, 8.2f);
            Instantiate(_enemyShipPrefab, new Vector3(randomNumber, 5.8f, 0), Quaternion.identity);
        }

}```
wintry quarry
ruby python
#

!code

eternal falconBOT
wintry quarry
#

Presumably you're destroying something from that list you're spawning things from though

solemn fractal
#

that is my powerups script.

wintry quarry
solemn fractal
#

if I am also deleting it

wintry quarry
#

Anyway what's in the list you're spawning power ups from? Are they prefabs or scene objects

solemn fractal
#

they are prefabs

#

my enemies also prefabs

wintry quarry
#

You sure?

#

Show the list

solemn fractal
#

and I am following a course I am doing code and everything is 100% iqual and for me doesnt work.

wintry quarry
#

There's a difference between a prefab and an instance of a prefab in a scene

solemn fractal
wintry quarry
solemn fractal
wintry quarry
#

Delete the ones from the scene

solemn fractal
#

because i didnt have the spawn so far

#

so to test things

#

I had to just leave it there

#

to hit play and test if it was working

wintry quarry
#

Now you have it

#

So delete them

#

Basically I bet you are referencing those rather than the actual prefabs

solemn fractal
#

OH i know I think. i assigned to the spawn manager on my last SS the prefabs from the hierarch and not from the project folder

#

let me test

wintry quarry
#

Yes that's what I said

solemn fractal
#

Yeah amazing Man, thank you. That worked

#

😍

mystic oxide
#

im still new to this, how do you access gameobject from another scene?

wintry quarry
trail halo
#

Hey, i want to acces this float value via script so that i can change the rotation speed of the hdri sky. How do i access this float?

young warren
trail halo
ruby python
#

Mornin' all, I was just wondering if there was a more 'elegant' way to do this.

Idea is that it's a 'Super Soaker' type water pistol (ie, needs water and air pressure to operate), so trying to figure out the best way to 'detect' whether the pistol has both of these elements etc.

if (Input.GetKey(KeyCode.Space))
        {
            GameManager.instance.AdjustAir(1f);
            GameManager.instance.AdjustWater(1f);

            if (GameManager.instance.playerAir <= 0)
            {
                DisableLineRenderer();
                //do crappy spurt  -- maybe show message
            }
            else if (GameManager.instance.playerWater <= 0)
            {
                DisableLineRenderer();
                //Do 'dry fire' -- maybe show message
            }
            else if (GameManager.instance.playerAir <= 0 && GameManager.instance.playerWater <= 0)
            {
                DisableLineRenderer();
                //Do Nothing  -- maybe show message
            }
            else
            {
                lineRenderer.SetPosition(0, gunMuzzle.position);

                RaycastHit hit;
                if (Physics.Raycast(gunMuzzle.transform.position, gunMuzzle.transform.TransformDirection(Vector3.forward), out hit, weaponRange, weaponImpactMask))

Blah blah blah, you should get the idea. 🙂

languid spire
ruby python
#

Ah I think I see my mistake. That should be first no?

languid spire
#

yes

ruby python
#

Okay, thanks. 🙂

solemn fractal
#

Hey guys.. I have the using UnityEngine.UI; at the top. Is I just use the variable type as Image it doesnt allow me and I need to use as it is in the image below. is there a way that I can just write Image instead of the way it is now?

static cedar
#

I think it's because UnityEngine defines an Image class too.

mystic oxide
#

i was trying to store username to other scene's script

eternal needle
wintry quarry
#

But yeah some central manager Singleton is the typical way to go here

static cedar
#

Is there any way to enforce singleton on a monobehaviour script?

pseudo sable
#
public static Singleton Instance { get; private set; }
private void Awake() 
{ 
    // If there is an instance, and it's not me, delete myself.    
    if (Instance != null && Instance != this) 
    { 
        Destroy(this); 
    } 
    else 
    { 
        Instance = this; 
    } 
}

from https://gamedevbeginner.com/singletons-in-unity-the-right-way/, some good info there too

sand glen
#
// Singleton
static SomeClass _instance;
public static SomeClass Instance {
    get => _instance;
}
private void Awake() {
    if(_instance != null && _instance != this) {
        Destroy(gameObject);
        return;
    }
    else _instance = this;
    DontDestroyOnLoad(gameObject);   // If you want it to persist through scenes
}
#

This proved to me as best version of singleton

astral topaz
#

!code

eternal falconBOT
teal viper
#

The error says that the class doesn't contain a method called Interact. Read the error.

languid spire
#

This variable declaration has nothing to do with your error

ruby python
#

Not sure if in the right place, but is it possible to stretch an object dynamically along it's Z Axis so that it's end point is the same as the termination point of a raycast?

teal viper
#

This is inside the interface. Not your class.

languid spire
#

obviously not
InteractablePopup is not IInteractable which would be accessed as interactable anyway

#

what?

#

Do you see an Interact method in that script?

#

btw your code looks an awful lot like GPT garbage

modest dust
#

Follow a C# tutorial

#

An interface cannot be used unless you add it to your class

ionic elk
#

any info on whats going on?

modest dust
#
public class InteractablePopup : MonoBehaviour, IInteractable
{
// Implement IInteractable below
}
ionic elk
#

like is it a logic error or a compiler error?

languid spire
#

but even then you need an instance variable to call it not a class name

unreal phoenix
#

is there a way to do this without making the variable a method?

private bool myBool { if(SomeThing) {return true;} else {return false;} }
pseudo sable
#

can shorten it to private bool myBool => SomeThing;

unreal phoenix
#

What

pseudo sable
#

functionally the same as the code you posted, since SomeThing is already a bool that you're using in your condition

young warren
#

Yeah. What you have is basically if SomeThing is true, return true. Else return false

#

So just return SomeThing?

unreal phoenix
#

Assume that (Something) is not simply a boolean variable, otherwise why would I even make a new bool?

young warren
#

If it's not a boolean variable, you could not have put it in the if statement like that

#

Please don't provide false examples and expect an accurate answer

pseudo sable
#

SomeThing can be replaced with any condition

#

private bool myBool => SomeThing && SomeThingElse == "Hello";

young warren
#

Whatever SomeThing is, it needs to have equated to a boolean

pseudo sable
#

private bool myBool => ThingThatsInTheIfCondition;

unreal phoenix
#

you can do this???

private bool playerOnGround => Physics.CheckSphere(transform.position - new Vector3(0, playerCollider.bounds.extents.y / 4, 0), 1f, layerMask, QueryTriggerInteraction.Collide);
young warren
#

Well, what does CheckSphere return

pseudo sable
#

yep, so long as CheckSphere returns a boolean

gaunt ice
#

lambda expression is still method...

pseudo sable
#

it is

#

all variable getters are technically methods

unreal phoenix
#

But now I don't have to convert playerOnGround to GetPlayerOnGround()

queen adder
#

Does anyone know how to fix this? Basically, I have intergrated my Unity WebGL game into a site but the page that handles my build is on top of my navgiation bar

unreal phoenix
#

That sounds completely like a html issue

queen adder
#

it is but it's the build file that unity provides

unreal phoenix
#

What is responsible for the nav bar?

#

can you not put the build into a div and conform it to a flex layout?

timber tide
#

scoot it down a bit

unreal phoenix
#

How to turn off these hints being above a line in VSCode?

#

I thought they were called inlay hints but apparently not