Any good examples for shooting?

I was curious if there are good project examples for shooting projectiles? That is all :slight_smile:

1 Like

I’m interested as well. Would be nice to see a demo project of a sample FPS.

1 Like

I actually have a solution to this.
Basically in a nut shell I pick an object I want to turn into a projectile, clone it and put it in an array that is functioned to always move at a constant rate.

Here is the code to elaborate more clearly. Comments there to help it’s readability.

//Setting up the variables for the test. The attribute variable is the object i want to clone.
var CloneTest2 = pc.createScript('cloneTest2');

CloneTest2.prototype.initialize = function() {
    this.entities = []; //creating an array to affect later. 

// update code called every frame
CloneTest2.prototype.update = function(dt) {
    //this for loop is to move the entities array on the y axis. 
    //everytime I pressed the 1 key I'd cloned the attributed object.

//this is where the fun is
//basicially I'd get the location of our entity that this script is attached too, then clone our attributed object,
//then add it as a child to the project under the root, and spawn it at the location we got earlier and put it under the 
//entities array with a PUSH. 
CloneTest2.prototype.cloning = function() {
    var spawnSpot = this.entity.getPosition();
    var test = this.testObject.clone();;

as for an FPS, you may just need to just get the look vector some how to be the dynamic variable to for loop to all projectiles.

Meaning FIND where the player is looking and then make all things shoot from that angle.

Another thought I just had, is if you distinguish between local vs world position and translation, you can possibly and simply just add the ‘gun’ child to a parent who’s local/world position dynamically affect the ‘gun’ position and translation. Basically have a simple movement for the projectiles in one direction always, and just have them parented to the Player. So when the player turns, the projectile turns.