#💻┃code-beginner

1 messages · Page 312 of 1

languid spire
#

you changed the wrong = to +=. Please think a little about what you are doing

reef totem
#

u told me to

languid spire
#

I told you to change = to +=. I expected you to be sensible enough to know which one

reef totem
#

ok

#

one last question

#

how to i know how many units my cube will move foward

languid spire
#

well according to your code it is test*Time.deltaTime so that will be 2 units / fps

reef totem
#

since the variable test only controls the speed of the cube im geussing

reef totem
languid spire
#

probably not as I don't know what you are trying to achieve

reef totem
#

thats litteraly it

summer stump
#

There is more to it than that

languid spire
#

ok, but over what time scale?. You have not thought this through

polar acorn
summer stump
#

How it transitions between those states is a huge part of it

reef totem
summer stump
#

They want to know how fast you want it to move

reef totem
#

like idc

languid spire
summer stump
#

But just try dotween as linked above

reef totem
#

maybe like 0.5 units per second..

reef totem
polar acorn
# reef totem like idc
transform.Translate(5 * Vector3.forward);
transform.Translate(-5 * Vector3.forward);

There it's now moved 5 units forward then backward

zenith cypress
#

"why is it not moving" Kappa

reef totem
#

huh

reef totem
#

but i mean it makes sense

polar acorn
reef totem
#

both these command are being run at the same time so ofc its not gonna move

polar acorn
#

Since the time doesn't matter, this does solve your problem

polar acorn
#

unless, of course, time does matter and you need to decide on what you actually want to be happening

summer stump
reef totem
reef totem
#

this is the speed

summer stump
polar acorn
#

Keep track of how much you're moving each frame, check if it's equal or greater than 5, then reverse it

summer stump
#

Ah yes, my initial suggestion 😂

reef totem
#

but then im changing it based on how much time it takes and not on how many unit it takes

#

if that makes sense

summer stump
#

You are changing by the units distance with digi's suggestion

#

It will not be affected by time at all

reef totem
#

can u give me some code to copy and paste so i dont look like an idiot

#

and accidently type the wrong thing

reef totem
#
    public float units= 5f;
    void Update () 
    {
       transform.Translate(units*Vector3.forward * Time.deltaTime);
       
       transform.Translate(-units*Vector3.forward * Time.deltaTime);
    }
#

so i change units from 5 to 0.5

#

thats what your suggesting

#

i dony understand

summer stump
#

Not even a little

polar acorn
reef totem
#

yes i know

#

thats why im sooo confused

summer stump
#

One Translate call total

reef totem
polar acorn
#

So, how about you work through the suggestions, try to come up with a full solution, then post that, instead of trying to get confirmation for every intermediate step

reef totem
#

ok fine

#

but im trying to confrim every immediate step because if i dont i will just be judge and feel like shit

summer stump
polar acorn
#

I'll give you the necessary information in the form of a bulleted list:

  • You can translate an object by "X units per second" by multiplying X by Time.deltaTime as you pass it into Translate
  • If you store that value in a variable, you can add that to a running total to know how much you've moved an object by
  • If you check that running total, you can know if you've moved an object 5 units
  • If you multiply the speed by -1, you can start moving the same speed in the opposite direction
reef totem
#

also im been trying this for like the past hour and ive watched tutorials so its not like i didnt try

reef totem
polar acorn
summer stump
reef totem
languid spire
reef totem
#

im new to this

rich bluff
#

lets not doubt the effort put in, and instead be patient and try to explain

reef totem
#

this is all confusing

rich bluff
#

narrow down the source of confusion

polar acorn
languid spire
# reef totem im new to this

which is why you should be thinking about every single little thing you do and work out in your head what that actually does

polar acorn
#

but it's not complicated enough to need one

rich bluff
#

coroutines serve a specific purpose - they give you asynchronicity

#

they allow you to pause and continue execution later

#

if the task you are trying to solve can be fully done in update, every frame, then coroutines are not necessary

reef totem
polar acorn
languid spire
rich bluff
#

at least in my experience, the topic can get voodoo

languid spire
reef totem
#

i swear i do no undertsnad the bullet points for the life of me

#

ive been reading them over and over gaain

#

i didnt undertsna dexaplanaition

polar acorn
reef totem
#

so far i have 2 variables

#
    public float unitSpeed = 5f;
    public float totalUnits;
rich bluff
#

you want to know how far the object travelled?

reef totem
#

yes

rich bluff
#

how do you know how much the object has travelled in one frame?

reef totem
#

I dont

rich bluff
#

how does your object know how far it has to go in one frame?

reef totem
#

unfortunatly

rich bluff
#

but it does move?

#

using Translate

reef totem
#

yes

rich bluff
#

so somehow you already have that distance

#

otherwise the object wouldnt move

reef totem
#
   public float unitSpeed = 5f;
    public float totalUnits;
    void Update () 
    {
       transform.Translate(Vector3.forward * unitSpeed* Time.deltaTime);
    }
#

this is all i have

rich bluff
#

what Translate does?

reef totem
#

move an object

rich bluff
#

how does it know how far to move?

polar acorn
rich bluff
#

it should click soon

reef totem
#

would x in this case be unit speed

#

im sorry

#

im just soo confused

rich bluff
#

you have transform.Translate( distance/direction )

#

your Vector3.forward is a vector3 (0,0,1)

#

one unit on z

reef totem
#

correct

rich bluff
#

which you multiply by 5, then by some time.delta value like 0.01

#

which will be the final distance and direction the object will move

#

(0, 0, 0.05)

polar acorn
rich bluff
#

so you can express your code like

#
Vector3 distance = Vector3.forward * unitSpeed* Time.deltaTime;
transform.Translate(distance);
#

technically its not distance, i call it offset, since its a vector, not a scalar

#

but you can get the scalar with distance.magnitude

reef totem
#

so this is bassicly the same code by rephrased differenly

#

and then i times distance by something

rich bluff
#

remember the bullet point

reef totem
#

by speed

#

no

rich bluff
#
  • If you store that value in a variable, you can add that to a running total to know how much you've moved an object by
summer stump
summer stump
#

distanceMoved += distance....
if distanceMoved > threshold

reef totem
#

i kinda undstand now bc i sort of have this with my player script

#
 Vector3 move = transform.right * playerX + transform.forward * PlayerZ;

        characterController.Move(move * speed * Time.deltaTime);
summer stump
reef totem
#

ik

summer stump
#

Ok just making sure

reef totem
#

but im saying that this is sort of similar

rich bluff
#

i always prefer to create local variables that express intent

#

cramming everything into parameters or conditionals makes it hard to understand code at a glance

summer stump
#

That is a good practice for sure.

#

I do that with bools too, then my if statements are very short and clear

rich adder
#

always put V3 last in the calcualation

#

floats first (slight efficiency microptimization)

