#💻┃code-beginner

1 messages · Page 617 of 1

wintry quarry
#

What's going through the gameobject?

honest iron
wintry quarry
#

Ok so another GameObject

honest iron
#

1sec

steep rose
#

show us the collider configuration

wintry quarry
#

you would have to explain what the player is and how it is configured and how it moves

#

and how you configured the MeshCollider as well

#

basically show us the two objects you're expecting to collide

honest iron
steep rose
#

inspector

wintry quarry
wintry quarry
#

show the whole editor including the inspector

#

it also seems like that thing has at least 3 different colliders

honest iron
#

ok, i want to add to my enemy collider the cover his body without blocking the "empty" spaces under it, if i use mesh collider the player can go through the enemy and if i use box collider im blocking those "empty" areas

wintry quarry
#

you're using a CharacterController

#

CharacterControlller cannot use any additional/extra colliders

#

you get the capsule that is the CC, and that's it

#

if you want a differently shaped collider you generally will want to use a Rigidbody-based controller or roll your own kinematic controller.

honest iron
#

the cc is on the player, i want the shaped collider on the enemy

wintry quarry
#

your player has an extra Capsule Collider on it

#

you can't do that

honest iron
#

im using that Capsule Collider for trigger

honest haven
#

So i was having a issue with unity detecting a controller when nothing was connected but it did print out and empty string. so i added this script to it so if its empty assume its not a connected controller. it works bt just wanted to check if it would stop 3rd part controllers or the code is no good. https://paste.ofcode.org/teXjuThBxP2gPv8RH7RigA

subtle hedge
#

i'm sorry but i told you the purpose

#

to see keep the player fixed to the ground and rotate him acording to the surface of the ground

polar acorn
#

wouldn't it make more sense to raycast where they're going to be and then setting the rotation and position there?

subtle hedge
#

Well

#

i'm trying to keep the player fixated to the ground and not fall, and the ground is a cillindar and i need the player to be able to go 180 around it

faint osprey
#

how would u add a collider to a line renderer

polar acorn
subtle hedge
polar acorn
subtle hedge
#

a cilinder

#

and it gotta go around it

polar acorn
#

yes I am aware

subtle hedge
polar acorn
#

You compute where the player would be if the movement were on a flat surface, then raycast down from that position. If it hits something, you move the player to the location and normal of the hit point

subtle hedge
pure drift
#

when i press the delete key assets dont remove from the scene does anybody know why that is

mystic ferry
#

Is it possible to hide vertices that are weighted to a certain bone?

subtle hedge
# polar acorn yes I am aware
float vertical = Input.GetAxis("Vertical") * walkigSpeed * Time.deltaTime;

transform.position += new Vector3(horizontal , 0, vertical);

Ray ray = new Ray(transform.position, -transform.up);
if(Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, treeLayer))
{
    if(hit.collider == null)
    {

    }
}```am i on the right path ?
rocky canyon
polar acorn
rocky canyon
#

no clue just a guess

polar acorn
#

And make sure you use the object's local down vector, not world down

subtle hedge
polar acorn
#

Then see if it hits

grand stone
#

hi

subtle hedge
#

should i put it on a vector ?

polar acorn
#

However much you want to move by

subtle hedge
#

transform.positon += hit.point ?

#

or offset ?

grand stone
#

I need some help with my hands to work in FPS Game, i have a script https://paste.mod.gg/jbqhcvlzzsoz/0 which basically makes the hands 2 bone ik constraint locked on to a grip of a weapon they pick up, although it seems to get attached, the IK doesnt work. sorry if its the wrong channel, i couldnt see any animation help

subtle hedge
polar acorn
subtle hedge
#

there are no flast edges

subtle hedge
#

can't really wrap my head around it

subtle hedge
#
float vertical = Input.GetAxis("Vertical") * walkingSpeed * Time.deltaTime;

movementPos = new Vector3(horizontal, 0, vertical);

Ray ray = new Ray(transform.position, -transform.up);
if(Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, treeLayer))
{
    if(hit.collider != null)
    {
        fixedPos += transform.position + movementPos + hit.point;

        transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
    }
}

transform.position += fixedPos;```
#

that's with what i came int

polar acorn
#

Do you understand the parameters you are passing to Ray

subtle hedge
#

Vector3.down*

polar acorn
# subtle hedge

So, quick question: When you're not holding any directions, what do you expect movementPos would be?

subtle hedge
#

if i'm not holding any direction it would be 0, 0, 0 right ?

#

so it's basically not hiting anything

polar acorn
subtle hedge
#

nope, i want it to start at the current position of the player

#

so i should insert the current position of the player at the start ?

polar acorn
#

Perhaps you should be adding some sort of offset to the player's position to get the origin

polar acorn
#

There you go. Now use the object's local down vector (or negative up, I suppose) instead of Vector3.down

subtle hedge
#

alright, let's move on to the raycast

#

is any issue there ?

polar acorn
#

the entire fixedPos computation makes no sense

subtle hedge
#

so, i'mm adding the point where i want it to be fixed there

polar acorn
#

That also doesn't make sense

#

Think through the numbers

#

hit.point is the world position the line hits an object

subtle hedge
#

so i should get the direction of it ?

#

or should i add it to the movementPos instead ?

wicked pulsar
# subtle hedge

Sorry, I scrolled up and saw that your conversation goes on for a while. What is this supposed to be doing?

polar acorn
subtle hedge
#

on the ground

#

but it's flying up

polar acorn
#

What is a value in code that represents a world position that would be on the ground?

#

Maybe somewhere that hits a collider of a solid object?

subtle hedge
polar acorn
subtle hedge
wintry quarry
#

Adding a position to a position is not a good idea

polar acorn
wintry quarry
#

It's rapidly going towards infinity

polar acorn
#

What is the value of MovementPos? What happens when you add the world position of the target location to it?

#

If I'm at "100 miles north of Scranton" and I add "101 miles north of Scranton" then how far away would I be from Scranton?

subtle hedge
#

and the ray is drawn from there

polar acorn
subtle hedge
#

IT DOUBLES

#

and it causes not the movement i want

#

didn't quite got the result i was hoping for

#

it should be able to move around the cilinder

#

and not go throught it

faint osprey
#

im trying to add a collider to my line renderer and it wont work

ripe shard
polar acorn
faint osprey
#

so i have a script that makes a line renderer create segements betweena start and end point and i want to add a collider to the rope

polar acorn
#

Okay and what did you do that "didn't work"

#

and in what way did it not work

faint osprey
#

i tried to add a mesh collider to it and it didnt do anything

wicked pulsar
# subtle hedge

I noticed that once your raycast finds a hit, you check to see if a collider exists. Under what condition does your raycast find a target, but there is no collider?

polar acorn
#

did you use it

safe root
#

!code

eternal falconBOT
safe root
#

I'm trying to have a enemy be able to rotate towards the player but since I don't lock the rotation it ends up falling over. Is there a way to have it rotate but be able to stand straight up without it falling over

https://paste.ofcode.org/gYKBhKNTmQPkgA5MKMjWJr

#

Yes I know I need to remove some stuff from my code btw

wicked pulsar
safe root
wicked pulsar
#

Check the rigidbody component and restrict it from freely rotating on any axis you don't want.

safe root
wicked pulsar
safe root
wicked pulsar
# safe root Is there a way to active and deactive those axis?

Well, you have some options depending on what you need:

  1. Restrict rotations until the unit is shot -> like a ragdoll on death
  2. Don't restrict anything, but have a script "correct" the object to a more upright position each frame, to simulate a "standing up" force.
#

If you want the object to tilt over a bit under some circomstances, you'll have to add a force to move it upright so your bullets have something to fight against.

safe root
wicked pulsar
obtuse ether
#

just wanted to ask if i was doing this code right because my high school mind is melting rn trying to understand raycasts lmao

#

what im trying to do is to make a raycast that goes diagonally down to see if theres a gap

#

and if the raycast doesnt hit anything then just jump

#

but my brain doesn't want to brain and refuses to understand how all these raycast functions work

