Currently the developers are putting their own money into JC2-MP to keep the servers online.

Please take a few seconds of your time and disable your AdBlock plugin for our website.

Ad revenue is not going to developers, it is used purely for covering our hosting costs.

 

You are also free to donate, which removes all ads from our website!

Patch 0.3 was just released! Full changelog here: https://t.co/4A50m6IKen

2 years ago

Advertisement
August 23, 2019, 03:12:04 pm

Author Topic: [Release] Physics Engine - Bouncy Balls  (Read 2592 times)

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
[Release] Physics Engine - Bouncy Balls
« on: October 18, 2016, 02:00:19 am »
Physics Engine - Bouncy Balls

This is a networked, client-authoritative, sphere/ball physics engine scripted entirely in Lua for Just Cause 2 Multiplayer!





Video Demonstration

Check out this video to see how simulated spheres can interact with the game world and other game entities.

Features

- Rigid bodies are currently limited to only spheres.
- Adjustable gravity and air density. Simulate moon physics if you'd like!
- Sphere properties are fully customizable:
    - Enable or disable dynamic movement or collisions
    - Hue, density, restitution, drag coefficient, friction coefficient, and radius on sphere creation.
    - Initial position, angle, linear velocity, angular velocity, and world can be specified.
- Client-authoritative physics simulation:
    - Discrete collision detection.
    - WorldNetWorkObjects are used to sync information across clients.
    - The client of the player that is nearest to a ball is the controller of that ball.

Usage

- To create a sphere, call the Sphere constructor in a server script with a table of arguments. The only required argument is a position.

    - position: Vector3
    - angle: Angle (default = zero angle)
    - dynamic: boolean (default = true)
    - collisions: boolean (default = true)
    - hue: number 0 to 360, inclusive (default = random)
    - density: number greater than 0 (default = 100)
    - restitution: number 0 to 1, inclusive (default = 0.6)
    - drag_coefficient: positive number (default = 0.47)
    - friction_coefficient: positive number (default = 0.3)
    - radius: number greater than 0 (default = 1)
    - linear_velocity: Vector3 (default = zero vector)
    - angular_velocity: Vector3 (default = zero vector)

- Other configurables are in shared\config.lua:

    - air_density: number in kg/m^3
    - gravity: Vector3 defining acceleration due to gravity
    - sync_interval: positive number (explained below)
    - icosphere_levels: positive number (# of polygons = 20 * 4^levels)

- Example scripts are provided where pressing Z will spawn a sphere in front of a player. Spheres are removed after 60 seconds of existence.

Notes

- Collision detection is discrete, not continuous. This means that very small and/or fast objects can tunnel through other objects or surfaces.

- The physics simulation is relatively demanding. One to two raycasts per frame per sphere are required for accurate world-collisions. Additional number crunching controls kinematics, entity collisions, and sync. You will not be able to simulate hundreds of objects at a time. On my machine (i5 4460 / GTX 970), I was able to run about 40 spheres before my FPS started to drop below 60.

- Sync is tuned to be conservative. The sync interval is measured in "meter-seconds" with a default of 3. If you plan to have a lot of objects, you may want to increase this. If you plan to have few objects, you may want to decrease this. With a value of 3, if a sphere moves 3 meters in 1 second, or 6 meters in 0.5 seconds, or 0.1 meters in 30 seconds, a sync update will be sent. Essentially, the faster a sphere is moving, the more frequently the updates will be sent. Note that, to reduce bandwidth, sphere angles are not synced.

- The engine does not account for low FPS or high ping. If a client is controlling physics with either, then you may see some unexpected results.

- Spheres are technically icospheres represented using the built-in Model class. They use a primitive shading algorithm designed to show rotation, not dynamic lighting or fancy textures. Although, I suppose you could texture the spheres if you were so inclined.

- For simplicity, players and vehicles are treated as spheres when they collide with sphere objects.

Thank You

Thank you to Dev_34 and Lord Farquaad for helping test the sync and thank you to F430 for participating in the video linked above!

----

Clone or download from GitHub here!

----

If I have left anything out of this post, or if you have questions, or are experiencing bugs or difficulties using this, please let me know below!
« Last Edit: October 18, 2016, 05:59:54 pm by SinisterRectus »

Lord_Farquaad

  • Full Member
  • ***
  • Posts: 217
    • View Profile
Re: [Release] Physics Engine - Bouncy Balls
« Reply #1 on: October 18, 2016, 02:05:42 am »
BALLZ



There are so many different minigames and gamemodes that these could be made into.  The possibilities are unlimited!

Anyway, these are epic and I highly recommend anyone to try them out and see what you can do with them.

Urik

  • Donator
  • Full Member
  • *****
  • Posts: 119
    • View Profile
Re: [Release] Physics Engine - Bouncy Balls
« Reply #2 on: October 18, 2016, 02:23:16 pm »
This is definitely exciting. I recall we tried to do a football game once by using a player-occupied tuk-tuk as a ball... Didn't work out much due to him falling out of it when it was flipped all the time.
I've tried this out, indeed collision is like point-to-point so it's tricky and doesn't feel right at times cuz it doesn't account for vehicle geometry, but it's very cool and I hope some servers pick it up.
Btw, is it possible to make balls not expire? For me, they disappear after about 1 minute.

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
Re: [Release] Physics Engine - Bouncy Balls
« Reply #3 on: October 18, 2016, 05:37:50 pm »
This is definitely exciting. I recall we tried to do a football game once by using a player-occupied tuk-tuk as a ball... Didn't work out much due to him falling out of it when it was flipped all the time.
You can now disable vehicle ejection, but you'd need custom vehicle and camera physics, and that's annoying to do.

Quote
I've tried this out, indeed collision is like point-to-point so it's tricky and doesn't feel right at times cuz it doesn't account for vehicle geometry, but it's very cool and I hope some servers pick it up.
Yeah. I could use hitboxes, but that's more complicated and I'm not interested in doing that just yet. Maybe in the future. I could use a raycast to get the vehicle geometry, but there is no guarantee that the raycast will hit the vehicle in the right spot, or hit the vehicle at all. I went with a shape trigger and sphere collision for guaranteed consistency.

Quote
Btw, is it possible to make balls not expire? For me, they disappear after about 1 minute.
The expiration is due to the code in server-example.lua. You can discard the example scripts entirely and write your own. The core files are hidden inside _init folders.

dab88

  • Donator
  • Hero Member
  • *****
  • Posts: 658
    • View Profile
Re: [Release] Physics Engine - Bouncy Balls
« Reply #4 on: October 19, 2016, 07:27:50 pm »
ball pit in the dish please