#💻┃code-beginner

1 messages · Page 114 of 1

ivory bobcat
#

So collision is occurring

unborn gale
#

srry no

ivory bobcat
#

So it isn't..

unborn gale
#

correct

uncut holly
#

following 1 by 1 ... i already checked my code from the beginning ... its only this LogicScript variable names logic that did not show up on unity

ivory bobcat
#

Show us the inspector for your rigid body component

subtle canyon
#

@unborn gale and are you sure that you have assigned tar tag to whatever gameobject you are colliding with.

ivory bobcat
#

Nothing prints so likely no collision is occurring at all

#

They're either not touching or cannot touch

unborn gale
#

dis

subtle canyon
cosmic dagger
unborn gale
ivory bobcat
cosmic dagger
uncut holly
# cosmic dagger Because you haven't created it yet. Is this the first tutorial in a series or th...

GMTK is powered by Patreon - https://www.patreon.com/GameMakersToolkit

Unity is an amazingly powerful game engine - but it can be hard to learn. Especially if you find tutorials hard to follow and prefer to learn by doing. If that sounds like you then this tutorial will get you acquainted with the basics - and then give you some goals to learn ...

▶ Play video
subtle canyon
# unborn gale dis

No I am not talking about that you need to set the tag of a gameobject as well.
like this

subtle canyon
unborn gale
uncut holly
ivory bobcat
unborn gale
ivory bobcat
#

Show us the inspector for the green ball

subtle canyon
unborn gale
cosmic dagger
ivory bobcat
cosmic dagger
unborn gale
ivory bobcat
uncut holly
unborn gale
cosmic dagger
ivory bobcat
uncut holly
unborn gale
#

does nothing

ivory bobcat
cosmic dagger
unborn gale
uncut holly
#

ah finally match and syntax error go bye bye

unborn gale
#

nothing changes nitherway

ivory bobcat
#

Trigger colliders cause the on trigger enter message to occur. For on collision enter, you need a non trigger collider.

uncut holly
#

yeah originally i though LogicScript is a variable type like int and float. now i learnt that when i create script the public class that comes along with the code means a new variable type is created

ivory bobcat
unborn gale
#

nothing happens when I turn it off

subtle canyon
ivory bobcat
#

Well, it can't be on. You've eliminated one issue.

#

For collision to occur, both objects must have colliders and at least one must have a rigidbody.

unborn gale
#

yo guys, I just realised I was spectating the wrong prefab

#

everything is ok

cosmic dagger
ivory bobcat
#

It's actually required to get help here - seriously.

cosmic dagger
#

That's part of it. Unity needs to be connected with your IDE. Intellisense and autocomplete should work . . .

pastel sinew
#

Can someone give me an explanation as to why one would handle the rotation of a rigidbody in Update() and the elevation in FixedUpdate() when using the rb for a player character?

#

Saw it in an article on Medium.

rich adder
eternal needle
cosmic quail
pallid verge
#

I have a cannon that shoots a projectile towards the player but when it reaches the players position on the frame that it the projectile was shot, it stops. How can i make it travel in that direction without stopping. This is the current code:

eternal needle
tough lagoon
cosmic quail
#

definitely do not want interpolating aim in ANY game, not just competitive

tough lagoon
#

Mouse input returns an absolute X/Y position, but there are other things in can return or you can access such as velocity

unreal imp
#

guys how i can make the bullet get the rotation of the gun forward and go to the forward direction? var bullet1 = Instantiate(bullet, bulletSpawn.transform.position, Quaternion.identity); bullet1.transform.localRotation = Quaternion.LookRotation(-bulletSpawn.forward); bullet1.GetComponent<Rigidbody>().velocity = (bullet1.transform.forward - bulletSpawn.transform.position).normalized * shootForce;

#

i wanted to generate the bullet from the gun and after center it into the crosshair

#

i have the idea to manage that by set the bullet to the rotation of the gun

tough lagoon
cosmic quail
spiral glen
#

Is there a way to see if an object is visible or not?

tough lagoon
spiral glen
tough lagoon
unborn gale
#

why is my sprite pixalated?

pallid verge
unborn gale
#

update the position of the player every frame, it is only updating once (when the bullet was shot)

pallid verge
#

i told you it was on update

summer stump
# pallid verge update

MoveTowards only moves towards the second parameter. So just either make a different point further than the target or use a different method

summer stump
#

transform.position is the cannon round, right?

unborn gale
#

srry am just as a noob as you

pallid verge
summer stump
#

What is target, a Vector3 or a Transform?

#

Looks like v3 actually

pallid verge
#

its a vector2

summer stump
#

So the value won't update as the player moves
It is just the point when the value was captured

pallid verge
#

yep

#

i thought of capturing the direction as a vector2 and then making the projectile move in that direction but idk how to do it

summer stump
#

I think that is what Ashimry was talking about

summer stump
pallid verge
#

chat gpt told me to add a rb to the projectile and add speed to it, you think that would work?

summer stump
summer stump
uncut dune
#

how do I convert a number without rounding to an int like 1.89 = 1, 10.1 = 10, ...

pallid verge
gaunt ice
#

you need to cast vec2 to vec3

pallid verge
uncut dune
pallid verge
summer stump
uncut dune
#

thats exactly what Im looking for

#

Im making a timer for my game thats why

summer stump
pallid verge
#

cant i just make the variable a v2

summer stump
pallid verge
#

like this

#

this is what gpt told me to do

#

but now they bounce off the walls

summer stump
fluid kiln
#
public class PlayerAnimationManager : MonoBehaviour
{
    public Animator animator;
    public PlayerStateData state;

    void Update()
    {
        BaseMovement();
        TransformedMovement();
    }

