#💻┃code-beginner

1 messages · Page 96 of 1

summer stump
#

Yes you can

slender nymph
#

yes you can. but interfaces are not components so you cannot add it to a gameobject

boreal tangle
#

I am trying to add the PlayerMovement file but it keeps giving me can't add script

slender nymph
#

fix the rest of your compile errors

boreal tangle
#

Unity and vs are clear of errors

slender nymph
#

you have zero errors in the unity console? not even unrelated ones?

boreal tangle
slender nymph
#

can you add it via the Add Component menu? if not, try restarting the editor

boreal tangle
#

ok

#

The script wont even pop up in add component

slender nymph
#

then restart the editor

boreal tangle
#

I did that too but it still wont let me

slender nymph
#

then there is some context you are not providing, such as whether this class is in some other assembly

boreal tangle
#

is it that I made some of the scipts in vs community instead of making it in unity?

slender nymph
#

no

boreal tangle
#

the assembly's are the same

summer stump
boreal tangle
#

I think il just start a new project and rewrite everything

summer stump
#

I guess, but there is a much less nuclear option here somewhere
Also, that makes me feel like you aren't using vwrsion control?

#

Can you show a screenshot of the error when you try to drag it in

boreal tangle
summer stump
boreal tangle
#

oh

slender nymph
#

are you sure you've restarted unity?

boreal tangle
#

i exited out and reoponed the project in the hub

summer stump
# boreal tangle

Hmmm. Try commenting out everything in the script, saving, compiling in unity, uncommenting, and compiling again

boreal tangle
#

ok

#

it worked somehow!

#

Thank you

summer stump
boreal tangle
#

I dont know what it is

#

or how to turn it off

summer stump
slender nymph
#

an editor restart would have reloaded the domain though

boreal tangle
#

I think it was off

sharp mica
#

I'm trying to assign a CanvasGroup to turn on and off a panel. The CanvasGroup works, but not sure where I went wrong in the code to get it to work. I'm following a Tutorial on an older version of Unity so I think that might be why, but not sure where it's wrong

summer stump
summer stump
slender nymph
sharp mica
slender nymph
#

where are you calling this method and what debugging have you done to ensure your conditions are evaluating to what you expect?

sharp mica
slender nymph
queen adder
#

is this a help channel

slender nymph
#

most channels are help channels. but you can use id:browse to find one that is relevant to your issue

queen adder
#

thank you

sharp mica
#

Thanks @slender nymph I'll work through that.

queen adder
#

im following this tutorial https://www.youtube.com/watch?v=rJqP5EesxLk&list=PLGUw8UNswJEOv8c5ZcoHarbON6mIEUFBC

i made this script after i turned my action map "default" into a class as seen in the first image. in the second image you can see my code for a input manager located in the scripts folder, and in the thrid image is my errors. what have i done wrong?

The first video in a series where we are creating a First Person game!
In this video we look at setting up our characters movement.

I've setup a Discord!!! and I would love to have you help me start up a friendly community where we can all help each other grow as game developers!

Discord invite link:
https://discord.gg/xgKpxhEyzZ
Can't wait t...

▶ Play video
slender nymph
eternal falconBOT
queen adder
#

ah

dense root
#

How long is everyone's project list? When you want to experiment with a new mechanic do you prefer to make a new game or do you prefer to test it within another game?

tender stag
#

do whatver i gotta do there

#

and then move it into my main project after it works

dense root
#

Gotcha

rare basin
#

that is weird approach

tender stag
#

works for me

rare basin
#

just make new branch on git, and experiment there

eternal needle
azure zenith
#

I have a vehicle in my scene that randomly moves in all sorts of directions when the game starts

#

It is like some invisible ghost is moving it

#

The position keeps changing

ruby ember
#

does someone know how to make visible and invisible text button

like it says visible but when i click it it says invisible

halcyon mauve
#

I am trying to get a 3d cube to change colors when an option is selected on a dropdown box. This is the code for the scripts I have

using System.Collections.Generic;
using UnityEngine;

public class Dropdown : MonoBehaviour
{
    public Material[] colors;
    public GameObject cube;

    public void DropDownOptions(int val)
    {
            cube.GetComponent<Renderer>().material = colors[val];
    }
}
#

What am I missing?

calm coral
ruby ember
#

sorry buddy but i kinda don't know how to code

#

that's why im here

normal slate
#
void Update()
{
    Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    mousePos.z = transform.position.z;
    Vector2 direction = mousePos - transform.position;
    float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
    angle -= 90f;
    rb.rotation = angle;//Quaternion.Euler(0, 0, angle);

    float hInput = Input.GetAxisRaw("Horizontal");
    float vInput = Input.GetAxisRaw("Vertical");

    if (Mathf.Abs(hInput) > 0 || Mathf.Abs(vInput) > 0)
    {
        Vector2 direction2 = new Vector2(hInput, vInput).normalized;
        Vector2 movement = direction2 * speed;
        rb.velocity = movement;
        rb.angularVelocity = 0f;
    }
    else
    {
        rb.velocity = Vector2.zero;
        rb.angularVelocity = 0f;
    }
}
#

is there anything that i did not optamize properly here?

#

I know fixed update is good for velocity but i also have it mixed with the rb.rotation so its not smooth without update.

#

i am lagging like crazy because of this and its updating so slowly someone help XD

#

its still colliding but its like its delayed collision and its updating the position in a clipping mannor if that makes sense?

queen adder
#

so im gonna fix that

ivory bobcat
normal slate
#

so yeah

#

the rectangle is a tile map

#

has a tile map collider 2d

#

the player has a 2d cylinder2d collider

#

and for some reason my whole game is lagging like crazy to the point where its clipping through

#

i have no clue as to why its doing this. I was gone for 2 days and it started happening ;p

ivory bobcat
#

Is the game lagging or the character simply teleporting?

dense root
#

How do I get Unity to not resize my images upon load, keep the ratio the same as it was when it was uploaded?

ivory bobcat
normal slate
#

yeah sure thanks

normal slate
#

@ivory bobcatfixed it haha it was just my pc 😭

#

i am so sad i gotta get a new pc this thing is about to die

golden finch
#

hello, so I'm new to coding I just started yesterday and I followed brackeys fps controller system and all worked okay, sometime later I got this error saying that UnassignedReferenceException: The variable groundCheck of PlayerMoveScript has not been assigned. even though I did assign ground check (I think), so well here's the code, it all worked fine until I deleted something (outside of the code) and I started getting the error, it was just in the console because in game everything worked out well, here's the code (can't get more than this script cause Im on my phone rn out of my home) https://pastebin.com/ANakeWzg

#

I rewrote the part that was conflicting and still nothing

ivory bobcat
#

You need to assign ground check from the inspector or through code etc

golden finch
#

i did

ivory bobcat
#

Verify it

#

It's likely not assigned if the error said so

golden finch
#

cant rn since not on my home but I think I assigned it, maybe if I re do ground check it'll work

ivory bobcat
#

You'll need to wait till you're available to check to figure it out

golden finch
#

alright

golden finch
ivory bobcat
#

It's definitely not assigned. There may be another object with the component in the scene, if anything.

golden finch
#

ok

summer stump
# golden finch ok

One thing you can do is search in the hierarchy. You would type t:PlayerMoveScript and only objects with that component would show. It may show more than one, which might be the issue as Dalphat said.
There IS a missing reference somewhere

golden finch
#

alr

halcyon mauve
#

is this the correct logic to check if a toggle has been turned off?

checkbox.onValueChanged.AddListener(delegate { CheckBox(checkbox); });

#

The main thing is to get a 3d cube to rotate 90 degrees while it is toggled on, but I am having difficulty in achieving that, I believe it is something to do with this part though im not 100 sure

polar acorn
halcyon mauve
#

So that does work to check if the box has been toggled at any time?

summer stump
halcyon mauve
#

This is the function it is calling

{
    isRotating = isCheckbox;
    transform.Rotate(0f, 90f, 0);
}
#

Does this even work to have the cube rotate 90 degrees each second?

slender nymph
#

fun fact, that's not passing the value of the checkbox to the CheckBox method. it's passing whether or not the checkbox object is null 😉

halcyon mauve
#

Oh

slender nymph
#

you don't need to create a delegate there. just AddListener(CheckBox) should (theoretically) be enough

halcyon mauve
#

thats not what I need. I am wanting it to rotate a cube on its y-axis continuously while the toggle is on

slender nymph
#

that's also not what is happening. you'd be better off just checking the checkbox's value inside of Update and calling transform.Rotate there

halcyon mauve
#

so checkbox.AddListener(CheckBox(checkbox));

#

