#Diagonal Direction on Input Axes Release Across Frames
1 messages Β· Page 1 of 1 (latest)
oh thanks it's much easier now, also no i honestly can't get why it doesn't work
wait i'll send the code with your suggestion added, maybe i did something wrong
it looks like there is no difference so idk what to do
So you added the code but didn't really integrate it with what you've already got going on... I provided it just an example, without knowing what your code looked like to begin with.
I think my facingDirection is your moveDirection. And instead of using two floats to track moveX and moveY individually, mine just combined them into a single Vector2 input, which was necessary in order to use input.sqrMagnitude to more easily check how many input axes had values - for example, that is that my input.sqrMagnitude == 0f is equivalent to your moveX == 0 && moveY == 0.
At a glance I'm not sure if it's necessary to keep track of the lastMovementDirection seperately from the previousInput - I think they'd probably represent the same thing - but that can be ignored for now.
So let's see...
I think this would be the two integrated https://gdl.space/odiwozokeh.cpp
(or one version of it anyway)
though this seems like it might be a bit off, both in the original and the integrated one above:
if((moveX == 0 && moveY == 0) && moveDirection.x != 0 || moveDirection.y != 0)
{
lastMoveDirection = moveDirection;
}
if (input.sqrMagnitude == 0f && moveDirection.x != 0 || moveDirection.y != 0)
{
lastMoveDirection = moveDirection;
}
I'm pretty sure these conditions will be evaluated from left to right, so the original is more like
((moveX == 0 && moveY == 0) && moveDirection.x != 0) || moveDirection.y != 0
I've not really worked with Animator yet - what's it do with lastMoveDirection, out of curiosity?
sry i fell asleep but lastMoveDirection was my attempt to solve this problem
nonono you sleep - then you should sleep. Sleep solves more coding issues than thinking
tried to make it remember the last input i've used
yeah but no honestly i'm pretty i have insomnia ? or smth, gonna see a sleep therapist or idk what it's called, during the next holidays, if i'm awake i can't sleep before quite a while
quite annoying lol
but yeah i slept enough for now fr
I feel that - some medical-grade insomnia ended my collegiate pursuit early. I've gotten a lot better at it in the last three years or so, but it took a lot of mental health work - in my case my sleep issues ultimately seemed to stem from the nature and nurture of my upbringing... go figure π
I've been recently thinking about finally finishing my degree, now that I can actually sleep somewhat. But I totally understand the havok that insomnia can wreak upong your livelihood
also with this code, it's pretty cool, but the character won't stop after i used a keys, like if i go in one direction and stop pressing, he won't stop
I'll need to think on that a moment...
oh yeah same here, these issues are really annoying for college, it's cool you managed to recover from it, i know much people who think they won't figure out how to get out of it, on my hand i know it's just because it's last year of school etc... so yeah it should be fine later (also big gamer moment), also best of luck if you ever go finish your degree
if it helps i could stream it like, tomorrow or something
to show what is happening
Okay yeah - this code works under the assumption that moveDirection is just the vector which represents the direction which the character is facing, but the Move() method operates under the assumption that the character actually wants to move in the way of moveDirection... so maybe it's best to keep these things separate... But the duct-tape fix would be
void Move()
{
if (input.sqrMagnitude > 0f)
rb.velocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);
}
"If there's any input whatsoever, propel the GameObject in the direction of moveDirection (input)"
...but ultimately, we're starting to compound a bunch of variables which could be simplified into more direct relationships with some thinking. But for the moment, I'd really just like to see the whole system "work," overly-obtuse relationships be damned π
yep me too, also thanks so much for helping, it's nice to have someone to help when you're banging your head for so long
also didn't you say you were a beginner ?
I really like weird problems because they force me to explore things which I wouldn't have otherwise... or verbalize the things which I think I understand in such a manner that I come to understand them better. Answering others' questions is a big part of my learning strategy, as I've discovered
so weird... same problem
I've spent a bit over a decade working with code, but I'm totally new to C# and Unity
yeahhh happy to see someone with such a good vision of the subject, unfortunately i'm too much of a beginner to be able to do this rn
oh wow so still, pretty new to this that's impressive
so i guess wait
mmmmmmmmmmmmm
nvm
The basic logic of most any language will carry from one to the next - it doesn't matter which language you learned to communicate with computers with, the most basic concepts will carry over between dialects - you just need to learn the new words for what you're used to saying, for the most part.
What's your code look like, presently?
yeah that's true, my teacher used to say "oh wow it'll be so hard for you guys later you'll see" cuz he only teached us python but bruh it's really similar for the most part
https://gdl.space/oxagolehac.cpp it's quite literally just the one you gave me with your modifs as well, also sorry for being so not like, helping much ? but i just wanna learn the basics and i already mess up π
That's a language which I never touched π. But I've heard that a lot - that Python is easy to learn. The collegiate program which I briefly engaged in switched to starting with Python not too long after I left... prior to that the program had a fairly astounding failure rate. And now Python actually seems to have like really important relevance in world. Data science and AI applications seem to favor it - which was definitely not the case at the time. My coursework then was just C, Java, and a little bit of assembly... I think C might be the most important of the three, just to have a general sense of what's happening "on the metal" - a vague idea of how code actually does what it does on physical hardware. Assembly solidifies that idea and can make you a mile better at using a debugger to figure out why and how your code does what it does... but it's probably not ultimately necessary in order to write good code.
But with or without that, the general logic is all the same between languages... I think it's actually called "propositional logic," by the mathematicians. My absolutely favorite part of the coursework I took was a bit in a "Discrete Mathematics" course where we translated parts of the US Constitution into "propositional expressions" in order to prove it's logic or look for logical errors. But in any scenario, you don't need a concrete understanding of the technicalities of how a computer works to understand the logic behind it's basic operations... Computers were built by humans, for humans. And most every language is created to make the logic they depend on accessible to humans - so most languages use the same sort or logic that we can understand, no matter where we see it, or the ways in which it's expressed.
Yeah i've been told that too about Python, the sad thing is that we only use python and not anything else, like an engine or something, only Python++ so we feel very limited and have to learn anything on our own, just like right now. I also learned Rust a year ago in order to make a few mods in Smash Ultimate, this language tho is one of those which feel a lot more different than others, especially when it comes to macros, still don't understand it quite well. But yeah Python is preferably teached (at least in france), because it would make for a really good base as it seems to use most of the words used in other language such as C#, C++, C, etc
I have to apologize in advance for the length of this reply - I've wandered faaaaaar off topic O,o
ahah no worries man i like having a normal conv too
sorry for being so not like, helping much ?
Not a problem... we all learn in different ways. And for my own ends, your pursuit is helping me to understand Unity better... I need the challenge to improve, and often I'm procrastinating on doing something with Unity, but a question will entice me to explore... So I hope it's oftenly a win-win. I can learn from the challenge, and the asker can learn from whatever implementation I come up with...
But at the same time I hope there are others more experienced who are following my conversations, because I can make no guarantees that my approach is terribly reasonable or that there is not some better way to achieve the goal than whatever I came up with. To that end, I want to emphasize that I'm just sharing an idea - it may not be the best idea, and you should most definitely seek to refine it if at all possible π
like an engine or something...
The things which interpret or compile a language are all engines of a sort... My favorite language is JavaScript and I've worked with it for well over a decade - but I still don't entirely understand the crazy things the interpreter does under the hood to try and run our code just a little bit more efficiently.... JavaScript is usually ran in an environment where it interoperates with a specific set of APIs - the web browser... When we execute our JS code in a web browser, it's sort of running against an engine in it's own right.
I also learned Rust a year ago
That's also a super important one. Parts of the Linux kernal and Windows are now written in Rust. The NSA released a statement in the last few months urging developers to switch over to "memory safe languages" - they're asking for devs to stop working in C and C++ because they're "close the metal," and it's relatively easy to write code which will start modifying bits of memory which it logically shouldn't... And that possibility becomes a vulnerability, when someone figures out what the original code is doing. The NSA wants devs to shift to working in languages which will protect against fucking up when working with memory addresses... and Rust is one of those. The language will go far and be used for many things in the near future. It's pretty awesome that you have some exposure to it already.
especially when it comes to macros
You don't really need to worry too much about macros. The rough idea is that they're just a very basic sort of code which executes at "build-time" - they do something right before a program is converted into a binary or ran in "development mode", and then never again... Apart from limiting the code which is compiled for a build - e.g. separating code which should execute in the Unity editor from code which should be included in the distributed game built on Unity - everything you can do with a macro can do in code as well. A macro will likely be more efficient if and when it's applicable to use - but until you understand that distinction, it won't be the crucifix in your code to code it instead.
But yeah Python is preferably teached (at least in france)
That market is growing rapidly... I think it's probably a smart decision on the part of the French educational system π
Okay, so finally the code at hand...
I think this might all come down to all the sluff I don't know about the Animator... like with this code in place, now moveDirection is most definitely a normalized Vector2 representing which direction the character should be facing, despite letting go of w/s or a/d inputs at different times.... But I don't understand how it could be moving forward in that direction if the only code which actually moves the game object is
void Move()
{
if (input.sqrMagnitude > 0f)
rb.velocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);
}
... if the player is not pressing any WASD key, then this should...
well, oh shit - it never resets. If the player stops giving inputs (input.sqrMagnitude == 0f), rb.velocity just stays at whatever it last was π