    public void BaseMovement()
    {
        if (state.isAttacking)
        {
            if (state.isFacingUp)
            {
                animator.Play("CastingRight");
            }
            else if (state.isFacingDown)
            {
                animator.Play("CastingLeft");
            }
            else if (state.isFacingLeft)
            {
                animator.Play("CastingLeft");
            }
            else if (state.isFacingRight)
            {
                animator.Play("CastingRight");
            }
        }
        else if (state.isMoving)
        {
            if (state.isFacingUp)
            {
                animator.Play("WalkingNorth");
            }
            else if (state.isFacingDown)
            {
                animator.Play("WalkingSouth");
            }
            else if (state.isFacingLeft)
            {
                animator.Play("WalkingLeft");
            }
            else if (state.isFacingRight)
            {
                animator.Play("WalkingRight");
            }
        }
        else // When not attacking or moving
        {
            // Set the animator to idle states based on facing direction
            if (state.isFacingUp)
            {
                animator.Play("IdleNorth");
            }
            else if (state.isFacingDown)
            {
                animator.Play("IdleSouth");
            }
            else if (state.isFacingLeft)
            {
                animator.Play("IdleLeft");
            }
            else if (state.isFacingRight)
            {
                animator.Play("IdleRight");
            }
        }
    }

What am i doing wrong? when the charactetr is not moving it doesn't play the idle animation and the issue seems to be here

pallid verge
fluid kiln
pallid verge
gaunt ice
#

is it rigidbody2d?

fluid kiln
#

if ur talking to me x.x

summer stump
pallid verge
languid spire
pallid verge
#

which seems to have made it worse because now the projectiles are affected by gravity

summer stump
gaunt ice
#

no
btw you should check the value of player state, and where you update the state

summer stump
pallid verge
#

but can i move a static one?

fluid kiln
languid spire
summer stump
pallid verge
#

i made direction a v3 and it doesnt complain now

#

is this what u were telling me earlier?

summer stump
fluid kiln
pallid verge
languid spire
fluid kiln
fluid kiln
pallid verge
summer stump
languid spire
pallid verge
#

@summer stump it works but now i gotta make them destroy on impact with anything

gaunt ice
#

i think isFacingUp and isAttacking are independent boolean

languid spire
#

same state variable

fluid kiln
#

its the same but it has multiple bools

#

i know it sounds horrible but trust me the animator won;t do what i need it to do

#

so i need to build a base myself

gaunt ice
#

so where are you update the value, the booleans are not toggling is not the problem of where you check them

summer stump
summer stump
languid spire
tawdry mirage
#

what will happen if script name in unity is different from class name it contains?

summer stump
languid spire
tawdry mirage
languid spire
#

yes

tawdry mirage
#

is it ok to name it like that to make it look more clear in unity's explorer, like if i open some folder and i see Actor(that i use as component) and to the right there are scripts with classes Actor inherit from, all of them in sequense that matches iheritance chain?

pallid verge
summer stump
languid spire
#

@fluid kiln btw a much better way of doing this would be to use a Flag Enum so it can contain multiple states, an array of your Animation names then use the Enum as an index into the array. No more huge if statements required

pallid verge
#

but now the projectile shoots a little from above the gun

warm anvil
#

Good afternoon. New member, eager to learn more because I know enough that I don't know enough and lastly I love creating something even if it's just for me and hopefully close friends to enjoy.

I’m using unity’s new input system and using just a gamepad. I’m using the left stick as movement. I needed to hold the left trigger to activate a cursor and move the cursor with the left stick. Do you recommend creating a new Action Map for the cursor and treat it like a UI or just put a condition in the movement script that says roughly “if the left trigger move the cursor and don’t feed rb.velocity”. With the second choice since this is my first game I’m starting to predict this might get very messy/conditional (lot of if/else). Thanks for the experience!
Ps. Feel free to let me know if this or there is a more appropriate area to ask questions such as this. Thanks!

copper locust
unreal imp
languid spire
#

right click Text, your IDE should tell you how to fix it

pallid verge
copper locust
#

do you use TMP text? or just regular text?

pallid verge
# copper locust yeah

im currently using the transform.position of the gun so idk how much more accurate i could make it

copper locust
#

using UnityEngine.UI; ?

unreal imp
copper locust
#

oh it says that you need to fix the mistakes in the scripts before starting tha game

#

what about this one?

cosmic quail
#

set up ur ide so it underlines ur errors?

#

!ide

eternal falconBOT
cosmic quail
#

cuz its SetActive not setActive

copper locust
#

SetActive with big S

cosmic quail
#

!ide

eternal falconBOT
cosmic quail
#

read what the bot says

#

if setActive doesnt have a red underline then your ide is not configured

copper locust
#

send a screenshot of the code

cosmic quail
#

select one of the options the bot gave and read

#

to fix it

copper locust
pallid verge
verbal dome
#

LateUpdate + late execution order if needed

#

Or a coroutine + WaitForEndOfFrame

#

You said you are using the gun's position for the bullet spawn pos... I doubt your gun's pivot is at the gun's muzzle

verbal dome
#

Do what

pallid verge
verbal dome
#

You don't want your gun's pivot to be at the end of the muzzle, somewhere around the rear grip is ideal

#

Put an empty there

#

Looks like you tried that already so what went wrong?

pallid verge
pallid verge
#

i just found another huge problem

verbal dome
#

Where you want the bullet to spawn

pallid verge
#

how can i set the pivot there?

verbal dome
#

Idk what you mean. You don't want the gun's pivot to be at the end of the barrel.

#

You just want an empty gameobject there and use that object's position to spawn the bullet

pallid verge
#

alright i get it now

pallid verge
#

i think its something with the rigidbody on the projectile

#

because it kinda does a curve before going to the player

#

ill show u wait

#

and i can confirm its because of the rb, when i removed it, the bullet goes straight

cosmic quail
#

u cant get red underlines and stuff to appear?

#

u using visual studio?

#

did u get it through the unity package manager or what?

#

do u have this here?

summer stump
#

!ide

This guide will walk you through it

eternal falconBOT
cosmic quail
#

didnt u say u reinstalled it like 5 min ago?

summer stump
cosmic quail
#

do u have it in your package manager

#

window > package manager

#

is it installed too? has "Remove" in the bottom right corner?

pallid verge
# pallid verge

@summer stump sorry to bother you but do you have any idea of whats happening?

cosmic quail
#

edit > preferences

#

show a screenshot of ur code

#

maybe it is working?

pallid verge
#

did you try restarting?

cosmic quail
#

well i have no idea what to do. usually the ! ide bot just solves the problem

pallid verge
#

vs

#

or unity

cosmic quail
#

both of them?

pallid verge
#

maybe some molecule from space hit your hardware and now it doesnt work properly

#

it happens

rocky canyon
#

bit flip

pallid verge
#

rarely, but it happens

summer stump
#

Show your external tools window

pallid verge
summer stump
#

I thought you were using VS, not VS Code

#

Show your extensions in VS Code

#

And do you have any error regarding an SDK in the editor?

summer stump
#

It will just say that word in a popup. If you don't see it, ignore that

verbal dome
pallid verge
verbal dome
#

@pallid verge If that's the case, then check the Physics 2D tab in the settings and change the layer matrix so that bullet layer doesn't collide with your gun

pallid verge
#

projectile and gun scripts

verbal dome
#

Or manually ignore collisions between them with Physics.IgnoreCollision

verbal dome
#

Lol, the example script does exactly that

#

Ignores collisions between the gun's collider and the bullet's collider

pallid verge
#

Should i do Physics2D instead of physics?

#

since my game is 2d?

verbal dome
#

Oh yeah

#

Wait does it even exist

#

Yeah it does

#

So yep, use the Physics2D version

summer stump
#

Don't just switch randomly. Stick with VS and stop flip flopping.
Ok, so close VS, click regenerate project file in the external tools window and reopen vs

Having a working ide is a requirement to get help here btw

pallid verge
#

thank you

cosmic quail
#

if nothing ends up working u can just completely delete unity and vs and everything, and download them again (back up ur project tho)

pallid verge
pallid verge
summer stump
#

You have the Unity workload in VS?

#

Part of the guide here

#

!ide

eternal falconBOT
rich adder
#

what doesn't work?

#

did you regen Project files in External Tools?

#

open script, screenshot Visual Studio open with Solution Explorer

tacit estuary
rich adder
#

Right click on Assembly and do Reload with Dependencies

#

screenshot vs again

#

well not you don't have to do it again 🙂

#

unless you reinstall OS or sum

#

xp++

#

bugs are part of the job

#

I would recommend follow a structured path , the c# or unity learn ones are good

#

check the pins in this channel

queen adder
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using Image = UnityEngine.UI.Image;

[CreateAssetMenu(fileName = "Humanoid", menuName = "Humanoid")]
public class Humanoid : ScriptableObject
{
    public static float Health = 100;
    public static float maxHealth = 100;
    public static float walkSpeed = 5;
    public static float sprintSpeed = 10;
    public static float jumpPower = 7;
    public static string deathReason;
    public static string deathMsg;

