2.0.1 • Published 2 years ago

@rbxts/projectile-cast v2.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

@rbxts/projectile-cast

Simple projectile package based off of @rbxts/projectile.

Create a projectile using the following options:

Configs

Acceleration?: Vector3; ( Defaults to 0, 0, 0 )

The constant force applied to the projectile.

Bounce?: boolean; ( Defaults to false )

Whether the projectile should bounce

Penetration?: boolean; ( Defaults to false )

Whether the projectile can penetrate through objects in the world

Resistance?: number; ( Defaults to 1 )

The amount of resistance applied during a penetration

MinExitVelocity?: number; ( Defaults to 100 )

The minimum exit velocity of the projectile. If the calculated exit velocity in a penetration is less than this value, the projectile will be destroyed.

CanCollide?: boolean; ( Defaults to true )

Whether the projectile can collide with other objects (whether it should check for collisions)

PhysicsIgnore?: Array<Instance>; ( Defaults to an empty array )

The list of Instances (and their descendants) to ignore during all physics calculations

Duration?: number; ( Defaults to 2 )

The maximum lifespan, in seconds, of the projectile

MaxRange?: number; ( Defaults to 5000 )

The maximum distance, in studs, that the projectile can travel

Renderer?: IRenderer; ( Defaults to a white CylinderRenderer )

The renderer for the projectile

Simple demo:

// main.client.ts
import { Projectile, CylinderRenderer } from "@rbxts/projectile-cast";
import { Players } from "@rbxts/services";

const SHOT_COUNT = 3;
const MIN_SPREAD_ANGLE = math.rad(0);
const MAX_SPREAD_ANGLE = math.rad(10);

const random = new Random();

const mouse = Players.LocalPlayer.GetMouse();

let tag: object | undefined;

mouse.Button1Down.Connect(() => {
    const myTag = {};
    tag = myTag;

    while (tag === myTag) {
        const character = Players.LocalPlayer.Character;
        if (!character) break;

        const head = character.FindFirstChild("Head");
        if (!head || !head.IsA("BasePart")) break;

        const position = head.CFrame.Position;
        const endPos = mouse.Hit.Position;

        for (let i = 0; i < SHOT_COUNT; i++) {
            const velocity = new CFrame(position, endPos)
                .mul(CFrame.Angles(0, 0, random.NextNumber(0, 2 * math.pi))) // roll to a random angle
                .mul(CFrame.Angles(0, random.NextNumber(MIN_SPREAD_ANGLE, MAX_SPREAD_ANGLE), 0))
                .LookVector.mul(75);

            const Bullet = new Projectile(position, velocity, {
                Acceleration: new Vector3(0, -50, 0),
                Bounce: true,
                Penetration: true,
                MinExitVelocity: 50,
                PhysicsIgnore: [character],
                Duration: 4,
                Renderer: new CylinderRenderer(Color3.fromHSV(math.random(), 1, 1)),
            });
            Bullet.Touched.Connect((rayResult: RayResult) => {
                print(rayResult.Instance);
            })
        }
        task.wait(1 / 30);
    }
});

mouse.Button1Up.Connect(() => (tag = undefined));
2.0.1

2 years ago

2.0.0

2 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago