12/20/2023 0 Comments Unity raycasthit2dThis can simplify and isolate compounding effects of other items in your scene or prefab. Google for how on your particular mobile target, such as this answer or iOS: or this answer for Android: Īnother useful approach is to temporarily strip out everything besides what is necessary to prove your issue. If you are running a mobile device you can also view the console output. You could also just display various important quantities in UI Text elements to watch them change as you play the game. You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime. You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc. If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances. You can also supply a second argument to Debug.Log() and when you click the message, it will highlight the object in scene, such as Debug.Log("Problem!",this) Knowing this information will help you reason about the behavior you are seeing. are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation) what are the values of the variables involved? Are they initialized? Are the values reasonable? is this code even running? which parts are running? how often does it run? what order does it run in? To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.ĭoing this should help you answer these types of questions: you're getting an error or warning and you haven't noticed it in the console window the code is executing on another GameObject than you think it is the code is executing far MORE OFTEN than you think the code is executing far LESS OFTEN than you think the code is executing far EARLIER or LATER than you think the code you think is executing is not actually executing at all What is often happening in these cases is one of the following: Once you understand what the problem is, you may begin to reason about a solution to the problem. You must find a way to get the information you need in order to reason about what the problem is. Third, if none of that helps you, welcome to debugging. Second, always use named arguments with Physics.Raycast() because it contains many poorly-designed overloads: This will make fixing the GetRa圜astHit2dInfo action kind of difficult because it can't just store the RaycastHit2D - it also needs to store a reference to the input distance float separately so that can be factored into getting the distance.First I don't see where you're even calling shoot() in the above code, so that might be something to look at. Right now your action always gives a "distance" result between 0.1 which is incorrect for any ray length /= 1. My suspicion is that the documentation may be based on some pre-release version of the function where there was no input distance (and distance was instead taken from the magnitude of the direction vector). So you always have to multiply the result by the input distance to get an actual hit distance. So if your input ray distance is 10, and the ray hits something at 5, fraction will return 0.5 even though your input direction vector is normalized. In reality it seems to always pass the hit distance as a fraction of the total ray length (not as a fraction of the magnitude of the input direction as the documentation implies). Yes, I know, the problem from what I can see is that that statement (which is from the Unity documentation) is actually wrong. I am on that case, the direction I pass is normalized. Quote -If the ray's direction vector is normalised then this value is simply the distance between the origin and the hit point Are you able to verify this properly with testing? I think it's simply because my direction is normalized actually. Quote -storeHitDistance.Value = action * rayLength In my experience you have to multiply the hit.fraction by the input distance to get an accurate result, even when using a normalized direction vector. They seem to assume input distance = 1 in their writing. I think there is an error in the Unity documentation for action which means the hit distance output gets incorrect results. Hahahah yup, just check another thread, and there is the surprise, the new animator package for 4.3.Ĭheers for Jean, Alex and the whole Playmaker guys for the awesome tools!!! Unity 2D and Physics 2D Support now available
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |