#💻┃code-beginner
1 messages · Page 658 of 1
but from the back i can be the correct distance of interactrange
Kinda confusing
I'll double check it's collider
you should give this a read https://unity.huh.how/coroutines/waiting
or wait, i guess you are setting hashappened to false in the coroutine? it's not exactly very clear with these screenshots of code
yeah that's just checking it's value not setting it, not sure if you actually read what i said
is there a shortcut to getting a list of the four orthogonal directions? I'm imagining something like Vector2Int.orthogonal() that returns a List<Vector2Int>, but I'm not sure whether this exists and can't find it
I set the value to true futher down
hashappened = true;
So it only runs if it hasnt happened yet
please read what i said
I did, it's working so i'm unsure why you're referencing that that's all
so where do you set it to false again? or do you only want this to happen one time ever?
Yeah it's a one time jumpscare
Issue I'm having now with the raycast (sigh) is the range of 30 works fine from behind, But i have to walk about 3 grids infront of it for it to trigger it's facing front
And there is nothing in the way of it so i'm a little confused
confirm your assumptions, log what is detected by the raycast
Loud audio warning
This is whats happening, Seems it's only detecting when I look at the top of the box collider which is very weird
yeah it's just grabbing objects behind it
Until I look at the head I believe
Wait will children inherit the tag of a parent?
Oh that's likely the issue then i'll double check
I think I figured it out lol
I'm looking through this door way from the inside
I think the mesh renderer is blocking the ray
So it's actually hitting the open space of the door
unless it has a collider then no it isn't
have you actually confirmed that is what is being hit?
like have you actually logged what is hit
I'm abit confused on the log line I need
Debug.Log(hitInfo);
just returns 'object'
so print the info in that object?
So like Debug.Log(hitInfo.collider.name);
sure, but you can add more than just a single piece of data to a log
Oh my god I'm hitting the invisible box trigger that actually spawns the mob behind you when you walk in
for example you could do this: Debug.Log($"Raycast hit {hitInfo.collider} with tag {hitInfo.collider.tag}", hitInfo.collider);
this will print the name and tag of the object as well as highlight the relevant object when you click it
I didnt think a ray would hit this?
see this is why you need to verify your assumptions. you probably want a layermask on the raycast so it only hits specific layers (like actual obstacles)
There isn't any jumping in this game so i'll just drop it to footheight as it's impossible to 'look through it' at that height
But I appriciate you helping me debug ALOT
I'll defo be doing more debugging when running into issues like this
I also found this! QueryTriggerInteraction.Ignore) which apparently fixes the issue
what result are you actually trying to get here? "a list of the four orthogonal directions" doesn't make sense
I was just wondering whether there was a shortcut that evaluates to {Vector2Int.up, Vector2Int.right, Vector2Int.down, Vector2Int.left} so I can easily iterate over it
but if there isn't, it's not a big deal to just create a variable containing this list
yea there isn't one. just a note those arent orthogonal
Can someone help me as I'm just learning how to heal because my player doesn't respond to my keys when I want to move him
public IEnumerable<Vector2Int> AllDirections() {
yield return Vector2Int.up;
yield return Vector2Int.left;
yield return Vector2Int.down;
yield return Vector2Int.right;
}```
this is a fun way
but a static array works too
good god burn it with fire
In this code right here, "return dst;" is written to "return the results". However ☝️ 🤓 as this method already calculates the results, what's the point of using "return"? Is it because it returns the result back to the method? Wouldn't the method already calculate and have the result: ☝️ 🤓
(serious question btw)
You know how you have float dst = on the line you call that function
That is because the function returns a value
If it didn't return the value, there's zero point in running the function at all because it wouldn't actually do anything
You'd compute a number then immediately volleyball spike it directly into the dumpster when the function ends
😍
" Is it because it returns the result back to the method" so is this kind of the answer?
Just tryign to make sure I understand what you are saying
If your function returns void, it can't be on the right side of an =
yes?
If it returns a value, you can use it anywhere that would expect that type
So, this function returns a float, so you can use a function call anywhere that expects a float
For example, you could use this function as a parameter in a new Vector3, or even as one of the parameters to another execution of this function
It returns the result back to the caller yes.
So here, can you get the location of a player (vector3) and the location of another players vector3 and paste it there instead of needing to paste numbers? would that work (I am just talking about the raw idea not the details)
I have no idea what you're asking here but this function takes four floats as parameters. You can get those floats however you like
literal values and variables/properties/methods/etc can be used interchangeably, as long as they have the same type. So as long as whatever you plug in is a float, you can put anything you want in there. Be it 5 or transform.position.y or myRigidbody.velocity.magnitude it will ahappily accept anything that is a float or can be coerced into a float
😍 so yes
the only thing your method requires is that the expression you pass in is a float
it can be literally anything that resolves to a float type
fun note - because your method returns float, it too can be used as a parameter that expects a float.
The method has no return statement
but you specified it as returning a float
Do you need it to return something?
it doesn't look like the caller is using or expecting it to return anything
Although it's also not doing anything right now
so it depends what you're trying to actualyl do here
are you wanting the function to change the values of the variables from Update?
you would either have to return that data, or use ref params
I'm trying to get input from the user of x and y, these inputs will be used to change the size of a cube
😭
The simplest thing to do here would be to use Vector2
because a function can only return one value
👨🪵 🔥
but a Vector2 is two floats wrapped up in one
Wait it also looks like you're not even using your parameters really
I'm actually really confused about what your code is supposed to be doing
LMAOOO
are you trying to SET the scale of the cube, or GET it?
set the scale
Also why are you using Console.ReadLine?
This is not a console application
this is a Unity game
you can't use Console.ReadLine
how do I get input
what kind of input
you don't
How would the user enter anything into the "console"
it's a 3D application, not a command line app
oh my goooood
I will complete this some other time than
😭
if you wanted to code such thing
how would you have done it
I'm trying to figure out what the "thing" you want to code is still
maybe you want to display some text inputs on screen and let the user input stuff there?
Get a cube
Then resize the cube to match?
and be able to change it's scale
based on what though
through user input
what kind of input
from where?
wdum?
from their mind?
I thought of getting it from the console
Typed into an input field in the screen?
I will have to create some UI
I thought of it as if it's a console program
Does this part of the code make sense for you? + would it work?
I know it wouldn't
but just this part
does it make sense?
basically something like:
public Slider xSlider;
public Slider ySlider;
public Transform theCube;
void Update() {
Vector3 scale = new(xSlider.value, ySlider.value, 1);
theCube.localScale = scale;
}```
this is what I would do
there's no reason to have two separate variables here
Just directly reference the Transform
this is what I would do
you should definitely continue trying to learn how functions work though - that's valuable knowledge
Welcome to this introduction to game development. We'll be starting from the beginning, so no prior knowledge of programming or the Unity game engine is required.
Unity can be downloaded here: http://unity3d.com/get-unity
Watch episode 01: https://youtu.be/9iCnjdXEfMA
If you'd like to support these videos, you can make a recurring monthly don...
going through this
bonk, i tried to get a horizontal direction, and rotate it 90 degrees
it always seems to be almost the same direction though
did i do a mistake?
do i need to normalize it?
Add logs
i havent debugged much in unity yet, how do i do that?
oh i figured it out
i forgot that this object is off in narnia
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 5f;
public Rigidbody2D RigidBody;
public Weapon weapon;
Vector2 moveDirection;
Vector2 mousePosition;
void Update()
{
// Get input for movement
float moveX = Input.GetAxis("Horizontal");
float moveY = Input.GetAxis("Vertical");
// Get mouse position
mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (Input.GetMouseButtonDown(0))
{
// Fire the weapon
weapon.Fire();
}
moveDirection = new Vector2(moveX, moveY).normalized;
mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
void FixedUpdate()
{
if (moveDirection != Vector2.zero)
{
RigidBody.linearVelocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);
}
else
{
RigidBody.linearVelocity = Vector2.zero; // Stop the player when there's no input
}
Vector2 lookDirection = mousePosition - RigidBody.position;
float aimAngle = Mathf.Atan2(lookDirection.y, lookDirection.x) * Mathf.Rad2Deg - 90f;
RigidBody.rotation = aimAngle;
// Rotate the player to face the mouse position
}
}
hey so whenever i let go of my wasd keys to move the player they keep moving for a couple of seconds after, any help?
GetAxis has some smoothing by default. Use GetAxisRaw to skip that, or modify the gravity/sensitivity settings of the axis in the input manager
@flint tendon
legend thank you
using UnityEngine;
using UnityEngine.InputSystem;
public class FollowShip : MonoBehaviour
{ public Transform player;
[SerializeField] private float MousePosY;
[SerializeField]private float MousePosX;
[SerializeField] private float LimitRotationX;
[SerializeField] private float LimitRotationY;
// 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()
{
Vector3 MousePos = Input.mousePosition;
MousePosX = MousePos.x;
MousePosY = MousePos.y;
LimitRotationY = Mathf.Clamp(-MousePosY, -80,80);
LimitRotationX = Mathf.Clamp(MousePosX, 300,-300);
transform.position = player.position + new Vector3(0,1,-2);
transform.rotation = Quaternion.Euler(LimitRotationY, LimitRotationX,0);
}
}
``` when i look left and right it snaps to each side any way to fix this
nevermind i fixed it!
I'm trying to make an expandable menu. When I click on it (as shown in the gif), it doesn't expand, it does this weird thing. I'm not sure exactly if it's something wrong in the code or something wrong I'm doing in Unity. I've followed two YT tutorials and still got the same results.
This is how I'm trying to get it to look when it expands
Looks like they “expand” inside the button itself
Did the tutorial use some kind of component that offsets the buttons from each other, or offset their location in thr code?
I know I'm supposed to use DOTween Package. It wasn't super clear if it used some kind of component that offsets the buttons from each other or offsets their location in the code since there was just music playing and no actual speaking. I can send the code if it helps
It might
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
A tool for sharing your source code with the world!
A tool for sharing your source code with the world!
You can send these to me in DMs, and I can take a look at it when I’m done with work, if somebody else hasn’t already responded by then
I was able to fix it, thank you. I ended up just recreating the images and adding the button component and that fixed it. I guess I did it incorrectly the first time.
Now I need to figure out why the buttons are like this when I load in. Edit: Fixed
hey guys
Can you help me create first person player movement for mobile with unity's new input system?
I have asked in input-system channel also.
don't crosspost please
Very cool!
Yo im cooked
I just tried to make a audio fader
And its so bad it causes unity to tweak out and no longer is able to be clicked on but keeps running
and i can't even force close it in taskmanager cause taskmanager doesn't recognize it as a application running
It might be because
oid FadeSong(int newSong, int old)
{
Debug.Log("fade");
float timeToFade = 0.25f;
float timeElapsed = 0f;
while (timeElapsed < timeToFade)
{
if (old == 0)
{
song1.volume = Mathf.Lerp(0.1f, 0, timeElapsed / timeToFade);
if (newSong == 1)
{
song2.volume = Mathf.Lerp(0, 0.1f, timeElapsed / timeToFade);
}
if (newSong == 2)
{
song3.volume = Mathf.Lerp(0, 0.1f, timeElapsed / timeToFade);
}
}
if (old == 1)
{
song2.volume = Mathf.Lerp(0.1f, 0, timeElapsed / timeToFade);
if (newSong == 0)
{
song1.volume = Mathf.Lerp(0, 0.1f, timeElapsed / timeToFade);
}
if (newSong == 2)
{
song3.volume = Mathf.Lerp(0, 0.1f, timeElapsed / timeToFade);
}
}
if (old == 2)
{
song3.volume = Mathf.Lerp(0.1f, 0, timeElapsed / timeToFade);
if (newSong == 0)
{
song1.volume = Mathf.Lerp(0, 0.1f, timeElapsed / timeToFade);
}
if (newSong == 1)
{
song2.volume = Mathf.Lerp(0, 0.1f, timeElapsed / timeToFade);
}
}
timeElapsed = Time.deltaTime;
}
if (old == 0)
{
song1.Stop();
}
if (old == 1)
{
song2.Stop();
}
if (old == 2)
{
song3.Stop();
}
}
Is it because im trying to use Mathf.Lerp over a certain time
without using IEnumerator
Does that kill me
this is your culprit
while (timeElapsed < timeToFade)
also how are either of your variables ever supposed to change on their own?
you mean Timetfade and elapsed?
I have ```cp
timeElapsed = Time.deltaTime;
To deal with that while loop no?
@swift elbow
Cause its not an ienumerator
the while loop never stops
can you explain this a little more
yes
Cause i thought this line would stop the while loop
its not just that
you need to yield to exit the loop
cause once it gets to that, timeElapsed is no longer smaller than timeTofade
what is yield?
it's what allows the loop to stop running
that won't on it's own
why not?
The contents of a while loop is the only thing running until the condition is met. It's important understand this means no other code is running, not even the code that updates input or renders the game.
i used a while loop in a different area of my code that does stop naturally without a yiled
yield
So time won't advance because your code is the only thing occurring
If it's in an Update loop then it's called every frame, so just use an if statement
the Update loop is the loop, no need to nest another one in it
while (newSong == n)
{
newSong = Random.Range(0,3);
}
This is in the update loop
and succesfully stops
Sure, because its condition can end
However what was above was its own method for fading tracks
yea but in the method, Time.DelteTime is stopping?
it's condition relies on something within the loop
don't forget that Update is already a loop
Yea but the code i sent at first isn't in the update loop
its just a different method for fadingtracks
and it isn't called every Update?
if not, and it isn't from a coroutine, then it isn't going to do anything over time
Nah, its called every 5 seconds for testing purposes
so you do already have a loop
ah wait you mean it should do an entire fade every 5 seconds right
ok well, it needs to be able to do something over multiple frames
that would involve being in Update or a coroutine
otherwise you'd be doing the whole thing within a single frame, and that's not much of a fade, is it
yea makes sense
what in the hell am i looking at
yo chillll im new 😭
ah yeah in regards to that; whenever you have symmetric x1, x2 etc, it should be in some other structure
why are my code components greyed out?
Are there errors/warnings in the console or the inspector?
Yeah turns out i messed some code up
is there a way to make Awaitable.WaitForSecondsAsync() ignore timescale (can't divie by timescale because it needs to be 0)?
can't seem to find anything about it online
Seems like an oversight from Unity to not include a WaitForSecondsRealtimeAsync.
You can do is write your own async function that uses Awaitable.NextFrameAsync in a while loop until enough real time has passed.
couldn't you await Task.Delay in that case?
Task.Delay() doesn't work on web builds
straight up just doesn't
you should specify that you're using web next time then if you don't want solutions that won't work for the platform you are building for
i'd preferably like solutions that work for all platforms
well your only option then is what MentallyStable suggested and just loop until that time has passed
This should work.
public static async Awaitable WaitForSecondsRealtimeAsync(float seconds, CancellationToken cancellationToken = default)
{
float targetTime = Time.realtimeSinceStartup + seconds;
while (targetTime > Time.realtimeSinceStartup)
{
await Awaitable.NextFrameAsync(cancellationToken);
}
}
i see
hey i got a problem, I feel like it's very simple but i'm missing something, i basically have a button, and on this button i added a script called "HouseInfo.cs" which looks like this :
public class HouseInfo : MonoBehaviour
{
public void OnMouseDown()
{
Debug.Log("inventory");
}
}
and whenever i click on the button, it doesn't print inventory somehow ?
may someone help me on this problem please ?
OnMouseDown is called when game objects with colliders are clicked. And the colliders can't be triggers, unless Physics.queriesHitTriggers is true.
That's not correct for a button
You should be using IPointerClickHandler or just use the on click event on the button component itself
my Button is a prefab, and when i'm putting the script in his components it doesn't work aswell
@brave compass what do you recommend doing pls
PraetorBlue's answer is what I would answer. OnMouseDown is not the right event to use when using UI buttons.
so I need to have a Graphic Raycaster on the canvas if i'm using IPointerClickHandler ?
i just saw that on the doc
I think one is always added by default when you create a Canvas.
Hey guys, I'm not sure if this is quite the right place to ask for help with this but I'm trying to follow the unity coding tutorials and am on unit 4, I've just imported the tutorial assessts but they're all coming up pink? I think it's something to do with a rendering issue but when trying to swap the render I have no other options than what I'm using now. Thank you for any help
Unfortunately none of these worked for me, I don't have any of the options listed that they select on my edit tab or window tab
Your project needs to use the same render pipeline as the tutorial. Check what the tutorial uses and create a new project with that render pipeline, or convert the current one
oh mb the convertor only works for basic materials
i see here this is a custom material/broken material
its not likely gonna be easily convertable.. (you'll most likely have to try to chagne the shader to something that will work..) or recreate that shader somehow like in shadergraph
if u want it to just be not pink u can probably just use on of the basic Lit shaders
either under Standard> or Universal Rende> if ur using urp
ah true.. ^ try to stick with the same renderer.. it'd just be less hassle in the long run
I've managed to find out where I went wrong.... I had a old version of unity from 2020 being used instead of 6.1 😮💨
Thank you all for your help, I have learned quite a bit about rendering pipelines and the like and will keep it in mind if I ever independently work on a game :)
soo much more to learn about em if im being honest..
lots of things it includes heh
Seems to be the way of all things unity, never ending rabbit holes!
hehe.. u got the idea 👍
6.1 ain’t all that. i recently reverted
nothing wrong with it considering its the latest version and wrinkles will slowly be ironed out..
but yea comparing the newest version with an older more stable version doesn't necessarily mean its bad
It's perfectly fine for following along a beginner tutorial
ppl have unwarranted hate for 6+ for some reason 😅
#1 issue ive seen isn't b/c of the editor itself but b/c they defaulted to the new input system for Unity6 and almost every beginner tutorial uses the old
does the job.. but yea new system has lots of cool little perks
rebinding and multiple devices are why its worthy imo
much easier to do that stuff
and i guess action/event based inputs are better than polling inputs in general
I remember making a rebinding system with the old input system
Lost the original code
But i remember suffering to make it work
i could 💯 imagine
If I have started a coroutine and the mono behaviour was destroyed, is the coroutine stopped aswell?
yes, the coroutine kinda runs on the component
Are you 100% sure?
Coroutines are also stopped when the MonoBehaviour is destroyed or if the GameObject the MonoBehaviour is attached to is disabled.
MonoBehaviour.StartCoroutine
Thanks
this is also quite easily testable if you don't believe it
send the current code with the listed methods below 👇 and also explain what supposed to happen instead.
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
What is the actual question, I just see a mouse circling a skeleton
The enemy is walking around a certain patrol area and when it sees our player, it shoots, but when it sees the player, instead of breaking the loop, it makes a patrol movement and shoots when it comes in its way.
So, the issue that it's going back to a patrol right after attacking? What are you expecting it to do instead
Hitting the player kind of breaks the patrol
Don't stop following the player
In order to know what "breaks the patrol" means, you are going to have to say what you expect it to be doing instead
It certainly looks like it does, considering it turns around and goes the other way
yep
yeah what ? you just contradicted the issue you listed lol
In this episode we'll finally create melee enemies and ranged enemies. Then we'll add a simple patrol behavior to our enemies.
➤ Knight Sprite Pack: https://assetstore.unity.com/packages/2d/characters/knight-sprite-sheet-free-93897
➤ Starting Project: https://github.com/nickbota/Unity-Platformer-Episode-9
➤ Complete Project: https://githu...
I did it according to this video
You just said the Patrol breaks and follows player, but it looks its still Patrolling..
patrol is not broken i guess the translation is wrong
Let me explain again
The skeleton walks around a certain patrol point and if a player comes in front of it, it shoots, but when the player moves away, it continues to walk between patrol points instead of following the player.
well yes you worded it wrong the first time then
yes because
"Hitting the player kind of breaks the patrol
Don't stop following the player" is confusing if it showing it actually DOES NOT follow player
so you want to actually STOP the patroll and follow the player
now we need to see the code as was asked...#💻┃code-beginner message
I'm throwing the code
also is the video you sent do the behavior you want or is just something you trying to add yourself ?
read the** 📃 Large Code Blocks** section plz
sorry https://paste.mod.gg
A tool for sharing your source code with the world!
wait a minute
you have to hit save before sending the link, so it generates the link
copy code, paste it on the site, hit save send link.
A tool for sharing your source code with the world!
add myself
https://paste.mod.gg/sddvfcvmuqcc/0 attack script
A tool for sharing your source code with the world!
is this the only script ? certainly there is something more where is the player detection part
oh nvm..
this will require you to do quite a bit of work for the conversion, is there really no Follow part of the video series ?
first thing would be communicating to the move script that now instead of rightEdge/leftEdge you need to replace it with a target
Trying to get character to slow down and stop moving. I can use W to get them moving but it takes forever to do so, and I have to move the blend tree bar which it should juse be controlled via pressing the W key, and releasing to stop.
Can someone help? I've been working on this all morning and its so annoying
Like even taking my finger off the w key it still moves which Is not good
:/ I have a competition tomorrow, I don't know if I will make it
you need to start by getting your !IDE configured 👇 (then properly format your code)
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
well it would be possible but sounds like you don't know much about code this will be difficult to pull if in a day.. There is lots to unpack here
Yes, I don't know much, I'm new.
it may seem like "oh just switch it to this" but that does require a bit of base knowledge, mainly referencing and a basic state or even statemachine perhaps
first would be making such a boolean like IsFollowingPlayerTarget or something, then you would use that to change the patrol behavior.. Or use a condition when player is detected to just switch the Patrol move script to a Follow Player script which you can code seeprate to make it a bit easier
Actually this system is not a big problem for this skeleton but since I did not have time I copied it instead of a separate intelligence and made it a boss by only changing the appearance, so the boss works with problems.
idk what " boss works with problems." means in this context
problems is pretty vague
send video wait
I followed the guide but I couldn't find the common7/IDE or any
Folder for visual studio just the .Exe
you realize you have VSCode and not Visual Studio right?
Everything is the same except the animations.
well not only did you follow the wrong guide considering you are using vs code and not visual studio, but that part of the guide is usually unnecessary
If you need to link the exe manually you did something wrong in the setup, a properly followed setup would show the IDE in the dropdown
No I didnt. I am just learning still and only been doing it for a week now
Okay then I need to install visual studio?
did you not notice that the logo icon did not match the one you were using when another one did?
if you want to follow the guide for visual studio, then yes you'll need to install visual studio.
should look like this when properly configured
Notice it will show the VSC version and the VIsual Studio Editor pakcage "enabled" then you can see all your Unity classes etc.
Not really
you should try paying attention to what you are doing/reading then
why not look up how to do a 2D sidescroller follow player type of meachanic and switch out the script from patrol move to follow player when player is detected ? this will probably be the most straight forward way you can do this
this way you dont have to worry about a statemachine or anything just yet
Alright well my bad
I searched for many resources but couldn't find any, I don't think I have much time to make it from scratch right now.
This is something i find hard to believe, i been through thousands of resources and they do indeed show this
idk where you got that "couldnt find any" from
I searched for a YouTube video but when I tried it was broken
I don't have much knowledge so I guess I won't be able to solve the problem.
tbh this is how they say "skill issue"
its most likely the video was fine and you just copied / followed it wrong due to lack of knowledge of what you're copying in the first place
hello i am currently moving my player with transform.Translate
Is it better to use FixedUpdate or Update ?
I don't think so
eh if you want collisions to work properly, you should not use Translate in the first place
Update, since you wouldn't have any interpolation
but generally there are better options than transform.Translate
i know but it will be a mobile game without rigidbody so i think i will be ok (and every collision will stop the game 🙂 )
ty
how do you plan on detecting collision to on obstacle in the first place anyway ?
those usually require 1 rigidbody
OnCollisionEnter()
see message #💻┃code-beginner message
ohh
You would get a more accurate result if you use Rigidbody on player then move with .linearVelocity in FixedUpdate
Trying to scale a cube with some input and a method. What's gone wrong here?
i never understand how to make it properly with rigidbody (with addforce if i remember correctly) There is always something who dont make my playerMove smooth
like the mouvement is ok but when i jump he is too slow or something like that
then you are not doing it right my buddy
with .linearVelocity you get a closer result to Translate because it ignores mass and acceleration/friction
unlike AddForce's default mode
Oh ok i will look at this
You should convert the input field text... Not the field itself
And use the Parse() method instead
TryParse to cover all weirdness
I'm using input legacy
not tmp
ohh right Im blind mb
bwt If you use TMP_InputField the component can actually use Regex / Set the field mode to only accept numbers
you should do Debug.Log(input.text) and see what is actually getting in that function
also i would do TryParse
bool success = int.TryParse(myValue, out number);
if (success)
{
Debug.Log($"Converted '{myValue}' to {number}.");
}
else
{
Debug.Log($"Attempted conversion of '{myValue ?? "<null>"}' failed.");
}```
it works 😍
but still don't understand the error
Changed from empty string to a "1" and it fixed it
Thanks
Because "" is not a number
I tried to use tmp input field but didn't know what it was called
I can't believe it was that simple
you can prevent player from passing in any letters just incase
otheriwse you need to gracefully handle those edge cases
You still need to check for empty string though. Blank is a valid entry for an input field with this set but still isn't a number
This is the mess I created yesterday trying to do the same thing
What's the error say
yea your code is very brittle right now @open apex
any wrong input and everything breaks
i spent so much time trying to find how to make my player move with addForce and the solution was only LinearVelocity 💀
I gave praetorblue so much headeache for this yesterday 😭
well different methods used for different purposes 😛
sent him this and he was bamboozled
also Console.ReadLine doesn't work in Unity lol there is no Console to read input from
yeah 😔
that was me yesterday
I can feel the evolution
Okay I have the right version with visual studio 2022 but I still am having issue with the code itself. Its like the character continues to move even when I take the finger off the W key when they should be stopping
from caveman to the stone age
wdym "the right version with visual studio 2022"
can you show its configured then cause now you switched IDE
do note a configured IDE is required before you get help here thats why its usually best to take care of that first
I set it to be configured for game development in unity added it to unity from the external tools.
the word "show" is very important here
Show where exactly?
okay this show partially what was asked sure, what about the IDE itself, does it say Assembly-CSharp
see: 👇
that arrow chef kiss
quick hint , if you click that Yellow BroomSweep icon to properly cleanup / format the code
the indents look wonky and hard to read
^-- <insert crazy arrow>
i just Ctrl + A, C, V
didnt even know that was down ther 😄
Yeah it still didn't work the character model keeps moving even after letting go
Of W
well yeah this wont magically fix any bad code / logic but at least its configured properly
Lmao I am
Following a guide to figure this out.
Can you like give a quick rundown / recap of the original problem
Its like the character continues to move even when I take the finger off the W key when they should be stopping
what makes you believe this? can u show the code that supports that statement?
Essentially the character is supposed to move progressively accelerate on the velocity of the blend tree from walk to run by pressing W.
When I let go of W it should progressively decelerate and stop
deceleration is a positive value , how is velocity supposed to go down or am i missing something ?
whats =+ ?
+= and =+
thats why i genuinely asked what it was
lo
Hi, confused regarding what the 0 here does?
u might want to expose ur velocity variable in the inspector
just to take a gander at the values u have
it does "being a 0"
cuz it's seeing it as velocity = +Time.deltaTime i guess?
it makes it a Vector3... by putting a zero in the Y place..
Vector3 (x,y,z)
Ohhh weird.. I never seen =+ before I suppose yea
Turns into a 0 + X operation
ya me neither lol.. learn something new everyda
so what's the point of "vertical"? that is what I am confused about, horizontal is x and vertical is y
ohh I understand now
vertical in the input terms is forward and backwards on the joysticks or W and S on the keyboard..
nvm
isn't vertical for y though?
W and S be forward and backwards.. hence being applied to the Z
WHy are they making use of it for z?
depends on what ur using it for..
because thats back and forward in 3d
"Vertical" is an input axis that maps to W/S and Up/Down arrows. it has nothing to do with X Y and Z, it's just an input axis named vertical
thank you 🙂
I know..?
according to your question you didn't know
- 0, Vertical, Horizontal
- Horizontal, 0, Vertical
- Vertical, 0, Horizontal
- Horizontal, Vertical, 0
- Vertical, Horizontal, 0
- 0, Horizontal, Vertical etc
its the default name Unity has given it in the Input Manager
i tried to get em all
you could've called it "FlourBruth" in Input manager in Unity project settings and it would work the same as its mapped to specific keys there
can you theoratically add movement to the player without use of AddForce? as in
keyPressedDown = x axis + 0.1 every 1 second
yes.. u can set velocity directly..
CC's have a Move() function that takes a vector3..
u can do it in there as well.. (input * speed * time.deltatime) for ex
sorry for being uneducated but what is cc?
character controller
all those functions do is basically move the transforms after it did the physics movement
its a unity component that makes building a character controller easier
if you moved transform directly its basically teleport and you skip through walls / collider and anything physics related
so it's already in place we can just make use of it instead of writing it ourselves?
This is the other persons code and this is mine
yea.. u still have to write code for it.. but all the necessities are there..
thanks guys
Character Controller is a component from the original PhysX (physics engine) , unity has just adapt it for use in their API
continue on ur journey 🫡
so far so good
yea see
this makes sense to me
+= for go..
-= for slow..
yes notice the very big difference in operators lol
what u have is odd lol
Its odd?
if you were to use += still for deceleration, you need deceleration constant to be a - number
but -= is more straight forward
in the context yes..
like the code says and like we've said..
its -= and u =+ which i'd never seen b4.. had to have someone chime in to even know what it was.. but if ur trying to copy the code from the tutorial 1:1 what you have is odd yes.. and incorrect
velocity += acceleration;
velocity += deacceleration;```
So that += can cause it to not respond to the deceleration of velocity?
look at ur code brother
"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 185
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2025-05-12
omg "code literally did not exist"
those bottom two values are slow as molassis lol
Okay well its now:
velocity = - Time.deltaTime * deceleration now)
And it still didnt work
still wrong..
omg..bruh..
🤦♂️
operator dislexia
u either use a += and a negative value for deacceleration
or u use -= with a Positive value for deacceleration
"Equals negative x" and "minus-equals x" are not the same thing. You literally have the answer in front of you, look at the tutorial
📌 and really important note here: += is not the same as =+ and -= is not the same as =-
the tutorial has it correct..
just gotta manage to carbon copy it over to ur side somehow
Hello again 😉 so i used linearVelocity but its weird because when i put contraints on the x and y position ( my player move on the Z axis) it will work only if i uncheck the Y contraints and also my player get slower when he is on the middle of the map and when i go to the maximum position ( on the Z axis) he will not stop and idk why because it was working when i was using transform.translate 🥲
{
private float lineLimit;
public float speed;
private Rigidbody rb;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
rb = gameObject.GetComponent<Rigidbody>();
Debug.Log(Screen.currentResolution.width);
lineLimit = Screen.currentResolution.width / 2;
}
// Update is called once per frame
void FixedUpdate()
{
if(Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if(touch.position.x > lineLimit && gameObject.transform.position.z < 4.7f)
{
rb.linearVelocity= new Vector3(0, rb.linearVelocity.y, speed);
}
else if (touch.position.x < lineLimit && gameObject.transform.position.z > -4.7f)
{
rb.linearVelocity= new Vector3(0, rb.linearVelocity.y, -speed);
}
}
else
{
rb.linearVelocity = Vector3.zero;
}
}
}```
I can't quite follow what your issue is but your code will only stop the object when you are not touching the screen. Until you release, it's going to keep going
I edited it but it still isn't working
the velocity is indeed working tho
It seems to be working just fine, the value is increasing while you hold the button and decreasing when you're not
i see it 👀
What are you expecting to happen that isn't?
blendtree <- i believe
Looks like the blend tree's threshold is 1, so it would need to actually reach that value to change
you literlly have no IDLE pose ?
what to do when speed is 0 ? what animation is supposed to go to for stopping
I do have a idle pose but it didn't say to add it to the tutorial
could you send the tutorial rq
Learn how to animate characters in Unity 3D with dynamic animations from blend trees!
This beginner-friendly tutorial is a complete walkthrough of one dimensional blend trees and how we can use blend trees to create new animations for our characters using float parameters
ACCESS PROJECT FILES & SUPPORT THE CHANNEL:
💛 https://www.patreon.com...
Yeah, this does explain how to use a blend tree, but, again, what's the thing you're expecting to happen that isn't?
Is this basically this?
It should show the character being able to accelerate presses W and lets go of W decelerates.
Unless I'm missing something
Transform based movement is teleportation. It will move the character but it's not going to respect any sort of physics or colliders
Your blend tree settings look like they're set to go from 1-2, in your video you stopped it at around 0.3
yes I have been told that, but is this correct?
Run the code and see
You can check to see if it's doing what you want
Its just strange his moved so fluidly, while mine takes a long time to start accelerating. Also the character starts to stop accelerating around 1 in velocity and stutters @polar acorn
You are controlling the wrong value here..
like i have to change linear velocity and velocity in the same time ??
the Blend tree value is "Blend" but you are controlling "velocity" they are different parameters
Show the settings of your blend tree, it's cut off in your video
I don't know why you sent a video instead of a screenshot and then didn't even show your blend tree settings in the video
this is not even close to the oirignal video..
you added transitions when you can do it all in the Blend tree
Your blend tree is "Blend" parameter, yet ur controlling transitions with "velocity"
considering you messed a -= with =+ you seem to have a" copying exactly as is " issue lol
then wonder why it dont work right :]
its all very confusing at first sure, the video is showing you exactly how to set it up though.. you added some extra stuff on your own, before you try things on your own you have to understand what each thing does
The video goes into deep detail about all those boxes. So, right now, your animation will blend between Walking and Running whenever the parameter Blend is between 1 and 2
Now, is the parameter Blend ever between 1 and 2?
Hello 🙂 i solved my problem with contraints but my program who block the player when he go too far still dont work
{
if(Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if(touch.position.x > lineLimit && gameObject.transform.position.z < 4.7f)
{
rb.linearVelocity= new Vector3(0, rb.linearVelocity.y, speed);
}
else if (touch.position.x < lineLimit && gameObject.transform.position.z > -4.7f)
{
rb.linearVelocity= new Vector3(0, rb.linearVelocity.y, -speed);
}
}
else
{
rb.linearVelocity = new Vector3(0, rb.linearVelocity.y, 0);
}
}```
"who block the player when he go too far" sorry what ?
Using 1 for walking and 2 for running the character is just nudging now
gameObject.transform.position.z < 4.7f
ohhh you want to clamp his movement
I'm on a mobile rq so can't analyze the whole thing but first make sure your conditions / values are what you expected them to be.. Use Debug.Logs also you might need to clamp a seperate variable
yes it was working before i changed transform.translate to rb.linearVelocity
I have no idea what you mean by this. A blend tree will mix between two animations based on a parameter. If your parameter named Blend is between 1 and 2, it will mix between your Walking and Running clips.
is it due to fixedUpdate ??
So, what is Blend? Is it between 1 and 2?
it should technically work similar, i still wouldnt grab input of touch in FixedUpdate and keep it in Update , only rb movement should generally be in FixedUpdate
like rb.velocuty = or addforce
Blend is always 0, which is not between 1 and 2
So it will always be playing the Walking animation
If the value is less than your first threshold, it will play 100% of the first clip. If it's higher than the last threshold, it will play the second animation. If it's in between, it will blend.
The tutorial is very clear on all this, if you actually listen to what it has to say instead of finding code to copy paste out of it
I have been rewatching these videos to understand it
It's legitimately one of the best explanations of how a blend tree works on the entirety of the internet
Alright I'll rewatch the video.
So, knowing now what all these boxes mean, what are you expecting to happen that isn't? Because it seems like it's doing exactly what should be expected
The walking should accelerate to running more easily. It feels like its stuck in walking
Well, yes. Because your blend tree is set to transition from walking to running as your parameter Blend goes from 1 to 2. You can look at the value and see that it remains firmly rooted at 0
0, being less than 1, will play only the Walking animation
I thought you said blend is always 0?
It is, and I just repeated that one second ago
You can look at the value and see that it remains firmly rooted at 0
Your blend tree will transition between Walking and Running depending on the value of the parameter you've chosen, Blend. If Blend is less than the threshold of Walking, it will play Walking. If it is greater than the threshold of Running, it will play Running. If it is in between them, it will play a proportional mix of the two (so, halfway between the thresholds means halfway between the two animations)
Knowing this information, look at the values you have selected for the parameter and the thresholds. Do they make sense
What parameter and thresholds do you actually want to use
does something who execute like an update but before update exist ?
Chances are, if you need this, you're doing something wrong
I wanna blend those togrher but I don't understand what numbers I need to do that now. I'm a bit confused on that part, but I understand the rest I think.
when all the code is in fixedUpdate it wont clamp my player and if i put in update it will clamp only if i stop pressing the key so if i hold my key my player wont stop 🥲
public class playerMove : MonoBehaviour
{
private float lineLimit;
public float speed;
private Rigidbody rb;
bool right = false;
bool left = false;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
rb = gameObject.GetComponent<Rigidbody>();
Debug.Log(Screen.currentResolution.width);
lineLimit = Screen.currentResolution.width / 2;
}
// Update is called once per frame
void Update()
{
if(Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if(touch.position.x > lineLimit && gameObject.transform.position.z < 4.7f)
{
right = true;
}
else if (touch.position.x < lineLimit && gameObject.transform.position.z > -4.7f)
{
left = true;
}
}
}
void FixedUpdate()
{
if(Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if(right)
{
rb.linearVelocity= new Vector3(0, rb.linearVelocity.y, speed);
right = false;
}
else if (left)
{
rb.linearVelocity= new Vector3(0, rb.linearVelocity.y, -speed);
left = false;
}
}
else
{
rb.linearVelocity = new Vector3(0, rb.linearVelocity.y, 0);
}
}
}
I just explained what the numbers mean.
You have parameters in your animator. They're just variables you can set in code.
The box at the top of the blend tree is which parameter you want to read.
The threshold values determine which clip is played based on that parameter.
Less than the first threshold = play the first clip entirely
More than the second threshold = play the second clip entirely
In between = blend the two animations
Velocity remains at whatever you last set it at until you change it or some other force slows it down. The only thing in your code that will ever change velocity to 0 is when Input.touchCount is 0. Nothing else will ever stop it
If you want it to stop when it's at a specific position, you will need to tell it to do so
Simply "not changing the velocity" does not stop the object. You have to set it to 0
Does this make it so it respects physics and colliders (adding rigid body)
Okay I figured it out
This one will exert forces, but by directly manipulating the position instead of using velocity or forces, it won't respond to any. For example, getting hit by a fast moving box going the other way isn't going to actually move it, it's going to set it's position to the new location. This can be a desired outcome, and is commonly used for Kinematic Character Controllers.
Would this be ideal for 2d smooth player movement (or not)?
¯_(ツ)_/¯
What's "ideal" for movement is going to be entirely up to you
There isn't one "best" way to do movement
ideal for me is smooth movement
player stops moving when the getkeydown a,b,c has stopped
What's "smooth movement" is going to be entirely up to you
Hello everyone!
I'm currently trying to the cop car ai's less...messy? Honestly i just want him to spawn in paralel to the road (in this case it would be 270 on the Y axis)
Here's the code if you'd like to have a look: https://paste.mod.gg/qetzkovooluv/0
A tool for sharing your source code with the world!
I don't mind if the cop car throws himself out of the road once in a while but every time right after spawning is definetly not ideal.
I tried forcing its spawn angle, limiting its turning angle and turning speed but nothing quite fixed it.
don't crosspost
Do you have Cinemachine installed
[apparently](#archived-code-general message) , probably best continue the one in #archived-code-general ig
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
hello, i'm trying to refactor my code from this
{
void Interact();
bool CanInteract();
}
to this
using System.Collections;
public interface Interactable
{
IEnumerator Interact();
bool CanInteract();
} ```
but the use of yield returns seems to break my logic, so im just trying to wrap my head around best practices for a IEnumerator interface
```cs using System.Collections;
using UnityEngine;
public class Chest : MonoBehaviour, Interactable
{
public bool isOpened { get; private set; }
public string ChestID { get; private set; }
public GameObject itemPrefab;
public Sprite openedSprite;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
ChestID ??= GlobalUtilities.GenerateUniqueID(gameObject);
}
public bool CanInteract()
{
return !isOpened;
}
public IEnumerator Interact()
{
if (!CanInteract()) yield break;
OpenChest();
}
private IEnumerator OpenChest()
{
SetOpened(true);
if (itemPrefab)
{
GameObject chestItem;
yield return chestItem = Instantiate(itemPrefab, transform.position + Vector3.down, Quaternion.identity);
}
}
public void SetOpened(bool opened)
{
if (isOpened=opened)
{
GetComponent<SpriteRenderer>().sprite = openedSprite;
}
}
} ```
No idea what that yield return is trying to do
ya finally figured out teh key it wanted
that doesn't really make any sense
im just trying to get a generic interface, so that when i say add quests or chocies its flexable
What are you actually trying to do with those IEnumerators
im just trying to get a generic interface, so that when i say add quests or chocies its flexable
So... what are you trying to do with the IEnumerators
Why are they not just functions that return void like your original interface
make a dialog system, make an encounter system, make an interactable system, make a party syste, make an inventory system, make traps, make cutscenes, maybe make a shop?
Okay, but, why are they IEnumerators
... because i want an interface that can go though the elements of the various different collections i have?
Okay, so you intend to use them as an iterator to build up a collection? Not a Coroutine?
i'll have coroutines too, its just im trying to refactor what i have to make it more robust, should i have been using a coroutine in the code i gave?
If you intend to use it as a coroutine, you need to run it with StartCoroutine. If you intend for it to build up a collection, you would yield return one individual element of the collection
And then do .MoveNext() on the IEnumerator to get the next thing in the collection
These are pretty different use cases, highly unlikely that you'll ever be doing both with the same interface
and startcoroutine needs a return type?
StartCoroutine returns Coroutine
{
if (!CanInteract()) yield break;
StartCoroutine(OpenChest());
}
private void OpenChest()
{
SetOpened(true);
if (itemPrefab)
{
GameObject chestItem = Instantiate(itemPrefab, transform.position + Vector3.down, Quaternion.identity);
}
}
right so this doesnt cut it
You need to pass an IEnumerator to the coroutine
Before you were calling it like a normal method but it was an IEnumerator.
Now you're calling it like an IEnumerator but it's a normal method
right
{
if (!CanInteract()) yield break;
StartCoroutine(OpenChest());
}
private IEnumerator OpenChest()
{
SetOpened(true);
if (itemPrefab)
{
GameObject chestItem;
yield return chestItem = Instantiate(itemPrefab, transform.position + Vector3.down, Quaternion.identity);
}
} ```
but i still cant open the chest
For a coroutine, that yield return doesn't really make sense
In a coroutine, the yield return is basically the "Wait condition"
default being yield return null which will resume next frame
ya its not working still, how would i structure a coroutine to Instantiate an itemPrefab and flip a sprite to open?
Why would that need to be a Coroutine? What are you waiting for in it?
because otherwise i'm making two different interactables and isn't the point of this is i only need one?
I'm still not sure why these return IEnumerator. What were you trying to do that couldn't be done with a normal method?
its a matter of putting everything under the same interactable interface
What does that have to do with coroutines?
And what are you intending to do that would require an IEnumerator
they're a part of IEnumerable?
But what does that have to do with your interface
move, display text, pull up an invetory item for a relavent fight?
Okay, and what are you intending to do that would require an IEnumerator?
i'm trying to refactor my code
Let me rephrase this:
What do you think returning IEnumerator does?
This line:
yield return chestItem = Instantiate(itemPrefab, transform.position + Vector3.down, Quaternion.identity);```
Is showing me that you are probably confused about how coroutines work. Because it's pointless for this to be a coroutine and it's pointless to `yield return` this object
an interface that allows you to iterate the elements of a collection ?
Right, so why are you making something an iterator? What is the point of doing so? Where are you actually using any of the features of IEnumerator
What is the purpose of this function? What do you want it to do?
ok let me ask you this, would you make a pokemon game in unity withOUT Ienumerator?>
k wrong person
Yes, easily
You could probably use coroutines somewhere
your SCRPTABLE OBJECTS?
What do any of those have to do with IEnumerator?
I really don't think you fully understand what this return type means
You seem to be dead set on returning it and have provided no reasons to do so
Why do you desperately need to be able to do foreach(var x in OpenChest()) somewhere?
that's a really weird question
that's like saying "Would you make a house without torx screws?"
Maybe?
THATS WHAT IM TYRYIN TO REFACTs
So, you want to iterate over this function in a foreach? Why?
no i am tryin to move AWAY from taht
Then why the hell are you making your functions IEnumerators
Either they're Coroutines or iterators in a foreach
that's what IEnumerator does
and you don't wanna foreach them, and you don't have any wait conditions
so what is the point
the point, is i am trying to make a game, this game will have a bunch of interactables that will do EVERYTHING YOU CAN THINK OF. and you are telling me, once again, taht everything i am trying to do beyond basic fucking if statments is wrong and this si not the way to do it
jesus christ chill
have you conisdreed, foir opne fuckiing second that peopl,e come here to fiugure out how to do thigns RIGHT?
So, without just stating the definition of IEnumerator, what problem are you expecting this to solve? In terms of actual game interactions and normal english words, what are you intending IEnumerator to do
I told you how to do it right, and that there seems to be no reason to use IEnumerators and you've fought me every step along the way
and can't explain why it has to be one
i dont know how muc more basic you want me to get then i want to make unicorn overlord
The solution is: Don't return IEnumerator. You aren't doing anything that needs to return IEnumerator
So don't
It's a tool that does not apply to the things you say you're trying to do
so there is no point to do it
ok so if you don't understand it, don't use it randomly hoping it'll stick
so then mr expert wehat IS the point of Ienumerator?
I'm asking you, what problem are you trying to solve with IEnumerator, because none of the things you've described are things that would warrant it
I told you, to make it so you can iterate over a function, or as a coroutine
Both of which you have said you don't want or don't need
read my chat again i WANT coroutines
Then what is the wait condition you want for your function
the rest, yes i am trying to figure out and notjhig that has been said HERTE has been helpful
What is your function waiting for
for the chest to open and the item to spawn
Does that actually take any time?
Spawning an object does not take time
Changing a sprite does not take time
They're all synchronous
So, why is it a coroutine
You don't just change code for no reason, you identify a problem, and do something that gives a solution. Right now, you don't seem to have a problem
We still haven't seen this interface
you haven't?
And that doesn't explain why OpenChest needs to be a coroutine
We have, it was at the top of the monolithic post they made at the start:
public interface Interactable
{
IEnumerator Interact();
bool CanInteract();
}
Ok well I didn't see it till now, no
becasue my singalton dialog manager uses this
Uses what
A tool for sharing your source code with the world!
so im confused what the disagreement is here
at some point in the chain of code you'd want to actually yield return some kind of actual YieldInstruction
Yes, this contains many coroutines.
These coroutines properly have wait conditions
I think demonicArbitror just hasn't managed to ask the actual question they want the answer to here - which is probably something like "How do I make this coroutine happen over multiple frames and some period of real time?"
So, what does that have to do with this interface?
interfaces have DIALOGH TEXT?
I have been trying to ask them what they actually want to do but I keep getting "YoU cAnT mAkE a GaMe WiThOuT iEnUmErAtOrS"
What?
so right now you have 2 detached coroutines, that's unnecessary
you could choose to either centralize it, and have Interact be the only coroutine or have both be coroutines where Interact yields OpenChest, or not, and have OpenChest be the only coroutine
which you choose depends on where you need the control over the coroutine
suppose you need to stop the coroutine, would that be from the thing calling Interact or the thing defining OpenChest?
actually i was just asking about refactoring from a void to an ienumerator becasue i wanted to tie all my syustems together
Are you trying to start a coroutine from the function this Interface defines?
but nnonoooo Im DOiing It WRong
ok well "refactoring" a return type doesn't really make sense..?
and you haven't explained why
this isn't a "refactor" kind of thing
do i need to define REFACTORING to you?>
this is a "radical change in functionality" thing
this comment here explicitly says you want to move away from ienumatiors but now your saying your asking about moving to them?
no, we all know what it is
refactoring is making a code yield the same result with a different process
this is not that
Not however you mean it, because completely upending the functionality of your interface to make an iterator you don't want to iterate through isn't what I'd call refactoring
then what IS it because it lookms liek that to me
you want to make a synchronous system, asynchronous? that's not refactoring
Which is why I am 100% sure you have no idea what an IEnumerator is
that explicitly changes the behaviour
greatr you figure out why im in thbsi fucoiing discord
Which is why I continously ask what it is you're trying to accomplish
because this solution does not solve the problems you have stated
So I'm confused why you're insisting on doing it
"Hey man, why are you standing in the snow in your underwear with a pickaxe in your hand?"
"I'm trying to bake a cake"
do you have a reason, one that would be apparent in the resulting behaviour, to use coroutines? think about that
The thing you've said you want to do does not follow from the thing you're trying to do to do it
"hey man im trying to refactor this code tom amek a better game" shits words in my mouth
Are you actually here for help, or for an argument?
ok, so making everything a coroutine doesn't automatically achieve that, see link above
Why are you trying to change your perfectly functional interface into an iterator
What is the point of iterating this function
What goal is it intending to accomplish
An IEnumerator is not "Better code" that is a goal in and of itself
help would be nice but @polar acorn cant seem to check his ego
then ignore him, you still have plenty of questions to answer
This isn't an ego problem, I solved your goddamn question an hour ago
@echo cradle go give this a read
The answer is: "Fucking don't"
think about what you're trying to achieve with making everything a coroutine
There's no reason to make these functions IEnumerators
no man your being shockingly rude and childish in general
my goal, is get an inventory system, a collsion system, an ineractable system, a dialog system, and game all wrking together
and are they working together?
why do you think im here?
Okay, cool. Your original interface does that just fine
What is the problem with it
What does making it an iterator actually do to move towards that goal
good, then you've found an issue!
that's not equivalent to "i want to make everything a coroutine"
go dig into why exactly stuff doesn't work together
Then maybe describe the actual problem.
again, go read about X/Y problem
once i've stopped fighting with @polar acorn , maybe
I have been begging you to describe the problem and you just fucking won't
if you don't like the interaction, block him and answer everyone else's questions
ive been descripbing it in a bounch of differente ways, none of them seem to work, much like my code
if you keep insisting on fighting with digiholic, then it really does seem that you just want a fight
And I've told you none of what you've described requires anything to return IEnumerator. So just, don't do that
at this point its more of a problem with the 'your doing it all wrong' attitude thats pissig me off
then ignore it
you have actual issues to solve, don't you?
the block button exists for a reason
use it
so we can all move on
the block button blocks possiblilites
i mean, it doesn't actually fully block, so not really
Is your code doing what you want?
If no, then I'd say you are doing it wrong and I'm trying to explain how to do it right but you won't fucking tell anyone what you want to do so no one can help
... you HAVE heard of growing right?
Buddy are you drunk
yeah no clue where you're trying to pull this but it isn't going to be productive lmao
right, i was clearly in a X/Y situation as whoever outlined
What are you even talking about
no i have fury
get that checked
it's not gonna make you more productive
and honestly, it's gonna make everyone else not want to help you
hmm anger does give motivation,m it jsut lacks focus
Which is why I tried to get you out of it by asking what the fuck you were trying to accomplish with IEnumerator. Literally my first fucking question was an attempt to ask your problem instead of your proposed solution
So basically, you have interactions that need to wait for some time(for an animation or something to complete) and you decided that you need coroutines everywhere for that?
anyways, are you gonna ask about your actual issue now
rather than stepping aside and trying to make everything a coroutine, seemingly for the sake of it?
or at least a 'standard approach' to the various different systems i want to implement
your systems aren't working together, so find out why
...a standard approach in.. game design in general? yeah that's not really a thing
right what im trying to say is i want one interactable button, and for it to access all these different systems though one common interface?
was that better?
sure, didn't you already have that though
In C# the standard way to do this is async. This allows you to make methods that would wait for something or execute something in the background. But there are many other ways to do it, like callbacks for example.
what was the issue with the old system?
Okay, and why does your initial interface not already do that, but the new one does?
How does your "refactor" actually work towards solving that problem?
because i want to weave in things like the dialog system and other animation based systems, so doesnt my 'interact' need to be an ienumerator for that or else ill be using multiple different interfaces?
What makes you think that it needs to be an ienumerator?
because the dialog system is and i get compiler errors otherwise?
Provide one specific reason with code example where it has to be an ienumerator.
A function does not need to be an IEnumerator to start a coroutine
How about you show the actual error
Because you can 1000% call any of the coroutines in dialog manager without needing to be an IEnumerator
And it seems like you messed up the syntax and assumed that meant you had to basically turn your entire project into coroutines instead of trying to solve the original problem
Which is literally what the XY problem is
heres an old project with the old input manager, it got the interactable from the opposing collider, i dont know if it HAS to be an ienumerator but this is just what i ended up doing https://paste.mod.gg/sxxjhtririys/0
A tool for sharing your source code with the world!
as for teh actual error my codes a mess after trying to refactor it today
Version control
Not to be that guy but not sure how keen the server is on messing with pokemon fangame projects, might fall under modding type territory
one man show, but ya for days liek this it would be nice, w/e its like 4 scripts
most solo devs still use version control
Doesn't matter. It's to keep your changes organized and backed up.
Do you know what "refactor" means?
How to play a anim from its beginning every time. Here is what I use but it doesnt restart it if it is already playing hitEffectAnim.Play("effect");
yes i faield to refactor, happy now?
he asked for an exampel that was teh one on hand
you keep using the word, I'm only wondering what you think it means
Refactoring is the process of improving the internal structure of existing software code without altering its external behavior or functionality. because i got in a fight with someone's ego today it failed. any more questions?
my 'productive day' went out the window as soon as i had to ask for help here
If your not in a productive mindset it's going to be very hard for anyone to help you regardless of your personal perception of their ego
going back and reading, it appears like you were offered a lot of people's time to try and help you
It just comes off as very combative
There's no reason whatsoever for the Interact method to be a coroutine. It doesn't do anything at all here.
And to think it could have been productive if you had just actually provided context the first time when asked, and believed people when they said it didn't need to be an IEnumerator
You, in fact, already had the working code all along
i mean isn't a requirement of refactoring means you already HAVE working code?
Yeah, and it also means not changing the functionality of it into one that does not for no benefit
right, it was jsut like that there because everything was an ienumerator in that example. im just looking for a clean way to implement an interface taht is scaleable to my wims
What you started with was perfectly scaleable
then lets hope tomorrow my questions are something different.
id suggest trying to plan the question, figure out the best way to explain your goals and what you have
It'll be the most productive way for anyone to help you
thought i did today burt clearly, i need to look into it
its a skill that takes time to develop!
I assume that the reason this is a coroutine is because some of the interactions are actually doing something over time.
In this case, I'd have a whole interaction queue system on a character that can keep track of current interaction/s and update it correctly. Instead of just making the interact method a coroutine.
I'll sometimes draft questions in notepad, write all the details out, and then I think if there's a better way to phrase what I've got
yes that's why its like that, but in my current project i haven't have any animations yet. i was just trying to get everything set up. sorry i jumped the gun on ienuerable
ok actually thanks becasue my next questiojn was handling multple ineractables in range
A project I'm working on now had something called actions queue. There are different actions in the game, like sleeping, sitting, opening doors, crafting, moving items between inventories, etc... And the characters are controlled by ai mainly so they need to be able to queue many of this actions in order or parallel. Which is why there is a state machine on each character that handles queueing, executing, updating, finishing actions. All of this is done via the update, so no coroutines involved. This is the simplest setup you can have without complications.
Some actions would execute immediately, some wait for an animation to complete. This is all handled during the action update.
And interactable objects just provide the character with the required action. They don't handle the logic of the action(though some actions might call on some of the object's API).
What type is Action in that implementation?
They all extend an abstract plain class CharacterAction.
Heard, whats your method of providing them an update loop?
They are updated from the mentioned state machine on each character.
From character update loop
Ah nice
bumping this so it's seen.
What are you trying to play? Is it a state in the animator?
So, the state machine holds a reference (or is passed a reference) to the current action, and within its Update the state machine executes the current action's Update?
I guess state machine is not entirely correct way to describe it. It's a class that has a queue of actions. Basically in encapsulates the logic of queueing and updating actions. The character just calls enqueue and update methods on it. The "state machine" checks if there's a current action, updates it and handles finishing it. If there's no current action it dequeues the next action assigns it as the current action and repeats.
The character class itself only holds that state machine reference. As well as a planner object reference. The planner generates several actions and passes them to the character for it to enqueue and execute them. The code is still a bit sloppy, but it took me several iterations to get here, so I'll just keep it as is for now.
I'm not sure if this is where I ask but I need help. I have a tile moving script, except my character would slightly move and offset their path when I try to collect an item, I'm guessing it has something to do with the Rigidbody on the item, does anyone know a fix?
What is the desired behavior?
And what do you mean by "tile moving script" and "offset their path"
whose path?
Nah, that's pretty cool. It's always nice to see how others implement or build a system/mechanic . . .
The players path
Presuumably your player is colliding with the item
So make the items use trigger colliders instead maybe? Hard to say as you have given very little detail here.
When the player collides with the object, it's meant to go into the inventory, just as it goes in and deletes itself, if slightly pushes the player off of the middle of the tile
It's 2d btw
They just explained above how you can fix the issue . . .
yep, refer back to #💻┃code-beginner message
I'll give it a try, but I'm pretty sure it didn't work originally
Yea, it won't go in the inventory now
I mean, trigger colliders work in general, so it would have been a problem with your implementation. if you have a question about a specific implementation not working feel free to share the details of what you tried, including code and how you set the scene up.
i.e. did you actually switch to OnTriggerEnter2D instead of OnCollisionEnter2D?
Oh
A trigger collider does not physically collide with the object. It's a trigger zone. You need to change how the object's collide with each other since you are using a trigger collider instead of a regular collider . . .
I'm applying a texture to a plane, and i want to use alpha clipping to remove the white
i set the material to cut out mode, but no matter what i set the alpha cutoff slider to, it doesnt remove the white
am i misunderstanding something?
alpha cutoff clips pixels with low alpha
not white pixels
Make sure your texture has an alpha channel and is configured correctly in the importer
You want "alpha is transparency" checked
Also the image needs to actually have those transparent pixels
hm, in the tutorial i was following, they had a texture with a white background
does it need to be a texture with a transparent background? (but then what's the point of turning the transparent part of a texture transparent?
I have no idea what I'm looking at but yes it needs to be transparent
leaf texture with a white background
what's the purpose of alpha clipping then?
is it to prevent a square shaped texture with transparency from say casting a square shadow?
Again alpha cutoff for cutout shader only works with the alpha channel
it clips the transparent fragments entirely
and yes it affects shadows
It lets the material be opaque and write to the depth buffer to properly sort with other objects, while also having transparency defined by the texture
yeah sorting with transparent shaders is often a nightmare
mmkay, time to photoshop then woo
oo yea ive seen games make mistakes in that
it's entirely possible to write a cutout shader that cuts out white pixels instead of alpha
but it seems weird
also in this case wouldn't it cut out the white numbers on the dart board?
yeup, but i'm mostly just practicing
in this case this texture is temporary and just for prototyping
hm well now it looks like this
What's the original image look like
If you set it to Point filter, does it mostly fix it?
(though it may add other artifacts, I just want to see something)
got crispier but no
that feels like some kind of weird sampling error 🤔
What if you disable compression?
no visible change

