Sign in to follow this  

How to do physics in three.js + node game

Recommended Posts

So, im doing a first person shooter using three.js.

Now the question, that i have, is, how do I do physics. First of all, player movement, so the player can not walk through obstacles and jump on crates and not fall into the ground. I gotta do this client-side (for prediction) and server side (so players can not cheat). I dont know, whats the best way to go here, since it also has to be done server side, it shouldnt be too expensive. Do i use a physics engine like cannon and just let the engine handle everything, client and server side aswell ?

Share this post

Link to post
Share on other sites

So I am working on a 3rd person game in three.js and I can kinda help here.

I use a RayCaster:

to detect any collisions with the environment. I do this whenever the player character moves from point A to B. So let's say the player is at A and is moving to point B (in the next frame). I create a RayCaster that originates at point A and is directed at point B. If the RayCaster collides with the environment then I do not allow the movement.


This approach is pretty simple and there's a couple issues with it that I am working on figuring out:

It's inefficient. Because I'm checking if the RayCaster collides with the entire environment (not just the player's immediate area). I plan on fixing this using spacial indexing, I just need to figure out how to do that.

I don't know how to do this on the server side (to prevent cheating like you mentioned) Any ideas there would be amazing.


I hope this helps!

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.