#💻┃code-beginner

1 messages · Page 678 of 1

muted sapphire
#

the only language ive seen doing that is python

stuck field
#

This is right, but it bugs people

muted sapphire
#

I'd have manually put it down the exact same way the code did

stuck field
#

Usually it should do 4 spaces (which is one tab)

#

Looks to be doing 3 up there

onyx geyser
#

update, i got to work after a bit of searching

muted sapphire
#

ohh thats what you mean

#

that seems like a configuration issue

stuck field
#

Yeah, it's likely

onyx geyser
#

so it turns, i just needed to do a normalized.
rb.Velocity = rb.Velocity.normalized

#

sorta way

#

if i understand it right, by saying normalized, it's taking the original vector's "speed" and constantly reverting the speed of the new Vector2 back to that specific speed

#

if anyone can clue me in on if that interpretation is correct

stuck field
#

Normalization scales the vector to a magnitude of 1

muted sapphire
#

I have no idea how that fancy stuff works

stuck field
#

I don't think it'd be the right thing to use

#

(Also reduces it to 1 if above)

muted sapphire
#

I feel like youve got bigger fish to fry

onyx geyser
#

well it certaintly worked on stopping the ball from growing in speed, and it's such a short line, why would it be the wrong thing to use

muted sapphire
#

shouldnt you try to fix the issue of it getting faster

#

instead of countering it

onyx geyser
#

well i tried finding the issue online, and, didn't really understand anything, i figured this is constantly reverting the speed back to what flyspeed is meant to be, as i can change flyspeed and it affects the zubat- i mean ball.

muted sapphire
#

It works

#

but it's not pretty

onyx geyser
#

oh?

#

if(rb.velocity.magnitude > Flyspeed)
{
rb.velocity = rb.velocity.normalized * Flyspeed;
}

#

wym

stuck field
#

Why not just clamp the velocity?

onyx geyser
#

idk how clamp works

#

i can give it a try

#

what's the difference between normalized magnitude and clamp?

stuck field
#

It takes a min and a max value and makes sure the inputted value isn't below min, or above max

#

Normalized sets the magnitude to 1

#

Clamp makes a value go between a specified min and max value

#

It's more pretty and less code than what you're currently doing at the very least

onyx geyser
#

really?

#

less code that 5 lines?

stuck field
#

Yeah, you won't need an if statement

#

It's just to set a max value, let's say your max was Flyspeed, you would clamp the velocity to a min of 0 (or -flyspeed), and max of flyspeed

#

That way velocity will always be at min what you specify, and max what you specify

#

You can see how it works here

onyx geyser
#

no overload for method clamp

stuck field
#

Mathf.Clamp, it's not Vector.Clamp

onyx geyser
#

yeah, i'm using mathf.Clamp

stuck field
#

Can you show me?

onyx geyser
#

rb.velocity = Mathf.Clamp(-Flyspeed, Flyspeed);

stuck field
#

You need to put the actual value you're trying to clamp in

#

(val, min, max)

onyx geyser
#

oh ?

stuck field
#

It's a little messy as you'll need to use the individual floats actually, but it can be one line

#

It'll work better though

onyx geyser
#

individual floats?

stuck field
#

Vector3.x

#

Y and z too

onyx geyser
#

ohh

#

like xvelocity and yvelocity

stuck field
#

Yeah

#

Pretty much creating a new vector3 with the clamped values

onyx geyser
#

so would be.. like mathf.clamp(vector2) kinda deal

#

i'm a little confused, never used clamp before

stuck field
#

The documentation will show you how to use it better if you want to go check it out quickly

stuck field
eternal needle
stuck field
#

I'm not too sure that's what is being looked for

#

It works on the positive end, but not the negative

eternal needle
#

Or vector2 if thats what they're looking for. Didn't see the full context above

stuck field
#

It's Vector3 I believe, but they are trying to clamp between -speed and speed, clamp magnitude would only allow speed, not both I believe

#

Correct me if I'm wrong though

onyx geyser
#

Vector2, i'm trying to stop a ball from gaining too much speed

eternal needle
onyx geyser
#

seems the tutorial i used wasn't very decent

eternal needle
stuck field
#

I'm aware

#

Kind of makes sense

#

I just was thinking magnitude didn't work that way, so my apologies

#

But yeah, then that should work too

onyx geyser
#

so if i make a few more floats for maximum and minimum, it'll make the clamp usable?

stuck field
#

You should use what bawsi said, more compact and cleaner

eternal needle
#

Look at the docs for Vector2 or Vector3.ClampMagnitude. I linked the vector3 doc above. They show you exactly how to use it

onyx geyser
#

well it's come up, so i'm curious as to how i would apply this to my code

stuck field
#

But I highly recommend using ClampMagnitude for this now that it's been brought up, it's a better solution

onyx geyser
#

oh wow, i read through it a little bit

#

it worked

#

huh

eternal needle
onyx geyser
#

one line, easier to understand

#

i'm still pretty proud of that if statement, but i'm glad you showed me this

#

so if i have it right.
rb.velocity = vector2.ClampMagnitude(rb.velocity, Flyspeed);
it's saying that rb.Velocity, aka the ball is being clamped directly by what it's set to? which would be Flyspeed?

#

did i get that right?

stuck field
#

Yup, it would clamp the magnitude of the vector to fly speed

sour fulcrum
onyx geyser
#

that's true, and the more i screw around even with something as simple as this, the more i'm starting to get it

#

a few days ago i didn't get any of what i typed

#

i still don't get a few things but i understand this now

#

how difficult would it be to set the corners of my paddles to send the ball down by .5 degrees?

#

i'd probably need a seperate box for them right?

stuck field
#

Not sure what you mean

muted sapphire
#

I literally started the editor with two cubes and one script in it and got SEVEN errors to my face

onyx geyser
#

well, in pong, when the ball hit's a corner, it sends it off in the direction of whichever corner it's on, but it might be easier to make it so the ball randomizes which direction it slings to upon making contact

eternal needle
onyx geyser
#

oh ?

#

that sounds a bit more complex on it's own

#

might be worth a try

eternal needle
#

Its a very basic formula at most

muted sapphire
#

oh my god theres an unity debugger for visual studio code

#

I've been freestyling my code

eternal needle
#

A math formula solves this right away

onyx geyser
#

Eh, roughly, I just don't want it to stay directly in the middle

muted sapphire
onyx geyser
#

It'd be nice to be able to have 3 points, a bottom, middle, and top.
If it hits the bottom, it goes down, if middle, it goes straight, if top, goes top

#

Side note, I've been using pokemon sprites and they've been knocking around a zubat

muted sapphire
#

for now I'd just give the ball like 0.5x the velocity of the paddle or something

#

when hitting it

#

meaning when moving up it gets speed upward

#

when down it gets it downward

#

it's what i wouldve settled on without mathing it through

onyx geyser
#

well that's no fun, maybe it's worth a try making seperate points of contact

eternal needle
#

Multiple colliders for something as simple as a pong paddle is questionable. If youre using this as a learning project, consider learning the simple math here

onyx geyser
#

that might be a good idea

muted sapphire
#

How do i get a single value from a vector?

#

(Vector2, in this case)

naive pawn
#

@muted sapphire sounds like you're thinking of wasd as 4 separate buttons? but you haven't set up your inputs like that
the composite control means wasd are being treated as separate sides of a single joystick, so there's no relevant bool to speak of

onyx geyser
#

i'm thinking what i could do is make an if statement that goes something like
if(collision=true)
{
randomize ball direction
}

#

but then it may also be a good idea to do the math, i just have no clue how i'd approach that topic

naive pawn
muted sapphire
#

im just restructuring my movement system right now trying to figure it out

eternal needle
onyx geyser
#

i figured as much, just didn't know.
i can probably go back to my flappy bird script and take a better look at how it reacts to collision and make a choice from there

muted sapphire
#

okay, so in simple words, how will i do something once one of these actions happen?

#

or should i be using axes for this

eternal needle
#

Have you looked at any tutorials for the new input system? There are a couple different ways to get notified of input in a script, or read the values directly

muted sapphire
#

And so far I'm working off of a (i think) 6 year old handbook

eternal needle
#

I mentioned where some resources are up here

muted sapphire
#

Yeah the main input system guide is structured so weirdly though

#

I have to search for the most simple things because they're buried somewhere

#

Alright got it to work although not beautifully

eternal needle
muted sapphire
#

What I meant was

#

The first proper explanatory tab in the resource starts with working out moving with two dimensional axes

#

THEN the first single press action is called

onyx geyser
#

trying to wrap my brain around how i'd just go about changing the angle upon hitting a collision

muted sapphire
#

...how did i even do this

onyx geyser
#

i don't think i'm deep enough in to do math right now, BUT, i can do something else

lusty star
#

i mean i didnt even check lol lemme check

#

yeah cant find it

onyx geyser
#

well, turning the box collider into capsul colliders seemed to work pretty damn good

stuck field
onyx geyser
#

but i run into another issue, some time after, it just gets stuck between both walls, bouncing continously

#

which, to be honest, might solve the problem i had with the box colliders

lusty star
naive pawn
#

it does, it just has different restrictions
python doesn't require semis, c# does
c# doesn't care about whitespace, python does

#

make sure you've configured c# to 4 spaces i suppose

muted sapphire
#

I loved breaking coding conventions just to confuse someone that saw my code

naive pawn
stuck field
naive pawn
muted sapphire
#

Maybe my original statement was weirdly formatted

#

but the only language i know that watches graphical syntax is python

naive pawn
#

you can do one liners in most languages, except a few features like if/else in python, nested control in python, preprocessor statements in c/c++

naive pawn
muted sapphire
#

depends on definition

naive pawn
#

you're thinking of whitespace significance

muted sapphire
#

one could argue syntax is things like ; or ()

#

which isnt graphical

naive pawn
muted sapphire
#

no??? its data

#

bytes

naive pawn
muted sapphire
#

yeah

naive pawn
muted sapphire
#

mostly yeah

naive pawn
#

im not sure what point you're trying to make here

muted sapphire
#

sigh

naive pawn
#

there are quite specific terms for these

#

"depends on definition" doesn't really work when the thing you're talking about has a single accepted definition

muted sapphire
#

usually in our circles we call both ();<> and so onward and whitespaces syntax

#

one because it is language syntax

#

the other is grammatical syntax so it goes better on our eyes

#

which is also language syntax in python

#

Thanks to python this established

#

It's really not so off one should have trouble understanding

onyx geyser
#

i have learned of reflect, i feel like this might be usable for this scenario

#

as the ball tends to get stuck between the two walls

naive pawn
#

what defines "language syntax" vs "grammatical syntax" to you
never heard of this distinction before

muted sapphire
#

take c

#

you have things like semicolons

#

or brackets

#

thats NECESSARY for the code to read what you write

lusty star
muted sapphire
#

you NEED to do that

muted sapphire
#

but theres other options, usually conventions, which is what you called whitespace significance and a couple tiny other things

#

in python thats significant too

naive pawn
#

indenting is styling/formatting, not syntax in c

#

syntax is specifically the things that matter to the language

muted sapphire
naive pawn
#

i have no idea what you're trying to say in those messages other than "whitespace is a part of syntax"

muted sapphire
#

Come on, I see your point but it REALLY isn't that hard to understand???

#

I'm not saying whitespace is a part of syntax

naive pawn
#

hell, c uses whitespace in its syntax, preprocessor statements have to end on a newline

muted sapphire
#

I asked if c used whitespace, which i referred to as syntax, meaning graphical syntax which is what we call whitespacing

naive pawn
#

i don't know what your stance is

stuck field
#

Looks like this

naive pawn
muted sapphire
#

yes

#

again, coming from python

naive pawn
#

they're still separate things in python

muted sapphire
#

not relaly

#

you get syntax errors for formatting something wrong

naive pawn
#

i know how python works lol

muted sapphire
#

I'm not explaining to you how python works

#

im telling you that if there is an error in the formatting and that error is a syntax error, then the formatting is a part of the syntax

naive pawn
#

formatting and syntax overlap here but they're not the same
formatting also defines how much to indent by, and makes it consistent, etc
the syntax says you can also just not have a newline and indent at all

muted sapphire
#

theres still a bit of whitespacing in python, but formatting is now a part of the synta

naive pawn
#

they occupy the same space, sure, but they are not one and the same

muted sapphire
#

its just like it always is, you have free space to choose how much whitespace you want to have

#

i think this is an opinional debate, theres not really right or wrong here

#

lets just agree to disagree

naive pawn
#

whitespace is involved in syntax
whitespace is involved in formatting
formatting isn't involved in syntax

naive pawn
#

but sure, you're free to ignore the established terms if you so choose

muted sapphire
#

it is also quite agreed upon pythons syntax contains formatting

lusty star
muted sapphire
#

you cant argue with whats quite established because so is this
most people ive met would disagree with you
conventions are relative compared to the people you convene with

stuck field
onyx geyser
#

would anyone happen to know how to change the angle at which a ball bounces off a collider, so that when it's bouncing between walls it doesn't normalize between them and get stuck?

#

tried using reflect, that didn't work, since it just reflects the way it came

naive pawn
muted sapphire
#

it is a convention

#

one can find a source to any convention if they so like

sour fulcrum
muted sapphire
#

its all a question of the people you convene with, like i said

lusty star
naive pawn
#

formatting is about the non-functional parts
syntax is about the functional parts
mixing them just causes issues with communication and managing tooling lol
ive never heard an actual take mixing formatting and syntax lol

lusty star
#

like exectly what you showed but instead of tab it says space

onyx geyser
#

doesn't work, maybe because i'm doing something wrong

sour fulcrum
naive pawn
muted sapphire
#

maybe the people and forums you surround yourself with say formatting and syntax are not related to one another because formatting is purely for the human to read
the people and forums I surround myself with say that formatting is all whitespace (so newlines, tabs, spaces, et cetera), which is usually only for the human to read, but python needs it, which is why that bleeds over

muted sapphire
#

I'm not pulling this out of thin air, this has been deep core anchored with most people I've met in forums or on discords

sour fulcrum
muted sapphire
#

code beginner unity

#

not code beginner c

naive pawn
#

i feel like that's just a misunderstanding on your part

muted sapphire
#

no

#

i literally just said it

sour fulcrum
muted sapphire
#

most people i meet consider whitespacing and formatting one and the same thing

naive pawn
#

well that's just not right

#

formatting involves so much more

sour fulcrum
#

Maybe i'm ignorant but isn't all whitespacing formatting but not all formatting is whitespacing?

muted sapphire
#

which would still make formatting partially a part of syntax

sour fulcrum
#

in python i guess, not c#?

naive pawn
#

quotes type in languages where it's flexible
declaration type/style
implicit modifiers
inline/oneline statements
array style

onyx geyser
stuck field
# lusty star you can see it in the vid

I'm not sure then, the only other thing I can think of is the "detectIndentation" setting that may be getting 2 and not showing the spaces value, if not I'm not really sure and I recommend going directly to vscode support on this as that shouldn't really be happening if all settings are right, otherwise, you can try reinstalling vscode or installing visual studio instead and maybe that will work properly

naive pawn
muted sapphire
naive pawn
muted sapphire
#

a part of formatting is a part of syntax

naive pawn
muted sapphire
#

they are not seperate

sour fulcrum
sour fulcrum
naive pawn
#

ooh new take

onyx geyser
muted sapphire
naive pawn
onyx geyser
#

and when using inDirection = rb.velocity, i'm assuming that's where the ball came from?

#

so in order to 'change direction', i'd have to change something inNormal, but i have no idea how to go about changing that

#

all of in.normals code piece confuses me

sour fulcrum
# naive pawn ooh new take

in my brain rn

syntax: ""identifiers"" on how to correctly read the language
conventions: trending ways on composing aspects of the language
formatting: the usage of syntax and conventions to write the language

not saying this is right whatsoever just how my brain is doing it

muted sapphire
#

let me make my stance more clear

#

with this terrible venn diagram

naive pawn
sour fulcrum
muted sapphire
#

python

naive pawn
#

that's in the realm of syntax, not formatting

sour fulcrum
#

i disagree then, since whitespace composition is required syntax. you would format your code around this requirement

naive pawn
# muted sapphire

hmm wait my stance would be the same but i'd probably define what the overlap means differently LMAO

muted sapphire
#

I made that venn diagram in like two seconds okay

#

cut me some slack

lusty star
naive pawn
onyx geyser
#

(idk if it was obvious, i'm trying hard not to ask for a direct answer, but this seems like one of those more obscure things)

sour fulcrum
# onyx geyser private void OnCollisionEnter2D(Collision2D collision) { Vector2 inDirec...

so couple things

inDirection :the velocity of your rigidbody, easy
collision.contacts[0]: during a collision, there can be multiple "contact" points involved. eg if i slap you in the face there's gonna be one for my palm, fingers etc. this code just grabs the first one
.normal: every point on a collider has a normal value associated with it (as a Vector3). this normal is the direction this point is meant to face outwards. In this example if you hit a flat wall, said wall's normal is facing away from the wall (can you see why we would want this information)
Vector2.Reflect: as mentioned in the docs, takes in a incoming direction and a normal and will give you a reflected direction coming off that normal

muted sapphire
#

How do I make the Transform of my player object accessible to my cameras public Transform import?

onyx geyser
#

so i WAS mostly correct, that Normal is the line i need to be focusing on if i want to change the way the ball perceives it

naive pawn
burnt vapor
muted sapphire
sour fulcrum
onyx geyser
#

yes i can absolutely see why we would need to know that information, because now the goal is to tell the ball that the normal it is hitting is not normal, while it's still remaining normal, as if it's hitting a corner

muted sapphire
#

i do a "public Transform player;" at the beginning of my camera script and then refer to this transform to define the new camera position

burnt vapor
#

It is a code smell to reference the player on the camera, though. if you need a reference on where to look at, add a TransformProvider or share the transform another way that doesn't put in a hard requirement

#

For example, you can also make it a delegate

muted sapphire
#

but in the selection in the menu on the side, the player objects Transform isn't visible, most likely because it is private

onyx geyser
muted sapphire
naive pawn
#

ah no that's on the class you aren't supposed to assign stuff there

muted sapphire
#

I'll do the offset later lets leave that out of the thing

naive pawn
#

you need to assign stuff on an instance of the class, aka a component

muted sapphire
#

oh my god im blind

sour fulcrum
# onyx geyser yes i can absolutely see why we would need to know that information, because now...

Gonna nitpick your thought process a little bit for learning if you don't mind

because now the goal is to tell the ball that the normal it is hitting is not normal
No, because the collision has happened. OnCollisionEnter is a reactionary function telling you what has happened, not a heads up on what is about to happen

What we want to do here (and what that code is doing) is use the information we have about the collision that did happen in order to tell the ball to move in a different direction. We don't need to change it's natural direction if we just tell it a new one

muted sapphire
#

shouldve seen it

naive pawn
#

that's just inexperience, you'll get better with it over time

onyx geyser
naive pawn
#

nothing im not used to lol

onyx geyser
#

now that i get that, i still don't quite know how to use normal, i tried to make a float out of it and it told me the same thing you did, that it wasn't being used

sour fulcrum
#

you don't need to use the normal directly, you can use the result from reflect

onyx geyser
#

reflect is meant to use it i assume, judging by that last bit, but to change it is how I'm confused

sour fulcrum
#

well now we have the resulting value from reflect

#

and it's a vector3

onyx geyser
#

(or, vector2?)

sour fulcrum
#

and you've messed with a rigidbody's velocity before 😄

onyx geyser
#

of course

#

so now i have a new vector2 to use, which means i can do something like change it's direction to 5?

#

this stuff is confusing me beyond belief

naive pawn
sour fulcrum
#

i goofed my b on that

sour fulcrum
#

for starters i would break this down into steps and first try to use the reflect value you got with your rigidbody

#

see what it does 😄

naive pawn
#

gotta check on that sometime...

sour fulcrum
#

just 0-1's

#

direction

naive pawn
#

think i got a good idea though actually since i saw something last night

#

it's not an arbitrary plane/line, is it? it's the one that passes through the origin and is perpendicular to the normal vector

#

and then projecting or reflecting with that plane or line involve directions, not positions - ie, relative to origin

onyx geyser
#

gonna mess around for a moment, got a few ideas at the least..

naive pawn
#

i think i was stuck on imagining them as an arbitrary plane unrelated to the origin and i couldn't figure out how that'd be represented with just 3 dimensions lol

onyx geyser
#

one of them of course, classicly being turning it into a float and seeing what that did (spoiler, it didn't work)

sour fulcrum
#

so my understanding of normals (someone can correct me if im wrong) is that each point on the mesh/collideretc. has a Vector3 normal value facing outwards from that position relative to the mesh

then the normal associated with the face of the contact is calculated based on the 3 normals that make the triangle face, relative to their positions

muted sapphire
#

Why is the position of my floor so specific? The cube directly above it is perfectly even, but 0,0,0 seems to be somewhere completely different now

sour fulcrum
#

then reflect samples the incoming direction and normal in order to rotate(?)(smarter word for this) the direction

naive pawn
naive pawn
muted sapphire
#

again, i apologize for my stupidity, I nested two floor elements (to make the floor move) in a singluar bigger floor element which was created at visual position

#

meaning some really jank values

onyx geyser
#

well, it did something

#

so i'm wondering if i create a new float with a very specific number if i can fix this

sour fulcrum
#

sure

onyx geyser
#

though it doesn't seem to accept floats..

#

rb.velocity = Vector2.Reflect(rb.velocity, inNormal);

muted sapphire
#

i do hope you gave the zubat the collision of a circle

onyx geyser
#

this is what i came up with that caused whatever that was

#

it's progress

sour fulcrum
#

what does it accept

onyx geyser
sour fulcrum
#

thats not a real answer 😄

onyx geyser
#

a few times it began spinning at the beginning, it was funny

muted sapphire
#

aand it seems that that was too much unity for my pc and its dying now

#

i guess that means a forceful break

onyx geyser
#

well, it accepts rigidbody, and itself

muted sapphire
#

oh my god

sour fulcrum
#

mouse over rigidbody.velocity and show

muted sapphire
#

does unity temporarily save to drives?

onyx geyser
#

linear velocity of a rigid body?

naive pawn
#

why do you ask?

muted sapphire
#

because it complained about my disk being full despite it not actually being that when i checked after closing the program

naive pawn
#

did you put the project in a synced folder? ie onedrive

muted sapphire
naive pawn
#

can you show the error

muted sapphire
#

no it was only once

naive pawn
#

it's gone now?

muted sapphire
#

it said something about trying to save to a disk drive with 0.00GB of space

#

it closed right after

sour fulcrum
naive pawn
#

ah ghost errors

muted sapphire
#

am i haunted now

naive pawn
#

always have been

onyx geyser
muted sapphire
onyx geyser
#

it's own instance by chance?

sour fulcrum
naive pawn
sour fulcrum
#

Vector2 is a value type, like ints, strings, bools, floats etc.

#

its just a lil piece of datas

#

in this case two floats

muted sapphire
#

every copy of TestProject_2_Final is personalized

sour fulcrum
#

you can make vector2's whenever you feel like it

muted sapphire
#

value types are fun

onyx geyser
#

maybe public Vector2 vec = ?;

sour fulcrum
#

i hate to be this person but the answer to this is searching vector2 unity

#

gotta get into that habit

muted sapphire
#

why does unity even have a special value type for that

sour fulcrum
onyx geyser
#

wow

#

that's uh

#

a lot

sour fulcrum
muted sapphire
#

it seems unnecessary to do that rather than just two floats

sour fulcrum
#

a vector2 is two floats

muted sapphire
#

or a float[] which is probably just what that is

sour fulcrum
#

i don't think it's an array

muted sapphire
#

yeah but at this point why call it vector2

sour fulcrum
#

it's a vector

#

with 2 values

hexed terrace
#

you need to do things with vectors that would become tiresome to keep tying out two floats..

onyx geyser
#

guess i can mess with the different vector2's

muted sapphire
#

eh, maybe, i dont know the oddities of unity further onward

#

maybe it does have some perks that only come into play later

onyx geyser
#

well i now know what negative does.

sour fulcrum
# onyx geyser a lot

all your looking for is how to make new vector2's, all you gotta look for in there is that

sour fulcrum
muted sapphire
#

Yes

#

But not a good one

#

I can do the complete math behind a video game

#

And I can do the complete concepting

sour fulcrum
#

Handling concepts like positions, rotations, scale, directions etc. etc. without a easy Vector2 class would be nightmare-ish

onyx geyser
#

i'm half tempted to just mess with all of them, it's kind of entertaining

sour fulcrum
#

just wait till you find out Vector3 and Vector4 exist 😄

onyx geyser
#

oh god.

muted sapphire
#

yeah that was obvious

onyx geyser
#

i'm so far away from the project i WANT to be working on, this is evident

sour fulcrum
muted sapphire
#

when does vector4 come into play though

sour fulcrum
muted sapphire
#

ah

sour fulcrum
#

(RGBA)

muted sapphire
#

was confused on why you were time travelling with objects

hexed terrace
#

have mostly seen Vector4's in shaders

muted sapphire
#

I feel like after Vector4 you should really just take a break tbh, I've once ended up with a 5-dimensional array when making a picture editor in Java for school and it made me rethink my whole concept

sour fulcrum
#

The stuff about directions and collisions and vector2's etc. your learning rn is great to learn in isolation but what you want to build up in the long run is the ability to learn these things yourself, by identifying what exactly you want, what you know, what you don't know and then researching those things

onyx geyser
#

makes me wonder just how difficult it'd be to make a kings field like

#

because that's the first 'step' towards the project i want to make

muted sapphire
sour fulcrum
#

Unity's documentation is really good tbh

#

far, far from flawless but like all things considered

#

it's samples can be lacking at time admittedly

muted sapphire
#

90% of it tries to mouthfeed me the things with a 30 minute video to explain a certain single line

#

and the other 10% are professional manuals that only help if you already know your stuff

sour fulcrum
#

if your seeing videos your not in the documentation lol

muted sapphire
#

some docs pages had videos linked

#

but that was the weird corners

sour fulcrum
#

manual stuff might have some if applicable

#

api doesnt

muted sapphire
#

thank you

#

somehow nothing links to that page

sour fulcrum
#

This just isn't remotely true but I'm glad you know about it now 😄

muted sapphire
#

None of the pages I found did at least

#

all documentations linked to were either third party and sucked or a weird corner of that page

sour fulcrum
#

and then if you click that first link

hexed terrace
#

Or clicking the litle ? on components will take you directly to the docs page for that component.

If the pg doesn't exist when you click that, it's (probably) because it's not a Unity component

muted sapphire
#

only thing i found was people trash talking it

#

now i have it though so its fine

#

as long as its decent

hexed terrace
#

it's alright

simple hawk
#

``using System.Collections;
using UnityEngine;

public class shootTest : MonoBehaviour

{
public float fireRate = 1.0f;
private bool canShoot = true;
private bool destroyBul;
public float timer = 5.0f;

[SerializeField] private GameObject bulletPrefab;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{

}

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.Space) && canShoot)

    {
        Instantiate(bulletPrefab, transform.position, Quaternion.Euler(0, 0, 0));
        canShoot = false;
        StartCoroutine(shootDelay());
        StartCoroutine(Bul());
    }
    IEnumerator shootDelay()
    {
        yield return new WaitForSeconds(fireRate);
        canShoot = true;
    }
    IEnumerator Bul()
    {
        yield return new WaitForSeconds(timer);
        destroyBul = true;
    }
    if (destroyBul == true)
    {
        Destroy.gulletPrefab);
    }
}

}``