    public static Image dmgOverlay;
    public static Image skull;

    // Start is called before the first frame update
    void Start()
    {
        deathReason = "Suicide";
    }

    // Update is called once per frame
    void Update()
    {
        Health += 0.0001f;
        Health = Mathf.Min(Health, maxHealth);
        dmgOverlay.color = new Color(dmgOverlay.color.r, dmgOverlay.color.g, dmgOverlay.color.b, Mathf.Max(dmgOverlay.color.a - 25 * Time.deltaTime, 0));
    }

    public static void SetHealth(float hp, string DR, string DMSG)
    {
        Health = hp;
        deathReason = DR;
        deathMsg = DMSG;
        dmgOverlay.color = new Color(dmgOverlay.color.r, dmgOverlay.color.g, dmgOverlay.color.b, 255);


    }
}
#

here is my code for a fading damage overlay screen effect

#

when i run the game, nothing happens except i get this error

#
NullReferenceException: Object reference not set to an instance of an object
Humanoid.SetHealth (System.Single hp, System.String DR, System.String DMSG) (at Assets/Scripts/Humanoid.cs:41)
DeathCube.Interact () (at Assets/Scripts/Misc/DeathCube.cs:11)
Interactable.BaseInteract () (at Assets/Scripts/Misc/Interactable.cs:16)
InteractionHandler.Update () (at Assets/Scripts/Player/InteractionHandler.cs:47)
rich adder
#

um we can't read lines on discord

queen adder
#

sorry

rich adder
#

!code

eternal falconBOT
queen adder
#

here is the

#

ph

#

oh

#

i'll just use gdl.space

rich adder
#

where do you assign dmgOverlay

queen adder
rich adder
#

thats not assigment

#

that declaring

queen adder
#

ah

#

ohhhhhh

rich adder
#

also static variables cant be seen in inspector therfore cannot be assigned that way

#

having static vars on SO is odd anyway

queen adder
#

well

rich adder
#

wait nvm

queen adder
#

im using a so to make a universal humanoid health for the player

rich adder
#

but yeah why is it static

#

yeah but no need for values to be static

queen adder
#

wellll

#

if i were to make it non static

#

i'd have to declare this SO in every script i have making it reference a different health value wouldnt it do that?

rich adder
#

but still no reason for it to be static at all

#

just make them regular public

#

or property with a backing field

queen adder
#

wait

#

the so changes its property for all instances?

rich adder
#

yes they are meant for non-mutable

queen adder
#

ohh

#

then there is no reason to have these be static

rich adder
#

copy the values over to another class like a poco then mutate them

queen adder
#

ill go ahead and make the changes

#

thank you

rich adder
#

if you change 1 static, you're changing the same one as only 1 exist of that field

queen adder
#

yup

rich adder
#

statics vars and SO act very similar in that matter

queen adder
#

so no need to make it static

rich adder
#

nope

queen adder
#

thank you

cosmic dagger
#

You can only see public methods . . .

#

How many arguments?

rich adder
#

variables in method's signature. aka inside parenthesis

#

Method(string imAText)

cosmic dagger
#

I should have said parameters . . .

rich adder
#

Yeah dont think those events support more than 2

#

in the inspector anyway, ofc with delegates you can do whatever.

cosmic dagger
#

But arguments are variables passed in (used) for the parameters of a method . . .

#

Then you should learn some basic c#. That's beginner stuff . . .

rich adder
#

I just showed you an example

#
public void Method(string thisIsParameter)```
#

what is the parameter type?

#

these are basic c# questions my guy

#

a type defines the object and its Type

#

eg. string, bool, int etc..

#

those are value types

#

etc

#

well then you should prob follow better teachings and learn this stuff

#

check the pins in this channel

#

no one is saying instantly , if you plan on doing any dev you have to know the basics

#

you're trying to enter a spelling contest without knowing words

earnest atlas
#

Hi, I have an issue with basic assignment I was given. I went step by step on the guide and had objects with Rigid Body and Box collider 2D, but for some reason it doesnt interacts with any other objects with Box Collider 2D. So far what I found online are not related to my issue. It just looks like they arent working? But they are enabled.

#

This is box collider settings. I think all is correct here?

sudden grove
#

hi

languid spire
sudden grove
#

does anyone know of any prebuilt inventory systems?

earnest atlas
earnest atlas
#

I tried changing discrete and active

rich adder
#

the amount of times its been asked its almost like..

rich adder
sudden grove
#

dayummm

earnest atlas
#

Yeah Im looking into it.

sudden grove
#

cause i think the last thing i want/need functionality-wise is an inventory system and thats it

rich adder
#

like its a trivial thing lol

earnest atlas
#

On triggerEnter and OnCollision are different methods. I should have set the Trigger enabled?

sudden grove
earnest atlas
#

No its not

rich adder
#

so then no

eternal needle
sudden grove
rich adder
#

yup. most basic one you can make is a dictionary

#

or even a list

sudden grove
#

what wowuld you suggest for what i want

rich adder
#

Dictionary is something you should learn in general for other stuf so I'd suggest that one. List is easier though

eternal needle
sudden grove
pastel sinew
#

@rich adder @eternal needle @tough lagoon Thanks for your guys' answers. @eternal needle is correct that in the article the rb is rotated by changing the localRotation (image is from the article). Since the article is about using the input system for a player controlled drone, using torque might even be the better way, since quadcopter drones dont turn instantly. Lets say I use torque for the rotation and addForce for the elevation I would put both in FixedUpdate() because thats where rigidbodys go? Edit: Added link to the article: https://gamedevdustin.medium.com/drone-controls-with-the-new-input-system-in-unity-2021-f990bc0f1d47

Medium

In this article we’ll look over the Action Map and input code that controls this flying drone.

eternal needle
rich adder
eternal needle
rich adder
#

Ah yes. Medium , the most trusted source

earnest atlas
#

I was missing box collider on the bullet...

#

It wasnt mentioned in the guide

sudden grove
rich adder
earnest atlas
#

nope nowhere mentioned 🙂

#

Just skipped

rich adder
#

wanna bet ?

earnest atlas
#

Yeah I reread the entire document

#

No I ment in the guide I READ

#

Not there

rich adder
rich adder
earnest atlas
#

Yeah this why I normally dont bother reading them and always google

rich adder
#

googling is good sure

#

just verify the answer across multiple sources

earnest atlas
#

But then my professor goes WhY It FeElS ThAt YoU DiDnT rEaD My GuIde

sudden grove
#

if i explain the type of inventory im looking for do you guys think you could tell me what the style is that im looking for?

eternal needle
rich adder
#

shit must've come out a cereal box

sudden grove
#

cause im looking for an inventory that as i collect items it "unlocks" it in the inventory, so that whenever you need it you open your inventory, and equip in, in turn equiping the item in game

earnest atlas
#

I havent worked with C# in like a year and fogror so much its sadge.
Last I remember trying to implement DI interface.

rich adder
earnest atlas
#

scripts are in C#

rich adder
#

thats just the langauge used to interfacte with API
Rigidbody / Colliders are specific to unity in this case

eternal needle
earnest atlas
#

unity is mainly C++? Or C# is enough?

rich adder
#

Unity Editor runs on C++ hence why we need an API to communicate with engine in c#

delicate zinc
#

is this a unity bug or smt

rich adder
eternal needle
#

this is a screenshot of like 4 colors lol

delicate zinc
#

2 box colliders are overlapping and idk why

rich adder
delicate zinc
#

oh

#

oops sorry

teal vale
#

Hey! I'm trying to achieve the sort of puppet combo style to my game, and for my enemy, I'm trying to make it so that when the player gets closer to the AudioSource, the pitch either increases or decreases. I found a video on youtube, but it's too low quality and I think he was speaking german, so I had no Idea how to follow along. Can anyone help me make this?

rich adder
teal vale
#

in like 440p

teal vale
#

yeah. he put 3 seconds worth of a brackeys tutorial and then his loudass mic starts blaring

#

no hate against the germans tho

#

we chillin

#

true, but that was back in the 40s. welcome to the modern day society

sudden grove
teal vale
#

alrighty then! good luck, my friend. I will also attempt to struggle with this predicament I am currently in

eternal needle
teal vale
#

Oh. You're that beginnner. All good. I hope I can explain. We'll move to private dms if that's ok. I would be happy to help you with that

#

I don't have too long. Gotta go to a christmas party

sudden grove
teal vale
#

"yep. That's me. you're probably wondering how I got into this situation"

#

so, you want me to help you in dms?

eternal needle
teal vale
#

I posess the knowledge to make a sprite appear on button press, but I do not know how to change audio pitch relative to a gameobject's position

#

i will attempt to explain as best I can in simplistic ways

rich adder
#

should be fairly simple

teal vale
#

I honestly got nothing. I don't yet know how to do stuff like that

#

clamping and things like that

#

lol at least you want to help

#

i gotta go. I'll be back maybe tomorrow. then we can figure this out

#

see ya!

sudden grove
# eternal needle i have no clue what you mean by this, or what that has to do with what i said ab...

im just trying to figure out how i want this to work, cause im not making an open world type game where you can have a sort of random inventory depending on howw you play the game, no matter howw someone plays it the inventory will always be the same, like old zelda games, you go through the dungeon, go through a trigger, wwhich would be the chest, and then that unlocked it in the inventory, in which the player would be able to equip and unequip whenever they wanted

rich adder
#

right click on the component you want and click Properties

sudden grove
visual hedge
#

heroToControl.transform.Find("HeroInventory").gameObject;
won't find that gameObject if it's not active, right?

sudden grove
#

in fact im pretty sure i have valid code from last night

summer stump
summer stump
sudden grove
summer stump
visual hedge
queen adder
sudden grove
summer stump
# queen adder

Can't do that there, have to do the = part in a method

queen adder
#

ok

summer stump
rich adder
#

but silly

#

just make it a regular UI element and attach button component to it

#

its the same thing ig but you can better customize it this way

sudden grove
#

im really trying to understand how to put together this inventory from watching this video but hes being so vague about it

rich adder
#

start with a baisic one..a collection

#

work your way up to UI n stuff

summer stump
#

Inventories are a broad topic for sure. Lots and LOTS of different ways to go about it. From a simple list, to slots, to diablo-like grids, and many variations on all three of those
Then there is the conversion between inventory item to gameObject or effect which is tough too

sudden grove
#

yeah its definitely frustrating to deal with haha

queen adder
#

i defined them in the declaration, and it was null

rich adder
#

the inspector

queen adder
#

thanks

rich adder
#

you should probably not have reference types outside an SO there

#

what is skull a texture ?

#

rawimage/ Image component displays the sprite/texture

visual hedge
#

When I am instantiating my hero, I want to reference those 2 gameobjects... and I am doing it like this:

          uiinput.inventoryPanelGameObject = heroToControl.transform.Find("InventoryEquipmentCanvas").gameObject.transform.Find("HeroEquipment").gameObject;```
which is giving me null reference exception. Why?
queen adder
#

skull is a image

rich adder
queen adder
#

skull shows up when you are below or equal to 50 health and you are being hurt

#

akin to postal 2's UI

#

store?

rich adder
#

yeah store the image you want to swap although dont see a reason why those two can't just be inside a UI manager

rich adder
queen adder
#

UI manager?

visual hedge
rich adder
# visual hedge I guess I did?

thos two?
uiinput.equipmentPanelGameObject = heroToControl.transform.Find("InventoryEquipmentCanvas").gameObject.transform.Find("HeroInventory").gameObject;

visual hedge
#

yeap

rich adder
#

thats a lot of stuff to check

#

and you should never use transform.Find, if the item is on the child just make a direct reference to it

queen adder
#

ill look at my code real quick and get back to you

visual hedge
#

I guess I will just refference those 2 game objects in character script anjd pass it to uicontrol. Will be easier 🙂

rich adder
visual hedge
queen adder
#

im sorry navarone im actually confused as to what you are doing

visual hedge
#

ohh I got where I made mistake anyways 😄

queen adder
#

actually it makes sense my code is actually kinda broken when it gets to the images

#

on the UI

#

i dont know what a UI manager is, is it a class?

#

anyways, when i declare the damage overlay and the skull, it shows a error saying that there are two types of images

#

the one declared in unityengine.ui and the one declared in unityengine.uielements

#

so i chose unityengine.ui because it let me edit the alpha of the two images

#

however this doesnt work

#

among many other errors

sudden grove
queen adder
#

it seems that all of the variables listed in humanoid is null given that all that happens when i access these variable is that i get an error like this

unborn gale
#

hi, I am trying to make an animation, when making a perimeter and referancing it in code it says there isnt a perimeter named (name of perimeter)

rich adder
rich adder
sudden grove
# rich adder huh

i have an idea for an inventory in which when you start the game its empty, but then as you progress through the game, you trigger an "event" in which unlocks a button in the inventory, therefore revealing the image, name, and ability to click, therefore allowing access to the item, then rinse and repeat, so the inventory would have all of the buttons premade but just disabled, and the events enable the buttons

#

its like unlocking keys for mobile doors as you progress through the game

rich adder
unborn gale
sudden grove
boreal tangle
#

does soemone know why the character cant walk with this code. I know using the input manger would be easier but I wanted to try it just keys.

rich adder
#

well then do it correct

rich adder
#

where is there a Building parameter

visual hedge
rich adder
#

so whats the actual problem ? 🤔

#

make what work

#

so reference that

#

then do .enabled = false on the renderer or GameObject.SetActive(false)

#

idk what to tell ya then

#

follow the tutorial better 🤷‍♂️

unreal imp
#

guys: 1.happy christmas, 2.how do i get the position of a collision between 2 objects? its for my bullet holes: ContactPoint contact = col.contacts[0]; Vector3 positionCollision = contact.point; var bulletHole1 = Instantiate(bulletHole, positionCollision.normalized, Quaternion.identity, col.collider.transform); bulletHole1.transform.LookAt(-gameObject.transform.forward);

rich adder
#

use the method

#

GetContact / GetContacts

unreal imp
rich adder
#

my first raycast took a whole day to figure out (and thats AFTER blindly copying)

#

with time it will take you less and less

#

🏅

#

this will get you disqualified from medal

rocky canyon
#

i get sidetracked when UI is involved.

#

Making the buttons juicy leads to dopamine hits just when clicking 😄

#

clean Console 🤤

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

public class PlayerScript : MonoBehaviour
{
    Rigidbody rb;
    public float speed;
    public float jump;
    bool jumpable = true;
    private FootstepController footstepController;
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();
        footstepController = GetComponentInChildren<FootstepController>();
    }

    // Update is called once per frame
    void Update()
    {
        
        if (Mathf.Abs(Input.GetAxis("Horizontal"))>0 || Mathf.Abs(Input.GetAxis("Vertical")) > 0)
        {
            if(rb.velocity.y == 0)
            {
                if (!footstepController.isWalking)
                {
                    footstepController.isWalking = true;
                }
                
            }
            
        }
        else
        {
            footstepController.isWalking = false;
            
        }
        rb.velocity = transform.right * Input.GetAxis("Horizontal")*speed + transform.forward * Input.GetAxis("Vertical") * speed+transform.up*rb.velocity.y;
        if (Input.GetKey(KeyCode.Space) && jumpable)
        {
            rb.AddForce(Vector3.up*jump*Time.fixedDeltaTime,ForceMode.Impulse);
            jumpable = false;
            footstepController.isWalking = false;
        }
        if (rb.velocity.y == 0 &&!jumpable)
        {
            jumpable = true;
        }
    }
}

it works well but the jump is not always working with the same force

rocky canyon
#

zero out ur Y velocity prior to the jump

#

if ur travelling downwards (negative in the y) ur jump will have to fight against it.. draining off some of the Y velocity

#

if ur travelling upwards it compounds and makes the jump higher

rich adder
#

and take out FixedDelta time

rocky canyon
#

zero'ing it out just before the jump will fix those issues

orchid raven
#

oh wait

#

i will try to make it else if

#

it's better now

#

wait

#

nvm

#

jump force is not the same

sudden grove
#

guys would it be possible to when i pick up my flashlight, it equips it, and it unlocks the button in my inventory, in which i can then click the button in my inventory to destroy object?

#

and again to equip it?

orchid raven
modest dust
#

But you basically described what you need to do, so there's no need to believe, just do it

sudden grove
modest dust
#

First I'd have to decode half of what's written there

fleet patio
sudden grove
#

im not the best at drawing but does it make sense?

main sage
#

not if we can't read it 🤣

sudden grove
#

okay lemme remake it and ill come back

modest dust
#

Easiest logic I can think of is:

  • Have flashlight prefab
  • On Flashlight pickup, auto-equip it and unlock button
  • Once the button is unlocked do what you want
#

There's nothing much to really think about here

eternal needle
sudden grove
sudden grove
eternal needle
#

no this exact sequence is impossible to code, its never been attempted

#

Yes of course its possible to code, you just have to do it

sudden grove
#

i was scared then

#

😭

eternal needle
#

like 99% of the time when someone asks "is this mechanic possible to code" the answer is yes. you just need to code it

sudden grove
#

