#💻┃code-beginner

1 messages · Page 457 of 1

rocky canyon
rich adder
#

the more the better 😛

frank flare
#

Pretty understandable

rocky canyon
#

bout the whole out vs ref shindig

sage lotus
#

hey guys, noob question.
idk what to search for to try and start learning this.
how to get a move to point (mouse click) but having it so the character can only move a certain number of units per turn

#

can anyone point me in a direction to start learning stuff like this?

rich adder
#

You'd need some type of algorithm , first define what a "unit" is

rocky canyon
#

turn based movement unity or grid movement (per turn)*

sage lotus
#

I'll try those. I searched similar things but had no luck. much appreciated

rich adder
#

ya A* usually will do the trick

rocky canyon
#

turn based games are much harder to make than realtime games imo

rocky canyon
rich adder
sage lotus
#

seems that way for sure, esp for someone like me that has very little to no experience

rocky canyon
#

meh, it just depends on what u build around it..

#

the movement system.. itself is a bit more involvde than other methods..

#

but once u get that going its going already..

#

it just depends on how much junk u throw on top

rich adder
#

tbh the hardest part i found was making specific shapes on a grid

#

for like attack patterns

rocky canyon
#

id just fake a grid..

#

use waypoints evenly spaced..

#

and then a* around

rich adder
#

I used tilemap but the hex on that is a bitch and half

rocky canyon
#

ya, i see those hex ones..

#

😅 phew

rich adder
#

I should've done square first UnityChanLOL

sage lotus
#

for things like hit percentage according to cover amount, angle, and distance plus accuracy stat seems to be doable with a lookup table rather than calculations, but i guess math is still needed for puting together the 4 different values

rich adder
#

math is everywhere my guy lol

sage lotus
#

I was thinking more of a baldurs game kind of movement. not tile based, but to move a certain distance per turn

rich adder
#

thats easier to do just by using positioning tbh

sage lotus
#

you tellin me all computers are just math machines? D:

rich adder
#

big ass calculator thats so loud 🫣

sage lotus
#

deer GOD

#

alright. thanks for the help guys. i'll get back to it

flat elbow
#

Hey so im trying to make a 2.5 fighting game but i have no idea how to add 2d sprites in the game

#

btw im using 3d unity

eternal falconBOT
#

:teacher: Unity Learn ↗

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

rich adder
#

just put a sprite render on it, same way you do in 3D as in 2D

rich adder
#

Unity is a 3D engine , the only thing that changes is the physics

flat elbow
#

i have no idea what just said

polar acorn
#

It's exactly the same

#

2D is just a checkbox on the camera and using all the physics components that have "2D" at the end

flat elbow
#

so do i use 2d unity instead of 3d???

polar acorn
#

Again, it's just Unity

flat elbow
#

Wth are you saying????????

patent patio
#

Hey, just out of curiosity, what is it called when doing something like this?
float a = bool ? value1 : value2;

flat elbow
#

im new to unity btw

rich adder
polar acorn
# flat elbow Wth are you saying????????

I'm saying:

There's no such thing as "3D Unity"
It's exactly the same
2D is just a checkbox on the camera and using all the physics components that have "2D" at the end
There's no such thing as "2D Unity" either
Again, it's just Unity

patent patio
#

Alright thanks 🙂

polar acorn
#

the question you asked was "How do I use sprites in 3D Unity" which I did answer.

flat elbow
polar acorn
#

If that's not your question, you should ask the one you really have

rich adder
flat elbow
polar acorn
rich adder
polar acorn
#

The bigger the question, the more general the answer has to be. The answer to "How do I make a 2.5D fighter" is "You do !learn and find out how to do whatever you want to do in Unity and make it to your specifications"

eternal falconBOT
#

:teacher: Unity Learn ↗

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

flat elbow
summer stump
summer stump
#

When posting that much code, please use a paste site

flat elbow
summer stump
#

Click that link. Read it

polar acorn
eternal needle
vapid yew
#

@summer stump Thanks for your input

rich adder
summer stump
vapid yew
#

Without discrediting your workflow it woudl have been faster to just paste it into your editor of choice instead of a hyperlinking.

vapid yew
#

This ensures question visibility too

polar acorn
#

We don't need your code to work

summer stump
polar acorn
#

I can 100% just not read the question and continue playing Minecraft

#

You're the one with a goal to your post

summer stump
#

But ok... someone may be willing to help. A lot of people here are on phones or just prefer paste sites, but best of luck!

vapid yew
#

I didn't know of the posting criteria. I just read it now.

spice sigil
#

I don't know if this is the right place and such, but can someone help me?

I made this movement script, but I click on the "S" key and on the down arrow it goes forward

I'm using the character controller

slender nymph
#

!code

eternal falconBOT
summer stump
spice sigil
rich adder
#

yet you can use a game engine ?

spice sigil
#

Yes

#

but if I try to take a picture it freezes

vapid yew
#

@slender nymph Hey pal can you help me with a #noob question?

#

I don't mean to call you, I just remember your usename.

summer stump
summer stump
vapid yew
#

Just for you, fine

summer stump
#

And being conscious of people other than yourself

vapid yew
#

It actually doesn't even meet the rule criteria. But there u go 🙂

vapid yew
half egret
#

Also... don't ping people randomly

#

That's pretty explicitly stated

steep rose
#

its a troll, dont mind him

#

mods should take care of it

half egret
#

Sleepy me always misses the obvious signs, time for bed

vapid yew
#

https://paste.ofcode.org/8biXBq89vaKcHZRVJ38Wqe

externalVelocity: the velocity/float/bob of a moving platform. I apply this to the player's velocity so they move around with the platform.
The player applies downwards force when landing on floating platforms.

  1. I know input/movement has to be framerate independent; Have I multiplied TIme.deltaTime correctly?

  2. Should I apply velocity.y += gravity * Time.deltaTime; every frame or just when the player is not grounded? When and why would you pick this?

  3. Should I call a second Move() to apply apply gravity/external velocity after my initial Move() call?

  4. Do I even need to smooth externalVelocity? Keep in mind I want to avoid jitter from the camera/characterController. The floating platforms are intentionally springy when the player walks on them.

summer stump
vapid yew
#

@summer stump My disappointment is immeasurable, and my day is ruined...

frosty hound
vapid yew
#

@frosty hound It's alright man=

frosty hound
#

!mute 310735647147163651 1w Prefers to be the nuisance.

eternal falconBOT
#

dynoSuccess __pipes__ was muted.

jaunty bay
#

quick question:

i want a DDOL object to run a function every time a scene is loaded (because my DDOL GameManager object should set the player's spawn every time the player enters a room). which function should i use?

wintry quarry
#

Alternatively make your own wrapper function around loadscene and just call that instead

solemn fractal
#

hey guys is there a way to do something like that? I want to have already pre difined how many of each monster I want will spawn in each wave of my game. And then I can access each value like waves.wave.goblins to get the value of that monster in that wave..

#

I dont know the name of that and if it is possible. with list or something?

#

An array of arrays something liek that? I used like that in javascriptvar chests = [ { name: 'Small chest', amount: 5 } algo assim

raw token
#

Sounds like you're looking for a Dictionary, or possibly a List of dictionaries, e.g.

List<Dictionary<EnemyType, int>> Waves

On a side note, an MS Paint illustration of pseudo-code is a weird choice... just use text, yeah? 🤪

solemn fractal
tepid idol
#

I lied, I fixed it

#

Thank you though, Raccoon

tepid idol
#

Well, I ran into another error sadly

#

The modifier 'private' is not valid for this item, line 160

#

I'm confused why it's not valid

languid spire
tepid idol
cedar bone
#

For some reason, my svg file is not appearing in game

sand heath
#

you just can't say private

cedar bone
languid spire
languid spire
pale ocean
#

Hi all, I'm working on a flappy bird clone, and I wanted to move pipes when they're out of the camera view closer to the player and this is the code I've written for this: https://hastebin.com/share/emeqihomaj.csharp anyways, it results in some funky looking pipes anyone got a clue on why this is happening

#

It works fine when I do it with a singular pipe, but when I use the pipe as a prefab

#

this is what happens

#

Also, it's moving the pipes way after they're out of view. I don't know why this is, but maybe it's a cinemachine thing

strong harness
#

Is it OK to define a dictionary with the key Vector3?

 public override int GetHashCode() => this.x.GetHashCode() ^ this.y.GetHashCode() << 2 ^ this.z.GetHashCode() >> 2;
languid spire
cedar bone
#

How do I set the layer of all the children and grandchildren of a parent?

keen needle
#

When you change it to the father, it asks you if you want to apply it to the children as well.

languid spire
rain solar
#

how can i simulate granular particles without killing fps in 2d world?

cedar bone
#

do i put a loop inside a loop?

storm heath
#

Hello

languid spire
strong harness
#

So, instead of defining icon position as a key, define a data structure?
For example <Gameobject, IconData>

languid spire
#

why not just use GetInstanceId() of the gameObject which is an int and unique

strong harness
languid spire
#

every Unity Object has a Instance id

strong harness
#

but yes, all icons that I want to show is related to a gameobject, perfect

rain solar
#

how can i simulate granular particles without killing fps in 2d world?

storm heath
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

storm heath
#

hello brothers

storm heath
#

I made my first game with tutorial

#

I know, it is so basic but it is not problem for me.

#

It is a car game

lunar hollow
#

How do i copy Variables from a Duplicated Script with the Same Variables to the Original one? When i copy the Component i can only paste it as new,

fickle plume
storm heath
#

you can drive your car and you can pass through obstacles

fickle plume
lunar hollow
storm heath
ivory bobcat
lunar hollow
#

Alright.

fickle plume
undone plume
#

Hi, i tried to make when the green image drag func is triggered, the red object (its an image) will be cloned as a draggable object. The clone works as expected but it wasn't visible in the game scene. how to fix?
this is the code to the green image: https://hastebin.com/share/anahocaxuc.csharp

lunar hollow
deft ridge
#

I'm making a figihting game in Unity, and I want to start by porting an Input Buffer that I coded in Python into Unity. Here is my ported code:
https://pastecode.io/s/5igxvaxz

I have everything set up in the Inspector, but when I run it just looks like this. Pressing buttons creates clones in the Buffer gameobject, but nothing actually happens on screen. How can I fix this?

fickle plume
#

It will save its current state

marble hemlock
#

okay so i was going through the beginner scripting resource and i got to classes, and i notice that he has this script, so i put it into my code (had to make minor adjustments for what I was trying to do)

#

but what im trying to figure out is what exactly in this script is letting it know that wasd is for those movements

#

is it the Vector3.forward and Vector3.right?

#

i understand how the script works, mostly, since he's already explained floats and translate and all that in the ones before it, but i dont understand how it knows wasd is the intended way to move

fickle plume
polar marsh
#

In unity settings vertical is set to W and S

#

and horizontal is set to A and D

fickle plume
#

And GetAxis alters it positively or negatively on input setup in the InputManager

polar marsh
marble hemlock
#

hold on ive lost the object

fickle plume
polar marsh
#

so if you swapped it round, w and s would move left and right and a and d would move forward and backwards

marble hemlock
#

i think i understand now
thank you both

polar marsh
#

Np man

#

If u want to change the key for any reason, the settings are under Project Settings/Input Manager

fickle plume
#

Right, you are applying translation in update, you do need deltaTime for it.

late burrow
#

startswith/endswith works at same speed regardless of string length?

wintry quarry
late burrow
#

not size im checking but size of the original string

agile summit
#

I've built a simple 2d platformer game for Windows; the Fullscreen Mode is set to "Exclusive Fullscreen". If we open an application like a Unity Project, it will take some time for it to open in the background. In the meantime, if we open our game and Unity Project completes loading and opening, it will overlap our game while it is running.

Does anyone know how to fix this?

short hazel
languid spire
#

Not strictly speaking true, a windows program can request to be 'Always On Top'

steep rose
#

OpenGL looking good right about now

languid spire
#

it's very trivial to write a wrapper program that does this if necessary

fervent wren
#

ait steve :p this is my first script in unity btw

#

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
[SerializeField] private float speed;
private Rigidbody2D body;

private void awake()
{
    body = GetComponent<Rigidbody2D>();
}

private void Update()
{
    body.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, body.velocity.y);
}

}

chilly halo
#

Does anyone know how to reference a .net assembly? I need to use system.windows.forms

languid spire
#

ok, it's pretty obvious.
The error message is telling exactly where the problem is. Line 15
So body is null

slender nymph
fervent wren
#

ohhh it tells you the line nice!

languid spire
languid spire
chilly halo
fervent wren
languid spire
fervent wren
#

thanks guys!!

languid spire
fervent wren
#

srry was just showing my meagre progress ^^ i'l post in there when i make something nice

#

im like following a tutorial online but when he types stuff, its gets proposed in the dropdown menu, with me it doesnt, is that like a setting somewhere?

eternal falconBOT
umbral rock
#

So im trying to make an inventory system but theres something wrong with a function that isnt working...
So as u can see i have a function called AddItem and it works in the item.cs and the inventory.cs but in my itemslot if i try to set the item sprite equal to the image(ui box) sprite it doesnt work, it doesnt even Log in the console that the item has been added...?

fervent wren
# languid spire !ide

im using visual studio, stuff like GetComponent, Rigidbody2D or SerializeField dont get proposed in the dropdown

languid spire
fervent wren
languid spire
#

this means your IDE is not configured. So follow the configuration steps in the bot message

mossy robin
#

Hello I need some help with maybe a script problem if anoyne can help

slender nymph
mossy robin
#

Its more to do with restarting the scene and some components are disabled while others are enabled and idk what could cause that

slender nymph
#

and yet you've still not actually provided any useful information that would allow someone to help you. 👇 !ask

eternal falconBOT
chilly halo
languid spire
umbral rock
#

im having issues with my inventory system, im trying to add an item to my inventory and if i debug it it should work but i dont see the item sprite on my UI image...

slender nymph
#

you need to get your !IDE configured

eternal falconBOT
umbral rock
#

this is the problem?

slender nymph
#

no, but it is a requirement

umbral rock
#

oh lol

#

but aside from that, is there anything that could fix the issue that i have?

umbral rock
rich adder
umbral rock
#

now its configured...

rich adder
#

show it

umbral rock
rich adder
umbral rock
#

yes its working

slender nymph
#

how have you confirmed that

umbral rock
#

if i collide everything goes good but the image is not in the inventory

umbral rock
slender nymph
#

how

umbral rock
#

and as u can see the item sprite is also in the itemslot

slender nymph
#

well idk where that first log is coming from. but the second log only proves that AddItem is being called

#

well then it is being set correctly. if it isn't working then either you are calling AddItem on the wrong object, or there is something else incorrect with your setup that you've not provided any details about

umbral rock
#

its basically just the itemsprite that wont get into the inventory image sprite

slender nymph
rich adder
#

looking for gameobjects by name is pretty bad tbh @umbral rock

clever basalt
rich adder
umbral rock
#

i just dont know where my error could be, code looks totally fine

slender nymph
#

because the code is totally fine. as you've shown, the correct property on the image component is being assigned correctly. something else is incorrect about your setup.

rich adder
# umbral rock

does the sprite in the inspector change? think i missed that part

umbral rock
#

could be because of the item sprite here? My item is red coloured but maybe the sprite i add is wrong?

slender nymph
#

the color assigned there has nothing to do with the actual sprite

umbral rock
slender nymph
#

in fact, the sprite renderer's sprite and the sprite assigned in the Item component are two completely different sprites

umbral rock
#

when i have not collided vs when i collide

slender nymph
#

even if you did use the same sprite though, the color property is on the SpriteRenderer not the sprite itself

rich adder
slender nymph
rich adder
#

what it supposed to look like ? change the tint back to white

#

black is tinting the sprite so you can't see anything prob

umbral rock
umbral rock
#

lol, how do i change the colour of it?

#

i'v set the image to green but not going to green

rich adder
#

wdym this is just a tint, it tints the whole sprite not specific parts

umbral rock
#

ohh, how do i remove it?

rich adder
#

what does original look like?

slender nymph
umbral rock
#

pretty new to the ui coding and editing in unity

rich adder
#

thats not the original sprite

#

show what ur trying to replace that with

slender nymph
#

well naturally nothing changed here because there is no sprite assigned to that image component

#

but yes, look at the material as well

#

and of course make sure you don't happen to have another image on top of that one you have selected. you've not bothered showing the actual hierarchy so it's not possible to tell

umbral rock
#

removed the images and added one, now it works to change colour, and when i collide with the item the image is a bit blurry and changes a tiny but but no item on it, lemme show u

rich adder
#

fix your Scale

umbral rock
#

theres a tiny tiny difference

slender nymph
#

let me guess, it's still being assigned to the "InputFieldBackground" sprite? the one you are explicitly assigning to it because that is the one assigned to the Item component?

#

at this point though, i am done repeating myself about what the issue is. so good luck 👍

rich adder
#

@umbral rock why do you need rounded sprites at runtime on image in the first place, why not just spawn that UI image with sprite already.

#

not sure why you're doing any of it at runtime tbh, are the slots not supposed to be fixed to a dashboard?

umbral rock
#

i'v added the sprite to the image now, it works now and the item is basically added, but the sprite of the item that is added into the itemslot is not good because now the itemslot is becomming a circle, so i need to change the sprite of the item to the one i want, whats the best way of doing this

slender nymph
#

whats the best way of doing this
assign the correct sprite?

umbral rock
#

well, now the sprite of the item is a knob, so the itemslot changes into that knob

umbral rock
slender nymph
#

wdym you can't add a sprite?

umbral rock
#

well, the item is a 9-sliced right?

slender nymph
#

you've literally described having added a sprite. just not the one you want

umbral rock
#

i cant set the sprite to 9-sliced

slender nymph
#

show the import settings for the sprite you are trying to use

marble hemlock
#

i require some assistance of the "i fucked up and im not even sure where" variety

#

so i made a movement script, and that went well
had a bit of trouble with the camera script, but found one online i understood pretty well but i had to adjust it to my script and set up and whatnot

umbral rock
#

well im not importing a sprite but i just want to show the original object... its hard to explain look

i want the same if u know what i mean

marble hemlock
#

video too big hold on

marble hemlock
#

thank you

slender nymph
marble hemlock
rigid robin
#

Hey guys, Im working on a gravity gun-esque tool for a 3d physics-heavy game and I noticed that when a given object is "held" by the tool, there is visible jitter. Now, interpolation is the solution for these kinds of camera-tracking situations, however I havent really used it before and so I have some concerns. First of all, if I have hundreds of objects with interpolation turned on, can this introduce a noticeable performance overhead? Could this be avoided by only turning on interpolation for a given object when it is interacted with by the tool? Can interpolation cause problems if I have some outside force affecting the held object, like an explosion or another object bumping into it, etc, or is this handled by the physics system internally?

marble hemlock
#

okay so the camera moves, which is great
absolutely perefct

#

problem is that the entire thing is moving, and i realize that part of the problem is that its attached to the player object, which is kind of lower on my concerns

umbral rock
marble hemlock
#

my primary concern is that i can go through objects, which wasnt really the goal

slender nymph
# umbral rock thats the problem i cant seem to be able to drag it

well since you're not providing any useful information, i don't know what to tell you. and i'm not going to play 20 questions just to get a tiny scrap of info. so post a full description of your current issue to a relevant channel (since it is not a code issue any longer it does not belong in a code channel) and someone who has the patience to help you will do so

rich adder
rigid robin
marble hemlock
#

yeah i gotta figure that out. im not entirely sure how to do that separately because i want it to to rotate it on the y axis, so the actual player moves, along with the camera

but i also don't want the player object to rotate on the x axis

slender nymph
#

obligatory "use cinemachine"
also the answer to your issue is to just rotate the camera around the X axis, don't rotate the player around the X axis

marble hemlock
#

i am unfamiliar with cinemachine and what it is but uh

#

i think the problem comes with that last line
to note, this is from a tutorial's script but due to me having a different movement set up, it functions a little differently

slender nymph
#

bad tutorial

marble hemlock
#

i had to throw out some stuff

slender nymph
#

don't multiply mouse input by deltaTime, it is already framerate independent

marble hemlock
#

i mean it gets the rotation working
its just i have everything turning

slender nymph
#

and separate the axes of rotation and only rotate the camera around the X axis

marble hemlock
#

i dont know how ;-;

#

im this 🤏 close to just making two individual scripts 😭

#

but surely it can be done in one

slender nymph
#

look at where you are rotating the object and think for a second

marble hemlock
#

i will attempt something

rich adder
#

Transform cameraTransform Transform playerBody

#

etc.
transform.rotation depends a lot on where you place the script.
pretty obvious putting this NOT on the camera but player you are rotating the whole player..

queen adder
#

Hey guys i have one question, where should I start learning on how to use unity?

eternal falconBOT
#

:teacher: Unity Learn ↗

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

queen adder
#

oh thanks

marble hemlock
#

something like this?

#

i forgot serializefield was very much a thing

#

fair point

#

will try

rich adder
#

you dont need to YRotate the camera though if its child of body

#

the body rotation of player will take care of that

slender nymph
#

ideally it won't be a child of the player though

rich adder
#

why's that?

marble hemlock
#

my god

rich adder
#

I usually child my camera to player body

#

is that wrong ?

marble hemlock
#

if i set one to 0 won't it just refuse to move the y value

marble hemlock
slender nymph
marble hemlock
#

now i have to figure out why i keep going through objects

#

i thought having a collider would just prevent objects from... well just going into each other

slender nymph
#

it entirely depends on how you are actually moving

rich adder
slender nymph
marble hemlock
rich adder
#

yes don't use translate

marble hemlock
#

thats specifically how im moving

#

damn

rich adder
#

slap a character controller on it

#

the direction n stuff doesn't change, replace it with cc.move method

marble hemlock
#

how do i send a script ;-;

rich adder
#

use links ⬇️

eternal falconBOT
marble hemlock
#

cant send here directly?

rich adder
#

no because its a pain to view

#

only small snippets is ok for codeblocks (4-5 lines)

marble hemlock
#

this was the movement ;-;

rich adder
#

yes, like I said. Put character controller and just replace the Translate to characterController.Move

#

that should fix collisions as you will be using a physics object + collider

#

you can remove any colliders you have on player, as character controller comes with one

marble hemlock
#

will report back once i finish fighting getcomponent to work

uneven oriole
polar acorn
marble hemlock
#

im not even sure but give me a bit
i went from 10 errors to 4 so clearly im going in the right direction

#

(?)

#

no it seems im stuck

#

i tried to use getcomponent but i might have been wrong in my selection

fervent wren
slender nymph
#

look at the message directly below the one you replied to. the bot linked relevant guides

fervent wren
rich adder
slender nymph
marble hemlock
#

OHHH

#

wait

#

wait

fervent wren
#

the first one

rich adder
#

so visual studio ?

fervent wren
rich adder
#

before the Updating part, there are quite a few more steps

fervent wren
#

jup, did all that

rich adder
#

did you verify you had Unity Workload?

#

ok so go into external tools in unity again, close vs., click Regen Project files, open script from unity..wait till it loads n report back with a screenshot

rich adder
# fervent wren

that would be the page, yes did you read the rest of the sentence

fervent wren
#

yes but this is where i got stuck

rich adder
#

open script again from unity

marble hemlock
#

i fix one thing and something else breaks notlikethis

rich adder
#

welcome to gamedev/coding

marble hemlock
fervent wren
marble hemlock
#

i am now moving relative to my position in the game world instead of just my own position and i dont even remmeber how to undo that

#

colliders work though

rich adder
#

oh right translate is local afaik and Move is not

#

use Transfrom direction or use transform.forward etc.

#

Vector3 uses world position

marble hemlock
#

goodbye vector3 it seems

rich adder
#

its still a vector3, its just already rotated according to transform

#

transform.forward will give you the objects local forward for example, still a v3

marble hemlock
#

thank you 🙏

#

on the bright side from this experience, if i ever want to make a ghost game i now know how

ancient ginkgo
#

so I'm new here and idk if anyone will know how to help, but essentially this is my first time ever coding/designing and on unity hub i tried to install the editor but its stuck validating the editor application... any tips?

eternal falconBOT
#
When Unity fails to install checklist
  • Make sure you have enough space including on C: drive.
  • Check that it's not being blocked by antivirus/security programs.
  • Look through the logs for a real reason why the setup fails they are pinned [here](#💻┃unity-talk message).

If you still have issues, perform a clean install in another location:

  • Install the Hub and Unity in a non-system drive or a clean new folder in the root of C: drive.
  • Failing that use the recovery Refresh option or reinstall OS entirely then repeat the previous step.
slender nymph
frank flare
#
using System.Collections;
using System.Collections.Generic;
using System.Security;
using JetBrains.Annotations;
using UnityEditor.Callbacks;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.InputSystem;

public class GrabItems : MonoBehaviour
{
    bool isHolding = false;
    public GameObject objectHolding;
    Rigidbody rb_objectHolding;
    public GameObject hands;
    public Vector3 farness;
    Camera cam;

    void Awake()
    {
        cam = GetComponent<Camera>();
    }

    void Update()
    {
        if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == false)
        {
            var ray = new Ray (cam.transform.position, cam.transform.forward);


            if (Physics.Raycast(ray, out var hit)) {
                var Object = hit.collider.transform;
                objectHolding = hit.collider.gameObject;

                if (objectHolding.TryGetComponent<Rigidbody>(out Rigidbody rb_objectHolding))
                    isHolding = true;
            }
        }
        else if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == true)
            isHolding = false;
    }
    
    void FixedUpdate()
    {
        if (isHolding) {
            //objectHolding.transform.position = hands.transform.position + farness;
            //objectHolding.transform.position = Vector3.MoveTowards(objectHolding.transform.position, hands.transform.position, 40f);
            rb_objectHolding.MovePosition(hands.transform.position * Time.deltaTime * 40f);
        }
    }
}

why is rb_objectHolding gray?

slender nymph
#

that's actually an unrelated local variable named rb_objectHolding not your field of the same name
remove the type on that line and it won't be declaring a local variable and will instead use the field

ancient ginkgo
cosmic dagger
#

also, Rigidbody in TryGetComponent is greyed out as well . . .

frank flare
cosmic dagger
slender nymph
frank flare
#

I want to use trygetcomponent as a check and assign rigidbody to rb_objectHolding

frank flare
slender nymph
#

yes

#

you can clearly see that it is now using the field rb_objectHolding rather than declaring a new local variable with that same name

frank flare
# slender nymph yes

oh I'm dumb I got to the solution before, I just forgot to add rigidbody to the object I'm raycasting

summer stump
cosmic dagger
# frank flare it doesn't help

it's because you specify rb_objectHolding as a Rigidbody making it a local variable. remove Rigidbody from TryGetComponent<> and the argument . . .

frank flare
#

yeah

slender nymph
#

having the generic type parameter there is perfectly fine, just a bit redundant since the method can infer the type from the output parameter. and if they want it to remain clear about what type it is supposed to be getting then leaving the generic type parameter is perfectly fine. the only issue was the declaration of the local variable as the output parameter

cosmic dagger
#

Yeah, I was just clarifying about why Rigidbody and the variable name were greyed out . . .

civic flax
#

hi, all. does anyone know real quick why it is saying object reference not set to instance of an object with this line? hpfohud.SetText(currenthp.ToString());

#

the code actually works perfectly, and does what i want, but for some reason it throws that error..

polar acorn
civic flax
#

but it works, though..

#

i dont understand how its null

#

current hp should be 200, and it displays 200, even the placeholder text where the hp is says "hps", not like i set it to 200 or something

#

but when i run the game it sets it to 200 correctly

polar acorn
#

You might have one of these running properly

#

but the existence of this error means there exists at least one instance of this script for which hpfohud is null

civic flax
#

i see, ill try and look for that

#

AH

#

thank you

#

i SOMEHOW put it on some random block in my level

frank flare
#
using System.Collections;
using System.Collections.Generic;
using System.Security;
using JetBrains.Annotations;
using UnityEditor.Callbacks;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.InputSystem;

public class GrabItems : MonoBehaviour
{
    bool isHolding = false;
    public GameObject objectHolding;
    Rigidbody rb_objectHolding;
    public GameObject hands;
    public Vector3 farness;
    Camera cam;

    void Awake()
    {
        cam = GetComponent<Camera>();
    }

    void Update()
    {
        if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == false)
        {
            Debug.Log("clicked");
            var ray = new Ray (cam.transform.position, cam.transform.forward);


            if (Physics.Raycast(ray, out var hit)) {
                Debug.Log("raycasted");
                var Object = hit.collider.transform;
                objectHolding = hit.collider.gameObject;

                if (objectHolding.TryGetComponent<Rigidbody>(out rb_objectHolding))
                {
                    Debug.Log("got component");
                    isHolding = true;
                }
            }
        }
        else if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == true)
        {
            rb_objectHolding.useGravity = true;
            isHolding = false;
        }
    }
    
    void FixedUpdate()
    {
        if (isHolding) {
            //objectHolding.transform.position = hands.transform.position + farness;
            //objectHolding.transform.position = Vector3.MoveTowards(objectHolding.transform.position, hands.transform.position, 40f);
            rb_objectHolding.useGravity = false;
            rb_objectHolding.MovePosition(hands.transform.position);
        }
    }
}

how can I make it slower?

#

rb_objectHolding.MovePosition(hands.transform.position);

#

in FixedUpdate()

#

what's explained in unity site does bugs

polar acorn
frank flare
#

I tried rb_objectHolding.MovePosition(hands.transform.position * 0.1);

#

and 0.5

polar acorn
#

That doesn't make much sense

frank flare
# polar acorn That will teleport it to a position that is 1/10th of the distance from the orig...
void FixedUpdate()
    {
        if (isHolding) {
            //objectHolding.transform.position = hands.transform.position + farness;
            //objectHolding.transform.position = Vector3.MoveTowards(objectHolding.transform.position, hands.transform.position, 40f);
            rb_objectHolding.useGravity = false;
            rb_objectHolding.MovePosition((hands.transform.position - objectHolding.transform.position) * 0.1f);
        }
    }

still doesn't work

polar acorn
strong wren
#

how can i make it so a bullet always goes the way of the barrel

#

wait thats kinda stupid leme send a screenshot to explain it alittle better

raw token
#

Set the bullet's rotation to that of the barrel. Propel the bullet on it's local forward axis

strong wren
#

as u can see the gun is pointing up and so is the bullet yet the force is being added vertically

polar acorn
strong wren
#

Bullet.GetComponent<Rigidbody>().AddForce(transform.forward * BulletForce); this is the code that makes the bullet go woosh

strong wren
polar acorn
strong wren
raw token
#

You're already doing that - it's forward just isn't aligned with the gun's

polar acorn
# strong wren i am

Then your bullet is moving local forward. It's just not facing the direction you want

#

So you need to make sure it is

strong wren
#

its facing up just like the gun

polar acorn
#

When you click on the bullet and look at the local transform gizmo, is the blue arrow pointing in the direction of the bullet

split dragon
#

Hi. I have a problem: I want to refer to the component in the script: "Localized String Event". I was able to find the name, but I can't access the Entry name. How do I access the Entry name?

polar acorn
strong wren
#

its pointing up, just like the bullet

frank flare
polar acorn
raw token
polar acorn
# split dragon

That doesn't look like it belongs to LocalizeStringEvent, that's a property of StringReference it seems

rocky canyon
#

ya, transform.forward only works.. if thats on the bullet..

strong wren
rocky canyon
#

if its not on the bullet u need to do bulletReference.transform.forward

#

as ur direction

polar acorn
frank flare
rocky canyon
#

basically thank DapperRaccoon, i just elaborated on what he said

