#Raycast issues
1 messages · Page 1 of 1 (latest)
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.
@rain dove, your attachment was automatically pasted to https://paste.myst.rs/u16r51aa
a powerful website for storing and sharing text and code snippets. completely free and open source.
i should say it's much much worse when the game is built than when you're playtesting
can you explain your issue more?
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
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
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
@rain dove, your codeblock was automatically pasted to https://paste.myst.rs/y9g68s6n
a powerful website for storing and sharing text and code snippets. completely free and open source.
that's the AI
@rain dove, your codeblock was automatically pasted to https://paste.myst.rs/82xqh6u4
a powerful website for storing and sharing text and code snippets. completely free and open source.
billboarding
@rain dove, your codeblock was automatically pasted to https://paste.myst.rs/paav962w
a powerful website for storing and sharing text and code snippets. completely free and open source.
and the script that handles all health related stuff
If your raycast is working as expected, what is the problem with the enemies colliders?
I have no idea, maybe they move alot with the billboarding and ai following and stuff but it should just be rotation so idk
What kind of collider are you using on your enemies?
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
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
i'll send an update asap
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
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
How close are you to the collider when that happens? Is there a chance the ray could be within the collider already when it is fired?
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
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
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
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?
i’m on 6000.0.32f1, my enemies move and turn based on an enemy AI script but i also have a billboarding script that has them always looking at the player to give that doom-like aesthetic since they’re flat images
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
If i see the bug somehow come back in the future i’ll make sure to do this thanks a lot
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)
sure thing, thanks for all the advice dude