polar acorn
obtuse ether
#

alr

#

so im pretty sure i did the first parameter right

wintry quarry
obtuse ether
#

but im not sure how to make it a certain direction so i just guessed with the Vector3(0, 0, 135)

wintry quarry
#

so that direction makes no sense

safe root
obtuse ether
#

yeah alr lol

polar acorn
obtuse ether
polar acorn
#

Right now, this is 135 units into the Z direction, which, since it's a direction means it's length will be treated as 1, so it's 0, 0, 1

#

which is into the screen

wintry quarry
obtuse ether
#

oh

obtuse ether
#

but ig not

polar acorn
#

that makes your 2D object spin

obtuse ether
#

ohhhh

#

so how do i change the direction of the raycast

#

im trying my best to understand this youtube video but im still not 100% sure about what im doing

polar acorn
#

Line starts at transform.position and goes to the right

wicked pulsar
obtuse ether
#

im not sure what kind of thing id have to type for that tho

polar acorn
obtuse ether
#

cuz i want it to be diagonal

polar acorn
#

Diagonal in which directions

obtuse ether
#

right down

polar acorn
#

So make a vector that is right and down in equal amounts

obtuse ether
#

so like 1, 1?

polar acorn
obtuse ether
#

yippe

polar acorn
#

Figure out which directions are which

obtuse ether
#

yep

#

1,-1

#

x 1 to make it go forwards

#

-1 y to go down

#

is this raycast hit check correct though?

wintry quarry
#

that correctly checks if anything was hit by the raycast yes.

obtuse ether
#

so if it doesnt hit anything it just jumps

#

oh OOP

wintry quarry
#

oh sorry

obtuse ether
#

how do i check if it didnt

wintry quarry
#

it's the opposite yeah

polar acorn
wintry quarry
#

you have it right

obtuse ether
#

oh okay phew

wintry quarry
#

I missed the !

obtuse ether
#

okay ty a lot for the help lol

#

gonna check and pray this works lmao

#

i just realized i was using AddForceX not Y 💀

wintry quarry
#

I didn't even realize they have AddForceX and Y now

wintry quarry
#

back in my day we had to craft our own Vector2s

obtuse ether
#

anyways i think i did something wrong because its not really jumping over the gap

wintry quarry
#

well if that screenshot from the vidfeo is any indication you seem to be doing this only in Start

#

which doesn't make a whole lot of sense

obtuse ether
#

im doing it in void update

wicked pulsar
wintry quarry
obtuse ether
#

alright

wintry quarry
obtuse ether
#

yeah the raycast isnt doing anything and idk why

#

put in a debug.log if it doesnt hit anything

#

and even when its falling into the void it doesnt do anything

wintry quarry
#

it's cnot clear what the scene actually looks like and what's going on

#

also how the object is moving in the first place

wicked pulsar
wintry quarry
#

which object am I supposed to be looking at?

obtuse ether
#

trying to make it follow the player

#

and also jump over ledges

wintry quarry
#

you're not adding enough force to make it fly

obtuse ether
#

asked abt how to make that work yesterday and they said use raycasts to check

wintry quarry
#

it's also not clear what the rest of the code making it move does, which is impoirtant

obtuse ether
#

alr

#

i mean script

wintry quarry
#

and what did you assign to JumpForce in the inspector?

obtuse ether
#

idk if i should add comments

wintry quarry
#

and is JUMP printing? How many times it it printing?

#

I think it's very likely your raycast is simply hitting the enemy itself

#

since you're not using a layermask or anything

obtuse ether
wintry quarry
#

right and?

obtuse ether
wintry quarry
#

Did it print or not

obtuse ether
#

it didnt lol

wintry quarry
#

if it didn't print then yeah the code isn't running

#

likely for that reason

obtuse ether
#

yk i can prolly google it lol

wintry quarry
#

then set it up in the inspector

#

and use it in the raycast (in the correct place)

#

it will decide which layers are considered for the raycast

#

anything NOT in the layermask will be ignored entirely.

obtuse ether
wintry quarry
#

look at the documentation or your IDE to see

#

where the layermask param goes

obtuse ether
#

alr

#

o its right after distance

#

so just RaycastHit2D raycastHit2D = Physics2D.Raycast(transform.position, new Vector2(1, -1), 2, myLayermask);

wintry quarry
#

yeah

obtuse ether
#

alr

obtuse ether
#

so if i use the layer ground in myLayerMask

#

will it only try to detect that layer

wintry quarry
#

then the raycast will only see things with the ground layer

obtuse ether
#

and then ignore the enemy since its a different layer??

wintry quarry
#

yes

obtuse ether
#

okay lol

obtuse ether
#

i now understand raycasts in 2d yippee

#

very cool

#

i can use this in future projects ig

#

500 jump strength was a bit much 💀

#

After some new ground checks + checks to see if you’re being chased it will now jump across ledges very cool

#

prolly gonna make 3 basic enemy types for my first level which 1: dont jump + dont chase, 2: chase but no jump, and 3: jump + chase

ebon sapphire
#

I have two scripts, one for my pause screen and one for my player movement. However, I cant seem to figure out how to reference the pause system in my player movement script. I have two Pastebins so you all can see my current code:

PauseSystem.cs - https://pastebin.com/btZyZNeX
playerMovement.cs - https://pastebin.com/NzqN7jV9

sour fulcrum
#

A lot of people have their pause feature in a GameManager that uses a “Singleton” pattern

rocky canyon
safe root
rocky canyon
#

try flipping the subtraction..

#

this - that -> that - this

timber tide
#

Double check that the gun placement is actually pointing in the forward direction

rocky canyon
#

that too.. to me it looks like its transform.right axis is facing the cam

#

unity is a Z forward engine.

#

blue = Z

safe root
#

Then it was facing backwards then and now it facing forwards

timber tide
#

make a sphere mesh, child it to the character, and change the position to z = 1

rocky canyon
#

as long as u have Local selected, youll be able to just kno

safe root
safe root
#

So I have this problem with the bullet from the weapon just going through the enemy for a few bullets before fixing itself. Is it a setting that could be causing this?

mossy dock
#

@safe root Hey! So I started scripting about 2 days ago, sorry I can't help you but I pinged you since your the most recent online, is there a chance you know how to make other objects connect to another object? Like I make a script in another game object and I want the script to say "Make the door play this open animation"?

timber tide
safe root
#

Bad at explaining, but if you can show me the script I can show it better

mossy dock
mossy dock
#

no more like I spawn in a new gameobject, and theres another gameobject that can be anywhere like "mushroom" in a platformer game 2K miles away, I can make like "if the player presses f then the mushroom will die" even if it wasnt in the mushroom game object, it was in an empty one

safe root
mossy dock
#

also , reason I'm going here not tutorials I came across a tutorial that said "If you try to learn programming through tutorials, it will pass right over your head."

He said "Learn the absoulute basics then try to make a game with those."

So maybe you can try smth like that too! Maybe.
If you want

timber tide
#

tutorials are fine

safe root
#

All depends how you lean

timber tide
#

there's so many things about game dev you're not going to naturally figure it out that easily

safe root
#

I learn best by trying, see if I can search up the problem and fix it. If not ask more experted people

mossy dock
#

WHY CANT I SAY HM, its banned?!?!!

safe root
#

I guess so

mossy dock
#

alr well thx for the help guys

#

time to

#

remake celeste

safe root
#

Have fun

mossy dock
#

Ik how to make a player move and how to collision with other objects now, so I just need to google up a little things on google for mechanics and I should be able to 😄

mossy dock
topaz mortar
# mossy dock also , reason I'm going here not tutorials I came across a tutorial that said "I...

tutorials are great for absolute beginners who do not yet know how unity works and what it's features are
once you're familiar with unity and it's basic features, you learn best by trying things yourself
that can be in the form of fully watching a tutorial, then trying to replicate it by yourself and look things up when you don't remember
but if you just blindly copy/paste from tutorials while doing stuff, you'll never actually learn how any of it works, or at least MUCH slower than if you would try to do it yourself

safe root
keen dew
#

It's because you're setting its position to a fixed distance (or actually a direction which doesn't make much sense)
Try rb.MovePosition(transform.position + oppositeDirection.normalized * Speed * Time.deltaTime);

safe root
visual linden
safe root
safe root
#

Thank you, that fixed both problems

tall abyss
#

Hello I’m new to making worlds, I need help to get beer pong to work and pool tables

#

I was wonder if someone here could help me edit some pool tables and beer pong

visual linden
topaz mortar
#

Alright 🤯 I have the following set up:
Weapon inherits from EquippableItem, which inherits from Item
WeaponSO inherits from EquippableItemSO, which inherits from ItemSO

Item has a reference to it's ItemSO
How do I turn that reference into a WeaponSO on Weapon?

#

public WeaponSO weaponSO => itemSO as WeaponSO;?

honest iron
#

hey, for NPCs do i make a script for every npc or one script for all?

swift elbow
#

not each individual NPC

honest iron
#

'type' like merchents, blacksmiths, etc..?

swift elbow
#

yeah exactly

honest iron
#

so if i have npcs that only talks i can make 1 script and use if (or switch ) for text

sour fulcrum
#

keep in mind 1 script != 1 usage of that script

rich ice
honest iron
#

thanks 🙂

#

gatta prec inherited

#

i haven't used it for awhile

sour fulcrum
#

feel free to ask questions if you get stuck

celest ore
#

Folks I want to make an auto-saving system, When Player unlocks a gameobject (Unlocking here means it sets the inactive gameobject as active) with some action , how do I collect and save the unlocked gameobjects and store them?

teal viper
celest ore
teal viper
celest ore
teal viper
#

Sure

celest ore
#

Okay thanks for the idea!

queen adder
#

Hi, i have a question about the Liskov substitution principle, I think the doc I m reading is misleading me.
A code must be bulletproof from using base class instead of subclass, or from using subclass instead of base class, in the first place ? Or it doesnt matter and your app must work with any class in a derived class tree

celest ore
#

Its like you have 4 children, but those 4 children are damn good that they can replace you without affecting your purpose and work

#

Basically if someone looks at one of your children, they think its you

queen adder
#

I ask the question, the doc might be wrong, because it states that "derived class must be substitutable for their base class" but you add functionnality in your subclass, by using parent class you easily get a NonImplementedException

#

Or am i wrong

celest ore
# queen adder

This means that if you have code that works with the base class, it should also work if you replace it with any of its derived classes.

queen adder
queen adder
celest ore
queen adder
#

That I understood

celest ore
#

Or the 1st line you're reffering?

queen adder
#

Yes, first sentence

celest ore
#

What Im saying and whats written both are the same thing

queen adder
#

If my code uses a super rare tropical fish for something, it should be able to consider using a fish in the exact same spot in the logic ?

celest ore
# queen adder Yes, first sentence
  1. A base class should always be usable instead of a subclass? (Incorrect interpretation)
  2. A subclass should always be usable instead of a base class? (Correct interpretation)
queen adder
#

Ok

celest ore
#

I think you got confused in this

queen adder
#

I read A base class should always be usable instead of a subclass

#

But it doesnt make sense

#

I understand A subclass should always be usable instead of a base class

celest ore
#

Yeah

#

the second one

queen adder
#

So it is me not understanding english properly

celest ore
queen adder
#

User error as always

celest ore
#

haha

#

no issues

#

happens

queen adder
#

Thank you

celest ore
#

Np

mossy dock
#

Guys please help 😦 I just spent like 50 mins on different tutorials finding a gun script that shoots bullets (ik in the script it doesnt tell the gun to shoot bullets, the problem is the gun isnt doing what IT IS supposed to do, go to cursor rotation)

eternal falconBOT
mossy dock
eternal falconBOT
mossy dock
burnt vapor
#

The bot stops when you stop feeding it commands

#

It also gave good advice on sharing the code because your current code is not being formatted

mossy dock
#

well okay, uploading it to scriptbin so other ppl can help then ig

#

Im so confused I havent gotten any sleep 😭

#

Im just trying to make "super mega kewl platformer top down slime color battle gun omega"

burnt vapor
#

Begin by properly sharing the code

#

And perhaps sleeping

mossy dock
#

Tried to make a gun that rotated around the player based on the direction of cursor, but terribly failed...

silent valley
#

You aren't going to receive help if you don't share the code properly

burnt vapor
#

It's the little things that greatly help a question

mossy dock
#

idk how to do a paste site but okay

#

Ill try to figure it out

burnt vapor
#

Did you read the bot message?

mossy dock
#

here goes another 2 hour of tutorials

silent valley
#

paste code into it, save. share the link. super easy

burnt vapor
#

The bot message is formatted in a way even a 5 year old can understand it

mossy dock
#

Tried to make a gun that rotated around the player based on the direction of cursor, but terribly failed...

#

oh, that was easy

hexed terrace
#

it would also be good for you to record a video to show what is happening - "terribly failed" isn't very descriptive of the issue

mossy dock
#

I only have 2 days of experience

honest iron
#

i've added EquipmentHolder to a prefab, but when i try to reach the Equipment within the EquipmentHolder im getting null

private void DropItem()
{
    Equipments weapon = Equipments.Weapons[Random.Range(0, 6)];
    Equipment equipment = new Equipment(weapon.EquipmentID, weapon.EquipmentType, weapon.EquipmentImage, weapon.EquipmentName, weapon.EquipmentBaseAttack, weapon.EquipmentBaseDefense, weapon.EquipmentBaseHP, weapon.EquipmentBaseMP, weapon.EquipmentEffects, 0, false);
    GameObject weaponPrefab = Resources.Load<GameObject>("Prefabs/Weapons/" + weapon.EquipmentID);

    SphereCollider sphereCollider = weaponPrefab.AddComponent<SphereCollider>();
    sphereCollider.radius = 2f;
    sphereCollider.isTrigger = true;

    EquipmentHolder holder = weaponPrefab.AddComponent<EquipmentHolder>();
    holder.Equipment = equipment;

    Quaternion rotation = Quaternion.Euler(0, 0, 90);

    weaponPrefab.tag = "Drop";

    Instantiate(weaponPrefab, transform.position, rotation);
}
#

    private void PickupItem()
    {
        if (droppedItem != null)
        {
            EquipmentHolder equipmentHolder = droppedItem.GetComponent<EquipmentHolder>();
            AddEquipmentToInventory(equipmentHolder.Equipment);
            Destroy(droppedItem);
            screenText.text = "";
            droppedItem = null;
        }
    }
hexed terrace
#

which line is null

honest iron
#

Equipment is the null

AddEquipmentToInventory(equipmentHolder.Equipment);

hexed terrace
#

so droppedItem doesn't have an EquipmentHolder on it

#

oh , no sorry

honest iron
#

lol

hexed terrace
#

at this point, .Equipment is null.. have you checked the inspector at this point (at runtime) and confirmed it's assigned?

#

also add a debug log above it to see..

Debug.Log($"equipment is null: {equipmentHolder.Equipment == null}", equipmentHolder.gameObject);
AddEquipmentToInven...```
honest iron
#

the EquipmentHolder is assigned,

hexed terrace
#

that log will be clickable and ping the gameobjec it's talking about

hexed terrace
honest iron
hexed terrace
#

You click that, and it'll ping the EquipmentHolder.cs file in the project window

honest iron
#

1 sec checking

hexed terrace
#

that public field is not visible in the inspector screenshot

honest iron
#

i think because its a class

hexed terrace
#

Equipment is a class?

honest iron
#

a script(object)

hexed terrace
#

script/class same thing - interchangable, I'm just trying to confirm by "its a class" You mean 'Equipment'

honest iron
#

yes

hexed terrace
#

if it's not a MonoBehaviour, put the serializeable attribude above the class declaration

[System.Serializable]
public class Equipment {}```
#

this will allow it to show in the inspector

honest iron
hexed terrace
#

there you go, it's not assigned like you think it is

honest iron
#

oh that worked

#

thanks 🙂

#

[System.Serializable] btw whats?

hexed terrace
#

there's more to serialization.. which may be a factor here

#

I'm not sure if it being non-serialized would mean it wouldn't copy over when you Instantiate from the code built prefab

boreal umbra
#

How can I write code in Unity to trigger when an object touches a second object?

verbal dome
boreal umbra
#

Is it right?

cosmic dagger
#

What's happens when you test it?

boreal umbra
#

No error but dont work

cosmic dagger
#

OK, that's a start. Do any of the objects have colliders?

polar acorn
eternal falconBOT
#

mad No

Be mindful, if someone requests your code as text, don't send a screenshot!

cosmic dagger
boreal umbra
#

ok thanks

verbal dome
# boreal umbra Is it right?

Depending on an object's name is not very robust. Usually instantiated objects have a "(Clone)" added to the name anyway so it wouldn't work with those

#

It's better to check if the collided object has a certain Component or Tag

#

TryGetComponent and CompareTag

native thorn
wintry quarry
queen adder
#

I want to create a rope between two characters that can increase & decrease it's length. I used HingeJoints2D.
If I spawn in new Rope Parts, they get hooked to the next joint, but they rotation is completely off.

So the Rope sticks together, but doesn't look like a rope anymore.

Do I missing something here?
How to spawn the RopeParts with the right rotation.

Everything falls apart as soon as I start moving

public class RopeManager : MonoBehaviour
{

    public RopePart[] ropeParts;
    
    public RopePart ropePrefab;


    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab)){
            AddRopePart();
        }
    }


    public void AddRopePart() {
        HingeJoint2D ropeMiddleJoint = ropeParts[(int)ropeParts.Length/2].GetComponent<HingeJoint2D>();
        RopePart newRopePart = Instantiate(ropePrefab,ropeMiddleJoint.GetComponent<RopePart>().NextSpawnPoint.position, Quaternion.identity,gameObject.transform);       
        HingeJoint2D newHinge = newRopePart.GetComponent<HingeJoint2D>();
        newHinge.connectedBody = ropeMiddleJoint.connectedBody;
        ropeMiddleJoint.connectedBody = newRopePart.GetComponent<Rigidbody2D>();
    }
}
native thorn
#