polar acorn
frank flare
# polar acorn Instead of trying to teleport it some percent of the distance, why not just get ...
void Update()
    {
        if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == false)
        {
            Debug.Log("clicked");
            var ray = new Ray (cam.transform.position, cam.transform.forward);


            if (Physics.Raycast(ray, out var hit)) {
                Debug.Log("raycasted");
                var Object = hit.collider.transform;
                objectHolding = hit.collider.gameObject;

                if (objectHolding.TryGetComponent<Rigidbody>(out rb_objectHolding))
                {
                    Debug.Log("got component");
                    isHolding = true;
                }
            }
        }
        else if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == true)
        {
            rb_objectHolding.useGravity = true;
            isHolding = false;
            rb_objectHolding.AddForce(hands.transform.position - (hands.transform.position - objectHolding.transform.position) * (1f - 0.4f), ForceMode.Force);
        }
    }
    
    void FixedUpdate()
    {
        if (isHolding) {
            //objectHolding.transform.position = hands.transform.position + farness;
            //objectHolding.transform.position = Vector3.MoveTowards(objectHolding.transform.position, hands.transform.position, 40f);
            rb_objectHolding.useGravity = false;
            rb_objectHolding.MovePosition(hands.transform.position - (hands.transform.position - objectHolding.transform.position) * (1f - 0.4f));
        }
    }

Do I do it like that? (in else if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == true) part)

#

also I think MovePosition isn't the best way...

#

because it's not really colliding

#

@polar acorn Should I keep it like that and move on or make it perfect?

polar acorn
#

You can very easily move something straight through a thin enough collider, even with interpolation enabled

tepid idol
#

Any idea why my camera is bouncing like this? float n = (_right + _left) / 2f; _zoom = n * Mathf.Sin(_angle * Mathf.Deg2Rad) / _camera.aspect; and float n = (_up + _down) / 2f; _zoom = n * Mathf.Sin(_angle * Mathf.Deg2Rad); should've fixed it but it for some reason didn't. Not sure what I'm doing wrong

polar acorn
frank flare
polar acorn
dry tendon
#

why when i click the button the log is executed but the uxml is not changed? ```csharp
private UIDocument uiDocument;

private void OnEnable()
{
    uiDocument = GetComponent<UIDocument>();

    if (uiDocument == null)
    {
        Debug.LogError("UIDocument component not found on the GameObject.");
    }
}

public void EnterFactory()
{
    Debug.Log("Entering factory");

    string path = "GameHUD";
    VisualTreeAsset newAsset = Resources.Load<VisualTreeAsset>(path);

    if (newAsset != null)
    {
        UpdateUI(newAsset);
    }
    else
    {
        Debug.LogError("VisualTreeAsset not found at the specified path.");
    }
}```
tepid idol
frank flare
#

ah yes

formal sable
#

So... I have an animations. Here my video:

And, while reading the notes, the animation does not go off in idle, as shown in the video, but the current animation, which was activated before, continues to run. Can you help me with this? I need to activate idle animation white reading the notes.

Here code of notes:
https://hastebin.com/share/fupabeyego.csharp

rich adder
split dragon
#

Hi. I have a problem with languages: When I change the language to another one, all the numbers disappear and just a word remains. How do I save the numbers after changing the language?
Example: "I love you: 100%", I change the language and it turns out: "I love you" without numbers. How do I save the numbers?

formal sable
frank flare
# polar acorn I told you how. Get the direction, multiply by a speed, add that to your positio...
void FixedUpdate()
    {
        if (isHolding) {
            //objectHolding.transform.position = hands.transform.position + farness;
            //objectHolding.transform.position = Vector3.MoveTowards(objectHolding.transform.position, hands.transform.position, 40f);
            rb_objectHolding.useGravity = false;
            float speed = 0.4f;
            Vector3 direction = hands.transform.position + objectHolding.transform.position;
            rb_objectHolding.MovePosition(direction * speed);
            //rb_objectHolding.MovePosition(hands.transform.position - (hands.transform.position - objectHolding.transform.position) * (1f - 0.4f));
        }
    }

idk honestly this is what I have right now, I'll just move on then ig

tidal kiln
#

thats not direction

rich adder
marble hemlock
#
if (Input.GetKeyDown(KeyCode.U))
{
    gameObject.SetActive(false);
}

quick question

#

this is basically designed to just let me turn a text prompt on off and the screen
is there a way to make it so that it keeps setting it to the opposite?

#

as in, "okay well this object is false so lets turn it to true" and vice versa