reef totem
#
    public float unitSpeed = 5f;
    void Update () 
    {
        Vector3 distance = Vector3.forward * unitSpeed* Time.deltaTime;
       transform.Translate(distance * Time.deltaTime);
    }

so this is bullet point 1 complete

rich bluff
#

incorrect

reef totem
#

fuck

polar acorn
#

Actually, correct

rich bluff
#

you have double delta multiplication

queen adder
#

hey

polar acorn
#

Oh, wait

#

right

#

I didn't notice that

reef totem
polar acorn
#

it is, indeed, incorrect

reef totem
#

ok

#

no i deleetd delta time number 2

rich bluff
#

in this case yes

reef totem
#

so now bullet point 1 is complete

#

moving on to bullet point 2

fervent mulch
#
public class groundCheck : MonoBehaviour
{
    public bool isGrounded;

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Ground"))
        {
            isGrounded = true;
        }
    }```
I want chatgbt to prevent the jumping animation if the player presses the space key and jumps, even if I press the space key again while in the air.
#

He suggested me some operations, I did them all, but this time the jump animation does not work at all.

rich adder
#

use your brain

reef totem
#

whats a running total

#

u need that bullet pint number 2

fervent mulch
#

I wonder if the problem is because I did not set the** gameObject** text as groundCheck?

reef totem
#

@rich bluff

polar acorn
reef totem
#

to what

fervent mulch
polar acorn
#

A "running total" is just a variable that you keep adding to

reef totem
#

give an example

rich adder
polar acorn
reef totem
#

fair enough

fervent mulch
reef totem
#

so how do i add distance to a running total

queen adder
fervent mulch
rich adder
reef totem
polar acorn
queen adder
reef totem
polar acorn
rich adder
#

what did you do that was not good?

final kestrel
#

Why do people say singletons are bad and we should not rely on them and stuff. Do I just not learn how to use them?

fervent mulch
rich adder
#

everything is bad if you over use it

final kestrel
polar acorn
rich adder
#

but most say singletons are bad are click baity videos

hexed terrace
final kestrel
rich adder
fervent mulch
#
public class groundCheck : MonoBehaviour
{
    public bool isGrounded;

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Ground"))
        {
            isGrounded = true;
        }
    }```
#

how can i fix

reef totem
fervent mulch
#

please teach me

reef totem
rich adder
# fervent mulch how can i fix

you're better off following a proper structured course instead of a spambot
there is literally no condition here to tell it where its not grounded

polar acorn
summer stump
#

I don't understand what part is unclear

#

You make a variable called distanceMoved

reef totem
summer stump
#

You add distance to it

summer stump
polar acorn
reef totem
#

thats more clear

summer stump
#

And it was pseudocode at that, which basically is plain english

rich bluff
#
Vector3 one = Vector3.one;
Vector3 two = one + one;
Vector3 three = two;
three += one;
rich adder
reef totem
#

fuck im done

fervent mulch
rich bluff
#

your brain is rewiring to think like a programmer, takes time

rich adder
reef totem
rich bluff
reef totem
#

nvm

summer stump
polar acorn
reef totem
#

i just need a break

#

like 30 minutes

polar acorn
#

You've just kept saying "pls give me code to copy" and then when someone does you say "pls english"

rich bluff
#

usually sleep is what helps the most in this

final kestrel
#

What people here suggest will make no sense if you do not even know what you're trying to understand.

willow scroll
rich adder
fervent mulch
rich adder
#

Yes because blindly following the GPT wont get you to learn anything..

#

if you want to truly learn, then start with courses on the basics. Get a box to move etc..

fervent mulch
final kestrel
#

I was following gpt as well then It got so complicated I had to reset my brain and start from scratch.

#

maybe that works for you as well

rich adder
#

they are simple , often wrong search engines

willow scroll
rich adder
#

LLMs are not smart

#

they are just globs data

willow scroll
#

This clearly doesn't make any sense, as you simply won't be able to follow the basic instructions you're given

rich adder
#

where the "make polished game for me" button

queen adder
# rich adder what did you do that was not good?

i tried this but idk```csharp
using UnityEngine;

public class PlayerController : MonoBehaviour
{
public float maxSwingAngle = 45f;
public float swingSpeed = 1f;

private Rigidbody2D rb;
private float currentSwingAngle;

void Start()
{
    rb = GetComponent<Rigidbody2D>();
}

void Update()
{
    currentSwingAngle = Mathf.DeltaAngle(0, transform.rotation.eulerAngles.z);

    float swing = Mathf.Abs(currentSwingAngle) / maxSwingAngle;

    float currentSwingSpeed = swingSpeed * (1 - swing);

    rb.AddTorque(currentSwingSpeed);

    float clampedAngle = Mathf.Clamp(currentSwingAngle, -maxSwingAngle, maxSwingAngle);
    transform.rotation = Quaternion.Euler(0, 0, clampedAngle);
}

}

dim sentinel
#

Can anyone please help me with an issue where my FPS camera jitters a little bit? I think I have the problem down to the rb rotation but I dont know what would be the correct fix

summer stump
willow scroll
# fervent mulch no

So questioning you "why is the line ... doing ..." won't give any proper answer, as you have non idea what a single character in your code is doing

rich bluff
#

interpolate it to player position

rich adder
dim sentinel
#

Ill try that

rich bluff
#

its a standard thing, camera rig being separate from the physical

dim sentinel
#

but even removing deltatime i still have it

#
    private void CameraMove()
    {
        float mouseX = Input.GetAxisRaw("Mouse X") * sensitivityX * Time.fixedDeltaTime;
        float mouseY = Input.GetAxisRaw("Mouse Y") * sensitivityY * Time.fixedDeltaTime;

        if (cameraPlayer != null)
        {
            rotationY = mouseX;
            rotationX -= mouseY;
            rotationX = Mathf.Clamp(rotationX, -60f, 57f);

            cameraPos.localRotation = Quaternion.Euler(rotationX, 0f, 0f);
            rb.MoveRotation(rb.rotation * Quaternion.Euler(0f, rotationY, 0f));
        }
    }```
#
    void FixedUpdate()
    {
        MovePlayer();
    }

    void Update()
    {
        grounded = Physics.Raycast(transform.position, Vector3.down, height * 0.5f + 0.2f, ground);

        MyInput();
        DragControl();
        SpeedControl();
        Hotkeys();
    }

    void LateUpdate()
    {
        CameraMove();
    }```
rich adder
rich bluff
#

oh you are moving camera in Fixed?

rich adder
#

dont get inputs inside fixedupdate

dim sentinel
rich bluff
#

yes

#

want smooth camera do it in update

rich adder
#

store it in a V2 to use in fixedupdate

#

everything else looks fine (aside from cameramove not being in update)

summer stump
#

You will have to reduce the sensitivity a lot when you remove it btw

rich adder
#

only line that should be in fixedUpdate rb.MoveRotation(rb.rotation * Quaternion.Euler(0f, rotationY, 0f));
rest of CameraMove in Update

dim sentinel
willow scroll
rich adder
dim sentinel
#

    void Update()
    {
        MovementInput();
        CameraInputs();
        DragControl();
        SpeedControl();
        Hotkeys();
    }

    void FixedUpdate()
    {
        MovePlayer();
    }

    void LateUpdate()
    {
        CameraMove();
    }


 private void CameraInputs()
    {
        float mouseX = Input.GetAxisRaw("Mouse X") * sensitivityX;
        float mouseY = Input.GetAxisRaw("Mouse Y") * sensitivityY;

        rotationY = mouseX;
        rotationX -= mouseY;
        rotationX = Mathf.Clamp(rotationX, -60f, 57f);
    }

    private void CameraMove()
    {
        cameraPos.localRotation = Quaternion.Euler(rotationX, 0f, 0f);
        rb.MoveRotation(rb.rotation * Quaternion.Euler(0f, rotationY, 0f));
    }
slender nymph
#

obligatory: use cinemachine

willow scroll
rich adder
dim sentinel
rich adder
dim sentinel
rich adder
dim sentinel
#

ill try doing the cameralocalrot

willow scroll
willow scroll
rich adder
#

prob

willow scroll
dim sentinel
dim sentinel
willow scroll
dim sentinel
willow scroll
#

Your rotation is set to one of those:

  • rb.rotation * sensitivityX
  • rb.rotation * -sensitivityX
  • 0
#

Is that what you want?

dim sentinel
#

I think its close to what I want

willow scroll
#

And yeah, there's no value in between, as that's the raw

dim sentinel
#

I can take a screen record to show you

willow scroll
dim sentinel
willow scroll
dim sentinel
#

it doesnt make it embed weird is that only for mp4?

slender nymph
#

use mp4 to embed in discord

dim sentinel
#

so the camera is moving okay mostly but when rotating the rb it seems to jitter a bit and its more evident on moving objects

willow scroll
#

mkv embed is not supported

rich adder
# dim sentinel

this looks to be more related to your movement than rotation

#

as its more visible while strafing

dim sentinel
#

but its only when both of those actions happen at the same time

#

when moving or rotating isolated it doesnt happen

willow scroll
# dim sentinel

Are you talking about the player slightly jumping when running?

rich adder
#

!code

eternal falconBOT
dim sentinel
willow scroll
#

Well, I feel like I don't see any camera jittering.

dim sentinel
rich adder
#

cam move in LateUpdate ?

#

which has rb.MoveRotation(rb.rotation * Quaternion.Euler(0f, rotationY, 0f)); ?

#

how it make sense to move Rigidbody on FixedUpdate but rotate it in LateUpdate ?

dim sentinel
dim sentinel
#

and ik it doesnt make sense to rotate rb outside fixed update but it just doesntlike fixed update for some reason

rich adder
#

how

willow scroll
dim sentinel
# rich adder how

I have no idea but putting the codes you suggested in fixed update just make it worse

dim sentinel
rich adder
dim sentinel
#

   void FixedUpdate()
    {
        rb.MoveRotation(rb.rotation * Quaternion.Euler(0f, rotationY, 0f));
        MovePlayer();
    }

willow scroll
dim sentinel
#

I might be reaching here but could it be my monitor refresh rate being 75?

#

it does make it slightly better when set on 60

willow scroll
dim sentinel
#

Its such a small jitter that makes me feel like something is wrong but its there

willow scroll
dim sentinel
#

but ive ran out of ideas as to what is wrong with the script

safe ingot
#

guys can you help for some reason i cant put inputTextfield to script

willow scroll
willow scroll
#

Perhaps you've made them TMP_InputFields

dim sentinel
rich adder
#

it has no problems like this

dim sentinel
rich adder
#

dealing with velocity is a pain sometimes

dim sentinel
#

are there any tradeoffs?

safe ingot
dim sentinel
rich adder
#

oh and you'd have to create your own accelerations/deceleration if you want that, but thats easy to do with Lerp/Animation curves

ivory bobcat
#

Otherwise, you aren't losing much other than the availability of tutorials (cc is a bit less popular than rb)

rich adder
willow scroll
dusk minnow
#

i need some help, this somehow logs null always, idk why#

willow scroll
#

Perhaps.. about the script..?

dusk minnow
#

why i wanna get the child and of each the inputfield component

#

only that part doesn work

rich adder
#

you mean grab input fields on each child?

dusk minnow
dusk minnow
willow scroll
#

And now, please, tell what this script is attached to

dusk minnow
#

i have the header in which are the childs "player" and player has a child "name" and in it is the input field

rich adder
#

you're looking for InputField but you have TMP ones

dusk minnow
#

how do i get tmp ones

rich adder
#

so change the type

willow scroll
#

I haven't mentioned it notlikethis

dusk minnow
#

they dont show

willow scroll
rich adder
willow scroll
#

I thought the script is attached to the wrong object first, which wasn't mentioned

rich adder
#

I always assume some new popular tutorial that shows wrong UnityChanLOL

#

the next brackys 😎

dusk minnow
willow scroll
rich adder
dusk minnow
#

to both of you

dusk minnow
#

lol

willow scroll
rich adder
willow scroll
#

Oh, I see, there are, yeah

rich adder
dusk minnow
willow scroll
#

You could have used google too

rich adder
#

you can like shorten that btw

#

they probably meant they didn't know it had different classes / namespaces

willow scroll
#

got it

rich adder
#

unity kinda confused the whole situation, as typical unity fashion

languid spire
rich adder
willow scroll
rich adder
#

unity search function only cares about ?q=

languid spire
#

people need to learn how to google, the most important key word first not last

rich adder
#

good googling skill is a dying breed sadly 😦

languid spire
#

if you want only unity results start the search with 'Unity'

rich adder
#

people dont you you can also do shit like
site:unity.com etc

#

ah i miss highscool computer class

willow scroll
final kestrel
#

I usually put "Unity" last T_T

languid spire
#

they should never have stopped teaching reverse polish notation

rich adder
#

yeah order doesn't matter that much sometimes

languid spire
#

oh yes it does

rich adder
#

some times it doesnt even care if you put Unity inside, I still get results if its specific Unity concept like GameObject

final kestrel
#

Noted

rich adder
#

not really

languid spire
#

Text mesh pro is Unity specific

#

try UI Elements Unity or Unity UI Elements

rich adder
#

hmm yeah slightly different but not by much

#

but yeah I did say sometimes, but mostly you will get in the ballpark of what you need

languid spire
rich adder
#

true but slightly bad googling better than no googling

languid spire
#

also true

rich adder
#

gotta take those small wins 😆

languid spire
#

yeah, extrapolate from google to youtube and you end up with a shit show

rustic maple
#

Argument 1: cannot convert from 'method group' to 'string', i got this error message after i editited my script but how do i know where to put "ToString"?

rich adder
#

show line of code of error

rustic maple
#

cuz i have followed a tutorial from someone to make flappy bird, and after that i followed someone others and edited in my script but now its giving errors

rich adder
#

that doesn't answer my question

rustic maple
rich adder
#

there is a huge different if you typed it like that

languid spire
rich adder
#

just remember, methods require ()'s

rustic maple
#

yeah sorry

#

gameOverScreen.SetActive(true);

rich adder
summer stump
#

Hmmmmmmmm. Are you sure that is the error line?

languid spire
#

that line will not give the error you showed

summer stump
#

Did you save it?

rich adder
#

you're most likely doing this

    int score;
    private void Method()
    {
        string someText = score.ToString;
    }```
rustic maple
#

i dont understand a thing about coding 😭😭

rich adder
eternal falconBOT
#

:teacher: Unity Learn ↗

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

strong wren
thorn tapir
#

Hi guys i just want to ask how to blend wasd movement? like if i press W and D at the same time the object goes north east

#

script so far:

#

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

public class aswrd : MonoBehaviour
{
public float moveSpeed = 5;
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
    if (Input.GetKey(KeyCode.D))
    {
        transform.position += Vector3.right * moveSpeed * Time.deltaTime;

    }
    else if (Input.GetKey(KeyCode.A))
    {
        transform.position += Vector3.right * -moveSpeed * Time.deltaTime;

    }

    else if (Input.GetKey(KeyCode.W))
    {
        transform.position += Vector3.up * moveSpeed * Time.deltaTime;

    }
    else if (Input.GetKey(KeyCode.S))
    {
        transform.position += Vector3.up * -moveSpeed * Time.deltaTime;

    }
}

}

rich adder
strong wren
#

dont use Else

thorn tapir
#

damn yall are quick

rustic maple
#

i fixed it!

strong wren
#

idk how to explain it lol

wintry quarry
#

delete the rest

rich adder
strong wren
thorn tapir
rustic maple
#

just readed wrong and went to the script where the error really was and deleted a line lol

summer stump
strong wren
rich adder
rustic maple
#

it was a whole empty line and when i deleted that the error was gone

rich adder
#

You probably saved it and refreshed script from previous state

wary sigil
#

does anyone know how to write a script that would randomly swap the location of 3 identical gameobjects when a button is clicked?

rustic maple
#

yeah i think thats it because i typed a script before and that one didnt work and i probably didnt save after i removed

rich adder
rich adder
thorn tapir
#

Is there a way to make like the game testing background not blue? is there an option or is it always like that

rich adder
#

under Solid Color

thorn tapir
#

ohhhhhhhhhh

wary sigil
formal escarp
#

Hey guys, how its called that little box where you can checkmark it? Sorry. im a bit stuck on getting the name of it, i know its not the transform or anything like that but i cant remember the name or how to do it.

#

i want it to become true i forgot to say lol

rich adder
green ether
#

.SetActive(true)

#

on the gameObject

green ether
#

.enabled on components

formal escarp
wintry quarry
#

GameObject.Find is NOT going to find inactive objects

formal escarp
wintry quarry
#

You should directly reference the object in the inspector

wary sigil
rich adder
#

this is not a code question
google them

formal escarp
thorn tapir
rich adder
#

popular is Asprite

wary sigil
rare basin
#

and put debug log inside that addlistener to see if it works

#

you can make that method public and drag&drop it to onclick even on the button directly in the inspecot

scarlet skiff
#

how do i spawn something using the canvas coordinates? its an UI image that imma have as an effect (the fly in the picture) and i want flies to be able to spawn on the screen to cover everything

obtuse osprey
#

im starting a 2d game would it be easier making the map with textures and using a tilemap in unity or making it in gimp also would this effect the code?

rich adder
#

depends on style of game levels 🤷‍♂️ also not code question

rare basin
rich adder
#

AddListener is much better imo

rare basin
#

it depends

rich adder
#

inspector is useful for UnityEvent that needs to be modular

#

but its a nightmare to know whats linked in the button whats not

rare basin
#

ok

fast glade
#

Would you prefer to use stack instead of a list in an ObjectPooler?

rich adder
wary sigil
rich adder
#

nah

#

add the log , thats more important

#

AddListener(Swap) is fine

fast glade
obtuse osprey
wary sigil
rich adder
rich adder
#

you already have a log in there it seems, is it printing ? etc.

rare basin
#

so becareful with that

wary sigil
scarlet skiff
south plover
#

If you have multiple scenes for different areas in your game, and you have for example an item, or ui, or an inventory screen, and you modify or update that item with new stuff on it,
how do you make that change be available across all levels so you dont have to go to every scene and carefully replicate the item/behaviour?

rich adder
wary sigil
rich adder
#

check Event System in playmode

#

it tells you

wary sigil
rich adder
#

if you don't see the window its collapsed at bottom , click it

wary sigil
#

so like this?

rich adder
#

thats not the event system

hexed python
#

I just wanna say again thanks to everyone here who answers questions! After the other day I was reading and rereading the explanations you guys were giving me, trying out the things I didn't understand, and now I've got my code in a pretty nice place!

I'm essentially able to make any kind of ProjectileSpell from a single scriptable object now (and that spell can be set in the inspector for all sorts of things like speed, range, recoil, if it's explosive, the prefab and particle effects)

Then I can literally just slap that spell on my Players or Enemies SpellManager, and it all just works so nicely!

Next step I'm gonna expand and work on a DefenseSpell and MeleeSpell scriptable objects with the same principals

wary sigil
summer stump
wary sigil
#

OK I figured it out!

#

Thanks for all your help!

calm hare
#

yo im trying to make my character move and the script has 0 errors but the character still isnt moving can anyone tell me why heres the script :

grizzled fulcrum
#

So I just tried to build the game for a test, and I'm getting these errors when trying to build it, any tips as to what's wrong?

#

This is the Menu script btw, for reference

slender nymph
eternal falconBOT
calm hare
#

okey

rich adder
calm hare
#

ok i think i did it i selected a bunch of stuff and changes some settings then clicked regenerate files

#

still doesnt work

rich adder
calm hare
#

whats that

#

wait

#

wait

#

this u mean?

rich adder
#

oh god

#

uncheck all those except first two

calm hare
#

ok

rich adder
#

(close vs)
go in your project folder, delete the csproj/sln files

#

then Regen again. Open script

calm hare
#

done

tough cave
#

Someone that can help me identify the problem? why are the bullets not going forward on my player? its stuck on the spawnpoint, unless I bump into it then it goes forward. But the same method is used on the other 'enemy gun' that is shooting something.

Both objects (the player and the enemy in the maze) use this method, but its in different classes. But I cant pinpoint why its not going forward for the player. zzz

  public void ShootBullet(int ranPos)
    {
        tempBullet =
            Instantiate(bullet[ranPos], bullet[ranPos].gameObject.transform.position,
                bullet[ranPos].gameObject.transform.rotation); 
        Rigidbody tempRigidBodyBullet = tempBullet.GetComponent<Rigidbody>();
        tempRigidBodyBullet.AddForce(transform.up * bulletSpeed, ForceMode.Impulse);
    }