i need to change the names of variables now that I am reading this

#

checkbox.Addlistener(CheckBox) ?

slender nymph
#

the method added as a listener is only going to be called once for each change of the value. so this isn't going to work the way you want anyway. just do this #💻┃code-beginner message

halcyon mauve
#

Am I supposed to be able to click on the code-begginer thing?

slender nymph
#

yes, it's a link to a specific message. the same message where i told you to just check the checkbox's value in Update

halcyon mauve
#

Oh sorry

grim tulip
#

Question how do I teach my self code and not in like the basic way like the way for me to know many possible ways on what to do and how to approach some things while writing the code?

tough lagoon
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

tough lagoon
#

It depends on how your brain works though

halcyon mauve
#

How would I check the index value of a dropdown box?

compact salmon
#

Hey guys, so I am trying to do a ground check with a raycast, and my Debug is stating that my Player is constantly grounded

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

public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 5f; // Adjust the speed as needed
    public float jumpForce = 10f; // Adjust the jump force as needed

    //private bool isGrounded;
    private bool canJump;
    private Rigidbody2D rb;
    private bool isGrounded;


    private void Start()
    {

        rb = GetComponent<Rigidbody2D>();
    }

    private void Update()
    {
        CheckGrounded();
        MovePlayer();

    }

    private void MovePlayer()
    {
        // Get movement input using the new Input System
        float horizontalInput = Input.GetAxis("Horizontal");

        // Move the player horizontally
        Vector2 movement = new Vector2(horizontalInput * moveSpeed * Time.deltaTime, 0f);
        rb.position += movement;

        // Jumping
        if (isGrounded && canJump && Input.GetButtonDown("Jump"))
        {
            rb.velocity = new Vector2(rb.velocity.x, jumpForce);
            canJump = false;
        }
    }

    private void CheckGrounded()
    {

        //LayerMask layerMask = LayerMask.GetMask("Ground");
        // Implement a simple check for grounding
        isGrounded = Physics2D.Raycast(transform.position, Vector2.down, 1.2f);
        Debug.DrawRay(transform.position, Vector2.down * 1.2f, Color.red);

        if(isGrounded) {
        Debug.Log("Grounded");
        } else {
            Debug.Log("Not Grounded");
        }
        // Reset canJump when grounded
        if (isGrounded)
        {
            canJump = true;
        }
    }
}
grim tulip
eternal needle
compact salmon
#

I've figured it out I believe

#

My raycast is hitting the Player

#

because it originates in the center of the Players collider

#

is there a way I can have the raycast ignore the player collider? or would I have to somehow compare collider tags?

eternal needle
charred spoke
#

Physic2D raycast has layermask Im pretty sure so just use that

nimble blaze
#

hello can someon help me im having these weird white lines in my art

#

they only apeear in the game view though

abstract finch
#
        {

        }```
Is there a way to have an out variable in the first line like out Attack currentAttack?
timber tide
#

if for some reason you want to redefine the variable later on you can always just add your own scope like

void Method()
{

  {
    Attack currentAttack = new();
    for (int i = 0; i < _attacks.Count; i++)
    {
      currentAttack.Value = 500;
    }

    AttackUnit(currentAttack);
  }

  Attack currentAttack = new();
}```

Not really a common practice but you can do that, though better just to redeclare instead of reinstantiating when possible. Actually probably doesn't matter since the compiler is probably smart enough.
gaunt ice
#

impossible in c#

#

you have to do that instead

{
  int i;
}
{
  int i;
}
abstract finch
#

ah nvm then i was trying to find a way to have less lines

ripe gale
#

Does anybody know any good unity game course that isn't using premade scripts?

eternal needle
ripe gale
#

I mean premade componets like rigidbody

timber tide
#

really it depends on the game you want to make

#

if you're reliant on speed, collision, and gravity then that's a lot more work

eternal needle
gaunt ice
#

everything in the engine is premade

ripe gale
#

Yeah I know that it's normal silly but I wanna learn c# too

#

and thought a game tutorial in unity would be a good way

gaunt ice
#

so why cant you use "premade" components?

timber tide
#

it's very possible to make a 2D platformer without rigidbodies if you do want to implement all that logic

#

or go half way and use unity's character controller

eternal needle
ripe gale
#

I'm completely new to this, I came from gamemaker where you do everything form scratch so I'm not really familiar with this field

eternal needle
#

There are online guides on how to learn as well like on w3schools. Realistically any of the top websites you see on google will be fine as well

timber tide
#

usually a good idea. Make something not dependent through an update rendering loop like chess or checkers, or if you want to write one of those yourself that's possible too hahah

ripe gale
#

alright thanks for the help everyone!

eternal needle
# ripe gale alright thanks for the help everyone!

https://www.w3schools.com/cs/index.php
this is the website i was referring to. i would say when you understand what a class is and how it can be used then you're probably fine to look into unity. This doesnt mean just use a class once, but actually make your own code and play around with it. You just really dont want to be guessing c# syntax while trying to learn unity, which is something that is done very often in this channel. Issues that should take 10 minutes end up taking the people literal hours.

ripe gale
#

I will try it out, thanks!

tawdry nymph
#

I want my enemy to smash the ground wait for a few seconds and then go back up but it doesn't work and I don't know why. Here is my code https://gdl.space/ifitumewud.cpp

crystal flax
#

Need help trying to toggle highbeams and lowbeams for vehicle spot light

`public class ToggleHeadLights : MonoBehaviour
{
float range;

Light lt;

float delay = 0f;

// Start is called before the first frame update
void Start()
{
    lt = GetComponent<Light>();
    range = lt.range;
}

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.F) && delay <= 0f) {
        lt.range = range * 2;
        delay = 0f;
        delay += Time.deltaTime;
    }

    if (Input.GetKeyDown(KeyCode.F) && delay >= 3f) {
        lt.range = range / 2;
        delay = 3f;
        delay -= Time.deltaTime;
    }
}

}`

low tide
#

hello

ivory bobcat
crystal flax
#

So basically if I run this code

#

I press F and the range of the spot light is multiplied by 2

ivory bobcat
#

I can read the code. What isn't working and what is though

crystal flax
#

Afterwards, if I try to do it again and nothing happens when it's supposed to divide it by 2

#

Basically back to how it was before

ivory bobcat
#

Try placing a log in the if statements

#

Likely delay plays a role in the unwanted behavior

crystal flax
#

I'm trying to have it so there's a delay between button inputs so that if you press "F", it doesn't try to switch the ranges back and forth in the same frame

ivory bobcat
#

I'm assuming it'll only ever be zero

#

Or rather, zero plus some small delta

crystal flax
#

Basically, I'm trying to get it to how a flashlight would normally work in any game, toggling on/off

ivory bobcat
#

So what would the above code do if delay was 1..

#

Guess

crystal flax
#

If it's delay by 1 second

ivory bobcat
#
if delay is zero or less
    do this
if delay is three or more
    do that```
#

So if the delay is between the two values, what would happen?

static cedar
ivory bobcat
#

Aye

#

On initial start it's zero, so it'll do the first if statement when the button is pressed.

#

Thereafter, it'll not do anything anymore

#

Because delay would likely be a value greater than zero but less than three

crystal flax
#

Yeah

#

But I also don't think the deltaTime is doing anything

ivory bobcat
#

It doesn't do anything. It's simply how long it took between this frame and last frame

#

I'm assuming you're wanting to increment delay in update and not exclusively in the if statements

crystal flax
#

Yeah

subtle folio
#

hi so i'm developing a mobile game and there's a bug where if i press 2 buttons simultaneously they would trigger their onclick events at the same time. how do i do it so that it will only trigger either the first button's or the second button's onclick event?

i made a code that would make the other buttons not interactable when a button is pressed but it only works when the button is released, so you can press multiple buttons at the same time and the script wouldnt work

eternal needle
# crystal flax Need help trying to toggle highbeams and lowbeams for vehicle spot light `publi...

you'd probably have a way easier time using a bool or enum to keep track of what your current mode is, high or low beams. The delay you have doesnt need to increment/decrement, this is really just one timer that counts to 3 (or down from 3 to 0). Id also just store the high and low value instead of doing the math, lets you customize it more later in inspector anyways. Based on your bool or enum, swap the values when input is given

ivory bobcat
#

I would simply place an early if statement to exit the function if the requirements aren't met

#
if(!first)
    return;```
subtle folio
#

say i have 2 buttons, new game and load game, if i press the 2 at the same time then release them at the same time, the game bugs out and tries to create a new game then load a saved game simultaneously

ivory bobcat
#

Set flags/states to prohibit false positives such as selecting two buttons

subtle folio
#

any hints on how can i do that? pointers perhaps :>

ivory bobcat
#
if a button was pressed already
    return;//ignore this function
...
buttonPressed = true;```
#

