r/learnjavascript • • Dec 25 '22

Any way to make this 3d in JavaScript?

198 Upvotes

36 comments sorted by

153

u/shuckster Dec 25 '22

It’s an undocumented feature:

window.makeGameGoNow();

12

u/Bugwhacker Dec 25 '22

Would love to know the optional configuration parameters of this global function. MDN isn’t telling me :(

/s

9

u/TheVirtuoid Dec 25 '22

That's why it's undocumented. :)

IIRC, there are three configuration parameters:

  1. psych <Boolean>: Set to true when your brat of a younger sibling is playing the game. The game will randomly do weird, unrelated 'stuff'.

  2. monetize <Boolean | Number>: Set to true to enable playing of ads at the most critical moments of the game. Set to a number to have the game display an ad every <number> seconds.

  3. magic <Map>: Series of keys that define game mechanics. These are used / ignored randomly with each launch.

67

u/[deleted] Dec 25 '22

three.js

8

u/[deleted] Dec 25 '22

Do you want an interactive game? Or just a 3d animation running in the browser?

-24

u/SignHot6352 Dec 25 '22

Isn’t every game interactive?

19

u/[deleted] Dec 25 '22

I was asking if he wants an actual game or just an animated 3d scene… Finding Nemo is 3d animated, yet not an interactive game. But yes, to be precise I would say a game is interactive. 😉

12

u/xocrystalcastles Dec 25 '22

Three.js, Babylon JS, or D3.js

6

u/33ff00 Dec 25 '22

You can do this in d3?

11

u/VegasTamborini Dec 25 '22

Nope

4

u/Swagasaurus-Rex Dec 25 '22

I mean if you wrote all the 3d light transport code and shaders and everything… ya I still wouldn’t recommend d3 for this

0

u/[deleted] Dec 25 '22

I didn't know d3 was still around

6

u/TheVirtuoid Dec 25 '22

There are some great suggestions here - I personally like BabylonJS. They have some good examples in their documentation.

Just a friendly warning - creating this kind of game is not easy, especially if (like me) you have limited experience in game mechanics. I'm writing a car racing game, and what appears on the surface to be real simple has been a brain-buster. :)

But you will learn a lot - just be prepared to spend some serious time working it out.

4

u/Timotheteus123 Dec 25 '22

I recommend combination of three.js, react, react-three-fiber, drei

7

u/TheRealFloomby Dec 25 '22

Just use three.js or vanilla webgl directly. React is poorly suited for games.

1

u/RobertKerans Dec 25 '22 edited Dec 25 '22

Just to note that three-fiber is a declarative wrapper around three, the additional overhead is tiny -- it's essentially just a different API for the same thing (declarative vs imperative)

Now if you then put that 3d GL stuff inside react-rendered DOM nodes that render/rerender a lot then sure, that'll fry performance straightaway. But if not difference should be minimal

(not saying the wrapper is a good/bad idea or whether it should/shouldn't be used)

3

u/TheDownvotesFarmer Dec 25 '22

React?? Why would you? Better all core with vanilla, react it is a transcompiler

1

u/Timotheteus123 Dec 25 '22

The biggest difference is declarative vs imperative. With React you also get useful stuff, components, logic reuse with custom hooks, reactive state (including jotai or zustand), contexts, memoization, state machines with useReducer or xstate. The cool thing about react is that it's simply a reconciler of components, it can add component systems to non-DOM systems like Three.js objects.

3

u/TheDownvotesFarmer Dec 26 '22

All of it unnecessary and expensive, all of it can be achieved by just using closures.

1

u/game_brewer Dec 25 '22

Try threejs.org/

1

u/kr1kun Dec 25 '22

playcanvas?

1

u/LazaroFilm Dec 25 '22

Try psx.js

1

u/KhazadTheBanBender Dec 25 '22

Blender and three.js, these guys can make great things together and in my March learning plan

1

u/Jsk84 Dec 25 '22

Rogue Engine is a unity like game development environment that uses three.js.

1

u/[deleted] Dec 25 '22

There’s a “Make Minecraft with JavaScript” tutorial on Youtube, from FreeCodeCamp. Might get you started in the right direction.

1

u/frading Dec 26 '22

Try with https://polygonjs.com, it's a node-based and procedural webgl editor. It has various examples to get you started https://polygonjs.com/docs/examples

1

u/Fauphi Dec 26 '22

anybody has the source of this video clip?

-11

u/[deleted] Dec 25 '22

[removed] — view removed comment

-7

u/SignHot6352 Dec 25 '22

Why the downvotes? I’ve been using chatgpt for coding since it’s release and it’s the best tool I’ve found so far, saves hours of finding answers through Google or Reddit