rich adder
calm hare
#

whats vs

#

oh

rich adder
#

using transform.up as forward is very weird in 3d

calm hare
#

it says waiting for second key of chord

rich adder
grizzled fulcrum
rich adder
calm hare
rich adder
calm hare
#

oh it worked

#

nvm nvm im just stupid

tough cave
#

thats the only way it would go into the direction I want it to go. doing .forward or .right, somehow goes on the blue line, and not the green line. I tried doing .right * -1 but it wasnt working sadly. but up somehow did. idk why or how

grizzled fulcrum
calm hare
#

ok so im in solution explorer now

rich adder
rich adder
calm hare
rich adder
grizzled fulcrum
rich adder
# calm hare

did you click regen earlier?
and open the Script from unity not VS

grizzled fulcrum
#

Sorry if it's something so obvious

slender nymph
calm hare
rich adder
grizzled fulcrum
#

Ah nevermind then, I just didn't pay attention

calm hare
#

@rich adder u there

rich adder
#

after u hit regen

calm hare
#

ok il try it

scarlet skiff
calm hare
#

i hit regen its still the same

rich adder
rich adder
calm hare
#

cant move

rich adder
#

what?

#

whats up with your attention span. Still trying to get ur IDE to work..

scarlet skiff
#

maybe both ui and code quesiton

#

idk

calm hare
rich adder
#

spawn it inside canvas no ?

scarlet skiff
#

yes

rich adder
scarlet skiff
#

so it spawns under Effects

#

ill try canvas.transform

grizzled fulcrum
#

So I did the thing and apparently all I had to do was just install the "GAme development with Unity" workload, and it was done

calm hare
rich adder
calm hare
#

is it the opening file from unity

scarlet skiff
calm hare
scarlet skiff
#

its an image

calm hare
#

u mean this?

rich adder
rich adder
scarlet skiff
scarlet skiff
#

to basically be able to spawn the fly on the position it is currently on

rich adder
tough cave
#

My player is able to shoot sum bullets rn, but only issue rn I be having rn is when I spam shoot, not alle dissapear after 2 seconds. Only if i shoot once, and wait 2 sec, it will successfully destroy the bullet, But prolly cuz i spam it it keeps overriding the tempBullet. so the old bullet will stay and will not be destoryed. hmm. thoughts?

    public void ShootBulletPlayer(int ranPos, GameObject playerPos) // called by a UnityEvent
    {
        Debug.Log("Shooting a bullet rn");
        tempBullet =
            Instantiate(bullet[ranPos], playerPos.transform.position,
                playerPos.transform.rotation); 
        Rigidbody tempRigidBodyBullet = tempBullet.GetComponent<Rigidbody>();
        tempRigidBodyBullet.AddForce(transform.forward * bulletSpeed, ForceMode.Impulse);
        Invoke(nameof(DestroyBullet), 2.1f);
    }
    

    public void DestroyBullet()
    {
        Destroy(tempBullet);
    }
grizzled fulcrum
#

I'm just waiting on VS to update so I can try to build the game again

rich adder
scarlet skiff
rich adder
rich adder
#

your error is a build error

#

Building strips all UnityEditor library

#

so all definitions of those other classess get lost, then you get error

grizzled fulcrum
scarlet skiff
#

idk what u mean but this one

rich adder
strong wren
#

heyo

#

its me again

#
  {
      if (PS.CoinsPerSec <= 0)
      {
          Debug.Log("Yes this is working");
          PS.Coins += PS.CoinsPerSec * Time.deltaTime;
          CoinsPerSecCounter.text = PS.CoinsPerSec.ToString("0/s");
      }
  }```
#

so im having an issue where the Debug.Log Thing is always on

#

but i made it so if CoinsPerSec is Larger then 0 then should the Code in the if statement work but its always working

rich adder
scarlet skiff
#

that little square ish at the bottom left is the camera, or what the camera sees, and the big one is the canvas and what will be overlayed on top of what the camera sees, it is there i want these fly prefab to appear

grizzled fulcrum
scarlet skiff
strong wren
strong wren
polar acorn
#

This is the opposite of larger than 0

rich adder
strong wren
scarlet skiff
#

here, yes

polar acorn
strong wren
#

the default number is 0

#

so it should not be anything diff

polar acorn
#

Because that check would be true unless it was negative

#

If the number is never negative then it is doing exactly what you've told it to do

strong wren
polar acorn
rich adder
strong wren
polar acorn
strong wren
#

its supposed to work if PS.CoinsPerSecond is larger then 0

rich adder
strong wren
#

and at the start the value of PS.CoinsPerSecond is 0

polar acorn
#

so it logs

#

You just said it's never negative, so that condition is never false

strong wren
#

should i change the 0 to a -1?

polar acorn
strong wren
#

but that wouldnt fix it nvm

polar acorn
#

If you don't want >=, why are you using >=

strong wren
polar acorn
strong wren
#

yeah

scarlet skiff
#

this is the fly object im talking about.

The effect im going for is that these flies will spawn somehwere between the top 80 to 100% of the screen and at any x-cord of the screen, and will slowly fall down and then destroy themselves, they would cover up, well, everything. anything from the player, gameobject or the players healthbar

polar acorn
strong wren
scarlet skiff
strong wren
#

1>0

polar acorn
#

Why aren't you using that

strong wren
polar acorn
strong wren
#

but the issue fixed itself

rich adder
polar acorn
scarlet skiff
strong wren
short hazel
polar acorn
ivory bobcat
#

Was it an issue with math or the greater-than/less-than symbol? Glad the issue was resolved though.

polar acorn
short hazel
#

The character exists but it's not easily type-able on a keyboard, so they went for the two-character form >=

strong wren
polar acorn
rich adder
scarlet skiff
rich adder
#

you're working with anchors mostly

scarlet skiff
#

what values would this vector have so it spawns in the top half

rich adder
scarlet skiff
#

and `canvas``here is the gameObject right? that was in my scenes hierchy in the ss i showed earlier

rich adder
#

canvas is a Canvas component

scarlet skiff
#

so id have to get it from the canvas gameobejct

kindred nest
#

in a GameObject generated also named Canvas

#

yup basically

scarlet skiff
#

hmmm i see

rich adder
#

drag n drop

kindred nest
#

but add private or public before Canvas and ]

#

depending on what you need, 99% private

rich adder
#

all declared variables without specifying access modifier are private

kindred nest
#

I suppose, but there's nothing wrong with being verbose

rich adder
#

agree on actual scripts its good practice, showing examples on discord. more to type 😛

green copper
#

the image where the player weapon and player movment scripts are missing is of my partner's instance, and the one where everything is working there is mine. Any idea what happened? He claims to have not touched anything but I've never seen anything like it and my copy is still working. using unity's version control system

scarlet skiff
#

now this solution works, but im wondering, is there a way to convert to or get cords to Screen Space without referecing the canvas component? since its a type of Space like camera space maybe there is a way, this would be a little nicer since the fly effect is a prefab and id have to find the canvas gameobject ina scene since i cant reference objects in a scene

rich adder
#

but this is probably better for UI

green copper
rich adder
scarlet skiff
rich adder
green copper
scarlet skiff
#
var randomPos = new Vector2(Random.Range(0, Screen.safeArea.xMax), Screen.safeArea.yMax);
transform.position = randomPos;

like this?

#

oh u beat me to it lol

timber tide
#

Forget the exact issues, but usually updating the prefabs and pushing the scene is what I always try to do

green copper
scarlet skiff
#

do ppl use var just to type faster and it doesnt matter since ur giving it a vector2 value or is there a more practical use?

rich adder
#

or if you got some long ass class you cannot recall

timber tide
eternal needle
scarlet skiff
#

hmmm i see

scarlet skiff
#

or whatever component u r getting

rich adder
#

imagine you have a really long class MyVeryLongClassName

#

put that inside a foreach (especially handy for KeyValuePairs dictionary)

#

😦

#

var is much nicer

scarlet skiff
#

hm i see

green copper
timber tide
#

doesn't matter besides who edits that asset last

eternal needle
# scarlet skiff is that simply cuz var is easier to type than the type of the class?

Sometimes the line does get really long if you have to write the type out fully, and it's already fully visible what the type is in my example.
Otherwise it may just be confusing to others like
var x = someObj.MySecretFunction();
You have no clue what the type is from reading it, you have to mouse over it or look at the function declaration

naive pawn
#

var secret = new();

rich adder
#

nice compile error

#

type cannot be inferred bla bla

naive pawn
#

funnily enough var x = GenericClass<>(); is allowed in java and it infers to the constraint

green copper
# timber tide doesn't matter besides who edits that asset last

the assets dont seem to be the problem, his version is just missing the scripts in the scene itself. If the deleted the bugged script references, version control offers to delete them off my machine as well but I don't want that, there's a lot of properties that'd need to be set again.

Is there a way for him to resync his editor with mine? My copy is working fine but his claims there are no pending changes that need to be made

rich adder
#

C# is java but better

hollow zenith
#

Is there a way to Clamp a value to min, but not max? I.e. I want to clamp value 0.5f to minimum of 1, but value of 100 wouldnt change.
I dont really know what maximum value I want, but I might just put something there.

#

Do I just use float.MaxValue

naive pawn
brave compass
naive pawn
#

i mean they are really similar but with the different backgrounds and different featuresets i find it increasingly hard to compare them (in terms of which is better) as i learn more about c#

brave compass
scarlet skiff
rich adder
#

but yeah mentally got it

rich adder
#

(they need to be spawed as children/grandchildren of canvas)

scarlet skiff
#

oh ye

#

i simply js need to parent them right?

rich adder
#

pass the transform of canvas in Instantiate

scarlet skiff
#

meaning.. ill still need a reference.. lol

#

you win some you lose some

rich adder
#

that will have reference to Canvas

scarlet skiff
#

ye, im gonna have probably 4 game modes and its gonna be in all of them

#

so no biggie, really

rich adder
#

like I said just pass them through the spawner object

#

should be very easy

tough cave
#

How come my bullets are not firing forward to the point I'm looking at? even tho the pivot arrows rotate allong the way I rotate? I thought addForce(transform.forward, means its going to shoot on the green arrow axis. And I would think when reading the code, it will find the trans.pos + rotation, and based on those cords it will shoot something forward no?

   public void ShootBulletPlayer(int ranPos, GameObject gunPos)
    {
        Debug.Log("Shooting a bullet rn");
        tempBullet =
            Instantiate(bullet[ranPos], gunPos.transform.position,
                gunPos.transform.rotation); 
        Rigidbody tempRigidBodyBullet = tempBullet.GetComponent<Rigidbody>();
        tempRigidBodyBullet.AddForce(transform.forward * bulletSpeed, ForceMode.Impulse);
        Destroy(tempBullet, 2.1f);
    }
hollow zenith
rich adder
#

I asked earlier to see your pivots you never replied 🤷‍♂️
your bullet Forward direction and gunPos Forward must be the same (pivot wise first)

brave compass
tough cave
#

Cuz it was indeed the fix, I turned it into .forward and it started shooting forward. Just only in 1 direction no matter how I rotate the player lol.

tough cave
#

on it

timber tide
#

working on a single scene between people has always been a problem for me

green copper
#

he hadn't pushed any of his updates :) [pain]

#

fixed it by having him save his script and test scene, reinstall, and add it back

#

and got a reminder of why we push things more often

obtuse osprey
#

Assets\follow_player.cs(4,19): error CS0116: A namespace cannot directly contain members such as fields, methods or statements

#

fix?

rich adder
#

you probably have bad curly braces

scarlet skiff
#

beautiful

obtuse osprey
#

but now there is another

rich adder
#

the only errors are most worrysome are null references since they are runtime

rich adder
eternal falconBOT
rich adder
#

read bot Msg

tough cave
#

Whats the best practice where to keep/hide the bullet objects? I fixed the issue on bullet shooting in 1 direction only but placing the objects under the players object, so it follows the players rotation. So I hid the bullets inside the gun. Got a hunch this aint smart cuz its putting a body inside a body, which will make them pop out of eachother. and hiding them under the world also feels wrong. Whats the approach for this lol.

grizzled fulcrum
#

Ight I got one last problem to take care of
There is a code to move boxes in the game, and also "Solar Panels" per say. I had a previous problem before (I assume with the button stacking) where E was used to both pick up and drop the box, but then it would bug on drop. I changed the drop to T, and now the boxes work, but said "Solar Panels" don't even get picked up anymore, and I'm unsure how I can fix this one

rich adder
#

you didnt fix issue if you broke it with another

#

you just covered up a sinkhole with some leaves

polar acorn
tough cave
#

Cuz I made 3 types of bullets objects, and I spawn a clone of them each time I shoot. assuming I need to hide the parent bullet somewhere. Need a way to spawn a object thats disabled, and will shoot a clone of the bullet thats enabled. Is that the way? Or is there some option In unity Im unaware of.

hasty geyser
#

Hello, when I play my character, when I press the d key once, it takes a step. When I don't press it, it doesn't stop when it should stop. To stop, I have to press the d key again. The same goes for the a key I press when moving left. Also, it doesn't turn its head synchronously, how can I fix this?

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

