#💻┃code-beginner

1 messages · Page 209 of 1

rocky canyon
#

urs looks to start at the center..

rich adder
#

Gear:
amazn.affiliate/product

rocky canyon
#

gotta offsetem

glacial coral
#

how?

rocky canyon
#

iono, are you sure its identical to the tutorial?

#

did you perhaps miss any clicks within the editor it might have made.. etc

glacial coral
#

the only thing I've changed is the tile images. But they are 36x36, same as video.

#

I made them in photopea

carmine sierra
#

Does anyone have any pointers on how I can try and fix this

rocky canyon
#

you know what block of code is responsible for all tha?

rich adder
glacial coral
carmine sierra
rocky canyon
#

i dont get what ur issue is exactly, what is the video showing?

rich adder
carmine sierra
#

but I want it to start moving again when I go back into the range

#

if you get it

rich adder
#

use a bool then instead of OnMouseDrag which isnt releable

carmine sierra
#

so I thought it would work as im using an if statement within onmousedrag

rich adder
#

use Update

carmine sierra
#

cause i also have onmouseup and down

rocky canyon
#

ya, i would just run two functions in the update, and swap between the two w/ a boolean triggered like nav said

rich adder
#

if its in range the follows, otherwise no but its still "following"

#

until you let go

rocky canyon
#

that way, when u go back in range it'll still be updating the position as long as u havent released the mouse

carmine sierra
rocky canyon
#

nested ifs 😄

rich adder
#

isFollowingMouse/isHeldDown
isInRange

#

bam

#

done

rocky canyon
#

yup.

carmine sierra
#

dont exactly get how I could differentiate the isinrange and held down bool though

#

how would ishelddown set to true?

#

ohh okay

#

i get it now mb

rocky canyon
#

when you click onto the slingshot

#

:}

carmine sierra
#

thanks ill try it

rocky canyon
#

if its pressed then u check again if its in range to track.. else dont track

carmine sierra
#

Doesn't work

#

Same result i mean

rich adder
carmine sierra
#

and set to false using onmouseup

rich adder
#

dont use that..

#

that works on colliders still

carmine sierra
#

what do you mean?

rich adder
#

wait hold on nvm

#

Note that OnMouseUp is called even if the mouse is not over the same Collider as the mouse has been pressed down on. For button-like behavior see: OnMouseUpAsButton.

carmine sierra
#

yeah that'

#

s the intention

#

i don't need the mouse to be released on the collider

#

i think i found the issue

carmine sierra
#

YES

#

i found it

#

thanks for your help

rich adder
rocky canyon
#

i juuust got done like hardcoding this kind of behaviour

#

using a focused object and all that 🤣🤦‍♂️

rich adder
#

lol isnt this basically the Event Trigger?

rocky canyon
#

yea buts its 3d + UI objects

rich adder
#

but you can do the same with Event Trigger 😭

rocky canyon
#

i use that too

#

on other parts like the submenu

rich adder
#

ohh was just curious what the benefit was there since they both can raycast on3D cols

rocky canyon
#

like here shortly this walkie talkie should become like a 3d radial menu that also has events they fire off

#

but i went and tied in the mouse behaviour w/ the selection part of it for now

rich adder
rich adder
rocky canyon
#

i just have no reason to fire it off yet

#

im designin for mobile friendly.. so its got me all mixed up w/ inputs

carmine sierra
rocky canyon
#

i thought coding it out myself would help kinda keep me grounded

rich adder
#

yeah mobile is challenging

#

*good mobile controls

rocky canyon
#

it should be updating thruought the period it is or isnt in range

rich adder
#

yeah it was supposed to be all in the same update if statement

carmine sierra
rocky canyon
#

well do it all the time

#

if you havent released the mouse yet it should be updating

#

when u get back into range it should already know the position it needs to go to

carmine sierra
#

yeah i changed it to that and it works now

rocky canyon
#

u dont have to constantly set the position of the sling shot to the mouse position but, u should be updating it anyway since ur actively shooting the slingshot

frigid sequoia
#

Am I dumb? Like where is my knockbackValue becoming 0?

eternal needle
polar acorn
eternal needle
#

0 * 100 is still 0

cosmic dagger
#

are you passing in 0? bc that will result in 0 . . .

slender bridge
frigid sequoia
#

Am I forgetting basic math? Isn't 10/100*100= 10?

#

Is cause it is calculating it as a int?

eternal needle
#

Look at the type you are using

#

Int / int = int. Not float

frigid sequoia
#

I though it would try to cast the result to a float, since the method requieres a float

eternal needle
#

Cast 0 to a float = 0 still

#

Its not like it remembers that there was a 0.1

slender bridge
#

totalDamageTaken / 100f * DamageToKnockBackblahblahblah

cosmic dagger
#

totalDamageTaken or 100 need to be a float. the integer division will result in 0 . . .

eternal needle
#

When you debug in the future, remember to log the entire calculation instead of just one part. No need to assume what the values are, because of cases like this

frigid sequoia
#

So... just one of the elements been declared as a float will result on a float as output?

slender bridge
#

test it yourself

cosmic dagger
umbral marsh
#

is object pooling straight up better than invoke/destroy? are there scenarios where it's not worth?

rich adder
#

I think you mean Instantiate

umbral marsh
#

oh yes that

cosmic dagger
umbral marsh
#

cool thx

eternal needle
#

Like a rigidbody projectile for example, if you just add it to a pool then now you have to make sure it doesnt have any velocity/torque from a previous usage.

umbral marsh
#

that is exactly what im doing 😵‍💫

rich adder
#

its worth the extra legwork imo

#

same as writing the physics functions with nonalloc vs the regular ones

limpid wren
#

I'm making some scriptable objects and was wondering if there was a way to add stuff to the inspector like dividers or sections

rich adder
teal viper
#

Or a custom editor/inspector.

rich adder
#

def for dividers n stuff yeah

limpid wren
#

Custom inspector may be a bit much, I just want to be able to split the attributes by category

rich adder
dire tartan
#

if i have a camera and i want it to follow the player but only to rotate on the x axis how would i do that?

wintry quarry
#

Or better yet use Cinemachine

dire tartan
#

my mistake i meant a security camera object

#

i want the x and y to stay the same but it should only rotate on the z axis

wintry quarry
dire tartan
#

the way its setup is a bit odd

#

but the little half sphere rotates and the camera folllows it

copper perch
#

So, I have come pretty far in the last few days.
I have found all the scripts responsible for the firing the:

  1. Weapon.
  2. UIManager.
  3. PlayerManager.
  4. WeaponSwitcher.
    I added comments in the UI manager, Weapon switcher, Weapon, and Player Manager scripts to learn it better.
    I organized the UIManager script.
frosty hound
brisk escarp
#

i think this is the right spot to ask this question but anyone know why i have the following error, I have been following a yt tutorial and i cant understand this,,, error CS0246: The type or namespace name 'InventoryItem' could not be found (are you missing a using directive or an assembly reference?)

frosty hound
#

You have no type InventoryItem

#

Likely didn't follow the part in the tutorial where they made it.

brisk escarp
#

i have it in the hyrachy

#

hierarchy

frosty hound
#

That's irrelevant. Types are made with code.

brisk escarp
#

this is the script the yt vid had

north kiln
#

!ide

eternal falconBOT
brisk escarp
#

i have that already

#

and this is the yt script

north kiln
#

Your ide is not configured

craggy oxide
#

public GameObject player;
public TextMeshProUGUI coinsText;
private int coinAmount = 0;
private int maxCoins = 7;

    // Update is called once per frame
    void OnCollisionEnter(Collision collision) 
    {
    if (collision.gameObject == player)
    {
    Destroy(gameObject);
    coinAmount += 1;
    coinsText.SetText("Coins:" + coinAmount + "/" + maxCoins);
    }
    
    }

So my logic for collecting coins has an obvious bug.

The script is applied to multiple separate coins so the coin amount reverts to 0 every time the script is triggered, meaning that instead of saying "1/7 coins, 2/7 coins, etc.." it says "1/7 coins, 1/7 coins, 1/7 coins"

How do I rewrite this to fix this bug?

solemn summit
#

The coin amount should be stored elsewhere, not on each coin

brisk escarp
minor patio
#

yeah coin amount would need to be a player asset

craggy oxide
north kiln
#

Until your IDE underlines errors in red and gives full autocomplete it remains unconfigured

harsh sandal
#

Ngl im in the same boat as him with the IDE, i got the unity package in VS, i set VS in unity, i got VS package installed and updated and still dont got that

#

the web pages dont say to do anything more so im stumped on it myself, been just using the C# language mode as a substitute

minor patio
#

some kind of problem: I've got 8 features each with an increment button to raise its score from a pool of featureXP. Problem being if the total amount of featureXP is enough the increment happens successive times until featureXP is no longer enough to raise a feature's score. Method for comedic effect:
https://i.imgur.com/3rSzXx6.png

#

Curious if anyone can suggest an edit so that featureXP usage is limited to once per button-mash

solemn summit
#

!code

eternal falconBOT
solemn summit
#

Where are you calling IncreaseAmbition?

minor patio
craggy oxide
#

// In Player Script

public int coinAmount = 0;

// In Coin Script

private PlayerController playerController;
public GameObject player;
public TextMeshProUGUI coinsText;
private int maxCoins = 7;

 void OnCollisionEnter(Collision collision) 
    {
    int coinAmount = playerController.coinAmount;

    if (collision.gameObject == player)
    {
    Destroy(gameObject);
    coinAmount += 1;
    coinsText.SetText("Coins:" + coinAmount + "/" + maxCoins);
    }
    
    }

int coinAmount = playerController.coinAmount - "Object reference not set to instance of an object"
How do I fix this?

minor patio
#

...but that's not the issue
the issue is my pool of featureXP is being exhausted instead of stepping the score once

winged raft
solemn summit
winged raft
#

I presume it's attached to your "player" gameobject so just get it off of that in void Start()

#
playerController = player.GetComponent<PlayerController>(); 
craggy oxide
#

ooh alr
for some reason VS Code didn't pick up on the error to begin with so I thought it just automatically got it

#

thanks

minor patio
#

never assume anything is automatic in coding, Rhys atwhatcost

solemn summit
minor patio
#

the code looks fine, indeed; but when the solution is running I get an artifact where if I raise a score of 4 it jumps to 6 - it depends on the total amound of featureXP available from character selections

#

I get the impression its because the if statement encompassing the body of code is technically in effect until rep.featureXP is no longer enough to afford another increment of the score

polar acorn
modern rover
potent nymph
#

in hlsl (or for compute shaders in general), I'm having trouble understanding the usage of the X and Y threads
The default code for a compute shader is as follows:

[numthreads(8,8,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
    // TODO: insert actual code here!

    Result[id.xy] = float4(id.x & id.y, (id.x & 15)/15.0, (id.y & 15)/15.0, 0.0);
}
#

I'm assuming Result is the array for the texture, but why is "id.xy" used?

#

Most articles online use only the X thread for simplicity but I can't wrap my head around using X and Y

rich adder
#

why are you replying to someone in an unrelated conversation 🤔

lavish gate
#

I have 12 prefabs in my scene that all have the same script attached to them (somewhat irrelevant). I have an event in the script that tells the scene managers and what not that the game is over. but you cannot have a prefab reference something in the scene, whats a good way around this?

summer stump
#

See the singleton page here

rigid valve
rich adder
summer stump
rigid valve
rigid valve
#

like a cart

summer stump
#

Consider making the box kinematic

rigid valve
#

no I want the box to move plyer

summer stump
rigid valve
#

still its having shackky movements and also its not carrying the player when I am standing

#

it drops the player

summer stump
#

Yes, kinematic will help resolve that

#

Kinematic meaning it does not react to forces (like the players gravity when on top and mass when blocking it)

#

You can't use velocity though, after changing it

languid spire
#

Did you parent the player to the box?

summer stump
rigid valve
rigid valve
languid spire
#

might be best to use a parent constraint which you can enable/disable

languid spire
# rigid valve nope

if you want to move the box and have the player move with it they will need some kind of relationship

rigid valve
#

having friction wont work?

languid spire
#

no

summer stump
rigid valve
#

I have attached the code

summer stump
rigid valve
#

can u pls ellaborate 😶 its my first game

summer stump
#

MovePosition()

rigid valve
#

what should I replace that with?

rigid valve
rigid valve
rich adder
#

keep in mind that parenting will work but the player should also kinematic when on the platform

rigid valve
#

should I parent it from hierchy or the code???

languid spire
#

in the code, then unparent when the player leaves the box

rigid valve
#

but if i parent the box will player be able to move freely on the box thinkies

languid spire
#

yes

rigid valve
#

let me try this rq

languid spire
#

then you use localposition to move the player

rigid valve
#

i will write all this in box script right? not the player

languid spire
#

no, player script

rigid valve
languid spire
#

well the player knows when he lands on/gets off the box right?

rigid valve
#

no I have raycast only yo check if the player is grounded

languid spire
#

so you need to add that first

rigid valve
#

here i just need to add layermask to check if we are on box right?

rich adder
#

no you would need to distinguish you're somehow even on the box

languid spire
#

if your box has a collider why not use OnCollisionEnter

rich adder
#

same issue

#

they still need a way to detect it is actually a moving box to parent to

lavish gate
rich adder
rigid valve
languid spire
rich adder
#

ray is best bet ,esp if you want accurate way to detect when off

lavish gate
languid spire
rigid valve
#

why this simple mech is so confusing lol 😭

rich adder
#

i told you earlier too lookup this whole process

#

you stil need to turn player to kinematic when on platform, otherwise parenting wont keep dynamic from getting twitched off

languid spire
rigid valve
#

🤔

rich adder
#

no one said you can't you just dont have a Raycast hit param
How would the raycast know you wanted moving platform instead of ground without raycasthit

languid spire
#

because you have different outcomes depending on what you have hit, your code will be a mess

rigid valve
rich adder
#

or prob easier to make a another ray that only checks moving plats layer

rich adder
#

you still need to check collider with a tag or something
eg
if(raycast.collider.CompareTag("movingplat"))

lavish gate
#

Apex keep doing what you are doing right now but in future id recommend making a flow chart of how you want your code to run, i made this earlier because i wanted to write a losing method with a countdown for my game.

lavish gate
#

@summer stump Have already used what your solution to my problem was earlier, thanks though i forgot about singletons

static bay
#

interesting low number comparison there

lavish gate
#

Yeah id assume you could always just do hit.distance != 0f

tight zenith
lavish gate
#

Do you have everything installed properly?

fierce sonnet
tight zenith
rigid valve
tight zenith
potent nymph
#

I have a simple compute shader where all it does is assign the X thread id to an int array (basically just incrementing a number)

#pragma kernel CSMain

struct IncrementTest 
{
    int number;
};

RWStructuredBuffer<IncrementTest> increment;

[numthreads(10,1,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
    IncrementTest num = increment[id.x];
    num = id.x;
    increment[id.x] = num;
}
ivory bobcat
potent nymph
#

however I'm getting an error that Kernel at index (0) is invalid

potent nymph
#

here's the c# code

  private void CubeGrid()
    {
        IncrementTest[] data = new IncrementTest[100];

        int size = sizeof(int);
        ComputeBuffer testBuffer = new ComputeBuffer(data.Length, size);
        testBuffer.SetData(data);
        int kernelID = computeShader.FindKernel("CSMain");
        computeShader.SetBuffer(kernelID, "increment", testBuffer);
        computeShader.Dispatch(kernelID, data.Length / 10, 1, 1);

        testBuffer.GetData(data);
        for (int i = 0; i < data.Length; i++)
        {
            Debug.Log(data[i].number);
        }
        testBuffer.Dispose();
    }

#

but it's not a shader though

#

and it's more of a beginner question

lavish gate
#

It literally is a shader though

tight zenith
#

Does anyone know what's wrong here? I have everything installed as can see.

Error when compiling is attached as a TXT file

potent nymph
lavish gate
#

If kernel at index 0 is invalid it means there is an error with your shader code

potent nymph
#

anyways, I can repost the question in the other channels

lavish gate
#

HLSL

tight zenith
#

I dont have a shader?

lavish gate
#

talking to mookorea mayne

tight zenith
#

ohh i see

#

alr

ivory bobcat
tight zenith
#

Alright thanks

potent nymph
potent nymph
rigid valve
#

am I making anymistaker here in unparenting the player

potent nymph
#

ah, I figured out my problem

#

"num" is a struct, and I was trying to assign id.x (int) to it when I should be assigning it to num.number

gaunt stone
#

Hi, i tried importing a project which my friend made to my computer, i installed his asset folder into mine, but on running the project it gives me some error

#

the referenced script it is talking about does exist in the folder however

ivory bobcat
#

And where does the prefab reside?

gaunt stone
#

grid?

#

its in the hierarchy

tight zenith
#

Hi

#

How do I install specifically the Android SDK Platform 33?

fierce sonnet
#

hi, i am currently programming a evolution simulation and i have problems with the field of view always outputing angle = 0 even though the direction changes. I have print multiple values and aslo tried Vector3.Angle and inputting vector 2 to vector2.angle or vector 3 to vector2.Angle.

        bool IsWithinAngleOfView(Vector2 position)
        {
            Vector2 direction = position - new Vector2(transform.position.x, transform.position.y);
            float angle = Vector2.Angle(direction, transform.forward);
            return Mathf.Abs(angle) <= angleOfSight / 2;
        }```
ivory bobcat
#

This isn't really a coding question but seeing your asset folder structure would be necessary as it's related to your importing of another project.

gaunt stone
gaunt stone
#

in the screenshot

gaunt stone
languid spire
rigid valve
gaunt stone
#

he sent a zip file of his asset folder

noble summit
#

how do you share a unity project

languid spire
gaunt stone
#

let me do that

#

also, will the changes made by me, inflict his code as well

languid spire
#

no

gaunt stone
#

or will it be branched for me

#

oh ok

#

thanks

languid spire
rigid valve
#

._.

languid spire
#

from box to ground?

#

is hit.collider ever null?

rigid valve
#

its working nowwwww

#

I placed else outside the brackets lol

warm depot
#

is there a way to reference all objects that share the same name? Instantiated objects included?

glacial forge
#

are there any good resources or tools for 2D world generation? I have a good perlin noise function to get a height map which I can use to chose terrain type(biome generation), but I dont know how to populate a tile map with a script based on that perlin noise

for context I am making a game similar in style to factorio, so i am using a tilemap system

A future issue is also world wrapping I would like the game to wrap like sid meier's civilization, and im not sure how to go about that, I believe there are 2 schools of though. either duplicate camera but then objects passing over the border create an interesting challenge, or the load the world in chunks and move one chunk from the other end and then they step on that teleport the player. but this is a future problem I can solve but any useful links would be cool

bright oxide
#

does anyone know why it results in a null?

languid spire
bright oxide
#

What part of it

#

if you mean the format of the path, i tried the one in the documentation and it does not work

minor patio
#

any versed in conditional if statements? I have a method that increments a score by reducing a featureXP pool, but if the pool is large enough to increment more than once it does so:
https://i.imgur.com/McDWGfr.png
I'm trying to get an increment of 1 per button mash - no more, no less

#

oops

languid spire
fierce sonnet
bright oxide
languid spire
gaunt ice
earnest atlas
#

Spent a lot of time trying to understand why my object wasnt rotating properly....

I was using wrong axys rotation

sleek notch
#

What does it means? I Have reference to a GameObject that have to on start not active but if I set it into Start() or even into Awake it won't be functional. But if I .SetActive on a button it works normally

lavish gate
#

Do you have a scene set

earnest atlas
#

omg so much find

lavish gate
languid spire
sleek notch
lavish gate
minor patio
bright oxide
#

what is path even

sleek notch
#

I used all of it in Start() but it have same problem

lavish gate
languid spire
lavish gate
sleek notch
languid spire
#

so settingsMenuOne is null

minor patio
sleek notch
#

In this

lavish gate
minor patio
#

UI button with script attached

lavish gate
#

Also, no.1 Dont use gameobject.find

sleek notch
gaunt ice
#

do you know you can drag and drop the reference?
ofc your field needed to be serialized

lavish gate
sleek notch
lavish gate
#

Did you set them in the inspector?

minor patio
#

it's supposed to be once, but if featureXP is enough it will do it two, even three times

sleek notch
#

I did

languid spire
lavish gate
#

nvm oops

sleek notch
languid spire
#

trying to setActive before you actually Find it ain't gonna work is it?

sleek notch
#

I have no idea what is wrong

teal viper
sleek notch
#

I'll send video

languid spire
#

and post your full !code to a paste site

eternal falconBOT
sleek notch
ivory bobcat
#

Assuming transform position and position are the same

#

There's not enough info

vernal plume
#

oh caps

sleek notch
minor patio
# fierce sonnet pls someone 😅😭

Vector2 direction = position - new Vector2(transform.position.x, transform.position.y);
are you sure this is right? kinda looks like it needs to be a Vector2 position, not direction....

sleek notch
#

And also horizontal have to have H and vertical V

hallow adder
# fierce sonnet pls someone 😅😭

your angle calculation is probably wrong. Use transform.up instead. Assuming transform is something 2D like a sprite, you're probably getting (0, 0, 1) in the forward dir which gets implicitly converted to (0, 0) in Vector2.Angle, and if either of the inputs to Vector2.Angle has a very small magnitude it returns 0

#
  • or Vector2.right, it depends on how you've oriented your sprites. Whatever their forward dir would be
thorn kiln
#
    public Rigidbody2D myRigidbody;
    public CircleCollider2D myCricleCollider;
    public float flapStrength;
    public LogicScript logic;
    public bool birdIsAlive = true;
    public GameObject gameOverScreen;```So, with this stuff, how do you determine what the... I wanted to say "green text", but apparently discords code formatting doesn't colour it like visual studio. Anyway, how do you determine when to use stuff like Rigidbody2D, CircleCollider2D, LogicScript, etc should be. I know they're components on the object, but can you not use the transform properties when you just reference it as a game object?
lavish gate
#

How can I tell if an object is fully inside a trigger?

stone lance
#

One way is to do some math and the origin of the object

sleek notch
graceful spruce
#

Guys, how can I keep the points saved after I restart a scene

languid spire
graceful spruce
#
    {
        DontDestroyOnLoad(gameObject);
    }```
#

should it be in a Awake class?

languid spire
#

is that a joke?

graceful spruce
#

no

languid spire
#

you need to read about the Singleton pattern

native seal
#

can anyone point me in the right direction to achieve something like this? I want loot labels to respect other labels and find a spot on the screen if they are going to overlap

earnest atlas
#

what in the unholy UI that?

tepid summit
#

no clue'

#

it looks like they threw 14 games into a blender and poured whatever slurry came out onto their screen

earnest atlas
#

looks like these objects have some sort of collision logic

#

bye bye screen XD

tepid summit
#

thats what im sayin

low path
#

It’s path of exile man…. Items on screen are shown in text when you press a button… and there are a lot of items.

tepid summit
#

" a lot"

#

you mean a metric fuckton?

low path
#

Yeah PoE is known for uh… visual excess…

tepid summit
#

"excess"

#

bruh i need a 82372'' monitor just to see 3 pixels of game

low path
#

Tbf you generally filter out items by rarity … this is an extreme example…

tepid summit
#

"mildly extreme"

low path
#

Anyway they just wanted to know how to have labels show up in screen in a non overlapping manner in relation to screen position of objects they are labeling. I can’t think of a quick and easy way to do this in Unity so I’m sure it’s a custom algorithm they rolled…. I’m not sure this is a “code beginner” question.

languid spire
north kiln
#

I feel like you'd do some force directed graph or something

tepid summit
#

triggers dont work on ui elements do they?

north kiln
languid spire
#

flex box should handle this situation automatically

tepid summit
north kiln
graceful spruce
#

hey, so I added a DDOL on a canvas which keps track of the points however they are duplicating and the points are overlapping, is there a way to remove the one before it

tepid summit
#

destroy

#

or

#

insead of amking multiple canvases'

#

update a text object

graceful spruce
#

ok I'll try it

#

Thank you @tepid summit

tepid summit
#

all g @graceful spruce

languid spire
graceful spruce
#

ok I got it now

graceful spruce
#

This becomes missing

#
{
    private static GameManager instance;
    void Awake()
    {
        if (instance != null)
        {
            Destroy(gameObject);
        }
        else
        {
            instance = this;
            DontDestroyOnLoad(transform.gameObject);
        }

    }
}```
graceful spruce
languid spire
#

presumably that is a scene reference so you would need to do dependency injection on OnSceneLoaded

graceful spruce
vast vessel
#

how can i instantiate a game object, inside of another game object so that the game object im instantiating, dosnt penetrate out of the object im instantiating it inside of, using renderer bounds/extents?

im trying to get the effect of ammuntion and supplies dropping out of a box when it breaks.
i know how to get my object's pivot/origin inside of the box, but that will have the object penetrate the box's mesh, which i dont want.

graceful spruce
languid spire
agile hornet
#

Hello, so I created a player controller. I want it move and jump on input keys, and it works fine. But after jumping and the player lands on ground the player moves on its own without me pressing any button.

#
public class PlayerController : MonoBehaviour
{
    private float horizontalInput;
    private float forwardInput;
    public float speed = 10f;
    public float jumpForce = 7.5f;
    private Rigidbody PlayerRb;
    public bool onGround = true;
    
    // Start is called before the first frame update
    void Start()
    {     
        PlayerRb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        horizontalInput = Input.GetAxis("Horizontal");
        forwardInput = Input.GetAxis("Vertical");
        

        if(Input.GetKeyDown(KeyCode.Space) && onGround == true)
        {         
            Vector3 jumpDirection = (Vector3.right*Time.deltaTime*horizontalInput + Vector3.forward*Time.deltaTime*forwardInput).normalized;
            PlayerRb.AddForce((Vector3.up + jumpDirection)*jumpForce, ForceMode.Impulse);
            onGround = false;
        }

        if(onGround == true)
        {
            transform.Translate(Vector3.right*Time.deltaTime*speed*horizontalInput);
            transform.Translate(Vector3.forward*Time.deltaTime*speed*forwardInput);       
            PlayerRb.velocity = Vector3.zero;
        }
    }
    private void OnCollisionEnter(Collision collision)
    {
        if(collision.gameObject.tag == "Ground")
        {
            onGround = true;          
        }
        
    }

}

graceful spruce
#

I searched "dependency injection on onsceneloaded" as per your request and so much detailed and complex stuff came up

timber tide
#

Your problem is you're not logging your code. Get used to using Debug.Log or using breakpoints to figure out your logical problems. If you're still having problems, minimize to where it may be and post again.

eternal falconBOT
agile hornet
# vast vessel !code
public class PlayerController : MonoBehaviour
{
    private float horizontalInput;
    private float forwardInput;
    public float speed = 10f;
    public float jumpForce = 7.5f;
    private Rigidbody PlayerRb;
    public bool onGround = true;
    
    // Start is called before the first frame update
    void Start()
    {     
        PlayerRb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        horizontalInput = Input.GetAxis("Horizontal");
        forwardInput = Input.GetAxis("Vertical");
        

        if(Input.GetKeyDown(KeyCode.Space) && onGround == true)
        {         
            Vector3 jumpDirection = (Vector3.right*Time.deltaTime*horizontalInput + Vector3.forward*Time.deltaTime*forwardInput).normalized;
            PlayerRb.AddForce((Vector3.up + jumpDirection)*jumpForce, ForceMode.Impulse);
            onGround = false;
        }

        if(onGround == true)
        {
            transform.Translate(Vector3.right*Time.deltaTime*speed*horizontalInput);
            transform.Translate(Vector3.forward*Time.deltaTime*speed*forwardInput);       
            PlayerRb.velocity = Vector3.zero;
        }
    }
    private void OnCollisionEnter(Collision collision)
    {
        if(collision.gameObject.tag == "Ground")
        {
            onGround = true;          
        }
        
    }

}
agile hornet
# languid spire And this code does what?

Hello, so I created a player controller. I want it move and jump on input keys, and it works fine. But after jumping and the player lands on ground the player moves on its own without me pressing any button.

wintry quarry
raven hill
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerProjectile : MonoBehaviour
{
    [SerializeField] private Rigidbody2D MyRigid;
    private Vector3 target;

    // Start is called before the first frame update
    void Start()
    {
        target=Input.mousePosition; 
        var heading=target - transform.position;
        var distance = heading.magnitude;
        var direction = heading / distance;
        MyRigid.AddForce(direction, ForceMode2D.Impulse);
    }

    void OnTriggerEnter2D(Collider2D col)
    {
        Destroy(gameObject);
    }
}```

```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerThrowing : MonoBehaviour
{
    [SerializeField] private GameObject MP;
    private bool canThrow = true;
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Mouse1)&&canThrow)
        {
            Instantiate(MP, transform.position, Quaternion.identity);
            canThrow=false;
            StartCoroutine(DelayThrowing());
        }
    }

    IEnumerator DelayThrowing()
    {
        yield return new WaitForSeconds(1.2f);

        canThrow=true;
    }
}```

Does anyone know why the throwing direction is automatically clamped to throw forward?
agile hornet
vast vessel
#

why dont you debug it first

#

like debug your inputs

#

or take a look at your players rb velocity

#

it could be anything

agile hornet
languid spire
agile hornet
languid spire
vast vessel
#

also check if onGround is indeed being set to true, when you fall back to the ground. you might have not tagged your ground gameobject, collisions not being registered and ....

mortal bridge
#

my question is why collision with ground onground true is at the last lines

vast vessel
vast vessel
agile hornet
mortal bridge
#

Yes

#

wait

#

you see something in update?

#

PlayerRb.velocity = Vector3.zero;

agile hornet
mortal bridge
#

@agile hornetPlayerRb.velocity = Vector3.zero;

vast vessel
mortal bridge
#

players velocity is set to 0 each fps ground on ground is true

vast vessel
#

go watch a charachter controller tutorial or something lmao

mortal bridge
agile hornet
mortal bridge
#

it will jump in the faced direction

mortal bridge
#

are you sure your scene view is not upside down

agile hornet
tepid summit
agile hornet
mortal bridge
#

like the perspective you are watching

#

or camera idk

tepid summit
#

if it is..,

vast vessel
#

i want it to be completley inside

#

covered

tepid summit
#

make the casing not hae a collider

agile hornet
agile hornet
mortal bridge
# agile hornet Exactly.

yeah bro actually kinda stupid people tell you to go take courses or watch tutorials in these kinds of situations

#

I see what you tryna do

vast vessel
# tepid summit make the casing not hae a collider

you are not getting what im saying..... okay look, we have the extents property of two mesh renderers. how do i position the game object of one of the mesh renderers, so it is completely inside the extents, of the other objects mesh renderer

tepid summit
#

i dk

agile hornet
mortal bridge
#

adding forces

vast vessel
agile hornet
#

Creating a playercontroller.

tepid summit
#

they probably do know'

vast vessel
#

also i recommend NOT watching brackeys

agile hornet
tepid summit
tepid summit
fierce sonnet
mortal bridge
#

pshyics engine be confused with velocity setting to 0 each frame

mortal bridge
vast vessel
earnest atlas
carmine sierra
tepid summit
#

no yt tutorial

#

genuinely

mortal bridge
#

Yt tutorials suck

tepid summit
earnest atlas
carmine sierra
tepid summit
vast vessel
mortal bridge
# tepid summit A good amount

yep. and let me tell you that if its a popular one it suckest the most. 5-10 views is good enough for it to be good

carmine sierra
raven hill
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerProjectile : MonoBehaviour
{
    [SerializeField] private Rigidbody2D MyRigid;
    private Vector3 target;
    private Vector3 ScreenPos;

    // Start is called before the first frame update
    void Start()
    {
        ScreenPos=Input.mousePosition;

        target = Camera.main.ScreenToWorldPoint(ScreenPos);

        /*var heading=target - transform.position;
        var distance = heading.magnitude;
        var direction = heading / distance;*/
        MyRigid.AddForce(target, ForceMode2D.Impulse);
    }

    void OnTriggerEnter2D(Collider2D col)
    {
        Destroy(gameObject);
    }
}```

So this works, but it's just slightly off. Does anyone know ho I could fix it?
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerThrowing : MonoBehaviour
{
    [SerializeField] private GameObject MP;
    private bool canThrow = true;
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Mouse1)&&canThrow)
        {
            Instantiate(MP, transform.position, Quaternion.identity);
            canThrow=false;
            StartCoroutine(DelayThrowing());
        }
    }

    IEnumerator DelayThrowing()
    {
        yield return new WaitForSeconds(1.2f);

        canThrow=true;
    }
}```

This is where I instantiate the projectile
tepid summit
#

mess with the instantiate inputs

timber tide
#

I'm not understanding your direction

languid spire
timber tide
#

It's just a point here, no?

carmine sierra
languid spire
carmine sierra
languid spire
#

considering you do not specify what 'this' actually is, how could I know?

carmine sierra
#

this is clipping

timber tide
#

sorting layer

languid spire
#

wtf is 'this'?

carmine sierra
#

the cannonball is teleporting the mouse and clips into the ground

raven hill
carmine sierra
#

but okay il check out sorting layer

languid spire
carmine sierra
carmine sierra
languid spire
#

that says this not what this is

gaunt ice
carmine sierra
languid spire
#

still did not specify what this is

carmine sierra
#

clipping?

#

is that not the right terminology

languid spire
#

what is clipping

carmine sierra
#

when two objects overlap when they shouldnt

#

is it not?

languid spire
#

which objects are clipping

carmine sierra
#

the cannonball and ground

#

its in the video

languid spire
#

then wtf did you not say that?

carmine sierra
#

im confused lol

languid spire
#

you cannot just say 'this' and expect us to know what this is, you have to be specific

carmine sierra
#

are you confused or is it me

languid spire
#

I'm not confused, you need to ask questions better

carmine sierra
languid spire
#

because only you knows what you mean by this

carmine sierra
#

I gave the cannonball and ground the same sorting layer but they still clip

modest dust
#

I guess what you really want is to make the ball not go "into" the ground area, i.e. stop at it's surface?

tepid summit
#

make the ball 1 more

modest dust
#

Then say so for the love of god

carmine sierra
tepid summit
#

set ball to 1 and ground to 0

carmine sierra
#

preventing it

modest dust
#

Setting the sorting layer will only make it render above the ground

carmine sierra
carmine sierra
ivory bobcat
modest dust
#

To prevent the ball to actually go into the ground either use colliders and move the ball to the mouse pos using physics or make your own custom stuff

languid spire
#

Did you set the correct Order in Layer for both objects?

carmine sierra
#

but cause its following the mouse i don't think the layers will change anything?

ivory bobcat
#

I think he said the drag operation doesn't use physics until the ball is launched - he's teleporting the ball.

modest dust
#

So either that or physics

carmine sierra
modest dust
#

physics

#

or custom code

#

as I said

carmine sierra
#

I know I could use something to do with the y coordinates, but I will have different weapons

modest dust
#

Then physics or a bunch of custom code

carmine sierra
languid spire
#

Colliders, Rigidbodies

modest dust
#

Set the colliders correctly and apply force / change velocity so that it goes towards the mouse

#

Physics will prevent the ball from going into the ground

carmine sierra
modest dust
#

Yes

#

As I stated multiple times

languid spire
#

do not use translate, use rigidbody moveposition

modest dust
#

Or custom code

carmine sierra
languid spire
#

no

ivory bobcat
#

Either that or raycast towards the mouse and stop the ball/string intermediately

carmine sierra
#

whe nthe ball touches?

ivory bobcat
#

How would I know?

#

When you're detecting the position of the mouse

carmine sierra
#

is there any built in functions which can tell when two objects are touching

#

like is touching or something

ivory bobcat
#

Sure physics

mortal bridge
carmine sierra
timber tide
#

just clamp the position for where it will read mouse position

#

the y value

mortal bridge
trail heart
#

I recommend clamping by distance or by position as well (or both)
No need for colliders when you can always predict where the object's motion should stop

#

Colliders don't work smoothly anyway for any non-physically moved objects

mortal bridge
#

yeah theres that

#

ooh so you are the angry bird guy

#

I remembr

#

yeah what spazi and mao says makes more sense in this context

ivory bobcat
trail heart
mortal bridge
#

fixed

wind raptor
#

Just starting to wrap my head around events. I've only used references up to this point. Is there a way to invoke a unity event with a parameter?

scenic saffron
#

i made a player movment script but it has 2 issius

  1. if i dont move exactly in one direction (e. g. y=70°) i go faster

  2. if i hold down space my second jump is a little bit higher

scenic saffron
raven hill
#

lol

#

use 3 `

#

before and after the code

mortal bridge
#

@scenic saffronhey man just share it in one of these sites !code

eternal falconBOT
mortal bridge
#

Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:

// Your code here
scenic saffron
mortal bridge
#

Movment nice

#

well diagnal movement is usually faster in games because of mathematics

scenic saffron
#

i thought its only when i press to movment keys at the same time like a+w

mortal bridge
#

I worked in 2d games its a common issue in 2ds we used to fix it by claming 1.4 to 1

#

and normalize in unity I am guessing

mortal bridge
scenic saffron
#

i have a timer

mortal bridge
#

or increaesee cooldown

scenic saffron
#

my first jump is fine then it goes up by a little bit and then it stays at that value

mortal bridge
#

I have this works fine for me

cosmic dagger
graceful spruce
#

I have a canvas where I added a dont destroy on load script, inside the canvas there’s 2 texts and those are assigned to the player 1 and player 2 when object collide with them they lose a point and the other player gets a point. However, when I load another round/scene it says that the text object has been destroyed and im accessing it. How can I fix that?

wintry quarry
earnest atlas
#

is there a way to create DDOL object from prefab?

wintry quarry
#

The best way though would be for the text objects to listen to events / read data from your Singleton instead of the other way around

graceful spruce
#

When I add DDOL script to the text it says “cant add them it has to be root game object”

