#💻┃code-beginner

1 messages · Page 243 of 1

stuck jay
#

Not saying it's bad since I haven't tried it yet, but I personally can't think of any advantages this would give that using components wouldn't... so far

pallid nymph
rich adder
stuck jay
#
public class Health : MonoBehaviour
{
    [HideInInspector] public GameObject damageDealer;
    public int currentHealth;
    public int maximumHealth;
    private bool canBeDamaged;
    private float cooldownTimer = 0.2f;
    private float currentTime;


    void Start()
    {
        currentHealth = maximumHealth;
    }

    void Update()
    {
        DamageCooldown();
    }


    public void TakeDamage(int damageValue, GameObject gameObj)
    {
        if (canBeDamaged == true)
        {
            currentHealth -= damageValue;
            damageDealer = gameObj;
            canBeDamaged = false;

            if (currentHealth <= 0)
            {
                Death();
            }
        }
    }
}

public class DamageOnCollision : MonoBehaviour
{
    public int damageAmount;

    void OnCollisionStay2D (Collision2D other)
    {
        Health otherHealth = other.gameObject.GetComponent<Health>();

        if (otherHealth != null)
        {
            otherHealth.TakeDamage(damageAmount, this.gameObject);
        }
    }
}

public class XPOnDestroy : MonoBehaviour
{
    public int xpValue;


    void OnDestroy()
    {
        LevelSystem damagerLevelScript = GetComponent<Health>().damageDealer.GetComponent<LevelSystem>();

        if (damagerLevelScript != null)
        {
            damagerLevelScript.addXP(xpValue);
        }
    }
}```
rich adder
#

why not just store LevelSystem

#

directly

stuck jay
#

Because I might need damageDealer for other stuff

pallid nymph
#

LevelSystem itself gives me mixed feelings... but also storing the damage dealer is odd

#

damageDealer is a damageDealer for just an instant, it's not like a permanent damage dealer to the Health guy

#

so storing it there is weird

rich adder
stuck jay
#

It's a part of Health.cs

rich adder
#

what type is damageDealer

stuck jay
#

GameObject

pallid nymph
#

you need damage events that go left and right... I think... also fewer random GOs and more typed Monos

stuck jay
#

The only GameObject here is damageDealer and it's there to track which GameObject dealt the last damage

pallid nymph
#

I'd use some kind of Entity base class for that, just gives more information about what the object actually is, plus some options in the future to add some functionality to it and not have to GetComponent for everything

crisp copper
#

how can i make a easy dobul jump system?

rich adder
#

using an int

#

lookup on google, so many ways to do it

modest dust
stuck jay
pallid nymph
# stuck jay Can you explain this more?

as for "damage events left and right", I meant that defender should get an event about getting damaged, and then attacker should get an event about dealing damage and what the final damage was... and then the damage dealer would be part of the event parameters... and the XP thing would listen to that event and will have the attacker from arguments

#

and it would be XPOnDeath, not OnDestroy, but that's more fair

crisp copper
pallid nymph
#

@stuck jay okay, I think what you need is an event on the health component that someone killed it and who it was... that's all you need to do XPOnDeath - it'll get the Health, subscribe to OnDeath event, give XP on death
(is this what the others already suggested? 😅 yes, yes it is, I just re-read earlier... so yeah +1 to that)

fickle plume
modest dust
fickle plume
modest dust
#

You're in it right now.

crisp copper
#

is it the code general?

modest dust
crisp copper
#

i cant send my code here @rich adder is geting angry when i send it

rich adder
crisp copper
rich adder
#

did you read this ?

crisp copper
#

im dum

rich adder
#

click one of the links, paste the code. Save and send link

crisp copper
#

like that

rich adder
#

you dont have a grounded check

crisp copper
#

@modest dust @fickle plume now you can help me

rich adder
#

prob wanna implement that first

crisp copper
rich adder
#

You need to reset a jump counter to maxJump counts when you land aka grounded

stuck jay
#

Why's there an isGrounded check on characterController?

fickle plume
crisp copper
#

idk know

rich adder
stuck jay
rich adder
elder jewel
#

Hello, could anyone tell me by any chance what went wrong with this collider? i was following this tutorial on how to make a player movement, but my colliders wont "Live" collide when i move like in the Video (Video with time Stemp: https://youtu.be/0-c3ErDzrh8?si=xSc_tH_dHbEyCK-5&t=189)

(reuploaded to fix an error in the edit of the previous version)

Heya Pals!

Welcome to a first in a series of video tutorials for Unity Development. We'll be covering all kinds of content in the series, so be sure to subscribe and check the playlist for future videos.

Music: Rifti Beats - Chocobo & Chill [Gamechops.com]

Chapters:
0:00 - Intr...

▶ Play video
crisp copper
#

@rich adder cam ypu help me shange the script? becus i dont get it?

crisp copper
#

what?

rich adder
#

First step to solving a problem is break it down into smaller problems

crisp copper
#

some people is saying i need to set it to not grounded but how?

stuck jay
fickle plume
stuck jay
#

That way you can re-use CharacterMovement on enemies

crisp copper
#

and i need to do so i can jump 2 times befor i need to tushe the ground

rich adder
rich adder
rich adder
elder jewel
rich adder
# crisp copper idk

well you have to count how many jumps you have and how many max you can do , wouldn't you agree ?

fickle plume
rich adder
# crisp copper yes

so start with that first step of making a jump counter with a maxlimit, You need obviously 2 numbers

#

how you made variables make two

summer stump
fickle plume
#

@crisp copper It looks like you are asking for entire tutorial to do something for you. Create a thread for it

summer stump
#

@crisp copper have you gone though !learn ?

eternal falconBOT
#

:teacher: Unity Learn ↗

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

rich adder
#

Yes you need the basics first, don't try to run without knowing how to walk

summer stump
modest dust
# crisp copper what?

Never used a CharacterController but this is the general and most simple setup I'd make for a double jump

private bool m_didMidAirJump; // or an int counter if you want to allow double jump during a fall

private void Update() {
  if (Input.GetKeyDown(JUMP_KEY)) {
    if (IS_GROUDED) {
      Jump();
    }
    else if (!m_didMidAirJump) {
      m_didMidAirJump = true;
      Jump();
    }
  }
}

private void Jump() { ... }

private void OnGrounded() {
  ...
  m_didMidAirJump = false;
}
```(And yeah, do go through unity learn first)
rich adder
#