public class PlayerMovement : MonoBehaviour
{
PlayerControls controls;
float direction = 0;

public float speed = 800;
bool isFacingRight = true;
public Rigidbody2D playerRB;
public Animator animator;

private void Awake()
{
    controls = new PlayerControls();
    controls.Enable();

    controls.Land.Move.started += ctx => // Yürüme başladığında
    {
        direction = ctx.ReadValue<float>() * speed;
    };

    controls.Land.Move.performed += ctx => // Yürümeye devam ettiği sürece
    {
        direction = ctx.ReadValue<float>() * speed;
    };

    controls.Land.Move.canceled += ctx => // Yürümeyi bıraktığında
    {
        direction = 0;
    };
}

void Update()
{
    // Karakterin hareketini güncelle
    playerRB.velocity = new Vector2(direction * Time.deltaTime, playerRB.velocity.y);
    animator.SetFloat("speed", Mathf.Abs(direction));

    // Karakterin yönünü çevir
    if ((isFacingRight && direction < 0) || (!isFacingRight && direction > 0))
        Flip();
}

void Flip()
{
    isFacingRight = !isFacingRight;
    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
}

}

tough cave
#

Or can I make a prefab out of a bullet, remove it from the world, and link the gameobject to the prefab? instead of a object thats inside the world?

grizzled fulcrum
eternal falconBOT
polar acorn
tough cave
#

Aha didnt know u can link them to scripts as objects, thought its simply to reuse objects like environment. oops cool. nvm! ssh got it

uncut prawn
#

hi there,

I need some help in implementing basic topdown 2d movement. All the youtube resources I went through recommend using FixedUpdate for the movement itself, but that doesn't sit right with me since it looks terrible, the sprite obviously isn't moving smoothly and I'm not sure how to fix it

I've used lower level engines before and it was always way simpler to get this stuff to work, it was always some math multiplied by delta time to account for different framerates, but Unity has been giving me a lot of issues with that

    void Update()
    {
        float moveX = Input.GetAxisRaw("Horizontal");
        float moveY = Input.GetAxisRaw("Vertical");

        moveDirection = new Vector2(moveX * moveSpeed, moveY * moveSpeed).normalized;
    }

    void FixedUpdate()
    {
        rb.velocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);
    }

soo, how can I actually make it move each frame? (Moving the FixedUpdate contents to Update didn't work)

#

this is basically what I'm trying to achieve (minus the rotation stuff), this one was from a different engine

polar acorn
#

FixedUpdate is already framerate-independent, but if you want to work with per-second numbers, you can convert them to per-physics-step by multiplying them with Time.fixedDeltaTime

#

It won't actually affect the values, just let you work in human readable values like "units per second" to make the math easier to do in your head

uncut prawn
#

that still doesn't fix my issue with the choppiness though

#

I have a 144hz monitor, yet the sprite moving feels as if it was 60fps, which is super choppy looking

polar acorn
uncut prawn
#

essentially what you'd get if your fps was half of your refreshrate

#

kinda feels like it

#

instead of player movement that happens every frame, it looks as if it was skipping and only happening on some

naive pawn
#

oh whoops, confused you with another asker who was setting the position in FixedUpdate

short hazel
#

Try enabling interpolation on the Rigidbody2D if you haven't done that yet, it smoothes out the position between physics updates

uncut prawn
#

thank you!

short hazel
# uncut prawn thank you!

If I remember correctly, with this setting enabled, any modification made to the transform will be ignored (as it's now governed by the Rigidbody).
Modify the position and rotation via the Rigidbody directly

uncut prawn
#

oh that's really helpful, thanks for mentioning it

#

I'm implementing the rotation as we speak so I'll remember to do it through the Rigidbody

short hazel
#

The docs say that you can modify the transform, but if you do, immediately execute Physics.SyncTransforms() so the Rigidbody updates its own values

#

I don't know whether doing that is expensive, especially if you have a lot of physics objects in the scene

naive pawn
uncut prawn
#

hmm yeah that sounds expensive

short hazel
#

And that would be in Physics2D, since you're in 2D. But yeah use the rigidbody directly

uncut prawn
#

oke thank you!

short hazel
#

I love the docs

#

What does it do? It synchronizes.

naive pawn
#

lmao

uncut prawn
#

lmao

naive pawn
#

man, why do the 3d versions have such more detailed docs though

#

had issues with collider layers, 2d docs were absolutely useless, all the info i needed for that issue was in the 3d docs

short hazel
#

Ever tried to deal with collision contact points in 2D? Man the descriptions are so confusing. There's:

  • collider: The incoming Collider2D involved in the collision with the otherCollider.
  • otherCollider: The other Collider2D involved in the collision with the collider.
    OK but which one is my collider and which one is the one I just encountered
#

For 3D it's thisCollider and otherCollider and it's way clearer

naive pawn
#

wait, that's the opposite

#

that's cursed as hell

short hazel
#

Depends on how you interpret "incoming". For me it's the one you just collided with, but seems like it's not

uncut prawn
#

oh btw, any reason as to why this line would break movement? it basically introduced other choppiness and made it feel as if it's on ice

// update evt
rb.rotation = Mathf.Atan2(rotation.y, rotation.x) * Mathf.Rad2Deg;
naive pawn
#

incoming is the one that is not this one

short hazel
#

So 2D's otherCollider is yourself? wat

uncut prawn
#

dunno man

#

all this physics stuff is messing with me, Im used to low level stuff and doing all the math myself

naive pawn
uncut prawn
#

oh wait that wasn't a question for me nvm

short hazel
naive pawn
#

have you tried SetRotation?

uncut prawn
# short hazel Haha, post your entire movement class
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 5.0f;
    public Rigidbody2D rb;

    private Camera mainCam;
    private Vector2 moveDirection;
    private Vector3 mousePos;

    void Start()
    {
        mainCam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
    }

    void Update()
    {
        float moveX = Input.GetAxisRaw("Horizontal");
        float moveY = Input.GetAxisRaw("Vertical");

        moveDirection = new Vector2(moveX * moveSpeed, moveY * moveSpeed).normalized;

        mousePos = mainCam.ScreenToWorldPoint(Input.mousePosition);
        Vector3 rotation = mousePos - transform.position;

        rb.SetRotation(Mathf.Atan2(rotation.y, rotation.x) * Mathf.Rad2Deg);
    }

    void FixedUpdate()
    {
        rb.velocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);

    }
}
uncut prawn
naive pawn
#

also just a sidenote, you might want to set angular drag to 0

short hazel
#

And set the rotation in FixedUpdate since it's now a physics operation

uncut prawn
#

wouldn't that mean that the rotation only updates every 50 frames?

short hazel
#

Yeah but you have interpolation. Continue polling mouse position in Update

uncut prawn
#

so basically most stuff is bandaided by interpolation?

short hazel
#

When you have a framerate that's much higher than the fixed physics timestep, yep

naive pawn
#

YieldInstruction

Description

Base class for all yield instructions.
why doesn't CustomYieldInstruction extend it then wtf

uncut prawn
#

like, I'm much more of a fan of running stuff per frame and adjusting the amount by deltatime

short hazel
#

Try in Update but with setting the Transform directly, call SyncTransforms() if you don't rotate or it behaves weirdly

#

Docs are not that clear on whether interpolation also affects rotation, but I'd say yes, since you can have angular velocity

uncut prawn
#

nope that doesn't work

#

well, part of me just wants to throw the physics features into the trashcan and do this stuff myself, would that be dumb?

#

or rather, isn't that one of the biggest parts of the engine? the physics engine?

short hazel
#

You'd have to detect collisions yourself in that case. Try with the rotation in FixedUpdate and if it doesn't feel good, trash the rigidbody and roll your own system

#

There's plenty of methods in Physics2D which allows you to detect what's around a specific point, but creating a good collision detection system is not an easy task

uncut prawn
#

sadly the FixedUpdate method feels way worse

#

I need that part to run at the framerate, since the game's main thing is meant to be butter smooth movement and player control

#

dunno what to do, I really dont wanna throw away 80% of what the engine offers if I was to do collisions myself...

strong wren
#

Rigidbody interpolation stops for a tick if any transform changes are made. You can increase the physics tick rate if you want to increase responsiveness to input.

uncut prawn
#

I see, would it be smart or dumb to set the physics tick rate to the game's FPS and multiply stuff by delta time to have it be consistent across various framerates?

#

also would that affect the polling rate of inputs? I also need those to run per frame since the movement itself isn't as responsive as it should be

strong wren
#

I don't think physics engines like the tick rate being changed each tick. Input is generally evaluated at the start of each frame. Make sure to use the new input system to get the latest input backend improvements across platforms.

uncut prawn
#

right

#

one question, how much would I be alienating myself from most of the unity community if I just didn't use the physics system at all?

#

is it common that someone decides to go that route?

strong wren
#

Rolling your own is fine if you want to. Unity officially provides 4 different physics engines, with even more thirdparty solutions available 😛

rocky gale
#

can someone help me in networking

rich adder
rocky gale
rich adder
#

how?

rocky gale
#

the last time someone talked in the help channel was over 10 hours ago...

#

sorry

#

in teh general

#

channel

rich adder
#

you gotten answers before though didn't you?

#

be patient

#

also you should put a little more effort into your debugging. how you present your question

rocky gale
#

what

rich adder
honest vault
#

Hello,i have created a new animation for my character and now im unable to move

honest vault
polar acorn
#

Does your animation control the object's Transform at all?

sleek stone
#

Does anyone know why my spotlight fade won't fade in?

using System.Collections.Generic;
using UnityEngine;

public class CameraFlash : MonoBehaviour
{
    public Light spotlight;             
    public AudioClip flashSound;        
    public float flashDuration = 0.1f;  
    public float fadeDuration = 0.2f;   
    public float cooldownTime = 1.0f;   
    private float lastFlashTime;        
    private bool isFlashing;            

    void Start()
    {
        spotlight.enabled = false;

        lastFlashTime = -cooldownTime;
    }

    void Update()
    {
        if (Time.time - lastFlashTime > cooldownTime)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (!isFlashing)
                {
                    StartCoroutine(Flash());
                }
            }
        }
    }

    IEnumerator Flash()
    {
        isFlashing = true;

        float timer = 0f;
        while (timer < fadeDuration)
        {
            float intensity = Mathf.Lerp(0f, 1f, timer / fadeDuration);
            spotlight.intensity = intensity;
            timer += Time.deltaTime;
            yield return null;
        }

        spotlight.intensity = 1f;
        AudioSource.PlayClipAtPoint(flashSound, transform.position);
        yield return new WaitForSeconds(flashDuration);

        timer = 0f;
        while (timer < fadeDuration)
        {
            float intensity = Mathf.Lerp(1f, 0f, timer / fadeDuration);
            spotlight.intensity = intensity;
            timer += Time.deltaTime;
            yield return null;
        }

        spotlight.intensity = 0f;

        lastFlashTime = Time.time;

        isFlashing = false;
    }
}```
eternal falconBOT
grizzled zealot
#

Want to play audio when shooting a gun. I want to use a variety of slightly different audio to make it non-repetitive. What's the suggested method:

  1. Have each shot audio in a separate file and then play one.
  2. Have all shots in a single file with a specific offset (e.g., second 1, 3, 5, 7, 9) and then always play from that index.
frosty hound
#

Separate files. The new upcoming version of Unity also has a new sound asset that let's you specify a list of sounds to randomly play from specifically for doing what you're asking.

#

Alternatively, you can do one shot and just change the pitch randomly with each shot.

atomic sierra
atomic sierra
#

wdym

#

in the unity hierarchy its

#

GameObject (called Player)

Sprite (PlayerBody)
Sprite (DashIndicator)

abstract finch
#

Whats the best way to clamp the vertical rotation of something based on knowing the target position? I.e. head rotating to look at a target.

main anchor
main anchor
# polar acorn What is line 22

line 4 on the hastebin is line 22, but i occasionally get the error from the other 2 hints on line 26 (line 8 on hastebin) and line 30 (line 12 on hastebin)

polar acorn
misty coral
#

I am trying to pull the gun model toward a position behind it for a certain amount of time

#

but in Update()...

#

The program tries to keep the gun either at the aimed in position or the hipfire position

#

does the boolean shootCheck work as intended?

#

I rlly can't figure out how to "deactivate" that part of the code while the recoilAnimation() is running

summer stump
glass ivy
#

Is there a physics event that gets called when 2 trigger colliders intersect? OnTriggerEnter only detects colliders

deft grail
#

that question doesnt really make sense to me

timber tide
#

If OnTriggerEnter fires then atleast two colliders do intersect

summer stump
timber tide
#

Ah, you want only trigger colliders eh

#

Probably just compare that the collider you are colliding with has IsTrigger enabled

whole idol
#

aloha

glass ivy
summer stump
glass ivy
#

layers are set properly

glass ivy
summer stump
deft grail
summer stump
#

That is not a dynamic rigidbody, it is a kinematic one

slender nymph
#

it is fine for OnTriggerEnter

summer stump
#

Oh dang. You right. Sorry.

I thought it needed TWO rigidbodies for kinematic. But the chart matches kinematic with static 🤷‍♂️

timber tide
#

you need atleast 1 rigidbody and 1 trigger

#

mix and match em

slender nymph
#

yep as long as any rigidbody is involved with the trigger overlap then it will fire OnTriggerXXX messages

glass ivy
#

weird, i've never had trouble with this, might be layers

glass ivy
slender nymph
#

that's kind of an odd way of describing it. what is actually happening is that any collider that is a child of a rigidbody becomes part of that rigidbody's compound collider so collisions and overlaps happen as a result of that parent rigidbody

glass ivy
#

i need another set of eyes at the end of the day 😅 ok... it's working, it's just late evening logic

glass ivy
misty coral
#

How can I moveTowards a position for 5 seconds

glass ivy
#

especially because there is zero indication of that compounding in the rb inspector