This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-05-14 11:06:44

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Raycasting help

I've made a simple raycaster with 3 rays, each feeding into a separate list then then after they've finished scanning broadcasts to the renderer and it draws, my problem is that at the end of each array (the 3 sprites cover 50 degrees, 20,10,20) the line is shorter than it should be ie. the 20th, 30th and 50th rays are about 50 steps shorter than they should be.


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#2 2012-05-14 19:41:33

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Raycasting help

I'm afraid it's going to be pretty hard to help without being able to see the code.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#3 2012-05-14 19:50:13

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: Raycasting help

Like what AtomicBawm3 said, I don't understand how to help without seeing the code. But, I can show you this guide that you can use to find your mistake. If your talking about the fisheye problem, where even if you're looking at a straight wall the wall looks curved, you would have to use cosine or something like that. AtomicBawm3 could help you with that if that's the problem.

Offline

 

#4 2012-05-15 11:04:41

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Raycasting help

My code is basically the exact same thing, all that's different is that I use start my counting variable at 1 and go up. And cosine? I've found no need for trigonometry in this?


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#5 2012-05-15 19:14:43

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: Raycasting help

zammer990 wrote:

My code is basically the exact same thing, all that's different is that I use start my counting variable at 1 and go up. And cosine? I've found no need for trigonometry in this?

basically, if you have 3-rays moving 1 step then adding one to a "wall distance" variable, instead of having add wall distance to list you would have

add <<[cos v] of (wall distance)>*(angle offset)> to [wall distances v]

Last edited by TorbyFork234 (2012-05-15 19:15:08)

Offline

 

#6 2012-05-15 19:54:03

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Raycasting help

TorbyFork234 wrote:

zammer990 wrote:

My code is basically the exact same thing, all that's different is that I use start my counting variable at 1 and go up. And cosine? I've found no need for trigonometry in this?

basically, if you have 3-rays moving 1 step then adding one to a "wall distance" variable, instead of having add wall distance to list you would have

add <<[cos v] of (angle offset)>*(wall distance)> to [wall distances v]

Fixed.

The reason for the use of the cosine is that if it's not used there's a fisheye effect basically creating a bulge in your drawing.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#7 2012-05-16 10:49:25

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Raycasting help

Ok, thanks for the help, though it didn't really solve much  hmm


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

Board footer