1.0.2 • Published 5 years ago

rophysics v1.0.2

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

RoPhysics

Projectile Physics Calculations For Roblox Projectiles

About

RoPhysics is a JS library that calculates Roblox projectile physics.

Installation / Requirements

  • npm install rophysics --save
  • requirements: Node.js & npm (latest versions).

Usage

The functions file contains more detailed documentation, located in src folder

Calculate Projectile Trajectory Via Velocity:

const { trajectory } = require('rophysics');

/**
 * velocity =  initial muzzle velocity at which projectile was launched.
 * degree   =  angle at which projetile was launched (defaults to 45 degrees if left empty).
 * 
 * trajectory(velocity, degree)
 * 
 */
const data = trajectory(300)

console.log(data)

/* logs:
{
 muzzleVelocity: 300,
 launchAngle: {
  rad: 0.7853981633974483,
  deg: 45
 },
 distance: 458.72,
 height: 114.68,
 time: 2.16
}

 */

Advanced Usage:

This module provides more functions:

/*
  Convert meters to studs.
  meter = Number of meters to convert
  metersToStuds(meter)
 */
const { metersToStuds } = require('rophysics')

const meters = metersToStuds(20)
// => 196.2 studs


/*
  Convert studs to meters.
  studs = Number of studs to covert
  studsToMeters(studs)
 */
const { studsToMeters } = require('rophysics')

const studs = studsToMeters(196.2)
// => 20 meters


/*
  Calculate maximum projectile distance only
  velocity = projectile velocity (muzzle)
  degree = angle at which projectile was launched (default to 45 degrees if left empty)
  maxDistance(velocity, degree)
 */
const { maxDistance } = require('rophysics')

const distance = maxDistance(300, 45)
// => 458.72 (studs)


/*
  Calculate maximum projectile height only
  velocity = projectile velocity (muzzle)
  degree = angle at which projectile was launched (default to 45 degrees if left empty)
  maxHeight(300, 45)

 */
const { maxHeight } = require('rophysics')

const height = maxDistance(300, 45)
// => 114.68 (studs)


/*
  Calculate projectile travel time (when it hits the "earth") only
  velocity = projectile velocity (muzzle)
  degree = angle at which projectile was launched (default to 45 if left empty)
  timeTraveled(velocity, degree) 
 */
const { timeTraveled } = require('rophysics')

const time = timeTraveled(300, 45)


/*
  Convert degrees to radians
 */
const { degToRad } = require('rophysics')

const radian = degToRad(45)
// => 0.7853981633974483


/*
  Convert radians to degrees
 */
const { radToDeg } = require('rophysics')

const degree = radToDeg(0.7853981633974483)
// => 45

Understanding Projectile Physics

  • Roblox Blog(s):
  1. Potato Cannons
  2. Forum
  • YouTube videos/playlist on projectiles physics:
  1. Motion: 2D Kinematics
  2. Projectile Motion Equation
  3. Projectile Motion Example
  4. Fire A Bullet
  5. Bullet Drop

Contributing

Please make a PR or contact me via discord @midknightmare#666 or twitter @midknightmare

License

MIT

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago