playMaker

Author Topic: Raycast or Get Pixel Color, which faster/less taxing?  (Read 2833 times)

Raika

  • Playmaker Newbie
  • *
  • Posts: 30
Raycast or Get Pixel Color, which faster/less taxing?
« on: October 17, 2018, 12:18:10 PM »
So i have random generated cave(walls and empty space), how will it be better to add objects to the empty space? Raycast or take cave picture and Get Pixel Color?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Raycast or Get Pixel Color, which faster/less taxing?
« Reply #1 on: October 17, 2018, 05:28:57 PM »
Hi.
i think raycast.

Is there a reason that you are getting the pixel color?

Raika

  • Playmaker Newbie
  • *
  • Posts: 30
Re: Raycast or Get Pixel Color, which faster/less taxing?
« Reply #2 on: October 18, 2018, 04:14:18 AM »
More specific my cave have black walls, white empty space so I was thinking that taking picture from above and Get Pixel Color will be better because I need use this from hundreds to thousands of time, eg:

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Raycast or Get Pixel Color, which faster/less taxing?
« Reply #3 on: October 18, 2018, 04:19:07 AM »
Hi,

 what do you need to do with this information, maybe pathfinding would be better?

do you need to check everyframe? how many times per frame or seconds?


 Bye,

 Jean

Raika

  • Playmaker Newbie
  • *
  • Posts: 30
Re: Raycast or Get Pixel Color, which faster/less taxing?
« Reply #4 on: October 18, 2018, 05:45:00 AM »
I will try to explain, i need to use this mostly for creation of cave. When player enter new cave, game need to generate this cave, first step is generating shape (picture in my previous post), then i need to randomly spawn objects (e.g: iron ore), so i need just to know where is empty space, but to estimate where to place essential objects like cave entrance (player spawn), another passage (to another cave), treasure chest etc, I would like to be able to put these things on the ends of the cave, but i dont know how to do that. If you have some idea i will be thankful.
My plan was to start using Raycast/GetPixelColor from the corner to find closest place and put one essential object there and other on the opposite side of cave.
e.g:

What would be perfect (ends of cave) but dont know how to do that:


My plan with ray/pixelcolor:
« Last Edit: October 18, 2018, 06:53:53 AM by Raika »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Raycast or Get Pixel Color, which faster/less taxing?
« Reply #5 on: October 18, 2018, 09:44:40 AM »
Hi,

 how are the cave layout image generated?

 Bye,

 Jean

Raika

  • Playmaker Newbie
  • *
  • Posts: 30
« Last Edit: October 18, 2018, 09:57:22 AM by Raika »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Raycast or Get Pixel Color, which faster/less taxing?
« Reply #7 on: October 19, 2018, 04:40:30 AM »
Hi,

 well, this kind of work should be done in editor and not at runtime.

 but maybe you could make a scene that will process this image, save it into either xml or some scriptable object, or even in the scene itself that you then save as the scene for that level.

 reading pixels will be fine, you don't need raycasting here.

 you can also ksip nth pixels during your scan, that will speed up the process. or save to a lower resolution your image and scan that image for putting stuff in it.



 Bye,

 Jean

Raika

  • Playmaker Newbie
  • *
  • Posts: 30
Re: Raycast or Get Pixel Color, which faster/less taxing?
« Reply #8 on: October 20, 2018, 05:33:50 AM »
This is the solution to which I came, raycast to find white space, then check if this point is not to close to wall, then (in my case):
use 32 rays around this point, if more than 5 rays don't hit wall and if those rays are spread on multiple sides, point is deleted.

That's the result (for now):

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Raycast or Get Pixel Color, which faster/less taxing?
« Reply #9 on: October 29, 2018, 05:16:57 AM »
Hi,

 excellent, looks good to me!

 Bye,

Jean