sour fulcrum
#

there is a mistake in this code that would make it fail to compile

simple hawk
#

I'm using this code to fire a bullet from a gun, I added somw extra bits at the bottom to destroy the bullet after some time to make suure they don't stay for too long, but I'm not sure the Destroy part is correct

muted sapphire
#

that doesnt seem right

#

isnt that missing a (

simple hawk
#

ur right, now it's saying this

muted sapphire
#

i think its telling you that you cant do Destroy.something

#

you have to do something.Destroy

sour fulcrum
#

google "Unity Destroy Function"

onyx geyser
#

rahgg

muted sapphire
#

just a wild guess

onyx geyser
#

rb.velocity = new Angle(inNormal * 90);

#

i wanna say something like this might be close

eager spindle
#

GameObject.Destroy is a static method taking in a GameObject.

You can do Destroy(gameObject).

sour fulcrum
#

what is rb.velocity

leaden pasture
#

I also can't see any references to gulletPrefab so presumably that's meant to be bulletPrefab?

So you'd need to do Destroy(bulletPrefab)

muted sapphire
simple hawk
#

yea, that helped, thnx guys

eager spindle
#

Yes

muted sapphire
#

the arch nemesis of any coder

#

spelling

onyx geyser
#

i may have to sleep on it

leaden pasture
muted sapphire
onyx geyser
#

that seems right

sour fulcrum
#

if you give birth your not creating a timmy, your creating a baby named timmy.

Making something requires the Type

eg. new Vector2(newXValue,newYValue)

eager spindle
#

rb.velocity is the velocity of the rigidbody. It's represented by a Vector3.

If a rb's velocity is (1,0) it moves along the x axis at 1 unit per second.

A velocity has nothing to do with an angle

naive pawn
#

if you don't have a solid idea of what you want, write out what you do know instead of putting in random guesses like that

sour fulcrum
sour fulcrum
simple hawk
sour fulcrum
#

that's what velocity is

eager spindle
#

you can't assign an angle to a velocity

muted sapphire
#

its just speed

leaden pasture
sour fulcrum
naive pawn
muted sapphire
#

velocity having a direction feels very very wrong

naive pawn
leaden pasture
#

I mean. All vectors have direction. That's what a vector is. Magnitude & direction

sour fulcrum
muted sapphire
#

oh s**t velocity is vectoral

naive pawn
#

speed is always positive
1d velocity can be negative - speed is the magnitude of velocity

muted sapphire
#

my bad my teacher just lied to me like two weeks ago

eager spindle
#

It's kinda weird because people say the speed of an object is x m/s, but don't specify the direction

#

So people think speed is a single number

naive pawn
#

it is though

eager spindle
#

People confuse it with velocity

muted sapphire
#

speed is non directional

onyx geyser
#

so what am i doing

muted sapphire
#

velocity is directional appearantly

naive pawn
#

speed is just |v|

sour fulcrum
muted sapphire
#

yeah i know

#

i looked it up

#

i was just taught differently for some reason

#

but velocity being directional makes sense

naive pawn
onyx geyser
naive pawn
#

5 degrees from what?

#

the normal or the surface?

#

or the incoming angle?

onyx geyser
#

the normal presumably, that's what's this has been all about

naive pawn
#

gotta get precise with your goals before you can break them down

onyx geyser
#

if i knew every term under the sun then yes i would probably break them down, but that's why i'm in here, to learn how to break them down.

naive pawn
teal viper
#

We can't help you with something you're not sure about yourself.
Why do you need it to bounce at such a specific angle?

sour fulcrum
#

(feel like this might be a "see you at 3" vs "see you in 3 hours" typa situation)

onyx geyser
#

the image on the left is what i want to happen, the red being what i don't want to happen.
the image on the right is an accurate representation of what IS happening.

naive pawn
#

so what's the 5 degrees thing here?

onyx geyser
muted sapphire
#

I was about to ask too

#

the red line you drew in the left image are 5 degrees off 90°

#

the blue line doesnt really match up with anything

sour fulcrum
#

they want the rb to not get stuck in an infinite bounce cycle i believe

naive pawn
#

i thought you already had reflection off the normal thinkies

sour fulcrum
#

they have it but don't know how to use it

onyx geyser
#

just pretend that it's 5 degrees, i never intended for it to be so specific, just that i need the angle to change so it doesn't get stuck.

#

i'd even take a slight change over what's happening now

naive pawn
#

you have a Vector2 representing a direction (velocity), you pass it through reflect, you get a new direction that you can assign back to the velocity, no?

sour fulcrum
onyx geyser
#

an additional

naive pawn
sour fulcrum
#

your previous messages say the opposite. not pointing out as a gotcha but as an example of why you gotta be clear

#

as they are different things

naive pawn
onyx geyser
#

gods sakes give me a moment to collect my remaining cells

#

the coffee is thinning out and it's 4:30 am

#

when it hits the wall, i want to add a value to it's direction, so that it shifts slightly enough every time it hits that it will NEVER get stuck, that and it should theoretically add a bit more unpredictability to the ball itself.
so if it hits the wall at a 90 degree angle, it'll leave at 95 OR 85.

#

instead of going up and down

#

like it has been

#

is this clear enough

sour fulcrum
#

yeah that's a lot more explicit

onyx geyser
#

in trying to make this dudes tutorial make sense i've spent the last 4-5 hours making pong

#

i might as well as follow the 35 hour tutorial instead

naive pawn
#

you're gonna have to do some trig here

#

or i guess quaternions is the other options

#

basically:

  • reflect the incoming velocity along the normal
  • turn that velocity from x, y into r, theta (magnitude + angle) with one of:
    • Vector2.SignedAngle (deg)
    • Mathf.Atan2 (rad)
  • change the theta
  • turn that r, theta back into x, y (Vector2) with one of:
    • Quaternion.Euler (deg)
    • Mathf.Sin/Cos (rad)
  • assign that back to velocity
    you can mix rad/deg but you'll have to add the conversion factor Rad2Deg/Deg2Rad
#

does that make sense

onyx geyser
#

unfortuntely not, there is a few things i recognize

naive pawn
#

well, ask away about the parts you don't

onyx geyser
#

are you sure.

naive pawn
#

you can ignore the Mathf/Quaternion stuff for now, that's more of impl details

sour fulcrum
#

(if its like 5am you might wanna sleep)

naive pawn
#

make sure you understand the overall flow first

naive pawn
onyx geyser
#

(i'm too stubborn, i am going to make this ball bounce at an akward angle whether i like it or not)

naive pawn
#

that's ok, but it doesn't have to be right now

sour fulcrum
naive pawn
onyx geyser
#

at least from what i know

sour fulcrum
onyx geyser
#

i want to find out where this sits so i can base my questions around this

naive pawn
#

im not sure what your solution is, i wasn't following too closely in your convo earlier

naive pawn
onyx geyser
#

ok, so what is a theta

#

how is a theta used

naive pawn
#

theta is a greek letter that's commonly used to represent angles (some others are also used - alpha, beta, gamma, phi, can also represent angles)

#

the important thing is that we're changing the representation from x, y (cartesian) into a magnitude and an angle (polar)

#

are you familiar with the polar coordinate system?

onyx geyser
#

nope!

naive pawn
#

cool, try looking that up
you don't need to understand the math behind it just yet, just an overview of how it represents points

onyx geyser
#

while i'm doing that, what do you mean were changing x and y into magnitude and an angle

naive pawn
#

try looking up the polar coordinate system, i think it'll help illustrate

onyx geyser
#

it's made to determine a specifc point by taking two other points?

#

i assume this is a pretty important piece of math for programming as a whole judging by the way it looks

naive pawn
onyx geyser
#

ahh, ok i think i got it

#

as much as i can right now anyways

#

it's a lot like planning coordinates right?

#

so what were doing in this case is finding the coordinates of the ball and then shifting those coordinates? do i have that right or somewhat close?

naive pawn
onyx geyser
#

like when you're looking for a specific location on a map, you'd find the coordinates in a grid using a set of numbers

naive pawn
onyx geyser
#

right, were just finding it

naive pawn
#

like how 1 meter and 3ish feet have the same value, just expressed differently

onyx geyser
#

so the first step was reflecting, and now were finding the velocity in which it bounces from that wall? or where it will go once it bounces off since this takes place afterwards?

naive pawn
onyx geyser
#

rrah

naive pawn
#

(x=0,y=1) and (r=1, theta=90°) are the same point, but expressed in different systems

onyx geyser
#

oh ok i see i see

naive pawn
#

in the first, it's saying "go to the right 0 units, and go up 1 unit"
in the second, it's saying "go to the right 1 unit, and rotate that counterclockwise by 90°

onyx geyser
#

that's weird and complex

#

but i'm following

naive pawn
#

basically we want to modify the angle, but there's no angle to modify with the x,y representation
so we convert it to something that does have an angle, modify that, and then convert it back

onyx geyser
#

oh ok so that's the point of it being such a confusing mess

#

for conversion

#

so at the point of the code, how exactly did we come to find the x y? outside of using reflect, does the program now know what they are internally thanks to these 3 lines?

muted sapphire
onyx geyser
#

oh hey temple run

naive pawn
muted sapphire
onyx geyser
#

so even if i don't see it or have a clue what it is, it DOES exist

naive pawn
#

@sour fulcrum was your solution the OnCollisionEnter thing
im coming to realize ive had this discussion before with someone else and the issue was the collision had already happened and the velocity had changed, was that what you were referring to

onyx geyser
#

those being inDirection and inNormal, which didn't have an autocorrect yet are still correct

#

yep that was what we were talking about

#

that the collision happens and then we make the change

naive pawn
onyx geyser
#

i'm a father!!

sour fulcrum
#

but i was suggesting maybe to get kinda roughly ok results you could maybe just offset the normal from the contact point

naive pawn
#

the issue is more that the collision already happened though isn't it

sour fulcrum
#

nah Sila was just misunderstanding that we dont want to change the direction the collision caused, we want to give a new direction after it happened

onyx geyser
#

yep

naive pawn
#

ah ok i see

#

i suppose what im referring to is a new issue then?

#

once you get the normal of the collision, the rb velocity has changed so you wouldn't be able to get the incoming velocity

onyx geyser
#

i think we wanted to get the outgoing velocity and change that

naive pawn
#

or is Collision2D.relativeVelocity the incoming velocity?

onyx geyser
#

which is why it was important to have velocity, from my understanding

#

🤷‍♂️

sour fulcrum
#

so you are right in that that value is wrong and im a dumbass

#

but we didn't get to actually using that yet so im glad it was caught now 😄

naive pawn
#

aren't we all lamy_pain

#

i should test that

sour fulcrum
#

im 6 years deep into unity but with no formal educational in math so i have unpredictable blind spots when it comes to this aha, apologies

onyx geyser
#

so uh.. what next then

#

what're we doing

#

because it sounds like the direction shifted?

muted sapphire
#

How can i turn three float values into a Vector3? I'm unfamiliar with C# around that corner, especially with Vector3 being an unity specific class

clear juniper
muted sapphire
#

ah, the usual

#

thank you

naive pawn
# onyx geyser because it sounds like the direction shifted?

just to get you on the same page:
there's 3 velocities involved here

  • the incoming velocity
  • the outgoing velocity calculated from the collision
  • your custom outgoing velocity
    the last one is what we're trying to build, and it relies on the incoming velocity
    but in OnCollisionEnter2D, rigidbody.velocity is now the second one - we don't want that
naive pawn
sour fulcrum
muted sapphire
#

yeah, thank you, I didn't think it was this easy tbh

naive pawn
#

also fyi some unity apis have overloads to accept 3 floats or a Vector3, so if you're using one of those you don't have to make a Vector3

onyx geyser
sour fulcrum
muted sapphire
naive pawn
muted sapphire
#

Python does too much for me which makes debugging hell

onyx geyser
clear juniper
#

if I understand the aim correctly, can you not just do

void OnCollisionExit2D (Collision2D collision)
{
    ballRb.velocity = Quaternion.Euler (0,0,Random.Range(-5, 5)) * ballRb.velocity;
}```
#

or have I missed something

naive pawn
naive pawn
onyx geyser
#

yeah nothing happened

clear juniper
#

something should happen lmao, change it to -50 and 50?

clear juniper
onyx geyser
#

it works

#

kind of

#

it runs into the issue of sometimes not going the right direction after bouncing off a wall but other than that

#

it works.

#

how

#

how does this black magic work that i've spent the last several hours learning about?

#

idk if it's a normal feeling but seeing someone pop out of the woodworks with a code that works as it is needed after spending several hours prepping for an exhaustive process of math is definitely a unique feeling.

clear juniper
#

all that code does is rotate the velocity in the z direction randomly between -50 and 50 degrees. A negative value is anticlockwise, a positive value is clockwise, so you never actually need to work out the maths

#

and OnCollisionExit happens after the collision, so it's your final exit velocity that it is rotating!

onyx geyser
#

i think i know why this is one of maybe 8 emotes on the server now

clear juniper
#

being able to rotate vectors is a really handy trick to have in your game dev toolbelt 🙂

onyx geyser
#

because that is the exact feeling i feel upon see that this works and i didn't need to do a ton of guess work and find the normal and edit it.

clear juniper
#

rotatedVector = quaternion * originalVector

#

yeah I get the feeling lol

onyx geyser
#

that being said, it's now being added to the notebook

#

and i now need to go back through and make a ton of edits, because despite the fact that several hours of work could've been solved if i knew what a quaternion was, i still learned a lot

#

alright i'm going to bed..

clear juniper
#

good night 🙂

onyx geyser
#

i got to be up at before 1 pm for a doctors appointment

#

see if i can't get prescribed some Adderall

naive pawn
#

according to praetor and nav relativeVelocity is indeed the incoming velocity fyi

onyx geyser
#

good to know

#

thanks for helping me so much, i really appreciate it @sour fulcrum, you too chris

onyx geyser
#

btw, before i flat out disappear, i'd like to let you all know this is my wallpaper on my computer, my motivation for my project, and exhibits truth every time i look at it.

muted sapphire
#

Any ideas why this is never called? My parent object can ram the Cylinder named "Enemy" with tag "Obstacle" without getting to the debug statement

#

It never even makes it into the collision enter

fickle plume
muted sapphire
#

I was hoping that this would be triggered simply by two collision boxes touching each other

#

but this doesnt seem to be the case

naive pawn
#

does one of them have a rigidbody?

muted sapphire
#

No

naive pawn
#

yeah you need one

#

rigidbody is what drives physics

muted sapphire
#

I have the premade box collider and the capsule collider

muted sapphire
#

"this collider/rigidbody"

muted sapphire
#

they both have colliders

#

which is why i was hoping itd work

naive pawn
fickle plume
naive pawn
#

"when this collider has begun touching another rigidbody"/"when this rigidbody has begun touching another collider"

muted sapphire
muted sapphire
fickle plume
#

Since you were moving it by transform you need proper physics movement as well

muted sapphire
#

okay it works now

#

thanks

muted sapphire
#

went with the method of having the ground move below instead

trail heart
#

I don't think Rigidbody physics are designed to accomodate that kind of situation

muted sapphire
#

it works

#

except for the fact that the player doesnt get deleted when in the middle lane for some reason

#

only when in left lane, right lane, or transition

#

unsure what thats about but eh

#

I correct, it seems to not work when static

fickle plume
#

Even with kinematic rigidbody you still want to use Rigidbody.MovePosition so it updates properly in step with physics update. Teleporting transform will put some frames inside collider before hit registers.

muted sapphire
#

whenever NOT moving my character, the collision never occurs

#

only when going left or right it does

naive pawn
#

you probably need a dynamic rb on the thing that's moving

clear juniper
#

nah not necessarily, dynamic rigidbodies are for things that physics should move

muted sapphire
#

well, now my character has tremors

clear juniper
#

is your camera moving?

muted sapphire
clear juniper
#

can you record it and show your code?

muted sapphire
#

gladly

#

let me quickly see if i can make my character actually move properly again though

#

a part of my code that i had before doesnt like the rigidbody moving

clear juniper
#

oh can you screenshot your rigidbody too please?

muted sapphire
#

its almost unaltered but sure

fickle plume
#

make sure it's kinematic, if you replacing transform move

clear juniper
#

yeah that was my thought

muted sapphire
clear juniper
#

yeah you'll need to enable full contacts

#

by default, unity disables collision messages for kinematic/kinematic collisions and kinematic/static collisions

#

kinematic/static also happens for any object that has a collider and no rigidbody, unity treats those as static

muted sapphire
#

the tremors come from following

#

my transitions between lanes are done by checking if the player is in the correct lane and if not, moving them by speed into the target lane

#

somehow, the rigidbody seems to leave the middle lane ever so slightly enough that it goes too far

#

it surprisingly worked just fine when i used transform.Translate but the problems with that were long predictable

#

Might have to embed something for rounding down

clear juniper
#

can you paste your movement code here? 🙂
```cs
// your code
```
will format it like this:

// your code
muted sapphire
#
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.TextCore.Text;

public class Movement : MonoBehaviour
{
    public Object player;
    public float laneChangeSpeed;
    private InputAction laneLeft;
    private InputAction laneRight;
    private InputAction jumping;
    private int lane = 2;
    private Rigidbody motion;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        laneLeft = InputSystem.actions.FindAction("Lane left");
        laneRight = InputSystem.actions.FindAction("Lane right");
        jumping = InputSystem.actions.FindAction("Jump");
        motion = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        if (laneLeft.WasPerformedThisFrame() && lane > 1)
        {
            lane -= 1;
        }
        if (laneRight.WasPerformedThisFrame() && lane < 3)
        {
            lane += 1;
        }
        if ((lane - 2) < transform.position.x)
        {
            motion.MovePosition(transform.position + new Vector3(-laneChangeSpeed, 0, 0));
            if ((lane - 2) > transform.position.x)
            {
                transform.position = new Vector3(lane, transform.position.y, transform.position.z);
            }
        }
        else if ((lane - 2) > transform.position.x)
        {
            motion.MovePosition(transform.position + new Vector3(laneChangeSpeed, 0, 0));
            if ((lane - 2) < transform.position.x)
            {
                transform.position = new Vector3(lane,transform.position.y,transform.position.z);
            }
        }
        if (jumping.WasPerformedThisFrame())
        {
            
        }
    }
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Obstacle")
        {
            Destroy(player);
        }
    }
}
#

ignore the VERY clunky catcher in the middle

#

its a work in progress

#

trying to make it not shiver

clear juniper
#

it's not going to fix anything, but instead of void Update () you should use void FixedUpdate () when you're doing things with rigidbodies 🙂

muted sapphire
#

May i know what the difference is?

#

does it use time rather than frames?

clear juniper
#

FixedUpdate is when physics updates happen

#

it happens once every 0.02 seconds exactly (or rather, it tries to), where Update happens as soon as it can

burnt vapor
#

FixedUpdate is a static interval. It doesn't invoke every frame, rather it is a set number of invoked regardless of your FPS

muted sapphire
burnt vapor
#

So it's perfect for physics given that they will always have a reliable result

#

Important to note that if you don't rely on reliable output like this, you should just use Update. Perhaps you need it regardless, and pair it with Time.DeltaTime

clear juniper
muted sapphire
#

assumed as much

#

WasPerformedThisFrame doesnt really add up when its not called once per frame

#

I should probably begin seperating scripts

clear juniper
#
motion.MovePosition(transform.position + new Vector3(laneChangeSpeed, 0, 0));

this here should be changed to

motion.MovePosition(motion.position + new Vector3(laneChangeSpeed, 0, 0));

using motion.position instead of transform.position - again I don't think it will fix it, but it might do. Transform position and rigidbody position can get desynced

#

there are also a few places where you're setting transform.position instead of motion.position

muted sapphire
#

it goes a lot faster than that, the frame rate of the recording just isnt that high

clear juniper
#

yeah everywhere you use transform.position, change it to motion.position

muted sapphire
#

ah

#

oh yeah that worked

#

let me see if i need the catcher even or if its got itself

#

wait, it calls that 100 times a second, correct?

clear juniper
#

whatever the FPS is per second

#

so if the FPS is 100, it'll do it 100 times a second

muted sapphire
#

ah damn i use update not fixed update

clear juniper
#

tbh that's fine for now

#

don't worry too much about it - ignore what I said 😂

muted sapphire
#

DAMN YOU INPUTS

clear juniper
#

Update is FPS times per second, FixedUpdate is 50 times per second - which is why you didn't receive input

muted sapphire
#

figured that

clear juniper
#

you're actually using the new input system, a better way is probably to use events

muted sapphire
#

can you lock fps in settings? it would be kinda cool for later since im planning to make this for mobile

clear juniper
#

you can!

#

not in settings, it's Application.targetFrameRate = 60;

muted sapphire
#

ah yes, thanks

#

Although I am gonna have to figure out how to make it both compatible with 60 and 120 FPS

#

but thats a question for later

#

alright it works just fine now, even statically

burnt vapor
#

This value does not guarantee 60fps. It might get ignored altogether

muted sapphire
#

now onto further features

burnt vapor
#

Also depends on Vsync

clear juniper
burnt vapor
#

targetFrameRate might not even work on mobile. A lot of devices don't allow you to set a target

muted sapphire
#

amazing

#

i love mobile development

#

but again, thats something i can deal with later

burnt vapor
#

Comparing to other devices, xbox and playstation have hardcoded defaults. You know how ps5 has a performance mode that allows up to 120 FPS?

muted sapphire
#

yeah

muted sapphire
#

i mean, how do i make my input call that

clear juniper
#

the PlayerInput component 🙂

muted sapphire
#

oh component

#

my head was persistently thinking of library

clear juniper
#

ah yeah 😂 it's just a component, by default it uses SendMessage to call OnLaneLeft. You'll get a little info box under the "behaviour" dropdown on the PlayerInput component which will tell you the exact name, but I'm 90% sure that's right if it is called "Lane left" in your input actions asset

muted sapphire
#

I'll take all the things i had in global actions and instead put them into the playerinput components own thing

clear juniper
#

yeah you're basically doing input the most difficult possible way 😂 not your fault, all the tutorials are based on the beta version of the input system 🙃

#

PlayerInput component is great

muted sapphire
#

here, we just randomly click buttons and write stuff until it does what you want it to

#

alright it all works now, let me do jumping and crouching

#

what does the rigidbodys "use gravity" do, exactly? can i just use that to boost it up a little when i press jump

clear juniper
#

use gravity means it will continually fall down - but only when the rigidbody is "dynamic"

#

dynamic basically means unity calculates the position and movement based on forces - which is not what you want

muted sapphire
#

So what you're saying is i have to do gravity myself?

#

aww i dont wanna have to deal with another collision

clear juniper
#

yep! 😁 it's fairly straightforward though, and you don't have to deal with collisions - the rigidbody will sort that for you

muted sapphire
#

is there a command to check when my character is on the floor?

hexed terrace
#

not built in, no

clear juniper
#

all you'll want to do is keep track of a float _verticalVelocity, and add Physics.gravity.y to that every FixedUpdate. When you do MovePosition, use _verticalVelocity instead of 0 in your Vector3. Then when you jump, you set that velocity to some value, and your character will jump!

#

for checking when you're on the floor, you can raycast downward

muted sapphire
#

i kid you not just when you wrote that i made a yvelocity variable

clear juniper
#
if (Physics.Raycast(motion.positon, Vector3.down, 0.1f, LayerMask.NameToLayer("Floor")))
    // you're on the floor! Assuming your floor is on the "Floor" layer
#

0.1f there is the distance of the raycast

hexed terrace
#

you'd most likely also want to check the layer of the thing that's been hit

clear juniper
#

yeah

#

updated the snippet to do it the most simple way for now 🙂

muted sapphire
#

i feel like im gonna have to add a factor to that gravity

clear juniper
#

it's just using the gravity setting in project settings!

muted sapphire
#

one frame and my player is GONE

clear juniper
#

oh yeah you're moving with MovePosition

muted sapphire
#

oh wait its going upward

#

wtf

clear juniper
#

you'll want to multiply it by Time.fixedDeltaTime sorry 😂

muted sapphire
#

forgot a minus there

clear juniper
#

huh, I could've sworn MovePosition works with collisions

clear juniper
north kiln
clear juniper
#

isn't a layermask with a single layer the same value?

north kiln
#

No

clear juniper
#

huh

#

TIL

#

thought it was a shortcut to make the explanation a bit more straightforword. My bad 😂

naive pawn
naive pawn
clear juniper
#

should perhaps stop advising on things I rarely use 😂

muted sapphire
#

So what do i put instead?

clear juniper
#

up at the top you want a public LayerMask floorLayer;

#

then set it in Unity to the layer your floor is on (which should be different to the layer your player is on)

#

layers are up by the name of the gameobject 🙂

muted sapphire
#

then what do i put in the if statements?

clear juniper
#
if (Physics.Raycast(motion.positon, Vector3.down, 0.1f, floorLayer))
{
    yVelocity = 0;
}```
#

that should stop you falling through the floor!

muted sapphire
#

let me just

#
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.TextCore.Text;

public class Movement : MonoBehaviour
{
    public LayerMask floorLayer;
    public float jumpStrength;
    private float yVelocity;
    public Object player;
    public float laneChangeSpeed;
    private InputAction laneLeft;
    private InputAction laneRight;
    private InputAction jumping;
    private int lane = 2;
    private Rigidbody motion;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        laneLeft = InputSystem.actions.FindAction("Lane left");
        laneRight = InputSystem.actions.FindAction("Lane right");
        jumping = InputSystem.actions.FindAction("Jump");
        motion = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        if ((lane - 2) < motion.position.x)
        {
            motion.MovePosition(motion.position + new Vector3(-laneChangeSpeed, 0, 0));
            if ((lane - 2) > motion.position.x)
            {
                motion.position = new Vector3(lane - 2, motion.position.y, motion.position.z);
            }
        }
        else if ((lane - 2) > motion.position.x)
        {
            motion.MovePosition(motion.position + new Vector3(laneChangeSpeed, 0, 0));
            if ((lane - 2) < motion.position.x)
            {
                motion.position = new Vector3(lane - 2, motion.position.y, motion.position.z);
            }
        }
        motion.position = new Vector3(motion.position.x, motion.position.y - (yVelocity * Time.fixedDeltaTime), motion.position.z);
        if (Physics.Raycast(motion.position, Vector3.down, 0.1f, LayerMask.NameToLayer("Floor")))
        {
            yVelocity = 0;
        }
    }
    void FixedUpdate()
    {
        if (!Physics.Raycast(motion.position, Vector3.down, 0.1f, LayerMask.NameToLayer("Floor")))
        {
            yVelocity -= Physics.gravity.y;
        }
    }
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Obstacle")
        {
            Destroy(player);
        }
    }
    void OnLaneLeft(InputValue val)
    {
        if (lane > 1)
        {
            lane -= 1;
        }
    }
    void OnLaneRight(InputValue val)
    {
        if (lane < 3)
        {
            lane += 1;
        }
    }
    void OnJump(InputValue val)
    {
        if (Physics.Raycast(motion.position, Vector3.down, 0.1f, LayerMask.NameToLayer("Floor")))
        {
            yVelocity = jumpStrength;
        }
    }
}
#

doesnt work properly

#

oh wait

#

i should put floorLayer somewhere shouldnt i

clear juniper
#

yeah change LayerMask.NameToLayer("Floor") to floorLayer that was my mistake!

#

and maybe change cs yVelocity = 0;
to

if (yVelocity < 0)
    yVelocity = 0;
muted sapphire
#

you mean in case it stops jumps otherwise

clear juniper
#

exactly, yeah!

muted sapphire
#

still falls through the floor htough

#
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.TextCore.Text;

public class Movement : MonoBehaviour
{
    public LayerMask floorLayer;
    public float jumpStrength;
    private float yVelocity;
    public Object player;
    public float laneChangeSpeed;
    private InputAction laneLeft;
    private InputAction laneRight;
    private InputAction jumping;
    private int lane = 2;
    private Rigidbody motion;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        laneLeft = InputSystem.actions.FindAction("Lane left");
        laneRight = InputSystem.actions.FindAction("Lane right");
        jumping = InputSystem.actions.FindAction("Jump");
        motion = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        if ((lane - 2) < motion.position.x)
        {
            motion.MovePosition(motion.position + new Vector3(-laneChangeSpeed, 0, 0));
            if ((lane - 2) > motion.position.x)
            {
                motion.position = new Vector3(lane - 2, motion.position.y, motion.position.z);
            }
        }
        else if ((lane - 2) > motion.position.x)
        {
            motion.MovePosition(motion.position + new Vector3(laneChangeSpeed, 0, 0));
            if ((lane - 2) < motion.position.x)
            {
                motion.position = new Vector3(lane - 2, motion.position.y, motion.position.z);
            }
        }
        motion.position = new Vector3(motion.position.x, motion.position.y - (yVelocity * Time.fixedDeltaTime), motion.position.z);
        if (Physics.Raycast(motion.position, Vector3.down, 0.1f, floorLayer))
        {
            if (yVelocity < 0)
            {
                yVelocity = 0;
            }
        }
    }
    void FixedUpdate()
    {
        if (!Physics.Raycast(motion.position, Vector3.down, 0.1f, floorLayer))
        {
            yVelocity -= Physics.gravity.y;
        }
    }
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Obstacle")
        {
            Destroy(player);
        }
    }
    void OnLaneLeft(InputValue val)
    {
        if (lane > 1)
        {
            lane -= 1;
        }
    }
    void OnLaneRight(InputValue val)
    {
        if (lane < 3)
        {
            lane += 1;
        }
    }
    void OnJump(InputValue val)
    {
        if (Physics.Raycast(motion.position, Vector3.down, 0.1f, floorLayer))
        {
            yVelocity = jumpStrength;
        }
    }
}
clear juniper
#

did you set the floorLayer in unity?

muted sapphire
#

yes

#

Set the object "Floor" and it's children "Floor1" and "Floor2" to layer "Floor" and then set floorLayer to Layer "Floor"

#

but still falling through the floor

#

bullet into my head

clear juniper
#
    void Start()
    {
        motion = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        yVelocity -= Physics.gravity.y;
        if ((lane - 2) < motion.position.x)
        {
            motion.MovePosition(motion.position + new Vector3(-laneChangeSpeed, 0, 0));
            if ((lane - 2) > motion.position.x)
            {
                motion.position = new Vector3(lane - 2, motion.position.y, motion.position.z);
            }
        }
        else if ((lane - 2) > motion.position.x)
        {
            motion.MovePosition(motion.position + new Vector3(laneChangeSpeed, 0, 0));
            if ((lane - 2) < motion.position.x)
            {
                motion.position = new Vector3(lane - 2, motion.position.y, motion.position.z);
            }
        }
        if (Physics.Raycast(motion.position, Vector3.down, 0.1f, floorLayer))
        {
            if (yVelocity < 0)
            {
                yVelocity = 0;
            }
        }
        motion.position = new Vector3(motion.position.x, motion.position.y - (yVelocity * Time.fixedDeltaTime), motion.position.z);
    }
    
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Obstacle")
        {
            Destroy(player);
        }
    }
    void OnLaneLeft(InputValue val)
    {
        if (lane > 1)
        {
            lane -= 1;
        }
    }
    void OnLaneRight(InputValue val)
    {
        if (lane < 3)
        {
            lane += 1;
        }
    }
    void OnJump(InputValue val)
    {
        if (Physics.Raycast(motion.position, Vector3.down, 0.1f, floorLayer))
        {
            yVelocity = jumpStrength;
        }
    }