Grouded

modest dust
#

Grouded.

summer stump
#

Grouded..

rocky canyon
#

nvm

fickle plume
crisp copper
#

@modest dust you seam like a good scripter can you help me change my script so i can dubel jump

crisp copper
#

pls

fickle plume
#

@crisp copper This is not a place to ask people work for you.

stuck jay
crisp copper
#

i thin so

fickle plume
#

Again if you have further questions about it make a thread ( @crisp copper )

modest dust
#

I already did show you how to do it, now it's your turn to learn something

stuck jay
#

But yeah, good call

rocky canyon
pliant plover
#

Why

rocky canyon
#

!ide

eternal falconBOT
rocky canyon
#

configure ur IDE first

crisp copper
#

!code

eternal falconBOT
crisp copper
#

how can i fix this

rich adder
#

use it to your advantage

shell sorrel
#

your ide should tell you

#

but you just closed some parentheses ( ) too early

summer stump
languid spire
summer stump
#

Ah, yeah. What they said

languid spire
#

inb4, nested method as well, aint gonna work

summer stump
shell sorrel
#

and attention to detail

languid spire
#

but the nested method wont throw a compiler exception

#

it just wont be executed

autumn tusk
#

i geniunely feel like im about to go insane

#

i just want to destroy one singular instance of an object without having to instanciate it in its own script

#

i hate the unity destroy function so bad

rich adder
crisp copper
crisp copper
#

how can i fix that

rich adder
autumn tusk
summer stump
crisp copper
#

and how?

languid spire
summer stump
nocturne parcel
#

Take the OnCollisionEnter from the update method.

crisp copper
summer stump
#

What do you want to do

rich adder
#

don't dothat

crisp copper
autumn tusk
#

just a prefab switching system

rich adder
languid spire
autumn tusk
#

instanciating a prefab which the player is currently holding, and destroying the existing prefab

rich adder
autumn tusk
#

you can swap prefabs directly?

rich adder
summer stump
#

Prefabs do not exist in the scene

autumn tusk
#

yeah i mean gameobjects

#

sorry prefabs are confusing sometimes

queen adder
#

Yo.

summer stump
#

Ok, then yeah, you can of course swap them directly

#

Just myVariable = newObject

summer stump
queen adder
#

I'm new to Unity.

#

This is what I have done so far:

rich adder
queen adder
#

The movements...

#

I had none errors in vision studio.

#

And still...

#

I had errors in my Unity game

#

But I updated it

languid spire
#

you do know that Shift+Enter is a thing? Use it

summer stump
#

Then your !ide is unconfigured

eternal falconBOT
queen adder
#

Well yeah.

#

I was in studi

#

Studio

summer stump
#

Please do what steve said. Write a full message and then send it

queen adder
#

Ctrl + S

#

My bad.

#

How does codings work?

#

Vectors.

summer stump
eternal falconBOT
#

:teacher: Unity Learn ↗

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

nocturne parcel
#

Do you have any experience with coding? Not just game development.

nocturne parcel
#

I see. And what problem are you having? Try posting a screen shot.

rich adder
#

they said it

queen adder
rich adder
#

but they need to configure IDE first

queen adder
#

It ain't working.

nocturne parcel
#

Try configuring the IDE as navarone said

rich adder
#

as most things wont with errors

autumn tusk
#

dont exactly understand why this isnt switching

rich adder
autumn tusk
#

yep

#

error log says weapon is read only

summer stump
rich adder
rich adder
#

3 dots on _playerShootScript

nocturne parcel
#

For beginners

queen adder
#

Well, I already know the basics but the problem is that I have coded my movements and updated vision studio to my Unity game project. It didn't work but had errors in unity only and not my C# codes

nocturne parcel
#

Did you configure the IDE?

queen adder
#

Yeah.

#

I got everything set already.

inner bane
nocturne parcel
#

Then share your code. And the errors.

rich adder
modest dust
rich adder
#

unless you mean NullRefs

queen adder
rich adder
#

those are compile errors then..

queen adder
#

I prob did something wrong.

#

With codes

summer stump
rich adder
#

you need to configure your IDE

nocturne parcel
#

Again, configure the IDE

queen adder
#

How?

summer stump
#

!ide

eternal falconBOT
rich adder
#

in the instructions

summer stump
#

It was linked above

queen adder
#

Alright, I will see.

nocturne parcel
#

Did you mean Vector3.up? rb.AddForce(Vector3.down * Time.deltaTime * 3000f);

#

Also, don't use Time.deltaTime with AddForce

inner bane
#

in the player movement?

nocturne parcel
#

You're applying force down when player grounded

inner bane
#

oh

#

so what do I do,delete it?

nocturne parcel
#

I don't know if that's intentional or

inner bane
#
  • 0f);
rich adder
inner bane
#

kind of

#

if I fully understood it then I wouldnt ask here

nocturne parcel
#

Where did you copy it? That deltatime on add force is weird.

inner bane
#

some YT tutorial 💀

#

u want the link?

nocturne parcel
#

No need

rich adder
#

send

inner bane
#

Unity Wallrunning Tutorial by Lahampsink | Unity FPS Wallrun Controller
In this video I am going to explain how to add wallrunning to your unity game just like in KARLSON. Don't forget to like and subscribe!

Links:
➤GitHub - https://github.com/Lahampsink/WallrunTutorial
➤ Follow me on TikTok - tiktok.com/@lhgames24
➤ Youtube channel - https://...

▶ Play video
rich adder
#

they dont even explain the code..

#

what kinda tutorial is this

inner bane
#

idk the best I found tho

nocturne parcel
inner bane
#

well even if I aint crouching it still cant jump and slides too hard

rich adder
inner bane
#

aint found nothing about the sliding in the code

inner bane
#

wdym

rich adder
#