right sorry, should have been specific, as apposed to object variables

#

Having a public object variable string is essentially identical to using tags?

wintry quarry
#

there is no short/simple answer here to "faster or slower"

#

it depends

#

using tags can mean a bunch of different things

burnt vapor
#

We need an !itdepends command in here

calm badge
#

hey guys, idk i made a 3d model from blender and then export it to glb. i wanna put it to kotlin using sceneview. my 3d model doesn't load but others do? why is that

burnt vapor
#

Also got it in the C# server

naive pawn
queen adder
#

What should i google if i want to create a dynamic area in between other gameobjects. Like a lasso, how to check was inside ?

ripe shard
hexed crow
#

i wish i had a better way to ask this, but why does this not work??

queen adder
charred spoke
polar acorn
hexed crow
naive pawn
ripe shard
hexed crow
#

i’m sorry i’m extremely new to coding i don’t understand what that means

polar acorn
#

So what is the error currently

hexed crow
polar acorn
# hexed crow this

Okay so your script is not a MonoBehaviour. If you created it in Unity you would have had to manually remove the : MonoBehaviour , so, don't do that.

#

Leave that there, it's important

ripe shard
hexed crow
polar acorn
eternal falconBOT
hexed crow
#

`using UnityEngine;

public class MouseMovmentScript
{

public float mouseSensitivity = 100f;

float xRotation = 0f;
float yRotation = 0f;

public float topClamp = 90f;
public float bottomClamp = 90f;

void Start()
{
    //Locking the cursor to the middle of the screen while making it invisible
    Cursor.lockState = CursorLockMode.Locked;
}


void Update()
{
    //Mouse inputs
    float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
    float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

    xRotation -= mouseY;

    yRotation -= mouseX;

    xRotation = Mathf.Clamp(xRotation, topClamp, bottomClamp);
    
    transform.localRotation = Quaternion.Euler(xRotation, yRotation, 0f);

}

}`

polar acorn
#

Create a new empty script and compare what is there with what you have here

#

And see the difference

hexed crow
polar acorn
#

Then somehow you've deleted your script templates. I don't even know where to find them so I have no idea how you deleted them

#

You're creating these scripts in Unity, right?

hexed crow
frank rivet
#

https://github.com/brihernandez/MouseFlight

Litterally the flight sim installed from github gives this stupid jitteryness. I implemented this same flight sim into my game and its very much the same structure and stuff and yet the jitter problem is still there. it kind of started after I reloaded the prject.

GitHub

War Thunder style mouse flight controls for aircraft - brihernandez/MouseFlight

hexed crow
#

i like just clicked on “create empty c# script”

polar acorn
hexed crow
#

ooohh

#

sorry i’m new to unity

#

i’m level designer so i’m used to opening a program and already having everything done for you lol

#

if that makes sense

polar acorn
#

I don't even know where the "empty C# script" option is, I can't even find it on my end

hexed crow
#

this is what it looks like for me

#

maybe my version is different for some reason or whatever

slender nymph
silent valley
hexed crow
cosmic dagger
#

I have the same options, but they're custom editor scripts I created. Kind of cool if they do that by default now . . .

hexed terrace
#

I always choose the Empty C# Scipt now, all that's missing is : MonoBehaviour and comes with no extra fluff that gets deleted anyway

polar acorn
#

Ah, that'd make sense. I haven't upgraded this project to 6 yet

violet shoal
#

Hello, are there any common reasons for builds to show up as viruses for other people when they download it?
i've been building for a while and suddenly without changing anything, when i send my build to others their browsers detect it as a virus and block the download

terse niche
#

guys, what's wrong with my code?

naive pawn
eternal falconBOT
naive pawn
#

it'll highlight errors

terse niche
naive pawn
#

see the bot message

polar acorn
#

Not sure what that has to do with what you were asked to do

terse niche
#

sorry wrong channel lol

terse niche
polar acorn
#

Which one do you have

terse niche
#

I have unity and atom for script

polar acorn
#

Then you should switch to an actual IDE, pick one that's actually on the list and follow the instructions for that one

terse niche
#

okay, thanks !

subtle hedge
#

Hello, i have a problem with the player stopping half way the cilinder while i need it to be able to go 180 around it and i don't have any idea why it happends

subtle hedge
#

even if it's close to it

#

i debuged the ray and it's always pointing downwards

west radish
obtuse pebble
#

I have a Prefab gameobject attached to a canvas. It has a script that is supposed to write "OnPointerDown" in the debug console. However, the gameobject does not register when I press it. The prefab is an empty gameobject with text and a sprite attached as children. It still does not register when I attach the script to the sprite child instead. What am I doing wrong?

The canvas is set to screen space - camera, and the camera has a physics 2D raycaster.

wintry quarry
bold plover
#

I'm not quite getting the desired behavior for my player rotation handling near the bottom of this script. The debug console still shows some residual player rotation for a short while even when there is no player input. I'd like their currentSteerAmount to drop to zero when there is no input. I'm doing this so holding a turn in one direction has ramp up but then if for whatever reason you turn the other way it feels more responsive.
https://hastebin.com/share/xamugokitu.csharp

wintry quarry
#

it needs an Image or something

bold plover
#

Let me know if I can clarify better.

wintry quarry
#

use GetAxisRaw if you don't want that

obtuse pebble
wintry quarry
#

Is the event system all in order?

obtuse pebble
wintry quarry
#

why does your UI object have SpriteRenderer

#

that's not correct

#

UI should be using the Image component

#

SpriteRenderer is not a Graphic

#

and it's not for UI

obtuse pebble
frigid sequoia
#

Why have I been looking at this for a while and have the feeling I can simplify it but I can't tell how?

eternal needle
dry igloo
short hazel
#

else if (isDead) yep

frigid sequoia
#

Either if it's dead or the time is paused the Update should stop

#