rich adder
polar acorn
rich adder
#
active  = !active 
theObject.SetActive(active)```
marble hemlock
#

working my brain through this

#

wait it needs to be outside of the item

formal sable
rich adder
formal sable
marble hemlock
#

im so slow i was trying to figure out why it wasnt working but it was because at some point i had renamed the gameobject but didn't update it in any of the lines notlikethis

polar acorn
#

You should avoid things like Find

rich adder
#

this..is why

frank flare
#

alr made my dragging perfect (wasn't worth it tbh)

#

how can I make player not collide with objects and make it a toggle?

cosmic quail
frank flare
#

no, not collide with some specific object when I don't want it to

rich adder
eternal falconBOT
#

:teacher: Unity Learn ↗

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

frank flare
#

I see there are some layers, how can I add a custom one?

formal sable
rich adder
#

the way to fix it is learning how the animator works

#

then learning how the transitions affect the animations, the code is affecting that transition

summer stump
# formal sable Well, I wouldn't write to this channel then.

Have you done !learn ?

That should be done before you move onto doing things on your own or asking for help here.

There is beginner, and then there is a stage BEFORE beginner. You need to have a foundation of understanding for anything we say to make sense

Best of luck!

eternal falconBOT
#

:teacher: Unity Learn ↗

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

dawn basin
#

hi there, ive never had this issue in the past but whenever I edit code e.g. adding new public variables, they never appear in the inspector unless i manually reimport the script. There are no compile errors and im definitely saving the script. unity version 2022.3.19f1, vs version 2022 [17.10.35122]

rocky canyon
#

have u tried to restart to know if it still persists?

dawn basin
#

i have restarted both unity and vs and it still happens

umbral ginkgo
#

Privet pediki pososite

summer stump
dawn basin
#

when i click play it compiles yh

rich adder
#

afaik that only deals with playmode

dawn basin
#

should this be enabled?

rich adder
#

sounds like you have compiling script issue not so much domain reload issue

#

VS prob not triggering compile for some reason

dawn basin
#

any suggestions ?

raw token
#

Also check General > Auto Refresh, and double check your External Tools settings 👀

dawn basin
#

Auto refresh was disabled...

#

hopefully thats fixed now

#

thank you

rich adder
#

nicee

dawn basin
#

weird since i havent touched it

#

all good !

#

thank you

frank flare
#
using System.Collections;
using System.Collections.Generic;
using System.Security;
using JetBrains.Annotations;
using UnityEditor.Callbacks;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.InputSystem;

public class GrabItems : MonoBehaviour
{
    bool isHolding = false;
    public GameObject objectHolding;
    Rigidbody rb_objectHolding;
    public GameObject hands;
    public Vector3 farness;
    Camera cam;

    void Awake()
    {
        cam = GetComponent<Camera>();
    }

    void Update()
    {
        if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == false)
        {
            Debug.Log("clicked");
            var ray = new Ray (cam.transform.position, cam.transform.forward);


            if (Physics.Raycast(ray, out var hit)) {
                Debug.Log("raycasted");
                var Object = hit.collider.transform;
                objectHolding = hit.collider.gameObject;

                if (objectHolding.TryGetComponent<Rigidbody>(out rb_objectHolding))
                {
                    Debug.Log("got component");
                    Debug.Log(hands.transform.parent.parent.parent.GetChild(1));
                    Physics.IgnoreCollision(hands.transform.parent.parent.parent.GetChild(1).GetComponent<Collider>(), objectHolding.GetComponent<Collider>(), true);
                    isHolding = true;
                }
            }
        }
        else if (Mouse.current.leftButton.wasPressedThisFrame && isHolding == true)
        {
            rb_objectHolding.useGravity = true;
            isHolding = false;
        }
    }
    
    void FixedUpdate()
    {
        if (isHolding) {
            rb_objectHolding.useGravity = false;
            Vector3 direction = hands.transform.position - (hands.transform.position - objectHolding.transform.position) * 6f;
            rb_objectHolding.velocity = hands.transform.position - direction;
        }
    }
}

why does the line with Physics.IgnoreCollision(hands.t

#

discord size is limiting me

#

why that line doesn't seem to do any effect?

#

I want to make player not collide with an object when he's not supposed to

rocky canyon
#

use a paste-bin website if discord is limiting.. too big of a codeblock for the channel

frank flare
frank flare
#

tried this Physics.IgnoreCollision(objectHolding.GetComponent<Collider>(), hands.transform.parent.parent.parent.GetChild(1).GetComponent<Collider>(), true);

raw token
#

hands.transform.parent.parent.parent.GetChild(1) is quite the traversal... You might consider storing a direct reference such that it's less likely you'll make a mistake, and the code can function independently of the configuration of the hierarchy

rocky canyon
#

didnt even notice. that.. cursed line of code for sure

summer stump
#

The GetChild at the end is just icing on the catfood

frank flare
#
if (objectHolding.TryGetComponent<Rigidbody>(out rb_objectHolding))
                {
                    Debug.Log("got component");
                    Debug.Log(sigmaCapsule);
                    Physics.IgnoreCollision(objectHolding.GetComponent<Collider>(), sigmaCapsule.GetComponent<Collider>(), true);
                    isHolding = true;
                }

well, changed it to sigmaCapsule but it still does no effect

storm heath
#

hello guys

#

i need a help

#

how i can write jump code

rocky canyon
#

you tried google? google

raw token
frank flare
frank flare
raw token
#

I can't think of any good reason for IgnoreCollision() to not work, unless you have some other code which is consistently re-enabling collision. But an alternate solution may be to just change the held object's layer while held.

frank flare
#

I didn't change it except some settings at the start of the script (they're not important)

#

this is the only "Physics" there

storm heath
queen adder
#

hey i have a pb with my item script( i cant put the item) if you have other script or if you see the pb tell me pls

queen adder
#

its supposed to do that

queen adder
deft grail
#

an error is an error

#

needs to be fixed

queen adder
#

i have that

raw token
# frank flare this is the only "Physics" there

I'm not too familiar with IgnoreCollision(), but I would think to slap a script on the held object with a

OnCollisionEnter(Collision collision) {
  Debug.Log("Held object collided with " + collision.gameObject.name, collision.gameObject);
}

just to double check my assumptions and hopefully narrow down the problem space

deft grail
queen adder
#

i start unity today and idk what is it

#

ok

umbral rock
#

So im trying to make an rts kind of game where a building is generating points but the problem that i have is that its not constantly adding points, only when i place a building i get points, and i wanna put my function in the update function but it doesnt seem to work...

#

how do i make sure my points go up the whole time? basically updated

queen adder
errant flower
#

how do istop unity from collecting 4mb of ram per half second and eventually eating all of it because i accidentally ran a while function for too long

deft grail
storm heath
#

i started unity in 2024. But today i could
serious for unity.
Because i am a student and i had a so many homeworks and project

#

i need help for jumping

deft grail
#

what is the struggle your having?

umbral rock
deft grail
umbral rock
storm heath
deft grail
polar acorn
deft grail
storm heath
#

character

umbral rock
deft grail
storm heath
deft grail
#

not sure exactly how jumping works outside of a rigidbody, but i assume you just need to move it upwards

raw token
# frank flare

So do PlayerCapsule and Capsule both have colliders? I think your hands.transform.parent.parent... thing was targeting Capsule, but that log indicates that it's colliding with PlayerCapsule

deft grail
polar portal
#

im trying to have it write a game save using a json file, but when i close the program i get this error. i checked, and the locallow and defaultcompany folders arent read-only, so i dont get why this could be happening

umbral rock
frank flare
#

Capsule

deft grail
raw token
rocky canyon
#

if you click the CC w/ gizmo's enabled u'll see the green capsule

frank flare
frank flare
rocky canyon
#

shorthand for Character Controller, sorry bout that abbrev.

raw token
#

Unless you have a specific reason for a separate discrete collider, probably best to just rely on the one which CC already provides

frank flare
rocky canyon
rocky canyon
#

collapsing components is a good way to get rid of unwanted gizmo clutter (while keeping the actual gizmos enabled)

vast vessel
#

yo guys.
why do these two scripts(SequenceGraph.cs and Start_Node.cs) keep disappearing from visual studio?
I've tried to delete them and re-add them in hopes that the issue would be fixed but they keep disappearing.
I've also tried "Add existing item" option in visual studio but these two scripts will still disappear for no fucking reason!

#

they are there in file explorer but i just cant get them to show up in visual studio code, and unity dosnt recognize refrances made to those scripts!

#

here is my unity console

#

i have also restarted visual studio. didnt fix a thing

umbral rock
#

private void FixedUpdate() {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

    if(Physics.Raycast(ray, out hit, 1000, layerMask)){
        pos = hit.point;
    }
}

i wonder if the Ray is needed here? cant i just do this?
if(Physics.Raycast(Camera.mainScreenPointToRay(Input.MousePosition), out hit, 1000, layerMask)){
pos = hit.point;
}
}

eternal falconBOT
umbral rock
#

damnit, keep forgetting about it, sorry about that...

vast vessel
raw token
#

And possibly regenerating the project files from External Tools

vast vessel
#

ill try that

raw token
vast vessel
raw token
#

Excellent 😁

frank flare
marble hemlock
#

i feel like i have a problem i shouldnt have so uh

#

that's what the current script is, and when i click U, it unlocks the mouse, and freezes everything in place (minus the player rotation but thats a bit lower on my concerns)

#

but since thats the intended goal, i tried to apply that to another object, the menu

so i basically copied and pasted the script bit for the inventory, and then tried to apply it to the menu

rich adder
frank flare
rich adder
marble hemlock
#

the problem however is not hte inventory

#

its the menu

#

hold on lemme get a

#

im trying to redo this and if it just suddenly decides to work im going to lose it

frank flare
marble hemlock
#

🗿
alright

#

i guess its just decided to work now

frank flare
#

I'm using unity FirstPersonController

rocky canyon
rich adder
ionic zephyr
#

My game has different ranks (C,B,A,S) which are enums how can I make sure that if a condition evaluates for rank C, it also evaluates for higher ranks, for example, I can obtain this C rank item with a C rank Weapon, but also with B,A,S rank weapons

rocky canyon
#

character controllers dont do well w/ collisions (esp physics based ones)

rich adder
#

lol i remember running a gmod server I needed this plugin

rocky canyon
#

a simple solution would to be to check if the box (the thing ur carrying) is lower than the players feet

#

if it is.. u shouldnt lift on it edit: havent tried this myself.. just guessing

frank flare
ionic zephyr
frank flare
rich adder
rocky canyon
frank flare
#

main part on 0:18

rocky canyon
#

when i release i have to dampen the forces

rich adder
rocky canyon
#

so i dont yeet it across the globe

#

definitly script related is my guess

rich adder
# frank flare

its saying you're grounded when you're above the box midair

rocky canyon
#

since ur character controller isn't sinking thru the ground

frank flare
#

should I just add in Update a thing that just does grounded = false?

#

when I'm touching that cube

#

how would I detect touching cube tho if I disabled collisions between them...

rocky canyon
#

im confused what im seeing.. when ur above the box.. (an sink thru it) are u actively lifting that object

#

(is ur script doing anything to the box)

rich adder
rocky canyon
rocky canyon
#

thats what i intend on trying first.. and then i'll see

rocky canyon
#

ya, but the code you sent is to pick up the object..
in the video it appears u fall thru the cube w/o ever picking up the object.. (which shouldnt happen)
but i could see it possibly happening if ur interacting w/ the cube and messing w/ its physics

frank flare
#

it's kinda the only code I got

rocky canyon
#

my solution for moving objects was to use AddForce instead of directly seting the velocity

frank flare
#

there's also playercontroller I can upload it to pastebin

rocky canyon
#

the pickup code shouldnt have anything to do w/ the player falling thru the cube (if ur not picking the cube up)

frank flare
#

cube is regular

rocky canyon
#

b/c its not even being run at that point in time

frank flare
rocky canyon
frank flare
rocky canyon
#

it's not actually affecting my player in any way

#

does ur player consider the cube ground?

#

my ground check detects everything for now..

#

maybe it doesn't respect the cube as being the ground. so it phases into it.. until it actually touches the normal ground

frank flare
#

private void GroundedCheck()
{
// set sphere position, with offset
Vector3 spherePosition = new Vector3(transform.position.x, transform.position.y - GroundedOffset, transform.position.z);
Grounded = Physics.CheckSphere(spherePosition, GroundedRadius, GroundLayers, QueryTriggerInteraction.Ignore);
}

rocky canyon
#

the cube may not be part of GroundLayers

#

i have no idea

abstract pelican
#

Can anyone tell me why Carry triggers immediately and not after the timer?

rocky canyon
#

create a normal rigidbody cube.. and test if u can stand on it

#

see if its any different than the cube ur using to pickup

frank flare
#

that effect just happens after

#

Physics.IgnoreCollision(objectHolding.GetComponent<Collider>(), sigmaCapsule.GetComponent<Collider>(), true);
Physics.IgnoreCollision(objectHolding.GetComponent<Collider>(), plrCapsule.GetComponent<Collider>(), true);

rocky canyon
rocky canyon
#

soo yea, its the pickup script for sure then

rocky canyon
#

instead of directly setting velocity use RB.MovePosition or RB.AddForce, ForceMode being ForceMode.Acceleration

frank flare
#

I think the problem happens because of firstpersoncontroller

rocky canyon
#

is it possible to reset it to 0 each time u go into that if statement

#

when you interact -> set carryHoldTime to zero..
then ur if statement starts to increment it

rocky canyon
#

if its a rigidbody character controller.. u could move ur physics objects any way u wanted to. and you'd have more luck

abstract pelican
frank flare
rocky canyon
#

this would set it to 0 before the if statement started adding on to it..

abstract pelican
#

I already have it like this.

rocky canyon
#

then why does it debug 1,5000xxxxx

abstract pelican
rocky canyon
#

very strange.. 🤔

frank flare
hushed talon
#

hey im trying to get that when the key "W" Is pressed it adds force to the player cube. can anyone help ?

hushed talon
#

oop sorry

frank flare
#

how can I change layers of a cube? what is a default layer?

#

nvm I got it

#

but what are these 5 layers?

#

are they just 5 layers with random names?

#

but like

vast vessel
#

can i save a scriptable object, with GO references to specific scenes somehow?

frank flare
#

named with sense for organization?

raw token
# abstract pelican

The best thing you could do is attach the debugger, slap some breakpoints in the places of interest, and step through it...

But short of that, could you post the full script on a paste site? The excerpts you've shared thus far don't describe what you're seeing by themselves, but there's also not enough context to understand how they all connect

frank flare
rocky canyon
#

they're anything you want them to be..

frank flare
rocky canyon
#

they're used for layer masks.. layer based collisions.. comparisons etc

frank flare
#

or it's just organization?

rocky canyon
#

no, someof em are important..

#

default, ignore raycast for example

#

wouldnt wanna mess w/ those

#

the rest is up to you and how u wanna use em

frank flare
#

so these 5 are with special meaning?

rocky canyon
#

the original 5 you shouldnt try, or even want to change/modify

#

you have 32-5 other ones you can use for w/e

frank flare
#

can 31 layers be not enough?

queen adder
#

This is in the animator the parameter is there but it says it isnt when I run the method to activate it did I do something wrong



void fadeIn()
 {
     animator.ResetTrigger("Fadein");
     animator.SetTrigger("Start");

 }
 void fadeOut()
 {
     animator.ResetTrigger("Start");
     animator.SetTrigger("Fadein");
 }
#

!code

eternal falconBOT
rocky canyon
#

if ur using all 31 layers.. you either have a chunky game.. or ur doing something wrong

rocky canyon
#

like that ^

queen adder
#

Got it thannk

rocky canyon
#

yw! 🙂

rocky canyon
#

chck ur spellings

queen adder
#

i fooled me

#

thanks

rocky canyon
#

bamboozled 🪄 ⭐

#

word of wise.. try to use different names for ur clips vs ur transitions

#

it'll get complicated quick if u dont

#

even if its just FadeInClip vs FadeIn for the transition

raw token
# frank flare so these 5 are with special meaning?

Ignore Raycast is omitted from the default physics query layermask...

TransparentFX - apparently lens flare will be visible through these objects? 🤔

I don't think there's anything special about Water 🤷

Aaaaand no clue about UI either, unless it has something to do with input handling for UI shtuff... Or maybe just a convenience for a UI camera...

It is very strange that these don't seem to be well documented anywhere

rocky canyon
#

AHH we cant even remove it

raw token
#

This is going to haunt me

rocky canyon
#

just repurpose it 😛

#

Water is my new Ground layer

#
  1. Default: The standard layer that all GameObjects are assigned to by default; used for general-purpose rendering and physics interactions.
  2. TransparentFX: Intended for objects that require transparency and special rendering effects, often used for visual effects like glass or water surfaces.
  3. Ignore Raycast: Objects in this layer will not interact with raycasting, making it useful for objects that shouldn't be detected by raycasts (e.g., background elements).
  4. Water: Reserved for water-related GameObjects and effects; often used in conjunction with water rendering and physics systems.
  5. UI: Specifically used for Unity's built-in UI elements, ensuring they are rendered and managed separately from 3D objects.
#

the mo you kno 🌈 ⭐

raw token
#

Still mysteriously vague, but satisfying enough 😁

rocky canyon
#

default, ui, and ignore raycast being useful

marble hemlock
#
    private void Start()
    {
        movementScript = GetComponent<MovementScript>();
    }

and

 if (!inventory.activeSelf)
 {
     Cursor.lockState = CursorLockMode.Locked;
     Cursor.visible = false;
     Time.timeScale = 1;
     movementScript.GetComponent<MovementScript>().enabled = true;


 }
#

is "movementScript.GetComponent<MovementScript>().enabled = true;" this line not supposed to do this

#

im not getting an error but now if i called the component in start, do i need to call it again later?

languid spire
#

no, movementScript is already a MovementScript instance

marble hemlock
#

i tried to just write movementScript.enabled = true; but then it just fails

frank flare
#

how can I change layers through script?

languid spire
#

NRE ?

frank flare
#

idk if I'm trying to do something weird

frank flare
frank flare
raw token
marble hemlock
#

like im very sure it'll work but i vaguely remember being told that having the script keep using get component is not a good idea

languid spire
#

no it is not, you only do it once as you do in start

frank flare
marble hemlock
#

yeah im not sure how to get it to true

#

'Component' does not contain a definition for 'enabled' and no accessible extension method 'enabled' accepting a first argument of type 'Component' could be found (are you missing a using directive or an assembly reference?)

summer stump
rocky canyon
summer stump
marble hemlock
#

perhaps i am the flaw

languid spire
#

show the declaration of movementScript

marble hemlock
#
public Component movementScript;

    private void Start()
    {
        movementScript = GetComponent<MovementScript>();
    }
#

man i should not name these the same thing

languid spire
#

so change Component to MovementScript

marble hemlock
#

wha

#

it worked

#

i dont understand notlikethis

summer stump
rocky canyon
#

MovementScript movementScript is good enough for naming.

#

camelCase being the reference.

summer stump
#

Well MovementScript inherits from MonoBehaviour and has access to its properties.
Component comes earlier in the inheritance chain and does not

UnityEngine.Object > Component > Behaviour > MonoBehaviour > MovementScript

The ones at the end have access to the ones before it. The ones at the start have absolutely no clue about anything after it

marble hemlock
#

oh

#

ohhhh
i remember that page

languid spire
raw token
# marble hemlock i dont understand <:notlikethis:1068134558123442236>

You can totally store a reference to your script in a Component-type variable because as Aethenosity describes it is a Component due to it's inheritance chain, but then you can only access members which exist on the Component type. If you want to access the members you've declared within your script, then the reference must be stored in a variable of your script's type

marble hemlock
#

unity been beating my ass all day atwhatcost
Every time i think i get something i proceed to break another thing i didnt even know was a problem

summer stump
#

You could even store it as a UnityEngine.Object

You just wouldn't WANT to

rich adder
final kestrel
#
class InventoryData
int Id;
Item item;

public InventoryData(Item _item){
item = _item;
Id = _item.id
}

My question is... Do I need to give Id as a parameter? Or can I just do this and set the id to the given item's id in the constructor?

languid spire
#

sure, no problem, you could also do
int Id ( get { return item.id; ) )
and not set anything

final kestrel
#

I am trying to understand why he also adds id in the parameter. Isnt it just easier to just give the item whenever you new the class and set the properties/fields inside?

#

Think it makes the most sense as its readable and all?

final kestrel
#

I should work more on the properties and get used to them.

languid spire
#

if you find yourself duplicating data then properties are usually the answer

final kestrel
#

All right. I understand. Thanks!

marble hemlock
# rich adder how else do you plan on learning ?

its fun until every step forward is rewarded with a step back
i got the menu and inventory pausing like i wanted to and now the mouse keeps getting locked and unlocked regardless of what i want so

#

time to figure out which part i fumbled this time

#

i am so close

final kestrel
marble hemlock
#

whats setting me off is that menu and inventory basically have the exact script, except one always seems to have a problem the other doesn't

When i go to the menu, the mouse does not lock as its not supposed to
when i try to click the inventory, it lets the mouse move around until click on screen again and then it locks

#

but it looks like its glitching because it keeps flickering in and out

rocky canyon
#

does ur menu use the Escape key?

#

in the editor Unity uses escape to undock the mouse from the game.. it will override any cursor locking you have

#

until you click back onto the game so it goes back to focus

#

thats why people say in the build it will be fine

#

i tend to use a different key for when im building/testing the game.. and then when right before i build i replace it back to Escape

#

the backtick ~ key is a good alternative

silk night
rocky canyon
silk night
#

right alt + pinky right next to the enter key

rocky canyon
#

oof, ya edit: if ur using a QWERTZ keyboard.. maybe dont use the tilde key

silk night
#

^ is on the same key you got ~, ° with shift

rocky canyon
#

° is a cool key.. i wish i had it.. for degrees i always have to make due with *

silk night
#

i think i have used it twice since I know how to use a keyboard, one of those above

rocky canyon
#

im always impressed by those that use keyboards that try to pack 3 or 4 character on 1 key.

#

w/ StreetFighter type combo's to access them 😄

silk night
#

that key is the definition of wasted potential on qwertz 😄

rocky canyon
#

last offtopic question: where do you live that uses qwertz?

silk night
#

its so prominent and both signs on there have to be amongts the rarest every typed unless you're a ^^ type of person

#

germany

rocky canyon
#

ahh cool! i'll have to remember that

silk night
#

i can use both qwertz and mac keyboards (from work) and i can find some keys on english keyboards because ssh doesnt care what you got plugged in, if its set to english you better find those keys

rocky canyon
#

as long as WASD is in the same spot we're good 👍 or i'll need to have a rebinding menu for my game to be international

silk night
#

except for y/z all letters are in the same place, + we got äöü on here

#

but yeah, the y/z switch is a pain sometimes in games, "press z to lie down"... one broken finger later

rocky canyon
#

ya, the more i learn the more i figure that have a remapping input system would be a great addition

silk night
#

i mean the input system makes it easy with the auto-capture remap function 😄

warm raptor
#

what's the best way to manage the explosion radius for my grenade, should I spawn/acivate a sphere collider in trigger mode and check who is in the collider, but that mean that player could receive damage behind walls, or should I use a raycast to check what's the distance between the grenade and the players and check if their are collider /object between them, but that will mean that even tiny object could stop players from taking damage ?

deft grail
warm raptor
warm raptor
deft grail
silk night
silk night
#

but that method will only check if the center of that object is behind the wall, not if for example a foot is sticking out

warm raptor
silk night
deft grail
#

you can make the targets just be of a certain layer too, so it doesnt just get all random objects

warm raptor
warm raptor
deft grail
#

at each height

silk night
#

ive seen it solved by having a collider on each body part, head, torso, arms, legs and raycasting to each of them

deft grail
#

dont even need different colliders if you want, just do multiple raycasts

warm raptor
silk night
#

you can set the transform of the bone you want as raycast target and check if they raycast gets the whole distance to the bone without any collision with walls or stuff

warm raptor
polar acorn
rocky canyon
polar acorn
#

So, if you fix this problem you've got a leg-up on John Romero 😄

rocky canyon
#

its used more for just grenades too.. (when enemies are lookin for the player.. they need to be able to see his feet too)

warm raptor
rocky canyon
#

yea, no sweat

#

the more u have the more accurate the stuff will be..

frank flare
#

where should I contain scripts?

#

just a question for organization

frank flare
#

Input.GetKey("a"); is this the check if key was just pressed? like not the key is being pressed and not that the key has been unpressed but that the key was exactly just pressed?

raw token
frank flare
#

depressed??

#

you mean pressed?

raw token
#

Yeah

frank flare
#

depression in unity functions is crazy

#

anyways it seems to work

raw token
#

"pressed" and "depressed" are synonyms, albeit it's not a super common usage of the word 😅

frank flare
#

can I make some cooldown like 5 seconds? do I have to save previous time or what?

#

save previous time somehow and then -?

raw token
# frank flare can I make some cooldown like 5 seconds? do I have to save previous time or what...

Sure yeah - you can store the time of the event and check if the current time minus that is greater than your threshold. Or reset a timer to 0 and add Time.deltaTime each frame until it's greater than your threshold.

Or the super nifty route is to use a coroutine, in which case you just yield return new WaitForSeconds(threshold); and Unity will resume your code from that point after threshold seconds have passed

frank flare
#

coroutine is kinda messy and for smart people, isn't it?

#

what about simplier way like

#

getting unity clock

#

or os clock?

#

or whatever clock is it?

deft grail
frank flare
#

oldTime = clock()

if clock - oldTime > ...

frank flare
raw token
frank flare
#

time.time() is nice?

raw token
#

It's not a method, but yeah - that would fit the bill 👍

raw token
# frank flare coroutine is kinda messy and for smart people, isn't it?

They're not too crazy - they just take a little experience to get the hang of.

Broadly, they're just methods which will run up until a yield return something statement, where something is an instruction to Unity to tell it when to continue running again - in a frame, a few seconds, when the color of a dog turns blue, whatever.

Everything you can do with a coroutine you can do without, but it can definitely be a more clean and convenient way to write that sort of incremental logic

#

An awesome tool to have your toolbox - well worth learning at some point.

cosmic dagger
# frank flare where should I contain scripts?

typically, you place them on the GameObject that you want to have that behavior, but depending on the type of script: controller, manager, singleton, etc.) it will be on a top-level GameObject . . .

mint remnant
#

if you have a static class, non monobehaviour, you can't write to the Console log in anyway, correct?

slender nymph
#

you can still use Debug.Log

mint remnant
#

oh hrmm, ok will try that then

marble hemlock
#

is it a good idea to have different scripts for different buttons even if they're on the same screen

steep rose
#

Why would you want that

raw token
marble hemlock
#

sorry
so its a panel, and on the panel, there are two buttons with different functions
is it better to just have them with different scripts for each purpose?

raw token
#

Often times UI buttons need no script at all - you just assign a method to execute when clicked to the Button's OnClick Unity Event

(And usually that method exists on whatever logic you're affecting rather than the button - like a "Volume Up" button would execute a method on a SoundManager or something, rather than on the button)

slender nymph
#

there is no "better", do what makes the most sense to you. Though keep in mind that SOLID principles state that each class should have only a single responsibility.
When i'm making menus I typically put methods that buttons will call into classes where they serve similar purposes (like audio related buttons go in one class, resolution ones go in another, etc). it helps keep things organized

regal bear
#

Hello, first of all im very beginner at coding. Want to handle slide down if i jump to a slope. Not for a game mechanic, I want to make an RPG (just a hobby learning project) and i want something like World of Warcraft physic. When my character slide down, its stop sliding near the ground.
my code: https://pastebin.com/7AVV51mY

steep walrus
#

and im realizing my spread doesnt work either

dry tendon
slender nymph
#

you appear to be missing some code, nothing here has anything to do with "reangling the bullet". all this does is create a ray from the center of the viewport

dry tendon
steep walrus
regal bear
dry tendon