#Raycast issues

1 messages · Page 1 of 1 (latest)

rain dove
#

Yo, i've been going histerical over the shooting in my 3d fps game. It uses raycasts, and the enemies use a billboarding technique. I don't know exactly what it is, but specifically some enemies or things cause the shots to not affect the enemies at all. I have no idea what's causing this and how. Please help 😦

turbid flint
#

Show code

#

[]cb

jaunty dewBOT
#

Use codeblocks to send code in a message!

To make a codeblock, surround your code with ``` (3 backticks. Click here to see where the key is)

To use syntax highlighting, add the file extension of the language you wish to highlight (cs for C#, cpp for C++)

For example:
```cs
Console.WriteLine("Hello World");
```

Produces:

Console.WriteLine("Hello World");

To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.

north nymphBOT
rain dove
#

i should say it's much much worse when the game is built than when you're playtesting

turbid flint
#

can you explain your issue more?

rain dove
#

i'll try my best lol

#

So basically, sometimes when the player shoots the enemy, they don't recieve damage or anything, as if the raycast didn't hit it. I don't know if it's a raycast issue, or a collider issue, or what, but whatever i do doesn't seem to fix the issue. As I also said, the enemies in my game use a technique called billboarding, meaning they rotate a lot, so i don't know if that maybe messes up their colliders

humble raft
#

What does your debug raycast show in the Scene view when the enemy doesnt receive damage? If theres no raycast at all, its possible your enemies could be outside of whatever value you have range set to in your raycast or your direction is not at the value your expecting - id maybe move the debug line outside of your if-statement as well, so you can see what happens even when your raycast may return false

rain dove
#

Okay, so for some reason now the bug is completely gone in the scene test, but when the game is built it still persists. Adding a linerenderer.

#

Okay. I added a linerenderer and tried building the game. It seems like the raycast is working properly, but the problem is the enemy's colliders

#

I'll send all of the enemy's scripts

north nymphBOT
rain dove
#

that's the AI

north nymphBOT
rain dove
#

billboarding

north nymphBOT
rain dove
#

and the script that handles all health related stuff

humble raft
rain dove
#

I have no idea, maybe they move alot with the billboarding and ai following and stuff but it should just be rotation so idk

humble raft
#

What kind of collider are you using on your enemies?

rain dove
#

box collider, it's very wide and there's one for the body and one for the head

#

the one in the head has a head tag that basically multiplies the damage when hit

humble raft
# rain dove

Maybe you can try a capsule or sphere collider to test with, since rotating those shapes shouldnt affect the shortest distance your raycast would have to travel, you could also try increasing your raycast distance by a large amount to ensure your colliders are being hit, and try logging the object that was actually hit by your ray, it could be a layer related issue, you could also try adding a visible cube/mesh that matches your collider size/shape, and change its color based on if your raycast hit or not, so you have more of a visual of whats going on in a build

rain dove
#

i'll send an update asap

frank ether
#

Worth a try + seems like they would be more approapriate colliders in your case to give radially symmetric collision shape but I'm surprised if that alone is the issue. No matter how the rotations get updated to the collision shapes, the collider shouldn't just disappear. I think these collider issues were more pronounced in some old unity versions, nowadays even transform.position/rotation = updates the colliders just fine in most cases

rain dove
#

just tried using capsule colliders. Pretty much the same, the bullet raycast just phases through, i can even see the bullet impact on the wall behind the enemy.

#

if anyone wants the file or some screenies of like specific stuff i can send it over so you can check it out

frank ether
rain dove
#

i don't think so, it may be the case some times but this mostly happens at any range

#

the weirdest part for me is how it's like only specific enemies that just don't work, and they're not like different enemy types like the exact same gameobject

frank ether
#

Maybe you could try to call Physics.SyncTransforms just before calling the raycast. That used to be a thing for moving objects in earlier unity versions thought I don't think it should be relevant on newer versions

rain dove
#

abt to take a break but sure i'll try that before hopping off

#

thanks for all the help btw

#

oh my god i think it works

#

thank you so so much i've been so annoyed for days now

#

i'm definitely adding you to the game's credits lmao

frank ether
# rain dove oh my god i think it works

Oh nice, honestly didn't expext that to do anything. I think Physics.SyncTransforms is somewhat expensive so relying on that may not be a great solution. Could you specify what unity version you are on and how you are moving/rotating the enemies?

rain dove
frank ether
# rain dove i’m on 6000.0.32f1, my enemies move and turn based on an enemy AI script but i a...

Oh, so they move via NavMeshAgents. I'm haven't used those for a long time, but I'm surprised if they don't update the colliders correctly. The billboarding I'm much less concerned about since I assume it to only affect the rotation of the object so even if it doesn't update properly, it wouldn't make much of difference (especially with sphere and capsule colliders, the rotation doesn't really matter). You could try to add kinematic rigidbody to the agent to see if it makes a difference (rigidbodies used to be the default way to move objects so that they update their colliders for raycast queries). Could also just be a bug with unity 6. If adding kinematic rigidbody doesn't help either, you could even separate the colliders from the enemy into separate game objects and move that via physics to match the position of the visual enemy. I'm really surprised if that is really needed though

rain dove
frank ether
#

If you decide to keep the Physics.SyncTransforms solution, make sure it doesn't take too much of a hit for your performance, from what I have heard, using that is not really recommended (nor should it be needed)

rain dove