Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » how to make 3 D projects
- scratchgodo
-
Scratcher
1000+ posts
how to make 3 D projects
how do you make 3 D projects!
when [ v] key pressedEdit: Closed
when this sprite clicked
ask [] and wait
Last edited by scratchgodo (March 8, 2022 13:14:42)
- TRFGCode
-
Scratcher
6 posts
how to make 3 D projects
Hey! its very complicated, but i can do this
You need a variable called Render
this will render some objects when your at a distance
now make a hand sprite (optional)
Now draw a object that you want appear
now put this script in it:
enjoy!
You need a variable called Render
this will render some objects when your at a distance
now make a hand sprite (optional)
Now draw a object that you want appear
now put this script in it:
when green flag clicked
forever
if <(foo) = [your number]> then
show
if <key [w] pressed?> then
change size by (5)
end
if <key [a] pressed?> then
change x by (5)
end
if <key [s] pressed?> then
change size by (-5)
end
if <key [d] pressed?> then
change x by (-5)
end
else
hide
end
end
enjoy!
- souleymane2
-
Scratcher
100+ posts
how to make 3 D projects
Now, this is might answer your question. I'm not gonna provide much code, but gonna talk about two methods. (and probably the easiest). The first one would be raycasting. Pretty much, you cast rays around the player trying to find the nearest walls. This is by far, the easiest way of doing it from scratch but it provides many issues such as making enemy's much harder, and potentially a lot of repeating code. The other method would be to imitate a camera. Now I didn't do this yet, but they talk about it here: https://gamedev.stackexchange.com/questions/10030/how-do-3d-game-engines-render-3d-environments-to-a-2d-screen This would be a very big pain to do but if you are able to you should be able to do stuff like this https://scratch.mit.edu/projects/393464757/ or (if you put the work on it) a 3d version of Minecraft. The easiest way, but the one with the worst resolution, would be the one that I used (this is in my opinion). Now the project is here: https://scratch.mit.edu/projects/540467805/ but I'm still gonna explain how it works. (Note this would only be useful for a maze)
1. A player moves around using the arrow keys to turn and the w key to move.
2. If it touches a maze wall (minimap) it will move backwards.
3. There is a certain amount of walls (in my case 100 or 150 I forgot tbh) to be drawn. The player will turn around (whenever moved) and find the distance of each of these walls using a code similar to this one:
5. using a rectangle drawer you create an algorithm that will draw the walls depending on their distance.
That's how my engine works, now it doesn't give a really realistic 3d illusion, but it's easy to understand (at least I find it) and allows you to get 3d illusions without a ton of work. There are tutorials for 3d engines on scratch do (just have a quick search on youtube) but I find them complicated.
If you don't like any of those options, you can also have a look at how they created the first couple of 3d games. You will then need to translate the code, (into scratch blocks) and try to make a replica. But yea that's all I have to say.
1. A player moves around using the arrow keys to turn and the w key to move.
2. If it touches a maze wall (minimap) it will move backwards.
3. There is a certain amount of walls (in my case 100 or 150 I forgot tbh) to be drawn. The player will turn around (whenever moved) and find the distance of each of these walls using a code similar to this one:
define Turn4. You store the distance in a list that will contain every distance of the wall
point in direction (((direction) - (60)))
repeat (amount of walls)
set [distance to wall] to [0]
repeat until <touching [map] ?>
move (1) steps
change [distance to wall] by (1)
turn cw ((amount of walls) / (90)) degrees
end
end
5. using a rectangle drawer you create an algorithm that will draw the walls depending on their distance.
That's how my engine works, now it doesn't give a really realistic 3d illusion, but it's easy to understand (at least I find it) and allows you to get 3d illusions without a ton of work. There are tutorials for 3d engines on scratch do (just have a quick search on youtube) but I find them complicated.
If you don't like any of those options, you can also have a look at how they created the first couple of 3d games. You will then need to translate the code, (into scratch blocks) and try to make a replica. But yea that's all I have to say.
- DogCatPuppyLover
-
Scratcher
100+ posts
how to make 3 D projects
Follow this tutorial for sprite-based raycasting: https://en.scratch-wiki.info/wiki/Raycaster
- EpicGhoul993
-
Scratcher
1000+ posts
how to make 3 D projects
There are many ways to replicate a 3D environment. If you just started, maybe try parallax method: it doesn't need much code and the result is quite beautiful. Search “ parallax” for more info.
- Discussion Forums
- » Help with Scripts
-
» how to make 3 D projects