playMaker

Author Topic: SphereCast  (Read 8879 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14014
  • Official Playmaker Support
    • View Profile
SphereCast
« on: April 23, 2013, 10:52:27 PM »
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:



 Bye,

 Jean
« Last Edit: January 13, 2017, 12:12:19 AM by jeanfabre »

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • View Profile
    • Grinder Games
Re: SphereCast
« Reply #1 on: April 24, 2013, 02:42:06 AM »
Thats exactly what i need, it works great!

Thanks a lot!

tezer86

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: SphereCast
« Reply #2 on: April 28, 2013, 07: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 

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14014
  • Official Playmaker Support
    • View Profile
Re: SphereCast
« Reply #3 on: April 29, 2013, 11:57:33 AM »
Hi,

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

bye,

 Jean

tezer86

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: SphereCast
« Reply #4 on: April 24, 2014, 06: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

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • View Profile
    • Grinder Games
Re: SphereCast
« Reply #5 on: April 24, 2014, 06: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?
« Last Edit: April 24, 2014, 07:49:28 AM by doppelmonster »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: SphereCast
« Reply #6 on: April 24, 2014, 06:51:01 AM »
I've used this for AI/Pathfinding (modified it a bit though), been really consistent.

tezer86

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: SphereCast
« Reply #7 on: April 24, 2014, 06: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.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: SphereCast
« Reply #8 on: April 24, 2014, 06:59:57 AM »
Do you have colliders on the other objects you're trying to hit?

tezer86

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: SphereCast
« Reply #9 on: April 24, 2014, 07: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?




 

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: SphereCast
« Reply #10 on: April 24, 2014, 07: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.

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • View Profile
    • Grinder Games
Re: SphereCast
« Reply #11 on: April 24, 2014, 07: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  ...

tezer86

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: SphereCast
« Reply #12 on: April 25, 2014, 04: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

Kubold

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: SphereCast
« Reply #13 on: May 19, 2014, 01: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.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: SphereCast
« Reply #14 on: May 19, 2014, 04: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 ) in a package for the AI beta stuff.