#💻┃code-beginner

1 messages · Page 536 of 1

rocky wyvern
#

dont see why it would be tho

#

worst case scenario you just make multiple fixed timesteps

#

you can use a faster one for this

#

if you need a super slow one for something else

verbal dome
rocky wyvern
#

since you are using fixedupdate you should use impulse or velocitychange force modes

#

using default in fixedupdate will result in very small velocity change

#

I think?

torpid igloo
#

yep

#

works now

#

thanks everyone

swift crag
#

Impulse and VelocityChange apply an instantaneous change in momentum or velocity

#

You're meant to use these for things like jumping

#
if (doTheJump) {
  rb.AddForce(Vector3.up * 10, ForceMode.VelocityChange);
}
#

This is basically identical to

#

rb.velocity += Vector3.up * 10;

#

If you use these two force modes in every single fixed update call, you'll get 50 times more force or velocity change than you expected

#
void FixedUpdate() {
  rb.AddForce(Vector3.up, ForceMode.VelocityChange);
}
#

This will accelerate you by 50 meters per second every second

#
void FixedUpdate() {
  rb.AddForce(Vector3.up, ForceMode.Acceleration);
}
#

This will accelerate you by 1 meter per second every second

swift crag
#

It's wrong, but at least it's wrong in a framerate-independent manner 😉

#

It would be very wrong if you did that in Update, because then the amount of acceleration would depend on your framerate

rocky wyvern
#

I thought force was scaled by deltatime?

#

What’s the point of them even existing if they’re done by fixeddeltatime then

wintry quarry
rocky wyvern
#

Um yes I’m saying the force and accel modes are just like

#

Velocity change * 0.02 or whatever ur fixed step is at

#

Surprised they even exist if that’s the case is all

wintry quarry
#

Acceleration is so you can literally write the amount of acceleration you want in sensible units and it just works

#

Force is so you can literally write the force you want in newtons and it just works.

#

Acceleration is m/s^2

#

Force is in Newtons

#

It's possible to achieve the same result with any force mode but these are convenient for simplifying the math

cosmic dagger
#

Force and Acceleration apply x amount of force over time
Impulse and VelocityChange apply x amount of force during the one frame . . .

upbeat smelt
#

Those dropdowns are just shortcuts for adding and removing behaviours. Setting it to None just destroys the CinemachinePositionComposer behaviour, so that's what your code would need to do. However, that is not the recommended way to use Cinemachine. Instead, create a second CinemachineCamera without the PositionComposer and activate it.

real geyser
#

i have a problem where script is working when i out game object manually in the hierarchy. but when i try to instansiate it it doesnt work/ i have checked prefab and the gameobject is same

swift crag
swift crag
#

(at least when called in FixedUpdate -- I do not remember what happens if you apply a continuous force in Update)

#

I vaguely remember something being wrong

cosmic dagger
long jacinth
#

bruh im getting this silly error

swift crag
#

your IDE is still not working correctly

#

if it was, it would suggest a fix

long jacinth
eternal falconBOT
long jacinth
#

i did that yesterday and it didnt change anything

rich adder
long jacinth
#

how is configuring done

rich adder
#

did you click the links sent to you

#

click VS Code

#

double check each step is taken care of

long jacinth
#

it is

rich adder
#

well obviously something is wrong. Close VSCode, go to external tools in Unity and click Regen Project Files button. Open script again by double click in unity

#

check for errors in vsc

long jacinth
rich adder
rich adder
long jacinth
#

and the problem

rich adder
ancient karma
#

Quick question, I was hoping to detect a null reference for a condition (if this doesn't exist yet, do something else first). Is there any way I can write a condition that evaluates that?

swift crag
#

you can compare any reference type to null

#
if (foo == null) {

}
#

additionally, any Unity Object can convert into a boolean, so you can do

#
if (foo) {
  // it's a valid Unity Object reference
}

if (!foo) {
  // it's invalid
}
long jacinth
hexed terrace
# long jacinth

lol - why did you hide which external editor you have set in Unity? 🙂

rich adder
# long jacinth

you had vscode open first while I asked you close it before clicking the button. it probably cant connect vsc properly rn because of your compile error

swift crag
#

Oh, that's a very important note

#

If there are compile errors in your project, new packages can't have their code compiled

long jacinth
swift crag
#

So they can't start doing things

#

If you have had errors since you started trying to get your IDE working, then you need to fix them (probably just comment everything out) so that Unity can actually compile

long jacinth
rich adder
#

fix ide first

#

then you can use a fixed ide to let it Offer suggestion to fix the error in code

long jacinth
#

it doesnt autofill still

rich adder
# long jacinth it doesnt autofill still

no. now just try redoing the steps. close vscode this time, check off the first two also cause i think its default "Embedded packages" and "Local Packages" click Regen. Double click a script from unity.

#

check the vsc console /output for any errors

swift crag
#

you must be able to enter play mode before continuing -- that proves you have no compile errors

long jacinth
#

so i check these?

#

i can enter play mode

#

is this related

rich adder
#

might be

#

wait till the bottom loads

#

it should say either Assembly-Csharp or an error

long jacinth
rich adder
#

a minute or two depends

#

unless u got a potato

long jacinth
rich adder
#

is that AOE 3 open?

#

also I have literally no way of telling you how fast your own pc is lol. Everything you have open affects the memory/speed of course

long jacinth
long jacinth
rich adder
#

is still not loaded?

proper bobcat
#

I can't imagine it would take more than 5 minutes to connect to your editor of choice worst case scenario

rich adder
#

if its stuck or not loading then yea you have to check what the output / log window

long jacinth
#

its still loading

proper bobcat
#

I think theres another issue imo

rich adder
#

could just be corrupt .net sdk

long jacinth
#

it says this

proper bobcat
#

Could be. I havent read the entire convo. Did they have the VS studio package installed?

long jacinth
#

yes and fully up to date

proper bobcat
#

Oh...They need the Runtime

rich adder
#

the sdk installs both, runtime an sdk

frail hawk
#

imo just use VS instead Code

#

it is way better and provides more tools

long jacinth
#

ok ig i will reinstall it

proper bobcat
#

I'd just close everything and reinstall the needed dependencies

rich adder
#

I dont need a bulky editor sometimes

long jacinth
#

.9 or .8

proper bobcat
#

VS is also chunky, and bloated

frail hawk
#

fair enough

rich adder
#

also if you work on mac, VS is gone

frail hawk
#

well the new 2022 is pretty fast

rich adder
#

it was

#

new updates making it worse and worse, thats why i went to vsc for a bit

proper bobcat
#

I just prefer lighter editors. Its all preferences, they all work for most hobbyists

frail hawk
#

i even saw people coding in the plain text editor

swift crag
#

i saw a sophomore student programming in Microsoft Word

rich adder
#

me on vim or nano 🥲

frail hawk
#

Word oh wow that is new to me lol

long jacinth
#

or does that have nothing to do with unity

rich adder
#

if you want?

hexed terrace
#

VS is "better" that VSC

rich adder
#

community = free version

long jacinth
#

whats the difference

rich adder
#

you're not a corporation or business so no worry

hexed terrace
#

VSC is a glorified text editor

cosmic quail
#

there's a paid version? kekwait

hexed terrace
#

always has been

rich adder
#

C# Devkit implements the same license VS does

#

Community and Enterprise

frail hawk
#

as if anyone would pay money for it 😉

hexed terrace
#

businesses have to..

rich adder
#

yeah goodluck making money as business using community edition

#

m$ goons will catcha

cosmic quail
#

if my indie game makes money do i need to pay for visual studio?

rich adder
#

sure if its commercially used (and certain threshold is met)

long jacinth
#

so to switch what do i have to do

rich adder
#

you can also use Rider 😛

#

just don't umm make money without them knowing

swift crag
#

I use Rider (and paid for it, since I'm doing commercial work)

#

Pretty damn good IDE. I used VSC for a long time.

#

It's the only way I've been able to edit ShaderLab properly on my mac

rich adder
#

the open source license is very nice of them

hexed terrace
hexed terrace
#

!vs

eternal falconBOT
#
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

long jacinth
#

ok

cosmic quail
marble grotto
#

hi, i need help changing the shape of a collider box. I can provide a picture. I just need it to have an extended cuboid shape

cosmic quail
rich adder
swift crag
#

You start paying more attention to this stuff when you have a good chunk of money

marble grotto
#

i just need the box to extend into the corridor

rich adder
#

yeah don't mess with lawyers lol

#

pay your dues so you have no worries

swift crag
marble grotto
#

that doesn't work for what i need. Theres game states for ambience for outside and inside. When using 2 seperate collidors, the outside ambience leaks in for a second when switching collider

cosmic quail
long jacinth
#

what extention do i download for visual studio community to work with unity since i already have it installed

eternal falconBOT
frail hawk
#

it is really easy

long jacinth
#

ok

swift crag
#

Alternatively, you should change your system so that it plays the internal audio as long as any of the colliders are being overlapped

#

perhaps by counting up and down when you enter and leave colliders

marble grotto
#

thanks

swift barn
#

Can anyone help me? I'm trying to make my camera controller follow the player, but I keep getting this error? I'm new to C# and need to complete an assignment for my class. Anyone know a fix? Ill provide the script below! I am using visual studio and Unity

naive pawn
#

!code

eternal falconBOT
naive pawn
#

taking pictures of your screen is like, the worst way to share your code

swift barn
#

Oh is it? I'm sorry, Ill write it down

naive pawn
#

oh, that's even worse

#

no, don't rewrite code (or errors)

swift barn
#

How do I share it?

naive pawn
#

that'll just make it subtly different from the original

swift barn
#

Ah I see

naive pawn
#

you would just copy and paste the original into one of the sharing sites listed above

#

but before that

#

just show the error itself please

swift barn
#

Sure!

naive pawn
#

with screenshots, not with a picture of the screen

#

and show a stacktrace if one exists

swift barn
#

Ah I'm not quite sure what a stacktrace is, but I'll do my best to provide better info with clearer images, thank you!

naive pawn
#

click on the error in the console, if it shows a bunch of files and method names, that's a stacktrace

#

(i can explain what a stacktrace is/means later, but it might take a while given you're a beginner, so i'll leave that for later so we can go over the error first)

swift barn
#

I'm not quite sure how to utilize the link you sent me, would it be alright to send over the information here?

#

And I appreciate the help thank you!

naive pawn
#

the links there are for posting code, send a screenshot of the error stacktrace here

swift barn
naive pawn
#

did you destroy your player?

#

also why is it a recttransform?

swift barn
#

No I didn't destroy my player, I'm not sure why its giving me this error, I have a copy of the script if you need to see it

swift barn
naive pawn
#

check to see if you have other instances of cameracontroller, maybe

marble grotto
# swift crag You'd get rid of the MeshCollider entirely

i believe i fixed it. I didn't fully grasp the logic of state groups. Essentially, when leaving the first mesh, i had it switch to outside ambience since it needed to do that when leaving the building. But this would mean it would also trigger briefly when moving to the corridor. So essentially what i did was remove all references to outside ambience while in those meshes and added a new box collidor by the entrance with the sole purpose of retriggering the outside ambience. A simple fix

swift crag
#

ah, is "state group" a Wwise thing?

marble grotto
#

yes

swift crag
#

I'm not familiar with that system

marble grotto
#

fair

swift crag
marble grotto
#

i'm doing it for uni, music tech. They're making us use unity. I've never used unity before. Getting my way through it though.

swift crag
#

ah, I see!

alpine fjord
#

I've been curious, does everyone write their own scripts. Or do you find something similar and modify it?

cosmic dagger
wintry quarry
#

Beginners tend to copy-and-modify because they have no idea how to start

#

but once you learn the ropes, you write your own

swift crag
#

There is one case where I do wind up modifying existing code -- when I'm doing something weird with someone else's library

#

I've made a few edits to the unity splines package to make it perform better for me, for example

#

(I need to NOT aggressively recalculate the up-vector cache on splines that are changing every single frame!)

alpine fjord
#

Thanks guys.

swift barn
short mica
#

Hi, i just started learning how to use Unity. I'm currently trying to use a tileset to make a 2d platformer but there's this bug that showed up where if I run on a flat surface, my character still gains some vertical height and goes into a jump state

#

I was wondering if its a problem with the collisions on the tiles? or the code of my player movement

#

this is my code for my player movement, as well as the colliding components i added to my tilemap

wintry quarry
#

instead of multiple collidrs

short mica
#

is it the tilemap Collider2D?

wintry quarry
#

Yes

#

Here's a thread about this issue btw

#

There's not a single "one-size-fits-all" perfect solution

#

Also look at CompositeCollider2D

short mica
#

okok

#

thanks for the help

frosty field
#

i dont understand why but my camera is locking to offset(0, 5, -7) every time i press V, and its not locking to offset(0, 2, 1) at all

languid spire
#

Look at the logic of your code

frosty field
#

wdym 😭

#

its looking logic to me

languid spire
#

your logic is all wrong

frosty field
#

why?

languid spire
#

step through the code line by line

frosty field
#

oh

#

i think i get it

#

is it that if i press V, its changing to true but then instantly to false cuz when its true and get's an V input its going back to false?

languid spire
#

It's not changing to false at all.
When you press V ALL 3 of the If statrments become true

frosty field
#

huh?

languid spire
#

post your !code correctly and I'll show you

eternal falconBOT
frosty field
languid spire
#

OK. So
if (camCheck == false && Input.GetKeyDown(KeyCode.V)) is this true? Yes camCheck is false and V has been pressed
so set camCheck = true
next step
if (camCheck == true) is this true? yes, we just set it
next step
if (camCheck == true && Input.GetKeyDown(KeyCode.V)) is this true? yes
so
camCheck = false;
offset.Set(0, 5, -7);

humble forum
languid spire
#

so although you set offset.Set(0, 2, 1); is is only for one if statement

humble forum
frosty field
cosmic dagger
# humble forum

it's easier to paste your !code using one of the sites so anyone call look at all of it, instead of separate pictures for each section . . .

eternal falconBOT
humble forum
#

what im i doing wrong when i have a valid tile my ui opens and want to be able to place a building of my choice wich i am trying to set in PlaceDefensebuilding but it doesn t wanna place seems like my button doesn t respond to the klick event but don t know why

humble forum
long jacinth
#

i fixed the VS problem

#

i had to update .net thanks guys

frail hawk
#

so what are you using now

long jacinth
#

also i want to have a script that has a list of prefabs is there a way so that every gameObject already has that last of prefabs by defualt

long jacinth
frail hawk
#

cool

sage abyss
#

Hey, is there a way to find inactive gameobjects by tag?

cosmic dagger
sage abyss
west radish
sage abyss
long jacinth
cosmic dagger
west radish
#

I think I get what youre doing, but you might have to clarify

long jacinth
humble forum
# humble forum

anyone 🙃
place building is also there with an if statement btw

west radish
#

So its like you have 50 game objects (one for each state), and you want every state to have a list of every other state. That makes sense so far

long jacinth
#

each city has buildings and i want it so if u upgrade in one city it wont upgrade in the other

eternal falconBOT
#

mad No

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

cosmic dagger
rich adder
humble forum
rich adder
humble forum
#

wat is the word for c sharp for a codeblock?

west radish
#

As long as you create a different instance of each of your province gameobjects, you'll be able to different things with each instance without it altering the same thing in every instance you have

humble forum
# rich adder what is supposed to do?
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Tilemaps;

public class PlaceDefenseBuilding : MonoBehaviour
{
    [SerializeField] private GameObject buildingPrefab; 
    [SerializeField] private Tilemap tilemap;
    [SerializeField] private Button PlaceBuildingButton; 

    public void PlaceBuilding(Vector3Int cellPosition)
    {
        Vector3 cellWorldPosition = tilemap.GetCellCenterWorld(cellPosition);
        
        if (buildingPrefab != null && PlaceBuildingButton != null)
        {
            Instantiate(buildingPrefab, cellWorldPosition, Quaternion.identity);
            Debug.Log($"Gebouw geplaatst op {cellWorldPosition}");
        }
        else
        {
            Debug.LogError("Geen gebouw prefab toegewezen in BuildingPlacer!");
        }
    }
}
long jacinth
west radish
#

only if you accidentally made static instances

humble forum
#
  void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3Int clickedCell = PointedCell;
            TileBase tile = tilemap.GetTile(clickedCell);

            if (tile == expected)
            {
                Debug.Log("Je hebt op een verwachte tegel geklikt!");
                
                if (BuyScreen != null)
                {
                    BuyScreen.ShowPanel();
                }

                if (placeDefenseBuilding != null)
                {
                    placeDefenseBuilding.PlaceBuilding(PointedCell);
                }
            }
        }
    }
long jacinth
humble forum
rich adder
#

debug your tile and expected , and check with logs

west radish
#

ah, but a GameObject is just a class, and if you have a static copy of a class, you'll have 2 different class instances but as theyre static, it'll actually be like you only have 1 object with 2 clones

humble forum
rich adder
#

log what the true values are vs wat you expect them to be

humble forum
cosmic dagger
rich adder
humble forum
long jacinth
cosmic dagger
wintry quarry
#

People often confuse static classes with static references to an instance of a class.

#

The latter being more common

cosmic dagger
west radish
#

As I know each can be given a different name, I know changing one province isnt going to mess anything else up

rich adder
#

oh my.

#

that chained GetComponent was scary (whoever deleted code)

wintry quarry
west radish
#

yeah, but "State" has more technical meaning behind it

long jacinth
#

they are called governates in my area but i already handled the province name part i just have the building left

cosmic dagger
# long jacinth exactly

then, when the player selects a building to construct, you would use the prefab from the list and instantiate that prefab. this will return a copy (instance) of that prefab. make sure to assign this instance to a field or list on your city (to keep track of it) . . .

long jacinth
#

the first thing im gonna do rn is first of all try to think how i can even make the buildings show in the tab

frail hawk
#

buildings in tabs whats that

polar acorn
humble forum
#

navarone do you have any idea how i can fix it really don t know 😅

west radish
frail hawk
#

oh

rich adder
#

i don't have eyes/mouse on ur pc

west radish
long jacinth
#

im thinking about making one of those scroll wheel things and it adds a button for each building that exists or something

humble forum
rich adder
humble forum
rich adder
long jacinth
rich adder
long jacinth
rich adder
steep rose
#

or why a certain function you made is not working like expected (e.g position or rotation being wrong)

polar acorn
wintry quarry
humble forum
wintry quarry
polar acorn
humble forum
polar acorn
wintry quarry
steep rose
#

you just said it doesn't work

placebuilding func just doesn t seem to be triggered

wintry quarry
#

Dispel the idea from your mind that "bug == red text ERROR"

#

that's not what it means at all

humble forum
wintry quarry
#

debugging is definitely part of the process of writing code though

humble forum
# polar acorn So then _what is the problem_

i am trying to place a building when the player clicks a wreckege player clicks wreckege>ui spawns> player clicks desired building> building spawns and it goes wrong with clicking

humble forum
polar acorn
steep rose
#

undesired effect, means it is a bug

alpine fjord
#

If it's not working the way you want it to. Then it has a bug.

polar acorn
#

"I see this pile of meat and cheese in between two slices of bread and not a sandwich but whatever 🙂 "

rich adder
cosmic dagger
# long jacinth each city has buildings and i want it so if u upgrade in one city it wont upgrad...

i kinda hope this is a game about explaining tariffs: showing how American companies can choose to pay for them or find a cheaper competitor to buy from, the loss in revenue from said tariffs, then eventually increasing prices to recoup losses or maintain their current price, thus adding to inflation

make sure the player has the option to build factories to try to increase jobs that will lead to economic growth in their region. of course there are other factors to input, but it'd be an interesting concept for players to experience themselves . . .

humble forum
polar acorn
rich adder
long jacinth
humble forum
cosmic dagger
humble forum
whole sequoia
#

Can Somebody Help me With my Jumping Mechanics pls, The problem is that i can still jump even tho i m not on a game object with a tag called ground, This is the code:

eternal falconBOT
rich adder
# humble forum

if you plan on showing us logs can you please at least make them english..

long jacinth
humble forum
rich adder
whole sequoia
#

ohh

humble forum
#

but also the call does nothing :/

polar acorn
rich adder
whole sequoia
#

i m not sure how that works but..

#

i can try

rich adder
#

simple, you look them up and see how others do it
learn by someone whos been there before. thinksmart

polar acorn
humble forum
rich adder
whole sequoia
#

thnx tho

polar acorn
#

On the script that has the bug, placeDefenseBuilding is null

humble forum
polar acorn
rich adder
# humble forum how do i do that?

do it after this problem is solved but.. in Package Manager , find the packages In Project and you find that one called collab n remove it

humble forum
polar acorn
humble forum
#

like this? because i think it is wrong

rich adder
#

don't see any placeDefenseBuilding there

humble forum
polar acorn
#

What is the value of placeDefenseBuilding

rich adder
#

its a variable you made for that type, where did you give it value

humble forum
#

placedefensebuilding is a script and doesn t have a value only func placebuilding has?

polar acorn
#

placeDefenseBuilding

rich adder
polar acorn
#

where do you assign that variable a value

humble forum
#

that is the class im so confused

#

oh p

polar acorn
humble forum
polar acorn
#

in the code that isn't doing what you expect, you have a variable placeDefenseBuilding

#

What

rich adder
#

the class is the type you chose for the placeDefenseBuilding it doesn't tell us how you assigned value to it

polar acorn
#

Is

#

It

polar acorn
#

Where do you assign it

humble forum
#

pointedcell?

polar acorn
#

No

#

placeDefenseBuilding

#

the thing I've said

#

like twenty times

#

that you screenshotted

#

literally ten seconds ago

#

that one

rich adder
#

what is the value of placeDefenseBuilding

humble forum
#

    [SerializeField] private PlaceDefenseBuilding placeDefenseBuilding;

rich adder
#

where do you give it value

polar acorn
#

This fuckin variable

#

where do you assign it

rich adder
humble forum
polar acorn
#

and the log you said isn't running

#

only runs when the variable isn't null

#

so that would explain

#

why it is not running

humble forum
#

but why doesn t the else come in clutch then?

polar acorn
#

There's no else in the screenshot you sent

humble forum
rich adder
long jacinth
humble forum
#
using UnityEngine;
using UnityEngine.Tilemaps;

public class TileChecker : MonoBehaviour
{
    [SerializeField] private TileBase expected;
    [SerializeField] private Tilemap tilemap;
    [SerializeField] private BuyScreen BuyScreen;
    [SerializeField] private PlaceDefenseBuilding placeDefenseBuilding;

    private Vector3Int PointedCell
    {
        get
        {
            Vector2 screenPos = Input.mousePosition; 
            Vector3 worldPos = Camera.main.ScreenToWorldPoint(screenPos);
            worldPos.z = 0;
            return tilemap.WorldToCell(worldPos);
        }
    }

    public bool IsValid(Vector3 mouseWorld)
    {
        Vector3Int cell = tilemap.WorldToCell(mouseWorld);
        TileBase tile = tilemap.GetTile(cell);
        return tile == expected;
    }

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3Int clickedCell = PointedCell;
            TileBase tile = tilemap.GetTile(clickedCell);

            if (tile == expected)
            {
                Debug.Log("Je hebt op een verwachte tegel geklikt!");
                
                if (BuyScreen != null)
                {
                    BuyScreen.ShowPanel();
                }

                if (placeDefenseBuilding != null)
                {
                    expected.PlaceBuilding(PointedCell);
                    Debug.Log("you clicked the button");
                }
            }
        }
    }
}
#

but then i sort of gotta use expected?

rich adder
#

no you use SetTile if you are putting a tile on tilemap

long jacinth
rich adder
long jacinth
#

ok

humble forum
rich adder
#

i dont even know what it does since that doesnt make sense coming from TileBase

#

if it needs to be a prefab use Instantiate and place it with WorldToCell / CellCenter or whatever.
if its a tile in tilemap then use tilemap.SetTile(pos, tileYouWant)

tawny edge
#

Hello everyone, i am confused about my code:

I can move fine in all directions using the keyboard.
But for some reason , when i use my dualshock 4, i can only move horizontally, but not vertically, why is that???

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed = 10.0f;
    public float jumpForce = 50;
    private Rigidbody playerRb;
    // Start is called before the first frame update
    void Start()
    {
        playerRb = GetComponent<Rigidbody>();
    }

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

        playerRb.AddForce(Vector3.forward * speed * verticalInput * Time.deltaTime);
        playerRb.AddForce(Vector3.right * speed * horizontalInput * Time.deltaTime);

        

        
    }
    
    
    
}```
rich adder
#

dont use time.deltaTime on rigidbodies

#

also use FixedUpdate to move rb

wintry quarry
tawny edge
#

why? (i'm asking to undersatnd better, not to disagree with you)

rich adder
#

unless you use impulse ofc (like a 1frame jump not constant)

wintry quarry
#

Vector3.forward would move it horizontally

wintry quarry
tawny edge
wintry quarry
#

Using Time.deltaTime is not a replacement for that when it comes to physics and other simulations that have second-order functions-over-time in them like acceleration/velocity

wintry quarry
# tawny edge why?

deltaTime (or rather FixedDeltaTime) is already accounted for in the various ForceModes used in AddForce

#

what you are adding is extra noise that makes the units of the force you're adding nonsensical and unpredictable

#

By default, the force you add is measured in Newtons

#

and expected to be added consistently over time in FixedUpdate

humble forum
#

if (BuyScreen != null)
{
BuyScreen.ShowPanel();
tilemap.SetTile(clickedCell, expected);
}

but how can i make it work and have it dynamic so i can use it on all i just don t know anymore

tawny edge
humble forum
#

need to work for all buildings

wintry quarry
#

you might think of them as "North" and "East"

#

what you want is Vector3.up if you want to go up.

rich adder
humble forum
rich adder
humble forum
tawny edge
rich adder
tawny edge
#

Thank you both for answering my questions!

humble forum
rich adder
#

your set tile code has to "wait" till selection is done

#

the buttons have OnClick you can call set tile after thats clicked, you have to figure out which tile each building type ui corresponds to

long jacinth
#

how do i make stuff instantiate at the top

rich adder
#

probably fixing the alignment

humble forum
rich adder
#

we're talking about code/ structuring . player has no relevance rn

humble forum
rich adder
humble forum
delicate lance
#

Hey guy, for the past week Ive been making 1 tiny project/ day to get more familiar with the Engine, it's going great but now I need to create projects with better practices such as using getter/setters, interfaces/scriptable objects, etc. i have 2 questions

  1. Where can I learn the best practices to apply in projects?
  2. Do you guys recommend a youtuber or someone who goes through best practices - sometimes im not sure what to look for, and how it would be 'best practice'

Thank you 🥳

rich adder
delicate lance
#

I get most of my info from Unity docs at the moment and it works wonders, just knowing what to search for is what im looking for before i fall into bad practice like leaving everything like a score in update()

humble forum
rich adder
#

along with general c# practices still apply in unity

delicate lance
rich adder
humble forum
#

guess i have 30 min today to fix it going to bed soon

humble forum
humble forum
rich adder
#

can like ?

humble forum
#

just press it and place it

rich adder
#

okay so what I said stil applies

#

you have to know what you are pressing corrisponds to

humble forum
tawny edge
# wintry quarry As for: > i can only move horizontally, but not vertically, why is that??? Becau...

that didn't work, i should have clarified the type of game i'm making.
Vector3.up doesn't work as it makes my character go up in the air, that is not what i wanted so i changed back.

Look at the video, on the first part when the capsule is moving only sideways, i am actually using my controller and moving the joystick in CIRCLES, he should have moved farther and closer to the screen!
At the second part when the capsule does move in all directions is when i'm using my keyboard, all directions work!

what is going on here? why does it work for my keyboard and not my controller?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed = 10.0f;
    public float jumpForce = 50;
    private Rigidbody playerRb;
    // Start is called before the first frame update
    void Start()
    {
        playerRb = GetComponent<Rigidbody>();
    }

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

        playerRb.AddForce(Vector3.forward * speed * verticalInput);
        playerRb.AddForce(Vector3.right * speed * horizontalInput);

        

        
    }
    
    
    
}

long jacinth
#

"Instantiate(ButtonBuild, Spawn.transform.position,Quaternion.identity, Scroller.transform);" its not instantiating at spawn.transform.position"

humble forum
#

in 1 week now (had 2 weeks)

rich adder
#

you should've picked an easier project

#

there are pretty complex systems at work here, especially when that involves UI interactions

humble forum
#

need to make 3 levels with 3 challenges each

long jacinth
snow warren
#

hey guys

#

how to fix this

#

the Image is a system.drawing class

polar acorn
snow warren
#

currently using Unity6

snow warren
#

never experienced that before

polar acorn
#

It's possible they intend you to use a non-parametric version that is

polar acorn
snow warren
#

same for RGBA32

#

the class itself isnt

west radish
#

It's probably a silly question, but why is it when I give my game object the foo class as the component, its the foo's Update that gets called, not the Update from the base? I'm not too sure why this doesnt give me an error too, as I didnt override anything

public class foo : MyBase
{
    void Update()
    {
        Debug.Log($"This gets printed");
    }
}

public class MyBase : MonoBehaviour
{
    void Update()
    {
        Debug.Log($"this, does not.");
    }
}```
cosmic dagger
west radish
#

