#💻┃code-beginner

1 messages · Page 257 of 1

radiant frigate
#

well + whatever i need it to debug :

#

imma read the docs maybe i can figure it out alone now with the tips you gave me

#

ty both!

carmine turret
#

Any ideas on how I could fix this? or amI going to have to program my way around it 😛

#

Actually someone suggested changing this, oes anyone know what it does?

#

Okay nevermind I learnt what it does, but It doesnt seem to help.

buoyant knot
#

the point of iterations is to give the physics system the ability to refine the result of a simulation

carmine turret
#

Yup, got that

radiant frigate
#

okay i have made an advance

carmine turret
#

Sadly it doesnt seem to fix my issue

buoyant knot
#

think of a simulation like trying to solve a math problem approximately. More iterations lets you put more effort into the solving, which makes it more accurate. But should not fix a problem

#

if it does fix a problem, then you were really truly fucked

carmine turret
#

maybe if I crank it really high, but Of course I dont really want to do that becuase of performance

radiant frigate
carmine turret
#

Hrm... Not sure how I can go about fixing this honestly

buoyant knot
#

is your player’s rigidbody collision mode set to continuous or discrete?

carmine turret
#

Ah.

#

Discrete

#

assuming thats PROBABLY it

buoyant knot
#

yeah. that’s very wrong

radiant frigate
buoyant knot
#

change it

radiant frigate
carmine turret
#

Honestly, Think im basically done with my entire controller!

radiant frigate
#

here is the part of the code that should be affected by the bug.

buoyant knot
#

if your collision detection mode is set to discrete, you check collision at specific points, instead of like a continuous line. Which means you land inside walls and blocks and shit, instead of going up to them

carmine turret
#

Gotcha

#

Worse for performance I assume

#

but for one character I imagine its negligible

buoyant knot
carmine turret
#

hahaha

buoyant knot
#

oral tradition

carmine turret
#

The control feels super good to use

#

Some really decent platforming I think. now I guess... art and levels + level mechanics

#

eesh this is gonna be "fun"

buoyant knot
#

“fun” is code for garbage

carmine turret
#

My artistic skills are lacking

#

I could maybe buy some art assets but ehhh I dunno

#

then if I do still need to make some assets, the style wont match

buoyant knot
#

make it work before you touch art

carmine turret
#

same with the character I guess

carmine turret
#

Ive had some people playtesting too ^^

radiant frigate
carmine turret
#

I wish to potentially sell the game as my first indie game

#

I rewrote the entire code to be cleaner for future stuff just incase

radiant frigate
carmine turret
#

Thatway if I make map mechanics that require controller edits, then I can come back and do so easily

#

Appreciate it, but the test map I have isnt really suitable for it and I am shattered. 2 hours sleep in 48 hours is taking a toll hahaha

buoyant knot
#

Your game should be good without fancy art, and then you add art to enhance.

carmine turret
#

Of course

#

but I need art to build the map

buoyant knot
#

so don’t stress over art

#

you don’t need the mona lisa

carmine turret
#

its a grappling hook based height platformer

#

I could just grey boy everything for now

#

and make a bunch of grey assets and replace them with proper sprites later

silk night
#

If you are like me and need some eye candy while developing, even if the style is mismatching use free asset packs first, and replace them with a consistent style later

#

that way you can block out your level but it doesnt look like a grey-block desert

radiant frigate
#

loup can i ask for help in one thing, do you have a high knowledge on how references work ?

buoyant knot
#

i know the basics

radiant frigate
#

surely with that it will be enough i think

#

okay lemme give you full context

buoyant knot
#

and FindGameObjectByTag is a noob trap

radiant frigate
buoyant knot
#

because it has to search the whole scene for the reference

carmine turret
#

Then come back and make new assets matching the shapes I used before

buoyant knot
#

and also it would need to be unique

radiant frigate
#

yeah i have a prefab with that tag so i think thats where it all goes wrong

carmine turret
#

So ill prolly make like 20 or so different shapes for the platformers themselves + interactable objects, then come back and remake them in each map flavour

buoyant knot
#

if you have a fixed object in your scene, then use SerializedField

radiant frigate
carmine turret
#

(9 realms, so 9 different flavours some of which will be very similar)

buoyant knot
#

yeah, that’s very wrong

radiant frigate
buoyant knot
#

are both of the referenced scripts in the prefab

radiant frigate
#

nope

#

in is in the bullet that the first prefabed " pink enemy" instantiates

buoyant knot
#

does the object in the scene need a reference to the script in the prefab, or the other way around

radiant frigate
#

the bullet needs to know which bullet number she is so she can have certain rb2d.velocity

buoyant knot
#

so the script in the prefab needs to get information from the other object

radiant frigate
#

and im thinking that somehow has a conflict with the other thing shooting

radiant frigate
#

isnt there a way to instantiate it ( the bullet) as a child and get the information of the father (pink enemy)

buoyant knot
#

so you need to:

  1. When you Instantiate, keep reference to the object you made
  2. GetComponent on the thing you made, to search for a specific script.
  3. The script you find needs to have a public method in it so you can pass the necessary information in it
#

Instantiate returns a ref to the object made

radiant frigate
radiant frigate
buoyant knot
#

the return type of Instantiate is GameObject

radiant frigate
#

i havent really understood return completely

#

what i understood is that it returns a variable to something

#

but i dont know how to tell which one to whom it should be returning to

buoyant knot
#

it is a fundamental part of the language

radiant frigate
#

alright !

#

but b4 going to read the docs

#

i think the problem is the previously mentioned

#

but how can it affect in that way

#

wouldnt the bullet just get instantiated in the same way that the ones from the other pink enemy do but just from the position of the new pink enemy ?

buoyant knot
#

whenever you instantiate, you want to:

  1. Instantiate
  2. SetParent for the transform to the new parent gameobject
  3. Set the position
radiant frigate
#

yes i know thats what i want to do

#

but the thing that is missing is not that it doesnt spawn

#

its just that it doesnt take a velocity

buoyant knot
#

you need a reference to it to be able to tell it to be modified

radiant frigate
#

and why does it work in the first pink enemy?

buoyant knot
#

because you are probably getting a reference to the same one enemy when you FindGameObjectByTag

#

which is a function you should realistically not use

radiant frigate
#

i dont understand it but i guess once i read the docs maybe it becomes clearer to me

#

ty for the help!

#

is it this what i want to do?

#

btw whenever i ask something its more like giving my pov or what i think is correct and questioning it

#

not like: idk if this is it but it may be so imma just ask

timber parcel
#

I've been trying to include the class of this script into another script to access it's variables by doing this

Public PlayerCombat playerCombat;
public int damage = 1;

Public void Damage Player()
{
playerHealth = playerHealth - damage
}

playerHealth is the currenthealth (sorry if its a bit confusing)

#

problem is, when I do it, the variable isn't recognized in the other script

#

I'm gonna try to replicate it again since I deleted it all yesterday

eager plinth
#

does anyone know where I go to fix this error? like what pannel?

timber parcel
#

Have you tried restarting?

eager plinth
#

twice.

timber parcel
#

yikes

rancid tinsel
#

is there a way to check if an object is attached to a canvas in script?

eternal needle
timber parcel
#

maybe something along "isChildOf" perhaps?

#

aw

rancid tinsel
timber parcel
dawn kestrel
#

I'm trying to check on a specific layer if a particular region of space has any colliders. Google keeps leading me to methods like BoxCast and CheckBox, but they seem to have far too many arguments for what I'm looking for. How do I add something akin to a Collider to an object such that I can just get that attached collider-like-object to basically do a CheckBox by calling an argumentless method?

eternal needle
rancid tinsel
#

do you mean to put 2 separate objects in 2 scenes

#

in charge of the cursor?

eternal needle
eternal needle
dawn kestrel
#

is there a component that can call Physics.OverlapBox using public variables already set on the component?

eternal needle
#

if you have a question about how to use it, then thats better to ask rather than trying to find an alternative

dawn kestrel
#

do I just make a new behaviour script?

queen adder
#

Anyone know why a camera mode canvas rendering to a rendertexture displayed in a raw image doesn’t look exactly like what it shoud

queen adder
#

Above is the tmp text in the raw image, then theres the exact same tmptext but on a screen overlay canvas. i tried messing with the import settings, color format etc. to no avail

#

it looks like maybe its not supporting transparency correctly? which format would be correct:/

summer stump
#

It's not needed though

dawn kestrel
#

Is there a way to pull all the information needed for the cast from the object?

#

or rather, a component on the object?

teal viper
# queen adder

First figure out if the problem is with the render texture or the camera that renders to it.

summer stump
#

the link above shows what you need with example code and everything

eternal needle
dawn kestrel
#

haven't used that yet

summer stump
eternal needle
#

you might wanna do some basic c# lessons first then, if you arent sure about how to call a method

dawn kestrel
#

Here's an example of my code so far. I misunderstood a page that showed BoxCast listed under a heading of Methods under a heading of CapsuleCollider, and got a little too hopeful.

#

admittedly this is me modifying a far more complicated scene.

eternal needle
#

are you modding a game by chance?

teal viper
#

Seems to be something from VR chat.

dawn kestrel
#

a VRChat world, though really more of a system someone set up for making certain kinds of worlds

eternal needle
#

oh i didnt see the last message, yea u should be asking for help in the games modding community instead

dawn kestrel
#

they're not particularly active right now.

Though, the reason I asked about making it a new script is because each zone being checked will be tied to an area, thus for that particular object, I want the variables stored with it.

#

the jist of what I'm trying to do is check to see if an object on the Walkthrough layer is on the runway I have here.

#

since there will be multiple runways, the thing that makes sense for me is to have each runway have its own "checker" to see if the runway is clear, returning a bool to another object on its status when asked.

#

though more and more, it looks like a premade solution doesn't already exist (unless there was some way to use CapsuleCollider.OnTriggerStay like some sort of pseudo-bool)

rancid tinsel
queen adder
teal viper
queen adder
#

seems like for some reason the render texture has this blueish gray outline instead of additive alpha. which is weird, because i dont know what could be saturating it 🤔

rancid tinsel
queen adder
summer stump
#

You are setting it to be the child of an object
this.transform.SetParent(FindAnyObjectByType<Canvas>().transform);
So the canvas is likely being destroyed (assuming THAT is NOT in DDOL), which of course destroys its children

rancid tinsel
summer stump
polar acorn
rancid tinsel
summer stump
polar acorn
#

Cursor is not a DDOL object. It has a parent at the time you make it a DDOL

polar acorn
#

Only top-level objects can be made DDOLs

summer stump
rancid tinsel
#

oh should I set it to DDOL when making it the root

summer stump
rancid tinsel
#

btw is this the correct syntax for making it the root

timber parcel
#

Hey I need some assistance

rancid tinsel
#

i feel like i might be just doing some crazy stuff rn cuz ive never done this before

summer stump
#

just go straight to transform

#

And do DontDestroyOnLoad(cursorScript.gameObject);

rancid tinsel
summer stump
#

also, you don't need the "this" anywhere like that

rancid tinsel
#

ill try your method because its way cleaner lol

summer stump
#

gameObject already means that object the script is attached to

timber parcel
#

I asked a few moments ago

summer stump
polar acorn
rancid tinsel
rancid tinsel
#

tbh idk ive been coding for the past 18 hours

polar acorn
#

You've had to do so much parent shuffling and DDOLing instead of just like, having one in each scene

#

Do that and you basically cut out 80% of the code that's here

timber parcel
#

Im trying to get public variables from this script (related lines of code highlighted)

#

And here's the attempt

eternal falconBOT
timber parcel
#

I'm not really sure what I might be missing here, my other codes are following the same thing

polar acorn
#

You're trying to use a variable on Enemy that doesn't exist

summer stump
polar acorn
#

If you want to use a variable on an instance of PlayerCombat you have to tell it which PlayerCombat you want to reference

summer stump
#

myPlayerCombatReference.playerHealth

summer stump
# timber parcel Okay.. a bit lost here

you need a variable that holds a reference to the specific Player Combat component you want to get the playerHealth value from. Then you access playerHealth through that reference using dot notation

polar acorn
timber parcel
#

there is only 1 playerCombat script

summer stump
polar acorn
teal viper
summer stump
#

You could decide to make more at any point

timber parcel
#

How exactly do I specify which one?

polar acorn
summer stump
#

If you can, you want a serialized reference

#

Otherwise, you are likely instantiating something, and Instantiate returns the object instance that was instantiated, so you just pass that where it's needed

radiant frigate
#

is there smth that manages probability in Random.Range, for example: Random.Range(1f(10%), 2f(90%));

#

its something hard to explain so idk how to google it if it exists

summer stump
summer stump
radiant frigate
#

b4 all

summer stump
radiant frigate
#

does it work is the range is larger than 2 ?

radiant frigate
summer stump
#

but looking up the definition, the word doesn't really fit there

radiant frigate
#

didnt understand the word

polar acorn
radiant frigate
#

wouldnt that make the code chunky once you have like 10 options?

radiant frigate
#

true

#

my mind wanted to use that but went to a mix between that and ifs

#

i can just use switch and it would work

radiant frigate
#

i think it wont work tho because on what i want to implement it

#

but i will try b4 making assumptions since it works strange and i need to sit there and think how i want to make that

summer stump
radiant frigate
#

i will check that first then

#

ty!

timber parcel
summer stump
#

that is a declaration

#

you need to actually populate that variable with the reference

timber parcel
#

So in unity's case... drag and drop it into the box in inspector?

summer stump
#

You could drag the PlayerCombat script (that is attached to an object) into the field via the inspector

#

Yes, exactly

dawn kestrel
#

is there a quick and dirty way I could use a CapsuleCollider to pull parameters for a Physics.CheckCapsule?

timber parcel
#

Ok but here's the strange part, even though it's public, it doesn't appear in my inspector

#

the script is saved I assure

summer stump
timber parcel
#

monobehavior

summer stump
#