scenic saffron
wintry quarry
mortal bridge
languid spire
mortal bridge
#

normalized at the end

#

().normalized

languid spire
cosmic dagger
# scenic saffron isent it allredy normelized?

yes, it is, but why are you multiplying by movementspeed and 10? also, is this method called in Update, because you're using the default force mode which applies force over time . . .

scenic saffron
mortal bridge
#

😮

cosmic dagger
# scenic saffron

movementspeed is a float, right? it doesn't have a normalized property . . .

mortal bridge
#

is it movementspeed. ?

scenic saffron
#

my movment vector (moveDirektion) is normelized

mortal bridge
#

it doesnt run in update guy sent his code

carmine sierra
#

when setting a variable does the collider data type accept any kind of collider

scenic saffron
nova shore
#

trying to make a script where pressing a key will make it so that a cube will spawn in front of player

im using transform.forward and after a lot, ive found that transform.forward vector runs from the origin to the point that is 1 unit from the player head.
(tell me if im wrong)
why doesnt it start from the player head instead of the origin?

mortal bridge
#

good for pshyics

carmine sierra
#

If (otherCollider == weaponCollider) --> I am trying to make it so that code only accepts the collider of weaponCollider

cosmic dagger
carmine sierra
languid spire
scenic saffron
#

i guess i will leve the extra speed in the game for speedruners to expliot

#

but what about the jumping

languid spire
cosmic dagger
carmine sierra
nova shore
# cosmic dagger `transform.forward` is the z axis of the GameObject's transform. you need to add...

mate i know how to control its magnitude

the problem is that it doesnt exactly give me/convert the local forward point to world space

whats happening is
whenever i try spawning the cube and set its position to transform.forward * 10, the cube spawns 10 units away from origin and in the direction that player is looking
i want it to spawn 10 units away from player and in the direction that player is looking

nova shore
carmine sierra
#

nvm it shouldn't be 0 right

cosmic dagger
nova shore
#

lemme just sketch a diagram, it might help u understand

cosmic dagger
nova shore
cosmic dagger
#

you said you're trying to spawn the cube in front of the player, but where (what position) do you actually spawn it at? show code . . .

tepid summit
cosmic dagger
#

why the attitude? good luck then . . .

languid spire
nova shore
#

the cube should spawn at (x,y,z)
but its spawning at (x1,y1,z1)
i labelled the x1,y1,z1 as transform.forward cus when i log it thats what it prints

nova shore
vast vessel
nova shore
# tepid summit can you show me youe script?
                Debug.Log(transform.forward * 2.1f);
                Debug.Log(transform.position);
                //hum.SetState(Humanoid.States.ATTACKING);
                //Vector3 forwardDir = transform.forward - transform.position.normalized;
                GameObject clone = Instantiate(cube, transform.forward, Quaternion.Euler(0,0,0));
                clone.transform.localScale = new Vector3(1, 1, 1);
                clone.transform.position = transform.forward * 20; //tried setting the position so that it would appear in front of player
                Destroy(clone, 1);
               
//irrelevant to the issue but kept it 
 Collider[] Targets =  bc.ReturnTargetsInBox((transform.forward * 2.1f),new Vector3(1,1,1));
                Debug.Log(Targets.Length);
tepid summit
#

@cosmic dagger heres your code to look at'

short hazel
#