So I don't think I can use the else if

dry igloo
frigid sequoia
eternal needle
eternal needle
#

doesnt matter, thats not what im referring to

errant flame
#

im following a crappy bird tutorial, for some reason, when i build the game, the UI gets misplaced (top left score gets cut), inside unity I have these scaling settings and from the "game screen", the game looks alright in all resolutions, what could be wrong and how do i fix it?

#

im brand new to unity

dry igloo
dry igloo
frigid sequoia
#

This is like league where your skills still count their cd timer while you are dead

frigid sequoia
dry igloo
#

if your logic is 5 lines long and works as intended, you're very good to go

frigid sequoia
errant flame
frigid sequoia
#

Basically is to stop the Update of the subclass

#

I should have definitely given a whole different script for when a character is dead I think

crimson pike
#

context: object pool. want to give the pooled objects a timeout. Better to use coroutine or just a timed invoke? (there can be 100+ in the pool)

wintry quarry
#

Yes, have one person stand over the other's shoulder or use discord

#

otherwise - you should use git or other version control to collaborate

errant flame
#

nope still not getting it sorry. I have anchor to the center

#

what else do I need?

polar acorn
errant flame
#

tyty

eternal needle
crimson pike
#

its a reusable class i made UnitPool, and it uses a queue of classes implementing IPoolable

crimson pike
wintry quarry
#

similar to other VC. You make change sets, commit them, then pull them from theo ther pc

crimson pike
#

the coroutines would just be waiting for (timeout) seconds and then force returning the object to it's owner ObjectPool

eternal needle
crimson pike
#

mostly just there as a precaution so nothing hangs outside of the pool forever

#

yeah true.

eternal needle
#

id only really worry if you were using Invoke. if you use update or a coroutine and have performance issues, those performance issues are due to the amount of (likely moving) objects. not because of some timer

crimson pike
#

aye

eternal needle
#

i highly suggest just looking into git rather than unity's version control. you dont need an integrated version control, and git is used in every other branch of computer science. it's way more useful if you were to learn it

errant flame
#

I-m using deltTime, from the documentation I read that its the time from last frame. So in this case, would the position be independent from the frame rate? since faster frames mean smaller updates?

transform.position += Vector3.left * moveSpeed * Time.deltaTime;

#

However in practice, the speed dramatically jumps in the build

#

even the gravitational acceleration increases, which I have not coded myself but implemented with RigidBody2D, what could be wrong?

wintry quarry
#

this isn't enough context

#

yes Time.deltaTime is used to compensate for frame timing differences

#

it lets you convert a per-frame quantity to per-second

errant flame
#

What's the best way to share the full file?

wintry quarry
#

!code

eternal falconBOT
errant flame
#

But you wouldn't see the rigid body implementations etc?

#

Since that's done through the editor

naive pawn
wintry quarry
#

but if you're using a Rigidbody, that code is completely wrong

errant flame
#

That's for the pipes sec

#

I'm gonna share

#

https://pastebin.com/XcUq8Lva this is bird code
https://pastebin.com/NXaZdfgM this is the pipe mover code
in image rigid body of bird

#

The issue: everything in the game seems to speed up, including the falling speed of the bird and the speed of the pipes

wintry quarry
#

you should pick one or the other, not both

#

doing both causes issues

errant flame
#

I see, so tl dr I should never use Physics from the editor if im affecting movement in code?

wintry quarry
#

no idea what you mean by "use physics from the editor"

#

if you're using a Rigidbody you should move the Rigidbody via appropriate physical methods in your code

#

you should not move the object via teh Transform

errant flame
#

but for the pipes

#

the pipes are not rigid bodies

wintry quarry
#

what was the issue again

errant flame
#

everything speeds up randomly after build

wintry quarry
#

it shouldn't

#

make sure you saved your code

errant flame
#

its like theres 2 modes

#

it alternates between full speed

#

and normal speed

wintry quarry
#

also are you sure things are actually speeding up? Sometimes people perceive a speedup when the game resolution is larger

errant flame
#

yes

wintry quarry
errant flame
#

weirdly enough having amd in game overlay on top fixes the speed up

#

i will film with my phone, since the recording prevents the bug xd

wintry quarry
#

if your game is actually haveing framerate issues, that can cause the simulation to slow down

#

if you are exceeding the max timestep

errant flame
#

As you can see it randomly slows down to what should be the correct speed after the first death

#

And then speeds up again randomly

wintry quarry
#

what's in LogicScript

errant flame
wintry quarry
#

Any other scripts in the project?

errant flame
#

theres a pipe spawner and a collision detection for the score

wintry quarry
#

can you show them?

errant flame
#
wintry quarry
#

yeah i don't see anything in here that should do any of this

errant flame
#

there are no other scripts

wintry quarry
#

only thing I can think of is a framerate issue kicking us past the max timestep but that seems unlikely

#

or a hardware issue of some kind 😬

#

maybe some weird GPU setting or something

errant flame
#

maybe

#

amd is famous for weird drivers

#

ok I found the issue

#

its this gpu setting

wintry quarry
#

Oh wow I was not very confident saying that

#

That's crazy

errant flame
#

i can make a short video xd

wintry quarry
#

I believe you

errant flame
#

should i bug report this to unity or what?

wintry quarry
#

yes

errant flame
#

ok cool, i'll look into it tmr, gonna hit the bed soon

#

ty for the help

#

In theory it's an fps unlocker but prob does weird stuff behind the scenes

strong wren
worthy prairie
#

hi

polar acorn
worthy prairie
#

i am working on my own 2d game and want to do a really simple thing but cant figured it neither can chat
i have a gameobject (inside canvas and horizontal layout group) in it i have another game object (its child) which i want to place inside the bounds of its parent randomly. But i am just confusing myself with the coordinate system or idk, when i try to get the height of the parent i always get 100 or 0 both of which are wrong. I will greatly appreciate any help or advice how should i tackle this issue
thanks

worthy prairie
#

Vector2 parentSize = parentRect.sizeDelta;

Debug.Log(parentSize);

this will print: "(491.43, 0.00)" and parent height is clearly not 0 its just broken idk what to do man

hallow rock
#

Dont know how to fix this crap.

polar acorn
polar acorn
polar acorn
# worthy prairie

So, its height is driven by a layout group. When are you logging the height? You might be getting it before the layout has had time to resize it

worthy prairie
#

i fix it

polar acorn
worthy prairie
#

but have no idea why did it work 😄

#

in the parent object of the parent i unchecked control child size height

fleet venture
#

Is it possible to write unit tests for Monobehavior scripts? I see there is some unity test framework but does it allow that?

rich adder
#

You still need a poco iirc

#

Poco class runs function in MB to unit test

ripe matrix
#

hello, does camera.worldtoscreenpoint have a distance limit?

tribal fulcrum
#

can someone help me fix this error if possible please

slender nymph
#

that's not quite how you create a new instance of an array

grand snow
#

is this some homework or somethin cus those comments seem sus

tribal fulcrum
#

it is my homework yeah

#

i googled it and i figured out my error though

ivory bobcat
#

Is this Unity related?

slender nymph
#

Assembly-CSharp
seems like it

#

also coupled with the fact that they can't use newer c# features

pine narwhal
#

Why is my player going into the ground when it is moving?

polar acorn
pine narwhal
#

components of the player

#

everything was working properly until i merged it with the main branch

wintry quarry
#

is moving the renderer into the ground

#

and/or one of your sprites pivots is just off

#

(which is the same thing)

pine narwhal
#

do I have to fix the pivot points in the sprite editor manually for every sprite I used?

wintry quarry
#

maybe? I don't know what your art pipeline is

#

normally it's a spritesheet that is aligned properly from the get go

pine narwhal
#

tbh i don't know what to tell you since Im very new to 2d game dev but could you look at this and tell me what has happened?

#

is this what you mean by the rendering being moved when changing pivots?

wintry quarry
#

YOu need to look at your sprites in the sprite editor

#

and make sure their pivots make sense

pine narwhal
#

I just centered them all back to what they were originally