Where you'd reset the state once per frame or after completing/returning control to the menu

subtle folio
#

i would have to move functions like these to a script no?

ivory bobcat
#

You'd want to consider calling a function that would do other stuff and the wanted function that you've set.

subtle folio
#

so just one function with a flag and all the other functions that i want?

ivory bobcat
#

It's probably better to have a manager and simply fire a request for the event to occur. Where the manager would determine if the event should happen or not.

#

You'd then subscribe a single function for each button with a particular value to represent what has occurred ie an enum for main menu, info, new game or whatnot.

subtle folio
#

ahh i see, thank you

crystal flax
#

Thanks y'all

#

I got it working

proper flume
#

So I have a top down shooter I'm trying to make, and I'm confused on the scripting for it. It's a essentially a top down with a camera similar to Enter the Gungeon, with a toggleable FPS for ADS ( kind of like PUBG or COD Mobile). Anyway, I have the controls for that working pretty good, but I'm trying to get my character model to rotate with the FPS camera. I tried adding the same script from the FPS camera to the player, but that didn't seem to work. Is there a better way to do this? https://gdl.space/usidopipit.cpp

proper flume
#

Nvm, I'm gonna have to rewrite the whole thing. 😅

hidden sun
#

Hi, i made a small game and i used onmousedown. it will work on phone too? or i need to use touchdown/up?

graceful citrus
hidden sun
#

i have 2 buttons.. i use a lof of colliders

topaz mortar
#

not really the place for it, but there's no other place to ask for me
I have a 112 KiB MySQL database with 2 tables: players and items
somehow it is using 1GB memory? this seems insane?

proper flume
#

I cannot for the life of me figure this out. I'm following a tutorial for FPS movement and I have the EXACT same script as the guy I'm following but I'm getting the CS0103 "orientation does not exist in this context" error. https://gdl.space/egeqalafig.cpp

gaunt ice
#

did you saved your script?

proper flume
#

I did.

gaunt ice
#

the identifier name seems correct, by ctrl+f

proper flume
# topaz mortar is orientation set?

Orientation is supposed to be a public variable so I can assign it after the fact. With the break in the script though, it won't update to allow me that.

languid spire
topaz mortar
#

add a Debug.Log(orientation) right before setting moveDirection

queen adder
#

anyone know the solution guys

gaunt ice
#

you dont need to import particle system

proper flume
languid spire
#
orientiation.right

!!!!!!!!!!!!!!!

proper flume
frosty hound
eternal falconBOT
proper flume
topaz mortar
proper flume
topaz mortar
#

well one is named vs code or visual studio code
the other one is named visual studio

proper flume
#

Oh okay. Yeah, just Visual Studio then.

topaz mortar
#

should look like this

proper flume
topaz mortar
#

then what's the issu setting it up?

#

it's like the most important thing you'll ever do lol

proper flume
#

I'm not sure. I followed all of the steps in the setup guide Osteel posted, but I guess it's still not setup right? I've noticed this with other things on there as well. It doesn't underline spelling mistakes, and things like Vector3 are just normal type. I'll show a screenshot for reference.

topaz mortar
#

I didn't have to do any setting up iirc
I just installed Unity first and then Visual Studio automatically set up correctly when installed

#

maybe try uninstalling & re-installing

languid spire
proper flume
languid spire
#

yep, not set up correctly

#

open the solution explorer window

nimble blaze
#

it only changes just in the end

proper flume
languid spire
#

first thing, is the Unity workflow installed in VS?

proper flume
languid spire
#

IN VS

gaunt ice
#

open the vs installer, check if the game dev with unity installed

languid spire
#

I guess you did not follow the steps in the link

proper flume
languid spire
#

OK, so now the External Tools Window

proper flume
#

Actually, I think it's fixed now. I didn't realize that updating was part of the process and skipped over it when I installed since I thought it was already up to date. Updating it just now actually fixed it. Thanks for the help!

queen adder
#

Hey there quick update! I managed to "fix" this problem by adjusting the Obstacle Avoidance Settings. I turned the Quality from "High Quality" to "None" and it "works" now. But I don't know which further problems comes with that, so I'm "excited" so the what comes next...

queen adder
#

I just wanted a floodfill alg, accidentally made a pathfinder UnityChanOops

#

it was even faster than my old pathfinder which I spent like a whole day to improve

rustic cave
#

So I want the camera to follow the player. I have set up an empty GameObject which it's the target of the camera (let's call it camTarget). The problem is that I can't understand where to place the camTarget in order to make the main camera move as the player does. Here is the code:

using UnityEngine;

public class Camera_Follow : MonoBehaviour
{
    [SerializeField] public Transform target;

    float pLerp = .02f;
    float rLerp = .01f;

    private void LateUpdate()
    {
        transform.position = Vector3.Lerp (transform.position, target.position, pLerp);
        transform.rotation = Quaternion.Lerp(transform.rotation, target.rotation, rLerp);
    }

}```
short hazel
#

Both Lerp are wrong, the third argument (float value) should gradually go towards 1 over time

rustic cave
#

Here is the scene view. The cylinder is the actual player, and the capsule is the camera target.

short hazel
#

Here you're setting the position and rotation to 2% and 1% of the way between the two values, respectively
If I were you I'd just use Cinemachine which has all that behavior ready and much more configurable

proper flume
#

I have a toggle between 3rd and 1st person as a sort of ADS feature, but with my movement options it changes the rotation of my player in the 1st person mode ( intended) and I need to reset the players rotation when they go back in to 3rd person. What would I add to my script for that? I tried transform.Rotation a couple different ways but it kept returning errors. https://gdl.space/ucogacofad.cpp

rustic cave
proper flume
#

Nvm, figured it out.

ivory breach
#

Why does my coded camera boundary cause my ship to slide up/forward when my camera is tilted?

#

The sliding doesn't happen if I disable the tilting

rare basin
#

how can we know without any context and code

ivory breach
# rare basin how can we know without any context and code

So first of all, my virtual camera uses the following scripts to make it follow the player with some dampening, with boundaries to stop it from following after the camera hits it. The boundaries are in a fixed position from the starting point of the camera

#

The rotate script tilts the camera itself, but not the boundary

short hazel
#

!code is required to see where the issue could be

eternal falconBOT
ivory breach
ivory breach
bold nova
#

How does one call two coroutines sequentially?

#

I have these lines of code, only first coroutine is being called

#
var enemy = collision.gameObject.GetComponent<Enemy>();
            enemy.StartCoroutine(enemy.StumbleAnimation());
            enemy.StopCoroutine(enemy.CatchUpToThePlayer());
languid spire
#

that last line says Stop not Start

bold nova
#

Yeah, it still doesnt work proper;y, everything is executed in one frame

languid spire
#

indeed, to start the second after the first is finished, put the start it the end of the first

gaunt ice
#

you can yield return other coroutines

IEnumerator A(){
  yield return B();
}
bold nova
#
  public IEnumerator StumbleAnimation()
    {
        float speed = 0.001f;
        float time = 0;
        enemyAnim.SetBool("IsOutOfPlay",true);

        // enemy stumbles and flies in the air
        yield return new WaitForSeconds(0.5f);

        // lies on the ground
        while(time < 1)
        {
            transform.position = Vector3.Lerp(transform.position, outPoint.position, time);
            time += Time.deltaTime * speed;
            yield return null;
        }
        StartCoroutine(CatchUpToThePlayer());

    }

    public IEnumerator CatchUpToThePlayer()
    {
        float speed = 0.001f;
        enemyAnim.SetBool("IsOutOfPlay", false);

        // enemy cathced up to the player
        float time = 0;
        while (time < 1)
        {
            transform.position = Vector3.Lerp(outPoint.position, startRunPoint.position, time);
            time += Time.deltaTime * speed;
            yield return null;
        }
    }
languid spire
#

yes

bold nova
languid spire
#

no

bold nova
#

after 5 sec nothing happens and enemy is freezed

languid spire
#

Debug them

bold nova
#

initially it was all one coroutine, but that second lerp part wasnt executed, so i though that might help, it didnt

gaunt ice
#

so you have debug it and the while loop doesnt run?

#

and i think you doesnt reset the time so that it is still one before enter the while loop

languid spire
#

no

#

time is a local variable to both

#

my guess, errors in console

gaunt ice
#

he says they are one coroutine at beginning, maybe i misunderstood

languid spire
#

were

#

no reason for that not to run unless errors are being thrown

rustic cave
#

How do I rotate the camera ingame? I am using Cinemachine

bold nova
rustic cave
bold nova
#

program exits before reaching that line

ivory bobcat
bold nova
#
public IEnumerator StumbleAnimation()
    {
        Debug.Log("First coroutine");
        float speed = 0.001f;
        float time = 0;
        enemyAnim.SetBool("IsOutOfPlay",true);

        // enemy stumbles and flies in the air
        yield return new WaitForSeconds(0.5f);

        // lies on the ground
        while(time < 1)
        {
            transform.position = Vector3.Lerp(transform.position, outPoint.position, time);
            time += Time.deltaTime * speed;
            yield return null;
        }

        enemyAnim.SetBool("IsOutOfPlay", false);

        // enemy cathced up to the player
         time = 0;
        while (time < 1)
        {
            transform.position = Vector3.Lerp(outPoint.position, startRunPoint.position, time);
            time += Time.deltaTime * speed;
            yield return null;
        }
    }
bold nova
#

above you see the initial variant

ivory bobcat
#

Where did you place your logs?

#

Seems like both will properly execute

bold nova
#

so, i guess the line where i set bool to false is never reached

ivory bobcat
#

Why guess? Place a log after and see if it prints

#

Also, if time scale is zero, it'll never complete the first loop

bold nova
#

because in animator enemy is in stumble animation and IsOutOfPlay is true

ivory bobcat
#

It simply means that you did not get what you were expecting

#

You need to place a few logs or use the debugger to see what's actually occurring

ivory breach
ivory bobcat
bold nova
#

well, i've placed .log before setting IsOutOfPlay to false, as expected, nothing shows up

ivory bobcat
ivory breach
#

What more do you need?

bold nova
#

ok, i went through the code, after going through the loop couple of times i get this sccreen

bold nova
valid pulsar
#

I asked this question a few time but got busy with other things so i could not reply but I have a script i want to put on a button so when i press it the the next key pressed is set as the key for whatever action i set for it i.e. movement, dashing, ect. So i have an Input action reference i have on the button script that i can set the action i want to rebind to in and it properly updates the way i want it to (when i press the button then press a key it changes the action to the new key). Then I need to update the input action which holds the data for all the controls in the MenuManager so the code in the attached image is supposed to do that but as you can see in the logs it never changes the controls button.

bold nova
#

Im back to two coroutine, now at least the both play out but way too fast, how do i make sure second will play only after the first one done executing?

   public IEnumerator StumbleAnimation()
   {
       Debug.Log("First part");
       float speed = 0.001f;
       float time = 0;
       enemyAnim.SetBool("IsOutOfPlay",true);

       // enemy stumbles and flies in the air
       yield return new WaitForSeconds(0.5f);

       // lies on the ground
       while(time < 1)
       {
           transform.position = Vector3.Lerp(transform.position, outPoint.position, time);
           time += Time.deltaTime * speed;
           yield return null;
       }
   }

   public IEnumerator CatchUpToThePlayer()
   {
       Debug.Log("Second coroutine");
       float speed = 0.001f;
       enemyAnim.SetBool("IsOutOfPlay", false);

       // enemy cathced up to the player
       float time = 0;
       while (time < 1)
       {
           transform.position = Vector3.Lerp(outPoint.position, startRunPoint.position, time);
           time += Time.deltaTime * speed;
           yield return null;
       }
   }
sharp copper
#

Does anyone know how to create a camera shake when walking in 2d using cinemachine?

vernal bone
keen dew
vernal bone
#

Is there a proper way to check if 2D character is grounded?
And if counting colliders is best implementation, can someone tell how to ignore cinemachine confiner?

ivory bobcat
bold nova
keen dew
#

Ok, but it's still 17 minutes

#

The enemy flying around is a separate issue, solve it separately

ivory breach
ivory bobcat
ivory breach
#

The bounds DO work as intended. It is possible that the issue lies within the camera's clamping

ivory bobcat
#

What's the unwanted behavior? Did you intentionally elevate the ship or was that something due to the camera?

ivory breach
#

I want the ship's position to stay the same when it is hitting against the clamped position

#

But due to a strange interaction with the camera's bounds and the world to viewport clamp, my ship is sliding up/forward

ivory bobcat
#

Show your ship moment script please

#

If your ship is moving in an abnormal behavior, you'll need to provide that.

ivory breach
ivory bobcat
#

So to narrow this problem down, try commenting out the clamp position function

#

Does the ship still move abnormally?

#

If not, then it's solely due to these linescs void ClampPosition() { Vector3 pos = Camera.main.WorldToViewportPoint(transform.position); if (pos.x < 0.15f || pos.x > 0.85f || pos.y < 0.15f || pos.y > 0.85f) { pos.x = Mathf.Clamp(pos.x, 0.15f, 0.85f); pos.y = Mathf.Clamp(pos.y, 0.15f, 0.85f); transform.position = Camera.main.ViewportToWorldPoint(pos); } }

#

Where view port to world point is modifying the position of the ship.

ivory breach
ivory bobcat
#

Does it continue to slide up? (assuming you did not explicitly slide up in the original clip)

ivory bobcat
#

So, likely the repositioning of the player using view port causes an increase in y position and the camera to follow the player in y position.

ivory breach
ivory bobcat
#

Yeah. Figure out why the conversion is producing those unwanted values.

ebon robin
#

I NEED ACTUAL HELP

#

why is Coroutine always buggy

prisma blaze
#

how do i make an object eventually move to x axis =0?

     if(column == Column.Right && transform.position.x<3.5f)
     {
         Vector3 horizontalMove = transform.right  * speed * Time.fixedDeltaTime * horizontalMultiplier;
         rb.MovePosition(rb.position + forwardMove + horizontalMove);
     }
     else if (column == Column.Left && transform.position.x > -3.5f)
     {
         Vector3 horizontalMove = -transform.right * speed * Time.fixedDeltaTime * horizontalMultiplier;
         rb.MovePosition(rb.position + forwardMove + horizontalMove);
     }
     else if (column == Column.Middle && transform.position.x != 0f)
     {
        // Vector3 horizontalMove = -transform.right * speed * Time.fixedDeltaTime * horizontalMultiplier;
         rb.MovePosition(rb.position + forwardMove + horizontalMove);
     }```
#

the above code keeps moving the object from 3 different lanes where -3.5 is left, 3.5 is right and 0 is middle

#

but i don't know how to do the middle one

ivory bobcat
#

Specifically the position logs

ebon robin
#

how do I paste the logs here

ivory breach
ivory bobcat
#

Snap an image of the console logs from unity editor

ebon robin
ivory breach
ivory bobcat
glossy eagle
#

Hi. Does anyone know how can I set special characters to a text mesh pro UGUI component please? because nothing seems to appear, or it just shows up as a square😅

short hazel
glossy eagle
#

The thing is that I searched for a font that in theory supports those characters

short hazel
#

It's an import issue then, you need to tell the TMP Font Asset Importer to generate glyphs for these special characters

#

I think it does that by default, so check the import settings

gentle moat
#

does anyone know how to get a 2d top down movement/attacking similar to cult of the lamb? I want to have animations in 4-8 directions for walking and attacking, but I also want to only face the mouse when I attack

glossy eagle
short hazel
#

It's when you import the font and create a Font Asset from it, it opens a window with import settings

ebon robin
#

great now my slime doesn't even dash anymore

prisma blaze
# ivory bobcat ``` if right if less than zero go to zero else if less then 3.5 ...

I tried this code c# else if (column == Column.Middle && transform.position.x !=middle) { Vector3 horizontalMove=Vector3.zero; if (transform.position.x > middle) { horizontalMove = -transform.right * speed * Time.fixedDeltaTime; } else if (transform.position.x < middle) { horizontalMove = transform.right * speed * Time.fixedDeltaTime; } rb.MovePosition(rb.position + forwardMove + horizontalMove); }
I noticed that the object keeps trying to reach 0 but it never does, it's switching between different values (0.2,0.3...) i noticed this with the left and right logic too but it's not noticable since the check has >= and not strictly =. is there a way to solve this so it is guaranteed to reach the exact value, or do i have to use something like checking if it's in a value range?

glossy eagle
short hazel
#

The "Character Set" option

glossy eagle
#

what should it be on?

short hazel
#

It's in Extended ASCII mode which is still a small character set compared to Unicode or even UTF8 which can have thousends of glyphs

glossy eagle
#

and what do I enter in the select font asset😅

short hazel
#

None, as the message above says

frosty hound
#

I'm sure a lot of people can.

short hazel
glossy eagle
short hazel
#

Yes, it will scan the whole font file

rich adder
#

doubt anyone is gonna lay out a step by step online

glossy eagle
prisma blaze
gentle moat
#

i just can’t find any tutorials for it

#

all the ones i find make the player always look at the cursor

prisma blaze
#

currently i'm trying to snap the player if the position is between 0.5 and -0.5

rich adder
short hazel
ivory bobcat
rich adder
glossy eagle
# short hazel You need to specify ranges in that big text box. From the website where you got ...

it is from google fonts (https://fonts.google.com/specimen/Zen+Kaku+Gothic+New?preview.text=MWP2 指事字 á jet € %3F _ º ° ASDUV привет&sort=popularity&query=kaku&noto.query=kaku to be exact)
I don't really know what I'm looking for, like what are "ranges" in this case?

Google Fonts

Zen Kaku Gothic New is a contemporary Japanese gothic (san serif) typeface family. With this font, you can express fine typesetting without any professional det

gentle moat
ivory bobcat
mild mortar
#

I've attempted to do what was said here. (Not sure if it's right?)

But here's what it looks like and my script.

But my character doesn't seem to get parented when I touch it?

rich adder
prisma blaze
rustic cave
#

The Movement I got is "static". For example if I look backwards, and press W, It will go in the opposite direction instead of moving where the camera looks at. This is the current code.

using UnityEngine;

public class Movement : MonoBehaviour
{
    public CharacterController controller;

    public float movementSpeed = 50f;
    // Update is called once per frame
    void Update()
    {
        float inputX = Input.GetAxisRaw("Horizontal");
        float inputY = Input.GetAxisRaw("Vertical");

        Vector3 direction = new Vector3(inputX, 0f, inputY).normalized;

        if (direction.magnitude >= 0.1f)
        {
            controller.Move((direction * movementSpeed * Time.deltaTime)*2);
        }
    }
}
short hazel
ivory bobcat
rich adder
glossy eagle
rich adder
#

nowhere does it say so @rustic cave

rustic cave
rich adder
#

if you wanna move where you look you need transform.forward

rustic cave
glossy eagle
rich adder
short hazel
rich adder
#

code doesn't magically do things you don't program it to do @rustic cave

rustic cave
rich adder
glossy eagle
summer stump
rich adder
#

fr

short hazel
summer stump
twilit quiver
#

i've spent hours just fiddling around with the transitions trying to fix it

bold nova
#
    public IEnumerator StumbleAnimation()
    {
        float timeElapsed = 0;
        enemyAnim.SetBool("IsOutOfPlay", true);

        Debug.Log("Bool set");
        // pull enemy out of screen
        while(timeElapsed > 1)
        {
            transform.position = Vector3.Lerp(startRunPoint.position, outPoint.position,
                timeElapsed);
            timeElapsed += Time.deltaTime;
            yield return null;
        }
        Debug.Log("Pulled back");

        enemyAnim.SetBool("IsOutOfPlay", false);
        Debug.Log("Bool set false");

        timeElapsed = 0;
        // get enemy back on sceen
        while (timeElapsed > 1)
        {
            transform.position = Vector3.Lerp(outPoint.position, startRunPoint.position,
                timeElapsed);
            timeElapsed += Time.deltaTime;
            yield return null;
        }
        Debug.Log("Enemy is back on screen");
    }
short hazel
# glossy eagle chinese

Alright, some of the characters I see in your screenshot are definitely Japanese, so you can try with the Japanese Unicode range first to see if they're included:

bold nova
#

how do i make coroutines not play out at the same time?

#

all debug are displayed so, everything works, exept it all happens in one frame

summer stump
glossy eagle
summer stump
#

@bold nova

if (!isRunning) StartCoroutine(myRoutine);

IEnumerator myRoutine()
{
  isRunning = true;
  //do stuff
  isRunnimg = false;
}
dapper knot
#

hi everyone i was just wondering if yall could help me i was follwing a tutorial and i was trying to get the pause menu to work i have the start menu to work but whenever i press escape nothing happens only my mouse appears ?

#

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PauseMenu : MonoBehaviour {

public static bool GameIsPaused = false;

public GameObject pauseMenuUI;

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.Escape))
    {
        if (GameIsPaused)
        {
            Resume();
        } else
        {
            Pause();
        }
    }
}

public void Resume ()
{
    pauseMenuUI.SetActive(false);
    Time.timeScale = 1f;
    GameIsPaused = false;
}

void Pause()
{
    pauseMenuUI.SetActive(true);
    Time.timeScale = 0f;
    GameIsPaused = true;
}

public void LoadMenu()
{
    Time.timeScale = 1f;
    SceneManager.LoadScene("Menu");
}

public void QuitGame()
{
    Debug.Log("Quiting...");
    Application.Quit();
}

}

summer stump
# rustic cave

Looks like you need to use transform.forward of the camera

Or rotate the object along with the camera

short hazel
summer stump
rustic cave
summer stump
bold nova
bold nova
#

its all one coroutine

#

just need to play it sequentionally

summer stump
#

Show code at this point

But simply, a condition will stop more coroutines from starting

It will make it so only one runs at a time

eternal falconBOT
glossy eagle
bold nova
# summer stump Show code at this point But simply, a condition will stop more coroutines from ...

Coroutine in enemy's script

public IEnumerator StumbleAnimation()
{
    float timeElapsed = 0;
    enemyAnim.SetBool("IsOutOfPlay", true);

    Debug.Log("Bool set");
    // pull enemy out of screen
    while(timeElapsed > 1)
    {
        transform.position = Vector3.Lerp(startRunPoint.position, outPoint.position,
            timeElapsed);
        timeElapsed += Time.deltaTime;
        yield return null;
    }
    Debug.Log("Pulled back");

    enemyAnim.SetBool("IsOutOfPlay", false);
    Debug.Log("Bool set false");

    timeElapsed = 0;
    // get enemy back on sceen
    while (timeElapsed > 1)
    {
        transform.position = Vector3.Lerp(outPoint.position, startRunPoint.position,
            timeElapsed);
        timeElapsed += Time.deltaTime;
        yield return null;
    }
    Debug.Log("Enemy is back on screen");
}

playerControllerScript

    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Enemy") && isRolling)
        {
            var enemy = collision.gameObject.GetComponent<Enemy>();
            enemy.StartCoroutine(enemy.StumbleAnimation());

        }
    }

short hazel
# glossy eagle it was the copy pasted :/

Okay for completeness' sake, can you copy one that is like this (if you can find one) from your TMP input box, or from wherever you took them, and try to get its index in the charset?

Debug.Log(((int)'YOUR CHARACTER HERE').ToString("X4"));
summer stump
#

I would call a public method that in turn starts the coroutine.

#

That public method checks the bool to see if it's already running

#

If it IS running, don't start the coroutine

glossy eagle
short hazel
#

One that's Hiragana and didn't display at all

#

So yeah probably from the website

glossy eagle
#

like this for example?

short hazel
#

Yeah looks good to me

glossy eagle
#

got a warning in visual studio but anyway

gentle moat
severe drum
#

there is a way to check if a navmesh agente is conencted to a navmesh?

short hazel
# glossy eagle

Okay so that's the index of that character in the charset. Not sure how to deal with this because it's not in the range that was generated for this font

#

4EBA is from "CJK Unified Ideographs" and is range 4E00-9FFF which is a huge range

short hazel
glossy eagle
#

oh wow

#

well maybe it isn't worth translating it to chinese

bold nova
glossy eagle
severe drum
#

not sure if this is the best way to do this

short hazel
glossy eagle
short hazel
#

The à will be your regular Latin character range. As for the separator good question, try it and see

summer stump
glossy eagle
short hazel
#

That's the basic, you'll have to have at least the Supplement to get the accented characters. Each PDF has a table with the characters

glossy eagle
#

okay so, this range has the 'á', but when I enter that range, nothing appears😅 . I'm going to check if that's just the font now

#

it def has it

golden finch
#

how can i avoid this deformation when i parent an object to another?

runic compass
#

need some help

#

How come mine is not showing color nor giving me options to chose from?

wintry quarry
eternal falconBOT
golden finch
#

what do you mean with uniform

#

not sure

wintry quarry
golden finch
#

alr

summer stump
wintry quarry
#

If you need to scale something make it a leaf node without children

golden finch
#

ok

runic compass
summer stump
wintry quarry
runic compass
severe drum
#

got the snaping into the navmesh by enabling and disabling the navmesh agent while it dotn have navmesh connected, but i cant drag the unit out of it without doign the same thing

#

anyone have a suggestion?

#

mayeb there is a wy to cehck how far the cursor need to be from the attachzone?

visual valley
#

im randomly getting this thing where my typing bar turns into a box and it deletes stuff

languid spire
visual valley
#

what is the insert key

languid spire
#

The one with Insert written on it?

visual valley
#

cant find that one

#

wait

#

found it

#

thank you

azure zenith
#

Should method names be in pascal-case?

languid spire
north kiln
bleak vale
#

How to make list like this? I mean I forgot how it is called.

#

Slider is a thing that slide and how is it called?

#

Not a list because list looks diffrent

slender nymph
#

a field of an enum with the Flags attribute

#

also that is called a dropdown

bleak vale
#

Dropdown yes

#

Thank you mate

gentle moat
#

is it possible to make something happen becasue of an animation

#

like can I turn on a collider2D when an animation happens

#

if so how

wintry quarry
gentle moat
#

how would i do that

wintry quarry
#

Google Unity animation events

gentle moat
#

alright

#

also

#

what do the lines of code that start with // and have a message do

bleak vale
#

Its notes

#

It doesnt count to your code

#

@gentle moat its an example of my script

#

That has //

gentle moat
gentle moat
slender nymph
eternal falconBOT
gentle moat
#

ah

bleak vale
#

But its reccomendet to use this simple command

#

Because some of the ppl here that can help you are on phones and on phones they cant see the file of code so u would have to use this command to show them your code

gentle moat
bleak vale
#

Update

slender nymph
#

you can give your methods whatever name you would like

gentle moat
#

how do i do that tho?

slender nymph
rare basin
#

you cannot get help with this knowledge

gentle moat
#

i started unity like 3 days ago 😭

rare basin
#

because you just dont understand the help

bleak vale
#

You put it in Update and then u use if method

rare basin
#

You can turn on/off colliders in AnimationEvents

#

would be much easier with more control

bleak vale
# gentle moat i started unity like 3 days ago 😭

I reccomend you to learn basic C# first. I reccomend you the YouTube CodeBro channel with 4 hours C# tutorial. Its one of the best free tutorials and from there u would be able to make simple games belive me

gentle moat
#

alr

gentle moat
#

ty

#

im so dumb

slow dew
#

How do I get the brackets to format on the same line with Shift + Alt + F? back den I was using omnisharp but how do I do that with the new system of the C# Dev Kit?
eg, I want it to format as such

public class Player : MonoBehaviour {
    // Start is called before the first frame update
    void Start() {
      if (true) {
      //etc
    }
    // Update is called once per frame
    void Update() {

    }
}
rich adder
slow dew
rich adder
queen adder
#

Hey yall i need some help please.
Im trying to make a lives system in my game. Where the player has 5 lives, if they lose a life they need to wait say 20min to restore that life.

I got the code working for it.
But if i add my timer it will countdown the time from 120seconds (i made it 2min for testing) but it will count down super fast and the go into negative numbers when my debug shows i have only waited say 30sec.

Also my lives text doesnt want to display my current lives.
I have referenced both my texts.

I will add my code. Instead of using 5 seconds to test im using 2 minutes.

Any help would be appreciated please.

eternal falconBOT
golden finch
#

i know this might be a dumb question but i forgor, how can i make ads (aim down sights) make less recoil? i have floatsabout recoil like recoilx, recoily and recoilz, so what i need to know is, how do i decrease one number of a float when i hold left click? and get it back to the normal when not holding left click

short hazel
#

You can multiply the value with something less than 1 to decrease the recoil

golden finch
#

alr and how do i get it back to normal?

short hazel
#

Don't multiply anymore

golden finch
#

alr

short hazel
#

The initial recoil value does not change, you just apply a multiplier to it. Or use two distinct recoil variables

golden finch
#

ok

#

so its something like, adsrecoil = 5 and recoil = 10
when holding right click recoil * adsrecoil

short hazel
#

You're mixing both systems right now

#

Either:

  • Use two variables and don't multiply
  • Use a multiplier
golden finch
#

alright

abstract finch
#

Is there paranthesis placement correct here?

direction * (_moveSpeed * Time.deltaTime)```
slender nymph
#

yes

sharp abyss
#

It adds modifiers to stats but modifiers dont change anything

sage mirage
#

Hey, guys! I want to create in my game movement before starting playing the game with my controls what I mean is I want to move my character horizontally to a certain direction and when it arrives in that direction then the game starts with me controlling that player. Can I make that somehow?

tough lagoon
#

Sure.

Disable your player controller
Move X over time
Enable your player controller

Or just emulate the input inside the player controller while ignoring inputs, which would be even better, as it would use the right animations etc automatically

sage mirage
#

@tough lagoon Can you explain it and break it down to help me understand what I am supposed to do?

bleak pasture
#

disable/enabling player controller easily found on google. Move X over time = change the transform in the update method using the gameobject.transform, time.deltatime, a speed per deltatime and direction

sage mirage
#

I know how to disable and enable player controller. I am just confused of that he said with move x over time what is that?

bleak pasture
#

so if the speed is 5 m/s and your deltatime is 0.1s it's moving 0.5 along the X axis per time unit

#

It might not look perfect at first but it's a start. I dont know how exactly to make it look perfect either but if the position update are quick enough it will look smooth regardless

sage mirage
#

So, in that way you said player will not interact for that time with the character and when character reach that destination I will be able controlling the player?

bleak pasture
#

you'd check if you are inside of pre-placed shape to know you reached the destination

#

make sure it's big enough for the character shape that is how Id do it personally (aka a trigger shape) since unity has many way to check if something is inside something. But my unity is very rusty I just came back from unity 5 - 2 days ago so hopefully someone can help with code specifics

#

You also want to wait just a little bit once the character is in the shape to return control otherwise it feels weird to the player because they have no hint of knowing / they might be confused if they can control it or not

#

with a slight delay like 1-3s it's clearer they can now move the character

sharp abyss
acoustic arch
#

not sure if this is a code problem, but my spotlight for my flashlight works fine when pointed at the ceiling or floor

#

but when at a wall

#

if the light ever touches it the whole wall becomes lit for a bit

verbal dome
#

Sounds like it is vertex lit, maybe hitting the limit for pixel lights

#

Not a code problem in any way

fierce shuttle
iron veldt
#

When I try to drag my game object prefab into my editor and assign it to a variable I get an error saying "Type Mismatch". I double checked I used the correct version of "GameObject" because it is in the scene but for some reason I am still getting this error. Anyone know how to fix this (I'm trying to drag "Player Goal" btw).

rare basin
#

you should configure your ide btw

#

!ide

eternal falconBOT
wintry quarry
golden finch
#

alr so idk whats happening, but when i put a negative value, and after i stop holding the left click, the negative value goes to a positive value, not sure what can be making this error, my text is here

eternal needle
eternal falconBOT
golden finch
#

alr

eternal needle
golden finch
#

hold up

#

recoilX and anything that has to be with the x axis

#

everything else is ok

#

ive been struggling with it for the past hour or something

eternal needle
#

well recoilX and removeRecoilx only changes when you change it in inspector, so i assume you're talking about ADSrecoilX

#

the only thing i see is that you assign it 10, but then the recoilX is -10. removeRecoilx is 5. So you can probably tell how -10 -5 becomes -15

iron veldt
#

I'm kinda confused I went to their page and it says everything is up to date and stuff how do I actually get little red underlines in my code so I know if something is wrong through visual studios?

golden finch
#

yeah but not sure if i explained the right way

#

for some reason, positive and negative make the gun go down, but positive shoudl make it go up

#

and im modifying that on recoilX

eternal needle
iron veldt
golden finch
# golden finch and im modifying that on recoilX

i think this might be the line thats making problems public void RecoilFire()
{
targetRotation += new Vector3(recoilX * ADSrecoilX, UnityEngine.Random.Range(-recoilY * ADSrecoilY, recoilY * ADSrecoilY), UnityEngine.Random.Range(recoilZ * ADSrecoilZ, recoilZ * ADSrecoilZ));
}

eternal needle
golden finch
#

sorry for my ignorance, im practically new since i started coding 2 days ago

eternal needle
eternal needle
#

that way you can understand what the values actually are rather than "should be up, should be down"

golden finch
#

ok

eternal needle
#

you can also use Debug.DrawRay or DrawLine to visualize your vectors

iron veldt
golden finch
#

something like ths?

eternal needle
#

yea

golden finch
#

ooooooh alr

#

so ill just leavei t like that

#

ill send the debug log hold on

#

holy crap it fixed

#

thanks dude

#

you saved my mental sanity

#

ive been here on my pc the entire day trying to fix it 💀

eternal needle
#

it doesnt seem like ADSRecoil is even used

golden finch
#

yea so the ADSrecoil was used to mark what recoil i had rn, first photo is without aiming, second is with aiming

#

but it was honestly useless

eternal needle
#

oh then you probably want to use ADSrecoilX instead of recoilX since thats your affected value

#

same goes for the rest of the equation

golden finch
eternal needle
#

test it with exaggerated values, like 45 as your removeRecoil

#

right now, when you ADS, it doesnt have anymore/less recoil

iron veldt
#

How do I know if my IDE is configured or not

#

because I thought I got it but when I write something wrong there is no red underline

wintry quarry
placid hare
#

!collab

eternal falconBOT
waxen adder
#

How can I make a parameter in a function optional?

#

I tried just using "optional" (using my knowledge with unrealscript), but that didn't work

frosty hound
#

You can give it a default value so that you skip supplying it as an argument when making the function call.

waxen adder
#

Ah ok, so it just needs a default value

#

I wonder if optional in unrealscript just did that for me

#

Like just look at the type and then set it to the usual default if not supplied with a value

eternal needle
#

it would be 0 in this case

waxen adder
#

^ yeah, that's what I'm thinking unrealscript did

#

with "optional" anyway

dense root
#

!code

eternal falconBOT
dense root
north kiln
dense root
north kiln
#

Debugger or logging

tender stag
#

its the DrawFieldOfViewLines function

dense root
north kiln
#

Debug.Log("Played clip");

tender stag
#

it'll only do it once

#

after you call the audio do readInput.currentWord == "";

north kiln
#

Ah I didn't realise there was code, yeah, you're playing it continuously

dense root
#

So the issue is as I suspect it's play it over and over again

#

How do I get it to only play once?

tender stag
north kiln
#

It would make more sense if you weren't calling this function repeatedly in Update

#

and instead called it when the input changed or was submitted

dense root
#

Right

tender stag
small mantle
#

I'm barely starting to make Enemy Behavior on 2D Unity. I see people using something called a Navmesh and am wondering if I should use it as a begginer. What should I do? Also will it allow me to make a enemy AI that will have pathfinding and dodge getting blocked by environment?

timber tide
small mantle
#

@timber tide Forgot to ask if there is a official Navmesh download. I don't want to accidently download a virus. If you know one that would be very helpful 🙂

timber tide
#

I think it's included with built-in, but urp you need to get the package

#

well, the newer urp versions since they've updated it a bit as of recent

small mantle
gusty void
#

hi im trying to have both a spawn and this top-down movement work at the same time. but everytime it just makes my player stand still

slender nymph
eternal falconBOT
slender nymph
eternal needle
small mantle
#

Is Navmesh plus a different package? I see other people using it on 2D and not using the that is inside Unity Register

tender stag
#

how do i make it keep the same shape no matter what the rotation is?

north kiln
tender stag
#

whats that

frosty hound
slender nymph
#

not according to your screenshots

chilly helm
#

Anybody have advise for the best way to preventing the player from being able to jump through walls and climb through jump spamming? This seems to be a common issue online but none of the fixes seem to be working.. Any advise would be greatly appriciated!

polar acorn
small mantle
frosty hound
#

Yes, I'm aware. It's a third party git repo you can download through the package manager.

small mantle
frosty hound
#

There is no built in package one

#

You can use the package manager to download git repos.

gusty void
small mantle
north kiln
slender nymph
small mantle
frosty hound
#

So you need both

small mantle
tight patio
#

Ah, I'm having significant difficulty with my decision tree; it keeps returning the same result and I don't know how to fix it.
I'm making a cardgame AI that's supposed to return up to three possible different results, but I keep getting one result over and over. Could someone please take a look at my code and tell me where I screwed up?

vapid cypress
#

Quick question if anybody knows the answer.
I have a build file that has audio in it, I am following along with one of the tutorials and when I build and run the project the audio works but in the Scene and game views it doesn't, even when I press play and everything.
I have attached images showing that I am not muted and that it is not volume 0 as well.
Any help would be greatly appreciated!

Edit: Apparently the tutorial files didn't have an audio listener attached to the body of the model sooo

teal viper
tight patio
#

This is what I'm getting back, though if I'm honest, I don't know how to get the ToString to be more useful than this

#

As you say though, I'll run through and check if Randomly chosen value is the same every time

teal viper
small mantle
#

Need a bit help understanding NavMesh SetDestination(). How can I adjust the speed it goes to the target? ```agent.SetDestination(target.position);

tight patio
#

Hmm, this time it returned 0... that seems a bit low, since if I'm getting 0s and 1s consistently, then that means totalweight isn't being added to

teal viper
tight patio
#

Hmm, it seems to be going into the revolt leaf each time, but the randomly chosen value is always 0 or 1, which is the values if totalweight is 0, meaning nothing's getting added to it right, even when it reaches a binary node pair that should be weighted

#

but what I'm confused about is how it's getting there to begin with because the only place that should consistently have a revolt leaf is if the hand value is exceptionally good, which isn't the case

small mantle
tight patio
teal viper
tight patio
#

Right, I'm doublechecking as we speak.

teal viper
#

Probably an issue with variable captures. Value types are probably staying the same as when you create the delegates.

tight patio
#

(Sorry, this is taking longer than expected, I had to figure out what candidates were getting added by reworking the class a bit)

#

Ok, I think I figured it out actually, thank god

#

the gist of it was that the poorcheck seems bugged currently, and it always assumes the player is too poor to retreat, thus always returning the same result

#

it never even made it into the other nodes

queen adder
#

hi, is there a way to store different scripts in the same variable.
i want different type of scripts to be stores in each variant of the scriptable object.

#

like a generic variable that accepts different classes maybe?

timber tide
#

you can do generics but you'd have a concrete type for each SO

#

are you sure you just don't need inheritance?

pulsar lodge
#

Battle Manager - https://gdl.space/qusufiqula.cs
Spell Button - https://gdl.space/bogevowexo.cpp

Hey guys, I'm having an issue with these spell buttons i am instantiating, For some reason the on click event is not executing, I do have an event system in the scene. It looks like all the variables are populating correctly in the inspector but for some reason nothing happens when i try and click it. Not sure if it is somethhing wrong with the code or not. I copied the code for creating the buttons from another section of code when creating the enemy buttons and those work fine.

queen adder
timber tide
queen adder
dense root
#

How do I set my text to the following?

if (placeholderWords.Count == 0)
{
    Debug.LogWarning("No more words in the list.");
    inputField.placeholder.GetComponent<Text>().text = "No more words in the list!";
    return null;
}
polar acorn
#

Set the value of the input field rather than the placeholders text

dense root
#

sorry wdym by set value of input field

#

I thought this is how you would set the placeholder text value, it works for my other methods

#

i.e.

public void SwapPlaceholderText(string newPlaceholderText)
{
    inputField.placeholder.GetComponent<Text>().text = newPlaceholderText;
}
hasty spire
#

what would be the best way to get my jumping and falling animation to play i tried with velocity but given my platform isnt flat it keeps triggering at the wrong time

queen adder
hasty spire
#

it keeps triggering

#

should i just raise the threshold?

queen adder
#

you can try to add an overlap circle beneath the player and if it's colliding don't play the animation

queen adder
summer stump
#

As Moe said, you definitely want a grounding check

summer stump
# hasty spire how would i do that?

Raycast() or OverlapCircle()
Use a layermask to only check if it's on the ground layer
If they return values showing it hits the ground, then you are on the ground, and you should not use the jump OR fall animations

timber tide
queen adder
# hasty spire how would i do that?

create an empty, put it at player's feet
adjust the variables to suit your script

var hitCollider = Physics2D.OverlapCircleAll(empty.transform.position, Radius, 1 << LayerMask.NameToLayer("Ground"));
if (hitCollider.Length == 0 && velocity.y > jumpingThreshold) // Play jumping animation
else if (hitCollider.Length == 0 && velocity.y < fallingThreshold) // Play falling animation
pulsar lodge
#

the CastSpell() method

#

it is like the buttons are not even interactable, almost like an eventSystem isn't present, but it is. Does it matter that the buttons are instantiated after the event system already exists?

hasty spire
queen adder
timber tide
queen adder
hasty spire
#

also, is the empty game object a child of the player?

queen adder
queen adder
hasty spire
#

right let me try that

hasty spire
queen adder
weary moss
#

How do i set an object's rotation to 0?

weary moss
#

Thx

queen adder
#

my VS Code editor keeps giving me almost 30 errors saying that (This project is not supported in C# Dev Kit.) how do i fix this?

#

here is the output

#

from the console

teal viper
#

!code

eternal falconBOT
teal viper
#

And !ide

eternal falconBOT
queen adder
#

i've done everything listed on the !ide and it didnt work

eternal falconBOT
queen adder
#

specifically the one in VS Code

summer stump
#

If you wanna show the log, use the instructions above

small mantle
#

I have an enemy that is able follow the Player. It does this when it is in the distance of the Player, but when it isn't it stops. However, I don't want a full stop when the player exceeds the Distance from the Enemy. I want the Enemy to keep following for a few moments just in case he can catch up in time, and if it does then it keeps moving. ```cs void DetectPlayer() {

   distanceFromTarget = Vector2.Distance(transform.position, target.position);

    if (distanceFromTarget <= distance) {
        FollowPlayer();
    }
    else {
        StopFollowingPlayer();
    }

} ```
queen adder
#

these are all the extensions i have

#

sorry if this isnt in a good format

summer stump
#

Oh sorry, the image expanded when I clicked on it. You do have the right extensions

queen adder
#

yeah

summer stump
#

Ok, and packages?

queen adder
#

i think from the sheer amount of em i think would be flagged as spam

#

let me see if i can find a way to show them to you

summer stump
queen adder
summer stump
#

Ok, good. Right version.
But you should remove the Visual Studio Code Editor package

#

Now show the External Tools window

queen adder
queen adder
#

also sorry for ping

summer stump
queen adder
#

how do i remove engineering feature?

#

ah i figured it out myself

#

ive done what you said and i get the same exact thing

#

28 errors and broken syntax highlighting

shell zealot
#

!ide

eternal falconBOT
shell zealot
#

hello, I was wondering, what exactly is the difference between installing VS community edition manually and then using it with Unity versus just installing Unity Hub, and adding VS community edtiion as a module?

#

Are there any pros and cons in or the other?

summer stump
# shell zealot !ide

They were already linked to that

Edit: oh, did you do that for yourself? Sorry

summer stump
queen adder
#

what do you mean by sdk error?

summer stump
queen adder
#

ah

#

yes

summer stump
#

If it is still there when you reopen, you need to manually get the sdk and restart again
(A restart is required to automatically set the PATH. You can do it manually, but you need to know what you're doing to get it right)

#

It SHOULD have been installed with the c# dev kit extension though (but sometimes fails to)

unreal imp
#

Hello friends, I have a little problem and it is that when I shoot upwards and I am crouched the bullets go in the opposite direction from where they are pointing as if they were going towards the direction inside the player and I think that the code has something to do with it ``` private void Shoot()
{
audi.Play();

    Ray ray = fpsCam.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
    RaycastHit hit;
    
    
    Vector3 targetPoint;
    if (Physics.Raycast(ray, out hit))
        targetPoint = hit.point;
    else
        targetPoint = ray.GetPoint(1000); 

    
    var bullet1 = Instantiate(bullet, muzzle.transform.position, transform.rotation);
    bullet1.GetComponent<Rigidbody>().velocity = (targetPoint - muzzle.transform.position).normalized * shootForce;
}```
waxen adder
#

For anyone who uses visual studio. When using find and replace, is there some way to allow any character when filling in find? Kinda hard to explain, so I'll just show what I want:

Original find/replace
Find: dog1 is silly
Replace: dog1 is goofy

What I want
Find: dog[any character] is silly
Replace: dog[same character] is goofy

gentle moat
queen adder
gentle moat
#

but wherr

summer stump
# gentle moat but wherr

Wherever you want. At the end of update or start of FixedUpdate (using Normalize()) or in the MovePosition on line 26 using the property

timber tide
#

How is rigidbody accepting a float here for rotation

summer stump
#

It really doesn't matter much where as long as it's after the getaxis and before the move call

#

Oh hey, look at that (what Mao said) haha. Missed that.
Is that not giving you an error?

abstract finch
#

Is there a way to have a float be tracked in another script? I have a float called timeElapsed but i would like to track it in a seperate coroutine via a parameter or track this value.

teal viper
#

Or just use the reference to the instance that contains the float.

abstract finch
teal viper
#

A variable outside the coroutine wouldn't be local anymore - it would be a class member/field, but yes it would require that.

gentle moat
cerulean bramble
#

I'm having trouble finding any help on what to do if I want to read files from a folder in the game once built

#

does anyone know how to do that or anything I could reffer to for help?

iron veldt
#

Alright so I know I can't reference scene objects in the inspector for a prefab but how am I supposed to drag "Player Goal" and assign it to player goal in my script without getting this mismatch error?

#

And yes I configured my IDE as I was told to do earlier, and there aren't any errors popping up in my script

queen adder
#

Does anyone know how to save my game's details for the next time it's played?

#

I can't use player prefs for everything.

#

Is it possible to save things like transforms, positions of all enemies and things in Unity?

#

Does it require an asset?

#

What are some good assets for this task?

timber tide
#

Need to serialize your data usually by json then when you relaunch the game you deserialize it all

queen adder
#

Instead of GameObject?

#

Such as public GameObject goal?

#

Instead of public Prefab goal?

timber tide
queen adder
#

Thank you!

timber tide
#

Basically, everything you want to save should have its own data container class

#

then you write all that data as json

queen adder
#

The class?

timber tide
#

It's just data that you'd repopulate the next time you start the game. You'll have to have a custom load manager as well to know what type you're populating this data into.

queen adder
#

Appreciate it

timber tide
# queen adder Ah I'll have a look, thanks

Ideally you'd want to ID your SOs too so you can populate your save-specific data objects with those IDs. This also helps by identifying types upon deserializing your data, otherwise you can split types by directory or just type check.

#

Having a dictionary of your SOs to compare IDs will just allow quick lookup to reinstantiate and populate your objects

queen adder
# iron veldt

What do you mean then? What's the point of making playerGoal = GameObject.Find("Player Goal"); if you want to set it in the editor?

#

If you want to set it in the editor by dragging, first step is to delete that line.

summer stump
queen adder
summer stump
#

At the LEAST use the type version. But if you can, never use Find

gaunt ice
#

first !ide

eternal falconBOT
iron veldt
eternal needle
safe hull
#

If I wanted to create a script that is assigned to each individual object in a seed based generation map, which has its own type, hit points, drops, etc, should I use enums or class?

#

I don't completely understand how unity works, but I want to create an instance of the class for each object

#

does this mean adding the script component to each object?

#

does that accomplish what I'm trying to do?

summer stump
summer stump
summer stump
safe hull
#

I want to make the code as efficient as possible

summer stump
iron veldt
#

like just targeting it and going in that direction

summer stump
safe hull
iron veldt
#

well it's saying I need to install the unity extension, but when I go to click install nothing happens so I'm kinda stuck right now

summer stump
safe hull
#

I mean script

summer stump
# safe hull I mean script

Sure if you want. Really doesn't change anything. It's personal preference.
I do when it makes sense, and don't when it doesn't

safe hull
dreamy light
#

Hello, I'm trying to make a movement system in the style of the collide and slide algorithm but the walls kill all velocity and the ramps make you much faster

This is the script:
https://hastebin.com/share/agoqurucad.csharp

#

one sec

#

meant that to be mp4

safe hull
#

bruhh does unity srsly have accessibility incompatibility

#

I can't make variable unaccessable except through method

#

    public ObjectType getObjectType()
    {
        return objectType;
    }```
#

I don't want the variable itself to be accessable directly, I only want it to be accessed through the get method

#

because I don't want the objectType to be changed

summer stump
safe hull
#

okay then, what is that?

summer stump
#

public ObjectType objectType { get; private set; }

safe hull
#

[SerializeField] private static ObjectType objectType { get; private set; } = new ObjectType();

summer stump
#

Is ObjectType a class?

safe hull
#

yes

#

huh

summer stump
#

Ok then, sure

safe hull
summer stump
#

Oh, it has to be public

safe hull
#

alright

summer stump
#

Wait, you said it was a class

#

That is an enum

safe hull
#

yes

#

sorry

#

its a script

#

as well

summer stump
#

So then you don't do new on it

summer stump
safe hull
#

ok

summer stump
#

Classes, Structs, Enums, Types in general are what matter

safe hull
#

alright

#

a class is a method, right?

#

why am I being so dumb rn

summer stump
#

At the top where you write public class ObjectData

safe hull
#

public class ObjectData : MonoBehaviour this is a class

summer stump
#

ObjectData js a class

#

Yes

safe hull
#

public ObjectType getObjectType() this is a method

summer stump
#

Yes

#

You don't really need getObjectType with the property though

safe hull
#

I'm still getting inconsistent accessibility

safe hull
summer stump
#

public ObjectType objectType { get; private set; }

data.objectType

#

You can just get it directly

safe hull
#

and I can't edit it?

summer stump
#

It is publicly accessible