Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on April 24, 2013, 01:52:27 AM

Title: SphereCast
Post by: jeanfabre on April 24, 2013, 01:52:27 AM
Hi,

 following a thread, please find a regular SphereCast action, performing like RayCast only casting a sphere instead of a ray.

The action is available on the Ecosystem:

(http://i.imgur.com/HjIBxq2.png)

 Bye,

 Jean
Title: Re: SphereCast
Post by: doppelmonster on April 24, 2013, 05:42:06 AM
Thats exactly what i need, it works great!

Thanks a lot!
Title: Re: SphereCast
Post by: tezer86 on April 28, 2013, 10:47:52 AM
Hey Jean,

Thanks very much for sharing with everyone.

Just one thing I think this is missing is the ability to store the Hit target as a GameObject var. I am terrible at coding so would you be able to update your code with that? I think quite a few people would use it.

Cheers
Terry 
Title: Re: SphereCast
Post by: jeanfabre on April 29, 2013, 02:57:33 PM
Hi,

 you can do that already, the action "GetRaycastHitInfo" is compatible with my SphereCast action :)

bye,

 Jean
Title: Re: SphereCast
Post by: tezer86 on April 24, 2014, 09:29:55 AM
Hey,

I just got around to using this and I seem to be having a bit of trouble. The cast only seems to return a hit every now and then. Not sure if anyone else has seen these issues?

Cheers
Terry
Title: Re: SphereCast
Post by: doppelmonster on April 24, 2014, 09:33:31 AM
I use it in 2 games and it works pretty good. are you sure you have your transforms right and the capsule is pointing in the right direction?
Title: Re: SphereCast
Post by: Lane on April 24, 2014, 09:51:01 AM
I've used this for AI/Pathfinding (modified it a bit though), been really consistent.
Title: Re: SphereCast
Post by: tezer86 on April 24, 2014, 09:53:00 AM
Ah thats good to hear, means I can put it down to my own incorrect use of it and try and work out what im doing wrong.

Im not sure about the direction but that sounds like it might be the issue. To test it I just made the radius and distance huge. I was thinking that this would then  make a big sphere that would easily hit something but it still doesn't. So maybe there is a transform thing that im not getting.
Title: Re: SphereCast
Post by: Lane on April 24, 2014, 09:59:57 AM
Do you have colliders on the other objects you're trying to hit?
Title: Re: SphereCast
Post by: tezer86 on April 24, 2014, 10:06:31 AM
Yeah I have colliders. There sphere hits sometimes but then other times it doesnt, I think this must be a direction related issue. As the object the sphere starts from is moving on a random path.

I think the way I understand sphere casting might be incorrect. I currently have the direction set to 1,1,1. As I assume that it will create a sphere outwards to the size and radius that I have specified. im not actually sure if this is the case now.

So does the radius dictate the radius of the starting sphere or the radius that the sphere will end up at the end of the frame?




 
Title: Re: SphereCast
Post by: Lane on April 24, 2014, 10:21:03 AM
Spherecast is just a thick raycast. It doesn't go out in a spherical shape, or in all directions.

The 'direction' variable is a vector3, so if it was 0,0,1 then it would be straight forward as Z is forward.
Title: Re: SphereCast
Post by: doppelmonster on April 24, 2014, 10:47:41 AM
spherecast creates a capsule in the direction of the vector. with radius you can adjust the thickness of the capsule. Like lane said usually you keep the transform at 0,0,1 to shoot the capsule in the z direction. So 1,1,1 is an odd direction.

If you need a "real" sphere cast you would use a sphere collider as trigger or a lookAt action with a distance check  ...
Title: Re: SphereCast
Post by: tezer86 on April 25, 2014, 07:03:10 AM
Hey Guys,

Thanks a lot for the help and clearing that up. It makes a whole lot more sense now that I understand how it actually works :D

Sphere collider seems like a great fit what what I need.

Thanks again
Title: Re: SphereCast
Post by: Kubold on May 19, 2014, 04:24:52 AM
Hmm, if this is a "thick raycast", can it have an option to fire every frame or every other frame etc. (normal Raycast does it)? Right now it goes off just once.
Title: Re: SphereCast
Post by: Lane on May 19, 2014, 07:29:27 AM
It might have been for performance concerns. Casts have a tendency to get expensive sometimes. I've used spherecasts on the flight AI stuff i'm doing per-frame and haven't really noticed any issues, though. I have a spherecast action every frame ( click (http://hutonggames.com/playmakerforum/index.php?topic=5406.msg34223#msg34223) ) in a package for the AI beta stuff.
Title: Re: SphereCast
Post by: Kubold on May 19, 2014, 07:52:54 AM
Thanks!
Title: Re: SphereCast
Post by: doppelmonster on May 19, 2014, 10:52:25 AM
just use my new best friend action: "next frame event"

I love this thing  ;D
Title: Re: SphereCast
Post by: Kubold on June 11, 2014, 03:05:03 AM
Good tip! Thanks!

Anyway, spherecast every frame solved my camera wall clipping issue in TPP game. It's pretty much rock solid, camera never goes through walls, no matter what angle you try.
Title: Re: SphereCast
Post by: Khoa1994 on June 27, 2014, 02:08:30 AM
If SphereCast hits multiple objects, how could I store these objects to variables? "Get Raycast Hit Info" has only 1 "Game Object Hit" field. I want to store the hit objects into variables to perform operations on them.
Title: Re: SphereCast
Post by: jeanfabre on July 16, 2014, 08:50:28 AM
Hi,

 This action implement the version where it returns the first hit, to access all collisions, we should have a new action using SphereCastAll.

http://docs.unity3d.com/ScriptReference/Physics.SphereCastAll.html

 Please bump this next week, I'll if I can do it.

Bye,

 Jean
Title: Re: SphereCast
Post by: FRickReich on July 16, 2014, 12:08:03 PM
thats fun to use!
Title: Re: SphereCast
Post by: Corjn on January 12, 2017, 07:40:44 AM
The action don't work anymore :( I'm with playmaker 1.8.3 and unity 5.4
Could anyone test it too so we can see if it's only for me or if the code needs an update ?
Title: Re: SphereCast
Post by: jeanfabre on January 13, 2017, 02:12:48 AM
Hi,

 Tested and it works, what exactly doesn't work?

 Bye,

 Jean