ah, right

cosmic dagger
#

currently you can't because it's not virtual . . .

#

nor is it public or protected . . .

#

you need to allow the method to be overridden, and give it the appropiate access level . . .

humble forum
#

f god im done for today 🙂

north kiln
#

if these functions were public/protected you would be seeing a warning

west radish
#

What I'm not sure if is which update is the ony I should be getting Unity to call, because if I can have 2 different update methods in both the derived and base class, only one should be called

north kiln
#

Unity will call the more specific one, ie. the one in the inherited class. But it's bad to have an inheritance hierarchy and manually redefine functions like this

cosmic dagger
west radish
devout flume
north kiln
#

I don't use C++

devout flume
#

Fair enough, I'll look that up

devout flume
# north kiln I don't use C++

It doesn't hold the same meaning at all, and actually after thinking about it twice, that's quite logical because virtual in C++ has a lot to do with pointers

cosmic dagger
devout flume
#

However it will eventually prompt an issue depending on the context

swift crag
#

Both the parent and child classes declare a private method named Update

eternal needle
devout flume
swift crag
#

which is why these methods still get called even when they're nominally private

#

If it weren't for reflection, there would be no way for this ambiguity to come up at all

eternal needle
#

the differences are very minor

swift crag
#

C++ introduces about 30 ways to blow your entire leg off, but it's otherwise the same idea 🤭

astral ice
#

erm guys

#

for some reason my unity c# code is NOT showing up

#

like at all

#

vhat do i do?

teal viper
# astral ice

Open the solution explorer window/tab(should be accessible from view menu). Is there anything in it?

astral ice
#

yeah

#

alot of things

teal viper
# astral ice

They are unloaded though. Do you have the ide configured correctly?
!vs

polar acorn
teal viper
#

!vs

eternal falconBOT
#
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

median rune
#

Just a FYI for anyone having that weird bug with Start(), Awake(), and Update() its been fixed peeps. There more on the release notes friends.

junior saddle
#

sup gang

#

I'm trying to clean up my code a little

#

in my if statement on top, I have that in parentheses.

Does it replace what I have in red so I can remove it?
Remove what's in red

steep rose
#

if by replace you mean addcard being false and you are okay with everything in the new if statement then sure

junior saddle
#

yes I had "DontAddCard" as my bool before and that in red was left there as "true" x)

#

but yup it does work nicely, thanks

queen adder
#

looking for a scripter 2D URP junior am doing animations and sprites

eternal falconBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
Collaboration & Jobs

pure drift
#

does anybody know how i could get the enemy target position to work in the target spawn point serializefield

pure drift
#

thank you

rose geode
#

I got this error when trying to export from localization string table to character set for Russian, anyone encountered this?
"OverflowException: Value was either too large or too small for an unsigned byte."

swift crag
#

Oh huh, I didn’t know you could do that

#

Can you show the stack trace? Click on the message and look at the bottom of the console

rose geode
#

I'm sorry, unity localization has an error when trying to parse Russian characters, with other languages ​​like Japanese, French, Korean it's completely normal.

swift crag
#

The error is coming from code that tries to parse a format string's selectors

#

"Like this: {0}"

#

If it finds a character it doesn't like, it tries to turn it into a byte and then display it

#

But if that character's encoded value is too big, it doesn't fit into a byte, so you get an error

#

Can you check for strings that include curly braces like that?

#

If you have, say, "oops {ü}", that might break

#

(i don't actually know if that's out of range, but that's the idea)

nocturne kayak
#

Hey, i'm having a bit of trouble changing a method bool, i don't think i understand how they work properly

#

i'm calling hte onSelected() method from another script and i can trigger it no problem, however isSelected's printing false

#

what gives?

pure drift
swift crag
#

your set accessor does nothing

nocturne kayak
#

Ah, i see

swift crag
#

If you don't want to let other classes set it, use private set

nocturne kayak
#

once again the main problem in my code was between my chair and the keyboard

#

Still, i don't fully understand how the bool accessor works

#

i just saw i can't really set a variable in an interface there

swift crag
#

"in an interface"?

rose geode
nocturne kayak
#

i'm sorry, i'm still learning this as i go, but isSelected is a bool declared in an iSelectableFurniture interface which this class's pulling from

nocturne kayak
#

apparently i can't just use the good old bool isSelected in the interface code, so i have to do bool isSelected {get; set;}

swift crag
#

Ah, yes

nocturne kayak
#

but i don't really understand why, or how to use it

swift crag
#

You cannot declare fields in an interface

#
public class Foo {
  public bool field;
  public bool Property1 => true;
  public bool Property2
  {
    get => true;
  }

  public bool Property3
  {
    get
    {
      return field;
    }
    set
    {
      field = value;
    }
  }
}```
#

This class has one field and three different properties

#

the third property has both get and set accessors

#

I think you want to make the property only have a get accessor

#
public interface Selectable {
  public bool IsSelected { get; }
}

public class Whatever : Selectable {
  public bool IsSelected => selected;
  private bool selected;
}
#

e.g.

rose geode
swift crag
#

Can you show an example of a string that has the curly braces in it?

rose geode
#

It is strange that complex hieroglyphs of Japanese or Chinese do not have this error.

rose geode
#

I use a lot of smart strings in localize so I'm not sure which key it's actually failing on

swift crag
#

Hmm, that seems okay. It’s only a problem if you have cyrillic characters in places like “value” or “choose” or “0|1|2” here, I’m pretty sure

rose geode
#

I see what you mean, I will check it again and hope it works.

swift crag
#

You could do that by embedding the package

rose geode
#

I found it manually, I used the auto translate function in google sheets and it produced this string
Соответствует {количество} элементов

Thanks for taking the time to help me.

swift crag
#

You'd copy /Library/PackageCache/com.unity.localization@1.5.3 into /Packages/com.unty.localization@1.5.3, then go and edit the function

#

ah, nice!

#

That sounds like a bug. I'll look at reporting that tomorrow

slender nymph
nimble apex
#

lets say u have 3 int field that u can modify on inspector

public int A;
public int B;
public int C;```
if i turned them into an array

```cs
public int[] Array = new int[3];```
they cant keep the value from the inspector right?
naive pawn
#

you'd have to set them again, yeah

cosmic dagger
#

nope, just set them again . . .

naive pawn
#

there's nothing to indicate that A/B/C are linked to Array

#

also pretty sure you can't restrict the array size like that, setting an array in the inspector is an assignment, it'll just get replaced with whatever size array is set in the inspector

nimble apex
nimble apex
cosmic dagger
nimble apex
#

yeah thats what i talking about

#

i can guarantee there will only be 3 fields needed

#
    public int enFontSize = 60;
    public int tcFontSize = 60;
    public int scFontSize = 60;
    public int[] FontSizeArray = new int[3];```

if u guys curious, thats what im doing now
cosmic dagger
nimble apex
cosmic dagger
#

after you run the method and you check that each element is correctly copied, you can remove the three fields without worry . . .

naive pawn
cosmic dagger
naive pawn
#

but then why are you using an array

cosmic dagger
#

oh, for sure, haha. typically, most people wouldn't do that. though, i will say there are some scenarios where you only want a finite length for an array . . .

naive pawn
#

a limit, maybe? but an exact length doesn't seem like a situation you'd want an array

cosmic dagger
#

wait, isn't that exactly why you want an array?

naive pawn
#

if you have an exact length, that could imply each member is a specific thing. a struct would probably be better for that

#

like this situation

rocky wyvern
#

why not use a class or smt then

naive pawn
#

en/tc/sc FontSize aren't all interchangable, an array doesn't make sense for that. linear structures tend to be homogenous

naive pawn
rocky wyvern
#

probably biggest usecase for using array in a scenario like this is to iterate over elements but I would assume you don't have to do that for smt like this

#

like u just want to set xyz text font size to enfontsize if its set to english right

#

to be honest the 3 variables way sounds better

nimble apex
#

so why the hell we dont use an array to do that at first place?

#
text.fontsize = FontArray[(int)enum]```
you can definitely do this right?
naive pawn
#

why not use a dict for that, so you can benefit from having an enum?

nimble apex
#

because u need to tune the value of the size, if u use dictionary u need to visualize it

naive pawn
#

and you can have a list/array of structs so you can use to initialize that dictionary, if you don't want to manually serialize it, so you can actually use the enum names

#

if you use a list or array to begin with, you don't see the enum order in the inspector, that's more prone to mistakes

#

also with the array, imagine you forget to set one of the values. how would you know which one you forgot to set

#

an indexed container doesn't make sense when your values are specific to each key, each enum key

nimble apex
#

YO WAIT, we actually have one script

#

u never know the whole picture of a 5+ yrs old project💩

#

lets ignore who joe is but hes awesome 👍

naive pawn
#

great, use that

nimble apex
#
[ExecuteInEditMode]
class temp : MonoBehaviour
{
    private void Awake()
    {
        languageChangeText script = GetComponent<languageChangeText>();

        script.FontSize = new FontSizeDictionary()
        {
            { LanguageDataScript.LanguageCodeRes.ENG, script.enFontSize },
            { LanguageDataScript.LanguageCodeRes.CHT, script.tcFontSize },
            { LanguageDataScript.LanguageCodeRes.CHS, script.scFontSize }
        };
        Destroy(this);
    }
}```
#

btw this is the script that i gonna put to generate the dictionary

#

that coderes is enum i mentioned

naive pawn
#

🤨 why's your component in camelCase

nimble apex
rocky wyvern
#

camel for public fields too

vale karma
#

is there a way to create a trailer that can act as a threshold to only call UpdateBakedMesh() when blendcounter is above itself + 2 or something

#

its pretty process intensive, but setting it to every 100 frames instead of every frame helps fps immensely

nimble apex
#

actually no

#

we dont have standards 👍

#

if u really want one standard : as long as it can run with no errors

naive pawn
rocky wyvern
#

and its lazy

#

cant differentiate from local vars

naive pawn
nimble apex
#

btw for exceute in edit mode script, can you destroy the script itself? like remove it from the object

#

destroy is not working tho, because its editor mode?

rocky wyvern
#

yeah

#

destroy happens until the end of the frame

#

try DestroyImmediate

nimble apex
#

i do think execute in edit mode only scripts shouldnt follow monobehavior

#

like u just type functions and it will execute all of them at once

rocky wyvern
#

unity official docs literally say to use pascal case

naive pawn
nimble apex
#

for me , "fields" are just visible "variables", or like buttons on a control panel, they should follow what variables will be on public and private

rocky wyvern
#

Use pascal case for public fields, and use camel case for private variables: For an alternative to public fields, use properties with a public “getter” (see previous and following sections).

nimble apex
#

btw i never use m_xxxxxx to define stuffs

#

or _xxxxxx

rocky wyvern
#

😂 #

#

ok buddy

#

of course its consider

#

they're conventions

#

not the language literally doesn't work if you don't

nimble apex
#

having a small prefixes or symbols in front of namespace is really not used to , my own style is Pascal for all enum classes, public variables, classes and functions

camel for all private/local variables

static follows public/private

fields are visible variables, they will follow what variable should be

naive pawn
#

i don't know of any other languages that use PascalCase for fields either tbh.

rocky wyvern
#

the docs are all over the place

#

i mean ofc they are

#

its not written by one guy

charred spoke
nimble apex
naive pawn
#

nor any code, really

#

using PascalCase for fields would make it overlap with types

#

love me some Rigidbody2D Rigidbody; Rigidbody = GetComponent<Rigidbody2D>();

nimble apex
#

💩

rocky wyvern
nimble apex
#

the naming is more important tho lol

rocky wyvern
#

ur argument makes no sense

#

what if you wanted to use properties

#

which is very well accepted as pascal

naive pawn
rocky wyvern
#

its the exact same as ur example

#

because u gave it a bad name

naive pawn
nimble apex
naive pawn
#

properties in unity are in camelCase too

#

unity uses properties a lot and they're all in camelCase

rocky wyvern
#

zzz ok i cba

naive pawn
#

i couldn't find any "fields" in the docs, i think they might be listed along with properties. ill go check one sec

#

nope seems like they're all properties

#

and they're all camelCase

whole sequoia
#

hey, I Would Like Some Help With My camera and player system. the problem is that my player is not moving the direction the camera is facing, heres the code

naive pawn
#

unless your player is a child of the camera, the camera is rotating freely of the player

whole sequoia
#

oh

#

so anything i can do to fix that

naive pawn
#

you need to apply yaw (horizontal rotation) to the player and pitch (vertical rotation) to the camera, and then have the camera inherit the yaw from the player

whole sequoia
#

i have no idea what how to do that,

charred spoke
#

Simply move your player with tge forward and right of the camera transform instead of his own. Note that if your camera tilts you will have to project the vectors on a plane defined by the up of the player

tame jay
#

hi im working on a project for class and so ive got a textmeshpro - text to keep track of the score but unity is saying it cant find it?

naive pawn
tame jay
#

ive tried that and gotten an error too tho

naive pawn
#

did you import TMPro?

tame jay
#

im p sure i did but ill double checlk

#

ah okay so i did import it initially into unity but not into visual studio

#

thank you!

naive pawn
tame jay
#

err yes, i imported it into the script but that was the issue

north kiln
eternal falconBOT
astral ice
#

my code isnt showing up in visual studio, i asked yesterday but nothing helped

#

NEVA MIND WE FIXED IT

#

but i cant see code line numbers

#

like for example i cant see line 1, 2 etc

burnt vapor
astral ice
#

yeah its fine i worked my way around it but i still dont see them, its weird imo

naive pawn
#

just go enable them in vs options

true lava
#

Anyone have idea to implement this? so my bear ai can get shot because of box collider, when he died he play the dead animation, but box collider still active like he's alive. I need the box collider to adapt to bear dead animation because after the bear dead. player can loot by hit it with melee

teal viper
true lava
#

Ahh okayyy

willow shoal
#

hello what to write next? because I want the character to have a double jump "else" and what next?

#
    public CharacterController controller;

    public float speed = 12f;
    public float gravity = -9.81f;
    public float jumpHeight = 3f;

    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;

    Vector3 velocity;
    [SerializeField] bool isGrounded;

    // Update is called once per frame
    void Update()
    {
        
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if(isGrounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }

        
        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        Vector3 move = transform.right * x + transform.forward * z;

        controller.Move(move * speed * Time.deltaTime);

        if(Input.GetKey(KeyCode.R) && isGrounded)
        {
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }
        if (Input.GetKey(KeyCode.Space) && isGrounded)
        {
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }
        

        velocity.y += gravity * Time.deltaTime;

        controller.Move(velocity * Time.deltaTime);


    }
}
naive pawn
#

wdym what next

#

if you want it to have a double jump, implement that

burnt vapor
naive pawn
#

also why do you have 2 ifs for the same action

#

merge them into a single check

willow shoal
#

i need add else

#

and then what next?

naive pawn
#

what next for what?

#

what is your actual question here?

willow shoal
#

i just dont know what add after this if(Input.GetKey(KeyCode.R) && isGrounded) { velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);

naive pawn
#

to do what?

willow shoal
#

double jump

naive pawn
#

ok, have you researched that at all?

burnt vapor
#

If you want double jump, it's a matter of adding a boolean to check if you jumped once. Then, in your if-statement for jumping you want to check if you either jumped just once or you're grounded.

naive pawn
#

also, again, why do you have 2 ifs for the same action

#

that's going to make it impossible to do any branching conditionals

burnt vapor
#

I suggest you simply add an integer for "jump count". Then when you succesfully jump you increment it. If you then try to jump again, check if the count is equal to 1, and allow a jump again. If it's 0, check for isGrounded. Lastly, 2 always fails

#

The only thing left is setting it back to 0 when you get grounded again.

willow shoal
#

how it work

naive pawn
#

would probably be better to add a bool for that single mid-air jump

willow shoal
#

i will try

burnt vapor
#

The point is not really edge cases. That's up to them

#

Especially since there are plenty of things to consider here, and perhaps their game doesn't have ledges? 🤷‍♂️

queen adder
#
            TileScript choosenTile;

            
            //* Grid Spawn Logic 
            if (choosenTile == null) { //Error use of unassigned local Var

                var randomTile = UnityEngine.Random.Range(1,11) <= 9 ? _grassTile : _mountainTile;
                choosenTile = randomTile;

            }

Why do i get an error here? I want to check if it is null, why don't you let me? If i understand https://stackoverflow.com/questions/9609715/creating-nullable-class is corretly. Classes are automatly nullable, rigth? TileScript? choosenTile; Something like this also didn't work

burnt vapor
#

That said, your code is correct so I can only assume you have left out important bits. Please share all the code if you want to be helped.

#

The only thing I can assume is that this is a local variable, in which case you need to explicitly assign it to null

#

Right now you defined the variable, but it is not assigned

queen adder
burnt vapor
#
-TileScript choosenTile;
+TileScript choosenTile = null;
burnt vapor
keen dew
#

It's not complaining about checking against null. It's saying that you haven't assigned a value to the variable.

burnt vapor
#

All those yellow lines are spots where a variable can potentially be null but you have not handled it that way

burnt vapor
#

I do have to mention that in the case of Unity a lot can be wrong so I generally add it and then use what's called a "null-forgiving operator" on the spots that are incorrect.

queen adder
#

Thanks

willow shoal
#
    public CharacterController controller;

    public float speed = 12f;
    public float gravity = -9.81f;
    public float jumpHeight = 3f;

    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;
    
    Vector3 velocity;
    [SerializeField] bool isGrounded;
    [SerializeField] bool secondJump;

    // Update is called once per frame
    void Update()
    {
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if (!isGrounded)
            secondJump = false;

        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }


        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        Vector3 move = transform.right * x + transform.forward * z;

        controller.Move(move * speed * Time.deltaTime);


        if (Input.GetKey(KeyCode.Space) && isGrounded)
        {
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
            secondJump = true;
        }
        else if (Input.GetKey(KeyCode.Space) && secondJump)
        {
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
            secondJump = false;
        }
        velocity.y += gravity * Time.deltaTime;

        controller.Move(velocity * Time.deltaTime);


    }
}```
#

which line is wrong because I don't have an error and the character doesn't double jump

#

secondJump not working

naive pawn
#

you're making secondJump false when you jump the first time, instead of refreshing the jump

willow shoal
#

wait i will check

naive pawn
#

you don't need secondJump = true in the first check

willow shoal
#

oh yeah

#

thanks for help

naive pawn
#

also, use GetKeyDown instead of GetKey so it only triggers on the first frame that it's pressed instead of doing the second jump right after the first

willow shoal
#

ok

#

everythink work

#

thanks

burnt vapor
#

Perhaps you're still interested in learning a bit of debugging regardless, but that's up to you

sage steppe
#

Heya, im testing around a bit with AI using tutorial vids and im running into an issue where my AI wont pick up the player game object, im not sure why since the player is called "Player" which is the same name that the game object finds and assigns but I keep getting null instead, any help would be greatly appreciated, my code for the AI is below.

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEditor.Rendering;
using UnityEngine;
using UnityEngine.AI;

public class RKTiMove : MonoBehaviour
{
public bool isHostile;

public Transform currentWayPoint;
[Space(12)]

public NavMeshAgent AiAgent;

GameObject Player;
[Space(12)]
public float distToPlayerAttack;

public float speed = 3;

// Start is called before the first frame update
void Start()
{
    Player = GameObject.FindWithTag("Player");

    if (Player == null) {
        print("Player is null");
    }
}

// Update is called once per frame
void Update()
{
    if (!isHostile)
    {
        AiAgent.SetDestination(currentWayPoint.position);
        return;
    }else
    {
        print("Else statement worked");
        float DistToPlayer = Vector3.Distance(transform.position, Player.transform.position);
        if (DistToPlayer < distToPlayerAttack)
        {
            print("speed is 0 bozo");
            AiAgent.speed = 0;
        }
        else
        {
            print("cooking the speed rn");
            AiAgent.speed = speed;
        }

        AiAgent.SetDestination(Player.transform.position);
    }
}
private void OnDrawGizmosSelected()
{
    Gizmos.color = Color.red;
    Gizmos.DrawWireSphere(transform.position, distToPlayerAttack);
    
}

}

wintry quarry
sage steppe
#

Yeah

wintry quarry
#

If that's printing then indeed you don't have an active GameObject named Player in the scene

#

At least, not at the moment this script's Start is running

#

Make sure you actually have such an object in the scene

sage steppe
#

maybe the enemy loads before the player?

wintry quarry
#

you're using FindWithTag

#

not Find

#

So it needs to be tagged Player

sage steppe
#

ooh

wintry quarry
#

In the future for posting code: !code

eternal falconBOT
swift crag
#

The start order could definitely matter if you did something like this

sage steppe
swift crag
#
void Start() {
  gameObject.tag = "Player";
}

and then elsewhere:

void Start() {
  var whatever = GameObject.FindWithTag("Player");
}

gotta watch out for that kind of thing 😉

#

but yes, I think you're just missing the tag here!

sage steppe
#

actually where would i drag it since i dont see any specific Player thing here

wintry quarry
#

there's nothing to drag

sage steppe
#

nvm uhh i mean like how would i tag my player to it

wintry quarry
#

You need your player object to have the "Player" tag.

#

Select the player object

#

and change its tag to Player

naive pawn
wintry quarry
#

He was illustrating a possible source of a bug

#

not a suggested thing to do

naive pawn
#

ah, mb

#

i missed a bit of context and got confused with the rest of the messages 😅

sage steppe
#

its def working better

swift crag
sage steppe
#

Thank you! got it working now

silk scroll
#

I'm using a CharacterController and ProBuilder and for some reason, OnCollisionEnter is never being called.

fluid remnant
silk scroll
#

That doesn't work either tho.

fluid remnant
silk scroll
#
void OnControllerColliderHit(ControllerColliderHit hit)
        {
            LavaBounce bounce = hit.gameObject.GetComponent<LavaBounce>();

            if (bounce)
            {
                Rigidbody playerRb = GetComponent<Rigidbody>();
                playerRb.AddForce(Vector3.up * bounce.bounceForce, ForceMode.Impulse);
                
            }
        }```
#

i mean the code is just the void.

#

i don't know why it doesn't trigger

polar acorn
#

How do you know it's never being called

#

Have you put a log in the function? Maybe log bounce before it's checked?

silk scroll
#

I have put a log in yeah

#

I put a log to log just anything that collides and none of the Probuilder meshes are triggering it

runic lance
#

by the way, why is that people are referring to functions as "void" nowadays? 🤔

swift crag
#

it's a common error

polar acorn
#

And they don't know what "void" means

swift crag
#

void is just the return type of the function

runic lance
#

yes, but where does this comes from?

swift crag
#

it's the only keyword in the function's declaration

#

other languages might make you write, say, func Foo() or something like that

polar acorn
silk scroll
#

geez okay

silk scroll
#

I just added Debug.Log(hit);

polar acorn
silk scroll
#

The Player has a CharacterController yeah, and the other object has a Mesh Collider

#

it's a ProBuilder object so MeshCollider comes on it by default

swift crag
silk scroll
#

Yeah, the player capsule

snow warren
#

is there any API in unity 3d texture that allows me to copy blocks of one texture image to another texture image with how i flip the image

swift crag
#

to rule out it being something with ProBuilder, add a cube to the scene and try moving into it

#

Also, it's important to note that you have to move into the collider to get a message here. If you don't add gravity, and you're just walking around on a flat surface, you will not receive messages

silk scroll
#

Alright, well I've tried jumping on it

#

I'll try the regular cube

snow warren
#

Hey
Guys

I am having some trouble

i wanted to import image sharp library inside unity but there is a problem

i cant use the System.Runtime.Intrinsics

i thought unity6 uses Net 8

and Memory Intrinsics was defined in .Net 5+

I dont know what to do now
any helps are appreciated

#

and all i can find by googling Intrinsics is a C++ native memory intrinsics library that .Net have bindings for

queen adder
#

If i have a class that has another class in it, something like this public class JokerShop : JokerBase
What's the term for this, is nested Class correct?(for future google searches ) And how to acces the JokerShop Class properly?``` JokerBase MyJoker = XY
Myjoker.JokerShop.DoSomethingThatsOnlyInJokerShop;
JokerShop MyJokerShop = MyJoker.Get-JokerShop(SubClass) and save as new Variable

polar acorn
#

If you want to do something that is only in JokerShop, the variable needs to be of type JokerShop

queen adder
#

Thank you !

silk scroll
naive pawn
silk scroll
#

so then how would I create a spring pad using Character Controller

swift crag
#

The Rigidbody wants to move the object around after each physics update (if interpolation is off), whilst the CharacterController is moving whenever you tell it to

swift crag
#

you shouldn't need to do that

silk scroll
#

No, it still does nothing

#

I guess I'd have to put an invisible cube over the ProBuilder object as a workaround.

swift crag
#

You can use that to decide how much to move in the next frame

#

You could also just store a separate "spring velocity" that rapidly decays to zero over time

#

and add that into your movement each frame

#

Lots of options there -- you're inventing your own physics :p

delicate portal
#

How do I change fog settings in code?

#

These settings

swift crag
#

I don't remember how to fetch that..

#

Oh wait, they're all static properties!

#

So you'd do RenderSettings.fog = false; or whatever

slim lark
#

New to Unity, I'm trying to figure out how to "project" a png with transparency onto whatever is nearest on its path. Ideally warping to whatever is currently below it.

Literal description is it's a crosshair shaped light projecting down onto a moving tray.

I tried setting up URP to do it but some of the assets I can't replace don't have compatible shaders for URP. If it matters, this is for a VR project.

red igloo
#

Hi, I am trying to make a simple pick up and drop system where when the player looks at an item like a flash light and presses E the item is picked up and press Q to drop the item. This is my script just a simple ray cast how can I make it so when you look at an item and press E you pick the item and press Q to drop it. I am very confused on how to do it. https://paste.ofcode.org/FvimTSGeLNVhdN3t4asNLK

swift crag
steep rose
swift crag
#

Ah, I misunderstood -- I thought you were using URP already

red igloo
steep rose
#

you would also have to find which object the raaycast hit by either using a tag/layermask (not really recommended) or some other script which tells your grab script what it is

upbeat steppe
#

hi im super new to unity and i dont understand whats wrong with my code. can anyone help me?

steep rose
#

what is the issue, as they're many

cosmic quail
eternal falconBOT
cosmic quail
#

⬆️ fix your ide so it underlines your typos

upbeat steppe
steep rose
cosmic quail
swift crag
#

Note that, if you need to install a new package to get your IDE working properly, that won't be possible while you have compile errors.

#

You may need to get rid of the script to set that up properly

upbeat steppe
#

yeah but im dumb as hell i dont what a IDE is

swift crag
#

(just move it out of your Assets folder)

steep rose
#

also you do not need if(_Inputx != 0) as InputX will be zero already if not input is added, you are also using addforce in Update instead of FixedUpdate

swift crag
#

an IDE is an integrated development environment

cosmic quail
swift crag
#

a text editor that also has features like syntax highlighting and text suggestions

steep rose
#

also unnecessary usage of getcomponent and assignment in the start function (just use the inspector)

upbeat steppe
#

🙏

naive pawn
steep rose
#

I mean if you don't need to get it on runtime just use the inpector to assign it

#

that would be the easiest solution

naive pawn
#

getting components on the current gameobject via getcomponent in start/awake is pretty standard

steep rose
#

well yes, but that is for when you want to get it on runtime. I don't really see any need to do that except if you just don't want to do it manually

naive pawn
#

what need is there to do it via the inspector?

steep rose
#

it is easier

naive pawn
#

but that is for when you want to get it on runtime.
no, static components are generally retrieved like this too

naive pawn
steep rose
naive pawn
#

no, dragging the wrong component wouldn't be an issue.

#

dragging the wrong object would be

#

that's not an unreasonable mistake, just dragged the wrong object, and a beginner might not think to debug that

steep rose
#

yes a wrong component from another gameobject , Also most people should know how to use their brains to figure out a problem, no?

naive pawn
#

it's an extra step that might result in bugs.
assigning it directly wouldn't. and forgetting either would result in an error either way

naive pawn
#

they don't know where to start

steep rose
#

its critical thinking, and using the tools they have to figure out solutions

naive pawn
#

or you could recommend something that isn't likely to result in bugs

steep rose
#

this is why you would teach them to use the inspector

naive pawn
naive pawn
steep rose
#

such as assigning a rigidbody and floats as they have in their script, also if you saw a field that was unassigned not only would unity tell you through errors it is as simple as dragging and dropping the correct component into it. I'm not saying the getcomponent method is bad but for this situation it would be better to use the inspector as that is what it is for.

#

this is also a good way to teach people to actually think instead of mindlessly doing things, as they will see the error and wonder how to fix it/tinker with it