oh god its everywhere
rb.AddForce(Vector3.down * Time.deltaTime * 10f

nocturne parcel
#

Yeah see?

#

Lmao

#

You are constantly applying force down

rich adder
#

its the first line in Movement()

#

at least its in FixedUpdate..

rich bluff
nocturne parcel
#

Try removing that line

modest dust
# inner bane idk the best I found tho

Well, the best tutorial you can get is a C# course followed by a unity course and docs. From there it's just dividing your problem into sub-problems and completing them one by one. Copying without fully understanding isn't the best idea

rich adder
#

rb.AddForce(Vector2.up * jumpForce * 1.5f);
oh also Jump without Impulse?

#

weird flex

swift crag
#

AddForce applies a steady force to the rigidbody. It does not make sense to use deltaTime there.

#

It doesn't matter how small the timestep is -- you're applying a steady force.

#

On the other hand, if you want to do an instantaneous "shove", you want to pass ForceMode.Impulse as the second argument (again, without factoring in deltaTime)

inner bane
modest dust
nocturne parcel
#

Well, you could try another tutorial tho

rich adder
#

start with a structured course, learn the basic. Build up from there

inner bane
rich bluff
#

movement controllers are among the most complex things to code that look simple on the surface

swift crag
inner bane
nocturne parcel
#

Then bad news for you

inner bane
rich adder
swift crag
#

unless you don't want to make a game

rich adder
#

something will break you will not know how to fix it

nocturne parcel
#

It's like going to the gym for the first time and trying to lift 400 kg

inner bane
#

I just wanna see what dumb thing I make and nothing more

nocturne parcel
inner bane
#

I dont wanna be making fortnite 2 fr

modest dust
inner bane
#

ik

#

so I just quit it lol

nocturne parcel
inner bane
#

so anyone got a damn ideea if I can do smth or not to this?

inner bane
rich adder
nocturne parcel
#

honestly? i'd scratch that one

#

It is over complicated and full of weird mistakes

inner bane
#

alr

#

ty

nocturne parcel
#

When I saw num5 I gave up reading it

inner bane
#

lol

swift crag
#

that reminds me of dnSpy decompilation output

#

where it has to make up variable names

inner bane
#

I had do add some materials,to like lock the X,Y,Z camera directions else camera would fall off

tall delta
swift crag
#

catlikecoding is pretty great!

inner bane
#

I saw this dude's content alr but its a lil off

swift crag
#

i need to make my own highly opinionated "how do i shot web?" blog series

#

i hate watching video tutorials in most situations

inner bane
#

like I see this one got more mistakes than the one I send u

nocturne parcel
#

Catlikecode?

inner bane
#

Dave

#

or idk if its the same person

tall delta
inner bane
#

how could I repair em 😭 I only know to do the things in the hierarchy inspector settings not coding 300 lines

pallid nymph
#

a parkour CC would be thousands of lines of code... don't know what to tell you... there are paid assets and even they are usually the half of the code, the rest is something you need to code yourself

inner bane
#

nah I gotta quit fr

pallid nymph
#

it's not a good starting point

fickle plume
#

@inner bane Don't spam the channel. If you have an actual constructive question, here's how to ask it #854851968446365696

tall delta
inner bane
#

I only asked if someone knows what I could change so it works and if I didnt set something propely
I aint told noone to do it for me

fickle plume
#

I just see a lot of whining. Where's the actual question?

nocturne parcel
#

Well, remove the first line of code in movement

#

And remove all the deltatimes from the AddForce

swift crag
#

advice was given and suggestions were offered

#

this server will not rewrite your code for you

inner bane
#

I aint asked for that lol

nocturne parcel
#

We told you many times, you are constantly applying force down

inner bane
#

I aint said "Write this for me"

inner bane
nocturne parcel
#

Isn't it already broken

inner bane
nocturne parcel
#

I'm trying to read but gosh

#

try placing a ! before jumpingreal quick

#

!jumping

inner bane
#

and I delete the (); or let it there

nocturne parcel
#

let it here

inner bane
#

kk

nocturne parcel
#
if (readyToJump && !jumping)
{
  Jump();
}
fickle plume
#

If you going to get into fixing that for them, create a thread, please.

nocturne parcel
#

Sorry

inner bane
nocturne parcel
#

Well, we told ya there are many mistakes. Remove the delta time from add forces, use ForceMode.Impulse when jumping, etc.

inner bane
#

I got no ideea what that means,I'll search online
Edit:I can't find but I saw that someone tried in build and worked,should I build the game and try?

winter frost
#

Hello, how can I use FindGameObjectWithTag and ask it to only consider the gameObject if it is active? Thanks

nocturne parcel
#

It already does that by default, no? It won't get inactive objects.

rich adder
#

yes

winter frost
#

Ok, thank you

minor patio
#

I'm so braindead on null references

#

I can't even

lost anvil
#

is the best way to fix this clipping using a seperate camera for culling only the things you dont want to clip?

timber tide
lost anvil
#

and UI

timber tide
#

#built-in-pipeline

rich adder
#

Ui is clipping because you have screenspace - camera

lost anvil
#

ah right so that would be overlay im assuming

rich adder
#

you need to set a proper Z distance

lost anvil
#

what with screenspace camera?

rich adder
#

if its set on screenspace camera its a sitting on it

#

or just use Overlay if you dont care about depth for UI

lost anvil
#

okay, and for weapon the seperate cam is the play?

north kiln
#

And please don't post non-code questions in this channel in future

lost anvil
#

yeah my bad

rich adder
lost anvil
#

and if i do?

rich adder
#

then no two cameras is not the play

lost anvil
#

ok cheers

queen adder
#

coroutines are first start = first finish right?

#

like if you fire the same coroutine it won tget shuffled somewhere

rich adder
#

wdym fire the same coroutine?

queen adder
#

like a coroutine that waits for 3 sec then do something

#

if you fire it twice in a row

#

you are expected to see hte first one finish first 100% of the time

rich adder
#

you create one each time

#

unless you mean when you yeild return anothercoroutine ?

north kiln
queen adder
#
void Start()
{
  Startcor(x()); // i need this to finish first 100 of the time, vefore the thing below
  Startcor(x());
}```
queen adder
#

maybe someone had cases before where it didnt

rocky canyon
#

if its consistent now, it'll be consistent later as well..

faint sluice
rich adder
#

then why not just yield the coroutine

rocky canyon
#

code isnt gonna operate differently

#

unless ur code is different

queen adder
#

they wait for 3 seconds then do their job

rich adder
#

like this ? cs IEnumerator Start() { yield return x(); yield return x(); }

faint sluice
north kiln
#

These do different things from what's being asked

brazen cedar
#

How can I lerp the intensity of a Spotlight 2D in Unty?

rich adder
queen adder
faint sluice
queen adder
#

cant explain (still havent started coding it)

rich adder
hollow olive
#

hi there, i'm desperate need of help. I don't know what is the problem and i can't figure out what the flip is wrong here. Basically it's an ontrigger event script. All the info needed is in the image i think. Thanks for the help (i'm an absolute begginer in unity)

queen adder
#

imagine the first coroutine to pathfind, then the second coroutine will try to get all tiles the the pathfijnder found

faint sluice
#

@queen adder unless code is going to affect the duration of how long a coroutine will last, the one fired first will be completed first in that example you gave

queen adder
#

but they are both delayed by 3 secs

north kiln
eternal falconBOT
queen adder
#

some units need to farm everything beside the tiles, some need to kill enemies found instead

#

actually it would look cleaner with events ig

faint sluice
queen adder
hollow olive
rich adder
north kiln
rich adder
north kiln
#

And the bot message immediately after describes how to configure it

rocky canyon
#

i'd suggest not using OnTriggerEnter for your own UnityEvent..

warped dirge
#

hi can someone help me my inspector is all grey it has nothing in it

rocky canyon
#

unity already has functions called that.

hollow olive
#

oh so i'm pretty much writting with no valid code

faint sluice
north kiln
queen adder
#

IDE bot message should have
IDE = The place where you write codes

rich adder
warped dirge
#

omg im the dumbest guy on earth

#

im beginner so

rich adder
#

google "what is IDE"

hollow olive
north kiln
rocky canyon
#

OnTriggerEnterEvent?

#

idk lots of choices lol

hollow olive
rich adder
#

u good homie

rocky canyon
hollow olive
#

ok, i'm fixing the IDE now, when i'll be done i'm coming back for more advice

#

thanks guys

#

ya'll awesome

meager raptor
#

Does anyone know why this error is occuring

faint sluice
# meager raptor

You don't call methods of singleton before the instance is set

meager raptor
#

right so do i need to place it in start() ?

rich adder
#

ye

rocky canyon
#

try it and see

meager raptor
#

yea works, thanks

#

ive got another error if u guys dont mind

#

2nd pic is before game starts

#

but why does the layer change

rocky canyon
#

does ur code change it?

faint sluice
#

You're changing it from the methods i guess?

meager raptor
#

dont think so

rocky canyon
#

im pretty sure u do.. if u didn't it wouldnt change on its own..

faint sluice
#

Select on either of those variables from visual studio and click shift + f12 and see for yourself

meager raptor
#

ill show the code

faint sluice
rocky canyon
#

u just said ur not setting it in code

#

if u have it set in the inspector.. u could just remove those lines.. dont need em

meager raptor
#

ah ok

spiral narwhal
#

On the same spot as Java. Languages like Kotlin, Java, and C# are all there

rocky canyon
#

then test again and see.. im guessing the line is not completely correct.. and is not setting it correctly..

north kiln
rocky canyon
#

aye, theres the context i was lacking ^

meager raptor
#

ohh

#

yeah ur right there

meager raptor
rocky canyon
#

np 👍 🍀

shell sorrel
#

yeah would need to 1 << layerIndex to convert it

north kiln
#

Or use the correct function

shell sorrel
#

yeah or just do that

north kiln
#

Or preferably, and as we're doing now, nothing at all in code

primal turtle
#

Can someone explain how to use arrays in a simple sense? I tried reading the documentation but I'm not getting it.

rocky canyon
#

its a collection of things
they get numbered 0,1,2,3,etc

north kiln
primal turtle
rocky canyon
#

you mean a Ray?

north kiln
#

What does "send an array out" mean

primal turtle
#

raycast

rich adder
#

so you want to check for a component from the raycast?

wind raptor
#

How do I set a tmpro font asset from the inspector?

rich adder
wind raptor
#

What is the "type" of tmpro font assets is what I mean

primal turtle
#

but I want it to check in all directions with a box

primal turtle
rocky canyon
#

ya, ur confusing what u need

worthy merlin
#

Is there an easy way to convert Rotations -180 to +180 value to be based in 360 instead? Need it for a Compass heading UI

rich adder
rocky canyon
#

ya, ^ describe what u need... and someone will let u know the Best way to achieve it

primal turtle
#

I want to place a spring but I want to check before hand if it'd collide with walls floors etc to see whether or not it's placeable

worthy merlin
rich adder
#

sorry I meant add

primal turtle
rocky canyon
#

if the rotation is negative adjust it to the positive rotation in the 0 to 360 range

rich adder
#

set your Vector3 at the raycasthit point then do an additional check from there

primal turtle
#

thx

rocky canyon
#

ur username gives me anxiety

primal turtle
#

I can text it to lol

hollow olive
#

hey i'm back. This means my IDE thing is correctly set up now, right?

primal turtle
#

meager raptor
#

does anyone know why when i start my game, all my units have a health of 0, making all my units gone as soon as i play

hollow olive
rocky canyon
#

if it is you'll see Assembly at the top left corner

rich adder
#

Ss the visual studio

worthy merlin
rocky canyon
#

u could just invert the equation if thats the case...

rocky canyon
#

if > 0 subtract from 360

meager raptor
meager raptor
hollow olive
rocky canyon
#

noice!

meager raptor
hollow olive
#

that means i'm all set up?

rich adder
faint sluice
rich adder
#

I would not put it t on Update

meager raptor
primal turtle
meager raptor
primal turtle
#

if it somehow returns as 0, then it'll set your current health to 0 when it starts aswell.

rich adder
#

also the try catch here is wild

#

no need to do this

primal turtle
meager raptor
faint sluice
rich adder
#

anyway its an easy cleanup init values on awake , but only check health when a DMG method has ran not inside update

hollow olive
#

now, how do i fix this

meager raptor
primal turtle
#

just set your max health to a number and that could fix it, but I think it most likely has to do with something else.

shell sorrel
#

yeah that mulitpled nested try/catch with a catch all exception is pretty smelly

rich adder
worthy merlin
# rocky canyon if > 0 subtract from 360

How would this look in code. By flipping the greater/less than symbol it does this really change thing where half the heading is normal and then it gets into the 400s

faint sluice
#

@meager raptor check your inspector for the value of Max health tho

rich adder
primal turtle
rich adder
#

Yellow one is the on you made for some reason @hollow olive

rocky canyon
#

instead of the equation..

faint sluice
hollow olive
worthy merlin
rich adder
#

dont do that

rocky canyon
meager raptor
primal turtle
#

your setting your max health to enemy health

meager raptor
primal turtle
#

but if your enemy health is 0 it'll set all objects to 0 later

primal turtle
hollow olive
primal turtle
#

:)

rocky canyon
#

since u said it was correct.. but just backwards..

rich adder
rocky canyon
#

atleast thats what i thought when u said it

worthy merlin
faint sluice
rich adder
meager raptor
rich adder
#

i would do OnTriggerWasEntered or something

primal turtle
primal turtle
#

if either of the healths = 0 it'll intern make it 0 during runtime as well.

rich adder
#

the problem is because Update is running before its assigned

#

assuming its not set to 0

hollow olive
primal turtle
rich adder
#

it should be in awake

primal turtle
#

although,

rich adder
#

it has occured before where Update ran before start for me

primal turtle
#

yeah just check .health

tender stag
#

i have this counter movement method in fixed update

rich adder
#

but the health check should not be in Update in the first place anyway

tender stag
#

and its supposed to stop the player when hes not holding any input

rich adder
#

why check health everyframe when you can check every Hit..

tender stag
#

but when the counterMovementForce is high the player starts shaking

#

why?

primal turtle
rich adder
#

wasnt OP question that enemy Died when game started ?

#

unless I got lost somewhere

primal turtle
#

yeah

#

so it dies when start() runs

tender stag
primal turtle
#

because either the player or enemy health was 0

#

anyways he left chat so on point on thinking about it further

rich adder
#

wait nvm

meager raptor
rich adder
#

current health is never set.

meager raptor
#

but how would i modify the code

primal turtle
#

nvm

faint sluice
meager raptor
hollow olive
#

@rich adder it's better now right?

meager raptor
#

it's for a project

rich adder
shell sorrel
#

or just let it throw a exception if its truely not configured right

meager raptor
shell sorrel
#

using try catch for flow control is terrible

#

also if using it never catch all exceptions

faint sluice
primal turtle
rich adder
rich adder
shell sorrel
#

like no way i would ever let the try/catch like that pass a code review

hollow olive
shell sorrel
#

programming is about taking big complex things, and breaking it down into small easy to understand and implement steps

rich adder
#

I said the name of the Variable, of the UnityEvent cannot be the same name as a method..

hollow olive
#

but what's the "method"?

rich adder
#

A function

#

anything with () after it

#

void HelloFunc()

shell sorrel
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

shell sorrel
#

might be the place to look first if you are not sure about methods yet

rich adder
hollow olive
#

this is what i was intended to change?

hollow olive
#

or courses

#

well thanks for helping me anyways, you guys are awesome, : )

tender stag
#

i have this counter movement method in fixed update and its supposed to stop the player when hes not holding any input

#

but when the counterMovementForce is high the player starts shaking why?

#

its probably because im doing -velocity

#

and its adding force in one direction then the other

#

but i dont know how else to do it

eternal needle
tender stag
#

yup

eternal needle
#

Your counter movement magnitude should be limited to the players speed

#

Maybe limit each component (x and z) of the vector instead of the magnitude actually

solar charm
#

hi sorry for the question but where can i find the grid and snap window? im on 3d if that matters

solar charm
#

oh mb

tender stag
#

im trying to stop the player

eternal needle
teal viper
#

That's why, I think applying it as a force like that is silly. Unless you 100% confident in your formula, you shouldn't do it via adding force.

tender stag
#

how else should i do it

#

i dont want to instantly stop him

teal viper
#

Either set the velocity to 0 directly or use unity physics drag.

#

Or friction.

tender stag
#

yeah i cant mess with friction

#

maybe i could lerp his velocity to 0?

teal viper
#

For a character controller like that it would probably be best to just set the velocity for it's movement.

teal viper
tender stag
#

oh yeah i remember why i was using add force

#

i have 0 friction

eternal needle
tender stag
#

i did this

#

and hes still sliding

teal viper
tender stag
#

i cant touch the y velocity

#

it breaks my other things

#

thats why i set it to rb.velocity.y

vale karma
#

is there a reason why the model gets pushed backwards here? the player does what it needs to just fine, but now i wanted to add animations and its gettin kinda screwy

#

im just gonna start the animator from scratch, i think i got the idea but im not doing this right

#

any good tutorials on sub state machine animations?

teal viper
eternal needle
# tender stag could u help me?

its just a matter of comparing the vectors x and z value. if the counter movement's value is greater then just use the players current velocity. if the player isnt moving, the counter movement wont move them because itll be 0 on the x and z.
honestly not really sure what was happening with the y velocity part youve shown above. i was just looking at the counter movement part alone that you first wrote

eternal needle
#

What i like to do is store what the players velocity should be, then assign that to the rb.velocity. it makes it easier to control how it moves on slopes and all that jazz. Then your counter movement doesnt need to exist because you could just directly affected what the velocity should be
@tender stag

vale karma
#

i think i saw that somewhere, but cant find it now

#

ahhhh found it, from mixamo import, theres a motion tab with root motion node, its set to none, ill set it to hip

tender stag
#

rb.AddForce(slopeMoveDirection.normalized * acceleration);

#
if(isGrounded)
{
    moveSpeed = isSprinting ? sprintSpeed : isCrouching ? crouchSpeed : isCrawling ? crawlSpeed : walkSpeed;
}
else
{
    moveSpeed = (isSprinting ? sprintSpeed : isCrouching ? crouchSpeed : isCrawling ? crawlSpeed : walkSpeed) * airVelocityMultiplier;
}
vale karma
#

yea haha it didnt work go figure

eternal needle
teal viper
vale karma
#

no i meant the solution i thought i had

vale karma
#

i cant find it on the animator tab :/

tender stag
#

it works fine

teal viper
eternal needle
tender stag
vale karma
#

like the run animation itself? i looked on the animator controller and that was the solution i tried

tender stag
#

because then u could literally change direction straight away

#

with this it isnt instant

#

more realistic feel

teal viper
teal viper
#

To an object in the scene

tender stag
#

depending on the acceleration value

#

u see how mid air i try and change direction?

#

how it takes a long time

vale karma
#

im pretty confused, but heres a vid of all the things you may be talking about

tender stag
#

disable root motion on the animator

vale karma
#

im blind lol where is it at?

faint sluice
tender stag
vale karma
#

:0 whattttttttt

#

im an idiot

tender stag
vale karma
#

i forgot its on the model i imported and not on the empty i have everything else

#

i didnt connect the dots

teal viper
vale karma
#

okay, good to know, im not very good at animationssadok

teal viper
#

You guys made it too easy for him. I was gonna drag him through the manual...🥲

vale karma
#

I KNOW, i was waiting for it dlich

teal viper
#

Next time

vale karma
teal viper
#

Does that fix the issue though?

tender stag
#

took me half a day

vale karma
#

yea, it works, probably fixed more issues i didnt even know about

queen adder
#

is there a way to like make time instantly go 10 seconds?

#

all thing reliant on time to autoprogress

#

or even better maybe a while loop of slowly passing time pass very quickly in small intervals

rich adder
#

timescale ?

queen adder
#

nothing else?

#

like really instant :>

#

if i need to do something after, imma just do it in the next frame?

rich adder
#

idk its one way , depends. what are you trying to do exactly with it

tall delta
#

do you only need physics object to timeskip, or every single monobehaviour?

queen adder
#

just a sleep system

#

when u sleep progress things

rich adder
#

dont you have a custom clock ?

queen adder
#

what is that

rich adder
#

like in-game clock?

tall delta
#

ah, then I would say fire off an event and have every relevant script skip time.

rich adder
#

I usually have a gameclock where i can speed up/slow down and other things depending on time just get events from it, like tick etc.

queen adder
rose galleon
teal viper
teal viper
shell sorrel
#

then then its just a matter of scaling that by how much time you want to pass and adding it up

teal viper
#

I assume they want everything in the scene to move as if a lot of time has passed(like npcs and physical objects)

shell sorrel
#

yeah that would be pretty implementation dependent

rose galleon
shell sorrel
#

at work i can make that happen, but its because the actions in my npc behaviors are all programmed with the ablility to work in real time, and to just instantly apply the final state

rose galleon
#

why tho? The bool is only supposed to become true after the interaction happens, no?

teal viper
rose galleon
#

i used the jump code twice, and bools to make that

teal viper
#

Here's a pro tip on asking questions: don't assume people have access to the contents of your head or project.

shell sorrel
#

double jump is really just regular jump code with a tweak

shell sorrel
#

instead of checking if they are grounded, you check jump count to see if you are aloud to jump

teal viper
shell sorrel
#

once grounded you reset the jump count

rose galleon
teal viper
#

Yeah, I'd suggest doing it the way Passerby recommended.

vale karma
#

whats going on here with my jump animation? the code runs fine, never had problems with it so i know its the animation states, i am scratching my head

#

ohh got it workin, i was setting the ground state to transition to the jump, not the specific walk/run/idle substate, so it didnt see it

reef gale
#

Hey, I need some help regarding RigidBody physics. Essentially, when the player runs into a wall, the forces do a funny freezing thing where they all stop suddenly. Could I please have some help though?

#

Here is my code by the way:

#

!code

eternal falconBOT
reef gale
#
public class PlayerMovement : MonoBehaviour
{
    private void Awake()
    {
        rb = GetComponent<Rigidbody>();
        if (rb != null)
        {
            rb.freezeRotation = true;
        }
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow))
        {
            jump = true;
        }
    }

    // FixedUpdate is called once per physics step
    private void FixedUpdate()
    {
        if (!CubeExplosion.hasExploded)
        {
            transform.Translate(Vector3.right * Time.deltaTime * Input.GetAxis("Horizontal") * speed);
        }
        if (jump)
        {
            if (!CubeExplosion.hasExploded)
            {
                // Bit shift the index of the layer (8) to get a bit mask
                int layerMask = 1 << 8;

                // This would cast rays only against colliders in layer 8.
                // But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask.
                layerMask = ~layerMask;

                RaycastHit hit;
                // Does the ray intersect any objects excluding the player layer
                if (Physics.Raycast(groundCheck.position, groundCheck.TransformDirection(-Vector3.up), out hit, 0.75f, layerMask) || Physics.Raycast(groundCheck2.position, groundCheck2.TransformDirection(-Vector3.up), out hit, 0.75f, layerMask) || Physics.Raycast(
groundCheck3.position, groundCheck3.TransformDirection(-Vector3.up), out hit, 0.75f, layerMask))
                {
                    Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
                    Debug.Log("Did Hit");
                    rb.AddForce((Vector3.up * jumpForce) * Time.deltaTime, ForceMode.Impulse);
                }
                jump = false;
            }
        }
    }
}
rose galleon
#

how do I check collision by time touched, not just by the first touch?

shell sorrel
rose galleon
#

no

#

completely different thing

#

more of a damage kind of thing

shell sorrel
#

oh so want like damage over time in colldier

#

as something enters collider add it to a list, as it exits remove it from the list

#

in the Update method apply your damage and multiply it by time.deltaTime

rose galleon
#

how do I add a float to my vector?(tryna make a dash)

vale karma
#

i have a problem where my exit state is not called when changing the parent state. So say i am walking (sub) in grounded state (super) and jump. The exit state is called for the super state, but not its sub state

vale karma
#

with say vector = new Vector2 (x, floatValue, z);

#

theres also vector = Vector2.up * floatValue;

#

im sorry these are for changing the y value, to change the x value it goes in the x spot, and also Vector2.right *- or + floatValue

gaunt ice
#

vec.element+float

edgy forge
#

I need a singleton or something I think. I'm downloading AssetBundle content and I want that object to persist, but after I download it I kill the scene and load a new one.
are any gameobjects I spawn while the first scene is open going to stick around?

primal turtle
#

66 - 93, It won't fully run,

#

Can anyone figure out why it won't play?

jade quarry
#

I cant find Ai navigation under package manager

#

is there anyway I can still gett it ?

primal turtle
#

anyone here? :(

vale karma
#

i think its called navmesh

#

or nav something

#

its a bit dead tonight, but usually its busy

jade quarry
#

I am saying it not even here TT

vale karma
#

zoom out the picture

#

show me the entire window

#

most likely your looking in your project, you need to look in the unity registry

jade quarry
#

nvm

#

u were right thx man

vale karma
#

haha np

solar charm
#

idk what the problem is, i was following the tutorial and couldnt fix this problem, PLEASE HELP!

rich adder
eternal falconBOT
vale karma
#

i hate cropped photos haha, i turn into a crime scene investigator

rich adder
#

yeah the new style sucks lol

vale karma
#

im literally setting up a github project just so i dont have to copy and past stuff

#

code for 5 hours to save u 5 minutes

solar charm
solar charm
rich adder
vale karma
#

i just wish i was a GOOD programmer... i have so many good usefull ideas i could implement at my computer repair shop, and websites, etc, but i suck, and its such a slow process

solar charm
solar charm
#

so feel good about the fact that not a lot of people have your knowledge

solar charm
#

ohhh im so dumb sorry xd

rich adder
#

its fine lol

thick storm
#

I am ngl bro I am taking the unity beginner tutorials and stuff and I am really far on them but the main plan was to just learn the coding language and then switch to unreal engine again as I was doing world design and level design there before but I am ngl bro I am really having fun just coding way more than visual scripting and I even thankfully got good enough where I can listen to what the tutorial want me to do and do it before watching the tutorial and then confirming my work with the tutorial. and aside from that man the unity community got to be the best and most helpful community I have ever seen so I am really hard questioning going back to unreal lol.

solar charm
thick storm
solar charm
thick storm
solar charm
#

thanks, u 2 ❤️

vale karma
#

the problem isnt understanding the code to use it, its blending the code and refactoring it with your own once you learn it. It develops new ways to find errors a video or comments didnt go over before

vale karma
#

yea, its terrible

thick storm
vale karma
#

YES, i am a bit above that now tho, i can add states and substates to a state machine, and barely understand a game-ready inventory system just enough not to screw it up

#

but like everything i do outside a tutorial will always throw errors, not change the outcome, or do nothing. Even though it works in my head haha

thick storm
#

not there yet but I will be there one day hopefully

rich adder
vale karma
#

rn i am setting up github, after i need help from the binary gods

thick storm
vale karma
#

i havent used chatgpt, idk why but it seems to be too vague

#

or if i have to tell it such specific parameters that im proofreading my paragraph before i send it thats too much

ashen isle
#

ok go easy on me i am VERY beginner, but how i read this is that i cant name the camera a term that is used in code but no matter what i change it to it gives the same error (ignore thge last two compiler errors)

vale karma
#

what is Screen1 and 2 referring to?

ashen isle
#

thats what i originally named the cameras but it gave an error, im gonna change that after

thick storm
#

I am pretty sure you have to make variables for the screen one and two correct me if I am wrong

#

cause right now they are just names with no actions

vale karma
#

so you may have to start a bit earlier in the learning journey than this, it looks like you still need to set your camera objects to the variable, and then also you have the concept wrong there

ashen isle
#

oh i know like i said ignore the last two, im worried about the "a namespace cannot contain members etc."

#

im pretty sure its "public camera <name>" but whatever i put for the name that error wont goaway

thick storm
#

see this is something that I would put in chatgpt and it usually just fix it and tell me my mistake

ashen isle
#

lol

vale karma
#

unless he gets why he got it wrong hel have to do that a million times lol

thick storm
#

true

vale karma
#

so you basically made a variable, but what does the variable Camera Cam1 represent?

ashen isle
#

yeah ignore the entire start function im not worried about it rn

#

im making a crappy fnaf game im still teaching myself the basics

vale karma
#

im not either, what does the variable represent

ashen isle
#

im a baby in trhis lol

#

so im trying to make the game start on cam 1 (the office)

vale karma
#

what is the public Camera Cam; supposed to represent?

ashen isle
#

the office

thick storm
#

might just be a problem with your ide because I can add numbers to variables with no problem

ashen isle
#

where the player starts

vale karma
#

is it the camera?

ashen isle
#

yeah

#

i might not understand your question im sorry

vale karma
#

okay, so you made a variable that takes a type thats a camera

ashen isle
#

yes

vale karma
#

but, thats all you did, you named it Cam1 or something.

ashen isle
#

yeah

#

but i changed it to screen1, office, oofice, nothin

vale karma
#

all it knows rn is that you have an empty variable that holds a type camera. You have no actual information it points to inside of it

ashen isle
#

same error

#

wdym

vale karma
#

So, we get the component, say, a gameObject, and get the information at the start of the script, so the rest of the script knows what to do with it

ashen isle
#

isnt that why its poublic so i can draG It in in unity

#

do i have to do that for the error to go away

vale karma
#

so far we got

public gameObject cam;

void Start() 
{

}
#

im showing you lolll listen

grizzled zealot
#

All of a sudden I get all these CS3001, CS3002, and CS3003 warnings that my code is not CLS compliant. This include ScriptableObject and GameObject. Is there anything I can do to turn off these warnings?

ashen isle
#

sorry lol

thick storm
#

so like for example if you use a public with a float instead you will not be able to drag and drop

ashen isle
#

yeah a public float is a numerical value right

vale karma
#

but, in order to get the components information, we need to grab it from the top. So everything in the scene exists on a game object. that game object can have things like position, rotation yadayada. here, we are using the gameObject cam, which by using public, we can set the object from the hierarchy into the slot, and then reference the information from that game object in code

ashen isle
#

oh

#

so i replace cam with gameObject?

thick storm
vale karma
#

so it would look like ```
public gameObject cam;

void Start()
{
cam = GetComponent<GameObject>();
}

ashen isle
#

ooooh gotcha

#

l;et me try it brb

vale karma
#

i believe you can pull it from code using cam = gameObject.GetComponent<GameObject>(); or just from the inspector using public or [SerializeField] private

#

im sorry for taking a long time to explain it, but it is really necessary in order to further ur learning path

ashen isle
#

I thought i only had to do that if the script wasnt already on the game object. The cam im trying to reference is a child of the parent game object that the script is on

#

no ur good i appreciate the help

vale karma
#

yea thats correct, i use whichever way is convienent at the time

ashen isle
#

ik u had to drag and drop anyway but i thought getcvomponent was used to grab a diff game object

#

oh gotcha

#

thank u man

primal turtle
#

anything I need to check off or smt?

#

I can't get OnMouseOver

#

to work

vale karma
#

im not sure what your game is supposed to be about but i dont normally use kinematic rigidbodies

primal turtle
#

I added collider made it in front but it still won't register for some reason

vale karma
#

did you check the IsTrigger box?

primal turtle
#

Shouldn't I?

vale karma
#

and use public void OnTriggerEnter2D(or 3D)() {}

#

yes if you want to check if another collider has entered that collider, then yes

primal turtle
#
    void OnMouseOver()
    {
        logic.springPlaceable = false;
        logic.platformPlaceable = false;
        Debug.Log("ASD");
    }

    void OnMouseExit()
    {
        logic.springPlaceable = true;
        logic.platformPlaceable = true;
        Debug.Log("feoih");
    }```
#

this is my script

#

and it won't return anything

vale karma
#

yea im pretty sure this would take a long time to unwrap lol... i dont know what any of this does

primal turtle
#

this is what I've been using

#

I looked at other solutions on the web and didn't find anything

#

that would fix my issue

vale karma
#

do you have an input for your mouse?

primal turtle
#

wdym?

vale karma
#

like if i press W my character moves forward

#

if i move my mouse left my character does as well

primal turtle
#

I have left click and right click currently set up.

#

It's practically a mouse only game

vale karma
#

okay, youll have to set up a vector2 for your mouse

#

i use the new input system, it basically turns the vector2 location of the mouse into left right up down

primal turtle
#
Vector2 mousePosS = Camera.main.ScreenToWorldPoint(Input.mousePosition);```
#

I've used that but now how do I check whther that's over a game object?

vale karma
#

ahh crap im not sure

#

again im not too detailed on unity either haha

primal turtle
#

I'm not even on the input system lol i've been using Input.GetKeyDown(Keycode.etc..)

vale karma
#

you COULD make it a button

primal turtle
primal turtle
vale karma
#

and then use the unity onclick event

primal turtle
#

the game object is a tilemap

vale karma
#

change the image an stuff

#

ahh out of my expertise

primal turtle
#

tilemaps don't work with UI

#

atleast, not from my expierence.

vale karma
#

yea i like 3d and vr

primal turtle
#

ooh

#

anyways, I'm gonna take a break for the night and try to resolve this tomorrow.

#

it's almost been like 5 hours just trying to fix this :(

vale karma
#

best thing to do, see ya tomorow

jade quarry
#

hey I wanted to ask a question on this

#

but I following totourial rn and its kinda old

#

and this doesnt seem to work

rich adder
jade quarry
#

I following a totourial rn

rich adder
jade quarry
#

how would I fix this

rich adder
#

you prob copied wrong

#

you already assigned agent, why are you trying to assign bools to it afterwards

jade quarry
#

theirs was like this

rich adder
#

thats still nonsense

jade quarry
#

IK

rich adder
#

which tutorial, show me

jade quarry
#

here

rich adder
#

yup you copied wrong

jade quarry
#

OHHHH

#

fuck me

summer stump
jade quarry
#

TT

rich adder
queen adder
#

How can I send my codes without image format?

#

Because I have long code and it won't fit in the image

summer stump
eternal falconBOT
queen adder
#

ah thank you

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

public class CreateCubes : MonoBehaviour
{
    Player player;
    public GameObject Cube;
    float[] possibilities = { -5.5f,5.5f };
    float x;
    float y;

    private void Start()
    {
        player = GetComponent<Player>();
    }

    private void Update()
    {
        
        if(player !=null)
        {
            if(player.Coin % 5 == 0){

                Invoke("instantiateCube", 1f);
            }
            


        }
    }

    void instantiateCube()
    {
       
        int chance = Random.Range(0, 2);

        if(chance == 0)
        {
            int chanceOfAxis = Random.Range(0, 2);

            if( chanceOfAxis == 0)
            {
                x = possibilities[chance];
                y = Random.Range(-5.5f, 5.6f);
            }

            if(chanceOfAxis == 1)
            {
                y = possibilities[chance];
                x = Random.Range(-5.5f, 5.6f);
            }


        }
        if(chance == 1)
        {
            int chanceOfAxis = Random.Range(0, 2);

            if (chanceOfAxis == 0)
            {
                x = possibilities[chance];
                y = Random.Range(-5.5f, 5.6f);
            }

            if (chanceOfAxis == 1)
            {
                y = possibilities[chance];
                x = Random.Range(-5.5f, 5.6f);
            }


        }
        
      Instantiate(Cube, new Vector3(x, 3, y),Quaternion.Euler(Vector3.zero));


    }


}


so guys I have some error about this code. I wanted to Instantiate the cube prefab just "one" time when player.Coin values is equal five and its multiples. But the issue is when start the game cubes is starting to instantiate without waiting the value. ANDDD its instantiate infinite. I don't know what am I missing here. So Is there anyone who can help me

teal viper
queen adder
#

Ahh damn right

#

so I have to add another condition to stop it

#

But sometimes its start the function without meet the conditions

#

I was more interested in that why is that

queen adder
#

I mean for example
if(player !=null)
{
if(player.Coin % 5 == 0){

            Invoke("instantiateCube", 1f);
        }
        


    }

I added the if statement just in one block. When I added like that. It was starting without meeting the condition sometimes

teal viper
#

The only condition that can actually change is the player coins. And it would be true initially(when coins are 0)

queen adder
#

So I had to write another if into if statement

teal viper
#

What conditions are you talking about? The coins amount check?

queen adder
#

Yes exactly

faint sluice
queen adder
#

Oh 0/5 % is also 0?

#

i understand it

faint sluice
#

% gives "remainder"

queen adder
#

Yes yes i know

teal viper
#

The remainder of dividing 0 by anything is 0

faint sluice
#

Then rest is simple math