#💻┃code-beginner

1 messages · Page 15 of 1

tender stag
#

dont add it to the inventory again

#

like it did here

#

like it jumped to the first slot

wide silo
#

Yea he is using visual studio code so that makes me think maybe he didn't download the cs language

tender stag
#

so here i need to somehow check if there is going to be remaining amount after you would add to the inventory, and if so you just subctact the amount and refresh the cell

#

and is its more then you Remove()

#

i think

timber tide
#

The red circle, you're removing and readding is what I'm not understanding. You should be changing the value on the item in the slot as to where it's at and only removing if the value remaining is 0.

tender stag
#

because i pass in cells

#

to the add method

#

so if you quick stack on a hotbar slot

#

you add to the inventory cells

wide silo
#

I got a better idea why not keep the value of the cells add it to the one in the inventory then remove the first one

tender stag
#

which are these

wide silo
#

Yea so from my understanding if you remove it than add it to the inv it will add 0

#

(i didn't read and analyse the the script tho)

timber tide
#

Is that what's going on? You got the value on the cells and not the items?

tender stag
#

what do you mean value

#

the amount?

wide silo
#

Yup

tender stag
#

its on the Item

#

the cell holds the Item object

#

i just hide it in the world when a player picks it up

#

and show it when he throws it out

wide silo
#

Ok i get it

tender stag
#

when splitting items in the inventory i instantiate a new one

wide silo
#

But what about the amount of that item

tender stag
#

set the amount to half

wide silo
#

Ohh

#

I thought u split the same item

tender stag
#

it is the same item

#

its a copy

#

look

wide silo
#

Ye that's what i meant

timber tide
#

you dont need to make a copy

#

unless it's a new cell

#

rather, if you split it

tender stag
#

thats not important tho

#

but this is how it works

#

you see when i picked up the item, it got set not active in the hierarchy

#

and when i split the item a new one gets instantiated

#

anyway im going to sleep

#

i spent like the whole day and its still not working

timber tide
#

Well, from what I can see is that you're readding it to the inventory after stacking. That is something you should look into and see if you can manage just deducting from the original item's stack amount, and if that amount is reduced to 0, just delete that instance.

wide silo
#

Wait

#

Why not instead of deleting the old cell

tender stag
#

thats for stacking items

#

it destroys the instance when the item you are adding can fit into an existing stack

wide silo
#

Okay

#

Nah nvm

#

My idea sucks when i looked forward

timber tide
#

Alright, but here it looks like you're readding it to the inventory when the stack isn't depleted fully and that's the problem. If you're using some temporary instance to do this operation, then you need to carry over the previous item slot index I guess.

wide silo
#

Imma read the whole thing

tender stag
#

see ya guys

timber tide
#

later

tender stag
#

and thanks

summer stump
silent ember
#
    [SerializeField]
    Rigidbody2D rb2d;
    [SerializeField]
    Rigidbody2D spriteRb2d;
    float LifeTimer = 0;
    public float Range;
    public float flySpeed;

    private void Awake()
    {
        spriteRb2d.angularVelocity = -1500;
        Debug.Log("I should be spinning");
    }

    private void Update()
    {
        LifeTimer += Time.deltaTime;
        if (LifeTimer < Range)
        {
            rb2d.velocity = transform.up * flySpeed;
        }
    }
fickle plume
silent ember
fickle plume
#

Ah, you set it in awake. Do you get a delay for your debug message there as well?

fickle plume
#

Have you tried with lower angular velocity? Maybe you are breaking speed limits.

silent ember
#

oh that's a thing?

#

anyways, I tried setting it to only -100 but theres still delay

wintry quarry
#

The default limit is 7 rps I think? Which would be like 2520

wintry quarry
silent ember
fickle plume
#

If you are still struggling with this, test things in isolation. Use a clean scene and test that physics initializes properly there and everything works as expected, then start narrowing down what can cause it in your original one.

silent ember
sage lotus
#

I must suck at Google. Been searching

struct I would only want to use for temp bits of data like if a collider is colliding right?

#

But I dint understand why I wouldn't use a bool in that case

buoyant knot
#

no

sage lotus
#

Is there an immediate benefit of using a struct vs a class?

#

Oh sorry. Thanks fir the reply. I'll wait

buoyant knot
#

structs are value type. classes are reference type

#

that is the main difference to work with

#

as the name implies, struct is short for “data structure”

sage lotus
#

Oh so if I won't need to reference outside of the script then I can safely use a struct to do things like control camera behavior on collision

buoyant knot
#

yeah. for example, vectors and collisions are very great examples of structs

polar acorn
# sage lotus Is there an immediate benefit of using a struct vs a class?

Structs are immutable, and passed by value. If you have a variable with a struct type, it holds the data right there, rather than a pointer to the data elsewhere. This means structs are very efficient to create and discard, no allocations or freeing of memory required. It also means that if you have a lot of data in it, it takes up a lot of memory in the heap. There is a point, different on different machines, where the speed gained from skipping the allocations is less than the speed lost dealing with passing things to and from the heap.

Basically, for small amounts of data, structs are faster. For large amounts of data, classes are faster. If you need to have multiple variables affecting the same data, classes must be used.

buoyant knot
#

Mathf is a great example of a struct that makes no sense being a struct

polar acorn
#

Another artifact of old unity

buoyant knot
#

just in case he sees things that are structs or not, and is confused

sage lotus
#

I'm so new to all this, I appreciate you guys explaining it to me

buoyant knot
#

generally speaking: if you expect to need changes during the lifetime of the object, you should use a class. UNLESS the object is so extremely simple ans small, that you can afford to make a whole new one cheaply every time you want to “modify” it

sage lotus
#

although I'm a bit confused still on the Mathf bit. Mathf I've only seen used in equations so far and don't fully understand what the meaning that it's a struct is

buoyant knot
#

because you can’t modify a struct. you’re basically making a whole new one

buoyant knot
sage lotus
#

perfect. sounds like that's the way to go if I want a Zelda style behind the back camera

buoyant knot
#

that is a great example of a struct that has no business being a struct

sage lotus
#

oh i think i get it. so Mathf you wouldn't put into struct something something mathF

buoyant knot
#

On example I have of a struct is CardinalIntensity, which is a small struct which holds 4 ints. One for up/down/left/right

#

and I do a fuckload of math with it, and NEED operations on it to be blazing fast

#

needs to be a struct

#

COULD be a class, and I could make everything work. But it is a classic example of a time NOT to use a class

sage lotus
#

possible, but unoptimized.

#

noted

queen adder
#

can somebody help me? im trying to enable a game object by clicking the key tab, no errors in the output but doesnt work, ```cs
using UnityEngine;
using UnityEngine.InputSystem;

public class LeaderboardEn : MonoBehaviour
{
public GameObject objectToToggle;

private bool isTabPressed = false;

private void Update()
{
    if (Keyboard.current.tabKey.wasPressedThisFrame)
    {
        isTabPressed = true;
        if (objectToToggle != null)
        {
            objectToToggle.SetActive(!objectToToggle.activeSelf);
        }
    }
    if (Keyboard.current.tabKey.wasReleasedThisFrame)
    {
        isTabPressed = false;
    }
    if (!isTabPressed && objectToToggle != null)
    {
        objectToToggle.SetActive(false);
    }
}

}```

sage lotus
paper bridge
summer stump
summer stump
paper bridge
#

ah k

queen adder
summer stump
queen adder
celest fable
#

When I move, my player vibrates and idk why ;-;

public class PlayerController : MonoBehaviour
{
    private float speed = 10.0f;
    private float turnSpeed = 10;
    public float xRange = 4;
    private bool walking = false;
    public float horizontalInput;

    void Update()
    {
        horizontalInput = Input.GetAxisRaw("Horizontal");

        if (Input.GetKeyDown(KeyCode.Space)) {
            walking = !walking;
        }
        if (walking)
        {
            transform.Translate(Vector3.forward * Time.deltaTime * speed);
            transform.Translate(Vector3.right * Time.deltaTime * turnSpeed * horizontalInput);
        }
        if (transform.position.x > xRange)
        {
            transform.position = new Vector3(xRange, transform.position.y, transform.position.z);
        } else if (transform.position.x < -xRange)
        {
            transform.position = new Vector3(-xRange, transform.position.y, transform.position.z);
        }
    }
}

And then I have a script for the camera to follow it

public class FollowPlayer : MonoBehaviour
{
    public GameObject player;
    private Vector3 offset = new Vector3(0, 5, -6);

    void Update()
    {
        transform.position = player.transform.position + offset;
    }
}
queen adder
#

hmm

#

alright

queen adder
#
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private float speed = 10.0f;
    private float turnSpeed = 10;
    public float xRange = 4;
    private bool walking = false;
    private Rigidbody rb;

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

    void Update()
    {
        horizontalInput = Input.GetAxisRaw("Horizontal");

        if (Input.GetKeyDown(KeyCode.Space))
        {
            walking = !walking;
        }
    }

    void FixedUpdate()
    {
        if (walking)
        {
            Vector3 movement = Vector3.forward * speed * Time.fixedDeltaTime;
            rb.MovePosition(transform.position + movement);
            Quaternion turnRotation = Quaternion.Euler(0, horizontalInput * turnSpeed, 0);
            rb.MoveRotation(rb.rotation * turnRotation);
        }
        rb.position = new Vector3(Mathf.Clamp(rb.position.x, -xRange, xRange), rb.position.y, rb.position.z);
    }
}
celest fable
#

well it fixed the vibration when i move forward but now i just rotate in place nad dont move when i press a and d

queen adder
#

send vid

celest fable
queen adder
#

alright

#

give me a minute

#

to try and fix

celest fable
#

👍 '

queen adder
#
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private float speed = 10.0f;
    private float turnSpeed = 100.0f;
    public float xRange = 4;
    private bool walking = false;
    private Rigidbody rb;

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

    void Update()
    {
        horizontalInput = Input.GetAxisRaw("Horizontal");

        if (Input.GetKeyDown(KeyCode.Space))
        {
            walking = !walking;
        }
    }

    void FixedUpdate()
    {
        if (walking)
        {
            Vector3 movement = Vector3.forward * speed * Time.fixedDeltaTime;
            rb.MovePosition(transform.position + movement);
        }
        float rotation = horizontalInput * turnSpeed * Time.fixedDeltaTime;
        Quaternion turnRotation = Quaternion.Euler(0, rotation, 0);
        rb.MoveRotation(rb.rotation * turnRotation);
        rb.position = new Vector3(Mathf.Clamp(rb.position.x, -xRange, xRange), rb.position.y, rb.position.z);
    }
}
#

try now

celest fable
#

does the same thing just rotates much slower

queen adder
#

AUGGHHH

#

ok

#

change the speed to, 1000.0f

#

the turn

#

speed

#

oh wait

#

OHH

celest fable
#

i want it to just move left and right like physically in the world when I press a and d I had it working fine before but then it just like

queen adder
#

ok

#

1 sec

#
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private float speed = 10.0f;
    public float xRange = 4;
    private bool movingLeft = false;
    private bool movingRight = false;
    private Rigidbody rb;

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

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            movingLeft = true;
            movingRight = false;
        }
        else if (Input.GetKeyDown(KeyCode.D))
        {
            movingLeft = false;
            movingRight = true;
        }
    }

    void FixedUpdate()
    {
        if (movingLeft)
        {
            rb.velocity = new Vector3(-speed, rb.velocity.y, 0);
        }
        else if (movingRight)
        {
            rb.velocity = new Vector3(speed, rb.velocity.y, 0);
        }
        else
        {
            rb.velocity = Vector3.zero;
        }
        rb.position = new Vector3(Mathf.Clamp(rb.position.x, -xRange, xRange), rb.position.y, rb.position.z);
    }
}
#

try

#

@celest fable

celest fable
#

diditn work

#

ill figure it out dw abt it

queen adder
#

what happened

#

to it now

celest fable
#

it worked fine but once you pressed a or d it wouldnt stop moving that direction if you only tapped it once

queen adder
#

alright

celest fable
#

and you had to press the opposite direction to make it move

queen adder
#

u can modify it

#

i guess

#

oh wait

#

mb

#

lol

celest fable
#

ty for ur help 👍

inland canopy
#

can someone help me with canvas as when i select a child image i cant see the canvas

inland canopy
#

like i wasnt to set up buttons when i select the button i cant see the screen area so i dont know how will i anchor the buttons according to the screen

rich adder
inland canopy
#

like when the canvas is selected i can see the outer layer but it disappers when i select the image

rich adder
inland canopy
#

it works now. Thanks for the help!

hot hinge
#

hey the tutorial guy told me to make a camera script so if i rotate the camera doesn't rotate with me and it's all basically the same and it's working fine except the fact that i don't want the camerae to completely center around the player and i want it to be a higher and more to the right like a super mario game how do i write that in the code

celest fable
#

im trying to make the gold bars destroy after they are 6 units behind the player, but it only spawns like 2-5 before it gives up and stops

#

i have this script on my gold bar prefab

public class DestroyOffScreen : MonoBehaviour
{
    public GameObject player;
    private int i;

    void Update()
    {
        if (transform.position.z < player.transform.position.z - 6)
        {
            Destroy(gameObject);
        }
    }
}

and this is my spawn manager

public class SpawnManager : MonoBehaviour
{
    private int spawnRange = 4;
    public GameObject[] prefabs;
    private float startDelay = 2.0f, spawnInterval = 0.5f;

    // Start is called before the first frame update
    void Start()
    {
        InvokeRepeating("SpawnBar", startDelay, spawnInterval);
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void SpawnBar()
    {
        Vector3 spawnpos = new Vector3(Random.Range(-spawnRange, spawnRange), 0, transform.position.z + 20);
        Instantiate(prefabs[0], spawnpos, prefabs[0].transform.rotation);
    }
}
hot hinge
#

why does thta look like a mobile game ad

celest fable
#

im trying ot copy flop one of them to learn how to use untiy

hot hinge
#

oh cool

rich adder
rich adder
celest fable
rich adder
celest fable
#

its in my scene

#

is that why?

#

i was using the one from te scene cuz If i used the one from my project fodler the scale wasnt right and idk how to change it

rich adder
celest fable
#

ohhh

rich adder
#

you should have an option to apply all changes to prefab

celest fable
#

ohh i see

celest fable
#

im so lost i dont konw what im doing wrong ive done waht you said but they arent despawning at all

#

let me record a vid of it

rich adder
#

not sure what exactly that Player prefab is doing in there

#

in gold bar

celest fable
#

oh that was some dumb shit i forgot to remove it

#

i was trying to make it not spawn if you werent moving but I gave up and forgot to remove it

rich adder
celest fable
#

nope

rich adder
#

whats the current code for the bar

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

public class DestroyOffScreen : MonoBehaviour
{
    public GameObject player;

    void Update()
    {
        if (transform.position.z < player.transform.position.z - 6)
        {
            Destroy(gameObject);
        }
    }
}
#

thats the only script it has on it

rich adder
#

oh, which one is the pickup script then

celest fable
#

there is no pick up script yet i am not there yet

rich adder
celest fable
#

they are not despawning when they are off of the screen

rich adder
celest fable
#

wait I have an idea let me

#

hold on

#

nvm

rich adder
#

the one from the scene

#

you can't put player prefab in there, it wont work

#

and you can't put scene objects in prefabs

rich adder
# celest fable nvm
public class GoldBar : MonoBehaviour
{
    private Transform player;

public void Init(Transform p)
{
  player = p;
}
    void Update()
    {
        if (transform.position.z < player.position.z - 6)
        {
            Destroy(gameObject);
        }
    }
}```
celest fable
#

NRTJNU89TE09W3K4T09WLTTHP,TGPOJN,EDTJMPTGM,JDTGOLJ

#

im ghonnalsoe itomg

#

gomg

#

imso

#

bad at htis

rich adder
#

wat?

celest fable
#

nothign

#

jsut tired and

#

yeha

rich adder
#

maybe take this on after some rest

#

coding tired is never good

celest fable
#

no thank you

rich adder
#

ok

frozen dagger
#

whats wrong?

rich adder
#

hmm that line number doesnt make sense

polar acorn
rich adder
#

are you sure this saved changes?

frozen dagger
#

yeah

#

there is no errors in code

#

smth is wrong

rich adder
#

NRE are runtime errors

frozen dagger
#

actualy means what this is problem not with my code?

rich adder
#

probably haven't assigned a field

polar acorn
#

Save the script, clear the console, and run it again

#

Get the real line number

rich adder
#

^

frozen dagger
polar acorn
rich adder
#

anyway you're using animator but doesn't seem is assigned in inspector

frozen dagger
polar acorn
frozen dagger
rich adder
#

where did you assign it

polar acorn
#

Show where you assign animator

frozen dagger
#

i did

polar acorn
frozen dagger
#

damn...

summer stump
# frozen dagger

That is a declaration, not assignment. Common confusion between them

frozen dagger
#

i forgot to put script on icon, i put it on health bar...

rich adder
frozen dagger
#

wait...

rich adder
#

just make an inspector field for it and assign it like the rest of the references you have there..

frozen dagger
#

i didnt awake it...

rich adder
#

no need for any of that jazz

frozen dagger
#

it keep sending me errors...

polar acorn
frozen dagger
#

-_-

#

i set it on an function instead of void start()...

#

finnaly fixed

#

thanks

fair steeple
#

Hey why am I getting this error? seriously makes no sense

summer stump
fair steeple
#

Fixed it

#

I thought it would be assigned since I'm assigning it a valuse inside the if loop

cosmic dagger
light moss
#

How am I able to make a 1up system in Unity that if my Player collects 100 coins he will earn a 1up. Is there a video tutorial or anything?

fair steeple
#

meant switch

summer stump
cosmic dagger
fair steeple
summer stump
fair steeple
#

Nope

#

Is it necessary?

summer stump
# fair steeple Is it necessary?

If you don't, there is potential it won't be set. That's what the compiler is warning there. There IS a situation where it would never be assigned to

light moss
rich adder
cosmic dagger
rich adder
#

it's gonna be some basic == really

frozen dagger
frozen dagger
#

when true, script does not work

rich adder
#

probably because you're not using OnTriggerEnter

summer stump
frozen dagger
#

i didnt know about this function-

#

okay, thanks

rich adder
#

share full thing

gaunt ice
#

you use oncollisionenter to detect a triggered collider

rich adder
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

trim cedar
#

guys i think i am going insane what am i doing wrong
Here is my code

Debug.Log(index);
Debug.Log(objectives[index].objectiveName);
objectives.RemoveAt(index);

and here is my log

trim cedar
#

nuh uh

#

look at the second log

#

it prints the name of the objective

#

which is the item at that index

frozen dagger
gaunt ice
#

you use oncollisionenter2d

#

next time share the whole method

rich adder
#

also show full console window without cropping

trim cedar
rich adder
#

show console window with the error expanded

trim cedar
#

nah cuz that just destroys the game object, and i was getting the error before that

gaunt ice
#

you remove somthing from list in foreach loop?

cosmic dagger
# trim cedar

the line number is 77: objUI.UpdateObjectiveUI(objectives[i].objectiveName, objectives[i].objectiveInt, objectives[i].targetInt); . . .

cosmic dagger
# trim cedar

also, if you're storing the index to use a foreach, just do a for loop instead . . .

gaunt ice
#

he use a go for parent i guess

trim cedar
#

yeah i didnt realize i needed the index until after i made the loop so i just got lazy 💀

cosmic dagger
#

make sure objectives has items in its list . . .

gaunt ice
#

btw completeobjective maybe called in foreach loop and it removes element from the collection which iterated in foreach loop

rich adder
#

also why 3 params for the same item , just pass the item directly

trim cedar
#

u right i definitely wrote that at like 3 am

rich adder
#

😆 it happens

cosmic dagger
#

no, never. don't do that . . .

gaunt ice
#

though you will break the foreach loop once you find the target, but still you should avoid modify the collection in foreach loop

sullen rock
#

This might be a very wrong take, but to me, foreach feels barely useful, there isn't much it can do over a for loop, or I wrong?

#

I suppose it's more readable

wintry quarry
#

It's just syntax sugar for a for loop though

sullen rock
#

I tend to completely avoid it, since I might realize I need to index Im on later down the line, which would mean rewriting the loop

wintry quarry
#

Rewriting the loop is simple

#

Start with the simple thing

#

Don't do the complex thing until you need it

#

Rewriting stuff is normal

#

Ever hear of YAGNI?

sullen rock
#

you arent gonna need it?

frozen dagger
wintry quarry
#

Something is null on that line that you are trying to use

gaunt ice
#

the reference becomes null when he start play mode

frozen dagger
#

if (other.gameObject.CompareTag("spike"))
{
healthBar.TakeDamage(1);
}

wintry quarry
#

Probably their code is setting it to null then

sullen rock
#

but I see what you are saying

frozen dagger
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

wintry quarry
frozen dagger
gaunt ice
#

line 36 (start())

wintry quarry
#

healthBar = GetComponent<HealthBar>();

#

Why are you doing this

#

This making it null

frozen dagger
#

wait

#

uhh

timber tide
#

You're getting component but setting the healthbar elsewhere

wintry quarry
#

If you intend to set it in the inspector this is pointless and actually harmful

#

Since it's setting it to null

#

Just delete that line

frozen dagger
#

i forgot to cut it when i was testing code

#

finnaly fixed, thanks

rich adder
main flame
#

Hey, I'm trying to make an area on the ground where the player slides, how can I detect the player being in that area?

#

I tried using colliders but I don't want it to be collidable

ashen ferry
#

just make it a trigger

main flame
solar tide
#

Okay some questions relating Linecast.
I'm making a board game and I used Physics.linecast to find the objects next to my selected Unit. But the problem now is that if there are two objects surrounding my SelectedUnit, the linecasts hit only one of them and not both of them.
I thought I was making 4 line casts with my code but it seems I was wrong.

#

I wanna be able to detect and hit all objects surrounding my SelectedUnit in 4 directions

ashen ferry
#

is there a reason ur not using physics.SphereCast? you would get surrounding units in single run

light moss
#

Can someone please help me. I am trying to have it that when the player dies his 1up counter (top right) gets decremented. However when the player collects 2 coins the 1up counter gets incremented. However when the player does get 2 coins the coin counter gets to 6. Instead of Lives + 1.

ashen ferry
light moss
#

I know, the thing is, is that I have no clue on how to do that

ashen ferry
#

I would however move that logic to player itself and OnTriggerEnter see what kind of trigger it entered

uncut shoal
#
                    Debug.Log("Local Anchor: " + eAnchor.x + ", " + eAnchor.y);
                    var anchor = LocalToPixel(eAnchor);
                    Debug.Log("Final Anchor: " + anchor.x + ", " + anchor.y);``` why is this returning the wrong thing?
#

I'm making per-pixel destruction and trying to move the joint from the parent object that was just cut into several bits into the part with the joint

#
    {
        point = new Vector2(Stuff.RoundFloat(point.x, 3), Stuff.RoundFloat(point.y, 3));
        int x = Mathf.CeilToInt(Stuff.RoundFloat((((point.x - pixelSize / 2) / (pixelSize * size.x)) + 0.5f) * size.x, 3));
        int y = Mathf.CeilToInt(Stuff.RoundFloat((((point.y - pixelSize / 2) / (pixelSize * size.y)) + 0.5f) * size.y, 3));
        return new Vector2Int(x, y);
    }``` this is what LocalToPixel is
#

it works just fine anywhere else

#

but here it isn't working at all

#
    //Example: 1.48398183817, roundPoint = 3
    //Result: 1.484
    public static float RoundFloat(float value, int roundPoint)
    {
        float point = 10 ^ roundPoint;
        return Mathf.Round(value * point) / point;
    }``` this is `Stuff.RoundFloat` too
#

I tried to use LocalToPixel somewhere else and it works just fine

#
    {
        Debug.Log(LocalToPixel(new Vector2(Random.Range(-2.5f, 2.5f), Random.Range(-2.5f, 2.5f))));
    }```
#

its fine anywhere else but not here

ivory bobcat
uncut shoal
#

it becomes weird after I use the LocalToPixel function

ivory bobcat
#

I doubt rounding is the issue. Likely your computation (subtraction/division) of some arbitrary value.

ivory bobcat
uncut shoal
#

if I use the exact same values of these vectors somewhere else

#

in local to pixel

#

it works just fine

#

but here it doesn't for some reason

ivory bobcat
ivory bobcat
uncut shoal
#

the function is kind of a single line.

uncut shoal
#

what function

#

the local to pixel?

uncut shoal
#

do I now just log the value after each operation

#

OOH

#

I realized the issue

ashen ferry
#

I would see what float point = 10 ^ roundPoint does cause wtf

uncut shoal
#

its not about this function

ivory bobcat
#

If you're not certain of your math/numbers..

uncut shoal
#

the issue is that size.x isn't set.

#

size.y isn't too

#

since I set that AFTER this code is run.

#

I am very smart I know

#

thanks

cursive tangle
#

how to snap this type please help me

uncut shoal
#

ok this works!

#

thanks for the help guys

supple wasp
#

How did you do it

cursive tangle
#

what

supple wasp
#

The one to move the cubes

rich adder
supple wasp
#

Is there a video or script to do that?

cursive tangle
rich adder
supple wasp
#

That what I saw from learning C# from Unity I don't have much room to memorize that why I forget the things I see

rich adder
#

eh coding isn't really about memorizing

#

thats computers job

cursive tangle
#

i needed snap fix amount of left or right move my objects by mouse or touch through

fickle plume
#

@cursive tangle no reaction gifs, please

rich adder
#

code is the tools yes?

supple wasp
#

Yeah?

rich adder
#

"I want to make X, what do I learn to make X"

#

rinse repeat

ashen ferry
#

pov u want to make X but X was made by noone except some guy with bandicam watermark across yt 30sec clip 10yrs ago

rich adder
#

too true 😂

cursive tangle
#

I needed proper programer help

rich adder
cursive tangle
cursive tangle
#

What mean

rich adder
cursive tangle
#

No

#

I needed script

rich adder
#

you have to build it, or google .
You won't find script here..

cursive tangle
#

Dear i allready search Google and chat gpt

#

But not proper results

ashen ferry
#

bro u didnt even say ur problem or im tripping

supple wasp
#

Is there a video so I can learn unity c#?

rich adder
supple wasp
#

If possible, you can show the video in Spanish.

rich adder
#

the internet is full of them

#

does google español not exist?

#

haven't we been here before or am i having dejavu..

knotty plume
#

can anyone help with this?

ivory bobcat
#

Where open method was never called

solid coral
#

Triggers do not work after the build on android, but it works in the editor...

vapid crow
#

Why this is not working? I want to spawn prefab while pressing e and also while colliding

rich adder
cosmic dagger
#

OnTriggerEnter is called during a single frame . . .

vapid crow
#

oh

rich adder
#

use a bool in update to detect when ur inside trigger

vapid crow
#

alr

knotty plume
vapid crow
#

Thank you! @rich adder @cosmic dagger problem is fixed!

ivory bobcat
#

Whether it's used as an inspector callback or through code, it needs to be used somewhere for it to have occurred.

knotty plume
#

are you talking about public void Open(Vector3 UserPosition)

#

im just confused on which method

#

and thats the script on the door

#

which has the sounds attacthed to it

knotty plume
#

where should i call it

#

and how

fossil drum
#

All his code seems to be from ChatGPT, he doesn't know where Close and Open is called on the doors, I asked him in #💻┃unity-talk. I told him to do an actual programming course instead of just copying stuff from ChatGPT.

knotty plume
#

No i did not get it all from chatgpt

#

i followed a guide

#

and then when this error came up again and again

#

i handed it to chatgpt

#

i thought a class getting called is you writing it

ivory bobcat
knotty plume
#

and the sound plays with it

fossil drum
#

Well, something is calling Close and Open, and you say you followed a guide that wrote it, then you would know when you actually did write it.

ivory bobcat
#

I think you should follow the guide exactly as is

knotty plume
#

alright

#

sorry guys

fossil drum
#

I think getting some coding fundamentals would be better to get before following the guide, like the junior programming pathway linked in the top right.
Then you would actually get the idea behind why the guide does what it does. But what ever floats your boat.

knotty plume
#

yea probably should aye, i do not see the junior pathway link

fossil drum
knotty plume
#

cheers

royal linden
#

can someone help i cant get my player to move

royal linden
#

i have

rich adder
#

Have you read the Do because it doesn't seem you did

royal linden
#

i did

rich adder
royal linden
#

i got a code from there but idk i get errrr

daring sinew
#

how can i save my progress ingame? im making a 2d drag racing game and idk how to make a saving system,

knotty plume
daring sinew
#

^

royal linden
#

but theres a gazillen lines

knotty plume
knotty plume
ivory bobcat
royal linden
#

?

knotty plume
#

send the script

daring sinew
royal linden
rich adder
#

holy fuckballs

#

my eyes

daring sinew
#

lol

#

WTF

#

mans using notepad to code 💀

rich adder
#

i hope you're not actually using notepad to code..

daring sinew
#

^

timber tide
#

not even notepad++

fossil drum
# royal linden

I suggest using an actual !ide, it will help a lot with coding.

eternal falconBOT
#
💡 IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

VS Code*
JetBrains Rider
Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

rich adder
#

username checks out

rich adder
daring sinew
#

so, both?

rich adder
#

json is a good format to keep things organized

daring sinew
#

explain?

#

im not sure wdym "use a file"

ivory bobcat
# royal linden

Make sure to use an IDE that's properly configured. It's required to get help on the Unity Discord server - relative to code. You can check out how to do so in the #854851968446365696 channel

royal linden
#

ide?

rich adder
#

technically you can save it anywhere you want on pc, this is just a common folder for all platforms / devices

ivory bobcat
daring sinew
daring sinew
rich adder
#

uhh if you're still att that point understanding that vid might be hard for you lol

daring sinew
#

but could be

lime leaf
#

I might quit Unity

rich adder
#

this only tells you references but thats how you can connect 2 scripts

#

you just need them to be public variables / methods and use . operator

#

do some basic c# courses

ivory bobcat
rich adder
daring sinew
#

i have also made a rocket ship game

rich adder
#

its prob one of the most important operators

daring sinew
#

dot operator?

rich adder
#

dont they teach you anything in that school?

daring sinew
#

they make us make games from tutorials

rich adder
#

thats horrid

#

do they not have qualified CS teachers?

daring sinew
# rich adder

dot operator? the one that connects the code together, sorta?

daring sinew
rich adder
cold quest
#

I created a script but for some reason whenever I save it in Visual Studio I just get spammed with warnings in the console:

[Worker0] Import Error Code:(4)
Message: Build asset version error: assets/scripts/counters/platekitchenobject.cs in SourceAssetDB has modification time of '2023-09-30T10:02:15.8462733Z' while content on disk has modification time of '2023-09-30T10:03:15.9066344Z'

UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

What does this mean and how do I fix it?

rich adder
#

I have thing Called Robot.. I want robot to dance

Robot.Dance()

#

^ dot operator

daring sinew
#

yeah i know wdym now

knotty plume
#

i knew what that was just didnt know the terminology aswell lol

#

school doesn't teach terminology

short hazel
#

Never referred to it as the dot operator either in university

knotty plume
#

really

#

are you supposed to guess

rich adder
#

I never went to school , I couldn't tell ya

cold quest
short hazel
#

Yeah they just taught us that's how you access things but that's it

knotty plume
#

yea same at school for me

#

was uni good

#

im going uni in a years time

rich adder
short hazel
#

I think they call it "member access operator" officially

ivory bobcat
rich adder
#

close

cold quest
daring sinew
#

so uh

short hazel
# ivory bobcat The *dirty* solution.. 😳

Yeah the overall teaching was good, but the prof had their own naming conventions so we stuck to it for 2 years, and then when I got my first job that used the official conventions I was like "wtf???"

royal linden
rich adder
#

is not configured

short hazel
#

You now need to configure VS Code so it displays errors for you

fossil drum
ivory bobcat
royal linden
#

breh

short hazel
#

Html copy paste mishap

rich adder
# royal linden breh

this won't be the first spelling issue you will have coding if you don't configure it now.. You're only hurting yourself

ivory bobcat
#

Intellisense did not kick in. Your ide hasn't been properly configured.

gaunt ice
#

!ide

eternal falconBOT
#
💡 IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

VS Code*
JetBrains Rider
Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

rich adder
#

!vscode

eternal falconBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

short hazel
#

It might be also due to the fact that Restricted Mode is activated. See the blue bar at the top to disable it

#

You will need to do that anyway to configure it

rich adder
#

well at least now vscode is reduced to 1 extension and updating a package 😅

#

microsoft came in clutch on that one

short hazel
#

Yeah before it was hell, you almost had to open your computer and bend 2 CPU pins to make it work lol

rich adder
#

ah just realized they have compile error and external tools window might not see vscode until it compiles

tawdry rock
#

Is PlayerPrefs a temporary save? I used it to transfer some variables between scenes (the game level + menu) and they working but when i start a new play session i still can load them back however they also gets overwriten by the new session values.
For example if i have a score variable and the player scores 2 point then on the next try 1, the total score on the stat would show 3. If i exit the app and start again i can load back the total score 3, but if i score, say 2 point it the total score will be 2 instead of 5. (android phone)

river roost
keen dew
#

None of those work for your problem

#

Playerprefs is fine, you have some issue in your own code

river roost
#

oh I read the question wrong

tawdry rock
river roost
#

Show the !code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

keen dew
keen dew
#

You don't load the score into the variable when the game starts. It only updates the text.

tawdry rock
#

highscore works fine btw, only total coin/obstacles and number of tries get "overwriten" at new session

#

ohh so i should load them in the logic start method?

#

i did try to load them in the start method of the menu script tho, i will try to move them to logic then

spiral rain
#

Hello how do I get a value in a dictionary all I have is the key

fossil drum
#

yourDict["yourKey"] = the value of that key. Kind of depends on what kind of key you have.

spiral rain
#

A string that is it

#

Ok thx it works

tawdry rock
keen dew
#

You didn't do it properly then

tawdry rock
silent valley
#

Hi. Does anyone know a good tutorial or something for dynamic footsteps? Either they're all using the standardassets firstpersoncoltroller script and adding to it or they're really outdated.

silent ember
#

Unity giving me a missing reference exception even though I don't destroy the object in question

#

This is the code that causes the error. Basically subtracts the player health by 1 then disables the player object when it reaches 0.

#

Idk why it tells me the gameobject is destroyed even though I just disable it

river halo
#

I am making a game. I have created a ground material in the game. I want to randomly multiply this ground and make it a level, but the code I wrote did not work. I My goal is to make the character you see in the picture jump when it hits the ground, play like this.I will send you the code too, 1 minute

charred spoke
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

charred spoke
#

Please use one of the paste sites

heady nimbus
#

I've got a couple prefabs that make up different patterns of individual objects I'm spawning at once. Is there an easy way to get the size of the whole prefab without having to code it for each prefab?

Trying to get them to randomly spawn into a particular sized zone and need to adjust the position based on the size of the pattern so some of them don't go out of bounds

charred spoke
#

Well you could add up the bounds of all individual objects in the prefab with a script during editor time

#

Or when you spawn the objet depends on your need

heady nimbus
#

I was thinking if there wasn't a built in way, that I might just add a collider to the prefabs and use the bounds properties? Does that make sense? Seems easier than trying to add up all the children

wintry quarry
heady nimbus
#

I'm probably being dumb here, but if every prefab is different arrangements of objects, how could I do that consistantly? If I have 1 that's 4 rows of 2, and another that's 3 row of 4, and another that's a single row of 5?

heady nimbus
charred spoke
#

Just write a script that encapsulates the bounds of all children it will work for any number of children

late burrow
#

how to turn collider result from overlapsphere into meshcollider component

wintry quarry
#

DO you mean it's already as MeshCollider?

#

and you just want to treat it as such?

late burrow
#

yes

river halo
#

I'm making a game. I created ground material in the game
With this, I created a code called ground generator.
The purpose of the code was to make the ground prefab, multiply them randomly in a certain place and level them up, but when I ran the code, it did not multiply the ground. What is the reason for this error? My aim is to make the character you see in the picture jump when it hits the ground, to play this way.

#

can ı help me

wintry quarry
wintry quarry
eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

elder cove
#

Hi all. I want to check for inappropriate images within unity. Is there any sdk available for this?

river halo
#

Is it like this?

wintry quarry
#

just read and follow the instructions

river halo
gaunt ice
#

just pick a website you like in !code and paste your large code block on it.....

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

river halo
#

what about later

#

It doesn't work, what I posted is quite self-explanatory.

#

There is no error message in the code, I mean there is no error, the code does not replicate when it runs, can you solve this?

slender nymph
#

you've also already been told why it doesn't work

wintry quarry
#

it's already solved

#

you simply have to read what people are writing to you

river halo
#

I posted the code neatly in all 3 ways.

north kiln
#

and finally, where do you call start? because that isn't the same as Start which is what Unity will call automatically

ivory bobcat
river halo
#

Now I understand what happened, thank you

slender nymph
#

fix your spelling

river halo
#

ok thanks

#

I'm sorry I didn't understand at first

river halo
north kiln
#

start is not a thing

#

It won't be in any documentation or tutorials

#

It

isn't the same as Start, which is what Unity will call automatically

river halo
#

So is the start there unnecessary?

north kiln
#

No, you just haven't capitalised it properly, and somehow haven't noticed the difference in the 4 or so times it's been pointed out

swift crag
#

unity has a number of messages it will send to MonoBehaviours when certain conditions are met

#

for example, the Update message is sent every frame to every enabled-and-active MonoBehaviour

river halo
#

Yes, the first letter of the start was supposed to be capitalized, but I wrote it lowercase, thank you very much.

swift crag
#

and the Start message is sent before Update on the first frame an object is enabled-and-active

river halo
#

problem solved

swift crag
#

messages work by finding a method with a matching name and calling that

#

method names are case-sensitive

river halo
#

thanks goodday

thick goblet
#

Why does my player GameObject start bugging/flashing and shrinking when he jumps on the platform that has a setparent script when the player jumps on? Is there something wrong with the players transform?

unique valley
#

I want to create hilly terrain in 2D- is there an easy way to go abot this?

rich adder
# thick goblet

ur asking questions that we cannot answer based on this screenshot

thick goblet
#

One sec

timber tide
thick goblet
unique valley
timber tide
#

splinesssss

thick goblet
#

Damn could of just did it in 1 link

#

Anyway

unique valley
#

is that mostly editor or actually proramming focused

rich adder
unique valley
#

hmmm thanks

thick goblet
#

Not fully disappears, It flashes and it's scale starts have a seizure

#

Navarone I noticed a problem

#

While it's on the platform it starts parenting and unparenting

#

even when it didnt exit

#

yeah the debug.log keeps saying entered exit on repeat

rich adder
#

try make video if possible

thick goblet
#

Can't make a video but I got this

rich adder
thick goblet
#

the top collider has the trigger on the platform

unique valley
#

googling it shows a paid asset on the store

timber tide
#

Probably something like edge colliders and looping through the points

#

also mesh colliders

thick goblet
#

I got this navarone

#

error

#

I'm lost

rich adder
thick goblet
#

It shouldn't be

#

deactivating

languid spire
#

are you using object pooling for your platforms?

thick goblet
#

Not that I'm aware of

languid spire
#

then you need to search your code for a SetActive(false)

rich adder
#

are these two scripts only ones that are important ?

thick goblet
#

Well I flipped the istrigger on the boxcolliders on the platform

rich adder
#

also show rigidbody setting for platform

thick goblet
#

the flashing disappeared

#

I removed the rigidbody for the platform rn

#

but then the player doesnt get parented*

#

and just slides off

rich adder
#

how do you know its not parented?

#

check the hierarchy after u parent

thick goblet
#

one sec im onto something

#

yes it gets parented now correctly however

#

the player shrinks

#

once it becomes a parent of the platform

rich adder
silent valley
#

I think this way be the right place? My characters footsteps only work on flat surfaces or going down an incline but when moving up an incline, they do not work

subtle hedge
#
for (int i = 0; i < cablePoints.Count; i++)
{
    if(i < cablePoints.Count - 1)
    {
        cablePoints[i - 1].GetComponent<SpringJoint>().connectedBody = cablePoints[i + 1].GetComponent<Rigidbody>();
    } 
}``` i get that error beacose the ``i + 1`` but i don't  know how to make that error not occur
gaunt ice
#

no, is i-1

#

when i=0 you access cablePoints[-1]

thick goblet
gaunt scarab
#

Can someone please give me a 2D character coontroller

gaunt ice
#

no

#

try to make one first

rich adder
gaunt scarab
#

I just need a really simple one for a proof of concept

rich adder
#

it also has a video

silent valley
polar acorn
rich adder
#

yeah my mistake, it never is for those type of people xD

polar acorn
silent valley
#

I'll take a video. 1 min

#

OBS isnt working. Basically, the audio doesnt work when walking up any incline, but walking down it, it does. its very weird

#

going up. no sound. going down. there is sound. (footsteps)

#

Hope that makes sense

polar acorn
#

Show the code that plays the sound

silent valley
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

silent valley
polar acorn
silent valley
#

I'm assuming you mean I should increase my "Raycast" length?

languid spire
polar acorn
silent valley
#

Isn't that the empty "foot" object I have? If so, I have raised that and also increased the length

summer stump
#

Your foot transform needs to be moved up

summer stump
#

You might want to add a Debug.DrawRay to visualize the raycast

silent valley
#

Could I get a quick hand here please. Trying to draw the ray.

gaunt ice
#

why you draw"line" only if raycast hit something

swift crag
#

DrawLine takes two points.

#

You want DrawRay.

#

It takes a point and a direction

#

and draws a line from point to point + direction

#

also, the fourth argument is not a length.

#

It is how long the line will stay drawn.

rich adder
swift crag
#

if not provided, the line will last for one frame

silent valley
gaunt ice
#

you may use else to draw ray of different color
if hit draw red ray
else draw green ray
easier to debug

silent valley
swift crag
#

It is the distance for the raycast, yes

rich adder
swift crag
#

But you passed it as the fourth argument to DrawLine

#

That is not correct. The fourth argument is the duration of the DrawLine/DrawRay command

#

You should instead mutliply it by the direction the ray was casted in

#

-foot.up has a length of 1.

#

Multiplying it by raycastSize will give you a vector that's the correct length

#

so that Debug.DrawRay can draw a line from the start to the end of the raycast

polar acorn
#

There is no "length" parameter of DrawRay, the direction and length are the same one

shell bolt
#

Hi, I have two Shader Graph shaders that I want to use on a single sprite. However, SpriteRenderer only allows for a single material in the Inspector. Does this mean a sprite can only have 1 material assigned? Is there the option to use a materials array?

rich adder
#

cant you just combine the shaders into 1 ?

silent valley
#

I'm just reading all you have written and looking at unity docs

swift crag
#
Vector3 start = new Vector3(1, 0, 0);
Vector3 end = new Vector3(3, 0, 0);
Vector3 delta = end - start; // [2, 0, 0]

Debug.DrawLine(start, end);
Debug.DrawLine(start, start + delta);
Debug.DrawRay(start, delta);
#

these are all equivalent

rich adder
#

bruhhh never click this on VS Mac...it will leave you staring at your own code wondering why it looked spooky...

swift crag
#

mmmm IL

#

yum yum

#

minecraft drinking noises

rich adder
#

I was like "is this even my code" TIL about Intermedia Language mode

swift crag
#

IL is what your C# gets compiled into.

#

It then gets JIT'd into native code when run

normal pumice
#

Gameobject.add in a while loop not working the same as a debug statement

rich adder
#

Yea just thought i broke VS somehow lol

swift crag
#

unless you do IL2CPP, of course, in which case you compile it ahead of time

honest haven
#

8: 'PlayerController.rigidbody' hides inherited member 'Component.rigidbody'. Use the new keyword if hiding was intended. how do i get ride of this warning. Im asigning it in start with void Start() { rigidbody = GetComponent<Rigidbody>(); }

shell bolt
swift crag
#

now this is some legacy content

rich adder
swift crag
#

In the distant, distant past, you had a bunch of extra properties on MonoBehaviour

#

These don't actually exist anymore, but you still get warned that you'd be hiding them

#

if you declare a member with the same name as one from your parent, you're "hiding" it

honest haven
rich adder
#

i just call my rigidbody rb xD

swift crag
#

You can add new to signal that you meant to hide the field. Although, I think that'll then cause a warning when you compile, because that member doesn't actually exist in the built game

rich adder
#

or add the new keyword I suppose

#

public new Rigidbody rigidbody;

#

but yeah thats ugly

swift crag
#

I always call mine rb

rich adder
#

yeah very common across the board i think

silent valley
#

Thank you all for helping with that

honest haven
silent valley
#

So my ray starts at my empty game objects transform. it follows my player as it should. If I raise it. then it doesnt work at all

languid spire
rich adder
#

and by "raise it" you mean in the inspector / scene view or sum

silent valley
rich adder
rich adder
silent valley
#

What do you mean?

rich adder
#

what makes those different, I don't know much about it besides what u sent

daring sinew
rich adder
#

the cube car? is it also rigidbody?

daring sinew
#

yes

#

cube and 4 wheels are rigid

rich adder
daring sinew
#

ill show soon, got bored waiting and closed unity

polar comet
#

i've made a 3d project where you are able to move in every direction ( except downwards, gravity is dealing with that ) but for some reason, ground collisions work fine but when it comes to the side collisions of the platforms i'm using, it goes really weird. I can get inside it until the invisible plate i use that i place on top of the platform detects a collision with the sphere i use for the player. Can someone please help me with that ?

polar comet
#

ok give me a minute

hidden citrus
#

What would be a good way to Lerp between 0 and 1 using an enum and a dynamic time? like timer = 1 or 2+ etc. This is for the slider to go between 0-1 over X time

    IEnumerator LerpGlow()
    {
        mat.material.SetFloat("_Lerp", 0);
        float newTimer = 0;

        while(newTimer < timer)
        {
            newTimer += Time.deltaTime;
            mat.material.SetFloat("_Lerp", newTimer);

            yield return null;
        }
rich adder
#

Translate wont give you accurate collisions and will phase you thru stuff
you're essentially teleporting the player

hidden citrus
#

would it be
mat.material.SetFloat("_Lerp", Mathf.Clamp(0, 1, newTimer));
to clamp the range?

polar comet
rich adder
#

a component

polar comet
#

i don't think i'm using that

rich adder
#

but anyway dont use Translate lol

polar comet
#

ok give me a minute

#

there they are

polar comet
rich adder
#

use that

#

.velocity or .AddForce()

#

you can't freeze position tho

#

unless u only move up and down

polar comet
rich adder
#

the constraits you currently have on rigidbody

#

"Freeze Position"

#

do you know what that does

polar comet
#

well i think i tried to use it to solve an issue i had with camera movement but it didn't solve it so i did something else and it was a success this time so for now Freeze position is useless for me

#

but i want to know what is it's use

rich adder
#

it just freeze the rigidbody on those axes (ie if something smacks into it it doesnt fo flying on x or z)

#

or in your case also it doesnt rotate up or down when hitting something

stiff stump
thorn perch
#

Hi, I hope i am posting this in right channel, if not let me know and ill move it.

ive been trying to get my projectile to "kill" objects in my scene but i cannot wrap my head around why it doesnt work. Is there anyone that could help me to see what it is im doing wrong ?

what ive checked:
collision matrix - everything is ticked so everything can collide with everything.
box2d collider is set to "is trigger" on both projectile and enemy
body type: dynamic

collision type - discrete
Tags
layers

note: the enemy (2dsquarered) is a child of empty "Enemie"
2dsquarered is what holds collider, sprite and rigidbody2d

what i notice of behaviour: player and enemie doesnt collide and are able to walk through eachother.
bullet: flies through enemie.

ive added screenshots containing the various inspectors of each element and projectilebehaviour and enemyhealth script.

thanks in advance !

ashen ferry
#

yea so you need to change OnCollisionEnter2D into OnTriggerEnter2D if any of them is a trigger

thorn perch
thorn perch
ashen ferry
#

theres a mistake its OnTriggerEnter2D tho you should let vs autocomplete it

thorn perch
ashen ferry
#
    {
        
    }``` full footprint
#

Collision2D changes into Collider2D

thorn perch
#

ahhh

ashen ferry
#

start writting ontrigger in an empty line outside methods and it should suggest all related

thorn perch
#

when typing "ontriggereneter2d on a empty line, it doesnt bring in {} and all that stuff automatically, ive seen it done it before, would u know why ?

thorn perch
tender stag
#

@timber tide u think you can try and help me out?

#

you already read all of the code yesterday

#

i think u understand it as least a little bit

tender stag
ashen ferry
#

ive got no clue maybe something wrong with configuration

river halo
#

I can't find the render pipline in the unity edit section, how can I add it?

regal kayak
#

I have a parameter in my animator called speed which I want to be equal to my players movements, how would I write this in code?

swift crag
#

I do not know what you're referring to.

swift crag
#

or whatever value you want there

#

If you're using a rigidbody and it's named rb, you could do animator.SetFloat("speed", rb.velocity);

#

err

#

animator.SetFloat("speed", rb.velocity.magnitude)

#

there we go

#

rb.velocity is a Vector3. rb.velocity.magnitude is the length of that vector, which is your speed

swift crag
#

I guess that's kind of the default anyway, lol

#

doing it in LateUpdate would make your values a frame late

silent valley
swift crag
#

terrain positions are a pain in the ass

#

i've done this a few times lol

silent valley
#

Is there any reason that this code would stop my camera from moving left and right and locking it into the middle?

swift crag
#

is that the right code

#

it doesn't have anything to do with your camera

silent valley
#

exactly why im confused. if i remove my footstep script. my camera works?

#

This is the other script

swift crag
#

Perhaps an exception is being thrown and stopping something else from running

silent valley
#

why are these last 2 days very problematic xD

swift crag
#

Make sure you are not getting any errors in the console

#

notably, make sure that you haven't just hidden the errors

unreal imp
#

would anyone know how to make an object grabbing system like Half Life 2? The player holds an object that can be up to a certain size, his weapon disappears and when he presses left click he releases the object and right click he throws it and the weapon reappears

swift crag
#

currently, you only have the "combat" mode, where you have a weapon out

#

in that mode, you would show a weapon and let the player fire

#

when you exit the "combat" mode, you would hide the weapon

#

once that works, you would add a "grab" mode

#

I'd attach the object to the player with a FixedJoint

#

or maybe a SpringJoint, if heavy objects should move more slowly

#

when you enter "grab" mode, you would attach the joint

#

and in "grab" mode, you'd use the input that normally makes you shoot to instead disconnect the joint and shove the object

unreal imp
#

thanka

#

😘

swift crag
#

you could also check if the object is too far from the joint and forcibly exit "grab" mode

#

So I would start with "combat" and "idle" states

#

that'll be an easy one to do: just put the weapon away and do nothing special

river halo
#

I was using Unity Renderer. In Unity, there should be render pipline in the edit section, but there is none, how can I do it?

#

it should be like this

#

but it should be like the 2nd picture

#

Is it due to version difference?

fossil drum
river halo
#

I already added

upper spire
#

hello, im trying to integrate gpt into unity via this tutorial. https://www.immersivelimit.com/tutorials/how-to-use-chatgpt-in-unity
i have an error that i cant fix, ive looked everywhere to see where to get the namespace but to no luck.

    /// <summary>
        /// Optionally provide an IHttpClientFactory to create the client to send requests.
        /// </summary>
        public IHttpClientFactory HttpClientFactory { get; set; }

        /// <summary>
        /// Creates a new entry point to the OpenAPI API, handling auth and allowing access to the various API endpoints
        /// </summary>
        /// <param name="apiKeys">The API authentication information to use for API calls, or <see langword="null"/> to attempt to use the <see cref="APIAuthentication.Default"/>, potentially loading from environment vars or from a config file.</param>
        public OpenAIAPI(APIAuthentication apiKeys = null)
        {
            this.Auth = apiKeys.ThisOrDefault();
            Completions = new CompletionEndpoint(this);
            Models = new ModelsEndpoint(this);
            Files = new FilesEndpoint(this);
            Embeddings = new EmbeddingEndpoint(this);
            Chat = new ChatEndpoint(this);
            Moderation = new ModerationEndpoint(this);
            ImageGenerations = new ImageGenerationEndpoint(this);
        }

(the line with the error and the surrounding code)

violet rose
upper spire
violet rose
upper spire
violet rose
# upper spire alright, thank you! do i need to install that via the in unity package manager o...

It's not a Unity Package, it's just a .NET library. So maybe from NuGet https://www.nuget.org/packages/Microsoft.Extensions.Http/

upper spire
tulip stream
#

!cs

eternal falconBOT
#

You can format your multiline code block with C# highlighting! Just add cs to the start of it. Highlighting example below!

class Fluffs : FluffyCat
{
    public void PetCat ()
    {
        Debug.Log ("Petting Cat.")
    }
}
tulip stream
#

Hello, i'm new to unity and c# and eager to learn both, can you guys help me understand how does the distance inside the BoxCast work?

RaycastHit2D raycastHit = Physics2D.BoxCast(boxCollider.bounds.center, boxCollider.bounds.size, 0, Vector2.down, 0.1f, groundLayer);
#

for example in this code, i have a distance of 0.1f

#

does that mean that distance applies only to vector2.down?

violet rose
tulip stream
#

which mean the y axis -1

slender nymph
violet rose
#

@upper spire including external packages can be complex so don't fret if it trips you up. this may or may not work to fix for your error, but I hope it does!

tulip stream
#

so it that case it only affects Vector2.down right?

slender nymph
#

Vector2.down is the direction. i don't know what you mean by "affects" it since it doesn't change the direction. it's just how far in that direction the box travels during the cast

languid spire
#

@upper spire I'm not sure why they have made it so complicated. It is easy enough to write a GPT interface just using UnityWebRequest

tulip stream
#

btw why did my code show unformatted? i used cs after the three backquotes

swift crag
#

the syntax highlighting isn't as elaborate as it is in your code editor

#

notably, types and local variables aren't highlighted