Yeah transform.forward is a direction, not a position. If you need it to be offset 1 unit forward according to the current position then you need transform.position + transform.forward

nova shore
tepid summit
#

he does

#

you just had an attitude to him

nova shore
icy fossil
#

Hey guys, i'm pretty new to coding and idk if this question is more fitting in #⚛️┃physics but i've encountered a weird bug
Basically my Character can move trough walls, but only if i do not see the scene view. What i mean is that, when i have both the scene view and game view open everything is fine and the wall blocks the player. But when i only look at the game view he can suddenly move through them as if they were air
Any help is greatly appreciated

nova shore
short hazel
#

The position is not at the origin

nova shore
nova shore
#

my dumbass

#

@short hazel ty fam

nova shore
short hazel
#

What?

tepid summit
#

incorrect

short hazel
#

The forward direction is transform.forward, nothing else

nova shore
short hazel
#

Here you're computing a direction from a position and a direction, that's not right

#

A direction can only be determined from two positions when doing a subtraction

cosmic dagger
# nova shore dont think he gonna come back. he doesnt even understand the scenario to help me...

Your scenario is easy. Spawn at position of the object you want to be in front of, then multiply by how many units away

We can't tell where you're originally spawning the cube without code (that's why I asked)

Now with the actual code, your issue is that you're using transform.forward as the position which is incorrect as that is a direction

Very easy to help and debug but you didn't understand the situation . . .

nova shore
#

"Forward Vector from Player"

#

eh forget it, its working

#

bad at naming stuff

short hazel
#

I don't really know how, but as long as it works

nova shore
icy fossil
hardy heart
#

Hello! I am a new unity designer and I just watched GMTK's beginner flappy bird tutorial. I am trying to make sure that you can't get more score after dying. Please help...

tepid summit
#

reload scene on death

hardy heart
#

? I literally started yesterday so i know nothing lol

#

I cant find much online to help

tepid summit
#

followm the tutorial

hardy heart
#

he said the next best thing to do was to try to do this on your own, i couldn't figure it out

icy fossil
#

you could google how to reload a scene on death

hardy heart
#

ok

#

Well i want to keep my game over screen, but if you happen to land in between a pipe, you gain 1 more point.

#

That's what I want to stop

dense cypress
#

if you're using cc and not rigidbody, what's the best way to move the character keeping in mind it wants to interact with other objects with physics

delicate zinc
#

is this the right way to set default settings

#

idk if im doing smt wrong cos its not working

rare basin
#

that doesn't make sense

#

you are trying to load a key

#

okay nvm i read it wrong

#

yea it's good

delicate zinc
#

oh ok then its probably smt to do with my code to set the volume from playerprefs

languid spire
sterile radish
languid spire
spare mountain
languid spire
#

sorry wrorng, missed the !

spare mountain
languid spire
#

which is now worse because it will only save once

delicate zinc
delicate zinc
#

i have my settings as a different scene as the main menu so it didnt save the playerprefs

spare mountain
sterile radish
# spare mountain "first" in what regard?

i have this script attatched to a tower in my game and it locks onto the nearest enemy and shoots however i would like to change it in a way so that it shoots at the first enemy it sees not the closest

spare mountain
languid spire
#

so, as I said, you cannot, this code is not suitable for that

sterile radish
spare mountain
languid spire
#

no, you need to implement a trigger system, this uses completely different code

spare mountain
#

steve what are you talking about

languid spire
#

FindWithTag gives a random sequence of Enemies not 'the first'

spare mountain
#

good catch

#

you could make a separate enemy list and append them as they spawn so you can shoot the first one in range

languid spire
#

No, you need a trigger system and to implement OnTriggerEnter

spare mountain
#

but then varying speeds are an issue

spare mountain
languid spire
#

no they want the first in range

spare mountain
#

the furthest along enemy in range, sorry

timber tide
#

usually if you're casting or getting a group of objects in the same frame you'd want to sort it

spare mountain
#

you could sort by distance along the track if the enemies have a variable for that ^

#

that would be the best solution I can think of, but I want to know how steve wants to use triggers

languid spire
#

simple put a trigger collider on the tower, when ontriggerenter fires that is the one you shoot

spare mountain
#

what if an enemy moves faster inside of the trigger

#

now it's ahead, but it entered behind another enemy

languid spire
#

irrelevant, he wants to shoot at the first one

#

read what the OP said

spare mountain
#

yes, the first one isn't the first one that enters, it's the closest to the end (at least in bloons?)

#

roshi, can you clarify

#

do you want the first enemy that the tower sees (aka the one that enters its range first), or do you want the furthest along enemy the tower sees?

sterile radish
#

sorry, i should've explained this better, i want to shoot the first enemy but i want the tower behaviour to be similar to how amster is describing it and in bloons

languid spire
#

'similar to how in bloons td the monkeys shoot the first balloon they see and not the closest'

spare mountain
#

yes

#

so like I said

#

the furthest along enemy in range

#

that's how it works in bloons

short hazel
#

On trigger enter, add the enemy to a list. On enemy death / on trigger exit, remove it from the list. In Update get the closest one and shoot at it

spare mountain
#

oh wait

#

by "closest" do you mean closest to the goal?

#

that could work

timber tide
#

how do you resolve it all in a list using trigger, ah I guess it wouldn't be on the same frame then

#

Do like a queue, add newest enemies to it and then fire at the first in queue and check if it's still in range.

spare mountain
timber tide
#

Ah, right. The course can be somewhat complex too

#

Little tricky to keep sorted, so I guess you have to go through the list each update.

short hazel
#

I guess if the path is not straight you could represent it with a series of nodes, and use something to sort the enemies based on which node they're at, and how much in-between two nodes they are, to get the closest

#

With a straight path it's simple, but if you make some sort of circuit it gets complex fast

spare mountain
#

oof can't we just just store a variable for distance to the goal in each enemy

timber tide
#

it doesn't actually need to be resolved each frame is there is a cooldown on attacking

sterile radish
#

should i share my code for reference?

spare mountain
short hazel
#

Technically you could only recalculate it when one dies

spare mountain
#

because one could presume some will go faster than others

timber tide
#

but if it does need to be resolved each frame, you need to resolve it after physics update (if you're using OnTrigger)

short hazel
#

Then do it each frame, and if it gets slow optimize. In order:

  1. Make it work
  2. Make it pretty
  3. Make it fast
timber tide
#

or just physics query a overlap sphere or something yourself

#

Yeah, lot of ways you can optimize it, and I played that balloons game once and it was far from optimized

potent hornet
#

I'm trying to use my controller, and I can't figure out how to get the axises for my left and right stick. Do I need to change something in my Input Manager's settings

rigid valve
quartz mural
rich adder
#

these videos are the wors

quartz mural
#

apologies

rich adder
#

do a favor and post properly

rich adder
eternal falconBOT
quartz mural
#
public void SetMoveNames(List<Move> moves)
{
    for (int i = 0; i < moveText.Count; ++i)
    {
        if (i < moves.Count)
            moveText[i].text = moves[i].Base.Name; //Shows pokemon's move instead of the word move
        else
            moveText[i].text = "-"; // if there is no move it will show - 
    }
}
rich adder
#

also post the error stac trace

spare mountain
quartz mural
spare mountain
quartz mural
#

ok

rich adder
#

but anyway post it through a link

#

large code should not be posted in codeblocks

rich adder
#

you supposed to paste it , hit save and send link

#

are they still trying to figure how to post... UnityChanThink

spare mountain
rich adder
#

the bird

short hazel
#

If it fails to save, try another one. A few days ago gdl.space didn't work for another user

quartz mural
rich adder
#

why do people omit the rest of the code..

#

how the hell we gonna know which line is the error if you omit the info

rich adder
#
  • error from console..
quartz mural
quartz mural
rich adder
#

jesus..

spare mountain
#

😭

spare mountain
quartz mural
#

sorry guys im new

#

ok

rich adder
quartz mural
#

ok

wintry quarry
#

has the full error message been shared yet?

rich adder
#

in a very blury video above yes

spare mountain
rich adder
wintry quarry
spare mountain
#

it's not?

wintry quarry
#

the error contains the filename and line number of the error

#

the most important parts of the error message

#

share it

quartz mural
spare mountain
#

oh sorry yeah

quartz mural
#

thats one script

#

the last fucntino

#

is where the error is

#

when i call it

rich adder
spare mountain
#

send the error

quartz mural
#

ok

#

its in the vid but 😭

spare mountain
#

just send it

quartz mural
#

ok ok

cosmic dagger
rich adder
wintry quarry
quartz mural
wintry quarry
# quartz mural

Ok so it's this line:
moveText[i].text = moves[i].Base.Name; //Shows pokemon's move instead of the word move1

spare mountain
#

and it's specifically "moves"

wintry quarry
#

So either moves is null, moveText is null, or moves[i] is null or moves[i].Base is null or moveText[i] is null

short hazel
#

Yeah all that could be null

wintry quarry
#

you need to figure out which thing is null first

short hazel
#

Not just the text

rich adder
#

Debug time

quartz mural
#

how do i unnull it

spare mountain
rich adder
#

know which one is null, assign it

wintry quarry
#

don't try to skip the first step

quartz mural
#

ok

#

when i click on the error

#

it takes me to the battle system script

wintry quarry
rich adder
#

that only brings you to the line

wintry quarry
#

there are 5 references on that line that are being dereferenced

quartz mural
#

wait

#

can i show u smt

#

if i comment the line where i call the funciton

#

look what ahppens

wintry quarry
quartz mural
#

thats when i comment the line when i call the fucniton

wintry quarry
#

Now there's jsut another error happening at a different place

#

what's your point

quartz mural
#

to switch the "move" with the pokemons acc move

wintry quarry
#

You still need top fix the error

quartz mural
#

ok

#

so find which is null

wintry quarry
#

yes

#

Find which is null, and assign it

quartz mural
#

if i may ask

#

how do i do that

wintry quarry
#

Debug.Log or attach the debugger

quartz mural
#

okkkk...

wintry quarry
#

e.g.

if (moves == null) Debug.Log("moves is null");
/// etc```
#

there are 5 things you need to check

quartz mural
#

ok

rich adder
#

learn to use debugger and step through code 😈

quartz mural
#

🫡

abstract finch
#

do while loops check the condition after all the code is ran through inside it or does it check after every line?

short hazel
#

Before all the code

wintry quarry
abstract finch
#

thanks!

short hazel
#

do ... while checks after, ensuring at least one iteration

wintry quarry
#
while (cond) {
  A();
  B();
}```
Does:
- check cond (bail out if false)
- run A()
- run B()
- check cond again (bail out if false)
... so on
abstract finch
#

does for int loop function the same way?

spare mountain
#

just with incrementation, yes

abstract finch
#

got it thanks

wintry quarry
#

note that the init part only runs at the start

#

it's just a while loop with a couple extra bits

abstract finch
#

i see thanks!

earnest atlas
#
 private static GameController _instance;

 public static GameController Instance
 {
     get
     {
         if (_instance != null) return _instance;
         var gameControllerObject = new GameObject("GameController");
         _instance = gameControllerObject.AddComponent<GameController>();
         DontDestroyOnLoad(gameControllerObject);
         return _instance;
     }
 }```
I have code on instance object. I already have this object in all scenes. Does it do anything considered GameManager object already exists.
wintry quarry
earnest atlas
#

Yeah as I though gotta remove it

wintry quarry
#

with this code you should NOT have the thing in the scene at edit time

#

Either use this code OR place the thing in all the scenes

#

not both

earnest atlas
#

So this is entire thing I need?

#

Are there any pros of generating such object or no?

#

Considered on top if you want it to be something more complext then just data storage

bold nova
#

Hi, I', trying to create a sequence, where camera flyies through the whole (2d) level, after that the player charachter should play animation, but only after the camera span is over. I've tried it with DoTween and Coroutines, but they still work simultaneously. How to I give full controll to camera first?

Game manager code
    private void StartSessoin()
    {
// start camera span
        playerObserver.StartCameraSpanCoroutine();

// start intro animation
        guy.LetGoPresent();
    }

CAMERA CODE
public IEnumerator LevelCameraSpan()
{
    Vector3 destination = new Vector3(0, yPositions[yPositions.Length - 1], 0);
    Vector3 current = new Vector3(0, yPositions[0], 0);
    float time = 0;
    float timeInterpolator = time / transitionDuration;
    while (timeInterpolator < 1)
    {
        Debug.Log(timeInterpolator);
        transform.position = Vector3.Lerp(current, destination, timeInterpolator);
        time += Time.deltaTime;
        timeInterpolator = time / transitionDuration;
        yield return null;
    }

    yield return new WaitForSeconds(0.5f);

    current = new Vector3(0, yPositions[yPositions.Length - 1], 0);
    destination = new Vector3(0, yPositions[0], 0);
    time = 0;
    timeInterpolator = time / transitionDuration;
    while (timeInterpolator < 1)
    {
        transform.position = Vector3.Lerp(current, destination, timeInterpolator);
        time += Time.deltaTime;
        timeInterpolator = time / transitionDuration;
        yield return null;
    }
}
earnest atlas
#

wdym by full camera controll?

#

also !code

eternal falconBOT
bold nova
#

I want it to move the camera through the whole level , like a preview of the level, during that fly through no animation should be played, but with the code above camera starts to go up (i have 2d level) and player character starts intro animation in the same time

charred spoke
bold nova
#

Start coroutine inside another or this should be one big coroutine?

charred spoke
#

Both can work but I prefer to start coroutines inside a master sequence routine

dire tartan
#

i want the camera to rotate how its shown at the start and to follow the player what do i have to change?

rich adder
#

You'd need to fix your pivot though

bronze bane
#

!code

eternal falconBOT
wind raptor
#

I have a Singleon class. Is there a good reason not to make all my public methods/members static? So that outside calls can just be "SingletonClass.Function()" as opposed to "SingletonClass.Instance.Function()" ?