#bullet collision lag..?

1 messages · Page 1 of 1 (latest)

rigid sapphire
#

here

slender elm
#

so are the bullets rigidbody based or just transform

#

looks rigid body based nvm

rigid sapphire
#

yeh

slender elm
#

set the collider for the bullet physics to be continues

#

should fix your collision issue

rigid sapphire
#

no dice

slender elm
#

continuous

#

no

dense bane
#

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.

slender elm
#

i think he doesnt want the bullets to be instant though

rigid sapphire
#

^

dense bane
#

u can still raycast...

#

just lerp it towards that hit point

slender elm
#

can you do that?

#

oh

#

the more you know

rigid sapphire
#

hm

dense bane
#

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

rigid sapphire
#

but what if what you shot at is no longer there by the time the bullet arrives?

slender elm
#

velocity

rigid sapphire
#

like something moved out of the way

dense bane
#

how slow is the bullet, is the user supposed to see it?

rigid sapphire
#

yea

dense bane
#

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?

rigid sapphire
#

do i keep it continuous?

dense bane
#

yea but im curious because u said continuous didnt work

#

typically interpolation is used for the main character

rigid sapphire
#

doesnt seem to have worked either

dense bane
#

thats on the bullet right?

rigid sapphire
#

yup

dense bane
#

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 ?

rigid sapphire
#

sounds complicated

#

then am i having to decide between making the bullet instantaneous (raycast) and making it really slow

dense bane
#

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

rigid sapphire
#

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

dense bane
#

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

rigid sapphire
#

ohhhhhh

#

thats a good idea

#

ill try it but im not the best with raycasting

dense bane
#

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

rigid sapphire
#

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

dense bane
#

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

rigid sapphire
dense bane
#

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

rigid sapphire
#

mmm

#

what is that

dense bane
#

this raycast also is just used to end the bullet early and then paint itself on where it shouldve hit

rigid sapphire
#

also i cant get drawray to work

#

where does it go?

dense bane
#

its hit.point for the raycast hit position

rigid sapphire
#

Use of unassigned local variable 'hit'

dense bane
#

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

rigid sapphire
#

this is what i got rn

dense bane
#

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

rigid sapphire
#

idk why but its giving me errors now when it wasnt before

dense bane
#

i think the order is wrong

rigid sapphire
#

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

dense bane
#

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

rigid sapphire
#

ye

dense bane
#

oh in that code u removed the distance i just realized

#

thats why its breaking instantly

#

its going infinitely

rigid sapphire
#

ok

#

works REALLY well

#

but only for the right

#

ik you said that already

#

so how do i go about doing it for both sides

dense bane
#

i believe transform.forward should work

rigid sapphire
#

i tried that but it doesn't exist to vector2

dense bane
#

the bullets transform direction should be the direction it is being fired

rigid sapphire
#

it is

dense bane
#

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 🙏

rigid sapphire
#

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

dense bane
#

nice, its all solved now?

rigid sapphire
#

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

dense bane
#

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.

  1. u might have to fine tune the distance to get a result u are happy with,
  2. connect the line in afterwards,
    or 3. find a better solution
rigid sapphire
#

oh wait i know whats wrong with debugray lol

dense bane
#

yea debugray just didnt get updated i bet to not use Vector2.right

rigid sapphire
#

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

dense bane
#

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

rigid sapphire
#

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

dense bane
#

np goodluck, i think worse case scenario u could look into the following later depending on what u care about

  1. just leave that gap in
  2. undo this raycast and let it be in the wall
  3. try to draw it manually to fill in the gap
  4. try and find the closest point of the outer wall in the backwards direction of the bullet and draw it there