playMaker

Author Topic: Possible to limit Raycast to screen bounds?  (Read 888 times)

curb47

  • Sr. Member
  • ****
  • Posts: 256
Possible to limit Raycast to screen bounds?
« on: September 10, 2020, 07:54:17 AM »
Hello,

Is it possible to set screen edge bounds for Raycast?

When my character (top-down shooter) is shooting left/right it's fine, but when it's shooting up/down it kills enemies just off-screen. I'd like to keep the action contained in the screen.

Thanks in advance.

J.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Possible to limit Raycast to screen bounds?
« Reply #1 on: September 10, 2020, 11:45:09 AM »
HI.
Maybe better to shorten the range?
It might be strange that you can shoot a longer distance depending on your direction

or maybe zoom out when aiming up/down?

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Possible to limit Raycast to screen bounds?
« Reply #2 on: September 12, 2020, 05:49:30 AM »
Hi dino,

Yes, i have experimented with range, but the raycast is too short when facing left&right.

I had an idea though. How about putting a large cube object that fills the entire screen , turn off material render and add a box collider.
Then adjust the size of the box collider to set a screen bounds size of your choice.

That would work i think?

I can Get/Set Position to connect it to the camera too.

Would having such a huge box collider be expensive? Like, do large colliders take more processing power than smaller ones?

In my game i have always turned off the mesh collider for every object and replaced with either box or sphere colliders, but maybe a simple screen-sized box collider is not too expensive.? I don't know.

Thanks for all your help dino. I just noticed from my previous forum posts that i hadn't responded to a few of your suggestions, and the thread got buried. I'm sorry about that; I really appreciate the help you, and jeanfabre provide.

I'm loving the journey I'm on with Playmaker and Unity, so thank you.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Possible to limit Raycast to screen bounds?
« Reply #3 on: September 12, 2020, 06:37:37 AM »
hi,
I think you could have 2 colliders set (1 on top and 1 on bottom)

and maybe set as child to the camera, only thing you need to check to what happens if you change screen resolutions.

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Possible to limit Raycast to screen bounds?
« Reply #4 on: September 12, 2020, 07:32:27 AM »
Ah yes, of course, just colliders for top and bottom.

Thanks