forest summit
#

if i want to get the velocity of an object right before it collides with something, should i use the contact point with the GetPointVelocity function or will that return the velocity after the collision happened?

forest summit
tribal fulcrum
#

guys can a string be capitalized

polar acorn
tribal fulcrum
#

oh ok

glacial forge
#

Hello, I am making a underground 2d game. its essentially just a game where you are constantly digging down. I was wondering what is the best way to populate a tile map on level load? There are 3 ways of doing it that i thought of.

Generating the entire map, then only rendering what is near you.
Generating the entire map and just loading it all at once
Generating chunks as you get near them.

Im not sure what exactly is best practice, im basically brand new to game development ( i know the basics of unity and am very practiced in c# just never made a game). The tiles themselves are very simple and the only data they hold is their sprite then probably a indicator of what kind of resource they are (probably just held in the tile name). The levels themselves can be 1000x10,000 roughly if i had to guess, but i havent flushed that out so I cant say for sure.

any help/useful resources we be appreciated

wintry quarry
#

you can start with #1 and switch to #3 later

glacial forge
#

thought so but again not super practiced so was just shooting from the hip

tribal fulcrum
#

can someone help me with the bottom method

#

i dont remember how to have them add up every time

rich adder
eternal falconBOT
wintry quarry
tribal fulcrum
#

i have to return the sum of the entire array basically

#

by iterating through each number in it and adding them

wintry quarry
#

so make a variable and add to it

#

but why is your return type int[]?

#

Don't you want to just return a single number?

tribal fulcrum
#

whoops

rich adder
#

int counter;
for(etc.
counter += number[i]

glacial forge
#

there is also just array.Sum()

wintry quarry
#

or foreach (var num in array) sum += num;

tribal fulcrum
sour fulcrum
tribal fulcrum
#

im sure theres plenty of ways to write it though

rich adder
glacial forge
#

fair. learning linq is a great way to get faster at coding for future reference

sour fulcrum
glacial forge
#

thats y i said future reference. good foundation is best

slender nymph
#

considering this is their homework, i doubt that their teacher wants them using linq just yet

glacial forge
#

lol

sour fulcrum
#

flex on em

wintry quarry
#

maybe you should be using your Add method you wrote too lol

#

for homework's sake

glacial forge
# wintry quarry you can start with #1 and switch to #3 later

just checking to see if this is a reasonable way to do this. Right now I have a gameobject with a script attached that on startup makes a tile map object and just loops through and places tiles. (ill make it threaded in the future with a task list).

could also have the tile map be separate and just pass that in via a serialized object. again not sure what is best practice

slender nymph
#

ill make it threaded in the future with a task list
you can't touch the unity api on other threads

glacial forge
#

good to know

#

I could make the array of objects with threads and pass them back into the tile array (in the case that the tiles were large objects)

#

in this case i wont worry about it though

glacial forge
slender nymph
#

that means that most of the unity api is not accessible off of the main thread

glacial forge
#

ok yeah so background processing is fine, just bring it back to main thread before you try to apply it. got it

rich adder
#

If you use Awaitable you can switch up which thread it happens on

glacial forge
#

cool

rotund bolt
#

oh my god

#

that did not format the way i thought it was going to

#

maybe this is better?

sour fulcrum
#

only 1 for single lines, 3 for blocks

rotund bolt
#

hello, i have these two classes that work together to move my character around in unity. it currently works as intended but i am following a tutorial and they dont really explain "why" it works.

I see that the Update() method happens every frame, which initializes inputVector with the GetMovementVectorNormalized() method every time Update() is called. It then gets a little fuzzy to me as I examine what happens inside of GetMovementVectorNormalized()
.
I see inside that GetMovementVectorNormalized() it initializes a Vector2 object called inputVector and then (somehow?) assigns the values of inputVectors y and x variables to key presses such as W,A,S,D with the if statement if (Input.GetKey(KeyCode.W) ).

My question is this: Does the line if (Input.GetKey(KeyCode.W)) automatically just wait for a keystroke to happen? If the Update() method is happening every frame, and if if (Input.GetKey(KeyCode.W)) is
getting ran every frame as well, why does it not break when I dont press a keystroke?

rotund bolt
lilac valley
#

I have always had a doubt in Unity. I come from Roblox Studio, and when we reference objects, we do: workspace.something.something, but in Unity, I do not know very well which is the correct way to reference GameObjects/Components, I usually do it by creating a field of the type of component I want to access, but in the case I do not know which component I want or I get it while the game is running (after a certain action for example), how would I do to reference an object correctly? Could someone help me with this? I'm kinda lost

#

I know about the GetComponent and GameObject.Find thingys, but i feel they are not the best way

wintry quarry
#

It doesn't wait for anything

rich adder
#

Find is the worst

lilac valley
rotund bolt
rich adder
#

if you only need it once you dont need to make a field

#

depends how you want to grab the component, normally physics query, collision etc.

lilac valley
#

hmm, okay

#

thank you

#

sorry for the stupid question, but its kinda confusing 💀

sour fulcrum
rich adder
sour fulcrum
# lilac valley sorry for the stupid question, but its kinda confusing 💀

It's totally normal to be confused.

In the way c# is designed (and maybe how roblox does it?) all references need to be set in code because the language wasn't designed with some nice looking editor in mind. w/ Unity and the Unity Editor the ability to "expose" (via serializing) certain fields where we can drag and drop references ourselves is kind of black magic in regards to how the language works and is a nice and convenient luxury

#

fields are just a box/container for a value so you can either set what that value is via code or via the unity editor

lilac valley
#

yea, I started unity around 2 weeks ago, I'm really loving it, but i always wondered how people would do that, but I got a better idea now

tribal fulcrum
#

is there any way i can zoom out on visual studios

#

so i can take a screenshot of my code

wintry quarry
#

!code

eternal falconBOT
tribal fulcrum
sour fulcrum
# lilac valley I know about the GetComponent and GameObject.Find thingys, but i feel they are n...

Also, while GameObject.Find is almost always gross, stuff like GetComponent, FindObjectsOfType and FindObjectsByTag all have completely acceptable usecases, but they do take "some" work that can almost always be avoided when using more than once by just saving the work that was done the first time. eg.

PlayerManager : MonoBehaviour
    public void HealAllPlayers()
        foreach (Player player in Object.FindObjectsOfType<Player>)
            player.health = 100;

is bad because your doing the work of searching for all the players every time

PlayerManager : MonoBehaviour
    List<Player> allPlayers;

    private void Awake() //happens once when the PlayerManager initializes
        allPlayers = Object.FindObjectsOfType<Player>().ToList();

    public void HealAllPlayers()
        foreach (Player player in allPlayers)
            player.health = 100;

doing the work once and "caching" the results by storing them where they can be accessed later is better because then you only look for them once

hallow rock
#

What’s going on here?

wintry quarry
#

i.e. it's a script that no longer exists or something

wintry quarry
hallow rock
#

thank you so much.

wintry quarry
# frank rivet bump

You either:

  • didn't enable interpolation on your Rigidbody
  • Are moving your camera at the wrong cadence
  • are breaking Rigidbody interpolation with some code that directly modfified the Transform
frank rivet
#

maybe I should

#

!code

eternal falconBOT
zinc zenith
#

Sorry to do this to you guys but where should I start. I've been wanting to learn game development for a while and have tried several times but never had dedication to do it. I plan to learn C# then eventually move on to C++ but I just don't know where to begin. I've watched a few videos but ultimately none of them helped. I scrambled around Unity for 5 minutes yet I couldn't find where to begin and what to do, so is there some other game engine that supports C# that I can use?

frank rivet
#

planecontroller: https://paste.mod.gg/wblrwihcmgpa/0

Hud.cs

//
// Copyright (c) Brian Hernandez. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
//

using UnityEngine;

namespace MFlight.Demo
{
    public class Hud : MonoBehaviour
    {
        [Header("Components")]
        [SerializeField] private MouseFlightController mouseFlight = null;

        [Header("HUD Elements")]
        [SerializeField] private RectTransform boresight = null;
        [SerializeField] private RectTransform mousePos = null;

        private Camera playerCam = null;

        private void Awake()
        {
            if (mouseFlight == null)
                Debug.LogError(name + ": Hud - Mouse Flight Controller not assigned!");

            playerCam = mouseFlight.GetComponentInChildren<Camera>();

            if (playerCam == null)
                Debug.LogError(name + ": Hud - No camera found on assigned Mouse Flight Controller!");
        }

        private void Update()
        {
            if (mouseFlight == null || playerCam == null)
                return;

            UpdateGraphics(mouseFlight);
        }

        private void UpdateGraphics(MouseFlightController controller)
        {
            if (boresight != null)
            {
                boresight.position = playerCam.WorldToScreenPoint(controller.BoresightPos);
                boresight.gameObject.SetActive(boresight.position.z > 1f);
            }

            if (mousePos != null)
            {
                mousePos.position = playerCam.WorldToScreenPoint(controller.MouseAimPos);
                mousePos.gameObject.SetActive(mousePos.position.z > 1f);
            }
        }

        public void SetReferenceMouseFlight(MouseFlightController controller)
        {
            mouseFlight = controller;
        }
    }
}```
eternal needle
eternal falconBOT
#

:teacher: Unity Learn ↗

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

zinc zenith
native thorn
obtuse ether
#

trying to use DG.Tweening to make a smooth hp decrease but sometimes when taking dm + dying to an enemy i get this error message

#

tried to fix it by making the HP script that used tweening a function

#

and then only updating it when taking damage

obtuse ether
ivory bobcat
#

Where/when are you destroying the image/object?

#

I'm assuming from the coroutine die cooldown

obtuse ether
#

it reloads the level scene which is what is ig destroying the image/object

ivory bobcat
#

So.. which variable would they be referring to? It should be a reference to an image object

obtuse ether
void thicket
#

LoadScene and everything destroyed

obtuse ether
#

yeah

ivory bobcat
#

Perhaps consider stopping the tween if possible before loading a new scene?

void thicket
#

There's autokill option iirc

obtuse ether
#

o yeah lmao

void thicket
#

SetLink

obtuse ether
ivory bobcat
void thicket
#

autokill was something related to pooling, SetLink is probably what you finding

obtuse ether
#

yep figured out how to use .setlink and it worked thx a lot

native thorn
#

Is a coroutine typically more or less efficient than setting up a simple timer to fire off

teal viper
#

Don't think of performance. Think of readability, extendability and debuggability.

#

Implementation can be adjusted later.

native thorn
queen adder
#

Yeah those small things would only matter if you have like hundreds of instances running all at once

timber tide
#

coroutines make a little amount of garbage, but there's always alternatives like pooling them, or using UniTask which have some similar features of pre-allocating them

#

and another alternative is just make a manager system where gameobjects can subscribe to

charred spoke
sour fulcrum
#

hard to be super definitive without context, no?

safe root
naive pawn
sour fulcrum
#

hard to tell if it's more without context? surely in some scenarios it's worth considering the tradeoff of what that "barebones" timer would be (eg. having that update loop even running on that class)

fleet venture
#

I only have mb classes

#

But I need to write unit tests it’s a requirement

native thorn
#

If they're close enough to be irrelevant that's good news ahaha

sour fulcrum
#

(hence why i asked that :P)

keen dew
safe root
keen dew
#

It's tilting because its position is higher than the player's position, so it looks downwards

honest iron
#

for some reason only my HP bar updating, im only able to set them

 playerHP = playerMaxHP;
 playerMP = playerMaxMP;
 SetPlayerEXPToLevelUp();

 playerHPBar.maxValue = playerMaxHP;
 UpdatePlayerHPBar();

 playerMPBar.maxValue = playerMaxMP;
 UpdatePlayerMPBar();

 playerEXPBar.maxValue = playerExpToLevelUp;
 UpdatePlayerEXPBar();

 public void UpdatePlayerHPBar()
 {
     playerHPBar.value = playerHP;
     playerBarsTexts[0].text = playerMaxHP + "/" + playerHP;
 }

 public void UpdatePlayerMPBar()
 {
     playerMPBar.value = playerMP;
     playerBarsTexts[1].text = playerMaxMP + "/" + playerMP;
 }

 public void UpdatePlayerEXPBar()
 {
     playerEXPBar.value = playerExp;
     playerBarsTexts[2].text = playerExpToLevelUp + "/" + playerExp;
     print("EXP:" + playerExpToLevelUp + "/:" + playerExp);
 }
teal viper
#

And make sure you don't have errors in the console

safe root
keen dew
# safe root Stop tilting forwards

Try this to keep it level:

Vector3 flatPosition = new Vector3(transform.position.x, 0, transform.position.z);
Vector3 playerFlatPosition = new Vector3(player.transform.position.x, 0, player.transform.position.z);
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(playerFlatPosition - flatPosition), rotationSpeed * Time.deltaTime);
keen dew
#

You're doing Slerp wrong

safe root
#

Ah, I see. I'll to do study these then. Thank you

frank rivet
verbal karma
#
spotlight.pointLightInnerAngle = 45f;
spotlight.pointLightOuterAngle = 45f;

why doesnt this change the Light2D spotlight angle? im positive the reference is valid

verbal karma
#

URP

verbal dome
#

In HDRP at least you need to change it via the additive light data component instead

#

See if URP has a similiar component it adds to lights

#

Oh wait, you said Light2D

verbal karma
#

the component itself works, I just cant set the angle within a script, it just refuses to update

#

indeed

honest iron
#
        foreach (Skill skill in Skills[i])
        {
            GameObject skillObject = new GameObject();
            skillObject.name = skill.skillName + " Skill";
            Image skillImage = skillObject.AddComponent<Image>();
            skillImage.sprite = skill.skillImage;
            skillObject.GetComponent<RectTransform>().SetParent(skillsTabs[i].transform);
            skillObject.SetActive(true);
            skillObject.AddComponent<SkillHolder>().Skill = skill;
            Button skillButton = skillObject.AddComponent<Button>();

            skillButton.onClick.AddListener(() =>
            {
                selectedSkill = skillObject.GetComponent<SkillHolder>().Skill;
                skillName.text = selectedSkill.skillName;
                skillLevel.text = "Skill Level : " + selectedSkill.skillMaxLevel + "/" + selectedSkill.skillLevel;
                skillDescription.text = selectedSkill.SkillDescription;
            });
        }
}
#

the images are too small, how to make them them fit

naive pawn
#

not really a code question? might want to make a horizontal layout group

honest iron
#

ok thanx

valid vine
#

i have just got some issues in c#. i want to make a simple script for a 3d object to move and i tried to make it in 2 hours and it dosent work😭 . can someone explain whats wrong?: transform.position += new Vector3(0, 0, 5f) * Time.deltaTime;

hexed terrace
#

share your !code properly ( 👇 ) , and not just a single snippet like that

eternal falconBOT
hexed terrace
#

and maybe look at one of the thousands of tutorials for movement that are available online!

knotty fable
#

hello

#

newbie here just starting c#

burnt vapor
astral falcon
burnt vapor
#

I would say that is actually better because a timer might need an additional thread or won't work directly in the same Unity "cycle"

#

I would not know though, I mostly ask because I am interested in what the better approach would be

astral falcon
#

Unity has to handle all those coroutines, even when coming from native IENumerable stuff, that might be the overhead. But as said, just guessing here with short reading about whats happening under the hood

grand snow
#

I presume unity will check the yield each update anyway to see if its done so probably no better

hot harbor
#

Is there a way to serialize a Tuple?

#

To be more specific I want to assign a transform for each weapon item, which results in

Tuple<Transform[], Weapon[]> thing
#

Which does not get serialized

grand snow
#

nah make your own class with these 2 fields and mark it as serializable

cosmic dagger
hot harbor
#

The goal is to assign a transform for each specific weapon and I want them to be a one-to-one relation instead of relying on array index

#

the problem is my Weapon is a scriptableObject and I'm not sure if private variables behave normally

cosmic dagger
#

I like using an index though since grabbing it from the collection is O1, it's easier and smaller to store an int . . .

hot harbor
#

Thanks

#

I'll stick to indices for now I guess

grand snow
#

well this will be arrays of references so such a benefit is minimal

sour fulcrum
#

offtopic it seems a little interesting that your weapons are paired with just regular transforms rather than a more direct way of correlating that data

#

i've just never seen something like that before

hot harbor
#

It's because I wanted the locations to not be linked directly to the weapon so I could swap the positions around without attaching the location to the SO

sour fulcrum
#

ah fair. i've usually done that by having some small component on the transform that communicates w/ whatever is managing this but i could totally see that approach

grand snow
#

so you want to associate data with a weapon but not "attach" it to a weapon? wut

hot harbor
sour fulcrum
hot harbor
#

put more elegantly than I could

grand snow
#

Better to have some runtime object and keep the "weapon data" seperate

hot harbor
#

I do

grand snow
#

but only using some index to link the data seems flimsy

sour fulcrum
#

or be even more cursed and start making self-referencing runtime sos

hot harbor
#

a prefab of a turret keeps both the transform positions of the weapons and the weapon's configurations(scriptableObject)

#

Like this

sour fulcrum
#

oh yeah the exact example i was thinking about when mentioning my approach previously was for a turret setup like this haha

grand snow
#

yea id not do this but have a class/struct to hold this data

sour fulcrum
#

a serialized dictionary can also be nice for cleaning up the inspector for those

hot harbor
#

Dictionary sounds much more expensive to initialize than a Tuple though

sour fulcrum
#

i haven't gotten further and/or paid enough to pay for all my various tech debt crimes so i can't confirm or deny that

#

I've had a great experience using ayellowpaper's SerializableDictionary project on the asset store though

cosmic dagger
solemn python
#

any android dev here? How can I disable these adaptive performence logs?

rich adder
fleet venture
#

ye i got it figured out with a tutorial

#

i just had to create a shit ton of interfaces and wrappers

scarlet skiff
#

There is a layer called player. It's the player's layer. There is a layer called ground. It's a layer for the ground. I have items with colliders. I want this collider that the items have to act as a normal collider when it touches the ground. But when it touches the player, I want it to act as a trigger collider. I was thinking maybe to create an item layer and then have it ignore the player layer, but then that wouldn't even trigger the isTrigger collider. So what would be the best approach?

Basically, it can collide with the ground, it has gravity and once the gravity drags it down to to touch the ground, it stays there, but the player should be able to walk through the item, while still being able to detect its there.

How do i approach this?

timber tide
#

Should be able to just make a child object with a trigger collider

polar acorn
scarlet skiff
#

so the item has its own layer which ignores collision with player laye,r but has a child that doesnt have the item layer, and that child has the trigger collider?

polar acorn
#

yes

timber tide
#

Triggers are fine, but non-triggers would become composite

scarlet skiff
polar acorn
#

Do note that this would necessitate a Rigidbody on your player character, since putting two rigidbodies on the same object is going to cause problems. But that's most likely the case already

polar acorn
scarlet skiff
#

yes player already had rb

#

okay thanks

timber tide
#

You can actually exclude colliders from the rb directly from the component if not the matrix setting

#

but probably worth it to do it globally if you've multiples

deft ridge
#

How do you trigger particle effects using animation animation events? I have a Slash effect prefab that I want to time to an attack animation, and I want to be able to set the location rotation and scale for each animation's slash effect

timber tide
#

If you know how to add events, you make a script with methods specifically to be called by those events

#

Usually you can send in parameters with the events, so give it the position where it is in the animation, move the particle system there, then Play() the system

#

or, attach the system locally to the bone of where the particle system should be played and just Play() it

deft ridge
#

alright, thanks!

ripe matrix
#
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class CombatUI : MonoBehaviour
{
    public GameObject enemyUIPrefab; 
    public Camera mainCamera;      
    public Canvas canvas;             

    private Dictionary<GameObject, RectTransform> enemyUIMap = new Dictionary<GameObject, RectTransform>();

    void Update()
    {
        GameObject[] allEnemies = GameObject.FindGameObjectsWithTag("Player");

        foreach (GameObject enemy in allEnemies)
        {
            if (enemy == gameObject) continue;

            if (!enemyUIMap.ContainsKey(enemy))
            {
                GameObject uiElementPrefab = Instantiate(enemyUIPrefab, canvas.transform);

                Debug.Log($"Instantiated UI for {enemy.name}");

                enemyUIMap[enemy] = uiElementPrefab.GetComponent<RectTransform>();
            }

            RectTransform enemyUI = enemyUIMap[enemy]; 
            Vector3 screenPos = mainCamera.WorldToScreenPoint(enemy.transform.position);

            if (screenPos.z > 0)
            {
                enemyUI.gameObject.SetActive(true);
                enemyUI.position = screenPos; 
                Debug.Log("updated ui position");
            }
            else
            {
                enemyUI.gameObject.SetActive(false);
                Debug.Log("UI is hidden");
            }

        }

        List<GameObject> enemiesToRemove = new List<GameObject>();

        foreach (var entry in enemyUIMap)
        {
            if (entry.Key == null)
            {
                enemiesToRemove.Add(entry.Key);
            }
        }

        foreach (GameObject enemy in enemiesToRemove)
        {
            Destroy(enemyUIMap[enemy].gameObject);
            enemyUIMap.Remove(enemy);
        }
    }

}

Above here, i have a script to display a crosshair over other players. However, when the players are too far away, it doesnt work?

#

I can't seem to find any issues

bright zodiac
#

but yeah they will never allow us to serialize Tupple/ValueTupple for a good reason

#

imagine if some dumbo coders do this

(int, float, (float, int, (string, string))) a;
#

now imagine how they'd serialize that 😂

proper yacht
#

How should character move within new input system? I've set invoke events in behavior and wrote this method:

        private void OnMove(InputAction.CallbackContext ctx)
        {
            Vector2 _movement = ctx.ReadValue<Vector2>();
            _characterController.Move(new Vector3(_movement.x, 0, _movement.y) * _speed * Time.deltaTime);
        }

Character is moving by 1 value and only when I press (I'm using Value in action type but it works so idk)

#

As I've read it should be in Update but a couple of weeks ago when I started learning Unity it worked without it

#

I'm not full of confidence about the best solution in this situation

rich adder
#

move the actual CC in update

#

make _movement not local

small dagger
#

Is it possible to reference a specific file type in code? For example, I want a serializedfield variable that can hold OGG files

small dagger
#

gotcha

#

is there a way I can see what data type these imported assets and stuff would be?

polar acorn
#

Unity doesn't deal in file types, they deal with Asset types. File types can tell Unity which kind of asset it is, but multiple file types can map to the same type of asset

#

For example, png and jpg both become Textures

small dagger
#

gotcha, makes sense

polar acorn
#

(Or Sprites depending on your project settings)

small dagger
#

Is there a way I can see what asset type something is in the editor? I have it selected but can't seem to see it in the inspector

proper yacht
polar acorn
polar acorn
small dagger
rare elm
#

hello. i'm trying to use a sprite sheet i bought on unity store. i have two problems, both of which are probably pretty simple

  1. i've been using auto-trim to get the sprites out of it, but these sprites move around on the canvas when they "jump," and auto-trim effectively removes that. they are gridded. can i just specify math to place them?

  2. i've been making animators by dragging things onto the scene, because i don't know what i'm doing. the problem is, this time that produces bad results, because i get the entire sheet, which contains multiple characters, in a single animator. is there a way for me to specify what sub-range to use?

#

i guess i could just cut the sprite sheet apart but these seem like things i ought to know either way

proper yacht
boreal umbra
#

Can I give coordinates after vector2?

naive pawn
#

needs more context

#

absolutely no clue what you're talking about there

cosmic dagger
rich adder
boreal umbra
#

For example, let the ball jump 1 unit up and 1 unit to the left.

naive pawn
#

not a code question