#can anyone help me with debugging my
1 messages · Page 1 of 1 (latest)
https://paste.mod.gg/izfnlghtkous/0
BlazeBin - izfnlghtkous
A tool for sharing your source code with the world!
https://paste.mod.gg/nkjaavcjbgsg/0
A tool for sharing your source code with the world!
A tool for sharing your source code with the world!
@silk wing What's the issue exactly?
the attack only works right
the left attack dosent work
What? I see you're using Physics2D.OverlapCircleAll which has no left & right.
Are you trying to cast the sphere left or right depending on character facing direction?
yep
You calculated this value, but later on you don't use it in the overlap circle?
Vector2 attackPosition = (Vector2)attackDirection.position + lastDirection * attackRange;
Physics2D.OverlapCircleAll(attackDirection.position, attackRange, detectEnemy);
wait is this the solution
im confused
oh shit
i should change it to attackPosition
still didnt work...
thank you for your help btw im really dumb and dont know how to code so i may not know what to do even when u give me clear answers lol
apologizing in advance
I recommend you start using OnGUI for debugging - it'll show values in real time & less laggy than Debug.Log
{
GUI.Label(new Rect(10, 10, 100, 20), "My Cool Variable = " + myCoolVariable);
}```
Basically let's make sure your lastDirection works before we go into the other stuff.
the left direction returns correct, (-1,0)
i think it has to do with the attack math or the shape of the attack
im so stuck bro
fuck
And the right direction?
Nah definitely not... This is extremely simple, we just need to determine at which point things went sideways.
... Huh?
When you multiple (0,0) by the attackRange, you will get (0,0)
wait
too many things happenig in one frame (when you press space key) i dont know if that is a good idea
Attack input detected
UnityEngine.Debug:Log (object)
attack:Update () (at Assets/attack.cs:37)
lastDirection: (0.00, 0.00)
UnityEngine.Debug:Log (object)
attack:Update () (at Assets/attack.cs:40)
attackDirection.position: (0.75, -3.08, 0.00)
UnityEngine.Debug:Log (object)
attack:Update () (at Assets/attack.cs:41)
attackRange: 0.6
UnityEngine.Debug:Log (object)
attack:Update () (at Assets/attack.cs:42)
Attack Position: (0.75, -3.08)
UnityEngine.Debug:Log (object)
attack:Update () (at Assets/attack.cs:48)
Enemies found: 0
UnityEngine.Debug:Log (object)
attack:Update () (at Assets/attack.cs:53)
thats right
and left is
Last Direction: (-1.00, 0.00)
UnityEngine.Debug:Log (object)
Movement:Update () (at Assets/Movement.cs:33)
Yeah the state pattern is gonna be super useful here.
https://gameprogrammingpatterns.com/state.html
Attack input detected
UnityEngine.Debug:Log (object)
attack:Update () (at Assets/attack.cs:37)
lastDirection: (-1.00, 0.00)
UnityEngine.Debug:Log (object)
attack:Update () (at Assets/attack.cs:40)
attackDirection.position: (0.68, -3.08, 0.00)
UnityEngine.Debug:Log (object)
attack:Update () (at Assets/attack.cs:41)
attackRange: 0.6
UnityEngine.Debug:Log (object)
attack:Update () (at Assets/attack.cs:42)
Calculated attackPosition: (0.08, -3.08)
UnityEngine.Debug:Log (object)
attack:Update () (at Assets/attack.cs:46)
Attack Position: (0.08, -3.08)
UnityEngine.Debug:Log (object)
attack:Update () (at Assets/attack.cs:48)
I thought you only want, "character is facing left" or "character is facing right"
yeap
woah thats fire i needa study that soon </3
Too many variables, too much bloat
So how do we know if the attack should happen on left or right side?
Would it be if (attackPosition.x < 0.0f) { // Left side stuff } ? Since right is 0 or greater?
Are you flipping your character sprite to face left or right too? Based on this?
yea this Vector2 attackPosition = (Vector2)attackDirection.position + lastDirection * attackRange;
returns attack position based on direction
This whole thing is way too overcomplicated. There's only like 3 variables at play
i have an overlap circle that starts on the right side of my character
and its moving that
im gonna be completley honest with you this is the result of like 3 tutorials mashed together
idk jack shit about unity and im tryna make up for it with basic js and python knowledge
i did read the api
which helps a bit
sorry bro ðŸ˜
attack position. direction tells u where the attack originates and last direction is (0,0) or (-1,0), right and left respectivley
attack range is a float thats set to 2
@silk wing
float attackRangeAdjustedToDirection = -attackRange;
if (characterFacingRight)
{
attackRangeAdjustedToDirection = attackRange;
}
Vector2 overlapCirclePosition = characterPosition + new Vector2(attackRangeAdjustedToDirection, 0.0f);
// or, = new Vector2(characterPosition.x + attackRangeAdjustedToDirection, characterPosition.y);
// Then whatever else
Physics2D.OverlapCircleAll(overlapCirclePosition, attackRange, detectEnemy);
Is this making sense?
You have everything ready for this, just need that characterFacingRight condition.
so if character faces right, the attack would be the default value or the current position, which is right since the attack sphere is currently placed right
Yeah. Basically you just need to change 1 variable, the X offset
and since the attack range adjusted to direction reverses the attack range
istead of changing the position of the actual sphere
Yep just flip the value if doing it left
I'm still using overlapCirclePosition so, that's the computed "final adjusted value"
im not sure how id implement this, would i just add it to my current code?
Well first of all can you just Debug.Log "Left" or "Right" instead of that whole ass Vector value please.
Maybe it's like this? I'm not sure how you're doing this exactly
if (attackDirection.x < 0.0f)
{
Debug.Log("Left attack");
}
else
{
Debug.Log("Right attack");
}
The main idea here is, we need to verify the reliability of your "character is facing direction" stuff
Before we go and start doing more with that like OverlapSphere or calculating positions
not sure just doing attackDirection.x would work
is that how you read vector values?
let me check
Yeah Vector2 is x,y Vector3 is x,y,z
like myCoolVector.x
Yes let's get that "Left attack" and "Right attack" working first 🗿

Okay. So, what variables can we use then, to determine which direction the character is facing?
Maybe the rb.linearVelocity
for some reason it works fine
like the output left right attack
not the actual attack
the debug log
Yeah I'm saying, the log is correct.
We need to start with that, before the next stuff
Pro Tip - always verify your variables before building other stuff on top of them 
Any reason to not use lastDirection ?
Seems like that would be either positive or negative depending on the float moveInput = Input.GetAxis("Horizontal");
Input.GetAxis("Horizontal"); usually returns between -1 and 1 🤔
sorry quick question
If you need to wait until the character is actually moving that way, rb.linearVelocity would be better.
my characters are currently able to push each other
how would i disable that
would it be in rigidbody2d?
Rigidbody settings, collision layers, Include Exclude, Physics.IgnoreCollision
Those are a few ways
Include/Exclude is easiest, if you have your objects set to certain layers already
You could use Include Layers and Exclude Layers.
oh
i just
realized the problem
the reason it wasnt working was because when my enemy moves into my player
it pushes the player right
which changes its attack to right
meaning enemies coming from the left are basically unkillable
while that somehow didnt apply to characters coming to the left
So do you want the player to be able to attack left as soon as they start moving left? Or would they have to wait until the Rigidbody is moving left?
// Based on movement input only
if (moveInput < 0.0f)
{
}
else
{
}
// Based on if the Rigidbody changed directions already
if (rigidbody.linearVelocity.x < 0.0f)
// etc
as soon as they start moving left
So you can just use the lastDirection for that
Make the lastDirection a public variable, perhaps add [NonSerialized] before the public keyword. This requires using System; which would go at the top next to using UnityEngine;
Then in the attack code...
JK just saw, you have a function that retrieves the value
got it done
also the collision affecting direction was one thing but i still notice that sometimes it dosent register the direction correctly so gotta keep checking that
maybe ur current suggestions will kill all the stones w one bird
yep
illl steal leave it public for easier use
So yeah...
if (playerMovement.GetLastDirection().x < 0.0f)
{ // Left side }
else
{ // Right side }
give the state pattern a try - Polymorphism is super useful in OOP languages not just for character movement
Composition vs Inheritance - another cool related topic
so like this basically?
No
Well... I guess sort of
you're using lastDirection directly as the position? I thought there's some fixed distance away that the attack checks for enemies
Let's think more here... What's the difference between left and right?
Just the "x offset" value that the OverlapCircleAll needs to use right?
ur right the attack dosent work at all anymore
So that's the only difference we need in our code ...
yeap and the overlap circle all starts on the right side of the player
that would be the attack range right?
No yo... The attack range is the size of the sphere right ?
The first parameter of OverlapCircleAll is the position to place the sphere, not the radius / range
*detect enemy
@silk wing you realize you're not supposed to be spamming multiple messages across multiple channels, right? Every channel I go to it's you asking about this AI generated code you're trying to debug
I'm saying, how far from the character do you want it to be
mb bro leme close those channels
also vengeful thanks for the help in advance and if ur worried about ai generated code its not lmao i can pull references for tutorials used
i sorta... get it...?
@silk wing
private float sphereOffsetDistance = 1.0f; // outside of all functions
// maybe make it Serialized and add a [Range(0.0f, 2.0f)] for playmode tuning convenience
// recall that the value resets after exit playmode, use scriptable objects to solve that
// this goes after if (Input.GetKeyDown)
float sphereOffsetX = sphereOffsetDistance;
if (playerMovement.GetLastDirection().x < 0.0f)
sphereOffsetX = -sphereOffsetDistance;
Collider2D[] DamageEnemy = Physics2D.OverlapCircleAll(new Vector2(characterPosition.x + sphereOffsetX, characterPosition.y), attackRange, detectEnemy);
Red is the distance (sphereOffsetX)
Blue is the radius (attackRange)
for if (playerMovement.GetLastDirection() < 0.0f), the < operator cant be aplied to type vector 2 and float?
Notice that I used the character position in Physics.OverlapCircleAll
Doesn't it require that? I believe it checks an absolute position, not relative from current object or something.
Sorry, just add .x
characterPosition does not exist, that was me writing in English
Maybe, playerMovement.transform.position ?
right so you control that by using the two variables sphereoffset and attackrange
Yeah so... Just finish writing the code
Does playerMovement.transform.position work? instead of characterPosition which is pseudocode
works amazing sorry i didnt realize it was pseudo lol
get last direction is a method tho?
Omg ... yo
GetLastDirection().x
omg.
You're trying to run & swim before you walk
You know you're using the old input system too, right? Out dated as of Unity 6
uhh.... no... i didnt