Discuss Scratch

meowmoo
Scratcher
500+ posts

How To Make A 3D Game

paskal06 wrote:

B1ue123 wrote:

I have a project that shows simple 3D. It isn't perfect by any means, but you might be able to do something with it.
The URL is http://scratch.mit.edu/projects/21572717/#player

That,s not 3D. 3D is something which you can see at all positions.
no, that is just wireframe 3D

http://fyucha.com/

R a i n b o w
nwolf2012
Scratcher
20 posts

How To Make A 3D Game

meowmoo wrote:

dm_games wrote:

it's very complicated maths. Scratch doesn't have a feature to change the sprites 3d rotation
not really, look:

meowmoo wrote:

actual script that will go to a 3D position that is rotatable based on two variables:

define 3D x:(X) y:(Y) z:(Z)
set x to ((([sin v] of (turn X)) * (X)) + (([sin v] of (turn X)) * (Z))
set y to ((([cos v] of (turn Y)) * (Y)) + (([cos v] of (turn Y)) * (Z))

when green flag clicked
forever
set 3D effect to (3D)
end
meowmoo
Scratcher
500+ posts

How To Make A 3D Game

nwolf2012 wrote:

meowmoo wrote:

dm_games wrote:

it's very complicated maths. Scratch doesn't have a feature to change the sprites 3d rotation
not really, look:

meowmoo wrote:

actual script that will go to a 3D position that is rotatable based on two variables:

define 3D x:(X) y:(Y) z:(Z)
set x to ((([sin v] of (turn X)) * (X)) + (([sin v] of (turn X)) * (Z))
set y to ((([cos v] of (turn Y)) * (Y)) + (([cos v] of (turn Y)) * (Z))

when green flag clicked
forever
set 3D effect to (3D)
end
what?

http://fyucha.com/

R a i n b o w
nwolf2012
Scratcher
20 posts

How To Make A 3D Game

meowmoo wrote:

nwolf2012 wrote:

meowmoo wrote:

dm_games wrote:

it's very complicated maths. Scratch doesn't have a feature to change the sprites 3d rotation
not really, look:

meowmoo wrote:

actual script that will go to a 3D position that is rotatable based on two variables:

define 3D x:(X) y:(Y) z:(Z)
set x to ((([sin v] of (turn X)) * (X)) + (([sin v] of (turn X)) * (Z))
set y to ((([cos v] of (turn Y)) * (Y)) + (([cos v] of (turn Y)) * (Z))

when green flag clicked
forever
set 3D effect to (3D)
end
what?

That was just a joke.
thirdlion
Scratcher
20 posts

How To Make A 3D Game

guys I thank you! SO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MUCH FOR YOUR HELP!!!!!!!!!!!!!!!!!!! :{])
meowmoo
Scratcher
500+ posts

How To Make A 3D Game

thirdlion wrote:

guys I thank you! SO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MUCH FOR YOUR HELP!!!!!!!!!!!!!!!!!!! :{])
your welcome!

http://fyucha.com/

R a i n b o w
the_pumpkin_pi
Scratcher
100+ posts

How To Make A 3D Game

Just re-mix other peoples projects. I got my first fav and love by doing that.

define 3D
forever

say [just copy,N,paste]
say[I'm always right on scratch :D]
end

IN IT TO WIN IT!

supercreeper2005
Scratcher
100+ posts

How To Make A 3D Game

Airtoum wrote:

I JUST WANT THE 3D FORMULA! I NEED IT! NOW!
Try this
when [up arrow] key pressed
change size by (-10)
change y by (10)
change x by (-3)

Hello! I'm a scratcher who likes RPGs. Please view my rpg and try out this FNAF based game! Please favorite and Love my games and visit my profile! Also try out our featured project.

Want your Project featured? Click here!
If you are proud of your project, compete here.

Thanks to @austin360 for helping with the RPGs graphics
when I receive [a scratch account v]
imagine :: custom
program :: custom
share:: custom
when I receive <<[a favorite v]:: events > or <<[a follow v]:: events > or <<[a comment v]:: events > or <[a love v]:: events  >> >>
say [Thanks!] for (2) secs
say [You wil get a love too!] for (2) secs
say [I will suggest this to followers!] for (2) secs
say [I'm actually serious! Check out the projects above!] for (2) secs
1337_5CR47CH3R
New to Scratch
27 posts

How To Make A 3D Game

There's no “magic” 3D formula. It requires math no matter what.
The basics are:

Projection
If you have some point(s) with coordinates (x, y, z) then to project them onto the screen, you'll need to use some math. Consider the following (Bill Nye lol):

As you can see, it is a pinhole camera. Only light rays that go through the hole form the picture on the wall. Basically, this projects a 3D scene onto a 3D surface. We can model this to make 3D in scratch. Of course, no pinhole camera provides a perfectly sharp image because the pinhole has to be greater than 0 size. However, when we model this mathematically, we can make the pinhole be 0 size. Of course, there is another problem: the projected image is upside down! To fix this we move the viewing place in front of the pin, which doesn't make sense in real life, but works perfectly well mathematically and in code.

Ok, so now we have our viewing plane in front of the hole. The hole now becomes your eye, and the plane is the screen! Now all we need to do is figure out where stuff in 3D goes on the plane. Let's go back to the example of the pinhole camera. Each light ray that bounces from a distinct point in 3D space and goes through the pinhole gets projected onto the viewing plane. So all we need to do is draw some rays:

As you can see, the point (x, y, z) is now projected onto the plane at 2D point (x', y') (say: x prime, y prime). Using some basic triangle similarity, and assuming the lengths indicated, we can see that y' = y/z, and we can use the same argument to say x' = x/z
Of course, this assumes that the plane is square. What if it's not? Well, since Scratch is 480x360, we need to shorten the horizontal coordinates, x, to compensate. This just means before calculating x' = x/z, multiply x by 360/480, to shrink the scale along the x-axis to match the scale along the y-axis. Basically what this is doing is first dividing x by 480 to transform the range of x values, to then multiplying by 360 to transform the range to match the range of y values, .

Rotation
Translation is easy, all you need to do is add or subtract from the x, y, or z values to move along in some direction. Rotation is harder, however, and requires trigonometry. Rotation is defined by 2 axes, so in 3D there are 3 ways to rotate, rotation around the x-axis, y-axis, or z-axis. Every type works the same way, all you need to do is swap out x, y or y, z or x, z. To start, I'll deal with just changing x and y, aka rotating around the z-axis.

Here we have (x, y) which we want to transform to (x', y') (note: not the same x' and y' as in projection. x' and y' is just a system of notation).
So how do we rotate in these coordinates? It's kind of hard. Luckily, there's another type of coordinate system, polar coordinates. Instead of being defined by x and y, polar coordinates are defined by angle and radius. Take a look:

Whoa. Now all we need to do is increase the angle! But how do we change between cartesian (x, y) and polar (r, O) coordinates? Easy, use trigonometry. atan means arc-tangent, which is the inverse of tangent, which is sine / cosine. You should know this already.
There are 2 ways of expressing the inclination of a line. Slope (y/x) and angle(O). Tangent can help us convert between the two.
y/x = atan(O)
O = tan(y/x)
So to convert (x, y) to (r, O), the first step is O = atan(y/x)
Next is r, which is easy, according to the Pythagorean Theorem. So we have
r = sqrt(x*x + y*y)
O = atan(y/x)
Now we just increase the angle to make it O+a, where a is the angle you want to rotate by (important note: angles in polar coordinates are counterclockwise, so a positive a will be counterclockwise, and negative will be clockwise).
Now convert (r, O+a) back to cartesian coordinates. We can do this with the definition of sine and cosine.
x' = r*cos(O)
y' = r*sin(O)
Now let's put it all together:
x' = sqrt(x*x+y*y)*cos(atan(y/x)+a)
y' = sqrt(x*x+y*y)*sin(atan(y/x)+a)
Using trigonometry identities we have
x' = sqrt(x*x+y*y)*(cos(atan(y/x))*cos(a) - sin(atan(y/x))*sin(a))
y' = sqrt(x*x+y*y)*(sin(atan(y/x))*cos(a) + cos(atan(y/x))*sin(a))
sin(atan(m)) = m/sqrt(1+m*m) and cos(atan(m)) = 1/sqrt(1+m*m) so
x' = sqrt(x*x+y*y)*((1/sqrt((x*x + y*y)/x*x))*cos(a) - (y/(x*sqrt((x*x + y*y)/x*x)))*sin(a))
y' = sqrt(x*x+y*y)*((y/(x*sqrt((x*x + y*y)/x*x)))*cos(a) + (1/sqrt((x*x + y*y)/x*x))*sin(a))
take …/x*x and …/y*y out of the sqrt to make sqrt(…)/x and sqrt(…)/y and then cancel the sqrt(x*x+y*y) (if you don't get it just trust me on this
I don't want to type out all the steps in between because it's messy)
x' = ((1/1/x)*cos(a) - (y/(x/x))*sin(a))
y' = ((y/(x/x))*cos(a) + (1/1/x)*sin(a))
moar simplification gets us
x' = x*cos(a) - y*sin(a)
y' = y*cos(a) + x*sin(a)

Wow. Very neat and simple.
As I said, replace (x, y) with (x, z) or (y, z) to rotate around the y and x axes, respectively.

Conclusion
3D is a very complicated subject that involves a lot of math. I demonstrated the math behind 2 concepts: projection, and rotation. This should enable you to create some basic 3D (it's up to you to implement the math in code). You can rotate the 3D scene with the rotation math I proved, translate by adding or subtracting x, y, or z, and then project it onto the screen using the projection math I proved. If you need more help or don't understand, you can always make another forum post or do a google search. If you don't think you're ready to make 3D yet, by all means don't make 3D. 3D code can quickly get out of hand and you will end up not understanding anything. I hope you will eventually make great 3D projects though!

This concludes this tutorial.
HTH

7H15 15 1337
nwolf2012
Scratcher
20 posts

How To Make A 3D Game

when green flag clicked
go to x: (131) y: (635) z:(121)//category=motion
set [health v] to [100]
set map length to (pick random (50) to (1000000))//category=looks
set map width to (pick random (50) to (1000000))//category=looks
set map height to (pick random (50) to (1000000))//category=looks
forever
face towards [mouse pointer v]//category=motion
if <key [w v] pressed?> then
change z by (9)//category=motion
end
if <key [s v] pressed?> then
change z by (9)//category=motion
end
if <key [a v] pressed?> then
change x by (-9)//category=motion
end
if <key [d v] pressed?> then
change x by (9)//category=motion
end
if <key [space v] pressed?> then
jump (10)//category=motion
end
end
Villager303
Scratcher
3 posts

How To Make A 3D Game

Try this XD

when green flag clicked
go to x: (10) y: (10) z:(10)
get 3d model (http://static.fjcdn.com/pictures/Well+hello+there....+Cake+or+pie_48e3b4_3636572.jpg)
set camera pos x: (0) y: (0) z: (0)
set camera point of interest x: (10) y: (10) z: (10)
render 3d objects
change camrea pos x: (.5) y: (10) z: (-10)
end
end
end

Last edited by Villager303 (July 26, 2014 09:58:20)

beaple
Scratcher
16 posts

How To Make A 3D Game

people i will make history on scratch and make a good graphic 3d gameabout time stampy v.s 2 comes out i will make an advanced game
paskal06
Scratcher
17 posts

How To Make A 3D Game

Try this project. The framework 3d is so fast. http://scratch.mit.edu/projects/11731611/
WO997
Scratcher
64 posts

How To Make A 3D Game

Ok so i know how to make 3d projects just see my profile, formula for 3d is: X=virtualx/virtualz, Y=virtualy/virtualz SIZE OF SPRITE*=virtualsize/virtualz, any questions? *or pen

https://scratch.mit.edu/projects/58287862/ game based on World of Tanks
SNUGGINBUNNY
Scratcher
13 posts

How To Make A 3D Game

add [3D Is Awesome] to [ 3D Game]
letsplayally
Scratcher
100+ posts

How To Make A 3D Game

Hey I gotta a beta 3D engine which is easy to use and it really looks like 3D!: http://scratch.mit.edu/projects/24874034/ If that doesn't work I can give you the mathematical formula (the hard way) but it is very very long and hard to make in scratch.
nwolf2012
Scratcher
20 posts

How To Make A 3D Game

SNUGGINBUNNY wrote:

add [3D Is Awesome] to [ 3D Game]

Again, SNUGGINBUNNY..!
meowmoo
Scratcher
500+ posts

How To Make A 3D Game

@dadOfMrlog has an amazing 3D turoial: http://scratch.mit.edu/studios/202972/ and a 3D environment: http://scratch.mit.edu/projects/25217786/

http://fyucha.com/

R a i n b o w
epicsandwich123
Scratcher
100+ posts

How To Make A 3D Game

hey, no offence, but 3d is probably WAY to advanced for you! it's nothing like the 3d head you made. You'll need to use the pen tools. http://scratch.mit.edu/projects/25217786/

a great project, look at the script.

ever wanted some awesome sening blocks? http://scratch.mit.edu/discuss/topic/45738/
how about copying and pasting? http://scratch.mit.edu/discuss/topic/41980/

#sorry, but games coming soon. check my old account, awesomegames123!

Powered by DjangoBB