#bullet collision lag..?
1 messages · Page 1 of 1 (latest)
set the collider for the bullet physics to be continues
should fix your collision issue
no dice
raycast would solve this and it seems like thats exactly what u want. the collision is going into the wall because of the speed and even with setting bullet to a different collision detection method wont solve this 100% of the time, raycasting does not have this issue.
i think he doesnt want the bullets to be instant though
^
hm
well u can lerp or just add force in that direction
i didnt read the whole convo, idk what you're using to push it
but what if what you shot at is no longer there by the time the bullet arrives?
velocity
like something moved out of the way
how slow is the bullet, is the user supposed to see it?
yea
what i said about raycasting then add force might not be a nice solution because you'll still need to check when it collides. Can u try setting the bullet to interpolate?
do i keep it continuous?
yea but im curious because u said continuous didnt work
typically interpolation is used for the main character
thats on the bullet right?
yup
freezing the bullet wont do anything after its already collided with the middle of the wall..
raycasting is definitely a solution for this, im just concerned for the case of shooting a bullet far and it getting stopped by something that moves into its path. You wouldn't be able to cast the raycast from the player when the bullet fires in such case
i guess u could just deal with that case by storing the hit point of the raycast and comparing distance to the actual hit ?
sounds complicated
then am i having to decide between making the bullet instantaneous (raycast) and making it really slow
player shoots -> player fires bullet, player sends raycast, store the hit point
bullet travels and eventually hits something, get the location of the bullet on hit
compare (bullet hit point - raycast hit point) < some small distance
if the bullet is close enough to the 1 raycast then draw on the raycast point
if not, draw on the bullet hit point
but this only exists if your bullet is slow enough to be stopped by something. like if an npc can jump in between your bullet and the wall
that case of something falling onto the bullet may still have the same bug too if its falling fast, but it might make more sense to allow the bullet hit splat to be drawn in the middle of an npc rather than setting every single moving thing to interpolate/continuous especially when u said it didnt work on the bullet
i'll definitely look into it, but i just tested how the bullet landing effect actually looks in practice and even though its a bit disjointed it actually still looks acceptable
thanks for the explanation though
oh wait is it a continuous effect?
i thought it was shoot, and the hitsplat stays on the wall as like damage.
with this bullet trail, you can probably raycast from the bullet by a small amount to see if its close enough to hit something so you can stop the effect from going into the wall
raycasting is just a line going somewhere, starting from somewhere. U have options for it to ignore objects and have a max distance. Its really easy once u use it a few times.
Use debug.drawray to visualize it too by plugging in the starting position, the direction * hit.distance
im gonna use the raycast system that i use to control whether the player can jump or not
lets see if it works
hmmmm
fixed some stuff
it seems to work yeah
actually no not really it's doing all the same stuff as before
the raycast would have to be in the direction of the bullet, not always Vector2.right, but you also arent using raycasts properly here
what value are u using for raycastDistance
add a debug.drawRay to see it frame by frame, itll make more sense as to whats happening exactly, and turn on gizmos
no matter what i set it to there are inconsistencies
you're instantiating the bullet at its transform.position, which i assume is not what u want. Its basically ignoring the fact that a raycast exists
it should use the hit position
this raycast also is just used to end the bullet early and then paint itself on where it shouldve hit
its hit.point for the raycast hit position
Use of unassigned local variable 'hit'
drawRay needs gizmos on, but try
Debug.drawRay(transform.position, [your direction vector] * raycastDistance)
its unassigned if its not within that if statement
because the hit only is assigned if the bullets detects something nearby with the raycast
this is what i got rn
put out hit back in the Raycast parameters and also move the RaycastHit2D back to before the if statement. Alternatively u can just write out RaycastHit2D hit in the params
oh for the draw ray also put , 0.2f at the end so it wont instantly disappear. Draw ray lasts 1 frame
you'll see one issue hopefully with the raycast after draw ray works
i tried using one of the examples in that reference right there
it kinda works? for some reason it just doesnt move at all, i think its because the bullet is hitting the player or something
its likely because of what i said earlier for Vector2.right, its only gonna check to the right of the transform.position
do u see the rays being drawn
ye
oh in that code u removed the distance i just realized
thats why its breaking instantly
its going infinitely
ok
this
works REALLY well
but only for the right
ik you said that already
so how do i go about doing it for both sides
i believe transform.forward should work
i tried that but it doesn't exist to vector2
the bullets transform direction should be the direction it is being fired
it is
u only need the x,y for it i believe
i havent used 2d so dont quote me on that, but it compiles in my head so therefore it works 🙏
when the bullets are instantiated i make their rotation the saame as the rotation of the gun
(this is in another script mind you)
so it should be rotated correctly
wait
ive got it
awesome genius alert
alright it works like a charm
nice, its all solved now?
kinda
there is no problem with the landing effect anymore
the problem now is that the bullet sometimes stops too soon
if the raycast distance is too large it's gonna sometimes have a gap between the bullet and the effect
if the raycast distance is too short we're back to square one
the draw line only appears when the bullet's landed
kinda different on the left
the debug ray looks like its pointing the wrong direction on the left
but i figured this would be an issue tbh, i just dont know whats the best to do.
- u might have to fine tune the distance to get a result u are happy with,
- connect the line in afterwards,
or 3. find a better solution
oh wait i know whats wrong with debugray lol
yea debugray just didnt get updated i bet to not use Vector2.right
yeah yeah
i have an idea
how about we make the bullet instantly travel to the position of the landing effect
that seems to work
you could do that, im not going to suggest u change your shooting logic entirely around this issue, and im not saying u shouldnt do it either.
Its just what u want in your game, if u want to bullets to be slow for the purpose of dodging them then u cant make it instant. If u want fast bullets to avoid this bug and not being able to dodge them then thats fine
i don't intend for this game to be multiplayer; ai is probably gonna be very simple and there won't be many moving parts, so i don't think it's an issue... at least for now
but if nothing else goes awry thank you so much man
np goodluck, i think worse case scenario u could look into the following later depending on what u care about
- just leave that gap in
- undo this raycast and let it be in the wall
- try to draw it manually to fill in the gap
- try and find the closest point of the outer wall in the backwards direction of the bullet and draw it there