so if i drop the object then just spawn a new one, rinse then repeat, then yano

#

infinite flashlights

#

unlesssss

#

i destroy the previous flashlight when its clicked again

modest dust
#

I still don't quite follow

#

If you drop the flashlight then it no longer exists in your inventory

#

Only on the ground

#

There's always just one if implemented correctly

sudden grove
#

once its unlocked its unlocked

#

if that makes sense

#

its like "abilities"

main sage
#

so then maybe dont drop stuff on floor?

modest dust
main sage
#

or is this unlimited behaviour expected?

sudden grove
sudden grove
#

but then when you click it again in the inventory

#

it teleports it back to your hand

#

and if you click the button again whilst your holding it, then just destroy it aka "unequip"

eternal needle
modest dust
sudden grove
#

but in the case that they switch to another item, or despawn the item by unequiping it, i need to be able to spawn a new one when i click it

modest dust
#

Can't say much without seeing the actual code.

eternal needle
modest dust
sudden grove
#

or is that just an easy way of destroying it

modest dust
#

Show code where you try to access it.

#

Dear lord

eternal needle
sudden grove
#

that makes sense

wintry quarry
#

Then what isn't working?

modest dust
#

You have to have a reference to that class instance and access it via that instance.

sudden grove
#

cause i already technically have the code

#

i just need to slap it on the button

boreal tangle
#
    void Update()
    {
        walking(Input.GetAxis("Horizontal"));
        if (currentState == CharacterStates.walking) Debug.Log("walking");
    }
    public void walking(float direction)
    {
        if (direction != 0)  currentState = CharacterStates.walking;
        rd.velocity = new Vector2(direction * walkSpeed * Time.deltaTime, rd.velocity.y);
    }

Does someone know why the character with this script wont move?

modest dust
#

What's the context of what you're trying to do

wintry quarry
#

You said something about clicking on things. Presumably you'd get the reference through whatever that clicking mechanism is. But you haven't shared anything about that

sudden grove
#

@eternal needle do you by chance know which object id put into my button clicked function?

#

cause i need to reference a piece of code

#

not an object

modest dust
boreal tangle
modest dust
eternal needle
modest dust
sudden grove
#

wait ignore me

wintry quarry
#

A button? One button? This is confusing

boreal tangle
#

I thought you multiplied velocity by deltatime so it would work the same at every frame rate

modest dust
main sage
#

yeah that's real world time

#

not frame based

modest dust
boreal tangle
#

ok ty

sudden grove
#

wait dont ignore me

#

i need to fill in the thingies

#

like the rigid bodies, box colliders etc

true pasture
#

how could i run code only when a switch statements has nothing true in it

rich adder
sudden grove
rich adder
sudden grove
true pasture
rich adder
true pasture
rich adder
#

remove case

#

myb

true pasture
#

ah thanks

sudden grove
#

this would then do the job, without the major effort

rich adder
sudden grove
#

yeah

rich adder
#

well yeah

#

but i still dont know what you're doing with it

sudden grove
#

clicking the button would allow me to equip the torch from anywhere, as if i unlocked it

#

so what imma do is set it to when i pick up the torch for the first time, it unlocks the button, and that then gives me access to the torch

#

like an ability in the game

rich adder
sudden grove
#

its just kinda similar to what my regular pickup script does

rich adder
#

just equip it

#

SetActive(true)

#

or some

sudden grove
#

if i click the button, change the parent of the torch to Item location

#

thats how my currect code works

#

i mean my pickup code

boreal tangle
#
 Gizmos.DrawSphere(transform.position, col.bounds.extents.y);

does someone know why I keep getting an error when I try to put this code segment in update. it keeps saying "Gizmo drawing functions can only be used in OnDrawGizmos and OnDrawGizmosSelected" but I don't know what that means

sudden grove
#

i just need to be able to teleport it to my hand

rich adder
steady bear
#

!code

eternal falconBOT
rich adder
#

if you already picked up something its technically should be on the player already as child and SetActive to flase

sudden grove
rich adder
steady bear
#

Hi
I have Remote config (field "BuildingsResources"):

{
  "MetalMine": {
    "baseProductionPerHour": 30,
    "baseMetalCost": 60,
    "baseCrystalCost": 15,
    "baseEnergyCost": 10
  },
  "MetalStorage": {
    "baseCapacity": 1000,
    "baseMetalCost": 500,
    "baseCrystalCost": 300
  }
}

Plus I have those structs (also tried with classes):

[Serializable]
public struct BuildingsResources
{
    public BuildingMine MetalMine;
    public BuildingStorage MetalStorage;
}

[Serializable]
public struct BuildingMine
{
    public int baseProductionPerHour;
    public int baseMetalCost;
    public int baseCrystalCost;
    public int baseEnergyCost;
}

[Serializable]
public struct BuildingStorage
{
    public int baseCapacity;
    public int baseMetalCost;
    public int baseCrystalCost;
}

Then I'm getting this json by:

var jsonString = RemoteConfigService.Instance.appConfig.GetJson("BuildingsResources");
BuildingsResources = JsonUtility.FromJson<BuildingsResources>(jsonString);
OnLoadConfig?.Invoke();

But in action I have empty parameters inside MetalMine and MetalStorage.
What i'm doing wrong?

sudden grove
rich adder
sudden grove
rich adder
#

if you dropped it you gotta pick it up again anyway no?

sudden grove
rich adder
#

button doesnt come into play unless you are holding it already

sudden grove
#

if its dropped then itd just teleport the object back to my hand

#

like the skateboard from skate 3

rich adder
#

well we call that Design Feature that you should clarify before 😛

sudden grove
#

you drop it and then whenever you want you can just thors hammer it back

sudden grove
rich adder
#

so keep the reference to the object

#

so you can easily teleport it back

#

and what is even the point of dropping it if you can just teleport it back in your hand xD

sudden grove
#

really quick before i do any of this i probably should mention i dont know how to open my inventory yet, as well as freezing my camera and unlocking my mouse 😭

sudden grove
#

cause its a horror

#

i wanna do a thing where you can throw stuff and a monster will hear it and run to it

#

@rich adder this is the furthest ive ever got in a project so im really scatter brained lmaooo

rich adder
sudden grove
rocky canyon
#

if(tab){toggleInventory = !toggleInventory;}

#

🎅 o7

rich adder
#

:krampus

#

😢

sudden grove
#

@rich adder how would i code that if i press tab AND the gameobject is active, then disable the gameobject?

rocky canyon
sudden grove
rocky canyon
#

u call it whenever u want

#
   void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            ToggleThingAndObject();
        }
    }```
sudden grove
#

void Update()
{
if (Input.GetKeyDown(KeyCode.Tab))
{
Inventory.SetActive(!Inventory.activeSelf();
}
}

sudden grove
rich adder
#

u have extra (

rocky canyon
#

u could also just check the thing..

//do stuff that u want to do when the thingToToggle is true;}
else
{
//do stuff u wanna do when thingToToggle is false
}
rich adder
#

Inventory.SetActive(!Inventory.activeSelf); should work fine

sudden grove
#

i know this works, but it doesnt work the other way around

#

would i just disable it in else?

rocky canyon
#

think about why the else statement would run.. in that situation where the conditional is Inventory != null

#

oh and tryitandsee

sudden grove
#

im dying here 😭

#

so i can get it to disable

#

but then i click it again, and it doesnt enable

queen adder
queen adder
rich adder
queen adder
#

ahhh

#

hold on

#

i'll do that now

rich adder
#

depending on the image

queen adder
#

ah ok

#

how do i edit the color?

#

in this tutorial, the damage overlay is image type and the color is editable

polar acorn
#

Like that

#

That's how you edit the color of an Image

queen adder
#

well

#

i cant if its a sprite no?

sudden grove
#

bro i must be doing something wrong

polar acorn
queen adder
#

how?

polar acorn
sudden grove
#

this code is only turning OFF my canvas and once its off it wont come back on

polar acorn
teal viper
#

Next time google the API docs yourself.

sudden grove
#

hang on

polar acorn
queen adder
sudden grove
#

WHYYYYYY

#

now i add to the inventory some code that essentially says, when this is active, freeze my camera and unlock my mouse

teal viper
#

It's all explained in the docs.

sly peak
#

what chat do i go to for help regarding github with unity

teal viper
sudden grove
#

i click on it and its only looking in my heirarchy

polar acorn
sudden grove
#

wait wrong thing

polar acorn
#

Two images and neither contains what I asked

sudden grove
#

sorry

#

im kinda neww so im not sure i understand what your asking?

polar acorn
#

What type is the variable PlayerCamScript

sudden grove
#

uhm, where would i look?

polar acorn
#

Where you typed the variable

sudden grove
polar acorn
#

Why is this variable of type MonoBehaviour

sudden grove
#

i dont know how to set it to a script

polar acorn
polar acorn
#

Whatever type you actually want

sudden grove
#

i dont know why im so confused

polar acorn
#

What script do you want to reference

sudden grove
#

i wanna reference a script called PlayerCam which is attached to my camera

sudden grove
#

i did

polar acorn
#

Okay, show the updated code

sudden grove
sudden grove
polar acorn
#

Okay, good. Now drag in whatever object has the PlayerCam you want to reference

sudden grove
#

ohhhh

#

i get it now

#

thats abit weird

polar acorn
#

how is it weird

sudden grove
#

ion know

#

before this ive just been able to reference the script straight up

polar acorn
#

No you haven't

sudden grove
#

not reference the script THROUGH an object like that

polar acorn
#

You can't reference a script directly

#

because a script is not an instance

sudden grove
#

oh wait your right

polar acorn
sudden grove
#

im an idiot lolll

polar acorn
#

Those are both objects

sudden grove
#

yeah i realise now

#

i thought i referenced it straight up

sudden grove
polar acorn
sudden grove
#

but theyre both set no?

polar acorn
#

Well, considering that's a custom error message you wrote, where did you put it and what causes it to print?

sudden grove
polar acorn
# sudden grove

Well, it's in two places so it could be either of those conditions.

#

Is there a reason you're doing this manual null checking? Are these fields not being set a common occurrence you expect to happen in normal play?

sudden grove
sudden grove
polar acorn
polar acorn
sudden grove
polar acorn
sudden grove
#

sorry if i seem slow

polar acorn
#

So why not just remove them

#

They only make errors harder to find

#

If those are null, they should throw an error. You aren't doing anything useful by hiding the error and replacing it with a text message that doesn't give you any context

sudden grove
#

ohhh okay

polar acorn
#

Don't do that

sudden grove
#

i never wrote it, like i said chatgpt

#

this entire block was given to me

#

i just customise it to what i need

#

imma try to stop using it

polar acorn
polar acorn
#

It's in your project, it's your code

sudden grove
#

well its giving me the error cause the camera script is null?

#

or is that because its NOT null?

polar acorn
#

Doesn't matter get rid of it and read the much more useful error message unity provides

sudden grove
#

i got rid of them and im getting no errors?

polar acorn
#

Then you're good

safe carbon
#

So the ball bounces down perfectly on to last plane i was thinking of making it reset to its original position it dropped and basically make it infinite loop ive figured out i can just loadthe scene backup to make it infinite but what would be a good way to get rid of the bounciness it carries from the last plane

sudden grove
safe carbon
#

The issue was it was giving it unpredictable bounce because of the last plane is bounced off

#

I cant figure it out lol

polar acorn
safe carbon
#

Yeah that works perfect but i want a do it without

polar acorn
safe carbon
#

Reload

sudden grove
polar acorn
safe carbon
#

Ohhh

polar acorn
#

Along with resetting the position that should zero out any momentum it has

polar acorn
safe carbon
#

THANK YOU i was trying to turn off the bounce after it collides with last one no wonder that wasn’t working

#

It still had motion carried over

#

I am dum

sudden grove
polar acorn
#

If there's an error just let there be an error

#

Don't null check somethig unless there's a legitimate use case where those should be null

sudden grove
polar acorn
sudden grove
#

okay i get you

sudden grove
#

and heres my new code

polar acorn
#

Then this object does not have a PlayerCam script on it

drifting burrow
#

need some help with a problem. im trying to make my player teleport when entering a trigger. Im using this code and the debug.log gets executed but the player doesnt teleport to the destination. the teleport target is assigned and getting no errors notlikethis prob a stupid solution im overlooking. any help is appreciated

{
    public Transform teleportTarget;

    private void OnTriggerEnter(Collider col)
    {
        col.transform.position = teleportTarget.position;
        Debug.Log("Hit");
    }
}```
cosmic dagger
drifting burrow
#

