|
Hi. I'm working on a project right now and the main ability of the player is being able to grow and shrink whenever. I have no issue doing this BUT... if I grow while next to a wall my guy will go through the wall. I've tried using a raycast but I have objects in my game that have trigger colliders on them and the raycast detects the trigger. I also tried making the raycast ignore the trigger but it's attached to an object I want the player to collide with. So, if i make the raycast ignore that layer it will ignore the mesh I want the player to interact with... Please help. Thanks.
(comments are locked)
|
|
Your situation is such that you have some object (player or whatever) that can be scaled at runtime. When next to objects, this causes penetration as scaling will properly resize the collider of this object, but will not generate collisions. The only way I know of to resolve this is to perform a raycast and offset. You seem to be confused about raycasts or when you're doing them. You have objects with triggers colliders and objects with regular colliders, but that really doesn't mean anything to your problem, so consider them all as colliders just the same. To restate your problem in simpler terms, you have a number of objects with colliders and you only want to raycast against some of them. This can be done either with layers or on an object by object case. I'm sure somewhere in the 90+ questions tagged raycast, there's an answer to this, but I don't blame you for not finding it. To raycast only against certain layers, you would supply a layermask. Different raycasts can use different layermasks. Different objects (even children and parents) can be on different layers. If you simply place the things you don't want to cast against in certain raycasts on different layers than those you wish to cast against in those raycasts, you'll be fine. Say for example, I have a walls with colliders on Layer 9 (collision geo) and sound trigger colliders on Layer 10 (sound zones) and desks with colliders on layer 11 (interactive collision geo) and interactive zones for the desks on Layer 12 (interaction zones). If I want to shoot a gun , but not go through the walls or desks, I could raycast to those objects I wouldn't want to pass through, but not the interactive zones. So I would create a layer mask.
If this is not quite what you want, you may consider raycasting to the objects of importance individually, but this is a bit more expensive. You'll likely want to tag your objects for this purpose and at the very least only cast against objects within a set radius.
One thing to consider is that any offset you apply will upset the results from your raycasts because you will have just moved and you would then need to cast again to ensure that your offset didn't put you through a different object. This is where you would need to design your world and player abilities to prevent problems where you have a character being scaled into the walls on opposite sides. Something like:
Remember only to do your scaling raycasting when you're scaling up (and maybe down, depending on your use case). I can give you a better example of what's going on if you go to http://www.wyldstallynsgames.com then in Development Journal watch update 2 you will see what I'm trying to achieve. I got that you can set the ignore layers but I ran into a problem with my vacuums because when you get in the suction area(trigger collider that's attached to the parent of all aspects of the vacuum) it moves you based on the vacuum's position/direction. So if I put the vacuum's layer to ignore raycasts, which has the trigger collider and the mesh I still want the player to interact with, won't the raycast ignore the mesh?
Sep 22 '10 at 08:16 PM
Dr. Watson
Thanks for the beefy response XD
Sep 22 '10 at 08:17 PM
Dr. Watson
I never said anything about the ignore raycast layer. I said to use a layer mask or to raycast selectively. In my layer mask example, the vacuums would be like my Layer 12 against which I do not raycast in that example, but could easily raycast against in subsequent raycasts by using a mask that included that layer or without using a mask at all. A layer mask only affects the raycast to which you pass it. The raycast for the scaling would ignore the triggers because of the mask while any other raycast without the mask would not.
Sep 23 '10 at 01:57 PM
skovacs1
Ok thanks I'll see if that will do the trick!
Sep 23 '10 at 03:32 PM
Dr. Watson
(comments are locked)
|