(I think you showed it, but I can't remember)

summer stump
shut spade
#

quick question, how many does FindGameObjectsWithTag consume in the game?

timber parcel
#

sure, also which code? the enemy or PlayerCombat

shut spade
#

for ramming targets

summer stump
summer stump
shut spade
#

performance

summer stump
#

Avoid Find whenever possible

radiant frigate
shut spade
summer stump
#

almost every other solution is better

#

Serialized Reference is best

shut spade
#

ill try that

#

tysm

timber parcel
#

here ya go

summer stump
# timber parcel

Ok weird. Nothing wrong looking there. Show the Player Combat script?

dawn kestrel
#

I have a CapsuleCollider on a gameObject. I want to pull certain variables from the CapsuleCollider, then use those variables to calculate the Start Point, End Point, Radius, and Layer Mask of a Physics.CheckCapsule() call.

summer stump
#

You can't get the layermask from it of course

dawn kestrel
#

wait, really?

summer stump
timber parcel
dawn kestrel
#

CapsuleCollider has Layer Overrides. I thought I'd be able to pull those.

summer stump
summer stump
#

what would you even pull from the CapsuleCollider for layermask

#

that doesn't really make sense

timber parcel
#
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class Enemy : MonoBehaviour
{

    //hp
    public int maxHealth = 3;
    private int currHealth;

    public Animator animator;

    public bool enemyAlive = true;


    //fighting player
    public int damage;
    public PlayerCombat playerCombat;

    // Start is called before the first frame update
    void Start()
--rest of the script
timber parcel
#

yep, there's no * on any of the script headers (unsaved)

summer stump
#

The only other thing I can think is that there are compiler errors?

timber parcel
#

and I double checked by saving even those

dawn kestrel
summer stump
#

Just MAKE the LayerMask variable and set it

dawn kestrel
#

set it off what?

summer stump
#

I mean, you can just make variables for EVERY part of this, so I'm not sure what the fixation with the capsule collider is

summer stump
#

what does that even mean?

dawn kestrel
#

okay then, should I make a script that stores all the variables for a CheckCapsule on the object itself?

summer stump
#

I thought you had one already, since you are calling a method.... which needs to be done in a script
I would save the variables in that place

dawn kestrel
#

well, yes, but that's a different object, one that's gonna have to call a bunch of different areas

radiant frigate
#

why is this happening? it says i cant convert int to string but the guy uses it and works just fine

timber parcel
#

OK WEIRD! it finally works now, someone told me to replace

private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Player" && enemyAlive)
        {
            playerHealth.Takedamage(damage);
        }
    }

with

    {
        if (collision.gameObject.tag == "Player" && enemyAlive)
        {
            collision.gameObject.GetComponent<PlayerCombat>().TakeDamage(damage);
        }
    }

Im not too sure what he did there though..

#

but the damage amount can finally be changed in the inspector

summer stump
summer stump
dawn kestrel
#

should I be changing my workflow? Right now my logic is that the actual script that does things is on the panel/button that the player interacts with, and the variables for the object being affected remotely are on the object itself.

radiant frigate
summer stump
#

As the type

radiant frigate
#

yes ik

summer stump
#

Oh ok. The [] means array

radiant frigate
#

but the [] in both means like a list/array

summer stump
#

so, an array of ints, instead of an array of strings

summer stump
radiant frigate
#

never list?

#

because its fixated ?

summer stump
rich adder
#

arrays are fixed length

#

list are not

summer stump
#

List<int> is list

radiant frigate
summer stump
#

It's just how the syntax works

radiant frigate
#

yeah yeah i readed that yesterday or so

#

lists and arrays are so usefull

summer stump
#

And yes, arrays are fixed length. Lists have an array internally and methods to resize it and make sure the indexes have no gaps

dawn kestrel
#

hmm, so my next question is: if I store the variables I need on the object, is there a way I can use those variables to draw a gizmo?

radiant frigate
summer stump
radiant frigate
#

yeah yeah i just meant like that type of thing

#

ty!

summer stump
summer stump
radiant frigate
summer stump
dawn kestrel
#

I mean so that I can actually see in the unity editor what the area where the CheckCapsule is defined would be.

radiant frigate
# summer stump No problem!

a question about lists, if i write .remove (whatever i want to remove) it doesnt remove all of the items that match that description, is there a way of doing that?

#

for example a list that has (1, 1, 1, 2, 2)

#

is there a way to remove all 2?

radiant frigate
#

i have been thinking of maybe a while loop

#

ty!

ruby python
#

Mornin' all.

I have a ship flying over the moon at a fixed height, conforming to the sphere. On the moon I have some objects placed based on long/lat coordinates and based on images etc. they're accurate, so this is good.

Now what I'm trying to do is get the ships 'live' long/lat position but I'm not entirely sure how to do this. (currently was playing around with an empty at the center of the planet always 'looking at' the ship, but obviously this has problems when crossing the poles etc.

Would anyone be able to point me in the right direction on how to achieve this (a resource etc?) Thanks.

queen yoke
#

private and public i understand

#

but what about variable without both of them?

eternal needle
queen yoke
#

int vs private int = private both?

eternal needle
#

yes

queen yoke
#

ah! i seee

#

so when we use int
when we use private int?

summer stump
#

I generally always write private. Some people don't. It's just a personal choice

#

Just keep it consistent at least

queen yoke
#

lol ah! i see Thank you for both of your answer

#

for the private variable so can i use the same variable name in diffenct script because it's private saparate from each other?

rich adder
#

you could name it the same name even if public in different classes

queen yoke
#

can i change "other" in red circle to specific gameobject? i'd like to make a ball only to hit trigger

#

i mean other object which is not "ball" do not affect to this trigger

ruby python
# queen yoke

You can tell it to check the tag of the collider, if the collider other's tag == ball's tag, execute your existing isKickBallAttack

ruby python
#

That too 😉

queen yoke
#

thank you let me try

vagrant bramble
#

Hi, I hope I can get some help.

I have a question and have been tryin to understand this for awhile. I have my input system on a separate script and a character controller script to control the 2D gameObject which is my character. I don't know how to implement a sprint button so that when I hold it down, the movement speed changes.

In my Input script, I have a public void for Submitpressed and the function of if pressed true context.start and if not , canceled.

In my charactercontroller script, my movement section is the attached image. (I'm new to this so I followed someone else's tutorial)

When I pressed the sprint key, it only jerks forward and goes back to the normal walkspeed. Is there a code that I needed to implement to make sure when the sprint button is held down, the sprintspeed continues to hold until released? I look through a couple of other videos online to implement but can't stitch anything together that works.

InputScript: https://paste.ofcode.org/z2arnEyGpTTJTQGKK4nGQi
CharacterCode: https://paste.ofcode.org/qszfNXLgwh7e28wDag9zPn

keen dew
#

Show the input manager code. No screenshots, !code 👇

eternal falconBOT
vagrant bramble
keen dew
#
public bool GetSprintPressed()
{
    bool result = sprintPressed;
    sprintPressed = false;
#

this sets sprintPressed to false the first time you read the value

vagrant bramble
keen dew
#

...why would that affect it when the game starts?

#

Are you mixing it up with private bool sprintPressed = false;

#

And obviously you shouldn't set it to true there. Just remove that line.

vagrant bramble
keen dew
#

Yes, that's what I'm talking about

vagrant bramble
keen dew
#

You set the sprintPressed to false every time you check if the player is sprinting. So of course it will be false after that.

vagrant bramble
#

And if I want to add Animation to it, do I just add a line under the button pressed for move and run as well and linked that to the animation?

keen dew
#

The difference between sprinting and the other actions like jumping is that for those other actions you don't want the action to trigger every frame while the player is holding the button so that's why you set the variable to false for them, so that it only registers for the first frame

vagrant bramble
keen dew
#

Yes, in the player controller set the animation based on what the sprint status is

vagrant bramble
#

ok I'll try to figure this portion out

dawn kestrel
eternal falconBOT
rancid tinsel
#

any way to run OnPointerUp only if the mouse is still over the object that OnPointerDown was called on? I want the player to be able to drag the mouse off if they changed their mind and are still holding the left mouse button

#

What this causes is that the color changes, the player can drag the mouse off but the second they let go, no matter where their mouse now is, OnPointerUp is called

rancid tinsel
native seal
#

https://gdl.space/volopocutu.cs can anyone help me with this issue im having? somehow in the SetEnemyDifficulty function, the enemy.BaseStats which is on a scriptable object is getting changed even though im using a copy contructor

rich adder
rancid tinsel
native seal
#

a dictionary

#

that holds a enum and a class representing 2 floats, max and current

rancid tinsel
# rancid tinsel

seems like OnPointerUp takes "Press Raycast" whereas OnPointerDown takes "Current Raycast"

#

not sure what those are entirely

rich adder
native seal
#

EnemyData

#

EnemyData has Stats on it

rich adder
#

you're changing stats on the same object then

native seal
thorn tapir
#

What would be the "correct" way to implement crouching with the CharacterController? Modifying the controller height will make the player clip through the ground when the collider instantly expands (when uncrouching), but trying to LERP the height or do some wacky stuff with lerping player location while crouching and uncrouching feels really unprofessional/messy and causes tons of issues on slopes. Is there a better method that I'm not finding online?

rich adder
# native seal wdym

to me it seems you're making a copy of the same object and setting the values on the same thing

native seal
#

enemy is just a monobehavior

#

i define my enemies base stats on the SO then copy it over to the monobehavior and increase it depending on the difficulty

#

i don't understand how my SO is getting changed

rich adder
#

well if you're changing a reference type you're changingthe same object

native seal
#

but I used a copy constructor to create a new stats from the baseStats

#

does that not work?

rich adder
#

you prob made shallow copy or whatever is called

wintry quarry
native seal
#

well look at my copy constructor, is that a shallow copy?

rich adder
#

you mean this cs public Stats(Stats stats) { foreach (Stat stat in stats.Keys) { Add(stat, stats[stat]); } } ?

native seal
#

yes

rich adder
#

those are reference types

native seal
#

ahhh

#

i see

#

forgot my value is a class

#

i changed that recently

thorn tapir
#

It just seems like a janky solution even if it's industry standard

native seal
#

this should work now yes? public Stats(Stats stats) { foreach (Stat stat in stats.Keys) { Add(stat, new StatValue(stats[stat])); } }

rich adder
#

if its just stats make struct ?

wintry quarry
summer stump
native seal
#

an Enum

native seal
thorn tapir
#

alas it did not

wintry quarry
#

Changing the height and center is the way

native seal
#

basically when i pass my stats into a function, only a copy of the struct is passed

#

so I would have to make a new struct and assign it

#

just makes it more annoying

dawn kestrel
#

can anyone give me some advice on how to troubleshoot some code? I can't figure out how to check where it's going wrong.
https://hatebin.com/onsgobcdyq

rancid tinsel
#

am i correct in thinking this will check the OnPointerDown position against the current position of the pointer?

thorn tapir
wintry quarry
rich adder
wintry quarry
native seal
wintry quarry
#

If you moved the center down, when you increase the height of will put the bottom underground

rancid tinsel
rich bluff
#

purpose?

native seal
#

my Stats used to be a dictionary with Stat, float

#

but i changed it to StatValue which holds a max and current

#

forgot I had to change the copy constructor

rancid tinsel
# rich bluff purpose?

I want the player to be able to click on an object to place down a tower, but be able to still change their mind until they let go - this lets them drag off of the object which will return

#

also update: it worked 🙂

rich bluff
rancid tinsel
#

as in the IPointer interfaces?

rich bluff
rancid tinsel
#

im using them over getmouse.... because i dont want the player to be able to select towers etc while a UI component is in the way

rich bluff
#

it may break at specific angles scenarios because you are working in 2d ui space

radiant frigate
#

probability is an array, and if an item exceeds the price i want to remove all the numbers assigned to that item in the array (which i cant since its an array) so i should convert it to a list, but then how can i delete, for example all "2" inside the list ? and is there a way to make a list contain all that an array has?
Example:
private int [] probability = {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, etc etc
list<int> numbers = new list <int>();
numbers.add(probability);
or smth like that?

rich bluff
wintry quarry
dawn kestrel
#

is there a way I can highlight a point in the world given a Vector3 for debugging purposes?

rancid tinsel
radiant frigate
dawn kestrel
#

I tried and failed this. Is there a way to make it really bloody obvious?

rich bluff
wintry quarry
rich bluff
#

and only abort if not hovered

rancid tinsel
#

i can actually simplify is even further since im using the Enter and Exit for color changing already

#

so i can just compare the color

#

thank you!

radiant frigate
rich bluff
#

.Count

radiant frigate
#

that gives me a group of methods and i need it as a float

rich bluff
#

post code

radiant frigate
#

wait i think i know where i f up

#

nope i dont

#

the error says: you cant convert "group of methods" to "float"

rich bluff
#

what type is enemyType what type is probability

radiant frigate
#

i messed up the probability name

#

im an idiot

#

it was supposed to be numbers

#

it was an array

#

and it should have been a list

wintry quarry
radiant frigate
#

i dont know why but afterwards the error didnt show up

wintry quarry
#

Afterwards what

#

What error were you expecting

dawn kestrel
#

how do I get a gizmo to fire just once after using a method?

wintry quarry
#

Random.Range with two ints is a thing, and perfectly valid

dawn kestrel
#

wait, I see them!

radiant frigate
#

oh now i understand what you mean

radiant frigate
radiant frigate
radiant frigate
rich bluff
#

you make a class that you can send requests to

dawn kestrel
#

huh, I wonder why they are so off from where they were supposed to be

rich bluff
#

like draw box for 5 frames with this color

dawn kestrel
#

for reference, those red and yellow boxes are supposed to be at the ends of the capsule collider

rich bluff
#

you can draw gizmos in local space btw

#

Gizmos.matrix = transform.localToWorldMatrix

#

then you can use your capsule end points as just offsets

dawn kestrel
#

but they're drawn at the end points of my CheckCapsule method

#

!code

eternal falconBOT
dawn kestrel
#

not sure why the offset of the capsule collider is so far off from the offset of those end points

rich bluff
#

or start.y , whichever axis is "up" on the capsule

#

y probably

topaz thistle
#

!code

eternal falconBOT
topaz thistle
#

So, I'm trying to create the end game stats to appear when the timer hits 0, but when the timer hits 0, nothing appears to happen. Anyone know why? https://hastebin.com/share/neyonotugo.csharp

wintry quarry
rich bluff
#

what is Timer ?

topaz thistle
#

A script

#

The time does go below 0, I used a log statement for that

rich bluff
#

this can take a long time to debug, or you can use debugger to step through line by line and see where it fails

topaz thistle
#

But I'm not sure what else to do

wintry quarry
topaz thistle
#

All I can think of for a log statement would be the time. Would u be able to suggest some others?

wintry quarry
#

Yes, put a log inside that if statement and that function

#

To make sure they're actually running

topaz thistle
#

Ok

wintry quarry
#

Basic stuff. Question your assumptions

#

Make sure there's no errors as well of course..

topaz thistle
#

Yeah, there isn't :D.

rich bluff
#

ever used debugger?

topaz thistle
#

No?..

rich bluff
#

good time to start

topaz thistle
#

K xD

desert flume
#

how to access components and game objects from scripts without having the variable public

wintry quarry
#

If you mean "without assigning in the inspector at all", then you have to get a reference some other way

rich bluff
desert flume
#

Are there any bad practices that beginners would do that I would want to know?

wintry quarry
#

Sure, public variables are one

#

There's hundreds

topaz thistle
#

No idea why, but this time the script worked? Debug.Log scripts are just fixers I guess

wintry quarry
desert flume
wintry quarry
#

Too lazy

topaz thistle
rich bluff
rich bluff
#

relying on very specific paths, or tags in hierarchy instead of using interfaces or marker components to locate objects

desert flume
#

and what are marker components?

rich bluff
#

GetComponent<IMyInterface>()

desert flume
#

Ah

#

but the interface wouldnt be yours

#

it would be a unity component interface

rich bluff
#

marker component is just a dummy component, empty

#

what

desert flume
#

e.g getComponent<TextMeshProUGUI>

#

since how would a component implement your own interface

rich bluff
#

im talking about your code

#

the only you can have any interface you want

desert flume
#

Not sure I get it, do you have anything I can read?

rich bluff
#

from experience, a character rig, with bunch of hitboxes, mount points, etc

#

context for what im talking about

desert flume
#

how would I give IDamageable to a game object?

#

just have a script implement it?

rich bluff
#

yes

native seal
#

public class DamageTrigger : MonoBehaviour, IDamagable

desert flume
#

Yeah I get it

native seal
#

so then u can have some external thing access it through IDamagable instead of a direct reference to your class

dawn kestrel
#

alright, I got it this far! Thank you!

north kiln
#

Presumably a player or a damagable box or something would implement that one

native seal
#

interfaces are used to implement a feature shared between many things but have very different implementations

desert flume
native seal
#

it doesnt make much sense to have a interface on a generic "DamageTrigger"

#

unless thats for your player or something specific

north kiln
#

Hence why it didn't have the interface

native seal
#

ah i thought he wanted to know how to implement the interface on his class

#

didnt realize my fault

north kiln
#

I'll be updating my doc to be clear about the usage example 👍

dawn kestrel
#

oh goddammit. Do you know what my issue ended up being? I read this backwards.
layermask: A Layer mask that is used to selectively ignore colliders when casting a capsule.
"Layermask" is actually a parameter for what layers not to ignore.

radiant frigate
ruby python
#

!code

eternal falconBOT
ruby python
#

Hi all, would someone be able to check my maths on this bit of code please?

I'm trying to come up with a Long/Lat system and it's going pretty well. The Longitude calculation works fine, but my Lat calculation NaN's out almost immediately when I move and I'm not really sure where I've gone wrong.

void Update()
{
    RaycastHit hit;
    // Does the ray intersect the Moon's inner collider?
    if (Physics.Raycast(eagleGPSRayEmitter.position, eagleGPSRayEmitter.TransformDirection(-Vector3.up), out hit, Mathf.Infinity, layerMask))
    {
        eaglePosX = hit.point.x;
        eaglePosY = hit.point.y;
        eaglePosZ = hit.point.z;
        //Debug.Log("Hitting inner Collider");
    }

    longitude = (Mathf.Atan2(eaglePosZ, eaglePosX) * Mathf.Rad2Deg)-90f;
    latitude = (float)Mathf.Acos(eaglePosY) * Mathf.Rad2Deg;

    // this bit is to flip and quarter rotate the latitude number to put it where you would expect
    // (assuming you are an earthling)
    // with 0 at the equator, 90 at the north pole and -90 at the south pole
    latitude = (latitude - 90f) * -1f;

    Debug.Log("current long = " + longitude);
    Debug.Log("Current Lat = " + latitude);
}
radiant frigate
ruby python
#

Try debugging your list to check how many values are in there when you've assigned 'probability'

rich bluff
#

only possibility is that the raycast somehow returns 0 y

#

or some other crazy number resulting in infinity

#

try using debugger to see what exactly happens

thorn tapir
ruby python
#

It definitely doesn't return Zero, the value does change based on movement, but nans pretty much straight away. This is way more complicate maths than I'm used to if honest. lol.

rich bluff
#

first establish exclude that its a faulty raycast

#

faulty can mean it stops at some other collider, inside the collider or something else similar

ruby python
#

Raycast debug....

#

Values are 'moving' as expected.

teal viper
rich bluff
#
        public static float Acos(float f)
        {
            return (float)Math.Acos((double)f);
        }
#

yep

ruby python
#

Ah crap. 😕

teal viper
radiant frigate
vale cradle
#

guys i am working on my enemy and he is supposed to shoot fireballs when the player is in range but when i enter the enemy range it doesn't shoot fireballs and i get this error i am not able to understand where i went wrong even my code has no errors

ruby python
radiant frigate
#

omw

ruby python
#

Or 2.

vale cradle
#

i don't understand

#

am i supposed to change the player layer to enemy?

ruby python
#

Your variables enemy and anim are unassigned (Unity can't find them) in your EnemyPatrol script. How are you assigning them?

rich bluff
#

@vale cradle in your project panel, type into search t:RangedEnemy

vale cradle
#

okay

rich bluff
#

and check every instance for missing references

#

not project

ruby python
#

Guessing enemy is a gameobject and anim is your animation controller?

rich bluff
#

Hierarchy

vale cradle
rich bluff
#

it says enemy patrol is not assigned

vale cradle
rich bluff
#

i dont see enemy patrol in that screenshot, im assuming its another component

vale cradle
#

just a min

teal viper
vale cradle
#

i got where i missed it i didn't assign it to the animator

#

i got it

#

thankyou so much guys

radiant frigate
teal viper
cloud shore
teal viper
radiant frigate
teal viper
radiant frigate
#

yep apparrently not and thats what i dont get

#

since i have done the math so that doesnt happen

teal viper
radiant frigate
#

oh nvm i got it

#

i think i know where it is

ruby python
#

Hmmm. Would anyone have any clues as to how to fix my latitude issue please? Giving me a headache. lol.

radiant frigate
#

i think its because the maxType gets reduced b4 the foreach

#

so it starts deleting the "1" inside the list

#

and since 1 is the lowest thing it cant afford anything and the error jumps

rich bluff
teal viper
#

Debug it... So far these are just assumptions(that don't even make sense to me too)

rich bluff
#

my bad it should

radiant frigate
#

xD

rich bluff
#

you cant modify collection while foreaching it, but you are removing from a different one

#

you should learn to use debugger

#

it will solve a lot of issues

cloud shore
radiant frigate
rich bluff
minor patio
#

Shenanigans! Shenanigans!
I've got a method attached to a button that is for some reason executing twice... UnityChanThink

teal viper
radiant frigate
#

so just debug.log(int)?

#

well maxType instead of int

rich bluff
#

yes or learn to use the debugger

teal viper
minor patio
#

yup - debugger is essential, and I'm only just getting used to it

radiant frigate
#

that?

cloud shore
teal viper
radiant frigate
#

yeah my code is a bit spaguetti rn

#

but max type tells the game what probability to "erase"

#

there are 2 qualitys at the moment

teal viper
#

THe problem is not that a specific element is erased. But that all of them are erased

cloud shore
radiant frigate
#

if the engine cant afford quality 2(which costs 5) it will remove 1 from maxType

radiant frigate
teal viper
minor patio
radiant frigate
cloud shore
radiant frigate
minor patio
#

I'm just thinking out loud about how a method might inadvertenly be triggered twice by one button interaction - I do have it rigged with an interface that's very one-sided...

radiant frigate
teal viper
radiant frigate
#

yep

teal viper
#

You should debug properly

radiant frigate
#

how can i do that?

#

im reading the debug and i dont understand what happens

teal viper
#

Wherever you remove elements from the list, debug the count of the elements in the list

cloud shore
teal viper
radiant frigate
#

yep

teal viper
#

Then yes

minor patio
#

heh - deleting the interface didn't help
but it also didn't hurt 🙂

cloud shore
radiant frigate
radiant frigate
# teal viper Then yes

okay so what is happening is that once it beggins to delete an int from the list it just erases all of them

radiant frigate
#

yep

rustic epoch
#

I have a lil problem, could somebody help me ?

teal viper
cloud shore
minor patio
#

(bites lip) >:)

radiant frigate
#

what i am doing is that for each "maxType" (which starts at 2) inside an array called probability, it erases from the list numbers one "maxType"( a 2 )

#

or atleast that is my intention

rustic epoch
#

I have a code that is supposed to allow the player to move arround and move the camera as well, but it just moves the camera in one way, dont know why.

minor patio
teal viper
rustic epoch
teal viper
eternal falconBOT
minor patio
#

Remove will remove all the maxType entries found
try a RemoveAt...

radiant frigate
#

so it should erase the other two 2´s from numbers

teal viper
radiant frigate
#

yes

teal viper
#

And that's it

radiant frigate
#

and shouldnt try to delete more 2´s

minor patio
teal viper
radiant frigate
teal viper
radiant frigate
#

its under the loop

teal viper
# radiant frigate

Why would it matter after the loop? Do you understand how code is executed on computers?

radiant frigate
#

i think i do

#

which seems to not be the case

teal viper
#

So, why would it matter what it becomes after the fact? Also, the maxType in the loop is a different variable

rustic epoch
minor patio
teal viper
radiant frigate
radiant frigate
teal viper
rustic epoch
radiant frigate
#

it gives me an error if i do so

teal viper
radiant frigate
#

then how can i tell it to be the other maxType?

teal viper
#

Maybe think again what you're trying to do. Why would you want to use max type in a for each loop?

radiant frigate
#

foreach max type (which is 2) in probability

teal viper
#

for each is giving you values from the collection. If you're not using them, there's no point in it

radiant frigate
teal viper
radiant frigate
#

i just have the probability array so in each end of a round i can make the numbers list = new list <Int>(probability);

teal viper
#

That doesn't tell me anything.

radiant frigate
teal viper
#

I'm sorry, but I really don't understand what you're trying to do. Not from a coding perspective, but from pure logic perspective.

#

Maybe write your logic down on paper(in the form of a blockscheme for example)

radiant frigate
#

that whenever it cant afford an item erase it from the list so next time it tries to buy something the items it cant buy dont exist

#

i used a for instead of a foreach and it worked

#

i dont know why tho

teal viper
#

then it would look something like this, no..?

if(can't afford item)
  remove from list(item)
radiant frigate
#

but since i also have it done as a probability

teal viper
#

Then I don't understand what probablilities and other stuff has to do with anything

radiant frigate
#

i have more than one 1 and more than two 2

teal viper
#

I don't understand

radiant frigate
#

okay wait im going to try to explain everything

#

the engine has an amount of money

#

15 for example

#

each item has a price depending on quality:
q1 = 1$
q2 = 5$

#

so it chooses it random, but since i want that the higuer the quality the less chance there is to get it,

#

i have it choose from a random.range between 0 and the max amount of a list

#

lets say eight amounts of 1´s and two 2´s

#

so its 80% and 20%

#

once it decides which item to buy

#

lets say 1 q2

#

the money gets set to 10 since the price is 5

#

it chooses again

#

and its another q2

#

5 coins remaining

#

now its a q1

#

we have 4 coins

#

if the engine decides to buy a q2

#

for each 2 in probability it should erase one two in numbers

#

therefore the next time it tries to buy it it cant since there is no 2 in numbers

#

and can only buy q1 item

#

i think that summarizes it well

teal viper
#

That sounds super convoluted and prone to bugs to me.

radiant frigate
#

but that is for future enemies since i now only have 2 and the q1 is 1 coin so it is always affordable

radiant frigate
teal viper
#

For starters, it sounds like several independent systems are mixed together.

radiant frigate
#

it was the form that i came up with that was inside my knowledge

teal viper
#

One that should be selecting items randomly and one that maintains the list of available items?

native seal
#

digital when doing things like this do each step seperately

radiant frigate
#

i started doing each thing once at a time

native seal
#

for example in my game, item drops are rolled first by deciding if it should even drop, then deciding the amount to drop, then deciding if it should upgrade the rarity, then rolling the modifiers based on everything before

native seal
#

fixed it

radiant frigate
#

yeah i had something like that

queen yoke
radiant frigate
#

but since its not an actual shop it doesnt fit what i need

queen yoke
#

this scritp i write for +1 increment why when i hit to 3 time and hit 4th it's back to count 1

#

what im i wrong or missing?

radiant frigate
#

so i assign a price to each enemy and give money to the engine to go shopping

native seal
#

im confused as to what you want to achieve

radiant frigate
#

so it doesnt matter the combination it always has the same amount of "goldvalue"

#

to balance out each wave

#

so it wont happen that in the first round you get 4 q2 enemies and the next 2 q1

queen yoke
#

then +1 for each hit the goal

#

everything ok but when it cout 1 2 3 on hit no. 4 it count 1 again

native seal
radiant frigate
radiant frigate
#

and 2 amount of quality 1

native seal
queen yoke
native seal
#

so you want to pick a random amount of enemies that add up to 15 quality?

mint mirage
#

help, I wrote the same things in what was shown in Brackey's video but I keep getting an error

queen yoke
radiant frigate
#

q2 enemies have a 5 coins value

#

and q1 have a 1 coin value

queen yoke
#

ball hit throug many goal

native seal
#

so it could spawn 15 q1 or 3 q2 or 2 q2 5 q1

#

for example?

radiant frigate
native seal
#

just roll an amount of q2 then assign the remaining to q1

#

or roll q3, then roll q2, then assign rest to q1

#

to add up to whatever amount you want

radiant frigate
#

but when i roll q3 i dont want there to be more q3 than q2 or q1

#

so with the probability system i add that factor

native seal
#

ok then roll only up to half of the gold value

mint mirage
radiant frigate
minor patio
radiant frigate
#

but i also want there to be a possibility to be just q3 for example

native seal
#

ok then just do random rolls like i said

mint mirage
#

is that a problem?

minor patio
gaunt ice
#

you want a sum of value of coins dropped from enemy is some given number?

#

you need backtracking in this case

native seal
mint mirage
native seal
#

it needs UnityEngine only

minor patio
#

my bad - I knew it needed something

native seal
#

system is the c# library

#

monobehavior is a unity only class

radiant frigate
native seal
#

make a function then

radiant frigate
#

that does what?

native seal
#

that has a curve based on some input x

#

go on desmos to mess around, thats what I do

minor patio
#

anyone care to take a stab at why my code would be finding an object twice?

native seal
#

wdym?

minor patio
#

& no - it's not being called elsewhere

#

it's attached to a button, & it gets an object from the button's parent title field...

native seal
#

post code man

minor patio
#

where's hastebin?

radiant frigate
native seal
#

if you've done algebra in high school it should be simple to you

radiant frigate
#

but since i managed to do a system on which i have been working for 2 days i wanna take a rest and do something else like a new enemy or something like that

#

i have done algebra but the level of the school where i went was honestly shit so i didnt really learn much

native seal
#

in what way

#

that would be how you define your function

radiant frigate
#

ohhh

#

idk if there is a function for that

#

but i want there to be a possibility where all are high quality enemies,(just unlikely to happen)

#

maybe 1 quality 5 enemie and 3 q1

native seal
#

you would define your own

radiant frigate
#

yes i know but i dont know if i have the ability to do so

#

kewk

#

what is f(x) = mx + b?

native seal
#

okay well then there wont be some magical way to weight your results

radiant frigate
#

is it just a normal equation?

#

f(x) remembers me of graphs

native seal
#

it would be however you define your curve

#

yes

minor patio
native seal
#

functions can be mapped to a graph using x,y coordinates

radiant frigate
#

srry i didnt pay that much attention in math class

minor patio
#

close to

radiant frigate
#

tbh in no class

native seal
minor patio
#

ouch

radiant frigate
#

i dont know how to create functions it seems

native seal
#

for example, this is my function to determine the quantity of loot dropped

minor patio
#

now you too can create a function!

native seal
#

lol, it need to fix it though, right now enemies drop way to much loot

minor patio
radiant frigate
carmine elbow
#

is using Transform.Find() a bad habit? as it's basically hard coding and prone to failure if mistyped?

native seal
minor patio
#

how do I find the pastebin/hastebin links?

radiant frigate
#

f(x) = mb + b scared me

#

xD

native seal
#

so this is my function mapped to a graph where the x-axis corresponds to the monsters level and G is the loot bonus based on the rairty (500 is boss for example)

#

you could do something similar to weight your output based on multiple parameters

radiant frigate
#

yes but it is not directed only by two factors

native seal
radiant frigate
#

it has to include the amount of money currently the quality of the enemies the previously bought enemies and what qualities they were how much probable it is to choose 1 enemy etc etc

#

and to be honest i dont to involve myself in that now

#

since this isnt a definitive game but just a learning one

native seal
#

i dont see why it even needs to be that complex at all

#

but that would be possible

#

just use more parameters

#

in your function

#

but if you were to graph it, you would make x be whatever value you want to see on the x-axis unless you want to go into 3d planes lol

#

other parameters you can define like I did G

radiant frigate
#

you seem pretty chill

#

can i add you ?

native seal
#

sure, but no haha you would only go into higher dimensions if you want to visualize more than 1 value changing

radiant frigate
#

so ig it would be 3rd dimensional?

native seal
#

i don't think you're understanding what im saying

radiant frigate
#

it seems like im not

native seal
#

when you graph something on a 2d plane, you are visualizing the relationship between x, your input, and y, your output

#

you can define more parameters, but they would have to be defined like I did G and be changed manually

#

since any more variables would create more dimensions

#

its just for visualizing

#

nothing else

#

dont let it confuse you

radiant frigate
native seal
#

lol

#

just refer to the screenshot

radiant frigate
#

yeye ik

native seal
#

what would your parameters be and what would be your singular output

#

then think about how much you want each parameter to affect the output

radiant frigate
#

i want more than 1 output i think

native seal
#

that doesn't make sense

#

your output should be the quantity of the enemy

#

no?

radiant frigate
#

imma talk about that with a friend that graduated something related to maths so he can explain it further and for people as dumb as me

radiant frigate
native seal
#

your quality would be an input since you want to have enemies for each quality

#

then your function would take the quality and reduce the output if the quality is higher

#

in relation to your other parameters

radiant frigate
#

srry i think im dumb

#

xD

#

maybe im just not understanding it for some reason

native seal
#

you're fine but what do you mean more than one enemy per thing

#

f(enemy quality, total gold amount) -> some amount of that enemy to spawn

#

yes?

radiant frigate
#

with a lower chance of happening

#

but in case it decides to do a lot of high q enemies it will produce less since the gold can only afford that much

native seal
#

so just assign weights to each quality

#

and for each enemy spawned, loop through the weights and assign the highest enemy that rolled true

radiant frigate
#

srry but my brainpower is kinda off

native seal
#

this is my code that loops through several stat tiers and chooses the highest tier than rolled true

radiant frigate
#

i would love to understand it but i have been programming for 11 hours straight with no break for either water or food and im just completely empty rn

native seal
#

fair lol

radiant frigate
#

imma try to guess how it works tho

#

i love math

#

its fun

native seal
#

indeed

radiant frigate
#

i hated a specific part of maths but i cant remember

radiant frigate
#

be "the higuest

#

or do you have an inverted system?

native seal
#

tier 0 is the best while tier 9 is the worst

#

so it starts as the worst tier

radiant frigate
#

where quality 1/0 is the best

native seal
#

then rolls all the tiers

radiant frigate
#

ohhhhhh

#

yeah now it makes more sense