#πΌοΈβ2d-tools
1 messages Β· Page 28 of 1
what thing?
instead of
Debug.Log("2");
Destroy(gameObject);
levelManager.instance.Respawn();
should be
Debug.Log("2");
levelManager.instance.Respawn();
Destroy(gameObject);
or the respawn function wont be called, as the object will get destroyed before that happens
i have that now and same thing
send a print of all the enemy components
a screenshot of the enemy components/tag/layer info
just like the screenshot of the bullet
.
check if the enemy or the bullet have a rigidbody, and also make sure the collider is a collider2d instead of 3d
send a screenshot of the collider component on both enemy/bullet
without collider it's collision cant be detected
im sry .-.
check if that fixes the problem, if not something else is wrong
Iβll look into that thank you
it fixes it, but then the enemy forgets what the player is and were my shoot position is
What am I doing wrong here? I can move diagonally using W D and A S keys but not with W A and S D. https://pastebinp.com/MHSbnewuE6HbJAxfLZIHA#AtUXs2tg6pfciuXSLFWM6z8DdM100kMIlz0_p4q5Pdk=
S D goes the same direction with W D and W A goes the same direction with W S
wait I think I figured it out..
Yep, as always. When I ask for help I figure it out
Is there a way to make specific frame(s) of an animation interact-able?
what do you mean
So for example I want to be able to interact with a game object, but only on the last couple frames of its animation.
I suppose another way of putting it is that I want only those last few 2D sprites to respond to a key press.
if you are animating through the animator class you might need to lookup AnimationEvent
I am, and I will try that. Thank you π
I'm sure this gets asked a lot, but I can't seem to fix it. How do I get rid of these seams? I turned of antialising in the project, but it still happens to some tiles. I don't see these seams in Scene View, just when in Game View
Hi, I have a problem, I am doing a project to practice and improve in unity 2D and I am having a problem which I have been trying to identify for a long time and I cannot find it. When I am shooting the bullet which has a collisionador2d and a rigidbody2d and collides with a "Wall" the bullet is destroyed as I have assigned in the code but in certain parts of that wall the bullet penetrates, the problem is that the wall is single object and single collider, try adding the rigidbody2d of the bullet that does not sleep and the collision detection in "Continuous" but the problem continues, could someone help me? Thank you very much in advance
UsingTraductor sorry
@livid pilot surprised this is happening when you have the collision mode set to continuous, how fast is your bullet moving?
make sure the wall collider is thicker than the bullet moving speed, if bullet move by 1f each frame and wall is 0.8, one time outta 5 it will pass
@robust ivy isn't this the point of continuous rigidbody detection?
to avoid this substep problem?
if i have an object at 1f x and move it to 3f x instantly i can guarantee the collider wont see it
or hes moving the bullet without physic?
right.. but you're not just moving it, you're using the Unity physics engine to move it?
Maybe that's the problem
isn't the point of continuous collision detection to avoid objects passing through other objects which are smaller than the velocity vector
@livid pilot you could also raycast ahead of the bullet by the velocity
how are you moving the bullet
yeah i use rigidbody2d and collision
and you're listening to a banger
velocity
setting velocity directly?
Using rigidbody2d
_direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - wPivotReference.position;
_rigidbody.velocity = _direction.normalized * ammoSpeed;
https://forum.unity.com/threads/unitys-tilemap-problem-some-gaps-between-tiles.594331/ you may try this, similar
yep
well step 1 with that code, instead of 0.5f in the raycast
Shouldn't I do that?
it's ok to do but you're raycasting 0.5 units every time
even if the bullet is travelling much more than that each frame
so step 1 I would use rigidbody.velocity.magnitude instead of 0.5f
maybe clamped to a minimum of 0.5f if you want
so Mathf.Clamp(rigidbody.velocity.magnitude, 0.5, float.MaxValue)
something like that
the built-in collision system might be more practical, up to you
but that's not necessarily the root of the problem
yeah
I'd probably just go with the collision callbacks
OnCollisionEnter2D
but the fact your rigidbody2D is still going through the walls is weird to me
instead of setting the velocity @livid pilot try using add force, I have a feeling it won't make a difference but give it a go
Before I had a code using OnTriggerEnter2D but I couldn't find a way to make the damage be applied to a single enemy and not to all the enemies that collide with the bullet
yeah use AddForce(Velocity, ForceMode2D.Impulse)
instead of velocity =
that should stop the bullet going through walls
if you're going to use OnTriggerEnter2D/Collision enter 2D and you want it to only affect 1 target then put that logic on the bullet, not the enemies
so the bullet sends damage to 1 enemy then deletes itself
instead of several enemies detecting the bullet and adding damage to themselves
should hit only once whoever have the ontrigger if it has a destroy in it
the first problem make the second
hitinfo is a struct, you cant compare it with null
wait physics2d.raycast doesnt return a bool like the 3d ones?
yes
remove the hitinfo != null
you only need hitInfo.Collider != null
probably
thats what unity documentation says
you cant do equality comparer with struct, only classes
Unity was giving me an error to find the instance or something like that
uhhh
its a struct
I presume that the null reference was the hitinfo.collider
if it didn't hit anything
yeah
so just do if(hitInfo && hitInfo.Collider) I think
pretty sure if the first argument fails && won't evaluate the 2nd
it doesnt extend Object, which is a class
so it cant use the implicit bool conversion
oh weird wait you're right, ray2d isn't bool is it
yeah it seems its only in 3d
snap ofcourse
The problem continues
I'm working with layers in case I forget to tell you
no
yeah what's your error navarro, if(hit.collider != null) shouldn't be erroring
oh my b
so AddForce isn't making the bullet move? @livid pilot
what is the error?
I try not to ask for help but this problem is breaking my head
its okay to ask for help
exactly
for sure, just trying to understand your problem
ok well debug the vector you're supplying, let's see what that is Debug.Log(_direction.normalized * ammoSpeed)
because the AddForce function definitely should be moving your rigidbody
ok 1sec
what is ammospeed
check your rigidbody isn't kinematic, check it is being simulated, check ammospeed
it cant throw a null reference error
What is strange is that if I use Vector2.Up it also does not make the ammo move
if you are doing a null comparison if
shouldn't this be in your start code? or at the very least, comment out the velocity set in your start function
where does that debug come from
sounds like its another debug log
I told him to debug the velocity he was supplying the RB
cause it's not even moving right now
oh
Update
Start
it doesnt make sense
addforce should definitly work
it makes sense if the tag is "Object"
Exactly
addforce should be in update also
yeah
either the game objects Tag is "Object" or its another debug log
The code tells me well the names of the objects with which the ammunition collides
"Ground" "enemy"
your bullet is the actual collider
that layermask is telling the raycast that it will ONLY raycast for objects on those layers
the way you have used it with your raycast
ik
no
shouldnt it be a trigger collider
It does not move
that shouldn't make a difference for AddForce, he doesn't even have an OnTrigger event in that code
The collider added it a while ago to test, maybe that's the problem, I forgot
can you show me the rigidnody settings?
where did you put the addforce
your rigidbody can have a collider, that shouldn't be a problem
if ur bullet start on character its blocked? i think
The problem continues
Start
yep
because you're using ForceMode2D.Impulse
isnt it supposed to be in Update? or FixedUpdate
no because he's using an impulse
it's a single fire modify to the velocity
which is perfect for a bullet
try turning up ammo speed
could you also show me your rigidbody settings?
ah they assigned the addforce to the rigidbodys velocity?
No, because the weapon spawns the bullet and at the moment the bullet spawns it should start moving
I mean, what he's saying works too - it could be an addforce in update, but then your bullet would be speeding up each frame
assign a vector on rb.velocity
Of course
@worldly patrol no, that's what he had before if you look higher up
we're trying to use addforce to solve another problem
all i know is if a collider is over another and you add force it wont move, its stuck in that collider
id check that
thats why i think it should be a trigger
Yes, I tried to add it in Update and it didn't work either
@livid pilot @robust ivy this is probably the problem, but setting your bullet to trigger will mean it doesn't collide with anything
And why rb.velocity work and rb.addforce not work?
you sure the return statement code executed in the update before executing the method?
and then disable the layer interaction with bullets
isnt he using a ray cast anyway to destroy it
he is, but as somebody said further up - might be better to use the built on On Collision stuff
for sure
but shit, if he's using a raycast, then why even use physics at all π
just raycast and move the object
from the player instead of the bullet even
indeed
@livid pilot try what devil cut said though, at least it will tell us if that's the problem, set the collider to trigger
..
right. but there are ways to do it.
lol
can you post your code again
That way it worked correctly
this is giving me anxiety lmao
you have to go back to that way navarro
what worked navarro?
the ontriggerenter
ahhh
Only I did not find how to make the damage to an enemy alone
for that reason try using raycast
that's a relatively simple problem by comparison
so the bullet is moving now?
it will once its a triger
if he added a new entity with a collider that would just block the bullet from moving, creating more problem
bullet shouldnt be collider i think
since you want it to actually pass throught object (or get destroyed when it hit a certain collider on a certain layer)
@livid pilot
if the bullet is too fast it may pass through the enemy
@robust ivy ranger actually has a point there
the original problem of the bullet passing through the enemies will happen if it's a trigger?
or does continuous collision detection account for that with triggers?
it does? damn, didn't know that
that's rad
well, using the good method
addforce
i dont know about velocity
should be the same imo but im not sure
better use transform.translate
xd
it is definitely not better to use transform.translate...??
to give you the vector depending on bullets angle
using transform.translate will mean he can't do any collision detection?
i dont think translate is physic
and the bullet could just pass through the collider
i meant to use that method on the rbs velocity
No, I'm using physics for the whole game, I don't think it's a good idea to use transform.translate xd
Add Force is the method to use, it's the one unity wants you to use
and plays well with collision detection
yup
setting the velocity directly can cause the problem he is having
ah your bullet's angle doesnt rely on the player's angle right?
player and mouse
i meant the player's angle
I do not understand the question
I am using a translator and it is difficult to understand sometimes
Right now everything works fine
sounds like your bullet does not have an angle
for example its going upwards but its facing to the right
I just want the ammunition to hurt a single player and not everyone in their collision.
the ammo goes off with the angle of the gun
on the enemy script you need a on trigger collision that will destroy the bullet once hit
so your gun is a gameobject or a component?
or maybe its on your bullet?
I have a hurt collider
object
"Gun"
is a simply rectangle
the velocity of your bullet should be = gun.transform.TransformDirection(Vector2.right * speed) or something
it returns the vector to the gun's right direction
so if your gun is looking upwards, the bullet will go up
and so on
I rotation the gun as I mentioned and then when I instantiate the bullet I assign it Quaternion.Identity, anyway that already works correctly
As mentioned above I was trying to use raycast because using OnTriggerEnter2d the ammunition hurts more than one enemy and I didn't want that
But the guys told me that it will be easier to use OnTriggerEnter2D and fix the ammo problem because using raycast caused confusing problems
I actually did what you told me but it continues to hurt more than one enemy :/
bullet should be destroyed on first hit, it pass through enemies?
how is it hurting more than one enemy if its not passing throught it
so it send message to all enemy?
maybe that's the problem
idk
sendmessageupwards send a message to each parent gameobject in hierarchy from where that script run
Should send a message only to the player who crashed
Right now he sends the message to hurtBox which is the son of Enemy and in enemy there is the function to add damage
The problem that the ammunition collider calls all the OnTriggerEnter2d of the enemies that are inside and that is why I hurt more than one enemy
is that the global health of all enemies or its the health of any child ?
when _health reach 0 what happen
The enemy is deactivated
show that code
ok
gameObject is the Hordes ?
which is the parent of all the enemies
if its disabled all enmies are gone
hordes
I am deactivating them for optimization
If I destroy them I have to re-instantiate them and that is not good
when you kill an enemy, sendmessageupwards send a message to EnemyAI and enemyAI gameObject get desactivated (which deactivate all child too)
if enemyAI is on hordes (which is the top parent object) then all enemy are being desactivated
now I send you a video of the problem
i dont understand why you say it hit multiple enemy
yes
ok
yeah
bullet damages more than 1 enemy?
thats probably because
Destroy does not destroy the object immediatly
it gets destroyed after all update methods of all classes finishes
you could try DestroyImmediate
this is the problem
so instead of using the whole collider
you hsould use a point
thats where the raycast come in play i guess
ok i try it
exactly
so now that you have a working collision
just add the raycast on the bullet to point at 1 pixel only
For that reason I tried to use raycast but when using it I generated more problems
you could not use trigger, you can just for each loop on all enemies
Although this problem was solved
yeah but you changed alot of thing too in that same time, like the trigger
now that is working just add the raycast check
I don't understand how I should add that
i always do it this way
same way you did
HitInfo
you really just had to change the collider to trigger i think at start
foreach(var enemy in FindGameObjectsWithTag("Enemy"))
{
if (enemy.TryGetComponent<BoxCollider2D>(out var enemybox))
{
if (box.bounds.Intersects(enemybox.bounds))
{
// hurt enemy code
Destroy(gameObject);
break;
}
}
}
thats how i always do it
it will result the same thing as he have now
the collider will hit both ennemies
since both interesect
see the break
it breaks out of the for loop
so when it finds the first enemy that collided with the box
the for loop ends immediatly
what?
if it intersect more than 1 collider
you dont have any order which one it hit
it could be the one further which make no sense ot hit
cause there an enemy in front of you
look at the if condition
if box bounds intersects enemybox bounds
so the method under this if will never get executed if its a far enemy
but in his case both enemies are within the bounds
thats why he hit both
does that work navarro
The only way to solve it is to get a list of all the enemies that are colliding with the ammunition at that moment and apply damage to only one of them but I think it would not work correctly
if you're hitting multiple in the trigger, can't you just use a control bool?
have it set to "damageDealt = false"
or you can try the code i posted above, put that in the update
set it to true when you damage a target
The only way it could work is as it had before but it generated many problems
can someone gave me a code I can copy past it
Code about control
D - Move Right
A - Move Left
there are many tutorials online for input, depends what you're using
thx so much
google is your friend with unity!
@copper stump sorry
@livid pilot you want the bullet to ONLY affect 1 enemy, yes?
@still tendon it's alright man, no problem asking questions
ok so your bullet has the trigger logic on it yes?
yes
that's a pretty broad question, depends on the type of game, how much 'stuff' is going to be on screen, but 2gb sounds like a fine amount of ram for a 2d application
wont be full hd vr game but yeah it can work
One time i download unity but it downloded for me hundred of files
on my download file
2gb is the minimum to use unity editor i think
why?
@livid pilot does this work?
{
if(collision.gameObject.CompareTag("World"))
{
Destroy(gameObject);
}
if(collision.gameObject.CompareTag("Enemy"))
{
collision.SendMessageUpwards("AddDamage", 30f);
Destroy(gameObject);
}
}```
Yes but it hurts more than one enemy
right okay
so
private void OnTriggerEnter2D(Collider2D collision)
{
if (!damageDealt)
{
damageDealt = true;
if (collision.gameObject.CompareTag("World"))
{
Destroy(gameObject);
}
if (collision.gameObject.CompareTag("Enemy"))
{
collision.SendMessageUpwards("AddDamage", 30f);
Destroy(gameObject);
}
}
}```
how about that?
I mean
probably not
given the Destroy should be dealing with it
trigger are on each enemy
the bullet collider overlap both enemies
which kill em both
it should be araycast for a point from the bullet
okay, the trigger script wants to be on your bullet surely?
with the if condition it will kill only 1
you want the bullet to send damage, not the players
YEP
Currently the bullet is sending damage, that way I identify what it is colliding with
ok 2 second
raycast a point in the bullet script, not from the ontrigger
why are we back to using raycasts D:
cause the collider of the bullet overlaps both enemies
ah i see now
what if the furthest enemy in the box died
it wouldnt make sense
you could use distance
or raycast from center player to wherever it hit
Any enemy that enters the collision of the ammunition before being destroyed takes damage
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("World"))
{
Destroy(gameObject);
}
if (collision.gameObject.CompareTag("Enemy"))
{
hitCollider = collision;
}
}
private void Update()
{
if(hitCollider != null)
{
hitCollider.SendMessageUpwards("ApplyDamage", 30);
Destroy(gameObject);
}
}```
does that work?
that shouldn't require a raycast and should only hit 1 enemy
@livid pilot
As soon as bullet hit something, a raycast from center of the player should be done to the bullet, check which is the first collider hit, and destroy that one
That will apply 1000 damage to the player
Catch2 we are discussing it could kill the farthest player in the collider
cult has a point
but i try it
eugh, I was worried about that too
yeah alright
I mean, put the player on their own collision layer, put the enemy bullets on their own and put the local player bullets on their own, disable collisions between the player and the local bullets and just use "OnCollisionEnter2D" instead is the real fix
It will even further delay the destruction of the enemy
it should only delay it by a frame
well in that case my new code would be like
foreach(var enemy in FindGameObjectsWithTag("Enemy").OrderBy(go => go.transform.position.Distance(gameObject.transform.position)
{
if (enemy.TryGetComponent<BoxCollider2D>(out var enemybox))
{
if (box.bounds.Intersects(enemybox.bounds))
{
// hurt enemy code
Destroy(gameObject);
break;
}
}
}
``` something like that
layers and not tags?
but you are using CompareTag
right but we're discussing collision layers
separately
@livid pilot what layer are your bullets on?
Enemy2 is an extra layer that makes enemies collide with each other so that they do not merge
yeah i have tags
what layer are your bullets on?
hit
and the enemy have a empyobject with a collision trigger
and player is on player?
layer hurt
then if you set the collider on the bullet to be NOT a trigger, you should be able to use AddForce without issues
because player does not collide with hit
I suppose
no
hit only collide with ground
ok
and hurt
with add forces?
yessir
he posted videos, seems to be working
show me your entire bullet code
no work
surely it's alright in start, the bullets have no gravity, and he was using AddForce.Impulse earlier
ForceMode2D.Impulse even
it's either colliding with something or the force is too weak, are you sure the wall colliders aren't overlapping the
bullets
its not bad to set rigidbody.velocity = gun.transform.TransformDirection(Vector2.right * speed); is it?
well yes because you're hard setting the velocity
same
where addforce does collision detection and sets the velocity to 0 if you collide with something
if you're setting the velocity manually, you end up with the problem he had earlier where the bullet just skips over colliders
Yes, I showed you my layer configuration
yes your bullets collider with the "Ground" layer
are you sure there's no ground collider they're spawning inside
and anyway @worldly patrol addforce should work if just setting the velocity works
I'll disable that to be sure, ok?
so he may as well figure out why this is happening
yeah good idea @livid pilot try to isolate exactly the problem
okay, can you show me your rigidbody settings and collider settings?
Even try adding a value manually
instead of direction.normalized too, try just Vector2.Up * 1000
just a hard coded value
by your logic addforce should be added in update or fixedupdate right?
it shouldn't matter..
add a single force on start should still move the object surely?
but wouldnt it go through walls which is the issue right now?
I think I know what the problem is
I think I know what the problem is
no the issue right now is that the bullet doesn't move at all
and no it wouldn't mean that
@livid pilot the way you're determining the direction is Vector 3 too
kinematic is the problem i think
the fucking addforce work only dinamic
yes
Kinematic means "I am affected by physics, but something else is controlling me"
ok work
lmao
you should avoid setting velocity directly as it can mess with physics calculations
use AddForce instead
You can set ForceMode to continuous iirc
Maybe we can try raycast again
raycast in the trigger method?
Exactly
you probably need to use the one where it has the raycasthit2d array as a parameter
or make the bullet collider very tiny
and iterate in the array and pick the closest enemy
With raycast it is the only way to damage a single enemy
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.collider.CompareTag("World"))
{
Destroy(gameObject);
}
else if(collision.collider.CompareTag("World"))
{
collision.collider.SendMessageUpwards("AddDamage", 30f);
Destroy(gameObject);
}
}```
@livid pilot
yes but it wouldnt make sense if the furthest enemy in the collider died
ok i try it
but yes, navarro, using a raycast from the player is a good way to do it
@worldly patrol they very much do?
Rigidbody2D
there's an entire 2d physics engine my guy
oh
does not fit with my games
did you disable the trigger?
^
why
does not fit with my games
i make my own physics
Fairs x2
I guess non deterministic physics can be an issue
but they're pretty poo for characters too
The ammunition is destroyed with the world but it does not detect the player, I am finding out why
its cause the ammunition can't detect after its been destroyed ;D
I have to deactivate the trigger to the enemy's hurt collider
for some reason i get the error
Sorry to say the problem continues
i don't think you gave enough information
if its above then the error might be above the constructor
i don't think the constructor actually has a issue
might be a missing semi colon, some syntax error above that line likely @green veldt
I'm testing with the raycast and I don't know if it helps anything but if I activate the trigger in the ammunition, the ammunition pierces the ground as at the beginning
But if I deactivate it, it no longer does it
this is all thats above
Could the ammo go too fast or the raycast be a problem?
@green veldt are you sure that's the error line? You double clicked the error in unity?
yes
@livid pilot raycast just shoots a line between points/a point + direction and detects colliders
shouldn't care about the physics of that object, just the postion etc
wouldn't you have 1 rigidbody and 2 colliders? why would you want two rigidbodies?
if it helps, this is my first time using vs code for unity
Β―_(γ)_/Β―
@green veldt well there's no error in that code as far as I can see, I think we need more information, can you show more of the script you're using there?
ye
because 1 is for trigger, and 1 is for physics collisions
syntactically that's all fine
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
public class Pathfinder : MonoBehaviour
{
public Tilemap tilemap;
public Tile wall;
public Tile entry;
public Tile exit;
public Tile me;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
Tile[] getNextTiles(Vector3Int base)
{
Tile[] toReturn = new Tile[8];
/*
ORDER
0 - left
1 - leftDOWN
2 - leftUP
3 - right
4 - rightDOWN
5 - rightUP
6 - Down
7 - UP
*/
toReturn[0] = tilemap.GetTile(new Vector3Int(base.x-1, base.y, 0));
return toReturn;
}
}
``` here ya go
@copper stump
@worldly patrol sure, but you flag colliders as triggers, not rigidbodies
@green veldt it's the word base
base is a reserved keyword
you can't use it as a parameter in that function name
oooh
base?
oh wow
and needs changing in your get tile function too
yeah
definitely a keyword
thanks
refers to the base class in inheritance
hence the funky error messages which don't make sense
ah
vs code
first time w/ unity
keep an eye on your syntax highlighting
ye, for some reason it didnt pick up
lol ye
@livid pilot I've been thinking and I think you're right about the raycast solution being more reliable
private void Awake()
{
_direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - wPivotReference.position;
bulletRigidBody2D = GetComponent<Rigidbody2D>();
bulletRigidBody2D.AddForce();
Destroy(gameObject, livingTime);
}
// Update is called once per frame
void Update()
{
RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, _direction, bulletRigidBody2D.velocity.magnitude, layer);
if(hitInfo.collider)
{
if (hitInfo.collider.CompareTag("Ground"))
{
Destroy(gameObject);
}
if (hitInfo.collider.CompareTag("Enemy"))
{
hitInfo.collider.SendMessageUpwards("ApplyDamage", 30f);
Destroy(gameObject);
}
}
}```
this is how I would advise you implement it, if you wanted to
bulletRigidBody2D.velocity.magnitude
here you can see I'm using the bulletRigidBody2D.velocity.magnitude
as the length for the raycast
so you're casting ahead of the bullet as far as it will move on the next frame
I think i fix it
fair enough, only thing with the on collision solution is it CAN in rare circumstances apply damage to more than 1 enemy
but if that's not a problem for you then good job, got there in the end
no
enemy is trigger
probably didnt want the enemy to collide
ohhhh and you can call OnTriggerEnter from the "entering" object?
I did not know that
I did not know it either
no
Thank you so much to everyone who helped me, I was really exploding my head trying to figure it out
shoudlnt it be tiny number
From what I understand it is the distance where the raycast will go, at least that is what I think it is
again, I would suggest doing the velocity IMO
its same thing
I guess, given it's in on trigger it's not a problem
@livid pilot that look awesome man, damn.. more polished than anything I've ever made, feelsbadman
digging the flashing enemies
lmao
how have you done the animation for that?
ahahahaha
hours and hours of animation
ahahsahah
Thank you very much for the help, I will go to sleep
cya
I guess this is the best programming practice one can do, blow your head
you'll be dreaming in code tonight
Hahahahahaha
seriously, it happens
also one more question
how can i get the vector3int position from a Tile object
or Tilebase
im pretty new to unity, can i have some help here
trying to make a simple pathfinding algo
code
its not elegant nor effiecent, just doesnt rly work
not very good behaviour
path finding is a deep subject not meant for beginner, either use NavMesh from unity or a solution already made or follow some tutorial on youtube
cant really explain how it work from a to z, its long
well, im just trying the most simplest of methods, getting nearby tiles and going to whichever is closest
seems logical enough....
use A*
It's not too complicated if you keep it simple
@green veldt
Pathfinding can be simple
just scan around the object
above, to the upper right, to the right, bottom-right etc
u can make an array of the choices
pick the one that is most effective at decreasing the distance between u and the goal
Is this the right place for UI script questions?
Hey, I need some ideas to make this script better. Right now I have a script that shows the tiles that are within the camera but each time this method is run it clears the whole Tilemap. Removing this line makes it so it only renders what the camera sees but it does not remove it after the camera leaves. Using this line has huge performance impact. Instead of removing every tile and adding back the tiles within the camera view I should only remove the tiles that are outside the view and leave the rest. How would I achieve this?
@pale tide can't you set tilemap mode to chunk or something
what do you mean by that exactly?
To save performance
Also what do you mean by
huge performance impact
Good or bad
bad because the line is tilemap.ClearAllTiles()
and that line into an void Update()
makes it go from 600 fps to 60 fps
600 fps
if this isn't exaggerated, do you even need the optimization?
what line are you talking about Jelles
and why do you clearAllTiles?
camera frustrum will get the tile that arent needed off
Oh smart unity then, good stuff.
so me removing the tiles that are off screen and adding them back onscreen is already done?
yeah
try making a super huge map and see by yourself if performance is hit
objects are still loaded in memory thought, dont make a 16000x16000 tiles map (that take alot of memory), that would be more like 4 scenes of 4000x4000 tiles or something (which take 1/4 of the memory) then you load the other scene/map part additivly when you get near (but that is some mega huge map you probably wont make)
Its just an example but you get the idea
I think since 2018 or 2019 tilemaps got upgraded alot
Ahh well I am making something like 255x2000
should be fine
Okay youre right it did resolve the performance
thanks
If I ever plan on making longer maps I should divide them into chunks?
if you reach a bottleneck yeah
if not continue like that
look at memory used by all this
see if its too much for you
a 2d game using 5gb of memory is usually a bit too much
;p
i have a 600x500 map with over 10k objects and still under 1gb
it take alot
yep
okay great tysm
if you build for webgl there a 1gb limit you want to try to stay at i think
there also another limit
just thought about it
the floating point error thingy
i think the general idea is dont go over 2000f distance from origin (up bottom left right) which would be a 4000x4000
not totally sure
if you need more you reset the position of map and character to the origin (0,0) once you reach that limit
or weird animation and weird things will start to happen
I'm attempting to build a large 2D World using tilemaps in unity, and was wondering how to prevent lag, should I just load tiles within a certain range?
I am doing the exact same atm my issue was that I was drawing the world over and over again in the update that made my lag very bad
Did you figure out how to fix it?
If I can get all the tiles in a tile map, I can make sure they're all unloaded when the scene starts, and then load each one and unload it based on my distance to them
No clue if this is a standard approach for Unity, but long, long ago with an OpenGL framework I used an Octree to partition the space and load different "chunks" of tiles, for 2d you can use a quadtree I believe
I am hoping there is a Unity specific, cleaner solution that someone can correct me with though
I honestly think Unity might handle it on its own I haven't checked
When I try to create a game that makes clones of enemies and spawns them at a specific point, unity always makes the clones invisible. Does anybody know what the issue is?
It's 10
Making make sure the Z position is lower than the camera's
Also, again, look in the Sorting layers. They really help when you have a lot of things on different layers
I know i might sound dumb but how do I look into sorting layers?
I just changed my z position for my enemy, but its clones still goes invisible
Just Google Unity 2D sorting layers to look into sorting layers
Try going into 3D View and moving around to see if you can find the enemy
I tried sorting layer and going into 3d mode, but I still cannot see my enemy
is the gameobject there
if you double click it while in scene view it will bring you to it, if you still cant see it make sure it has a material
if its still not there screenshot
I did double click on my clone, but it just shows the polygon colider around it.
What properties should my material have?
Heres a screenshot of my enemy clone
nvm
How do you move each individual sprite?
this is weird, I attached a particle emitter to a game object and, when the particle lifetime is over, the parent sprite is deleted as well! How do I stop this from happening?
It seems to be related to me Destroying the component on OnBecameInvsible. Why does the particle life timer override the whole object? Is there something I'm not getting about how a particle emitter as a component works?
Handy thing a guy on another server posted https://www.youtube.com/watch?v=tdTfgo9_hd8
tiny tutorial that might be useful to some!
follow me
Twitter: https://twitter.com/PhillTalksAbout
Instagram: https://www.instagram.com/phillserraz...
GitHub: https://github.com/phillserrazina
My Projects: https://phillserrazina.itch.io/
#unity #gamedevelopment #tutorial #gamedev
@still tendon how are you calling the destroy? Are you specifying the component?
@pale tide assuming you sliced each sprite properly, you'd move them in the scene view.
You can either assign bones in the sprite editor or just move each sprite as a solid chunk.
can anyone help me on how to make my 2d character look/rotate wherever he is moving?
how do i change the position of a button from a script? Mine moves the button but to the completely wrong spot
set the transform. what does your code look like?
I just realized I had completely set a variable wrong using random. So sorry to bother you, I'm just dumb
are you starting from scratch or do you have something already? If you are starting new, start with a tutorial and post when you have a question. heres one: https://www.youtube.com/watch?v=dwcT-Dch0bA
Letβs give our player some moves!
β Check out Skillshare: https://skl.sh/brackeys7
β Character Controller: https://bit.ly/2MQAkmu
β Download the Project: https://bit.ly/2KPx7pX
β Get the Assets: https://bit.ly/2KOkwjt
β₯ Support Brackeys on Patreon: http://patreon.com/brackeys/
Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·...
how would i return the x and y values of a transform as 1 or negative 1 say +x,+y then it would output 1,1
basically want to use that as a direction the player is in that i can multiply by speed
if you just want a direction that is called normalisation, it doesn't set things to 1, it makes the vector have a length of 1
ahh ok
Unity has multiple parts of the API that does it, just look for .normalize properties and Normalize functions in the docs
does anyone know where to find scripts for expanding the sprite sheet editor built into unity, I am trying to have a script to batch rename all and batch change custom pivot without deleting all sprites
also batch trim
how would one disable all gameobjects in an array
would it be like for(int i = 0;i< GameObject[i];i++){GameObject[i].enabled = false;}
For starters, GameObjects are active/inactive, not enabled. SetActive(bool).
Then I'd advice against using GameObject as your array identifier.
In the loop condition you probably want to check the length of the array.
for(int i =0;i<Enemies.Count;i++)
{
Enemies[i].SetActive(true);
}
yes
I just put in Destroy(gameObject) in the onBecameInvisible private method. For some reason when i do this, the gameobject goes kaput along with the particles
If anything, if there were an alternate method for destroying objects that are outside of the camera that would probably help since becameInvisible is related to the renderer and may behave unexpectedly for example when the object is hidden behind another
@mossy coyote every time someone links that tutorial, a 2d fairy loses their wings and falls into lava and then posts here asking how to debug their being on fire.
@still tendon if you put the game object as the thing to be destroyed, then it will destroy the game object. You need to specify the component you want to destroy.
'Removes a GameObject, component or asset.
The objectΒ objΒ is destroyed immediately after the current Update loop, orΒ tΒ seconds from now if a time is specified. IfΒ objΒ is aΒ Component, this method removes the component from theΒ GameObjectΒ and destroys it. IfΒ objΒ is aΒ GameObject, it destroys theΒ GameObject, all its components and all transform children of theΒ GameObject.'
So you'd use a GetComponent or assign the particle system in the inspector.
I hate brackeys and this tutorial
welp i have no idea why my coroutine is working
im spawning my player 4 seconds after the game starts ive tried getting a reference using a bool on the coroutine in the player script but anyway after 4 seconds all attatched game objects get destroyed on that destroy thing i have the wait time set to 16f
hmm
also my editor is being dumb im sure it wasnt marking the coroutine as an error before
count your braces
Hello,
Why doesn't this work?
void Update()
{
CountDownAndShoot();
if (moving)
{
laserProjectile.transform.position = Vector2.MoveTowards(transform.position, player.transform.position,
projectileSpeed * Time.deltaTime);
if (laserProjectile.transform.position == player.transform.position)
{
moving = false;
}
}
}
its even
I am counting 9 on the image
Output values to understand what's happening, you can use temporary text elements to debug streaming data.
the bracket at the beginning of the script needs an end
Ah. You should format your code a bit... It's pretty hard to read for me
And what is the 9th for?
the 9th is the end
The end of what
Yeah, I get that
What is it saying when you hover over the red line?
Could you please send me the Code of this Script, so I can look at it as good as I can
https://pastebin.com/q2KXugNy
https://pastebin.com/eTfxaDpg
heres a pastebin for the scripts i think are the problems
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
if anyone wants to take a crack at it lmk
@valid dune Just format your code properly and remove brace on line 45
is there an auto format in vs code also line 45 on the 2nd pastebin is a else if
and 45 in 1 is instantiate afaik brackets are needed
is there an auto format in vs code
Things you can google right from the discord window (and should)
it will make it obvious
just did
anyone need help?
Is there a simple way to add a automatic player movement to a topdown game?
this is my code. I want the player to automaticly move in the specific directions. (just like snake)
lol. well, to be honest, I didn't watch the tutorial. My point was, there are a lot of tutorials out there and instead of asking how to do something that requires several steps, like moving a character around, it might be best to go through a tutorial and then bring back any specific questions to the group. But, I like the idea of things falling into lava!
It works as intended, it destroys the whole game object when it goes off screen. Problem is when i make it emit particles that say, last 5 seconds, after 5 seconds both the particles AND the game object that triggered them get destroyed
spawn a GameObject that exists for the sole purpose of having the particlesystem, maybe
anyone have any suggestions: I have a 2d game that I use tilemaps to draw the environment. I want to create a rain effect (both raid drops falling as well as creating drops hitting the surface). I created the drops falling using a particle effect. What about drops hitting the surface (creating little splatters image overlays randomly on the tile grid). Can that be done by a particle effect?
Not quite sure
Maybe would be better to have a rain animation
Can anyone recomend me what to use as a background to my 2d game cause i want to be able to texture paint it inside of unity
anyone have any good tutorials on movement scripts and animation? I would prefer not brackeys because I've done his tutorial 4 times and the jump animation is always bugged
I would also prefer if you could send an easy one because I am VERY new to C#
Hello everyone. I have this issue that I am trying to solve for 2 weeks now. I want to create a spawning system similar to Hack and slash games, but I can't find any resources online. Keep in mind that I am not a beginner developer. I can create normal spawners that just spam enemies every few seconds and enemies are also recycable. But this thing that I am trying to create is more open worldish. The level has a limit of enemies and the enemies can be also cleared the same way like in hack and slash games. I don't need code example, but a more design pattern, like what is the logic behind it? The game is top down 2D shooter in space
Hello guys. How do I make a gameobject follow a player and that it always stays on top of it?
simple way is align the gameobject like you want and drop it as a child of the player, that way moving the player all child follow and rotate like the player do
Hey guys one question
I created this code because my game has not gravity i dont know why, and i want to have a key for the mass
But when i press S the mass doesnt go up, why? What is wrong?
Doing a tutorial that illustrate working with physics systems first would help a lot. Tutorial links are pinned in #π»βcode-beginner . Also debugging guide. You need to test what's happening with inputs, what script is actually running etc.
Not sure if this is the correct place to post. I am trying to have a game object become interact-able within a certain frame window. Currently I have an Animation Event assigned to one of the key frames towards the end of the Animation Clip. It seems like this variable would need to be defined as a boolean value because it is either true or false. Maybe there is a better way to approach this?
@polar pagoda Don't cross-post.
@lean estuary π
Is there a way to make it so enemies will go through the player when they are invincible?
I played with isTrigger on the collider, but they all just fall through the floor lmao
You can set them temporarily to a layer that ignores collision with player (set in Physics collision matrix)
Hey, I need help on my 2d unity game if someone can please help me, I don't know how to add a shooting mechanic to my 2d side scroller
Hi everyone
It's me π
Again π
I have one question
Maybe some of you know that i write game to work of as engineering work]
My problem is this that when i colison with "coins" i have example 100 points
and
when i die and i klick again Play Game
this coins dont exist
in my code I have a command Destroy
and i dont know how do this that whene i restart game i have this again :
do what
load? destroy?
exist?
you could reload coins by spawning them back in?
or just reload the scene
when i reload lvl i have that i cant see coins which I collected
