#💻┃code-beginner

1 messages · Page 720 of 1

naive pawn
#

consider having the "interact" and "holdinteract" as separate things

patent wedge
naive pawn
#

those are 2 separate functionalities

#

"detect button press" vs "detect button press, keep track of held progress, check if it's full"

patent wedge
naive pawn
#

...ok?

polar acorn
#

Why does your interactable interface even care how the input happens? That sounds like something that should be on your behavior. The interface just needs to have an end point, the thing that you call when an interact happens

rich adder
#

IInteract, IHoldInteract
how hard is that?

polar acorn
#

Or, make your interface have two methods: OnInteractStart and OnInteractEnd.

Then, you call both on every interactable. Ones that are press just look for start and have an empty end method

patent wedge
polar acorn
#

Ones that work on hold actually do both

naive pawn
patent wedge
rich adder
patent wedge
#

but this is going way off topic i just wanted to know how to have an overridable / un-required boolean in my interface.

rich adder
#

..you're going against the whole design of an interfaces

naive pawn
#

massive xyproblem

polar acorn
#
class Handgun : IInteractable
{
  void OnStartInteract(){
    DoShoot();
  }
  void OnEndInteract() {}
}
class Flamethrower : IInteractable
{
  void OnStartInteract(){
    StartFire();
  }
  void OnEndInteract(){
    StopFire();
  }
}
#

Boom. One interface

#

two interaction styles

polar acorn
#

Stop wanting that

#

Interfaces, by design, do not have optional methods. The thing you're doing is making one with a default implementation. Everything that implements that interface still has that function

rich adder
#

"its a contract / an obligation" for those classes to implement those..

#

it guarantees those methods exists.

patent wedge
# polar acorn _This can not be done_

oh ok. but i don't want an onpress and on release. i want them to just have the player hold the button then it'll fire the method. which rn is handled by my interactor script that checks whether the object i'm interacting with has the boolean TakesTime set to true.

#

i'm fine if i can't.

naive pawn
#

starting to feel this is overcomplicated ngl

#

why couldn't you just have an interactable component instead of an interface
(potentially separate interactable and holdinteractable too)

then use a unityevent or something to link that to the actual behaviour

rich adder
#

if there is already and interactor with bool doing what you want, whats this conversion about interfaces again ?

patent wedge
patent wedge
rich adder
primal trench
#

let's say i have a base abstract class, gun, and a class which inherits from that, shotgun. if i later on want like, a double barrel shotgun, it'd be dumb to make a whole nother inherited class, no? is there a better way?

rich adder
polar acorn
#

Interfaces are the solution to the problem of "I don't know what class this is, I don't know what this class does, but I can guarantee, enforced by the compiler, that it has functions with these names and method signatures"

#

Optional things do not exist in interfaces

#

It cannot be done

patent wedge
primal trench
polar acorn
#

They can have functions too. They just shouldn't store state (due to inconsistencies with how they save things in the editor vs gameplay)

rich adder
#

it will be so much easier you can create almost unlimited weapon types just by changing a few common stats and creating a new SOs.
if some weapons shoot but "feel different" it just changing the stats..instead of having a clutter of classes

#

and you can still have some inheritance where needed

primal trench
slow blaze
#

Hey guys how do I make the line from the linerenderer component follow its gameObject parent?
I'm drawing it using this

if (Input.GetMouseButton(0))
                {
                    points.Add(new Point(virtualKeyPosition.x, -virtualKeyPosition.y, strokeId));

                    currentGestureLineRenderer.positionCount = ++vertexCount;
                    currentGestureLineRenderer.useWorldSpace = true;
                    currentGestureLineRenderer.SetPosition(vertexCount - 1, Camera.main.ScreenToWorldPoint(new Vector3(virtualKeyPosition.x, virtualKeyPosition.y, 10)));
                }```

which draws fine and correctly on screen but the drawing fails to follow its parent.
rich adder
#

like if your weapon has modifiable runtime stats that change, you wouldn't change it on the SO itself

polar acorn
primal trench
#

time to restart the weapon system TwT

rich adder
#

its good to just lay out all the options before delving deep. Weapons system can range from simple to very complex

#

good idea to take your time seeing what you got to work with
Interfaces, Abstracts and SO can all work together, or separate to create good weapon system

wispy wraith
#

hi guys just as a reminder how do you paste code on the server?

rich adder
#

hmm dyno asleep?

slow blaze
#

well that was underwhelming

#

!code

#

dyno indeed hit the hay

eternal falconBOT
rich adder
#

holy laggin hell

slow blaze
#

!ping

#

oh yeah brother is gone

rich adder
slow blaze
#

that didnt do it boo womp

gloomy lichen
#

hi why does my vs code wont show intellisense tooltip even after downloading unity extension on vs code and modifying my packet manager as well as external tools in unity?

hexed terrace
#

!vscode

eternal falconBOT
#
Visual Studio Code guide

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

https://on.unity.com/vscode

rich adder
gloomy lichen
grand snow
#

Make sure your unity preferences has Vs code set as the external editor too

gloomy lichen
#

i have all of that done already. When I type "Debug." or "transform." it doesnt recognizes it and intellisense doesnt show up either.

rich adder
naive pawn
#

have you installed the dotnet sdk and then restarted the ide

rich adder
rich adder
#

confirm that run dotnet --list-sdks in terminal

gloomy lichen
#

i restarted my system it works now

glacial plume
#

Could someone tell me why I cant access it? I have it already installed from registry

glacial plume
#

ty vm

#

@rich adder do you have an actual good beginner guide on unity game dev recommendation?

naive pawn
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

patent wedge
#

hey i'm can't figure out how to check where the player is looking a A, B, C i am currently using a very hacky method but even that doesn't work.

float Pos1 = (1Pos.position - PlayerPos).normalized.y;
        float Pos2 = (2Pos.position - PlayerPos).normalized.y;
        float Pos3 = (3Pos.position - PlayerPos).normalized.y;

        float dir = transform.rotation.eulerAngles.normalized.y;
        
        int val = 0;
        if (Pos2 - dir < Pos1 - dir)
        {
            val = 1;
        }
        else if (Pos3 - dir < Pos2 - dir)
        {
            val = 2;
        }
``` i really want a better method but i just can't think of it (also does anyone know how to shift lines to the left i know in vscode its Ctrl+{ )
naive pawn
#

also does anyone know how to shift lines to the left
in discord?

patent wedge
polar acorn
#

Delete the tabs

hexed terrace
#

Juste delete the blank space at the front of the line..

patent wedge
hexed terrace
#

there is not - it's not a fully fledged text editor, indentation isn't something you'd expect

polar acorn
#

So, get the directyion the player is looking in, and the directions you want to compare it to, and see which one has the highests dot product

#

(or the one above some threshold like 0.9 or something)

naive pawn
#

disclaimer: 1/-1 will represent parallelism/antiparallelism only if the inputs are normalized

polar acorn
#

Right, the key word being two direction vectors, meaning a normalized direction vector, not euler angles or anything with a magnitude

patent wedge
# polar acorn https://docs.unity3d.com/ScriptReference/Vector3.Dot.html The Dot Product of two...

so...

Vector3 Pos1 = (1Pos.position - PlayerPos).normalized;
Vector3 Pos2 = (2Pos.position - PlayerPos).normalized;
Vector3 Pos3 = (3Pos.position - PlayerPos).normalized;

Vector3 dir = Player.transform.rotation.eulerAngles.normalized;

int val = 0;
if (Vector3.Dot(dir, Pos2) > Vector3.Dot(dir, Pos1))
{
    val = 1;
}
else if (Vector3.Dot(dir, Pos3) > Vector3.Dot(dir, Pos2))
{
    val = 2;
}
``` (btw there is a better method by selecting everything and shift+tab)
naive pawn
naive pawn
naive pawn
polar acorn
naive pawn
#

you'd want Player.transform.forward

patent wedge
polar acorn
#

It is normalized

patent wedge
naive pawn
#

why do you think it isn't normalized

polar acorn
#

It is

naive pawn
#

Transform.forward
Returns a normalized vector representing the blue axis of the transform in world space.

naive pawn
umbral bough
#

bump

patent wedge
patent wedge
patent wedge
polar acorn
#

Try logging those values and see if the dot towards Pos3 is ever greater than the one for Pos2

patent wedge
patent wedge
polar acorn
patent wedge
polar acorn
#

If that condition is true, it sets val to 2

patent wedge
polar acorn
patent wedge
polar acorn
#

But also this is dot1 and dot2

#

I asked for dot2 and dot3 since those are the conditions of your if statement

patent wedge
polar acorn
patent wedge
sly vortex
#

Where's the best place to learn C#?

cosmic dagger
honest iron
#

how to see int[,] in the inspector?

wintry quarry
wintry quarry
#

what you can do is something like this:

[Serializable]
public class MyIntCollection {
  public int[] data;
}

public MyIntCollection[] allData;
red igloo
wintry quarry
sly vortex
wintry quarry
red igloo
cosmic dagger
short condor
#

IM BACK

#

Yay

rich adder
tiny crag
#

why is SpawnEnemy() being run constantly?

short condor
#

@tiny crag you have to somehow not make it run constantly

rich adder
#

also don't post code with screenshots

rich adder
tiny crag
tiny crag
#

but also for the trigger to happen 0.05 faster every time its triggered

cosmic dagger
tiny crag
#

!code

eternal falconBOT
tiny crag
short condor
#

This is not right

rich adder
rich adder
# tiny crag ok
Interval = 2f / gameSpeed;
Timer += Time.deltaTime;
if (Timer >= Interval){
  SpawnEnemy();
  enemyScript.movement();
  Timer = 0f;
  gameSpeed += 0.05f;
  foreach (EnemyScript.fullPosition enemyposition in enemyPositions){
    Debug.Log(enemyposition.x);
    Debug.Log(enemyposition.y); }
}```
tiny crag
short condor
#

Your doing something wrong then

tiny crag
rich adder
tiny crag
cosmic dagger
rich adder
#
Timer = 0f;
gameSpeed += 0.05f;
Interval = 2f / gameSpeed;```
tiny crag
#

no result

short condor
#

Nah man your doing SOMETHING WRONG THOUGH

rich adder
tiny crag
tiny crag
#

@cosmic dagger @rich adder omg all i needed to do was as randomunityinvader said and just reset the timer inside the method

#

idk why it doesnt work in the update method but it is what it is

short condor
#

Finally he did it

tiny crag
#

@cosmic dagger sorry i got the movement method inside the prefabs mixed up with the SpawnEnemy method im tired :)

tiny crag
rich adder
short condor
#

No problem

#

I'll help you whenever you need it

tiny crag
tiny crag
rich adder
tiny crag
#

yea

#

thanks for helping out btw

rich adder
# tiny crag thanks for helping out btw

order of event issue I think, I believe if you did

SpawnEnemy();
enemyScript.movement();
Timer -= Interval;  
gameSpeed += 0.05f;
Interval = 2f / gameSpeed;```
it should work fine
#

either way as long as its solved lol

frosty hound
fiery stone
#

hello, trying unity for the first time, following a quite old but good tutorial for player movement, heres my code:
https://pastes.io/unity-player-movement

but even though the movement works great, i cant jump 🤔

tiny crag
rich adder
#

if its not called, then one of those conditions isn't true

fiery stone
polar acorn
fiery stone
#

lemme record a clip

short condor
#

How do I say a useful thing

fiery stone
#

anyone?

rich adder
fiery stone
rich adder
#

removing it is not the solution..

fiery stone
#

i go up and basically glide in the air for some seconds

#

do i just change the air multiplier?

rich adder
#

what?

fiery stone
slow blaze
fiery stone
rich adder
#

all you need to do is make sure canJump starts true

fiery stone
rich adder
#

alright your project, do what you want lol

#

i offered you the solution but you seem fixed on removing something that was put in place for a reason

slow blaze
#

what does canJump do here when grounded is put

fiery stone
slow blaze
#

I guess multiJump

fiery stone
rich adder
#

the whole point of it is for a "cooldown" so you dont jump right after jumping

fiery stone
#

the glider thingy is prob because you fall so slowly

#

but why is that

slow blaze
#

if you use a Char Controller change your motion equation if you're using a rigid body increase downward velocity (or force depending on what you're using)

rich adder
#

mass does not change how fast it will fall

#

calling AddForce in multiple places is probably causing the issue in air

#

if you want something to fall faster you multiply the gravity by multiplier

#

rb.AddForce(Physics.gravity * forceFalling

tiny crag
#

im having yet another issue, i want the object running the code to keep the current value of spawnSide for the duration of its existence, which is why i try defining it in Start(). But that value isnt saved for the method called movement(). Why is that?

rich adder
fiery stone
rich adder
fiery stone
rich adder
#

make a video and post it, there is no VC channel here

rich adder
fiery stone
rich adder
fiery stone
tiny crag
fiery stone
rich adder
fiery stone
#

like when i dont press WASD?

polar acorn
rich adder
#

also that linearDamping is pretty high

fiery stone
fiery stone
rich adder
#

well technically JUMP is

eternal falconBOT
rich adder
fiery stone
#

lemme paste the updated code

rich adder
#

unless somehow Jump keeps running, its probably the damping imo

polar acorn
#

Put a log in Jump()

fiery stone
polar acorn
#

Then it's the damping

fiery stone
rich adder
#

pretty sure ..damping doesnt just pick XZ on its own..

fiery stone
rich adder
fiery stone
#

thanks for the help guys

#

ill be back later

#

because now ill try to implement sliding

hallow acorn
#

https://hastebin.skyra.pw/fezuqesopu.pgsql bro im gonna start tweaking im working on this for hours but i cant figure out what causes the problem. i have this character that should choose a random point to move to, but if its hungry (searchFood = true) it should first check if theres food near it, if yes it should move there, if not, it should search a random point again and move there instead. at first when it was hungry, it wouldnt move at all. ive got it to work a little bit, but as soon as a berry is in its range its getting mentally unstable or sh as it moves in a zigzag randomly. but if theres no berry in sight it just works. im getting more and more mentally unstable the more i try to fix this, so im pretty sure i wont find the issue myself, thank you in advance

rich adder
#

this is code is all over the place, many moving parts. Debug each one to see where it goes wrong

#

also seems way to overcomplicated for what you seem to want to do

hallow acorn
#

how would you do it?

rich adder
hallow acorn
#

are there some specific examples where?

rich adder
hallow acorn
rich adder
hallow acorn
#

yes exactly

#
if (Vector2.Distance(target, currentPosition) <= 0.2f)
{
    rb.linearVelocity = Vector2.zero;

    timeBetweenMoving -= Time.deltaTime;

    if (timeBetweenMoving <= 0)
    {
        targetX = Random.Range(transform.position.x - sightRadius, transform.position.x + sightRadius);
        targetY = Random.Range(transform.position.y - sightRadius, transform.position.y + sightRadius);

        timeBetweenMoving = Random.Range(-defaultTimeBetweenMoving / 3, defaultTimeBetweenMoving / 3) + defaultTimeBetweenMoving;
    }

}```
rich adder
#

make the distance a variable and debug it, see what values are doing
also isn't zig zagging meaning changing the target pos constantly, I dont think I see anywhere where you only search target if one was not set?

pseudo sorrel
#

Hello, Is anyone familiar with Photon sdk's and how they work??

rich adder
rich adder
hallow acorn
# rich adder which part

"also isn't zig zagging meaning changing the target pos constantly, I dont think I see anywhere where you only search target if one was not set? "

rich adder
hallow acorn
#

oh yeah that might be really possible

#

should i disable every berry except one for testing?

rich adder
#

try that first sure

hallow acorn
rich adder
hallow acorn
#

huh

#

thats weird

rich adder
hallow acorn
rich adder
hallow acorn
#

np

#

weirdly it just walked over the berry but completely ignored it

rich adder
#

and no zig zag ?

hallow acorn
#

no. just walking over the only thing able to keep it alive

#

0 survival instincts

rich adder
#

its only as smart as what you code it to be.. most likely something wrong in the code

#

I would use a switch statement here for a very basic state management, so you can see what happening with their " current thinking" too

hallow acorn
#

bro that theres something wrong in the code is the only thing i know rn 😭

hallow acorn
#

i think im just gonna scrap the whole project i dont want to see this little guy anymore

rich adder
#

Idle, Wandering, SeekingFood
etc.

#

you dont have to scrap the entire project, but perhaps make a simpler part / project where you only test the wander system / food seek

hallow acorn
#

imposter syndrome kicking in right now🙏

rich adder
#

thats what I usually do when Im stuck

rich adder
hallow acorn
#

this project is basicly empty

rich adder
rich adder
hallow acorn
rich adder
#

this is 2D project right ?

hallow acorn
#

yea

#

why?

rich adder
# hallow acorn why?

just curious, so you're not using pathfinding right ? just randomly moving top down or something in random dir ?

hallow acorn
#

man was i wrong

polar acorn
rich adder
#

you can still achieve the random pathing, just use A* project to simplify it or use the custom Navmesh by h8man

polar acorn
#

I think it's a CGP Grey quote that "Any solution that 'seems reasonable' and 'is easy to implement' is universally a colossal failure, the albatross of which will shackle all future developments in the field for decades"

rich adder
#

now thats a quote

hallow acorn
hallow acorn
rich adder
#

hmmm..lemme see If I can cook a quick example

hallow acorn
polar acorn
#

yes

polar acorn
hallow acorn
#

couldnt remember that quote tho

proper needle
#

i havent been on unity for a while so does anyone know what this is

proper needle
rich adder
#

well yeah those are part of MB

#

if you don't call them, they wont be called

proper needle
proper needle
proper needle
#

thanks

rich adder
#

when making a new script make sure you make it a MonoBehaviour script
(if you want to use those method / put script on gameobject)

proper needle
#

do i just replace void start with monobehaviour.start

#

if not what do i do

#

oh nevermind

rich adder
proper needle
#

is this right

#

im assuming it is

hallow acorn
#

try it

rich adder
#

yes

proper needle
#

alr imma test it

#

it works thanks

hallow acorn
#

is subtracting 1/50 from a value in FixedUpdate the same as subtracting Time.deltaTime in Update?

slender nymph
#

assuming you haven't changed the rate that fixed update is called it theoretically is. but also, why not just subtract Time.deltaTime?

hallow acorn
slender nymph
#

the better solution would be to use Time.deltaTime

hallow acorn
#

didnt evenn know you can change the rate

hallow acorn
slender nymph
#

yes. did you know that there is documentation for things like Time.deltaTime that tell you how they behave?

hallow acorn
#

ok sory ill use documentation next time

hallow acorn
# rich adder

thats crazy work for half an hour if you ask me thats pretty cool

#

especially considering i took 3 hours to make something twice as complicated work half as good

rich adder
hallow acorn
#

thats crazy

rich adder
hallow acorn
#

if (foodTarget == null) is this so it doest change the target as lon as it exists so it doesnt zigzag with multiple possible targets?

rich adder
#

yes that is so it doesnt keep running Overlap when it has a target to go to

#

when you reach the destination with V2.Distance you can eat the food and set it to Null

#

perhaps this simplified version can steer you in the right direction

#

ofc it would be also better to make a simple state machine with enum like mentioned earlier

hallow acorn
#

youre pretty good at what you are doing

#

thank you so much btw youre a lifesaver

rich adder
hallow acorn
rich adder
hallow acorn
#

yea

rich adder
#

ask me anything procedural and I go into fetus position and rotate in circles on the floor

hallow acorn
#

ngl thats so relatable tho

primal trench
#

how do i get alpha with .dds files? it shows transparency in my file browser but it's gone when in unity and there's no alpah options in the import bit

grand snow
#

Didn't even know it had any support for em

rich adder
primal trench
rich adder
#

ohh I see..thought things like DXT compression took care some of that, but Ig idk enough about it so i'll take your word UnityChanThumbsUp

primal trench
#

im not an expert i just know a few things TwT i did fallout 4 modding awhile back

rich adder
#

was about to say i only knew about dds cause of fallout :p

#

basically gpu compatible bytes vs metadata contained or something..

grand snow
#

You provide a normal image and it handles the format and mip gen based on settings you configure

rich adder
#

was about to say saw option to generate mip in import texture

grand snow
#

Pretty sure even source engine had mip gen it's nothing new

primal trench
#

whatever is there a way to use alpha with .dds?

grand snow
#

Check the docs for what textures unity supports. I'm going to presume no

languid pagoda
#

uh i shut down unity shut down my pc. and now none of my game audio works. Any suggestions?

#

there is sound int he editor I can manually play the script from the assets folder in the editor but its like none of my audio is actually playing now and I cannot figure out why

#

audiosource.Play is being called if i disable the audiosource it will throw warnings in the console

frosty hound
#

Check your game view isn't on mute, there's a button at the top.

#

Nevermind, don't crosspost please.

elder osprey
#

Hey, I'm trying to learn how to make Inverse Kinematics. I'm trying to make logic that moves the head point to where the player clicks, and its flying away so fast it breaks int limit. This is my code: https://hastebin.com/share/onifetozip.csharp

short condor
#

Is boocean a real thing or am I just making up nonsense

frosty hound
#

Nonsense

eternal needle
elder osprey
eternal needle
broken sail
#

when I lerp a rotation how can I keep it from going all the way around?

wintry quarry
broken sail
#

the trail obscures it a bit, let me make it more clear hold on

polar acorn
wintry quarry
#

but it sounds like maybe you're lerping euler angles instead of using the appropriate function for rotation interpolation which is slerp

broken sail
#

Trident.transform.eulerAngles = Vector3.Lerp(Trident.transform.eulerAngles, new Vector3(0, 0, 0), 0.3f);
yup that's it

#

so do I slerp rotation instead of lerping eulerangles?

wintry quarry
#

Yeah lerping eulerangles is a recipe for this kind of thing.

You can use Quaternion.Slerp instead

#

Trident.transform.rotation = Quaternion.Slerp(Trident.transform.rotation, Quaternion.identity, 0.3f);

#

although this is also framerate dependent but that's a whole separate issue.

broken sail
#

yup, works now

sudden prairie
#

No one answered it yet ⬆️

wintry quarry
#

most likely the body is just settling back to the stable orientation as you try to rotate it

#

it's also not clear exactly where this function is running

thorn yoke
#

hello beautiful people i need help making this door and door window open in sync. its from the abandoned asylum free pack on the unity store if that makes any difference

fiery stone
#

guys i have a problem

#

the character controller tutorial i was following

#

doesnt implement sliding

#

only crouching

thorn yoke
#

its somewhat similar to ue5 which is what im use to but i heard the pathing and ai stuff is way better here so here i am

teal viper
eternal falconBOT
#

:teacher: Unity Learn ↗

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

teal viper
#

Or read through the manual.

thorn yoke
#

i will absolutely do this once i figure out how to get the textures on some pinkage i got going on.

high mauve
#

hi

#

i need help with terrain generation so i am trying to build a map that generate infinitely and has trees and every thing with a road on which we can drive i tried the unity documentation but under terrain section there wasn't any thing about that can some one help

fickle plume
#

@high mauve Don't cross-post. If you have a code question then post the code you have problem with.

high mauve
#

i dint have a code , and what is this about cross-post isnt this a beginner chat?

fickle plume
eternal falconBOT
high mauve
#

ok thankyou

low goblet
#

when trying to reference my inputs with

[SerializeField] private InputActions _inputActions;

nothing pops up, and I have to reference individual refs such as

[SerializeField] private InputActionReference _zoomInput;

is this intended?

fickle plume
eternal falconBOT
low goblet
#

It's just my custom inputs with the input event system, my IDE is working fine and intellisense/debugging all works perfectly fine

fickle plume
#

Make sure your custom class is [System.Serializable]

low goblet
#

Still can't get it to show up in the interface for some reason after doing that, InputActions is just from the unity generated class

#

turns out setting the default value to something non null seemed to serialize it thonk

fickle plume
#

Might not have been saved previously. Project needs to recompile for serialization to update. Saving triggers it unless overridden.

low goblet
#

appreciate the help

glossy vigil
#

im new to unity, just bought a template for an incremental game im trying to create i imported it into my project but idk how to set it up/ make it run liek its advertise like despite me adding it idk where to put it for the thing to run

#

like i have it here

#

but i dont know how to actually put it to display so then i can mess around with the settings

rancid tinsel
#

Does anyone have a resource on how achievements (10 kills in smoke etc) are done in a clean, modular way? It's something that's been picking at my brain lately and I can't picture how it might be done

#

Not necessarily a C# resource just in general, or a source-code example from industry maybe?

keen dew
glossy vigil
#

What’s a scenes canvas

hexed terrace
glossy vigil
#

How can I access it

hexed terrace
# glossy vigil What’s a scenes canvas

This is a channel for code questions.
This server is not for help with bought assets.

Read the docs that came with the asset.
Contact the publisher of the asset for help.

Do tutorials on !learn 👇 so you know what you're doing

eternal falconBOT
#

:teacher: Unity Learn ↗

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

glossy vigil
#

I try dragging it in the scene but it doesn’t work

burnt trout
glossy vigil
#

it says this

#

but i try draging the button on the scene

#

and nothing happens

#

i try dragging it here

#

do i need like a specific scenes for these to run

keen dew
#

There isn't anything to "run". They are UI elements. You'll have to first learn how to do UI in Unity before using this asset

glossy vigil
#

wait

#

so this asset project

#

is just GUI elements

#

not a functionablre GUI?

keen dew
#

🥳

glossy vigil
#

fuckign hell

#

just got famoosed

sleek light
#

does anyone know how to read and work with values from light probes?

eager elm
rancid tinsel
#

This might actually be the best/only approach, but you never know

grand snow
sleek light
#

@grand snowim trying to make a stealth system where the players lighting is compared to the lighting of the wall behind the player (from the enemies perspective), and i read somewhere that light probes could be used for that kind of stuff but I'm open for better alternatives if there are any

river bone
grand snow
#

This would be editor only automation to prepare the data

sleek light
#

@grand snow I'm sorry, I'm very, very new to all of that. Could you explain that to me like I'm an idiot?

grand snow
#

Make new component that stores a grid of light data. You can read the lightmap data, parse it and write the new light data to your component in editor.
We can modify assets, prefabs and scenes outside of play mode with code which lets us do cool stuff and automations like this.

You can get the probes for a scene with https://docs.unity3d.com/ScriptReference/LightProbes.GetSharedLightProbesForScene.html
You then need to get the baked probes, sample the lighting and based on that figure out brightness for that position.
It may be a bit advanced but is most likely the way this would need to be done. Access the light probes and sampling colour would be required either way.

trim quarry
#

for some reason game build size keeps being more than 100 mbs, theres any reason on this?

#

all the assets that i inserted to the game is mirror

#

also it has a few amount of assets like textures and meshes

#

overall it shouldnt be more than 100 mbs

primal trench
#

how do i make it so if the player presses like, A and S at the same time it chooses one of the two instead of just stopping the player's movememt

naive pawn
#

do you mean like, A and D

#

depends on how you're processing input

primal trench
#

but i want it to choose w or s if both are pressed

naive pawn
#

yeah that's usually the intended behavior, and how you change it depends on how you're processing input

grand snow
#

and figure out from there whats taking up lots of space!

primal trench
onyx blaze
#

I'm trying to compare these strings (Line 168), but the code never enters inside the "If"

As example, I'm trying to compare "romantic" with "romantic"
But I don't know where I mistake :/

#

That's my Debug.Log

naive pawn
naive pawn
onyx blaze
naive pawn
#

well romantic should be 8 so seems like the first one has extra chars

#

where's that string from, and perhaps try logging out each char to see what said invisible chars are

#

i forget how you'd do the latter

wintry quarry
hexed terrace
#

Do not use strings to compare
Use and compare enums

acoustic belfry
#

Im trying to make the rigidbodies stay on a plataform

Doesnt work they just keep falling


public class movablePlataformBase : MonoBehaviour
{
    public Rigidbody2D rb; // Platform's Rigidbody2D

    private void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
    }
    void OnCollisionStay2D(Collision2D collision)
    {
        Rigidbody2D otherRb = collision.rigidbody;
        if (otherRb != null && otherRb.bodyType == RigidbodyType2D.Dynamic)
        {
            // Apply platform velocity to the object
            otherRb.linearVelocity += rb.linearVelocity;
        }
    }
}```
#

I mean

#

The plataform moves without them

grand snow
#

I think without them touching and there being high friction they often wont

acoustic belfry
#

Huh?

grand snow
#

adding velocity like you are wont really help because you keep adding the platforms velocity which will keep building up

acoustic belfry
#

Oh

#

Idk this was just a sketch

grand snow
#

why share it then 😐

acoustic belfry
#

Cuz is the only code i had in hand

grand snow
#

You can try translating the other rb by how much the platform moved or ensuring the velocity of the other rb does not drop below the platforms velocity

naive pawn
#

thonk the latter wouldn't allow you to go backwards relative to the platform

primal trench
grand snow
#

hmm thats true. maybe physics materials is the easy way then

grand snow
#

my other idea is adding force needed to move the other rb along with the platform

acoustic belfry
grand snow
#

yea try one with high friction on the platform

naive pawn
acoustic belfry
#

Oh

#

But the player has 0 friction

naive pawn
#

isn't parenting the usual recommendation? does that not work for rigidbodies?

grand snow
#

static can be set differently

naive pawn
acoustic belfry
#

Huh?

acoustic belfry
grand snow
#

check the doc page, there is dynamic and static friction as well as the combine mode

acoustic belfry
#

Im getting sligjty Lost, sorry ;-;

#

Ok

grand snow
#

perhaps high static friction + max friction combine mode on the platform will do it

#

actually put both high 😆

naive pawn
#

i feel like if you set only static high it could make walking forwards go backwards lol

acoustic belfry
#

How i can acess to dynamic friction?

#

I mean

grand snow
#

these are options on a physics material asset

acoustic belfry
#

Separately the frictions

grand snow
#

did you try making one even??

#

make one, slap it on, try out shit

primal trench
acoustic belfry
#

Doesnt appear

#

I already made a material (thats why the player has zero friction)

#

Theres only..friction

#

And bounciness

#

And the combines

grand snow
#

fuck is this 2d?

acoustic belfry
#

Yes

#

It is

grand snow
#

dang yea i forgot that has less options avaliable. try it anyway

acoustic belfry
#

Sorry i put the 3D one in hiatus cuz i discovered i would struggle with level design

acoustic belfry
grand snow
#

doesnt exist for 2d physics 🙁

#

they are seperate physics libs so we dont get the same stuff

acoustic belfry
#

O o f

#

Then what i should do?

frosty hound
#

This was already mentioned yesterday. Take the velocity of the platform and append it to the velocity you're planning on moving the character, this frame.

#

What you're doing now is having the platform control the velocity of the player, which is backwards.

acoustic belfry
#

I try it

#

Oooh

#

I mean

#

Im doing it that way cuz it must also checks enemies

#

Maybe objects

#

So it would look odd if some objects worked and others fell

frosty hound
#

And those objects should have controllers which handle this, not the other way around. Platforms are dumb objects, they should not have authority over anything other than their own movements.

acoustic belfry
#

Makes sense

primal trench
rocky canyon
#

platform be like: "imma platform doing my thing.. up n down, whatnot"
thing thats controlling the player movement: "ohh, hey platform, now i know ur a platform gimme ur up n down whatnot and ill go ahead and (add)apply that to the movemnt code we already got going on"

acoustic belfry
#

So in theory
When calculates if is standing on top of something or not, should check if has component movableBoi, if it is, should plus it velocity with thr plataform's velocity, right?

frosty hound
#

Yes, which is what was said yesterday

rocky canyon
#

like u on an airplane... if u walkin down the aisle.. ur moving a certain velocity.. and the planes moving a certain velocity... and from a bystander ur actually moving with both added

acoustic belfry
#

I did it. Didnt worked

What i did wrong?

frosty hound
acoustic belfry
#

Holup

#

Let me send the code

rocky canyon
#

same concept can be applied to all kinds of movement, momentum stuffs especially

#

knockback, so on and so on

patent wedge
#

how do i exit out of an if statement and go to the bottom else?

acoustic belfry
#

Holup

sour fulcrum
rocky canyon
grand snow
#

either if or else gets executed. If you want both you need a second if

rocky canyon
#

make a function that does the else stuff and call it at the end of the if

#

and also in the else at that point

grand snow
#

eh you can probably have a bool to control this logic being executed

acoustic belfry
#

Like this?

  {
      RaycastHit2D hit = Physics2D.CircleCast(transform.position, groundcolliderradius, Vector2.down, groundcolliderdistance, groundlayer);

      // Check if the hit object has the movablePlataformBase component
      movablePlataformBase platform = hit.collider.GetComponent<movablePlataformBase>();

      if (platform != null)
      {
          // Add the platform's linear velocity to your own rigidbody
          if (rb2D != null) // Make sure you have a reference to your rigidbody
          {
              rb2D.linearVelocity += platform.rb.linearVelocity;
          }
      }
  }```
rocky canyon
#

really not the same thing tho yea

acoustic belfry
#

I mean

#

The player doesnt stay with this neither

rocky canyon
#

is the code running? have u debugged and made sure u getting values?

frosty hound
#
  1. Are you even getting to this code? You haven't debugged that.

  2. Are your platforms actually using physics based movement?

#

These are basic things you should know to do by now. At some point, this handholding needs to be upgraded into critical thinking.

naive pawn
acoustic belfry
#

I mean, it would be weird if didnt ran

rocky canyon
#

debugging especially.. it should immediately be the first and always go to.. come with the facts! 📖 👨‍⚖️ lol

frosty hound
#

Alright, good luck then.

primal trench
acoustic belfry
#

All debugs work

naive pawn
rocky canyon
#

so the linearVelocity of ur player rigidbody has the extra platform velocity? do the numbers add up?
if soo it is working.

naive pawn
#

@primal trench why exactly do you want that behavior though? like i mentioned, it's usually the normal behavior that pressing both sides yields no movement

rocky canyon
#

if not.. what else would it be maybe try a multiplier to multiply the force of the platform and see if it just takes more effort to move ur rigidbody around

acoustic belfry
#

Mmm, idk

Only the debugs are triggered

acoustic belfry
#

......

It coould be part of the issue, if the plataforms arent moving actually?

#

A huge empty gameobject moves

#

It has plataforms inside

#

....yeah

rocky canyon
#

a "platform" should be the actual rigidbody object w/ a collider

#

or a collider within it children

acoustic belfry
#

It has a rigidbody

rocky canyon
#

b/c the raycast detects the collider
the rigidbody gives u the velocity

acoustic belfry
#

Just ...that doesnt move

hexed terrace
#

you have to move it by physics

rocky canyon
#

well if nothing is moving then ur player isnt gonna be moving

acoustic belfry
#

The parent moves with physics

hexed terrace
#

🤔

acoustic belfry
#

The childrens are it "decorations"

#

The thing is this

#

Big empty game object, has a rigidbody and a boxcolliser on the bottom for move, inside of it, are kinematic boxes

#

Its like a walking mountain

hexed terrace
#

This sounds like you're confused, the visual doesn't matter.

#

the "platform" is all the components made up to make it.

acoustic belfry
#

The plataform is a children

#

The plataform doesnt even moce

#

The parent moves

#

And by so, the plataforms follows it

#

Do that affects smt?

rocky canyon
#

the collider gets detected by the raycast
its hunting for movablePlataformBase
and im assuming it has a rigidbody
that means in theory all of these pieces need to be on the same gameobject for your script/setup to work from what it looks like (bare minimum the collider and the plateformbase script)

#

and just for a pro-tip u should be probably workin on this in isolation since ur having trouble with it..
forget the elaborate parent/many platform deals u got going on. and make a super simple platform..
test ur code with that.. if u can see and know how it works before hand it makes troubleshooting more complex situations make sense as u know what ur looking for.. and what the conditions made it

hexed terrace
acoustic belfry
#

Oh

#

Well, i guess makes sense

#

Is just i thought it wouldnt be that complex

primal trench
#
    {
        Vector3 Speed = new Vector3(MoveInput.x * CurrentSpeed, 0f, MoveInput.y * CurrentSpeed);
        Speed = transform.rotation * Speed;

        CharController.SimpleMove(Speed);
    }```
why can't the player move in the air
rocky canyon
# acoustic belfry Is just i thought it wouldnt be that complex

it is relatively simple.. like i said start simple and then graduate to more complex..
also (in my honest opinion) it helps do things like expose the rigidbody in the inspector like i did here.. so that i 💯 know
when its getting velocity from the rigidbody.. (inside hte platform code its just using simple Lerping and the rb.MovePosition())

and as u can see after getting it working thats just step one.. as theres already 1 bug i found in my own implementation where when the platform moves downwards it loses contact with the rigidbody.. probably some drag/dampening things i would need to consider to continue

tidal kiln
#

this is a simple fix, flying a character takes much more than that @primal trench

primal trench
#

ohhh no i meant move in the air as in like

#

you can adjust while in the air

tidal kiln
#

adjust what?

frosty hound
#

There is nothing in your code that suggests you cannot.

tidal kiln
#

meaning you can move slightly while in the air on the x and z axis?

frosty hound
#

The only assumption here is that your HandleMovement isn't being called while in the air, for whatever reason. Maybe you're only calling it when you've detected the player is on the ground.

trim quarry
#

its in the build?

polar acorn
primal trench
grand snow
eternal falconBOT
#
📝 Logs

Documentation

Editor logs

Windows: %LOCALAPPDATA%\Unity\Editor\Editor.log
MacOS: ~/Library/Logs/Unity/Editor.log
Linux: ~/.config/unity3d/Editor.log

Unity Hub

Windows: %UserProfile%\AppData\Roaming\UnityHub\logs
Mac: ~/Library/Application support/UnityHub/logs
Linux: ~/.config/UnityHub/logs

polar acorn
primal trench
#

yes

tidal kiln
primal trench
#

but when u press wasd while in the air

#

nothing happens

polar acorn
#

Then you can move in the air.

#

If it's called in Update uncondtionally, and nothing else is moving the character, this will work in the air

#

Maybe you should share !code

eternal falconBOT
trim quarry
primal trench
#

[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour
{
    [Header("Movement Speeds")]
    [ReadOnlyInspect] public float CurrentSpeed;
    [SerializeField] public float WalkSpeed = 3.0f;
    [SerializeField] public float SprintSpeed = 6.0f;
    
    public enum MovementState
    {
        Walking,
        Sprinting
    }

    [ReadOnlyInspect] public MovementState State;

    [Header("Look")]
    [SerializeField] float MouseSensitivity;
    [SerializeField] float VerticalClamp = 80.0f;

    [Header("Input")]
    [ReadOnlyInspect] public Vector2 MoveInput;
    [ReadOnlyInspect] public Vector2 LookInput;

    private float VerticalRotation;
    private CharacterController CharController;

    [Header("References")]
    public Transform CameraRoot;

    private void Start()
    {
        CharController = GetComponent<CharacterController>();
    }

    private void Update()
    {
        StateMachine();
        HandleMovement();
        HandleLook();
    }

    void StateMachine()
    {
        switch (State)
        {
            case MovementState.Walking:
                CurrentSpeed = Mathf.Lerp(CurrentSpeed, WalkSpeed, Time.deltaTime * 5); break;
            case MovementState.Sprinting:
                CurrentSpeed = Mathf.Lerp(CurrentSpeed, SprintSpeed, Time.deltaTime * 5); break;
        }
    }
    void HandleMovement()
    {
        Vector3 Speed = new Vector3(MoveInput.x * CurrentSpeed, 0f, MoveInput.y * CurrentSpeed);
        Speed = transform.rotation * Speed;

        CharController.SimpleMove(Speed);
    }

    void HandleLook()
    {
        float MouseXRotation = LookInput.x * MouseSensitivity;
        transform.Rotate(0, MouseXRotation, 0);

        VerticalRotation -= LookInput.y * MouseSensitivity;
        VerticalRotation = Mathf.Clamp(VerticalRotation, -VerticalClamp, VerticalClamp);

        CameraRoot.transform.localRotation = Quaternion.Euler(VerticalRotation, 0, 0);
    }
}

frosty hound
#

Log your CurrentSpeed in your HandleMovement function and see what it is when you're in the air.

primal trench
#

it's 3

frosty hound
#

But also why are you multiplying your calculated speed with the rotation of the object? What's the purpose of that?

polar acorn
#

Also nothing here seems to be changing MoveInput so where are you reading input?

primal trench
primal trench
polar acorn
frosty hound
#

And also the actual MoveInput to see if it's actually a value. We don't know how that is being passed in, or when, or what other potential ways you might be modifying it before it's sent.

primal trench
polar acorn
primal trench
polar acorn
#

Hold forward and show what it prints then

primal trench
#

here are a few

tidal kiln
#

while in the air?

primal trench
#

the player just...isn't moving

tidal kiln
#

maybe something outside of this script is preventing from moving the player

#

is the character (in the air) moving slowly or not at all

polar acorn
#

I'm pretty sure SimpleMove works fine in the air, it just replaces the y value with gravity. Just as a sanity check, replace it with .Move. You will no longer fall but you can at least try to see if you can move while ungrounded

polar acorn
primal trench
#

no like, if i do move it does remove gravty but you can move when ungrounded

primal trench
marsh mountain
#

Do you have ground check?

#

or ground layer?

primal trench
marsh mountain
#

I can't get unity ThirdPersonFollow component on cinemachine to work straight over the shoulder.

polar acorn
primal trench
#

yes

polar acorn
#

Then I guess you'll need to handle gravity manually and use .Move

primal trench
polar acorn
#

Keep track of your vertical speed separately, use that for the y value of your movement vector you pass to .Move. Subtract some gravity value from it every frame, and when you're grounded reset it to some small downward force like -0.1 so you can remain in contact with the ground

rocky canyon
# primal trench how would I do that?
        // Vertical movement (Y)
        float vertical = currentVelocity.y;

        if (controller.isGrounded && vertical < 0f)
            vertical = groundedGravity; // Stick to ground
        else
            vertical += gravity * Time.deltaTime; // Apply gravity

        // Combine horizontal + vertical and move
        currentVelocity = new Vector3(horizontal.x, vertical, horizontal.z);
        controller.Move(currentVelocity * Time.deltaTime);```

yup, you just take the movement u already have and tack on a gravity value before sending it to `Move`
something like this works to keep u pretty grounded
primal trench
simple prism
#

If I define a vertex shader that defines some input parameters that a mesh doesn't provide (like taking TEXCOORD1 but the mesh only having 1 uv channel), what happens if I use that shader to render the mesh?

trim quarry
#

what a sigma

polar acorn
trim quarry
rich adder
#

use words

trim quarry
#

so after building the project, suddenly its size got more than 100 mbs, ive looked to build logs and saw this

#

it just added 100 mbs from no where

#

i dont remember the engine itself weight like that

#

is it depending on build profiles?

inland flame
#

Should I use visual scripting or learn c#

rich adder
inland flame
#

I have experiences in visual but it's easier than unity but harder than scratch

inland flame
rich adder
trim quarry
inland flame
#

I tried roll a ball thing but

#

Got stuck in coding

trim quarry
#

theres tons of ways to learn

inland flame
#

And I don't want to use godot because I hate the node system

polar acorn
trim quarry
rich adder
trim quarry
#

the first build had 40 mbs weight

inland flame
# rich adder both

Where exactly can I find one that actually teaches me something, not just type and here is your script

neon forum
#

Can someone remind me what the order of awake, initialize, and start is? And isn't there a 4th thing?

trim quarry
#

but it got more than 100 mbs later

inland flame
#

Thanks

rich adder
# inland flame Okay

take it slowly , most of the concepts are the same no matter what you do VS or C#.
variables, methods etc.

inland flame
#

I know basics like variabled

rich adder
#

when you get more comfortable then you look into more specific unity API functions and concepts

inland flame
#

Because I have experience

#

I made a 2d game where you killed terrorists

rich adder
#

good so that can only benefit you further knowing these

inland flame
inland flame
#

If terrorist touches you-> -1 from "health" variable

trim quarry
rich adder
inland flame
#

I'll save that

rich adder
#

which causes less mess tbh

#

if you want to learn the components unity has you can play with their VS as well , while you learn the c# too.

inland flame
#

Thank you 🖤 🖤 🖤 UnityChanThumbsUp

naive pawn
neon forum
#

RandomUnityInvader answer it all good

neon forum
#

just needed to find something post init

inland flame
#

Is that a feature?

zenith cypress
rich adder
naive pawn
simple prism
rich adder
#

You can consider "Awake" their initializer for MB but otherwise you have none @neon forum

inland flame
#

The programming level I am currently at is print hello world

naive pawn
inland flame
#

Which is python

naive pawn
#

@inland flame perhaps give this a read

(in general) there's 3 major parts to programming:

  • Language - The syntax, structure, and paradigm of each language
  • Library - The interfaces and utilities that each environment or toolset provides
  • Logic - The algorithms to do work at runtime

Logic is almost completely transferrable between each language and environment, you just have to learn the specific Language and Library that you're using
Language is also shared quite a bit between languages

of course, learning 1 part at a time is easier than learning everything at once, which is why tools like scratch or code.org are popular as coding courses for beginners, especially kids, because it only focuses on the Logic aspect

simple prism
#

Then you really should learn C# first. Don't worry about anything Unity-specific. You feel that way because Unity tutorials probably assume that you already know how to program

inland flame
#

So there was a scene system, scenes were parts of game (like menu, shop menu, game itself , death menu etc) now I take a look at unity godot etc they use scenes for objects too

#

I don't exactly get that, everything is different

#

which is hard for me

simple prism
#

Did you use visual scripting then?

inland flame
#

Yes

rich adder
inland flame
simple prism
#

Then you are basically trying to learn unity and C# at the same time which can be overwhelming

tidal kiln
#

if you are actually planning to stay and keep learning unity game developement, you need to learn c#, it will take time, but if you just want to make something quick use visual scripting

inland flame
rocky canyon
#

SceneManagement and the BuildIndex (where u add all ur scenes for ur game to build) would be the "Scene System"

inland flame
#

If I use visual scripting

#

It will be boring after some time and I will regret because I don't learn c#

tidal kiln
#

visual scripting is usually good for small scale projects

simple prism
#

VS will be a complete mess and harder to understand than code after a while

rich adder
#

it just gets real messy once you start doing anything complicated that usually only takes 50ish lines

inland flame
tidal kiln
#

anything bigger and more complex, you will start seeing weaknesses, and the nodes will get a lot more complex very quickly

tidal kiln
inland flame
#

Unity was easier than godot for me

thorn kiln
#

So, I dunno if my idea is correct. I wanna have so if my player collides with the weak spot, it destroys the enemy. I'm just kinda piercing together other bits of code that are similar though, so I dunno exactly how to accomplish it.

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Weak Point"))
        {
            Destroy(Enemy.gameObject);
        }
    }```
rich adder
tidal kiln
#

You are comparing a tag to a name

rich adder
#

also yeah actually Tag != Gameobject names

inland flame
#

So should I use unity or not

rich adder
tidal kiln
#

but unity is good too

inland flame
#

Godot was bad for me because of node system

#

I want to add a city map, the nodes make it impossible for me to edit normally

#

Too complicated

tidal kiln
#

Don't go with unreal engine as a beginner by the way, unity would be good

rich adder
tidal kiln
#

Godot is also a good choice but again, every game engine has strengths and weaknesses

inland flame
#

Also my laptop has i3

#

I'm scared that after some time it will start to lag and crash

tidal kiln
#

so you can't even run GTA V 😅

inland flame
#

not even 4

#

wait

#

Yeah

#

I finished 4 in i3 it was fine but not 5 ;P

#

It was 10 fps

tidal kiln
#

how in the world did you complete GTA IV with just 10 fps

inland flame
#

30

#

With fps drops

tidal kiln
#

oh ok

inland flame
# tidal kiln oh ok

The best game I could do was a dark themed game where you had to pick up crystals, I couldn't code picking up system and I stole the movement systemUnityChanThumbsUp

#

But you had a flashlight

#

Which was a child of player

#

big achievement

thorn kiln
rich adder
glossy vigil
#

guys so i bught something like a template game, that the guy is able to run in like web version and he sent me a folder with scripts. how can i put these in a new empty project and make it run

naive pawn
#

did you read the file that is named READ ME

thorn kiln
rich adder
glossy vigil
#

just some bs

#

i assume he only sent me the code

#

and not

#

the sprites right

#

like not the full game just the coding behind

frosty hound
#

How would we know, you're the one with the files. If there are only scripts in that folder labelled Scripts, then you would probably be assuming correctly.

thorn kiln
rich adder
rocky canyon
#

b/c other is a collider.. collider doesn't have a .parent variable..
it's Transform does however

thorn kiln
#

Hmmmm, okay

#

That's gonna be hard to remember for me

gloomy bison
rocky canyon
#

the point that u assumed its gona be hard to remember is a better reason to jot it down

rich adder
#

yes taking notes is also good.. also you need to use it often to remembe rit

thorn kiln
#

Repetition is the mother of learning

rocky canyon
#

ur just grabbing the main Transform of the gameobject in order to access parent, child, etc, everything #💻┃code-beginner message thats on the doc page

thorn kiln
#

So what was the thing nav said about in an ideal situation you could make the reference to enemy directly on a component placed on weakpoint trigger ?

rich adder
#

So basically you would put a component that has a reference to the Enemy
then you can access it as a field / property

#

in case your trigger is buried down the heirarchy and doing transform.parent might not always yield the wanted transform

#

so it would look like if(other.TryGetComponent(out EnemyHurtTrigger trigger)){ Destroy(trigger.Enemy.gameObject)
EnemyHurtTrigger would just have
public Enemy Enemy // assigned in inspector

rocky canyon
#

^ yea.. the component u end up grabbin from the trigger/collision
would also have a reference to it's specific Enemy

polar acorn
thorn kiln
#

Hmm, I understand bits and pieces of what's being said

rich adder
thorn kiln
#

So, make a script, put it on WeakPoint
Write something like public GameObject enemyPrefab; at the start of the script
Drag the enemy prefab into it in the inspector
Is that right so far?

naive pawn
#

not the prefab, no

#

you want to know about the specific enemy, not the prefab it's from

thorn kiln
#

What do I drag into the inspector then?

rich adder
thorn kiln
#

Well my enemies are prefabs though?

rich adder
#

yes so you would make this in the prefab so it works for all enemies spawned from it

thorn kiln
#

Ah, I think I understand

rich adder
#

its just a quicker/safer way to reach the parent, or any objects you want
traversing through transform can be "weak" if the hierarchy changes you're shit outta luck.

polar acorn
thorn kiln
#

Double click the prefab to bring it up in the "blueprint looking room" and then drag the enemy parent from that heirarchy into the inspector

naive pawn
#

the prefab is basically a blueprint for the enemy

#

you can't use it directly

#

you Instantiate it to create an actual enemy from the blueprint, called an instance (hence the function name)

thorn kiln
#

Yes, that

grim wave
#

Hi, I'm trying to program a basic movement system into my game using the new input system, but I'm currently stuck with trying to figure out the code for sprinting and crouching. I plan to do a class callback in the Update function, but I have yet to figure out the actual code to put in the if function. Does anyone have any suggestions?

grim wave
#

oh, I want the sprint to just go forward

rich adder
#

so you could use transform.forward for example

#

but if you want a sprint like thing, I would maybe use a Coroutine and call it while thats goin on

thorn kiln
#

So what's this bit about?
if(other.TryGetComponent(out EnemyHurtTrigger trigger)){Destroy(trigger.Enemy.gameObject)
I assume that's going in the script attatched to the weak point. Is that gonna be using an ontriggerenter?

grim wave
#

oh yea that's true

#

I have to brush up on coroutines though, its been a hot minute since I've touched that

naive pawn
#

it checks if the other object has an EnemyHurtTrigger, and if it does, to get its .Enemy.gameObject and destroy it

rich adder
#

oh wait misread that

naive pawn
#

it's your code lmao

rich adder
rich adder
thorn kiln
#

If you put it on player, what would be the point of putting a script on weakpoint just to reference it's parent (enemy)?

rich adder
thorn kiln
#

Hmm, back to being confused

rich adder
naive pawn
#

like, that's not how it's defined

primal trench
#

how would i push a character controlleer to the ground?

polar acorn
#

So, you've now made a more robust system that can work for more than just "Destroy this object's parent"

naive pawn
# naive pawn like, that's not how it's defined

now it's just, the enemy that the weakpoint belongs to
could be the direct parent, could be something else

point is, it's managed by a serialized reference now, so it's more flexible
the player doesn't have to assume that it'll be the direct parent
@thorn kiln

thorn kiln
#

A few.
I'm confused about what code to put in what script and how to reference things in each

rich adder
#

If you have a script on WeakPoint you don't need to do .CompareTag anymore. The component already tells you what it is, and you can use that to do something with

thorn kiln
#

I was about to say "So I'm not putting any actual code in the EnemyHurt script that's attatched to WeakPoint at all?", but then Chris said the code would be easier to do on WeakPoint?

devout socket
thorn kiln
#

Okay, this is the end result of juryrigging everything people here said to me, and it works, though I can't say I fully understand it.

    private void OnTriggerEnter(Collider other)
    {
        if (other.TryGetComponent(out EnemyHurt trigger))
        {
            Debug.Log("Collided with weak point");
            Destroy(trigger.enemyPrefab.gameObject);
        }
    }```
rich adder
#

prefabs dont exist at runtime, they become regular gameobjects

thorn kiln
#

Just what the tutorials always ask me to write

rich adder
#

prefab in the name implies something you will spawn as a copy

#

its already an instance, just call it enemy or whatever

thorn kiln
#

Well, reguardless, I'm trying to understand the if statement

rich adder
#

if it does, stores the result as trigger

thorn kiln
#

So "other" I assume just means any other object besides the one the script is on
TryGetComponent is telling it to look for a component of the object it collided with?
It's looking for the script "EnemyHurt"?
I don't know what out is or what trigger means in this context

naive pawn
#

it's just the name

#

Type name is a declaration

rich adder
wintry quarry
thorn kiln
#

Okay, I kinda get that then. In the JS course I did the tutorials would always have you give stuff a filler parameter too, like "x"

wintry quarry
#

not sure what you mean by "filler parameter"

#

it's a parameter, with a name.

thorn kiln
#

Just that it's a thing that needs a parameter so any name is fine

rich adder
#

[Type] [name]

wintry quarry
#

Well typically you want to give your parameter a descriptive and meaningful name, but yes according to the compiler the name can be anything

rich adder
#

the name can be anything ya
just a name. You can literally call it asjhdjaskh and it will still work..

#

just who would remember that lol. you wanna be descriptive

thorn kiln
#

Well it's more an observation that it doesn't even make you type it, it just auto-completes to other

rich adder
#

thats the way unity setup the Code Snippets

tacit prism
#

using the sprint toggle i made causes my player to teleport, rather than increasing his movement speed
i set it to

{
    playerMoveSpd = playerRunSpd;
}
else
{ 
    playerMoveSpd = playerWalkSpd;
}
thorn kiln
#

Anyway, why is it out EnemyHurt trigger instead of something like how GetComponent works just typing "EnemyHurt"? What does out and trigger do here?

tacit prism
#

it worked when i did my 3d project but not when applied here

rich adder
# thorn kiln Anyway, why is it `out EnemyHurt trigger` instead of something like how GetCompo...

the same concepts here, except the result is coming from out because the function TryGetComponent already returns a value bool so you can't have 2 return values
trigger is just a name of the EnemyHurt found, stored in that name / variable (same thing, name can be anything here)
the bool is because TryGet returns true if it found the component you want, otherwise it just skips the if block

naive pawn
tacit prism
naive pawn
#

the code

rich adder
tacit prism
# naive pawn the code

i put the code in the video but alright

using UnityEngine;
public class PlayerWalk : MonoBehaviour
{

    private Rigidbody2D rb;
    public float playerMoveSpd;
    public float playerWalkSpd = 2;
    public float playerRunSpd = 4;
    private float moveHorizontal;



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

    void Update()
    {
        moveHorizontal = Input.GetAxisRaw("Horizontal");

        if (Input.GetKeyDown(KeyCode.LeftShift))
        {
            playerMoveSpd = playerRunSpd;
        }
        else
        {
            playerMoveSpd = playerWalkSpd;
        }

    }

    void FixedUpdate()
    {
        MovePlayer();
    }


    void MovePlayer()
    {
        Vector2 movement = (transform.right * moveHorizontal).normalized;
        Vector2 targetVelocity = movement * playerMoveSpd;

        Vector2 velocity = rb.linearVelocity;
        velocity.x = targetVelocity.x;
        rb.linearVelocity = velocity;

    }
}

naive pawn
#

i put the code in the video but alright
yeah that's not an adequate way to share code

tacit prism
#

idk what jetbrains is, i closed the project, and when i reopened it was there, im lowkey confused

naive pawn
#

it's the company that makes a lot of ides like rider, intellij, webstorm, clion

#

not sure why it's there tho

tacit prism
#

¯_(ツ)_/¯

rich adder
#

ide (Code Editor) probably thought you were trying to use a class from it

#

it does that sometimes

tacit prism
#

silly VS, whimsy little guy

naive pawn
#

perhaps try setting interpolation

tacit prism
#

i know what an ide is 😭

rich adder
#

just being explicit, some dont 😛 it is code beginner after all

#

You might want to give this some easing / interpolation if you want a smooth sprint

tacit prism
#

true lmao, im learning c# from the microsoft thingy, but also trying to apply stuff i learn along the way

tacit prism
rich adder
rich adder
tacit prism
#

i really dont know if i efficiently set up the movement, as im basing this off of a piece of code for 3d movement i studied

rich adder
tacit prism
thorn kiln
thorn kiln
#

I find documentation so hard to read

slender nymph
#

probably should make an effort to get used to it considering reading docs is like 90% of programming

thorn kiln
#

It becomes kind of an endless dive because every page uses other words that I also don't know

rich adder
#

the microsoft one is surprisingly good

thorn kiln
#

Or just lays it all out in a very technical way so it read like jargon

rich adder
frail hawk
#

sounds ok