i changed the code to other.CompareTag("Player") and the script is attached to the "teleporter" object

drifting burrow
cosmic dagger
#

or did you create a custom script that you use for your character controller?

drifting burrow
#

a custom script

cosmic dagger
#

your previous code will set any collided object to the teleport position because you don't check what the collided object is . . .

summer stump
drifting burrow
#

Collided with Player

cosmic dagger
#

log the position of the player and the position of the teleport GameObject (after you assign it) . . .

drifting burrow
#

visually the player isnt teleporting at all?

open veldt
#

Hiii Is there a way to set default values for inspector objects? I have a serializable class and I want the default values to be different, but setting default values in the class just doesn't work in the inspector for some reason

cosmic dagger
sudden grove
polar acorn
sudden grove
polar acorn
#

I don't see the InventoryState script on this object

sudden grove
#

lemme check where i put it

#

because the whole point is that its on the inventory i think, and its "looking" at player cam

summer stump
# sudden grove

Also looks like you gave a render pipeline/shader issue.
(Pink textures)

sudden grove
#

cause i keep biting off more than i could cheww

#

so i go through level design to more functionality on the player

#

to some more level design

#

so im focusing on my character fully before i do level design

sudden grove
#

it just disabled it off the bat

polar acorn
#

of the object

sudden grove
#

Inventory?

polar acorn
#

The one with the script that threw the error

sudden grove
polar acorn
# sudden grove

This object has no PlayerCam script on it, as I said before

sudden grove
#

yeah but what im saying is, is its looking at the Player Cam object, to then turn off the script, sort of reaching over to it and remotely turning it off, i just tried adding it to the actual camera and it just reversed all my controls and turned off the script without letting me turn it back on

polar acorn
#

this object has none

polar acorn
#

so in Start you set the variable to null

sudden grove
#

so how would i remotely turn off the script i need to turn off

polar acorn
sudden grove
#

so i have to do it on the camera?

#

aka the object WITH the script

polar acorn
sudden grove
#

i dragged in the correct object originally?

polar acorn
sudden grove
#

i mean on my next step

polar acorn
#

You are specifically setting that variable to the PlayerCam component on this object

#

Why are you doing that if you don't want to do that

sudden grove
#

ohh i see it now

#

im setting playcamScript variable to the GetComponent<PlayerCam>

polar acorn
sudden grove
#

im assuming its just a loop thats doing nothing?

#

literally just setting itself to itself

polar acorn
polar acorn
sudden grove
#

oh okay

polar acorn
#

it's setting the variable to the PlayerCam component on this object

#

which does not exist

#

so it's null

sudden grove
#

okay i think i kinda understand

#

so what would i be looking to do exactly

#

PlayerCamScript is referring to the script

polar acorn
drifting burrow
sudden grove
polar acorn
sudden grove
#

but it wont turn back on now

polar acorn
sudden grove
polar acorn
# sudden grove

So, every frame, if this object is active, disable playerCamScript. If this object is not active, enable playerCamScript

#

Is that what you want to happen?

sudden grove
#

wait so isnt that infinitely turning it off and on

#

so if its on turn it off and if its off turn it on?

polar acorn
quartz anvil
#

!code

eternal falconBOT
sudden grove
polar acorn
sudden grove
#

cause im trying to set it so that if my inventory is open, it takes that and turns off my camera

quartz anvil
#

'''cs

#

oop

sudden grove
#

i moved it onto my player because its not gonna be turned off

polar acorn
#

to toggle a different object

sudden grove
#

wait no hang on

#

this code does nothing but turns my script on and off

polar acorn