``` does this change anything?
#

I've moved a couple of things around, I can explain in a sec

muted sapphire
#

Oh yeah i can use fixedupdate now, thanks for the reminder

muted sapphire
clear juniper
#
  • put everything in fixedupdate
  • move yVelocity -= Physics.gravity.y; to the top of fixed update
  • don't do a raycast for applying gravity
  • move the final position change to after setting y velocity to 0 if you're on the floor
#

can you check if the raycast ever triggers in fixedupdate?

muted sapphire
#

it does not

clear juniper
#

what happens if you change the 0.1f to 0.6f

muted sapphire
#

what does that 0.1f do

#

nope still nothing though

#

yk what, i think im just gonna take a break

clear juniper
#

yeah that's reasonable 😂

clear juniper
muted sapphire
#

ah, i see

#

how can so simple things be so hard

#

i was planning to do so much but if that already causes so many problems i fear for myself

clear juniper
#

it's difficult to help over the internet, unfortunately! You get used to it though

#

I just wanna rewrite the whole thing the way I'd do it, but that would be helpful for nobody xD

hexed terrace
#

If the pivot is in the center of the player, that 0.1f won't be long enough

thorn galleon
#

Where can i find the anchor presets are in 6.0? I'm not seeing it in rect transform like shown in some tutorials

clear juniper
#

can you show a screenshot?

thorn galleon
clear juniper
#

you need a gameobject that has a Canvas component on it, and your UI has to be a child of that

thorn galleon
slender nymph
#

you should check out the documentation pinned in #📲┃ui-ux to learn how the canvas component works

rough sluice
#

Can someone tell me that why controls are weired?:
PlayerOneController.cs:

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

[RequireComponent(typeof(CharacterController))]
public class PlayerOneControl : MonoBehaviour
{
    [SerializeField] float _speed = 25.0f;
    [SerializeField] float _jumpSpeed = 8.0f;
    [SerializeField] float _gravity = 20.0f;
    [SerializeField] float _sensitivity = 5f;
    CharacterController _controller;
    float _horizontal, _vertical;
    float _mouseX, _mouseY;
    bool _jump;

    void Awake()
    {
        _controller = GetComponent<CharacterController>();
    }

    void Update()
    {
        _horizontal = Input.GetAxis("Horizontal");
        _vertical = Input.GetAxis("Vertical");
        _mouseX = Input.GetAxis("Mouse X");
        _mouseY = Input.GetAxis("Mouse Y");
        _jump = Input.GetButton("Jump");
    }

    void FixedUpdate()
    {
        Vector3 moveDirection = Vector3.zero;

        if (_controller.isGrounded)
        {
            moveDirection = new Vector3(_horizontal, 0, _vertical);
            moveDirection = transform.TransformDirection(moveDirection);

            moveDirection *= _speed;

            if (_jump)
                moveDirection.y = _jumpSpeed;
        }

        float turner = _mouseX * _sensitivity;
        if (turner != 0)
        {
            transform.eulerAngles += new Vector3(0, turner, 0);
        }

        if (looker != 0)
        {
            // action on mouse moving right
            transform.eulerAngles += new Vector3(looker, 0, 0);
        }

        moveDirection.y -= _gravity * Time.deltaTime;

        _controller.Move(moveDirection * Time.deltaTime);
    }
}
clear juniper
#

then in your code, cs if (looker != 0) { // action on mouse moving right cameraArm.eulerAngles += new Vector3(looker, 0, 0); }

#

where cameraArm is a public Transform cameraArm that you set in Unity 🙂

fervent abyss
#

hey guys, i have an issue that i cant seem to resolve
basically, i have a radar item in my game, that you can equip to track distance between you and the monster
the player has a radar script, that holds reference to the player head
the monster has a script MonsterLocation located on its body, with an instance so i can access its body transform like instance.transform.position, and it sets the instance when the monster is spawned

so basically the issue is:
if you equip the radar BEFORE the round starts (before the monster is spawned), it works fine and shows proper distance

but, if you equip the radar AFTER the round started (aka after the monster has been spawned), it shows a constant value of like ~0.5m, and never changes

here are the scripts. also the monster is spawned as a networked prefab because its a multiplayer game

using System;
using TMPro;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;

public class Radar : MonoBehaviour
{
    [Header("Player")]
    [SerializeField] Transform playerLocation;

    [Header("UI")]
    [SerializeField] TextMeshPro distanceInfo;

    void Update()
    {
        if(MonsterLocation.instance){
            distanceInfo.text = $"Distance:\n{Vector3.Distance(playerLocation.position, MonsterLocation.instance.transform.position):F1}m";
        } else {
            distanceInfo.text = "Distance:\n?m";
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using Fusion;
using UnityEngine;

public class MonsterLocation : NetworkBehaviour
{
    public static MonsterLocation instance { get; private set; }

    public override void Spawned()
    {
        base.Spawned();
        instance = this;
    }
}
#

like if someone could help cuz i cant fix ts somehow 💀

naive pawn
#

sounds like it's grabbing a stale MonsterLocation.instance, maybe?

#

try logging its position

fervent abyss
fervent abyss
naive pawn
#

try logging something in that Spawned

#

see if it's triggering when you don't want it to

fervent abyss
#

okay

fervent abyss
naive pawn
#

same as what?

hardy bobcat
#

Hey all, dunno if this is the right place to ask, but is there really not any way to limit the framerate in the editor? I tried to limit the unity editor framerate externally using the NVIDIA control panel, but doesn't seem effective

fervent abyss
#

like player pos = monster pos

naive pawn
#

ok, but does it log when it shouldn't

#

when is it logging - only when the monster spawns? does it log more than that?

polar acorn
naive pawn
fervent abyss
polar acorn
#

You reference the one you actually want directly

hardy bobcat
#

I've had luck doing it in gameview, I'm looking for a way to do it in the editor, since I have the editor open quite a bit, while doing stuff and my video card is absolutely flying

#

Does closing the scene tab do anything?

polar acorn
polar acorn
#

Probably best to just set instance in Start or Awake then

fervent abyss
polar acorn
#

Put a log when you set instance. Ensure that log only prints once. Try logging the name of the object it's on as well

real grail
# fervent abyss yeah

What you are doing is this:
This is basically a Singleton Setup

public class MonsterLocation : MonoBehaviour
{
    public static MonsterLocation instance;

    void Awake()
    {
        instance = this;
    }
}

Witch means there is only one of these in the scene.

If there is no Monster at the start.
Then in your Radar Script in Update:

MonsterLocation.instance should be null idk how is that not showing on your console for error if there is no moster at the begining.

fervent abyss
naive pawn
#

well it apparently isn't

real grail
fervent abyss
#

also when the monster is despawned after the round, it shows this

sour fulcrum
#

no, if you are logging monsterlocation.instance.transform.position, you are logging the monsterlocation position

polar acorn
polar acorn
polar acorn
fervent abyss
#

no wait what im confused

#

what im saying is that the monsterlocation.instance.transform.position gives not the monster location object position but the players position

polar acorn
#

Log MonsterLocation.instance.gameObject.name

#

See what object it's getting the position from

fervent abyss
#

okay

naive pawn
#

try t:MonsterLocation in the hierarchy search

fervent abyss
fervent abyss
fervent abyss
sour fulcrum
#

MonsterLocation.instance is not going to be the player. it's giving the monster location object position

polar acorn
fervent abyss
polar acorn
fervent abyss
polar acorn
sour fulcrum